/* ZonStockCount - Styles
 * Mobile-first, with a focus on outdoor / warehouse usage:
 *   - Large tap targets
 *   - High-contrast text
 *   - Dark mode for night / dim warehouses
 *   - No reliance on color alone for meaning
 */

/* ===================
   Tokens
   =================== */
:root {
  --brand-50:  #f0fdfa;
  --brand-100: #ccfbf1;
  --brand-300: #5eead4;
  --brand-500: #14b8a6;
  --brand-600: #0d9488;
  --brand-700: #0f766e;
  --brand-800: #115e59;
  --brand-900: #134e4a;

  --amber-300: #fcd34d;
  --amber-500: #f59e0b;
  --amber-600: #d97706;

  --green-500: #22c55e;
  --green-600: #16a34a;

  --red-500:   #ef4444;
  --red-600:   #dc2626;

  --slate-50:  #f8fafc;
  --slate-100: #f1f5f9;
  --slate-200: #e2e8f0;
  --slate-300: #cbd5e1;
  --slate-400: #94a3b8;
  --slate-500: #64748b;
  --slate-600: #475569;
  --slate-700: #334155;
  --slate-800: #1e293b;
  --slate-900: #0f172a;

  --bg:        #f8fafc;
  --surface:   #ffffff;
  --surface-2: #f1f5f9;
  --text:      #0f172a;
  --text-2:    #475569;
  --text-3:    #94a3b8;
  --border:    #e2e8f0;
  --border-strong: #cbd5e1;
  --shadow:    0 1px 2px rgba(15, 23, 42, .04), 0 4px 12px rgba(15, 23, 42, .06);
  --shadow-lg: 0 8px 30px rgba(15, 23, 42, .12);

  --radius:    14px;
  --radius-sm: 10px;
  --radius-lg: 20px;
  --gap:       12px;

  --appbar-h:  56px;
  --tabbar-h:  64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top:    env(safe-area-inset-top, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #0b1220;
    --surface:   #111a2e;
    --surface-2: #1a2542;
    --text:      #e2e8f0;
    --text-2:    #94a3b8;
    --text-3:    #64748b;
    --border:    #1f2a44;
    --border-strong: #2c3a5c;
    --shadow:    0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, .55);
  }
}

/* ===================
   Reset / base
   =================== */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "SF Pro Display",
               Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  font-size: 15px;
  line-height: 1.4;
  color: var(--text);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}
body.no-scroll { overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; color: inherit; }
a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
h1, h2, h3, h4, p { margin: 0; }

/* ===================
   Splash
   =================== */
