/* ─── Design Tokens ─────────────────────────────────────────────────── */
:root {
  --bg:            #F8FAFC;
  --surface:       #FFFFFF;
  --surface-2:     #F1F5F9;
  --surface-3:     #E9EEF6;
  --border:        #E2E8F0;
  --border-strong: #CBD5E1;

  --text:   #0F172A;
  --text-2: #334155;
  --muted:  #64748B;
  --faint:  #94A3B8;

  --accent:       #2563EB;
  --accent-light: #EFF6FF;
  --accent-hover: #1D4ED8;
  --accent-muted: #BFDBFE;

  --ok:       #16A34A;
  --ok-light: #F0FDF4;
  --ok-muted: #BBF7D0;

  --warn:       #D97706;
  --warn-light: #FFFBEB;
  --warn-muted: #FDE68A;

  --danger:       #DC2626;
  --danger-light: #FFF1F2;
  --danger-muted: #FECACA;

  --violet:       #7C3AED;
  --violet-light: #F5F3FF;
  --violet-muted: #DDD6FE;

  --radius:    8px;
  --radius-sm: 5px;
  --radius-lg: 12px;
  --radius-xl: 16px;

  --shadow:    0 1px 3px rgba(15,23,42,.07), 0 1px 2px rgba(15,23,42,.04);
  --shadow-md: 0 4px 12px rgba(15,23,42,.08), 0 2px 4px rgba(15,23,42,.04);
  --shadow-lg: 0 12px 32px rgba(15,23,42,.10), 0 4px 8px rgba(15,23,42,.05);

  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "Fira Code", Menlo, Consolas, monospace;
  --w:    1180px;
  --topbar-h: 60px;
}

/* ─── Reset ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; -webkit-text-size-adjust: 100%; }
body {
  min-height: 100%;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: inherit; }

/* ─── Layout ─────────────────────────────────────────────────────────── */
.container {
  max-width: var(--w);
  margin: 0 auto;
  padding: 28px 20px;
}

/* ─── Topbar ─────────────────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.topbar-inner {
  max-width: var(--w);
  height: 100%;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Brand */
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  text-decoration: none;
}
.logo {
  width: 32px;
  height: 32px;
  border-radius: var(--radius);
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 800;
  font-size: 15px;
  letter-spacing: -.5px;
  flex-shrink: 0;
}
.brand-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.2px;
}

/* Nav */
.nav {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-left: 10px;
}
.nav-link {
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  transition: background .12s, color .12s;
  white-space: nowrap;
}
.nav-link:hover  { background: var(--surface-2); color: var(--text); }
.nav-link.active { background: var(--accent-light); color: var(--accent); font-weight: 600; }

/* Topbar right */
.nav-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}
.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  text-transform: uppercase;
}
.user-chip {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 10px 4px 4px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 12px;
  color: var(--text-2);
  white-space: nowrap;
}
.role-pill {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--muted);
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: 999px;
  border: 1px solid var(--border);
}

/* Mobile nav toggle */
.nav-toggle {
  display: none;
  background: none;
  border: none;
  padding: 7px;
  color: var(--muted);
  border-radius: var(--radius-sm);
  line-height: 0;
}
.nav-toggle:hover { background: var(--surface-2); }
.nav-mobile-wrap {
  display: none;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 8px 16px 12px;
  flex-direction: column;
  gap: 2px;
}
.nav-mobile-wrap.open { display: flex; }
.nav-mobile-wrap .nav-link { display: block; padding: 8px 10px; }

@media (max-width: 680px) {
  .nav { display: none; }
  .nav-toggle { display: flex; }
  .user-chip .user-name { display: none; }
}

