body{color:var(--text);background:var(--bg)}
:root{--bg:#0b0f16;--card:#111827;--muted:#6b7280;--text:#ffffff}
body.theme-light{--bg:#ffffff;--card:#f3f4f6;--muted:#4b5563;--text:#111111}

:root {
  --bg: #0b0e14;
  --fg: #e6edf3;
  --muted: #95a1ad;
  --card: #131722;
  --accent: #3ea6ff;
  --ok: #3ddc97;
  --warn: #ffb703;
  --bad: #ff7575;
  --border: #1f2633;
}

body.theme-light {
  --bg: #f7f9fc;
  --fg: #0b0e14;
  --muted: #4c566a;
  --card: #ffffff;
  --accent: #0066cc;
  --ok: #009e60;
  --warn: #d48a00;
  --bad: #c0392b;
  --border: #e5e9f0;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, 'Helvetica Neue', Arial;
  background: var(--bg);
  color: var(--fg);
}

.app-header, .app-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.app-footer { border-top: 1px solid var(--border); border-bottom: none; }

.header-actions button {
  margin-left: 8px;
}

.controls {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--card);
}
.control-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.control-group .ml { margin-left: 16px; }

.kpi {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  padding: 12px 16px;
}
.kpi-card {
  background: var(--card);
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
}
.kpi-title { color: var(--muted); font-size: 12px; }
.kpi-value { font-size: 20px; font-weight: 700; margin-top: 4px; }

.chart-box {
  background: var(--card);
  margin: 0 16px 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
}

#map {
  height: 72vh;
  margin: 0 16px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  overflow: hidden;
}

button, input, select {
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
}
button:hover { border-color: var(--accent); cursor: pointer; }

/* Settings dialog */
#settings-dialog::backdrop { background: rgba(0,0,0,.5); }
.settings-form {
  width: min(1100px, 95vw);
  max-height: 90vh;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0;
}
.settings-form header, .settings-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.settings-footer { border-top: 1px solid var(--border); border-bottom: 0; }
.settings-toolbar {
  display: flex; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--border);
}
.settings-table-wrap { overflow: auto; max-height: 60vh; }
.settings-table { width: 100%; border-collapse: collapse; }
.settings-table th, .settings-table td {
  border-bottom: 1px solid var(--border);
  padding: 6px 8px;
  text-align: left;
}
.settings-table input[type="text"], .settings-table input[type="number"] {
  width: 140px;
}
.settings-table input[type="color"] { width: 40px; padding: 0; border: none; background: transparent; }
.settings-table td:first-child { color: var(--muted); font-size: 12px; }

/* Larger title in popup */
.popup strong { font-size: 18px; }

.popup { max-width: 240px; }

.popup { font-size: 16px; }

/* Compact layout for popup meta */
.popup .popup-meta { margin-top:6px; display:flex; flex-direction:column; gap:2px; }
.popup .popup-meta .lbl { opacity:0.8; margin-right:4px; }
.popup .popup-meta .val { font-weight:600; }

/* Force larger font size for popup */
.popup { font-size: 18px !important; line-height: 1.4; }

