/* ===== Popeyes executive dashboard — light "reporting" theme ===== */
.viz-root {
  /* surfaces & ink (validated reference palette, light mode) */
  --page:           #f4f5f7;
  --surface-1:      #ffffff;
  --surface-2:      #f1f3f6;
  --text-primary:   #101828;
  --text-secondary: #52596b;
  --muted:          #8a90a0;
  --grid:           #eceef2;
  --baseline:       #d6dae1;
  --border:         rgba(16,24,40,0.09);
  --good:           #12805c;
  --critical:       #d03b3b;

  /* brand */
  --brand:          #ff7b2c;   /* Popeyes orange — fills, bars, area */
  --brand-strong:   #d95f18;   /* accessible orange for text/accents on white */
  --brand-soft:     #fff1e7;   /* tint wash */
  --on-brand:       #3a1c05;   /* dark ink for text sitting on orange */

  /* shadows */
  --sh-card:  0 1px 2px rgba(16,24,40,0.04), 0 1px 3px rgba(16,24,40,0.07);
  --sh-pop:   0 8px 28px rgba(16,24,40,0.14);

  /* categorical slots (light) — fixed order, payment mix */
  --series-1: #2a78d6; /* blue   */
  --series-2: #1baf7a; /* aqua   */
  --series-3: #eda100; /* yellow */
  --series-4: #008300; /* green  */
  --series-5: #4a3aa7; /* violet */
  --series-6: #e34948; /* red    */
  --series-7: #e87ba4; /* magenta*/
  --series-8: #eb6834; /* orange */
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", "Malgun Gothic", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--page);
  padding-bottom: calc(66px + env(safe-area-inset-bottom)); /* room for tab bar */
}

