/* ==========================================================================
   POB Tracker — Design tokens
   ========================================================================== */
:root {
  --ink: #1A1330;
  --muted: #6B6478;
  --paper: #F8F6FC;
  --surface: #FFFFFF;
  --line: #E9E1F7;

  --brand: #7C3AED;
  --brand-dark: #5B21B6;
  --brand-soft: #F1E8FE;
  --accent-pink: #EC4899;
  --accent-pink-soft: #FCE7F3;

  --good: #16A34A;
  --good-soft: #DCFCE7;
  --warn: #D97706;
  --warn-soft: #FEF3C7;
  --bad: #DC2626;
  --bad-soft: #FEE2E2;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 32, 0.06), 0 1px 1px rgba(15, 23, 32, 0.04);
  --shadow-md: 0 8px 24px rgba(15, 23, 32, 0.08);

  --font-display: 'Sora', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;

  --topbar-h: 60px;
  --bottomnav-h: 64px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--paper);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
h1, h2, h3, h4 { font-family: var(--font-display); margin: 0; letter-spacing: -0.01em; }
p { margin: 0; }
button { font-family: inherit; }
a { color: var(--brand); }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }
::selection { background: var(--brand-soft); }

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* ==========================================================================
   Login screen
   ========================================================================== */
#login-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 24px 20px;
  background:
    radial-gradient(1200px 600px at 15% -10%, #3B1660 0%, transparent 60%),
    radial-gradient(900px 500px at 100% 110%, #4A0E3D 0%, transparent 55%),
    linear-gradient(180deg, var(--ink) 0%, #241640 55%, var(--ink) 100%);
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 32px 28px;
}
.login-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 24px;
}
.login-brand .mark {
  width: 38px; height: 38px; border-radius: 10px;
  background: linear-gradient(135deg, var(--brand), var(--accent-pink));
  display: flex; align-items: center; justify-content: center;
  color: white; font-family: var(--font-display); font-weight: 700;
}
.login-brand .name { font-family: var(--font-display); font-weight: 700; font-size: 1.15rem; }
.login-brand .tag { font-size: 0.72rem; color: var(--muted); }

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 0.82rem; font-weight: 600; margin-bottom: 6px; color: var(--ink); }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: inherit;
  background: var(--surface);
  color: var(--ink);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
.field .hint { font-size: 0.76rem; color: var(--muted); margin-top: 4px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.92rem;
  border: 1.5px solid transparent;
  cursor: pointer;
  transition: transform .08s ease, background .15s ease, border-color .15s ease;
  white-space: nowrap;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--brand); color: white; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { border-color: var(--brand); color: var(--brand); }
.btn-danger { background: var(--bad); color: white; }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 12px; font-size: 0.82rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.error-msg { background: var(--bad-soft); color: var(--bad); padding: 10px 12px; border-radius: var(--radius-sm); font-size: 0.85rem; margin-bottom: 14px; }
.success-msg { background: var(--good-soft); color: var(--good); padding: 10px 12px; border-radius: var(--radius-sm); font-size: 0.85rem; margin-bottom: 14px; }
.info-msg { background: var(--brand-soft); color: var(--brand-dark); padding: 10px 12px; border-radius: var(--radius-sm); font-size: 0.85rem; margin-bottom: 14px; }

/* ==========================================================================
   App shell
   ========================================================================== */
#app-shell { display: none; min-height: 100vh; }
#app-shell.active { display: block; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
}
.topbar .brand { display: flex; align-items: center; gap: 10px; }
.topbar .brand .mark {
  width: 30px; height: 30px; border-radius: 8px;
  background: linear-gradient(135deg, var(--brand), var(--accent-pink));
  color: white; display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-weight: 700; font-size: 0.9rem;
}
.topbar .brand .name { font-family: var(--font-display); font-weight: 700; font-size: 1rem; }
.topbar-actions { display: flex; align-items: center; gap: 6px; }

.icon-btn {
  position: relative;
  width: 38px; height: 38px; border-radius: 10px;
  border: none; background: transparent; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--ink);
}
.icon-btn:hover { background: var(--paper); }
.badge-dot {
  position: absolute; top: 4px; right: 4px;
  min-width: 16px; height: 16px; padding: 0 3px; border-radius: 999px;
  background: var(--bad); color: white; font-size: 0.62rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}

.demo-banner {
  background: var(--warn-soft); color: var(--warn); text-align: center;
  font-size: 0.76rem; padding: 6px 10px; font-weight: 600;
}

main.content { padding: 16px 16px calc(var(--bottomnav-h) + 24px); max-width: 1100px; margin: 0 auto; }

.page { display: none; }
.page.active { display: block; animation: fadeIn .18s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; gap: 10px; }
.page-header h2 { font-size: 1.3rem; }
.page-header .sub { color: var(--muted); font-size: 0.85rem; }

