/* ============================================================
   Tobacco Retail Manager — design system
   Apple-inspired: system fonts, restraint, depth, clarity.
   ============================================================ */

:root {
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;

  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-2: #fbfbfd;
  --text: #1d1d1f;
  --text-2: #6e6e73;
  --text-3: #86868b;
  --separator: rgba(0,0,0,.08);
  --accent: #0071e3;
  --accent-hover: #0077ed;
  --accent-tint: rgba(0,113,227,.10);
  --green: #34c759;
  --red: #ff3b30;
  --orange: #ff9500;
  --nav-bg: rgba(251,251,253,.8);
  --card-shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.05);
  --card-shadow-hover: 0 2px 4px rgba(0,0,0,.05), 0 10px 30px rgba(0,0,0,.09);
  --radius: 14px;
  --radius-sm: 10px;
  --nav-h: 52px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1c1c1e;
    --surface-2: #161617;
    --text: #f5f5f7;
    --text-2: #a1a1a6;
    --text-3: #6e6e73;
    --separator: rgba(255,255,255,.12);
    --accent: #2997ff;
    --accent-hover: #46a5ff;
    --accent-tint: rgba(41,151,255,.14);
    --nav-bg: rgba(22,22,23,.8);
    --card-shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.35);
    --card-shadow-hover: 0 2px 4px rgba(0,0,0,.4), 0 12px 32px rgba(0,0,0,.5);
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.47;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ---------- Navigation bar (frosted) ---------- */
.nav {
  position: sticky; top: 0; z-index: 50;
  height: var(--nav-h);
  display: flex; align-items: center; gap: 4px;
  padding: 0 max(16px, env(safe-area-inset-left));
  background: var(--nav-bg);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--separator);
}
.nav-brand {
  font-family: var(--font-display);
  font-weight: 700; font-size: 16px; letter-spacing: -.02em;
  margin-right: 18px; white-space: nowrap;
  background: none; border: 0; cursor: pointer;
}
.nav-links { display: flex; gap: 2px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.nav-links::-webkit-scrollbar { display: none; }
.nav-link {
  background: none; border: 0; cursor: pointer;
  padding: 7px 14px; border-radius: 99px;
  font-size: 13.5px; font-weight: 500; color: var(--text-2);
  white-space: nowrap;
  transition: background .18s, color .18s;
}
.nav-link:hover { color: var(--text); background: var(--separator); }
.nav-link.active { color: var(--accent); background: var(--accent-tint); font-weight: 600; }
.nav-right { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.nav-user { font-size: 12.5px; color: var(--text-3); white-space: nowrap; }

/* ---------- Layout ---------- */
.page { max-width: 1200px; margin: 0 auto; padding: 32px 20px 80px; }
.page-narrow { max-width: 760px; }
.page-wide { max-width: none; padding: 28px 28px 80px; }

.page-title {
  font-family: var(--font-display);
  font-size: clamp(28px, 5vw, 40px);
  font-weight: 700; letter-spacing: -.025em; line-height: 1.1;
  margin-bottom: 6px;
}
.page-sub { color: var(--text-2); font-size: 16px; margin-bottom: 28px; }

.section-title {
  font-family: var(--font-display);
  font-size: 21px; font-weight: 700; letter-spacing: -.02em;
  margin: 36px 0 14px;
}
.section-title:first-child { margin-top: 0; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
  padding: 20px;
}
.card + .card { margin-top: 16px; }
.card-click { cursor: pointer; transition: transform .22s cubic-bezier(.2,.8,.2,1), box-shadow .22s; }
.card-click:hover { transform: translateY(-2px); box-shadow: var(--card-shadow-hover); }

.grid { display: grid; gap: 16px; }
.grid-cards { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; cursor: pointer;
  background: var(--accent); color: #fff;
  padding: 9px 18px; border-radius: 99px;
  font-size: 14px; font-weight: 600;
  transition: background .18s, transform .1s, opacity .18s;
  white-space: nowrap;
}
.btn:hover { background: var(--accent-hover); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-secondary { background: var(--separator); color: var(--text); }
.btn-secondary:hover { background: rgba(0,0,0,.14); }
@media (prefers-color-scheme: dark) { .btn-secondary:hover { background: rgba(255,255,255,.2); } }
.btn-ghost { background: transparent; color: var(--accent); }
.btn-ghost:hover { background: var(--accent-tint); }
.btn-danger { background: var(--red); }
.btn-danger:hover { background: #e0342a; }
.btn-sm { padding: 5px 12px; font-size: 12.5px; }
.btn-icon { padding: 7px 10px; border-radius: 10px; background: transparent; color: var(--text-2); }
.btn-icon:hover { background: var(--separator); color: var(--text); }

/* ---------- Forms ---------- */
.field { margin-bottom: 16px; }
.field label {
  display: block; font-size: 12.5px; font-weight: 600;
  color: var(--text-2); margin-bottom: 6px;
  text-transform: uppercase; letter-spacing: .04em;
}
.inp, select.inp, textarea.inp {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--separator);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 15px;
  transition: border-color .18s, box-shadow .18s, background .18s;
}
.inp:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint); background: var(--surface); }
.inp-sm { padding: 6px 10px; font-size: 13.5px; border-radius: 8px; }
.inp-num { font-family: var(--mono); text-align: right; }
textarea.inp { resize: vertical; min-height: 70px; }
.hint { font-size: 12px; color: var(--text-3); margin-top: 5px; }
.err-text { color: var(--red); font-size: 13px; font-weight: 500; margin-top: 8px; }

/* checkbox rows (program → store assignment) */
.check-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border-radius: var(--radius-sm);
  cursor: pointer; transition: background .15s;
  border: 1px solid transparent;
}
.check-row:hover { background: var(--surface-2); }
.check-row.checked { background: var(--accent-tint); border-color: var(--accent); }
.check-row input { width: 18px; height: 18px; accent-color: var(--accent); flex-shrink: 0; }
.check-row .check-label { font-weight: 600; font-size: 14.5px; }
.check-row .check-sub { font-size: 12.5px; color: var(--text-3); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius); background: var(--surface); box-shadow: var(--card-shadow); }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th {
  text-align: left; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .05em; color: var(--text-3);
  padding: 12px 12px 8px; border-bottom: 1px solid var(--separator);
  position: sticky; top: 0; background: var(--surface); z-index: 1;
  white-space: nowrap;
}
.tbl td { padding: 7px 8px; border-bottom: 1px solid var(--separator); vertical-align: middle; }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tbody tr { transition: background .12s; }
.tbl tbody tr:hover { background: var(--surface-2); }
.tbl .num { font-family: var(--mono); text-align: right; font-size: 13px; white-space: nowrap; }
.tbl .brand-cell { font-weight: 600; white-space: nowrap; }
.tbl input.cell-inp {
  width: 62px; background: var(--surface-2);
  border: 1px solid var(--separator); border-radius: 7px;
  padding: 4px 8px; font-family: var(--mono); font-size: 12.5px; text-align: right;
}
.tbl input.cell-inp:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-tint); }
.cell-overridden { position: relative; }
.cell-overridden input.cell-inp { border-color: var(--orange); }