/* ===== Desktop gate (mobile-only) ===== */
.desktop-gate {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center; padding: 24px;
  background: radial-gradient(120% 120% at 50% 0%, #fff4ec, var(--page));
}
.desktop-gate[hidden] { display: none; }
.gate-card {
  text-align: center; max-width: 380px;
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 22px; padding: 34px 28px 30px; box-shadow: var(--sh-pop);
}
.gate-card .brand-mark { width: 56px; height: 56px; font-size: 30px; border-radius: 16px; margin: 0 auto 18px; }
.gate-card h1 { font-size: 21px; font-weight: 800; margin-bottom: 10px; }
.gate-card p { font-size: 14px; color: var(--text-secondary); line-height: 1.6; }
.gate-qr { width: 168px; height: 168px; margin: 22px auto 16px; background: #fff; border: 1px solid var(--border); border-radius: 14px; padding: 10px; }
.gate-qr canvas, .gate-qr img { width: 100%; height: 100%; display: block; image-rendering: pixelated; }
.gate-url { display: inline-block; font-size: 13px; font-weight: 700; color: var(--brand-strong); word-break: break-all; text-decoration: none; }

/* ===== Login screen ===== */
.login-screen {
  position: fixed; inset: 0; z-index: 90;
  display: grid; place-items: center; padding: 24px;
  background: radial-gradient(120% 120% at 50% 0%, #fff4ec, var(--page));
}
.login-screen[hidden] { display: none; }
.login-card {
  width: 100%; max-width: 380px;
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 22px; padding: 32px 26px 26px; box-shadow: var(--sh-pop);
  display: flex; flex-direction: column;
}
.login-card .brand-mark { width: 56px; height: 56px; font-size: 30px; border-radius: 16px; margin: 0 auto 18px; }
.login-card h1 { font-size: 20px; font-weight: 800; text-align: center; letter-spacing: -0.01em; }
.login-sub { font-size: 13px; color: var(--text-secondary); text-align: center; margin: 6px 0 22px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field span { font-size: 12.5px; font-weight: 650; color: var(--text-secondary); }
.field input {
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface-1);
  padding: 13px 14px; font-size: 16px; color: var(--text-primary); outline: none; transition: .15s;
}
.field input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.login-error {
  font-size: 13px; color: var(--critical); font-weight: 600; margin-bottom: 12px;
  background: #fdecec; border: 1px solid rgba(208,59,59,0.25); border-radius: 10px; padding: 9px 12px;
}
.login-error[hidden] { display: none; }
.login-btn {
  margin-top: 4px; border: 0; cursor: pointer;
  background: var(--brand); color: #fff; font-size: 16px; font-weight: 750;
  border-radius: 12px; padding: 14px; box-shadow: 0 4px 14px rgba(255,123,44,0.35); transition: .15s;
}
.login-btn:active { transform: scale(.98); }
.login-btn:disabled { opacity: .6; cursor: default; }
.login-note { font-size: 11.5px; color: var(--muted); text-align: center; margin-top: 16px; }

/* ===== Top bar ===== */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(14px + env(safe-area-inset-top)) 18px 14px;
  background: rgba(244,245,247,0.82);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 11px;
  display: block; object-fit: cover; overflow: hidden;
  box-shadow: 0 4px 12px rgba(255,123,44,0.35);
}
.brand-title { font-size: 16px; font-weight: 750; letter-spacing: -0.01em; }
.brand-sub { font-size: 11.5px; color: var(--muted); margin-top: 1px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.badge {
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.02em;
  padding: 4px 9px; border-radius: 999px; border: 1px solid var(--border);
}
.badge-demo { color: var(--brand-strong); background: var(--brand-soft); border-color: rgba(217,95,24,0.24); }
.badge-live { color: var(--good); background: #e6f5ef; border-color: rgba(18,128,92,0.30); }
.icon-btn {
  width: 38px; height: 38px; border-radius: 11px; border: 1px solid var(--border);
  background: var(--surface-1); color: var(--text-secondary);
  display: grid; place-items: center; cursor: pointer; transition: .15s; box-shadow: var(--sh-card);
}
.icon-btn:active { transform: scale(.94); color: var(--brand-strong); }
.icon-btn.spinning svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.asof { padding: 10px 18px 2px; font-size: 12px; color: var(--muted); }

.content { padding: 8px 14px 40px; display: flex; flex-direction: column; gap: 14px; }

/* ===== KPI grid ===== */
.kpi-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; }
.kpi {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 16px; padding: 15px 15px 14px; box-shadow: var(--sh-card);
  min-height: 96px; display: flex; flex-direction: column; justify-content: space-between;
}
.kpi-hero {
  grid-column: 1 / -1;
  background:
    radial-gradient(130% 150% at 100% 0%, rgba(255,123,44,0.12), transparent 55%),
    var(--surface-1);
  border-color: rgba(217,95,24,0.28);
}
.kpi-label { font-size: 12.5px; color: var(--text-secondary); font-weight: 600; }
.kpi-value { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.1; margin-top: 8px; }
.kpi-hero .kpi-value { font-size: 40px; }
.kpi-sub { font-size: 12px; color: var(--muted); margin-top: 6px; }
.kpi-delta { font-size: 13px; font-weight: 700; margin-top: 8px; display: inline-flex; align-items: center; gap: 5px; }
.kpi-delta.up { color: var(--good); }
.kpi-delta.down { color: var(--critical); }
.kpi-delta.neutral { color: var(--text-secondary); font-weight: 600; }
.kpi-delta .arrow { font-size: 12px; }
.unit { font-size: 0.58em; font-weight: 700; color: var(--text-secondary); margin-left: 2px; }

/* ===== Cards ===== */
.card {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 18px; padding: 16px 16px 14px; box-shadow: var(--sh-card);
}
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; gap: 10px; }
.card-head h2 { font-size: 15px; font-weight: 700; letter-spacing: -0.01em; }
.card-head-note { font-size: 11px; color: var(--muted); font-weight: 600; margin-left: 4px; }
.card-head-val { font-size: 13px; font-weight: 700; color: var(--brand-strong); font-variant-numeric: tabular-nums; }
.chart { width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }

/* ===== Segmented control ===== */
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; }
.seg-btn {
  border: 0; background: transparent; color: var(--text-secondary);
  font-size: 12.5px; font-weight: 700; padding: 6px 12px; border-radius: 8px; cursor: pointer;
}
.seg-btn.is-active { background: var(--brand); color: var(--on-brand); box-shadow: 0 1px 2px rgba(217,95,24,0.30); }

/* ===== Payment mix ===== */
.paymix { display: flex; align-items: center; gap: 16px; }
.chart-donut { flex: 0 0 auto; width: 132px; }
.legend { list-style: none; flex: 1; display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.legend li { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.legend .dot { width: 10px; height: 10px; border-radius: 3px; flex: 0 0 auto; }
.legend .lg-name { color: var(--text-secondary); flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.legend .lg-pct { font-weight: 700; font-variant-numeric: tabular-nums; }

/* ===== Leaderboard ===== */
.leaderboard { list-style: none; display: flex; flex-direction: column; gap: 2px; }
.lb-row { display: grid; grid-template-columns: 26px 1fr auto; align-items: center; gap: 11px; padding: 11px 4px; border-bottom: 1px solid var(--grid); }
.lb-row:last-child { border-bottom: 0; }
.lb-rank { font-size: 13px; font-weight: 800; color: var(--muted); text-align: center; font-variant-numeric: tabular-nums; }
.lb-row:nth-child(1) .lb-rank { color: var(--brand-strong); }
.lb-row:nth-child(2) .lb-rank,
.lb-row:nth-child(3) .lb-rank { color: var(--brand); }
.lb-mid { min-width: 0; }
.lb-name { font-size: 14.5px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lb-meta { font-size: 11.5px; color: var(--muted); margin-top: 3px; }
.lb-bar { height: 4px; border-radius: 3px; background: var(--brand); margin-top: 7px; opacity: .9; }
.lb-amt { text-align: right; }
.lb-amt .v { font-size: 15px; font-weight: 750; font-variant-numeric: tabular-nums; }
.lb-amt .share { font-size: 11px; color: var(--muted); margin-top: 3px; }

/* ===== Tooltip ===== */
.tip {
  position: fixed; z-index: 50; pointer-events: none; opacity: 0;
  transform: translate(-50%, -115%); transition: opacity .1s;
  background: #101828; color: #fff; border-radius: 10px;
  padding: 8px 11px; font-size: 12px; white-space: nowrap;
  box-shadow: var(--sh-pop);
}
.tip .tip-t { color: #b6bcca; font-size: 11px; margin-bottom: 3px; }
.tip .tip-v { font-weight: 750; font-variant-numeric: tabular-nums; }
.tip.show { opacity: 1; }

/* chart helpers */
.axis-label { fill: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }
.grid-line { stroke: var(--grid); stroke-width: 1; }
.baseline { stroke: var(--baseline); stroke-width: 1; }

/* ===== Views + tab bar ===== */
.view { display: none; flex-direction: column; gap: 14px; }
.view.is-active { display: flex; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  max-width: 520px; margin: 0 auto;
  display: grid; grid-template-columns: 1fr 1fr 1fr;
  background: rgba(255,255,255,0.92);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  border: 0; background: transparent; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 10px 0 9px; color: var(--muted); font-size: 11px; font-weight: 650;
}
.tab.is-active { color: var(--brand-strong); }
.tab svg { transition: transform .15s; }
.tab.is-active svg { transform: translateY(-1px); }

/* ===== Raw data controls ===== */
.raw-controls { display: flex; flex-direction: column; gap: 10px; position: sticky; top: 0; z-index: 5;
  background: var(--page); padding: 4px 0 6px; }
#filter-panel { display: flex; flex-direction: column; gap: 10px; }
#filter-panel[hidden] { display: none; }
.filter-summary {
  display: flex; align-items: center; gap: 8px; width: 100%; cursor: pointer;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px;
  padding: 11px 14px; box-shadow: var(--sh-card); color: var(--text-primary);
  font-size: 13.5px; font-weight: 700; text-align: left;
}
.filter-summary[hidden] { display: none; }
.filter-summary svg { color: var(--brand-strong); flex: 0 0 auto; }
.filter-summary #filter-summary-text { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.filter-summary .fs-edit { flex: 0 0 auto; font-size: 12px; font-weight: 700; color: var(--brand-strong);
  background: var(--brand-soft); padding: 4px 10px; border-radius: 999px; }
.search { display: flex; align-items: center; gap: 8px;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px;
  padding: 0 12px; color: var(--muted); box-shadow: var(--sh-card); }
.search input { flex: 1; border: 0; background: transparent; color: var(--text-primary);
  font-size: 15px; padding: 12px 0; outline: none; }
.search input::placeholder { color: var(--muted); }
.seg-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.seg-scroll::-webkit-scrollbar { display: none; }
.seg-scroll .seg-btn { white-space: nowrap; }
.table-meta { font-size: 12px; color: var(--muted); padding: 0 2px; }

/* query controls: store chips + date range + presets */
.ctrl-block { display: flex; flex-direction: column; gap: 7px; }
.ctrl-label { font-size: 12px; font-weight: 700; color: var(--text-secondary); display: flex; align-items: center; gap: 8px; }
.ctrl-count { font-size: 11px; font-weight: 700; color: var(--brand-strong); background: var(--brand-soft); padding: 2px 8px; border-radius: 999px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips-box { max-height: 208px; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 8px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-1); box-shadow: var(--sh-card); }
.chips-box::-webkit-scrollbar { width: 6px; } .chips-box::-webkit-scrollbar-thumb { background: var(--baseline); border-radius: 3px; }
.chip {
  border: 1px solid var(--border); background: var(--surface-1); cursor: pointer;
  color: var(--text-secondary); font-size: 12.5px; font-weight: 650;
  padding: 6px 11px; border-radius: 999px; white-space: nowrap; transition: .12s;
}
.chip.is-on { background: var(--brand); color: #fff; border-color: var(--brand); box-shadow: 0 2px 6px rgba(255,123,44,0.3); }
.chip:active { transform: scale(.96); }
.presets .chip.is-on { background: var(--brand-soft); color: var(--brand-strong); border-color: rgba(217,95,24,0.3); box-shadow: none; }

.daterow { display: flex; align-items: center; gap: 8px; }
.dateinput {
  flex: 1; min-width: 0; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-1);
  color: var(--text-primary); font-size: 14px; font-weight: 650; padding: 11px 12px; outline: none;
  box-shadow: var(--sh-card); font-variant-numeric: tabular-nums;
}
.dateinput:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.tilde { color: var(--muted); font-weight: 700; flex: 0 0 auto; }

.btn-go {
  border: 0; cursor: pointer; white-space: nowrap;
  background: var(--brand); color: #fff; font-size: 15px; font-weight: 750;
  border-radius: 12px; padding: 0 20px; box-shadow: 0 3px 10px rgba(255,123,44,0.32); transition: .15s;
}
.btn-go:active { transform: scale(.98); }
.btn-go:disabled { opacity: .6; }
.btn-go-full { width: 100%; padding: 14px; }

/* per-store detail (uniform with dashboard KPI tiles) */
.store-detail { }
.store-detail[hidden] { display: none; }
.store-detail .kpi-grid { grid-template-columns: 1fr 1fr; }

/* ===== Scrollable data table ===== */
.table-wrap {
  overflow: auto; -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border); border-radius: 14px;
  max-height: calc(100vh - 190px);
  background: var(--surface-1); box-shadow: var(--sh-card);
}
#raw-table { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 13px; }
#raw-table th, #raw-table td { padding: 11px 12px; text-align: right; white-space: nowrap;
  font-variant-numeric: tabular-nums; border-bottom: 1px solid var(--grid); }
#raw-table thead th {
  position: sticky; top: 0; z-index: 3; background: var(--surface-2);
  color: var(--text-secondary); font-weight: 700; font-size: 12px; cursor: pointer; user-select: none;
}
#raw-table thead th .sort-ind { color: var(--brand-strong); margin-left: 3px; font-size: 10px; }
/* first column = label, sticky left */
#raw-table th:first-child, #raw-table td:first-child {
  position: sticky; left: 0; z-index: 2; text-align: left;
  background: var(--surface-1); font-weight: 650; color: var(--text-primary);
}
#raw-table thead th:first-child { z-index: 4; background: var(--surface-2); }
#raw-table tbody tr:nth-child(even) td { background: #fafbfc; }
#raw-table tbody tr:nth-child(even) td:first-child { background: #fafbfc; }
#raw-table tbody tr:active td, #raw-table tbody tr:active td:first-child { background: var(--brand-soft); }
#raw-table td.pos { color: var(--text-primary); }
#raw-table td.dim { color: var(--muted); }
.raw-empty { padding: 30px; text-align: center; color: var(--muted); font-size: 14px; }

/* ===== App report ===== */
#app-body { display: flex; flex-direction: column; gap: 14px; }
#app-body .kpi-grid { grid-template-columns: 1fr 1fr; }
.donut-svg { display: block; width: 100%; height: auto; }
.rank-list { list-style: none; display: flex; flex-direction: column; gap: 2px; }
.rank-row { display: grid; grid-template-columns: 22px 1fr auto; align-items: center; gap: 11px; padding: 10px 2px; border-bottom: 1px solid var(--grid); }
.rank-row:last-child { border-bottom: 0; }
.rank-no { font-size: 12.5px; font-weight: 800; color: var(--muted); text-align: center; font-variant-numeric: tabular-nums; }
.rank-row:nth-child(1) .rank-no { color: var(--brand-strong); }
.rank-row:nth-child(2) .rank-no, .rank-row:nth-child(3) .rank-no { color: var(--brand); }
.rank-mid { min-width: 0; }
.rank-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rank-sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.rank-val { text-align: right; font-size: 14.5px; font-weight: 750; font-variant-numeric: tabular-nums; }
.app-note { font-size: 13px; color: var(--text-secondary); text-align: center; padding: 24px 16px; line-height: 1.6; }
.app-h2 { font-size: 14px; font-weight: 750; color: var(--text-secondary); margin: 4px 2px -2px; }

/* skeleton shimmer */
.skeleton { color: transparent !important; border-radius: 6px;
  background: linear-gradient(90deg, var(--surface-2) 25%, #e7eaef 37%, var(--surface-2) 63%);
  background-size: 400% 100%; animation: sk 1.3s ease infinite; }
@keyframes sk { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }
