:root{
  --bg:#f6f8fb;
  --text:#222;
  --muted:#6b7280;
  --brand:#1a3d6d;
  --accent:#2b66c9;
  --ok:#2e7d32;
  --ok-bg:#e8f5e8;
  --warn:#f57c00;
  --warn-bg:#fff3e0;
  --info:#2b66c9;
  --info-bg:#e3f2fd;
  --err:#d32f2f;
  --err-bg:#fdecea;
  --err-border:#f5c6cb;
  --card:#ffffff;

  --radius:12px;
  --shadow-sm:0 2px 8px rgba(26,61,109,.07);
  --shadow-md:0 8px 24px rgba(16,24,40,.08);
  --border:#e6e8ec;
  --nav-fg:#ffffff;

  --pill-bg:#eef4ff;
  --pill-border:#dfe7fb;
  --imp-bg:#fff6d5;
  --imp-border:#ffe08a;
  --imp-fg:#6b4f00;
  --head-bg:#f7f8fb;
  --row-hover:#fafcff;
  --menu-border:#e5e7eb;
  --danger:#b91c1c;
}

html[data-theme="dark"]{
  --bg:#0f1620;
  --text:#e6e9ef;
  --muted:#9aa4b2;
  --brand:#274d80;
  --accent:#5b9bff;
  --ok:#4caf50;
  --ok-bg:#173620;
  --warn:#ffab40;
  --warn-bg:#3a2a10;
  --info:#5b9bff;
  --info-bg:#122a44;
  --err:#ff6b6b;
  --err-bg:#3a1418;
  --err-border:#5c1f24;
  --card:#161e2b;

  --shadow-sm:0 2px 8px rgba(0,0,0,.35);
  --shadow-md:0 8px 24px rgba(0,0,0,.45);
  --border:#2a3444;
  --nav-fg:#ffffff;

  --pill-bg:#16233a;
  --pill-border:#2a3f66;
  --imp-bg:#3a3212;
  --imp-border:#5c4d1a;
  --imp-fg:#f0d878;
  --head-bg:#141c2a;
  --row-hover:#131b28;
  --menu-border:#2a3444;
  --danger:#ff6b6b;
}

/* Base */
*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0;
  font: 15px/1.45 system-ui,-apple-system,"Segoe UI",Roboto,Arial,"Helvetica Neue",sans-serif;
  color:var(--text);
  background:var(--bg);
}
.container{max-width:1200px;margin:0 auto;padding:22px}

/* Brand + nav */
#nav-root{min-height:56px}
.nav-bar{
  background:var(--brand);
  color:var(--nav-fg);
  position:sticky; top:0; z-index:10;
  box-shadow:0 2px 8px rgba(0,0,0,.08);
}
.nav-inner{
  max-width:1200px; margin:0 auto;
  display:flex; gap:16px; align-items:center; padding:12px 20px;
}
.brand{display:flex; align-items:center; gap:10px; font-weight:700; color:var(--nav-fg); text-decoration:none}
.brand img{width:22px; height:22px}
.nav-bar a{
  color:var(--nav-fg); text-decoration:none; padding:8px 12px; border-radius:8px;
  transition:background .2s;
}
.nav-bar a:hover{background:rgba(255,255,255,.12)}
.nav-bar a.active{background:rgba(255,255,255,.2)}
.nav-spacer{flex:1}
.nav-toggle{ display:none; background:transparent; border:none; color:var(--nav-fg); font-size:1.4rem; cursor:pointer; padding:6px 10px; line-height:1 }
#themeToggle{
  appearance:none; border:1px solid rgba(255,255,255,.3); background:transparent; color:var(--nav-fg);
  border-radius:8px; padding:6px 10px; cursor:pointer; font-size:1rem; line-height:1;
}
#themeToggle:hover{background:rgba(255,255,255,.12)}

/* Headings / cards */
h1,h2,h3{color:var(--brand); margin:0 0 12px}
.card{
  background:var(--card); border-radius:var(--radius);
  box-shadow:var(--shadow-sm); padding:18px; border:1px solid var(--border);
}
.section-title{font-size:1.25rem; margin-bottom:12px; border-bottom:2px solid var(--border); padding-bottom:6px}