/* ---------- Chips / badges ---------- */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 10px; border-radius: 99px;
  font-size: 11.5px; font-weight: 600;
  background: var(--separator); color: var(--text-2);
  white-space: nowrap;
}
.badge-accent { background: var(--accent-tint); color: var(--accent); }
.badge-green  { background: rgba(52,199,89,.14); color: var(--green); }
.badge-red    { background: rgba(255,59,48,.14); color: var(--red); }
.badge-orange { background: rgba(255,149,0,.14); color: var(--orange); }

.seg {
  display: inline-flex; background: var(--separator);
  border-radius: 99px; padding: 3px; gap: 2px;
}
.seg button {
  border: 0; background: transparent; cursor: pointer;
  padding: 6px 16px; border-radius: 99px;
  font-size: 13px; font-weight: 600; color: var(--text-2);
  transition: background .18s, color .18s, box-shadow .18s;
}
.seg button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.12); }

/* ---------- Modal ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,.4);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  animation: fadeIn .2s ease;
}
.modal {
  background: var(--surface);
  border-radius: 18px;
  box-shadow: 0 24px 80px rgba(0,0,0,.35);
  width: 100%; max-width: 480px;
  max-height: min(86dvh, 780px);
  display: flex; flex-direction: column;
  animation: popIn .28s cubic-bezier(.2,.9,.3,1.2);
}
.modal-lg { max-width: 720px; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px 0;
}
.modal-title { font-family: var(--font-display); font-size: 19px; font-weight: 700; letter-spacing: -.02em; }
.modal-body { padding: 16px 22px; overflow-y: auto; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 14px 22px 20px;
  border-top: 1px solid var(--separator);
}
.modal-close {
  border: 0; background: var(--separator); color: var(--text-2);
  width: 28px; height: 28px; border-radius: 50%;
  cursor: pointer; font-size: 15px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}
.modal-close:hover { background: rgba(0,0,0,.16); }

@keyframes fadeIn { from { opacity: 0; } }
@keyframes popIn { from { opacity: 0; transform: scale(.94) translateY(8px); } }

/* ---------- Toast ---------- */
#toast-root { position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  background: var(--text); color: var(--bg);
  padding: 10px 20px; border-radius: 99px;
  font-size: 13.5px; font-weight: 600;
  box-shadow: 0 8px 30px rgba(0,0,0,.25);
  animation: toastIn .3s cubic-bezier(.2,.9,.3,1.2);
}
.toast.out { animation: toastOut .25s ease forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px) scale(.9); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(8px) scale(.95); } }