/* Bottom tab bar (mobile) */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  height: var(--bottomnav-h);
  background: var(--surface);
  border-top: 1px solid var(--line);
  display: flex;
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav button {
  flex: 1; border: none; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); font-size: 0.68rem; font-weight: 600;
  padding: 6px 0;
}
.bottom-nav button svg { width: 22px; height: 22px; }
.bottom-nav button.active { color: var(--brand); }
.bottom-nav button.fab-add {
  position: relative;
}
.bottom-nav button.fab-add .fab-circle {
  width: 44px; height: 44px; border-radius: 14px;
  background: linear-gradient(135deg, var(--brand), var(--accent-pink)); color: white;
  display: flex; align-items: center; justify-content: center;
  margin-top: -22px; box-shadow: var(--shadow-md);
}
.bottom-nav button.fab-add.active .fab-circle { background: var(--brand-dark); }
.bottom-nav button.fab-add span.label { margin-top: 2px; }

/* Sidebar (desktop) */
.sidebar { display: none; }

@media (min-width: 900px) {
  .bottom-nav { display: none; }
  .sidebar {
    display: flex; flex-direction: column;
    position: fixed; top: 0; left: 0; bottom: 0; width: 232px;
    background: var(--surface); border-right: 1px solid var(--line);
    padding: 18px 12px;
    z-index: 25;
  }
  .sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 20px; }
  .sidebar .brand .mark {
    width: 34px; height: 34px; border-radius: 9px;
    background: linear-gradient(135deg, var(--brand), var(--accent-pink));
    color: white; display: flex; align-items: center; justify-content: center;
    font-family: var(--font-display); font-weight: 700;
  }
  .sidebar .brand .name { font-family: var(--font-display); font-weight: 700; font-size: 1.05rem; }
  .sidebar nav { display: flex; flex-direction: column; gap: 2px; }
  .sidebar nav button {
    display: flex; align-items: center; gap: 12px;
    border: none; background: none; cursor: pointer;
    padding: 10px 10px; border-radius: var(--radius-sm);
    color: var(--ink); font-size: 0.9rem; font-weight: 600; text-align: left;
  }
  .sidebar nav button svg { width: 19px; height: 19px; flex-shrink: 0; color: var(--muted); }
  .sidebar nav button:hover { background: var(--paper); }
  .sidebar nav button.active { background: var(--brand-soft); color: var(--brand-dark); }
  .sidebar nav button.active svg { color: var(--brand-dark); }
  .sidebar .spacer { flex: 1; }
  .sidebar .user-chip { padding: 10px; border-top: 1px solid var(--line); margin-top: 8px; }

  #app-shell.active { padding-left: 232px; }
  .topbar { display: none; }
  main.content { padding: 28px 32px 40px; max-width: 1200px; }
  .bottom-nav { display: none; }
}

/* ==========================================================================
   Cards, grids, tables
   ========================================================================== */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 18px;
  box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: 14px; }
.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: 1fr; }
.grid-3 { grid-template-columns: 1fr; }
.grid-4 { grid-template-columns: repeat(2, 1fr); }
@media (min-width: 640px) {
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .grid-3 { grid-template-columns: repeat(3, 1fr); }
  .grid-4 { grid-template-columns: repeat(4, 1fr); }
}