.splash {
  position: fixed; inset: 0;
  background: linear-gradient(180deg, var(--brand-700), var(--brand-900));
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  z-index: 100;
  transition: opacity .3s ease, visibility .3s ease;
  padding: 24px;
}
.splash--hide { opacity: 0; visibility: hidden; }
.splash__art {
  width: min(70vw, 320px);
  height: auto;
  border-radius: 24px;
  box-shadow: 0 12px 40px rgba(0,0,0,.35);
  background: rgba(255,255,255,.05);
}
.splash__caption { text-align: center; color: #fff; margin-top: 28px; }
.splash__title { font-size: 24px; font-weight: 700; letter-spacing: -.02em; }
.splash__subtitle { color: var(--brand-100); margin-top: 6px; font-size: 14px; }

/* ===================
   App shell
   =================== */
.app { min-height: 100%; display: flex; flex-direction: column; opacity: 0; transition: opacity .25s ease; }
.app--in { opacity: 1; }

.appbar {
  position: sticky; top: 0; z-index: 30;
  height: calc(var(--appbar-h) + var(--safe-top));
  padding-top: var(--safe-top);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 4px;
  padding-left: 4px; padding-right: 8px;
}
.appbar__back {
  width: 40px; height: 40px; display: grid; place-items: center;
  border-radius: 10px; color: var(--text);
}
.appbar__back:active { background: var(--surface-2); }
.appbar__title {
  font-size: 17px; font-weight: 600;
  flex: 1; padding-left: 4px; padding-right: 4px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.appbar__actions { display: flex; align-items: center; gap: 4px; }
.appbar__actions-row { display: flex; gap: 4px; }

.content {
  flex: 1;
  padding: 16px;
  padding-bottom: calc(16px + var(--tabbar-h) + var(--safe-bottom));
  max-width: 720px; width: 100%; margin: 0 auto;
}
body.no-tabbar .content { padding-bottom: calc(16px + var(--safe-bottom)); }

/* Tabbar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: grid; grid-template-columns: repeat(3, 1fr);
  z-index: 20;
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  font-size: 11px; font-weight: 500;
  color: var(--text-3);
  text-decoration: none;
  position: relative;
}
.tab__scan {
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--brand-700); color: #fff;
  display: grid; place-items: center;
  margin-top: -20px;
  box-shadow: 0 6px 20px rgba(15, 118, 110, .35);
  transition: transform .15s ease;
}
.tab--active .tab__scan { transform: scale(1.05); }
.tab--active { color: var(--brand-700); }
.tab--active:not(.tab--scan) { color: var(--brand-700); }
.tab:active { opacity: .7; }

/* ===================
   Buttons
   =================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 8px;
  height: 44px; padding: 0 18px;
  border-radius: 12px;
  font-size: 15px; font-weight: 600;
  background: var(--surface-2);
  color: var(--text);
  transition: transform .08s ease, background .15s ease, color .15s ease;
  user-select: none;
  white-space: nowrap;
}
.btn:active { transform: scale(.98); }
.btn--primary { background: var(--brand-700); color: #fff; }
.btn--primary:active { background: var(--brand-800); }
.btn--ghost { background: transparent; color: var(--text-2); }
.btn--ghost:active { background: var(--surface-2); color: var(--text); }
.btn--danger { background: var(--red-600); color: #fff; }
.btn--danger:active { background: #b91c1c; }
.btn--sm { height: 36px; padding: 0 12px; font-size: 13px; border-radius: 10px; gap: 6px; }
.btn--lg { height: 52px; padding: 0 24px; font-size: 16px; border-radius: 14px; }

.iconbtn {
  width: 40px; height: 40px; display: grid; place-items: center;
  border-radius: 10px;
  color: var(--text-2);
  transition: background .15s ease;
}
.iconbtn:active { background: var(--surface-2); }
.iconbtn--sm { width: 32px; height: 32px; border-radius: 8px; }
.iconbtn--danger { color: var(--red-600); }
.icon { display: inline-flex; width: 1em; height: 1em; line-height: 0; }
.icon svg { width: 100%; height: 100%; }

/* ===================
   Empty state
   =================== */
.empty {
  text-align: center;
  padding: 60px 20px;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  color: var(--text-2);
}
.empty__art { color: var(--text-3); width: 64px; height: 64px; opacity: .8; }
.empty h2 { font-size: 18px; font-weight: 600; color: var(--text); }
.empty p { max-width: 320px; font-size: 14px; }

/* ===================
   Sessions list
   =================== */
.session-list { display: flex; flex-direction: column; gap: 10px; }
.session-card {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  text-decoration: none;
  color: inherit;
  box-shadow: var(--shadow);
  transition: transform .08s ease, box-shadow .15s ease;
}
.session-card:active { transform: scale(.99); }
.session-card__main { min-width: 0; }
.session-card__name {
  font-size: 15px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.session-card__meta {
  font-size: 12px; color: var(--text-3); margin-top: 4px;
}
.session-card__stats {
  display: flex; gap: 12px; align-items: center;
}
.session-card__stat { text-align: center; }
.session-card__stat-num { font-size: 20px; font-weight: 700; line-height: 1; color: var(--brand-700); }
.session-card__stat-label { font-size: 10px; color: var(--text-3); text-transform: uppercase; letter-spacing: .04em; margin-top: 2px; }
.session-card__scan { grid-column: 1 / -1; }

/* ===================
   Scan view
   =================== */
.scan { display: flex; flex-direction: column; gap: 12px; }

.scan__header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.scan__name {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface-2);
  border-radius: 10px;
  padding: 8px 12px;
  font-weight: 600; font-size: 14px;
  max-width: 70%;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.scan__name .icon { color: var(--text-3); }
.scan__name-label { overflow: hidden; text-overflow: ellipsis; }
.scan__header-meta { font-size: 12px; color: var(--text-3); }

.scan__cam {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.scan__video {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; background: #000;
}
.scan__overlay {
  position: absolute; inset: 0;
  pointer-events: none;
  transition: box-shadow .25s ease;
}
.scan__overlay.flash-ok   { box-shadow: inset 0 0 0 4px var(--green-500); }
.scan__overlay.flash-muted { box-shadow: inset 0 0 0 4px var(--slate-400); }
.scan__overlay.flash-err  { box-shadow: inset 0 0 0 4px var(--red-500); }

.viewfinder {
  position: absolute;
  border: 2px solid rgba(255,255,255,.7);
  border-radius: 12px;
  box-shadow: 0 0 0 2000px rgba(0,0,0,.35);
  pointer-events: none;
}
.viewfinder::before, .viewfinder::after,
.viewfinder > .viewfinder__line { content: ''; }
.viewfinder__line {
  position: absolute; left: 8%; right: 8%; top: 0;
  height: 2px;
  background: var(--amber-500);
  box-shadow: 0 0 10px rgba(245, 158, 11, .7);
  animation: scanline 1.8s ease-in-out infinite;
}
@keyframes scanline {
  0%   { top: 4%; }
  50%  { top: calc(100% - 6px); }
  100% { top: 4%; }
}

.scan__error {
  position: absolute; inset: 0;
  background: rgba(0,0,0,.78);
  color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 24px; gap: 12px;
  z-index: 5;
}
.scan__error-title { font-size: 18px; font-weight: 600; }
.scan__error-body { color: rgba(255,255,255,.8); max-width: 320px; }
.scan__error-actions { display: flex; gap: 8px; }

.scan__controls { display: flex; gap: 8px; justify-content: center; }

.scan__status {
  align-self: center;
  padding: 4px 12px; border-radius: 999px;
  font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em;
  background: var(--surface-2); color: var(--text-2);
}
.scan__status--ok   { background: rgba(22, 163, 74, .15); color: var(--green-600); }
.scan__status--warn { background: rgba(245, 158, 11, .15); color: var(--amber-600); }
.scan__status--err  { background: rgba(220, 38, 38, .15); color: var(--red-600); }
.scan__status--idle { background: var(--surface-2); color: var(--text-3); }

.scan__last {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  min-height: 64px;
  display: flex; align-items: center;
}
.scan__last-empty { color: var(--text-3); font-size: 14px; }
.scan__last-inner { width: 100%; }
.scan__last-label { font-size: 11px; color: var(--text-3); text-transform: uppercase; letter-spacing: .05em; }
.scan__last-code {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 18px; font-weight: 600;
  margin: 4px 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.scan__last-meta { display: flex; gap: 6px; flex-wrap: wrap; }

.badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 11px; font-weight: 600;
  border-radius: 999px;
  letter-spacing: .02em;
}
.badge--count { background: var(--brand-700); color: #fff; }

.scan__list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-height: 280px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.scan__list-empty { padding: 20px; text-align: center; color: var(--text-3); font-size: 13px; }
.scan__row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  font-size: 14px;
}
.scan__row:first-child { border-top: 0; }
.scan__row-code {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  flex: 1; min-width: 0; padding-right: 12px;
}
.scan__row-count { font-weight: 700; color: var(--brand-700); }
.scan__list-more {
  padding: 10px 14px; text-align: center;
  color: var(--text-3); font-size: 12px;
  border-top: 1px solid var(--border);
}

.scan__total {
  position: sticky; bottom: calc(8px + var(--safe-bottom));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 16px;
}
.scan__total-inner {
  display: flex; align-items: center; gap: 16px;
}
.scan__total-inner > div { flex: 1; }
.scan__total-num { font-size: 22px; font-weight: 700; line-height: 1; color: var(--brand-700); }
.scan__total-label { font-size: 11px; color: var(--text-3); text-transform: uppercase; letter-spacing: .04em; }

/* ===================
   Session detail
   =================== */
.detail__header { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.detail__name {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 20px; font-weight: 700;
  text-align: left;
  color: var(--text);
  padding: 0;
}
.detail__name .icon { color: var(--text-3); }
.detail__meta { font-size: 12px; color: var(--text-3); }
.detail__stats {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 10px; margin-bottom: 14px;
}
.detail__stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
}
.detail__stat-num { font-size: 28px; font-weight: 700; color: var(--brand-700); line-height: 1; }
.detail__stat-label { font-size: 11px; color: var(--text-3); text-transform: uppercase; letter-spacing: .04em; margin-top: 4px; }

.detail__toolbar { display: flex; justify-content: flex-end; margin-bottom: 8px; }
.input--inline { height: 36px; padding: 0 10px; border-radius: 10px; font-size: 13px; }

.detail__list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.detail__row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: flex; align-items: center; gap: 8px;
}
.detail__row-info { flex: 1; min-width: 0; }
.detail__row-code {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.detail__row-meta {
  display: flex; gap: 6px; flex-wrap: wrap; align-items: center;
  font-size: 11px; color: var(--text-3); margin-top: 4px;
}
.detail__row-time { color: var(--text-3); }
.detail__row-count {
  display: flex; align-items: center; gap: 4px;
}
.detail__row-num {
  min-width: 32px; text-align: center;
  font-size: 16px; font-weight: 700; color: var(--brand-700);
}

.detail__footer {
  display: flex; gap: 8px; justify-content: space-between;
  padding: 12px 0;
  border-top: 1px solid var(--border);
}

/* ===================
   Settings
   =================== */
.settings { display: flex; flex-direction: column; gap: 8px; }
.section-title {
  font-size: 12px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-3);
  margin: 18px 4px 4px;
  font-weight: 600;
}
.settings__row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  min-height: 56px;
}
.settings__row--col { flex-direction: column; align-items: stretch; }
.settings__row--check { cursor: pointer; }
.settings__row-text { flex: 1; min-width: 0; }
.settings__row-title { font-size: 15px; font-weight: 600; }
.settings__row-sub { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.settings__row-value {
  font-size: 13px; color: var(--text-2);
  min-width: 64px; text-align: right;
  font-variant-numeric: tabular-nums;
}

.settings__seg {
  display: inline-flex; background: var(--surface-2);
  padding: 3px; border-radius: 10px;
}
.settings__seg-btn {
  padding: 6px 12px; border-radius: 8px;
  font-size: 13px; font-weight: 600; color: var(--text-2);
  transition: background .15s ease, color .15s ease;
}
.settings__seg-btn--on {
  background: var(--brand-700); color: #fff;
}

.settings__range-row { display: flex; align-items: center; gap: 12px; margin-top: 8px; }
.settings__range { flex: 1; accent-color: var(--brand-700); }

.settings__bulk { display: flex; gap: 8px; padding: 4px 0; }

.settings__formats { display: flex; flex-direction: column; gap: 6px; }
.settings__group-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-3); margin: 10px 4px 4px;
}

.settings__about {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}
.settings__about-title { font-size: 16px; font-weight: 700; }
.settings__about-sub { font-size: 12px; color: var(--text-3); margin-top: 4px; }

/* Toggle */
.toggle { position: relative; display: inline-block; width: 44px; height: 26px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle__slider {
  position: absolute; inset: 0;
  background: var(--slate-300);
  border-radius: 999px;
  transition: background .2s ease;
}
.toggle__slider::before {
  content: ''; position: absolute;
  width: 20px; height: 20px;
  left: 3px; top: 3px;
  background: #fff; border-radius: 50%;
  transition: transform .2s ease;
  box-shadow: 0 1px 2px rgba(0,0,0,.2);
}
.toggle input:checked + .toggle__slider { background: var(--brand-700); }
.toggle input:checked + .toggle__slider::before { transform: translateX(18px); }
@media (prefers-color-scheme: dark) {
  .toggle__slider { background: var(--slate-700); }
}

/* ===================
   Inputs
   =================== */
.input {
  height: 44px; padding: 0 14px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  border-radius: 12px;
  font-size: 15px;
  width: 100%;
  outline: none;
}
.input:focus { border-color: var(--brand-600); box-shadow: 0 0 0 3px rgba(20, 184, 166, .25); }

/* ===================
   Modal
   =================== */
.modal-root {
  position: fixed; inset: 0;
  z-index: 50;
  display: flex; align-items: center; justify-content: center;
}
.modal__backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,.55);
  display: flex; align-items: flex-end; justify-content: center;
  opacity: 0; transition: opacity .2s ease;
}
.modal__backdrop--in { opacity: 1; }
.modal__sheet {
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  width: 100%; max-width: 480px;
  padding: 22px 20px 24px;
  box-shadow: 0 -8px 30px rgba(0,0,0,.25);
  transform: translateY(20px);
  transition: transform .2s ease;
  max-height: 90vh; overflow-y: auto;
}
@media (min-width: 600px) {
  .modal__backdrop { align-items: center; }
  .modal__sheet { border-radius: 20px; transform: translateY(0) scale(.96); }
  .modal__backdrop--in .modal__sheet { transform: translateY(0) scale(1); }
}
.modal__title { font-size: 17px; font-weight: 700; margin-bottom: 6px; }
.modal__body { color: var(--text-2); margin-bottom: 16px; font-size: 14px; }
.modal__field { margin-bottom: 16px; }
.modal__actions {
  display: flex; gap: 10px; justify-content: flex-end;
  padding-top: 8px;
}
.modal__actions .btn { flex: 1; max-width: 200px; }