/* ─── Page header ────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}
.page-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.3px;
  line-height: 1.25;
}
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 5px;
}
.breadcrumb a { color: var(--muted); transition: color .12s; }
.breadcrumb a:hover { color: var(--text); }
.breadcrumb-sep { color: var(--faint); user-select: none; }
.page-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

/* ─── Buttons ────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  transition: background .12s, border-color .12s, box-shadow .12s, transform .06s;
  white-space: nowrap;
  text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn.danger {
  background: var(--danger-light);
  border-color: var(--danger-muted);
  color: var(--danger);
}
.btn.danger:hover { background: var(--danger-muted); }

.btn.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}
.btn.ghost:hover { background: var(--surface-2); color: var(--text); border-color: var(--border); }

.btn.sm {
  padding: 5px 10px;
  font-size: 12px;
  border-radius: var(--radius-sm);
  gap: 4px;
}

/* ─── Cards ──────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 20px;
}
.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.card-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.2px;
}
.card-subtitle {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
  line-height: 1.4;
}

/* ─── Grid layouts ───────────────────────────────────────────────────── */
.grid-2    { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3    { display: grid; grid-template-columns: repeat(3,1fr); gap: 16px; }
.grid-auto { display: grid; gap: 20px; grid-template-columns: minmax(0,1.6fr) minmax(0,1fr); }
@media (max-width: 900px) {
  .grid-2, .grid-3, .grid-auto { grid-template-columns: 1fr; }
}

/* ─── KPIs ───────────────────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 24px;
}
@media (max-width: 700px) { .kpi-grid { grid-template-columns: repeat(2,1fr); } }
@media (max-width: 400px) { .kpi-grid { grid-template-columns: 1fr; } }

.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 18px;
}
.kpi-icon {
  width: 34px;
  height: 34px;
  border-radius: var(--radius);
  background: var(--accent-light);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  margin-bottom: 10px;
}
.kpi-value {
  font-size: 28px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -.5px;
  line-height: 1;
}
.kpi-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  margin-top: 4px;
}

/* ─── Tables ─────────────────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-top: 12px;
}
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.table th {
  padding: 10px 14px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--muted);
  white-space: nowrap;
}
.table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-2);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr.rowlink { cursor: pointer; transition: background .1s; }
.table tbody tr.rowlink:hover td { background: var(--surface-2); }
.table td strong { color: var(--text); font-weight: 600; }

/* ─── Badges / Status chips ──────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid transparent;
  white-space: nowrap;
  background: var(--surface-2);
  color: var(--muted);
  border-color: var(--border-strong);
}
/* Job/Box statuses */
.badge.open     { background: var(--accent-light);  color: var(--accent);  border-color: var(--accent-muted); }
.badge.closed   { background: var(--surface-2);     color: var(--muted);   border-color: var(--border-strong); }
.badge.packed   { background: var(--warn-light);    color: var(--warn);    border-color: var(--warn-muted); }
.badge.stored   { background: var(--violet-light);  color: var(--violet);  border-color: var(--violet-muted); }
.badge.returned { background: var(--ok-light);      color: var(--ok);      border-color: var(--ok-muted); }
.badge.sealed   { background: var(--warn-light);    color: var(--warn);    border-color: var(--warn-muted); }
/* User roles */
.badge.role-admin    { background: var(--violet-light); color: var(--violet); border-color: var(--violet-muted); }
.badge.role-tech     { background: var(--accent-light);  color: var(--accent); border-color: var(--accent-muted); }
.badge.role-readonly { background: var(--surface-2);    color: var(--muted);  border-color: var(--border-strong); }

/* Item conditions */
.badge.good     { background: var(--ok-light);      color: var(--ok);      border-color: var(--ok-muted); }
.badge.water    { background: var(--accent-light);   color: var(--accent);  border-color: var(--accent-muted); }
.badge.smoke    { background: #FFF7ED; color: #C2410C; border-color: #FED7AA; }
.badge.fire     { background: var(--danger-light);   color: var(--danger);  border-color: var(--danger-muted); }
.badge.damaged  { background: var(--surface-2);     color: var(--text-2);  border-color: var(--border-strong); }

/* ─── Forms ──────────────────────────────────────────────────────────── */
.form { display: flex; flex-direction: column; gap: 14px; }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
@media (max-width: 600px) {
  .form-grid-2, .form-grid-3 { grid-template-columns: 1fr; }
}

.field { display: flex; flex-direction: column; gap: 5px; }
.field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  letter-spacing: .1px;
}
.field label .req { color: var(--danger); margin-left: 2px; }
.field-hint { font-size: 11px; color: var(--faint); margin-top: -2px; }

.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  line-height: 1.4;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,.10);
}
.field input::placeholder,
.field textarea::placeholder { color: var(--faint); }
.field textarea { min-height: 80px; resize: vertical; }
.field input[type="file"] { padding: 6px 10px; }