/* Buttons */
.btn{appearance:none; border:none; border-radius:10px; padding:10px 16px; font-weight:700; cursor:pointer}
.btn.primary{background:var(--ok); color:#fff}
.btn.secondary{background:var(--head-bg); color:var(--text); border:1px solid var(--border)}
.btn.primary:hover{filter:brightness(.96)}
.btn.secondary:hover{filter:brightness(.96)}

/* Inputs */
label.block{display:block; font-weight:600; color:var(--brand); margin:0 0 6px}
input[type="text"],input[type="date"],input[type="time"],select,textarea{
  width:100%; padding:10px 12px;
  border:1px solid var(--border); border-radius:10px; background:var(--card); color:var(--text);
  transition:border-color .15s, box-shadow .15s;
}
input:focus,select:focus,textarea:focus{
  outline:none; border-color:var(--accent);
  box-shadow:0 0 0 3px rgba(43,102,201,.15);
}
textarea{min-height:170px; resize:vertical}
.small{font-size:.9rem; color:var(--muted)}
.muted{color:var(--muted)}

/* Impersonation banner */
.imp{background:var(--imp-bg);border:1px solid var(--imp-border);color:var(--imp-fg);padding:10px 12px;border-radius:10px;margin:10px 0}

/* Pill */
.pill{display:inline-block;padding:4px 10px;border-radius:999px;background:var(--pill-bg);color:var(--brand);font-weight:700;border:1px solid var(--pill-border)}

/* Error banner (assets/notify.js) */
.err-banner{position:sticky;top:0;z-index:30;background:var(--err-bg);color:var(--err);border-bottom:1px solid var(--err-border);padding:10px 16px;text-align:center;font-weight:600;display:none}

/* Sync/status indicator */
.sync-status{display:flex;align-items:center;gap:8px}
.sync-dot{width:8px;height:8px;border-radius:50%;background:var(--muted);flex:none}
.sync-dot.ok{background:var(--ok)}
.sync-dot.err{background:var(--err)}
.sync-label{font-size:.85em;color:var(--muted)}
.sync-refresh{appearance:none;border:1px solid var(--border);background:var(--card);color:var(--text);border-radius:8px;padding:2px 8px;cursor:pointer;font-size:.85em}

/* Filters / table (list page) */
.filters{margin-bottom:18px}
.filters .row{display:flex; gap:12px; flex-wrap:wrap}
.filters .group{display:flex; flex-direction:column; gap:6px}
.filters input,.filters select{min-width:200px}

.inspection-table{
  background:var(--card);border-radius:var(--radius);box-shadow:var(--shadow-sm);
  /* allow action menus to overflow */
  overflow:visible;
  border:1px solid var(--border)
}
table{width:100%;border-collapse:collapse}
th,td{padding:12px;border-bottom:1px solid var(--border);text-align:left;vertical-align:middle}
th{background:var(--head-bg);color:var(--brand);font-weight:700}
tr:hover{background:var(--row-hover)}

.sort-th{cursor:pointer;user-select:none;white-space:nowrap}
.sort-arrow{display:inline-block;margin-left:4px;color:var(--muted);font-size:.85em}
.sort-arrow.active{color:var(--brand)}

/* Pagination */
.pager{display:flex;align-items:center;justify-content:space-between;gap:12px;padding:14px 4px;color:var(--muted);font-size:.9em}
.pager .btn{padding:6px 12px}
.pager .btn:disabled{opacity:.5;cursor:default}

/* Expand-in-place row */
tr.expand-row td{background:var(--head-bg);padding:14px 18px}

/* Status chips */
.status{padding:5px 10px;border-radius:999px;font-size:.85em;font-weight:700;text-transform:capitalize;display:inline-block}
.status.completed{background:var(--ok-bg);color:var(--ok)}
.status.pending{background:var(--warn-bg);color:var(--warn)}
.status.in-progress{background:var(--info-bg);color:var(--info)}

/* Row action menu (list page) */
.wrap-menu{position:relative; display:inline-block}
.menu-btn{appearance:none; border:1px solid var(--menu-border); background:var(--card); color:var(--text); border-radius:8px; padding:6px 10px; cursor:pointer; font-weight:700}
.menu-btn:after{content:"…"; font-size:18px; line-height:1; vertical-align:middle}
.row-menu{position:absolute; right:0; top:36px; width:200px; background:var(--card); box-shadow:var(--shadow-md);
  border:1px solid var(--menu-border); border-radius:12px; padding:6px; display:none; z-index:20}
.row-menu.show{display:block}
.row-menu button{width:100%; text-align:left; border:none; background:transparent; padding:10px 12px; border-radius:8px;
  cursor:pointer; display:block; font-weight:600; color:var(--text)}
.row-menu button:hover{background:var(--head-bg)}
.row-menu .danger{color:var(--danger)}

/* Subsections on form */
.subsection{margin-top:16px;border:1px solid var(--border);border-radius:12px;overflow:hidden}
.subsection-header{
  display:flex;justify-content:space-between;align-items:center;
  padding:12px 14px;background:var(--head-bg);cursor:pointer
}
.subsection-header:hover{filter:brightness(.98)}
.subsection-content{padding:14px;display:none;background:var(--card);border-top:1px solid var(--border)}
.checklist-item{
  padding:14px;border:1px solid var(--border);border-radius:12px;background:var(--head-bg);margin-bottom:12px
}
.response-options{margin:8px 0 10px}
.response-options label{margin-right:14px;font-weight:500;cursor:pointer}

/* Improved Drop Zone */
.drop-zone{
  position:relative;
  border:2px dashed #bcd3ff;
  border-radius:14px;
  background:linear-gradient(180deg,#fbfdff 0%, #f6f9ff 100%);
  padding:18px;
  text-align:center;
  color:#2b66c9;
  transition:background .2s, border-color .2s, box-shadow .2s;
  min-height:120px;
  display:flex; flex-direction:column; align-items:center; justify-content:center;
}
.drop-zone:hover{border-color:#8db5ff; background:#f2f7ff}
.drop-zone.dragover{background:#e7f0ff; border-color:#2b66c9; box-shadow:0 0 0 3px rgba(43,102,201,.15)}
.dz-hint{font-size:14px; color:#294f89}
.dz-thumbs{display:flex; gap:10px; flex-wrap:wrap; margin-top:10px; justify-content:center}
.dz-thumb{
  position:relative; width:96px; height:96px; border:1px solid var(--menu-border); border-radius:10px; overflow:hidden; background:var(--card);
  box-shadow:0 1px 4px rgba(0,0,0,.04)
}
.dz-thumb img{width:100%; height:100%; object-fit:cover; display:block}
.dz-del{
  position:absolute; top:4px; right:4px; width:22px; height:22px; line-height:20px; border:none; border-radius:999px;
  background:rgba(0,0,0,.55); color:#fff; font-weight:700; cursor:pointer
}
.dz-del:hover{ background:rgba(0,0,0,.75) }

/* Submit bar */
.submit-bar{position:sticky; bottom:0; background:var(--card); border-top:1px solid var(--border); padding:12px; display:flex; gap:10px; justify-content:flex-end}

/* Empty state */
.empty{text-align:center;padding:40px 16px;color:var(--muted)}
.empty h3{margin:0 0 8px;color:var(--brand)}

/* Details page */
.details-card{background:var(--card); border-radius:12px; box-shadow:var(--shadow-sm); padding:18px; border:1px solid var(--border)}
.photos{display:grid; grid-template-columns:repeat(auto-fill, minmax(140px, 1fr)); gap:12px}
.photos img{width:100%; height:120px; object-fit:cover; border-radius:10px; border:1px solid var(--border)}

/* Responsive */
@media (max-width:800px){
  .nav-toggle{ display:inline-block; }
  .nav-inner{ flex-wrap:wrap; }
  .nav-inner > a:not(.brand){ display:none; width:100%; }
  .nav-inner.open > a:not(.brand){ display:block; }
  .nav-inner .nav-spacer{ display:none; }
  #themeToggle{ display:none; }
  .nav-inner.open #themeToggle{ display:inline-block; width:100%; text-align:left; margin-top:6px; }
}

@media (max-width:700px){
  .container{padding:16px 12px}
  .filters .row{flex-direction:column}
  .filters input,.filters select{min-width:0; width:100%}

  .inspection-table table, .inspection-table thead, .inspection-table tbody,
  .inspection-table th, .inspection-table td, .inspection-table tr { display:block; }
  .inspection-table thead tr { position:absolute; top:-9999px; left:-9999px; }
  .inspection-table tbody tr:not(.expand-row) { margin-bottom:12px; border:1px solid var(--border); border-radius:var(--radius); padding:10px; background:var(--card); }
  .inspection-table tbody tr.expand-row { border:none; padding:0; margin:0 0 12px; }
  .inspection-table td { border:none; padding:6px 0; display:flex; justify-content:space-between; gap:12px; }
  .inspection-table td[data-label]::before { content:attr(data-label); font-weight:700; color:var(--muted); }
  .inspection-table td.actions-cell { justify-content:flex-end; }
}

@media (max-width:600px){
  .container{padding:16px 12px}
  .filters input,.filters select{min-width:160px}
}

/* Print: hide sticky nav & polish cards */
@media print{
  .nav-bar, .submit-bar, .err-banner { display:none !important; }
  body { background:#fff !important; color:#000 !important; }
  .card, .details-card, .inspection-table { box-shadow:none !important; border:1px solid #ddd; }
}
