/* Colours taken from Sell-Out Dashboard.xlsx */
:root {
  color-scheme: light;
  --ink: #000000;
  --muted: #595959;
  --line: #d9d9d9;
  --head: #808080;          /* metric column headers */
  --date: #0070c0;          /* date column headers */
  --sunday: #00b0f0;        /* Sunday date headers */
  --total: #ccc0da;         /* Total row */
  --region: #4f81bd;        /* region label cell */
  --region-cell: #b8cce4;   /* region value cells, selected slicer button */
  --filial-cell: #fcd5b4;   /* filial value cells */
  --left: #e6b8b7;          /* "Left to 100%" column */
  --avg: #8db4e2;           /* "Average" column */
  --good: #92d050;          /* projection > 100% */
  --bad-bg: #ffc7ce;        /* projection < 85% */
  --bad-ink: #9c0006;
  --teal: #4bacc6;          /* Filial-Brand header & regions */
  --purple: #7030a0;        /* Filial-Brand grand total */
  --red: #ff0000;
  --green: #008000;
  --group: #dce6f1;         /* Product sub-groups */
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: #ffffff; }
body { color: var(--ink); font: 12px/1.35 Calibri, Carlito, "Segoe UI", Arial, sans-serif; }
button, input, select { font: inherit; color: inherit; }

/* ---------- top bar & sheet tabs */
.topbar { display: flex; align-items: center; gap: 12px; padding: 0 16px; height: 42px; border-bottom: 1px solid var(--line); background: #fff; position: sticky; top: 0; z-index: 30; }
.topbar .logo { font-weight: 700; font-size: 14px; color: var(--region); white-space: nowrap; }
.topbar .logo small { font-weight: 400; color: var(--muted); margin-left: 6px; font-size: 12px; }
.topbar .spacer { flex: 1; }
.topbar .who { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar a, .topbar button.link { color: var(--region); text-decoration: none; background: none; border: 0; cursor: pointer; padding: 6px 8px; border-radius: 4px; }
.topbar a:hover, .topbar button.link:hover { background: #eef3fa; }
.tabs { display: flex; gap: 2px; padding: 0 12px; overflow-x: auto; border-bottom: 2px solid var(--region); background: #fff; position: sticky; top: 42px; z-index: 25; }
.tabs button { background: #f2f2f2; border: 1px solid var(--line); border-bottom: 0; padding: 7px 14px; margin-top: 6px; cursor: pointer; white-space: nowrap; border-radius: 4px 4px 0 0; color: #333; }
.tabs button.active { background: var(--region); color: #fff; border-color: var(--region); font-weight: 700; }

main { padding: 12px 16px 40px; }

/* ---------- slicer band (like the top of each Excel sheet) */
.band { display: flex; gap: 18px; align-items: flex-start; flex-wrap: wrap; padding-bottom: 12px; margin-bottom: 12px; border-bottom: 2px solid var(--region); }
.calbox { border: 1px solid var(--line); padding: 8px 12px; min-width: 180px; }
.calbox div { display: flex; justify-content: space-between; gap: 24px; font-weight: 700; padding: 3px 0; }
.typebox { display: flex; flex-direction: column; gap: 5px; padding-top: 2px; }
.sbtn { border: 1px solid #a6a6a6; background: #fff; padding: 4px 8px; font-size: 15px; text-align: left; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.sbtn:hover { border-color: var(--region); }
.sbtn.sel { background: var(--region-cell); border-color: #8ea9cf; }
.typebox .sbtn { width: 150px; }
.slicerbox { min-width: 0; }
.slicerbox .shead { display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--region); padding-bottom: 3px; margin-bottom: 6px; }
.slicerbox .shead b { font-size: 17px; flex: 1; }
.slicerbox .shead button { border: 1px solid transparent; background: none; cursor: pointer; padding: 1px 5px; color: #555; font-size: 14px; line-height: 1; }
.slicerbox .shead button.on { border-color: var(--region); background: var(--region-cell); }
.slicerbox .shead button:hover { border-color: var(--line); }
.sgrid { display: grid; gap: 4px; }
.sgrid.scroll-y { max-height: 92px; overflow-y: auto; padding-right: 4px; }
.sgrid .sbtn { font-size: 15px; }
.sgrid.small .sbtn { font-size: 13px; padding: 2px 6px; }
.chip { background: #eef3fa; border: 1px solid var(--region-cell); padding: 3px 8px; display: inline-flex; gap: 6px; align-items: center; color: var(--muted); align-self: center; }
.chip button { border: 0; background: none; cursor: pointer; color: var(--muted); padding: 0 2px; }

/* ---------- tables */
.panel { margin-bottom: 18px; }
.panel h3 { margin: 0 0 6px; font-size: 14px; color: var(--region); display: flex; gap: 10px; align-items: center; }
.panel h3 .right { margin-left: auto; display: flex; gap: 6px; }
.panel h3 .right button { font-weight: 400; background: #fff; border: 1px solid var(--line); padding: 2px 8px; cursor: pointer; color: #333; }
.scroll { overflow: auto; max-height: calc(100vh - 260px); border-left: 1px solid var(--line); }
table.grid { border-collapse: collapse; width: max-content; }
.grid th, .grid td { padding: 2px 8px; white-space: nowrap; text-align: right; font-variant-numeric: tabular-nums; border: 1px solid #fff; height: 19px; }
.grid thead th { position: sticky; top: 0; z-index: 2; color: #fff; font-weight: 700; background: var(--head); text-align: center; white-space: normal; min-width: 72px; vertical-align: middle; height: 52px; font-size: 12px; }
.grid thead th.h-date { background: var(--date); min-width: 74px; white-space: nowrap; }
.grid thead th.h-sun { background: var(--sunday); }
.grid thead th:first-child { background: #fff; }
.grid td:first-child, .grid th:first-child { position: sticky; left: 0; z-index: 1; text-align: left; min-width: 190px; }
.grid thead th:first-child { z-index: 3; }
.grid td { background: var(--filial-cell); }
.grid td:first-child { background: #fff; font-size: 11px; padding-left: 18px; }
/* total row */
.grid tr.tot td, .grid tr.tot td:first-child { background: var(--total); font-weight: 700; font-size: 13px; }
/* region rows */
.grid tr.reg td { background: var(--region-cell); }
.grid tr.reg td:first-child { background: var(--region); color: #fff; font-weight: 700; font-size: 13px; padding-left: 4px; }
/* product sub-groups */
.grid tr.grp td { background: var(--group); font-weight: 600; }
.grid tr.grp td:first-child { background: var(--group); padding-left: 10px; font-size: 12px; }
.grid tr.lv3 td:first-child { padding-left: 30px; }
.grid tr.lv4 td:first-child { padding-left: 42px; }
/* column tones on filial rows */
.grid tr.fil td.t-left { background: var(--left); }
.grid tr.fil td.t-req { background: var(--region-cell); }
.grid tr.fil td.t-avg { background: var(--avg); }
/* conditional formats */
.grid td.good { background: var(--good) !important; color: #fff; }
.grid td.bad { background: var(--bad-bg) !important; color: var(--bad-ink); }
.grid tr:hover td { filter: brightness(.96); }
.caret { display: inline-block; width: 14px; cursor: pointer; user-select: none; }
.client-row td:first-child { padding-left: 30px !important; }

/* Filial-Brand sheet */
table.fb { border-collapse: collapse; width: max-content; }
.fb th, .fb td { padding: 2px 10px; text-align: center; white-space: nowrap; font-variant-numeric: tabular-nums; height: 20px; font-size: 13px; }
.fb tbody td:first-child, .fb .corner { text-align: left; position: sticky; left: 0; min-width: 210px; z-index: 1; }
.fb .corner { background: var(--teal); color: #fff; font-weight: 700; text-align: center !important; font-size: 15px; }
.fb .corner big { font-size: 18px; display: block; }
.fb thead th { background: var(--teal); color: #fff; font-weight: 700; min-width: 76px; font-size: 14px; }
.fb thead tr.tot th { font-weight: 400; color: #f2f2f2; font-size: 13px; }
.fb thead tr.tot th.grand { background: var(--purple); color: #fff; font-weight: 700; font-size: 16px; }
.fb tr.reg td { background: var(--teal); color: #fff; }
.fb tr.reg td:first-child { font-weight: 700; font-size: 14px; }
.fb tr.fil td { background: #fff; }
.fb tr.fil td:first-child { padding-left: 26px; font-size: 13px; }
.fb td.red { color: var(--red); }
.fb td.green { color: var(--green); }

.cards { display: none; }
.note { color: var(--muted); padding: 6px 0; }
.warn { background: #fff2cc; border: 1px solid #ffd966; padding: 6px 10px; margin-bottom: 10px; }
.flex { display: flex; gap: 24px; flex-wrap: wrap; align-items: flex-start; }
.flex > .panel { min-width: 0; max-width: 100%; }
.loading { opacity: .5; pointer-events: none; transition: opacity .15s; }

/* ---------- login / admin */
.center { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { background: #fff; padding: 28px; width: 100%; max-width: 360px; border: 1px solid var(--line); border-top: 4px solid var(--region); }
.login h1 { margin: 0 0 4px; font-size: 20px; color: var(--region); }
.login p { margin: 0 0 18px; color: var(--muted); }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field input, .field select, input.cell { padding: 7px 9px; border: 1px solid #bfbfbf; background: #fff; }
.btn { background: var(--region); color: #fff; border: 0; padding: 8px 16px; cursor: pointer; font-weight: 700; }
.btn.secondary { background: #fff; color: var(--ink); border: 1px solid #bfbfbf; }
.btn:disabled { opacity: .5; cursor: wait; }
.err { color: var(--bad-ink); min-height: 18px; }
section.panel:has(.admin-section) { border: 1px solid var(--line); }
section.panel:has(.admin-section) h3 { background: var(--region); color: #fff; padding: 8px 12px; margin: 0; }
.admin-section { padding: 12px; }
.admin-section .row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.report { white-space: pre-wrap; font-family: Consolas, monospace; font-size: 12px; background: #f7f7f7; padding: 10px; margin-top: 10px; max-height: 360px; overflow: auto; }
table.plain { border-collapse: collapse; width: 100%; }
table.plain td, table.plain th { padding: 4px 8px; border-bottom: 1px solid var(--line); text-align: left; }
table.plain th { background: var(--head); color: #fff; }
table.plain input, table.plain select { width: 100%; padding: 3px 6px; border: 1px solid #bfbfbf; background: #fff; }

@media (max-width: 640px) {
  .topbar .logo small, .topbar .who { display: none; }
  main { padding: 10px 10px 30px; }
  .band { gap: 12px; }
  .slicerbox { width: 100%; }
  .grid td:first-child, .grid th:first-child, .fb tbody td:first-child, .fb .corner { min-width: 140px; max-width: 160px; overflow: hidden; text-overflow: ellipsis; }
  .sbtn, .sgrid .sbtn { font-size: 13px; }
}