.form-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding-top: 4px;
}

/* Inline select used in table rows */
.inline-select {
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
}
.inline-select:focus { outline: none; border-color: var(--accent); }

/* ─── Tabs ───────────────────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
  overflow-x: auto;
}
.tab-btn {
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  border: none;
  background: none;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
  transition: color .12s, border-color .12s;
  font-family: inherit;
}
.tab-btn:hover  { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ─── Notices (inline alerts) ────────────────────────────────────────── */
.notice {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  border: 1px solid transparent;
  margin-bottom: 16px;
}
.notice.ok    { background: var(--ok-light);     border-color: var(--ok-muted);     color: var(--ok); }
.notice.error { background: var(--danger-light);  border-color: var(--danger-muted); color: var(--danger); }
.notice.warn  { background: var(--warn-light);    border-color: var(--warn-muted);   color: var(--warn); }

/* ─── Toasts ─────────────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  top: 76px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  padding: 11px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  border: 1px solid transparent;
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: all;
  animation: toastIn .2s ease;
  max-width: 320px;
}
.toast.ok    { background: var(--ok-light);     border-color: var(--ok-muted);     color: var(--ok); }
.toast.error { background: var(--danger-light);  border-color: var(--danger-muted); color: var(--danger); }
.toast.info  { background: var(--accent-light);  border-color: var(--accent-muted); color: var(--accent); }
.toast.out   { animation: toastOut .2s ease forwards; }
@keyframes toastIn  { from { opacity:0; transform:translateY(-8px) scale(.97); } to { opacity:1; transform:none; } }
@keyframes toastOut { from { opacity:1; } to { opacity:0; transform:translateY(-6px); } }

/* ─── Confirm Modal ──────────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.35);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-overlay.open { display: flex; animation: fadeIn .15s ease; }
@keyframes fadeIn { from { opacity:0; } to { opacity:1; } }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: 24px;
  max-width: 380px;
  width: 100%;
  animation: slideUp .15s ease;
}
@keyframes slideUp { from { opacity:0; transform:translateY(8px); } to { opacity:1; transform:none; } }
.modal-title   { font-size: 16px; font-weight: 700; color: var(--text); margin-bottom: 8px; }
.modal-body    { font-size: 13px; color: var(--text-2); margin-bottom: 20px; line-height: 1.5; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* ─── Auth ───────────────────────────────────────────────────────────── */
.auth-wrap {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
}
.auth-card {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
  padding: 28px;
}
.auth-logo {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-lg);
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 18px;
  font-weight: 800;
  margin-bottom: 20px;
}
.auth-title    { font-size: 18px; font-weight: 700; color: var(--text); margin-bottom: 4px; }
.auth-subtitle { font-size: 13px; color: var(--muted); margin-bottom: 20px; }

/* ─── Item cards grid ────────────────────────────────────────────────── */
.items-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}
@media (max-width: 900px) { .items-grid { grid-template-columns: repeat(2,1fr); } }
@media (max-width: 500px)  { .items-grid { grid-template-columns: 1fr; } }

.item-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: box-shadow .15s, transform .15s;
}
.item-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.item-thumb {
  aspect-ratio: 4/3;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  cursor: zoom-in;
}
.item-thumb img { width: 100%; height: 100%; object-fit: cover; transition: transform .2s; }
.item-thumb:hover img { transform: scale(1.04); }
.item-thumb-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  color: var(--faint);
  font-size: 12px;
}
.item-body   { padding: 12px; }
.item-name   { font-size: 13px; font-weight: 600; color: var(--text); line-height: 1.3; }
.item-meta   { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ─── Lightbox ───────────────────────────────────────────────────────── */
#lightbox {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.88);
  z-index: 2000;
  align-items: center;
  justify-content: center;
  padding: 20px;
  cursor: zoom-out;
}
#lightbox.open { display: flex; }
#lightbox img {
  max-width: 90vw;
  max-height: 90vh;
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
  cursor: default;
}
/* Gallery nav arrows */
.lb-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255,255,255,.18);
  border: none;
  border-radius: 50%;
  width: 48px; height: 48px;
  color: #fff;
  font-size: 28px;
  line-height: 1;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  z-index: 1;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background .12s;
}
.lb-nav:hover { background: rgba(255,255,255,.30); }
.lb-prev { left: 10px; }
.lb-next { right: 10px; }
.lb-counter {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255,255,255,.65);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .3px;
  pointer-events: none;
}

