/* BoxInventory — mobile-first, dark, large tap targets. */
:root {
  /* Dark theme — soft charcoal with a calm sage-green accent. */
  --bg: #15171a;
  --surface: #1d2024;
  --surface-2: #262a2f;
  --border: #333840;
  --text: #e7e9e7;
  --muted: #8c938f;
  --accent: #84a99c;            /* muted sage / eucalyptus */
  --accent-2: #9cbfb2;
  --accent-press: #6e9183;
  --accent-contrast: #11201b;   /* deep green-black text on sage */
  --danger: #c87b73;
  --ok: #7fa8b8;                /* dusty blue (distinct from the green accent) */
  --radius: 16px;
  --tap: 50px;
  --shadow: 0 2px 16px rgba(0, 0, 0, .45);
}

/* Light theme — warm off-white with a deep sage accent. */
:root[data-theme="light"] {
  --bg: #edefea;
  --surface: #ffffff;
  --surface-2: #eff1ec;
  --border: #dde0d9;
  --text: #1c211e;
  --muted: #616860;
  --accent: #4f7d6e;            /* deeper sage for contrast on light */
  --accent-2: #6f9c8c;
  --accent-press: #3f6757;
  --accent-contrast: #ffffff;
  --danger: #b15049;
  --ok: #5a86a0;
  --shadow: 0 2px 14px rgba(40, 55, 45, .10);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: .3rem;
  padding: .5rem .6rem; padding-top: calc(.5rem + env(safe-area-inset-top));
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(140%) blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand {
  flex: 1; min-width: 0; font-size: 1.15rem; font-weight: 700; margin: 0;
  text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.topbar-right { display: flex; align-items: center; gap: .15rem; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 42px; height: 42px; color: var(--muted);
  background: transparent; border: none; cursor: pointer; border-radius: 12px;
  transition: background .15s ease, color .15s ease;
}
.icon-btn:hover { color: var(--text); background: var(--surface-2); }
.icon-btn:active { background: var(--border); transform: scale(.94); }
#backBtn { color: var(--text); }

.app {
  max-width: 720px; margin: 0 auto; padding: 1rem;
  padding-bottom: calc(2rem + env(safe-area-inset-bottom));
}

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  min-height: var(--tap); padding: .85rem 1.1rem; width: 100%;
  font-size: 1.05rem; font-weight: 600;
  border: none; border-radius: var(--radius); cursor: pointer;
  background: var(--accent); color: var(--accent-contrast);
}
.btn:active { background: var(--accent-press); }
.btn.secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn.ghost { background: transparent; color: var(--accent); border: 1px solid var(--border); }
.btn.danger { background: var(--danger); }
.btn.small { width: auto; min-height: 40px; padding: .45rem .8rem; font-size: .95rem; }
.btn[disabled] { opacity: .55; pointer-events: none; }
.btn-row { display: flex; gap: .6rem; flex-wrap: wrap; }
.btn-row > .btn { flex: 1; }

/* Menu */
.greeting { text-align: center; color: var(--muted); margin: .5rem 0 1.3rem; }
.greeting strong { color: var(--text); }
.badge-su { display: inline-block; margin-left: .4rem; font-size: .65rem; font-weight: 700; letter-spacing: .5px;
  text-transform: uppercase; background: var(--accent); color: var(--accent-contrast); padding: .12rem .4rem; border-radius: 6px; vertical-align: middle; }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: .9rem; }
.tiles-wide { display: grid; gap: .9rem; margin-top: .9rem; }
.tile {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .6rem;
  min-height: 124px; padding: 1.2rem; text-decoration: none; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 20px;
  box-shadow: var(--shadow); transition: transform .08s ease, background .15s ease, border-color .15s ease;
}
.tiles-wide .tile { flex-direction: row; min-height: 62px; gap: .8rem; justify-content: flex-start; }
.tile:active { transform: scale(.97); }
.tile:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
.tile .ico { color: var(--accent); }
.tile.primary { background: linear-gradient(145deg, var(--accent-2), var(--accent)); border-color: transparent; color: var(--accent-contrast); box-shadow: 0 6px 22px color-mix(in srgb, var(--accent) 45%, transparent); }
.tile.primary .ico { color: var(--accent-contrast); }
.tile.primary .tile-label { font-weight: 700; }
.tile-label { font-size: 1.05rem; font-weight: 600; }