/* ---------- Login ---------- */
.auth-wrap {
  min-height: 100dvh; display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.auth-card {
  width: 100%; max-width: 400px;
  background: var(--surface);
  border-radius: 22px;
  box-shadow: var(--card-shadow-hover);
  padding: 40px 34px;
  animation: popIn .4s cubic-bezier(.2,.9,.3,1.1);
}
.auth-logo { font-size: 40px; text-align: center; margin-bottom: 10px; }
.auth-title {
  font-family: var(--font-display);
  font-size: 24px; font-weight: 700; letter-spacing: -.02em;
  text-align: center; margin-bottom: 4px;
}
.auth-sub { text-align: center; color: var(--text-2); font-size: 14px; margin-bottom: 26px; }
.auth-card .btn { width: 100%; padding: 12px; font-size: 15px; margin-top: 6px; }

/* ---------- Store / program cards ---------- */
.entity-card { display: flex; flex-direction: column; gap: 6px; }
.entity-card .entity-name { font-family: var(--font-display); font-size: 17px; font-weight: 700; letter-spacing: -.015em; }
.entity-card .entity-meta { font-size: 12.5px; color: var(--text-3); }
.entity-card .entity-badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.entity-actions { display: flex; gap: 6px; margin-top: 10px; }

/* manufacturer tabs */
.mfr-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.mfr-tab {
  border: 1px solid var(--separator); background: var(--surface);
  padding: 8px 18px; border-radius: 99px; cursor: pointer;
  font-size: 13.5px; font-weight: 600; color: var(--text-2);
  transition: all .18s;
}
.mfr-tab.active { color: #fff; border-color: transparent; }

/* item grid (brand page) */
.item-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }
.item-card { display: flex; flex-direction: column; overflow: hidden; padding: 0; }
.item-img {
  aspect-ratio: 1; background: var(--surface-2);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-3); font-size: 34px;
}
.item-img img { width: 100%; height: 100%; object-fit: contain; }
.item-body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 5px; }
.item-name { font-size: 13.5px; font-weight: 600; line-height: 1.3; }
.item-upc { font-family: var(--mono); font-size: 11px; color: var(--text-3); }
.item-card.not-sold { opacity: .45; }
.item-card .barcode { padding: 4px 8px; background: #fff; border-radius: 6px; }

/* stats row */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 24px; }
.stat { background: var(--surface); border-radius: var(--radius); box-shadow: var(--card-shadow); padding: 16px 18px; }
.stat .stat-val { font-family: var(--font-display); font-size: 26px; font-weight: 700; letter-spacing: -.02em; }
.stat .stat-label { font-size: 12px; color: var(--text-3); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; margin-top: 2px; }

/* trend chart */
.chart-box { background: var(--surface); border-radius: var(--radius); box-shadow: var(--card-shadow); padding: 18px; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.legend-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 12px; border-radius: 99px; cursor: pointer;
  font-size: 12px; font-weight: 600;
  background: var(--surface-2); border: 1px solid var(--separator); color: var(--text-2);
}
.legend-pill.on { color: var(--text); border-color: currentColor; }
.legend-dot { width: 8px; height: 8px; border-radius: 50%; }

/* program detail layout: table + store panel side by side, stacked on mobile */
.program-layout { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr) 300px; align-items: start; }
@media (max-width: 900px) { .program-layout { grid-template-columns: 1fr; } }

/* utility */
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.muted { color: var(--text-3); font-size: 13px; }
.mt-8 { margin-top: 8px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; }
.mb-16 { margin-bottom: 16px; }
.empty {
  text-align: center; color: var(--text-3); padding: 48px 20px;
  font-size: 14.5px;
}
.empty .empty-icon { font-size: 40px; margin-bottom: 10px; }

.spinner {
  width: 28px; height: 28px; margin: 60px auto;
  border: 3px solid var(--separator); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* print (reports) */
@media print {
  .nav, .no-print { display: none !important; }
  body { background: #fff; color: #000; }
  .page { padding: 0; max-width: none; }
  .card, .table-wrap { box-shadow: none; border: 1px solid #ddd; }
}

@media (max-width: 640px) {
  .page { padding: 22px 14px 70px; }
  .nav-user { display: none; }
}