/* Photo count badge on item thumbs */
.item-thumb { position: relative; }
.item-photo-count {
  position: absolute;
  bottom: 6px;
  right: 6px;
  background: rgba(0,0,0,.55);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  pointer-events: none;
  letter-spacing: .2px;
}

/* ─── Empty state ────────────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 40px 20px;
  text-align: center;
}
.empty-icon  { font-size: 28px; opacity: .35; margin-bottom: 4px; }
.empty-title { font-size: 14px; font-weight: 600; color: var(--text); }
.empty-sub   { font-size: 13px; color: var(--muted); }

/* ─── Divider ────────────────────────────────────────────────────────── */
.hr { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

/* ─── Utility ────────────────────────────────────────────────────────── */
.muted        { color: var(--muted); }
.faint        { color: var(--faint); }
.small        { font-size: 12px; }
.bold         { font-weight: 600; }
.nowrap       { white-space: nowrap; }
.flex         { display: flex; align-items: center; gap: 8px; }
.flex-wrap    { flex-wrap: wrap; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.mt-4   { margin-top: 4px; }
.mt-8   { margin-top: 8px; }
.mt-12  { margin-top: 12px; }
.mt-16  { margin-top: 16px; }
.mt-20  { margin-top: 20px; }
.w-full { width: 100%; }
.section-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--muted);
  margin-bottom: 10px;
}

/* ─── Bottom Nav ─────────────────────────────────────────────────────── */
.bottom-nav { display: none; }

@media (max-width: 680px) {
  /* ── Prevent ANY horizontal overflow from rescaling the page ── */
  html { overflow-x: hidden; max-width: 100%; }
  body { overflow-x: hidden; max-width: 100vw; }

  /* ── Container: constrain width and clip overflow ── */
  .container {
    padding: 16px 14px;
    max-width: 100vw;
    overflow-x: hidden;
    box-sizing: border-box;
  }

  /* ── All grid/flex children must not overflow their column ── */
  .grid-auto > *,
  .grid-2 > *,
  .grid-3 > * { min-width: 0; overflow: hidden; }

  /* ── Cards: clip overflow ── */
  .card { overflow: hidden; }

  /* ── All inputs/selects cannot be wider than container ── */
  input, select, textarea { max-width: 100%; min-width: 0; box-sizing: border-box; }

  /* ── inline-flex elements (code-preview etc) become block on mobile ── */
  .code-preview { display: flex; width: 100%; box-sizing: border-box; }

  /* ── Topbar: slim down so it fits on 375px ── */
  .topbar-inner { padding: 0 14px; gap: 8px; }
  /* Sign-out btn is in the mobile hamburger menu — hide from topbar */
  .topbar .nav-right .btn.ghost { display: none; }
  /* Role pill takes space and isn't critical on mobile */
  .topbar .role-pill { display: none; }

  /* ── Page header/actions: stack on mobile, buttons wrap ── */
  .page-header  { flex-direction: column; gap: 8px; }
  .page-actions { gap: 6px; flex-shrink: 1; width: 100%; flex-wrap: wrap; }
  .page-actions .btn { flex-shrink: 1; }

  /* Prevent iOS auto-zoom on inputs (must be ≥16px) */
  .field input,
  .field select,
  .field textarea { font-size: 16px; }

  /* Ensure comfortable tap targets */
  .btn { min-height: 44px; }
  .btn.sm { min-height: 36px; }

  /* Extra bottom padding so content doesn't hide behind bottom nav */
  .container {
    padding-bottom: calc(72px + env(safe-area-inset-bottom, 12px));
  }

  /* Bottom Nav */
  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 200;
    background: var(--surface);
    border-top: 1px solid var(--border);
    box-shadow: 0 -2px 10px rgba(15,23,42,.07);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .bottom-nav-link {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 10px 6px;
    font-size: 10px;
    font-weight: 600;
    color: var(--muted);
    text-decoration: none;
    letter-spacing: .3px;
    text-transform: uppercase;
    min-height: 56px;
    transition: color .12s;
    -webkit-tap-highlight-color: transparent;
  }
  .bottom-nav-link:hover,
  .bottom-nav-link.active { color: var(--accent); }

  .bottom-nav-link svg {
    width: 22px;
    height: 22px;
    stroke: currentColor;
    stroke-width: 1.8px;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex-shrink: 0;
  }

  /* Center "+" FAB */
  .bottom-nav-new {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px 4px;
    min-height: 56px;
  }
  .bottom-nav-new a {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
    font-weight: 300;
    line-height: 1;
    box-shadow: 0 3px 12px rgba(37,99,235,.40);
    text-decoration: none;
    transition: background .12s, transform .1s;
    -webkit-tap-highlight-color: transparent;
  }
  .bottom-nav-new a:hover  { background: var(--accent-hover); }
  .bottom-nav-new a:active { transform: scale(.92); }
}