/* Select + storage */
.select { width: 100%; min-height: var(--tap); font-size: 1.05rem; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: .7rem .8rem; }
.storage-row { display: flex; gap: .5rem; align-items: stretch; }
.storage-row .select { flex: 1; }
.storage-chip { display: inline-flex; align-items: center; gap: .25rem; margin-top: .3rem;
  font-size: .78rem; color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent); padding: .12rem .5rem; border-radius: 999px; width: fit-content; }
.storage-chip .ico svg { display: block; }

/* Box meta (history) */
.meta-card { display: grid; gap: .1rem; }
.meta-line { display: flex; justify-content: space-between; align-items: center; gap: .8rem; padding: .5rem 0; border-bottom: 1px solid var(--border); }
.meta-line:last-child { border-bottom: none; }
.meta-label { display: inline-flex; align-items: center; gap: .4rem; color: var(--muted); font-size: .9rem; }
.meta-value { font-size: .9rem; text-align: right; }

/* Statistics */
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .7rem; margin-bottom: 1rem; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: .9rem .6rem; text-align: center; }
.stat-ico { color: var(--accent); display: flex; justify-content: center; }
.stat-num { font-size: 1.6rem; font-weight: 800; margin-top: .2rem; }
.stat-label { font-size: .75rem; color: var(--muted); }

.chart { display: flex; align-items: flex-end; gap: 3px; height: 120px; padding-top: .5rem; }
.chart-col { flex: 1; display: flex; align-items: flex-end; height: 100%; min-width: 4px; }
.chart .bar { width: 100%; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 2px; position: relative; display: flex; align-items: flex-start; }
.chart .bar-views { width: 100%; background: var(--ok); border-radius: 3px 3px 0 0; }
.chart-legend { display: flex; gap: 1rem; justify-content: center; margin-top: .6rem; font-size: .78rem; color: var(--muted); }
.chart-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: .3rem; vertical-align: middle; }
.chart-legend .sw-reg { background: var(--accent); }
.chart-legend .sw-view { background: var(--ok); }

.hbar-row { display: grid; grid-template-columns: 1fr 2fr auto; align-items: center; gap: .6rem; padding: .35rem 0; }
.hbar-label { font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-track { background: var(--surface-2); border-radius: 999px; height: 12px; overflow: hidden; }
.hbar-fill { height: 100%; background: var(--accent); border-radius: 999px; min-width: 4px; }
.hbar-val { font-size: .8rem; color: var(--muted); white-space: nowrap; }

/* Theme toggle */
.theme-toggle { display: flex; align-items: center; justify-content: center; margin-top: 2rem; }
.seg { min-height: 40px; padding: .4rem 1.1rem; border: 1px solid var(--border); background: var(--surface);
  color: var(--muted); cursor: pointer; font-size: .95rem; }
.seg:first-of-type { border-radius: 10px 0 0 10px; }
.seg:last-of-type { border-radius: 0 10px 10px 0; border-left: none; }
.seg.active { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); }

/* Auth */
.auth-card { max-width: 360px; margin: 8vh auto 0; }
.auth-logo { display: flex; justify-content: center; color: var(--accent); margin-bottom: .3rem; }
.check { display: flex; align-items: center; gap: .5rem; color: var(--text); }
.check input { width: auto; min-height: auto; }

/* Users */
.user-row { display: flex; align-items: center; justify-content: space-between; gap: .8rem; padding: .7rem 0; border-bottom: 1px solid var(--border); }
.user-row:last-child { border-bottom: none; }