/* ===================
   Toasts
   =================== */
.toast-root {
  position: fixed; left: 0; right: 0; top: calc(var(--appbar-h) + var(--safe-top) + 12px);
  display: flex; flex-direction: column; align-items: center;
  z-index: 60; pointer-events: none;
  padding: 0 16px;
}
.toast {
  pointer-events: auto;
  background: var(--slate-900);
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 14px;
  margin-top: 6px;
  box-shadow: var(--shadow-lg);
  opacity: 0; transform: translateY(-8px);
  transition: opacity .2s ease, transform .2s ease;
  max-width: 360px;
  text-align: center;
}
.toast--in   { opacity: 1; transform: translateY(0); }
.toast--out  { opacity: 0; transform: translateY(-8px); }
.toast--success { background: var(--green-600); }
.toast--error   { background: var(--red-600); }
@media (prefers-color-scheme: dark) {
  .toast { background: var(--slate-700); }
}

/* ===================
   Utility
   =================== */
[hidden] { display: none !important; }

/* ===================
   Small screens
   =================== */
@media (max-width: 380px) {
  .session-card { grid-template-columns: 1fr; }
  .session-card__stats { justify-content: flex-start; }
  .btn--lg { height: 48px; }
}

/* ===================
   Reduced motion
   =================== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0s !important;
    transition-duration: 0s !important;
  }
}