.metric-card { display: flex; flex-direction: column; gap: 6px; }
.metric-card .label { font-size: 0.74rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.metric-card .value { font-family: var(--font-mono); font-size: 1.6rem; font-weight: 700; }
.metric-card.accent-good .value { color: var(--good); }
.metric-card.accent-warn .value { color: var(--warn); }
.metric-card.accent-bad .value { color: var(--bad); }

.section-title { font-family: var(--font-display); font-size: 1.02rem; font-weight: 700; margin: 22px 0 10px; }

table.data-table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
table.data-table th {
  text-align: left; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.03em;
  color: var(--muted); padding: 8px 10px; border-bottom: 1.5px solid var(--line);
  white-space: nowrap;
}
table.data-table td { padding: 10px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data-table tr:last-child td { border-bottom: none; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px; font-size: 0.74rem; font-weight: 700;
}
.badge-pending { background: var(--warn-soft); color: var(--warn); }
.badge-supplied { background: var(--good-soft); color: var(--good); }
.badge-cancelled { background: var(--bad-soft); color: var(--bad); }
.badge-short { background: var(--bad-soft); color: var(--bad); }

/* Filters bar */
.filters-bar { display: grid; grid-template-columns: 1fr; gap: 10px; margin-bottom: 14px; }
@media (min-width: 640px) { .filters-bar { grid-template-columns: repeat(4, 1fr); align-items: end; } }
.filters-bar .field { margin-bottom: 0; }

/* Booking line item (ledger/manifest style) */
.line-item {
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-bottom: 10px;
  background: var(--paper);
}
.line-item-grid { display: grid; grid-template-columns: 1fr; gap: 10px; }
@media (min-width: 640px) { .line-item-grid { grid-template-columns: 2fr 2fr 1fr 1.4fr auto; align-items: end; } }
.stock-preview {
  font-family: var(--font-mono); font-size: 0.78rem; color: var(--muted); margin-top: 6px;
}
.stock-preview.short { color: var(--bad); font-weight: 700; }

/* Stockiest gauge card (signature element) */
.gauge-card { display: flex; align-items: center; gap: 14px; }
.gauge-ring { position: relative; width: 64px; height: 64px; flex-shrink: 0; }
.gauge-ring svg { transform: rotate(-90deg); }
.gauge-ring .bg { stroke: var(--line); }
.gauge-ring .fg { stroke: var(--brand); transition: stroke-dashoffset .4s ease; }
.gauge-ring.low .fg { stroke: var(--bad); }
.gauge-ring.mid .fg { stroke: var(--warn); }
.gauge-ring-label {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono); font-weight: 700; font-size: 0.78rem;
}
.gauge-meta .name { font-weight: 700; font-size: 0.92rem; }
.gauge-meta .sub { font-size: 0.76rem; color: var(--muted); }
.gauge-meta .figures { font-family: var(--font-mono); font-size: 0.76rem; margin-top: 2px; }

/* Notification panel */
.notif-panel {
  position: fixed; z-index: 40;
  top: var(--topbar-h); right: 0; left: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  max-height: 70vh; overflow-y: auto;
  box-shadow: var(--shadow-md);
  display: none;
}
.notif-panel.open { display: block; }
@media (min-width: 900px) {
  .notif-panel { top: 16px; right: 32px; left: auto; width: 380px; border-radius: var(--radius-md); border: 1px solid var(--line); }
}
.notif-panel-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.notif-item { padding: 12px 16px; border-bottom: 1px solid var(--line); font-size: 0.85rem; }
.notif-item:last-child { border-bottom: none; }
.notif-item.unread { background: var(--brand-soft); }
.notif-item .msg { margin-bottom: 4px; }
.notif-item .meta { font-size: 0.72rem; color: var(--muted); font-family: var(--font-mono); }
.notif-empty { padding: 30px 16px; text-align: center; color: var(--muted); font-size: 0.85rem; }

/* Overlay for panel dismiss on mobile */
.overlay { position: fixed; inset: 0; background: rgba(15,23,32,0.25); z-index: 35; display: none; }
.overlay.open { display: block; }

/* Tabs (used in admin screens) */
.tab-row { display: flex; gap: 6px; margin-bottom: 16px; overflow-x: auto; padding-bottom: 2px; }
.tab-row button {
  border: 1.5px solid var(--line); background: var(--surface); color: var(--muted);
  padding: 8px 14px; border-radius: 999px; font-weight: 600; font-size: 0.82rem; cursor: pointer;
  white-space: nowrap;
}
.tab-row button.active { background: var(--brand); border-color: var(--brand); color: white; }

/* Toast */
#toast-stack { position: fixed; bottom: calc(var(--bottomnav-h) + 14px); left: 50%; transform: translateX(-50%); z-index: 50; display: flex; flex-direction: column; gap: 8px; width: min(92vw, 420px); }
@media (min-width: 900px) { #toast-stack { bottom: 24px; } }
.toast {
  background: var(--ink); color: white; padding: 12px 16px; border-radius: var(--radius-sm);
  font-size: 0.85rem; box-shadow: var(--shadow-md); display: flex; align-items: center; gap: 8px;
  animation: toastIn .2s ease;
}
.toast.error { background: var(--bad); }
.toast.success { background: var(--good); }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* Empty states */
.empty-state { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty-state .icon { margin-bottom: 10px; opacity: 0.5; }
.empty-state .title { font-weight: 700; color: var(--ink); margin-bottom: 4px; }

/* Confirm modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15,23,32,0.4); z-index: 60; display: none; align-items: center; justify-content: center; padding: 20px; }
.modal-backdrop.open { display: flex; }
.modal-box { background: var(--surface); border-radius: var(--radius-md); padding: 22px; width: 100%; max-width: 380px; box-shadow: var(--shadow-md); }
.modal-box h4 { margin-bottom: 10px; }
.modal-box p { color: var(--muted); font-size: 0.88rem; margin-bottom: 16px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; margin: 10px 0; }
.spinner { width: 16px; height: 16px; border: 2px solid rgba(255,255,255,0.4); border-top-color: white; border-radius: 50%; animation: spin .6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.chart-wrap { position: relative; height: 240px; }
.remove-line-btn { background: none; border: none; color: var(--bad); cursor: pointer; font-size: 1.1rem; padding: 8px; }