/* === Dark blue theme and hero header === */
html, body { background: linear-gradient(90deg, #0a1a3a, #111322); color: #f2f6ff; }

.hero{
  padding: 28px 16px;
  text-align: center;
  background: linear-gradient(90deg, #173b8c, #0d1224);
  border-bottom: 1px solid rgba(255,255,255,0.12);
}
.hero-inner{ max-width: 1100px; margin: 0 auto; display:flex; flex-direction:column; align-items:center; gap: 12px; }
.hero-logo{ width: 124px; height: auto; filter: drop-shadow(0 4px 12px rgba(0,0,0,0.5)); }
.hero-title{ margin:0; font-size: clamp(20px,3.2vw,36px); font-weight:800; letter-spacing:.4px; color:#fff; text-transform: uppercase; }

/* Keep map readable on dark bg */
#map { background:#0a1a3a; }

/* Center and style the top header bar */
.header-bar{
  display: inline-block;
  width: 100%;
  text-align: center;
  font-weight: 800;
  font-size: 22px;
  color: #fff;
}
.hero, .hero-inner, .hero-title{ text-align: center; }

/* Centered header bar */
.header-bar{
  display:inline-block;
  width:100%;
  text-align:center;
  font-weight:800;
  font-size:22px;
  color:#fff;
}
.hero, .hero-inner, .hero-title{ text-align:center; }

/* Controls spacing when placed below the map */
main #map{ margin-bottom: 10px; }
section.controls{ margin: 8px 16px 16px; }

/* Photo in popup */
.unit-photo-wrap{display:none;margin-top:8px;max-width:280px;}
.unit-photo-wrap img{display:block;width:100%;height:auto;border-radius:8px}
.unit-photo-wrap.show{display:block}


/* --- Brand hero --- */
.hero.hero--brand{
  padding: 24px 16px 12px;
  background: var(--bg);
  text-align: center;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
body.theme-light .hero.hero--brand{ border-bottom-color: rgba(0,0,0,.06); }
.hero-inner{ display:flex; flex-direction:column; align-items:center; gap:10px; }

.hero-logo{ width:68px; height:auto; opacity:.95; }
.hero-agency{ margin: 0; font-size: clamp(20px, 2.4vw, 28px); letter-spacing: .06em; color: var(--text); font-weight: 700; text-align:center; }
.hero-project{ margin: 0; font-size: clamp(22px, 2.8vw, 32px); letter-spacing: .08em; color: var(--text); font-weight: 800; text-align:center; }

.u-upper{ text-transform: uppercase; }

/* Header actions row */
.app-header{
  display:flex; justify-content:flex-end; align-items:center;
  gap:8px; padding: 8px 12px; background: var(--bg);
  border-bottom: 1px solid rgba(255,255,255,.06);
}
body.theme-light .app-header{ border-bottom-color: rgba(0,0,0,.06); }
.app-header .header-actions button{
  background: var(--card); color: var(--text);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 8px; padding:6px 10px; cursor:pointer;
}
body.theme-light .app-header .header-actions button{
  border-color: rgba(0,0,0,.08);
}

.kpi-box{ color: var(--text); }

/* Ensure map takes space below hero */
#map{ min-height: 62vh; }

/* Popup text inherits theme color */
.leaflet-popup-content{ color: var(--text); }

/* Settings dialog color tweak */
.settings-form{ color: var(--text); }
.settings-table th, .settings-table td{ color: var(--text); }


/* --- Two-column layout: map left, side panel right --- */
.layout {
  display: grid;
  grid-template-columns: 70% 30%;
  gap: 12px;
  padding: 12px;
}

.layout-map {
  min-height: 70vh;
}

#map {
  width: 100%;
  height: 100%;
  min-height: 70vh;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 8px;
}

.layout-side {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.kpi-box {
  background: var(--card);
  color: var(--text);
  padding: 16px;
  border-radius: 8px;
  text-align: left;
}

/* --- Safe animations --- */
@keyframes fadeLeft { from{opacity:0; transform:translateX(-12px);} to{opacity:1; transform:none;} }
.hero-logo{ animation: fadeLeft .6s ease-out both; width: 160px; height:auto; }
.hero-agency{ animation: fadeLeft .7s ease-out both .05s; }
.hero-project{ animation: fadeLeft .8s ease-out both .1s; }

@media (prefers-reduced-motion: reduce){
  .hero-logo,.hero-agency,.hero-project{ animation: none !important; }
}

/* Popup improve contrast */
.leaflet-popup-content{ color:#000 !important; }
.leaflet-popup-content-wrapper,.leaflet-popup-tip{ background:#fff; color:#000; }

/* Chart area */
.chart-box{ background: var(--card); border-radius:8px; padding:12px; height:360px; }
#levelChart{ width:100% !important; height:100% !important; }

/* SAFE THEME TEXT */
body, .app-header, .kpi-box, .controls, .settings-form,
.settings-table th, .settings-table td, .settings-toolbar button, .settings-toolbar input,
.chart-box, .hero-agency, .hero-project, .header-actions button { color: var(--text); }


/* KPI Box Styling (card) */
#kpi-box{
  background: var(--card);
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
  padding: 24px;
  margin: 20px auto;
  text-align: center;
  font-size: 26px;
  font-weight: bold;
  color: var(--text);
}

/* FORCE LIGHT TEXT BLACK */
body.theme-light, body.theme-light * { color: var(--text) !important; }

/* Sticky right sidebar */
.layout-side{ position: sticky; top: 12px; align-self: start; height: fit-content; }

/* Skeleton loader */
@keyframes shimmer{ 0%{background-position:-500px 0} 100%{background-position:500px 0} }
.skeleton{ border-radius:12px; background: linear-gradient(90deg, rgba(255,255,255,.08) 25%, rgba(255,255,255,.14) 37%, rgba(255,255,255,.08) 63%); background-size:1000px 100%; animation: shimmer 1.2s infinite; }
.kpi-skeleton{ height: 84px; }
.chart-skeleton{ height: 340px; }


/* ===== AUTH OVERLAY ===== */
#auth-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 12, 20, 0.97);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(6px);
}

.auth-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 36px;
  width: min(420px, 92vw);
  gap: 6px;
}

.auth-box h2 {
  margin: 8px 0 4px;
  font-size: 22px;
  text-align: center;
  color: var(--text);
  letter-spacing: .04em;
}

.auth-subtitle {
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  margin: 0 0 16px;
}

.auth-logo {
  display: flex;
  justify-content: center;
  margin-bottom: 4px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  margin-bottom: 12px;
}

.form-group label {
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 10px 12px;
  font-size: 15px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
}

.form-group input:focus,
.form-group textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.btn-primary {
  width: 100%;
  padding: 11px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 4px;
}
.btn-primary:hover { opacity: .88; }
.btn-primary:disabled { opacity: .5; cursor: default; }

.link-secondary {
  display: block;
  text-align: center;
  margin-top: 14px;
  color: var(--accent);
  font-size: 14px;
  text-decoration: none;
}
.link-secondary:hover { text-decoration: underline; }

.error-msg { color: var(--bad); font-size: 13px; min-height: 16px; margin-bottom: 4px; }
.success-msg { color: var(--ok); font-size: 13px; min-height: 16px; margin-bottom: 4px; }


/* ===== APP MODALS ===== */
.app-modal {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0;
  width: min(560px, 95vw);
  max-height: 85vh;
  color: var(--text);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.app-modal.wide-modal { width: min(680px, 95vw); }
.app-modal.full-modal { width: min(940px, 97vw); max-height: 90vh; }
.app-modal::backdrop { background: rgba(0,0,0,.6); backdrop-filter: blur(3px); }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-header h3 { margin: 0; font-size: 17px; color: var(--text); }

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px;
}

.modal-footer {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  background: var(--card);
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-shrink: 0;
}

.btn-icon {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  line-height: 1;
}
.btn-icon:hover { color: var(--text); background: rgba(255,255,255,.06); }


/* ===== CASES LIST ===== */
.case-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 10px;
  background: var(--card);
}
.case-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}
.case-title { font-weight: 600; font-size: 15px; color: var(--text); }
.case-date { font-size: 13px; color: var(--muted); white-space: nowrap; }
.case-desc {
  margin-top: 6px;
  font-size: 14px;
  color: var(--muted);
  line-height: 1.5;
  white-space: pre-wrap;
}
.case-actions { margin-top: 8px; display: flex; gap: 6px; }

.btn-sm {
  padding: 4px 10px;
  font-size: 13px;
  border-radius: 6px;
  cursor: pointer;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-sm:hover { border-color: var(--accent); }
.btn-danger { border-color: rgba(255,117,117,.5) !important; color: var(--bad) !important; }
.btn-danger:hover { background: var(--bad) !important; color: #fff !important; }

.loading { color: var(--muted); text-align: center; padding: 24px; }
.no-data { color: var(--muted); text-align: center; padding: 24px; font-style: italic; }

/* Info button in Leaflet popup */
.btn-unit-info {
  margin-top: 10px;
  width: 100%;
  padding: 8px 12px;
  background: #1a56db;
  color: #fff !important;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: block;
}
.btn-unit-info:hover { background: #1e40af; }


/* ===== ADMIN TABLE ===== */
.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  color: var(--text);
}
.admin-table th {
  color: var(--muted);
  font-weight: 500;
  background: var(--card);
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  position: sticky;
  top: 0;
}
.admin-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.admin-table tr:hover td { background: rgba(255,255,255,.03); }
.table-wrap { overflow-x: auto; }

.admin-tabs {
  padding: 0 18px;
  border-bottom: 1px solid var(--border);
  background: var(--card);
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}
.tab-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 10px 14px;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  border-radius: 0;
}
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

.admin-toolbar {
  margin-bottom: 12px;
  font-size: 14px;
  color: var(--muted);
}


/* ===== USER INFO IN HEADER ===== */
.user-info-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.user-email {
  font-size: 13px;
  color: var(--muted);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.app-header {
  justify-content: space-between;
}


/* ===== RESPONSIVE ===== */
@media (max-width: 600px) {
  .auth-box { padding: 28px 20px; }
  .modal-header { padding: 12px 14px; }
  .modal-body { padding: 12px 14px; }
  .modal-footer { padding: 10px 14px; }
  .user-email { display: none; }
}

/* ===== UTILITY ===== */
.hidden { display: none !important; }

/* ===== POPUP — updated layout ===== */
.leaflet-popup-content-wrapper {
  background: rgba(12, 26, 46, 0.95) !important;
  border: 1px solid rgba(62,166,255,0.35) !important;
  border-radius: 12px !important;
  box-shadow: 0 8px 32px rgba(0,0,0,0.6) !important;
  color: #fff !important;
}
.leaflet-popup-tip { background: rgba(12, 26, 46, 0.95) !important; }
.leaflet-popup-content { color: #fff !important; font-size: 13px; min-width: 220px; }

.popup-title {
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  margin-bottom: 8px;
  line-height: 1.3;
}
.popup-info { display: flex; flex-direction: column; gap: 3px; margin-bottom: 6px; }
.popup-row  { display: flex; gap: 6px; align-items: baseline; flex-wrap: wrap; }
.popup-label { color: rgba(255,255,255,0.55); font-size: 11px; white-space: nowrap; flex-shrink: 0; }

.unit-photo-wrap {
  display: none;
  margin: 8px 0;
  border-radius: 8px;
  overflow: hidden;
  max-height: 150px;
}
.unit-photo-wrap.show { display: block; }
.unit-photo-wrap img { width: 100%; height: auto; display: block; object-fit: cover; max-height: 150px; }

.btn-unit-info {
  margin-top: 8px;
  width: 100%;
  padding: 8px 12px;
  background: #1a56db;
  color: #fff !important;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: block;
  transition: background 0.15s;
}
.btn-unit-info:hover { background: #1e40af; }

/* ===== UNIT MODAL TABS ===== */
.unit-modal-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--card);
  flex-shrink: 0;
}
.unit-tab {
  flex: 1;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 10px 14px;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  border-radius: 0;
  transition: color 0.15s;
}
.unit-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.unit-tab:hover:not(.active) { color: var(--text); }

/* ===== FOLDER CARDS (section grid) ===== */
.folders-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
  padding: 8px 0;
}
.folder-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 16px 10px 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
}
.folder-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 4px 14px rgba(0,0,0,0.3);
}
.folder-card.folder-empty { opacity: 0.4; cursor: default; }
.folder-card.folder-empty:hover { transform: none; box-shadow: none; border-color: var(--border); }
.folder-icon { font-size: 32px; line-height: 1; }
.folder-name { font-size: 12px; font-weight: 600; color: var(--text); line-height: 1.3; }
.folder-count { font-size: 11px; color: var(--muted); }

/* ===== SECTION FILES PANEL ===== */
.sec-files-panel { padding-top: 4px; }
.sec-panel-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
  flex-wrap: wrap;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.sec-panel-back {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  font-size: 12px;
  padding: 4px 10px;
  cursor: pointer;
  white-space: nowrap;
}
.sec-panel-back:hover { border-color: var(--accent); color: var(--accent); }
.sec-upload-btn {
  margin-left: auto;
  background: transparent;
  border: 1px solid var(--accent);
  border-radius: 8px;
  color: var(--accent);
  font-size: 12px;
  padding: 4px 10px;
  cursor: pointer;
}
.sec-upload-btn:hover { background: var(--accent); color: #fff; }

/* ===== FILES GRID ===== */
.files-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 10px;
  padding: 4px 0;
}
.file-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 8px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
}
.file-card:hover { border-color: var(--accent); }
.file-thumb-wrap {
  width: 100%;
  height: 72px;
  border-radius: 6px;
  overflow: hidden;
  background: rgba(0,0,0,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.file-thumb { width: 100%; height: 100%; object-fit: cover; }
.file-overlay {
  position: absolute;
  inset: 0;
  background: rgba(26,86,219,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  font-size: 22px;
  transition: opacity 0.2s;
}
.file-card:hover .file-overlay { opacity: 1; }
.file-big-icon { font-size: 36px; line-height: 1; }
.file-icon-link { text-decoration: none; display: flex; justify-content: center; }
.file-card-name {
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  word-break: break-word;
  line-height: 1.3;
  max-height: 2.6em;
  overflow: hidden;
}
.file-del {
  position: absolute;
  top: 4px;
  right: 4px;
  background: none;
  border: none;
  font-size: 14px;
  cursor: pointer;
  opacity: 0;
  padding: 2px;
  line-height: 1;
}
.file-card:hover .file-del { opacity: 0.7; }
.file-del:hover { opacity: 1 !important; }

/* ===== PDF / DOC VIEWER MODAL ===== */
.pdf-modal { width: min(900px, 96vw); max-height: 92vh; }
.pdf-modal-body { padding: 0 !important; flex: 1; display: flex; }
.pdf-modal-body iframe { flex: 1; width: 100%; border: none; min-height: 70vh; }

/* ===== ADMIN UPLOAD ===== */
.admin-upload-section { padding-bottom: 12px; border-bottom: 1px solid var(--border); margin-bottom: 12px; }
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 24px 16px;
  text-align: center;
  margin-top: 8px;
}
.upload-zone-icon { font-size: 32px; display: block; margin-bottom: 6px; }
.upload-zone-text { margin: 0 0 4px; font-size: 14px; color: var(--text); }
.upload-zone-hint { color: var(--muted); font-size: 12px; }
.upload-zone-btn { display: inline-block; margin-top: 10px; width: auto; padding: 8px 20px; cursor: pointer; }
.progress-bar-wrap { height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; }
.progress-bar-fill { height: 100%; background: var(--accent); border-radius: 4px; transition: width 0.2s; }
.progress-text { font-size: 13px; color: var(--muted); margin-top: 4px; }
.admin-sec-group { margin-bottom: 16px; }
.admin-sec-title { font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; padding-bottom: 4px; border-bottom: 1px solid var(--border); }
.admin-files-total { font-size: 13px; color: var(--muted); margin-bottom: 8px; }

/* ===== IMAGE VIEWER MODAL ===== */
.img-modal { width: min(900px, 96vw); max-height: 92vh; }
.img-modal-body { padding: 0 !important; display: flex; align-items: center; justify-content: center; background: #000; min-height: 60vh; }
.img-modal-body img { max-width: 100%; max-height: 80vh; object-fit: contain; }

/* ===== SECTION MANAGEMENT ===== */
.sec-mgmt-bar { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; align-items: center; }
.add-section-form { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; padding: 10px; background: var(--card); border: 1px solid var(--border); border-radius: 8px; margin-bottom: 10px; }
.add-section-form input { flex: 1; min-width: 180px; }

/* ===== FOLDER CARD DELETE BUTTON ===== */
.folder-card { position: relative; }
.btn-del-section {
  position: absolute;
  top: 6px;
  right: 6px;
  background: none;
  border: none;
  font-size: 14px;
  cursor: pointer;
  opacity: 0;
  padding: 2px;
  line-height: 1;
  z-index: 2;
}
.folder-card:hover .btn-del-section { opacity: 0.7; }
.btn-del-section:hover { opacity: 1 !important; }

/* ══════════════════════════════════════════
   DOCUMENT PROTECTION
══════════════════════════════════════════ */

/* Watermark overlay */
.doc-watermark {
  position: fixed;
  inset: 0;
  z-index: 99999;
  pointer-events: none;
  overflow: hidden;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 40px 20px;
  padding: 40px;
  transform: rotate(-30deg) scale(1.4);
  transform-origin: center center;
  user-select: none;
}

.doc-watermark span {
  display: block;
  font-size: 13px;
  color: rgba(0, 0, 0, 0.12);
  white-space: nowrap;
  font-family: Arial, sans-serif;
  font-weight: 600;
  letter-spacing: 0.5px;
}

/* Disable text selection in viewers */
#img-viewer-modal,
#pdf-viewer-modal {
  user-select: none;
  -webkit-user-select: none;
}

#img-viewer-modal img {
  pointer-events: none;
  -webkit-user-drag: none;
  user-drag: none;
}

/* Hide everything when printing */
@media print {
  body * {
    display: none !important;
  }
  body::after {
    display: block !important;
    content: 'Друк документів заборонено.';
    font-size: 24px;
    text-align: center;
    margin-top: 40px;
  }
}

/* ── Document content viewer ── */
.doc-viewer-content {
  width: 100%;
  height: 100%;
  overflow-y: auto;
  padding: 0;
  background: #f5f5f5;
}

/* DOCX rendered HTML */
.docx-content {
  background: #fff;
  max-width: 800px;
  margin: 20px auto;
  padding: 40px 48px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.1);
  font-size: 14px;
  line-height: 1.7;
  color: #222;
  user-select: none;
  -webkit-user-select: none;
}
.docx-content h1,.docx-content h2,.docx-content h3 { margin: 16px 0 8px; font-weight: 700; }
.docx-content p { margin: 6px 0; }
.docx-content table { border-collapse: collapse; width: 100%; margin: 12px 0; }
.docx-content td, .docx-content th { border: 1px solid #ccc; padding: 6px 10px; }

/* PDF pages */
.pdf-page-canvas {
  display: block;
  margin: 16px auto;
  max-width: 100%;
  box-shadow: 0 2px 12px rgba(0,0,0,0.15);
  user-select: none;
  -webkit-user-select: none;
  pointer-events: none;
}

/* Info message for unsupported formats */
.doc-info-msg {
  text-align: center;
  padding: 60px 20px;
  font-size: 18px;
  color: #555;
  line-height: 1.8;
}
.doc-info-msg small { font-size: 14px; color: #888; }