/* ─── Dropdown ───────────────────────────────────────────────────────── */
.dropdown {
  position: relative;
}
.dropdown-menu {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  min-width: 168px;
  z-index: 200;
  overflow: hidden;
}
.dropdown.open .dropdown-menu {
  display: block;
}
.dropdown-item {
  display: block;
  padding: 10px 14px;
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
  white-space: nowrap;
  transition: background .1s;
}
.dropdown-item:hover {
  background: var(--surface-2);
}

/* ─── Topbar search ──────────────────────────────────────────────────── */
.topbar-search {
  position: relative;
  display: flex;
  align-items: center;
}
.topbar-search svg {
  position: absolute;
  left: 10px;
  color: var(--muted);
  pointer-events: none;
  flex-shrink: 0;
}
.topbar-search input {
  width: 220px;
  padding: 7px 12px 7px 32px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  transition: border-color .15s, width .2s, background .12s;
}
.topbar-search input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
  width: 280px;
  box-shadow: 0 0 0 3px rgba(37,99,235,.10);
}
.topbar-search input::placeholder { color: var(--faint); }
@media (max-width: 900px) {
  .topbar-search { display: none; }
}

/* ─── Condition dots ─────────────────────────────────────────────────── */
.cond-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  vertical-align: 1px;
}
.cond-dot.cond-good    { background: var(--ok); }
.cond-dot.cond-water   { background: #0284C7; }
.cond-dot.cond-smoke   { background: var(--muted); }
.cond-dot.cond-fire    { background: var(--danger); }
.cond-dot.cond-damaged { background: var(--warn); }

/* ─── Error pages ────────────────────────────────────────────────────── */
.error-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  text-align: center;
  gap: 12px;
}
.error-page-code {
  font-size: 72px;
  font-weight: 800;
  color: var(--border-strong);
  line-height: 1;
}
.error-page-title { font-size: 20px; font-weight: 700; color: var(--text); }
.error-page-sub   { color: var(--muted); max-width: 360px; }

/* ─── Dark mode ──────────────────────────────────────────────────────── */
@media (prefers-color-scheme: dark) {
  :root {
    --bg:            #0B1120;
    --surface:       #131C2E;
    --surface-2:     #1A2540;
    --surface-3:     #1E2B47;
    --border:        #253352;
    --border-strong: #2E3D5E;

    --text:   #F0F4FF;
    --text-2: #A8B8D8;
    --muted:  #6B80A0;
    --faint:  #3D5070;

    --accent:       #3B82F6;
    --accent-light: rgba(59,130,246,.12);
    --accent-hover: #2563EB;
    --accent-muted: rgba(59,130,246,.25);

    --ok:       #22C55E;
    --ok-light: rgba(34,197,94,.10);
    --ok-muted: rgba(34,197,94,.25);

    --warn:       #F59E0B;
    --warn-light: rgba(245,158,11,.10);
    --warn-muted: rgba(245,158,11,.25);

    --danger:       #EF4444;
    --danger-light: rgba(239,68,68,.10);
    --danger-muted: rgba(239,68,68,.25);

    --violet:       #A78BFA;
    --violet-light: rgba(167,139,250,.10);
    --violet-muted: rgba(167,139,250,.25);

    --shadow:    0 1px 3px rgba(0,0,0,.4), 0 1px 2px rgba(0,0,0,.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,.5), 0 2px 4px rgba(0,0,0,.3);
    --shadow-lg: 0 12px 32px rgba(0,0,0,.6), 0 4px 8px rgba(0,0,0,.4);
  }

  /* Fix photo thumbnails in dark mode */
  .item-thumb img,
  .table img { border-color: var(--border) !important; }

  /* Fix lightbox */
  #lightbox { background: rgba(0,0,0,.92); }

  /* Fix modal */
  .modal-overlay { background: rgba(0,0,0,.6); }

  /* Fix auth page */
  .auth-wrap  { background: var(--bg); }
  .auth-card  { background: var(--surface); border-color: var(--border); }

  /* Inline select in dark */
  .inline-select { background: var(--surface-2); color: var(--text); }

  /* Print: keep white background for reports */
  @media print {
    :root {
      --bg:      #fff;
      --surface: #fff;
      --text:    #000;
    }
  }
}