/* Bottom sheet modal */
.modal.sheet { justify-content: center; align-items: center; background: rgba(0,0,0,.6); }
.sheet-card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 1.2rem; width: 100%; max-width: 420px; }
.sheet-card .controls { display: flex; gap: .6rem; margin-top: 1rem; }
.sheet-card .controls .btn { flex: 1; }

/* Cards / list */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem;
  box-shadow: var(--shadow);
}
.card h3 { margin: 0 0 .7rem; font-size: 1rem; }
.list { display: grid; gap: .6rem; }
.row {
  display: flex; align-items: center; gap: .8rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .9rem 1rem; cursor: pointer;
  text-decoration: none; color: inherit;
}
.row:active { background: var(--surface-2); }
.row .code {
  font-family: ui-monospace, Menlo, Consolas, monospace; font-weight: 700;
  font-size: 1.15rem; letter-spacing: 1px;
  background: var(--surface-2); padding: .3rem .55rem; border-radius: 8px;
}
.row .meta { flex: 1; min-width: 0; }
.row .meta .preview { color: var(--muted); font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .count { color: var(--muted); font-size: .85rem; }

/* Forms */
label { display: block; font-size: .85rem; color: var(--muted); margin: .8rem 0 .3rem; }
input, textarea {
  width: 100%; font-size: 1.05rem; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; padding: .8rem; min-height: var(--tap);
}
input:focus, textarea:focus { outline: 2px solid var(--accent); }
textarea { min-height: 80px; resize: vertical; }

.item-edit { display: grid; grid-template-columns: 1fr auto auto auto; gap: .5rem; align-items: start; }
.item-edit input { min-height: 46px; }

/* Quantity stepper */
.stepper { display: flex; align-items: stretch; }
.stepper .step { width: 36px; min-height: 46px; border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text); font-size: 1.4rem; line-height: 1; cursor: pointer; padding: 0; }
.stepper .step:first-child { border-radius: 10px 0 0 10px; }
.stepper .step:last-child { border-radius: 0 10px 10px 0; }
.stepper .step:active { background: var(--accent); color: var(--accent-contrast); }
.stepper .qty { width: 46px; min-height: 46px; text-align: center; border-radius: 0; border-left: none; border-right: none;
  padding: 0; -moz-appearance: textfield; appearance: textfield; }
.stepper .qty::-webkit-outer-spin-button, .stepper .qty::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.item-edit .del { background: transparent; border: 1px solid var(--border); color: var(--danger); border-radius: 10px; min-height: 46px; min-width: 46px; font-size: 1.2rem; cursor: pointer; }
.item-edit .note-btn { display: inline-flex; align-items: center; justify-content: center; background: transparent; border: 1px solid var(--border); color: var(--muted); border-radius: 10px; min-height: 46px; min-width: 46px; cursor: pointer; }
.item-edit .note-btn.active { color: var(--accent-contrast); background: var(--accent); border-color: var(--accent); }
.note-wrap { margin-top: .4rem; }

.item-view { display: flex; justify-content: space-between; gap: .8rem; padding: .6rem 0; border-bottom: 1px solid var(--border); }
.item-view:last-child { border-bottom: none; }
.item-view .qty-badge { color: var(--muted); }
.item-view .notes { color: var(--muted); font-size: .85rem; }

/* Media grid */
.media-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
.media-tile { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--surface-2); border: 1px solid var(--border); }
.media-tile img, .media-tile video { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-tile .badge { position: absolute; left: 4px; bottom: 4px; background: rgba(0,0,0,.6); color: #fff; font-size: .7rem; padding: 1px 5px; border-radius: 6px; }
.media-tile .del { position: absolute; top: 4px; right: 4px; width: 30px; height: 30px; border-radius: 50%; border: none; background: rgba(0,0,0,.6); color: #fff; font-size: 1rem; cursor: pointer; }

/* Scan */
.scan-wrap { position: relative; border-radius: var(--radius); overflow: hidden; background: #000; aspect-ratio: 3/4; max-height: 60vh; }
.scan-wrap video { width: 100%; height: 100%; object-fit: cover; }
.roi { position: absolute; inset: 18% 12%; border: 3px solid rgba(76,141,255,.9); border-radius: 12px; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); pointer-events: none; }
.scan-status { text-align: center; color: var(--muted); margin: .6rem 0; min-height: 1.2em; }

.ocr-preview { margin-top: .7rem; padding: .5rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; text-align: center; }
.ocr-preview canvas { background: #fff; }

/* Candidates */
.candidate { display: flex; align-items: center; gap: .7rem; }
.dist { color: var(--muted); font-size: .8rem; }

/* Lightbox */
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.92); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.lightbox img, .lightbox video { max-width: 100%; max-height: 90vh; border-radius: 8px; }
.lightbox .close { position: absolute; top: calc(.5rem + env(safe-area-inset-top)); right: .8rem; font-size: 2rem; color: #fff; background: none; border: none; cursor: pointer; }

/* Modal (camera capture / record) */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.95); z-index: 60; display: flex; flex-direction: column; padding: 1rem; padding-top: calc(1rem + env(safe-area-inset-top)); }
.modal video { width: 100%; flex: 1; min-height: 0; object-fit: contain; border-radius: 10px; background:#000; }
.modal .controls { display: flex; gap: .6rem; margin-top: .8rem; }
.modal .controls .btn { flex: 1; }

/* Misc */
.muted { color: var(--muted); }
.center { text-align: center; }
.empty { text-align: center; color: var(--muted); padding: 3rem 1rem; }
.error-box { background: rgba(255,90,90,.12); border: 1px solid var(--danger); color: #ffd2d2; border-radius: 10px; padding: .8rem; margin: .6rem 0; }
.code-big { font-family: ui-monospace, Menlo, monospace; font-size: 2rem; font-weight: 800; letter-spacing: 2px; text-align: center; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; margin: 2rem auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.rec-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--danger); display: inline-block; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(1.2rem + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
  padding: .7rem 1.1rem; border-radius: 999px; z-index: 80; max-width: 90%;
  box-shadow: 0 6px 24px rgba(0,0,0,.4);
}
.toast.err { border-color: var(--danger); color: #ffd2d2; }

/* WiFi coverage survey */
.wifi-map {
  height: 58vh; min-height: 320px; width: 100%;
  border-radius: 12px; overflow: hidden; margin: .6rem 0;
  border: 1px solid var(--border); background: var(--surface-2);
}
.wifi-hint { padding: .7rem .9rem; font-size: .85rem; }
.wifi-readout { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; min-height: 1.6rem; }
.wifi-live {
  display: inline-flex; align-items: center; font-weight: 700; color: #08130d;
  padding: .12rem .5rem; border-radius: 999px; font-size: .85rem;
}
.wifi-live.lost { background: #111; color: #ff5252; }
.wifi-mbps { font-weight: 800; font-size: 1.35rem; letter-spacing: .3px; }
.wifi-legend {
  display: flex; align-items: center; gap: .5rem; font-size: .78rem;
  margin: -.2rem 0 .4rem;
}
.wifi-legend-bar {
  flex: 1; height: 10px; border-radius: 999px;
  background: linear-gradient(to right, hsl(0,85%,45%), hsl(60,85%,45%), hsl(120,85%,45%));
}
.wifi-legend-lost { color: #ff5252; font-weight: 700; }
.wifi-dot {
  width: 14px; height: 14px; border-radius: 50%; flex: 0 0 auto;
  background: linear-gradient(135deg, hsl(120,85%,45%), hsl(0,85%,45%));
}
/* Leaflet router pin (emoji marker) */
.router-pin-inner {
  width: 34px; height: 34px; display: flex; align-items: center; justify-content: center;
  font-size: 20px; background: #fff; border: 2px solid #2f7bff;
  border-radius: 50%; box-shadow: 0 2px 8px rgba(0,0,0,.4);
}
/* Leaflet controls sit above the app's own z-indexed bits but below toasts */
.leaflet-container { z-index: 1; }