/* ─── Manual theme override (always wins over @media) ───────────────── */

/* Force LIGHT regardless of system preference */
[data-theme="light"] {
  --bg:            #F8FAFC;
  --surface:       #FFFFFF;
  --surface-2:     #F1F5F9;
  --surface-3:     #E9EEF6;
  --border:        #E2E8F0;
  --border-strong: #CBD5E1;
  --text:   #0F172A;
  --text-2: #334155;
  --muted:  #64748B;
  --faint:  #94A3B8;
  --accent:       #2563EB;
  --accent-light: #EFF6FF;
  --accent-hover: #1D4ED8;
  --accent-muted: #BFDBFE;
  --ok:       #16A34A; --ok-light: #F0FDF4; --ok-muted: #BBF7D0;
  --warn:     #D97706; --warn-light: #FFFBEB; --warn-muted: #FDE68A;
  --danger:   #DC2626; --danger-light: #FFF1F2; --danger-muted: #FECACA;
  --violet:   #7C3AED; --violet-light: #F5F3FF; --violet-muted: #DDD6FE;
  --shadow:    0 1px 3px rgba(15,23,42,.07), 0 1px 2px rgba(15,23,42,.04);
  --shadow-md: 0 4px 12px rgba(15,23,42,.08), 0 2px 4px rgba(15,23,42,.04);
  --shadow-lg: 0 12px 32px rgba(15,23,42,.10), 0 4px 8px rgba(15,23,42,.05);
}

/* Force DARK regardless of system preference */
[data-theme="dark"] {
  --bg:            #0B1120;
  --surface:       #131C2E;
  --surface-2:     #1A2540;
  --surface-3:     #1E2B47;
  --border:        #253352;
  --border-strong: #2E3D5E;
  --text:   #F0F4FF;
  --text-2: #A8B8D8;
  --muted:  #6B80A0;
  --faint:  #3D5070;
  --accent:       #3B82F6;
  --accent-light: rgba(59,130,246,.12);
  --accent-hover: #2563EB;
  --accent-muted: rgba(59,130,246,.25);
  --ok:       #22C55E; --ok-light: rgba(34,197,94,.10); --ok-muted: rgba(34,197,94,.25);
  --warn:     #F59E0B; --warn-light: rgba(245,158,11,.10); --warn-muted: rgba(245,158,11,.25);
  --danger:   #EF4444; --danger-light: rgba(239,68,68,.10); --danger-muted: rgba(239,68,68,.25);
  --violet:   #A78BFA; --violet-light: rgba(167,139,250,.10); --violet-muted: rgba(167,139,250,.25);
  --shadow:    0 1px 3px rgba(0,0,0,.4), 0 1px 2px rgba(0,0,0,.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,.5), 0 2px 4px rgba(0,0,0,.3);
  --shadow-lg: 0 12px 32px rgba(0,0,0,.6), 0 4px 8px rgba(0,0,0,.4);
}
[data-theme="dark"] .item-thumb img,
[data-theme="dark"] .table img      { border-color: var(--border) !important; }
[data-theme="dark"] #lightbox       { background: rgba(0,0,0,.92); }
[data-theme="dark"] .modal-overlay  { background: rgba(0,0,0,.6); }
[data-theme="dark"] .auth-wrap      { background: var(--bg); }
[data-theme="dark"] .auth-card      { background: var(--surface); border-color: var(--border); }
[data-theme="dark"] .inline-select  { background: var(--surface-2); color: var(--text); }
