/* Bonita Reports — light by default, quiet, one brand accent. A dark theme
   (FO Dashboard's palette: near-black surfaces, warm off-white ink, Bonita pink)
   is chosen with the ☾ / ☀ toggle and stored per browser; series colours switch
   to the dataviz palette's dark steps. */
:root {
  color-scheme: light;
  --plane: #f5f5f7;
  --card: #ffffff;
  --card-glass: rgba(255, 255, 255, 0.78);
  --ink: #1d1d1f;
  --ink-2: #5c5c61;
  --ink-3: #8a8a90;
  --hair: rgba(0, 0, 0, 0.08);
  --grid: #e8e8ea;
  --brand: #f01090;
  --rev: #2a78d6;      /* revenue · BTX */
  --exp: #eb6834;      /* expense */
  --amen: #1baf7a;     /* amenities · TS */
  --rc: #eda100;       /* housekeeping */
  --ops: #6250d6;      /* operations */
  --sup: #e87ba4;      /* suppliers */
  --good: #006300;
  --good-bg: #e4f4e4;
  --bad: #b42318;
  --bad-bg: #fbe7e5;
  --warn: #8a5a00;
  --warn-bg: #fff1cc;
  --hover: rgba(0, 0, 0, 0.05);
  --seg-bg: rgba(0, 0, 0, 0.06);
  --seg-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
  --card-edge: rgba(255, 255, 255, 0.7);
  --soft: #fafafb;          /* notes, order rows, inputs */
  --track: #f0f0f2;         /* bar-list tracks */
  --meter-track: #eef2f8;
  --axis-base: #cfcfd3;
  --sel-bg: #1d1d1f;        /* selected tab */
  --sel-fg: #ffffff;
  --pressed: rgba(42, 120, 214, 0.08);
  --tag-bg: rgba(0, 0, 0, 0.06);
  --btx-bg: rgba(42, 120, 214, 0.12); --btx-fg: #1c5cab;
  --ts-bg: rgba(27, 175, 122, 0.14); --ts-fg: #0d7a52;
  --alert-bg: #fffaf0; --alert-edge: #e8b04b;
  --bars-muted: #c9c9ce;    /* the non-peak columns */
  --radius: 18px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.05);
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", "Segoe UI", Roboto, system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--plane);
  color: var(--ink);
  font: 15px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--rev); text-decoration: none; }
button { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ── Top bar: filters scope everything below ─────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--card-glass);
  backdrop-filter: saturate(180%) blur(18px);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  border-bottom: 1px solid var(--hair);
}
.topbar-inner {
  max-width: none; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; margin-right: auto; }
.brand-logo { height: 46px; width: auto; display: block; }
.topbar-break { display: none; }
.brand strong { font-weight: 700; letter-spacing: 0.4px; color: var(--brand); }
.brand span { color: var(--ink-2); font-size: 16px; font-weight: 600; letter-spacing: 0.1px; }

.datenav { display: flex; align-items: center; gap: 4px; }
.datenav button, .seg button, .iconbtn {
  border: 0; background: transparent; border-radius: 10px; padding: 6px 10px; cursor: pointer;
  color: var(--ink-2); line-height: 1;
}
.datenav button:hover, .iconbtn:hover { background: var(--hover); color: var(--ink); }
.datenav button:disabled { opacity: 0.3; cursor: default; background: transparent; }
.datenav button.latest { font-size: 13px; font-weight: 500; white-space: nowrap; }
.datenav input[type="date"] {
  border: 1px solid var(--hair); background: var(--card); border-radius: 10px;
  padding: 6px 10px; font: inherit; color: var(--ink); min-width: 150px;
}
.seg { display: inline-flex; background: var(--seg-bg); border-radius: 12px; padding: 3px; }
.seg button { padding: 6px 14px; border-radius: 9px; font-weight: 500; }
.seg button[aria-pressed="true"] { background: var(--card); color: var(--ink); box-shadow: var(--seg-shadow); }
.user { font-size: 13px; color: var(--ink-3); display: flex; align-items: center; gap: 8px; }

/* ── Page ────────────────────────────────────────────────────────────── */
.page { max-width: none; margin: 0 auto; padding: 28px 16px 64px; }
.page.loading .refetch { opacity: 0.45; transition: opacity 0.2s; }
.refetch { transition: opacity 0.2s; }

.eyebrow { color: var(--rev); font-size: 13px; font-weight: 600; margin: 0 0 6px; }
h1 { font-size: clamp(30px, 5vw, 44px); line-height: 1.08; letter-spacing: -0.02em; margin: 0 0 10px; font-weight: 700; }
.lede { font-size: 17px; color: var(--ink-2); max-width: 70ch; margin: 0 0 22px; }
.lede b { color: var(--ink); font-weight: 600; }

.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px 20px; border: 1px solid var(--card-edge);
}
.card h2 { font-size: 17px; margin: 0 0 2px; letter-spacing: -0.01em; }
.card .sub { color: var(--ink-3); font-size: 13px; margin: 0 0 14px; }
.card .sub .key { display: inline-flex; align-items: center; gap: 6px; margin-right: 12px; color: var(--ink-2); }
.key i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; }
.key i.line { width: 14px; height: 3px; border-radius: 2px; }

/* KPI tiles */
.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.tiles.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 900px) { .tiles, .tiles.four { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; } }
.tile { padding: 16px 18px 12px; display: flex; flex-direction: column; min-height: 150px; }
.tile .label { font-size: 13px; color: var(--ink-2); display: flex; align-items: center; gap: 7px; }
.tile .value { font-size: 32px; font-weight: 700; letter-spacing: -0.02em; margin: 6px 0 6px; line-height: 1; }
.tile .value small { font-size: 15px; font-weight: 600; color: var(--ink-2); margin-left: 3px; letter-spacing: 0; }
.tile .delta-row { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--ink-3); flex-wrap: wrap; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-weight: 600; font-size: 12px; }
.pill.up { background: var(--good-bg); color: var(--good); }
.pill.down { background: var(--bad-bg); color: var(--bad); }
.pill.flat { background: var(--tag-bg); color: var(--ink-2); }
.tile svg.spark { width: 100%; height: 44px; margin-top: auto; display: block; overflow: visible; }

/* Tabs */
.tabs { display: flex; gap: 6px; margin: 26px 0 14px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  border: 0; background: transparent; padding: 8px 14px; border-radius: 999px; cursor: pointer;
  color: var(--ink-2); font-weight: 500; white-space: nowrap; display: inline-flex; align-items: center; gap: 7px;
}
.tabs button i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.tabs button[aria-selected="true"] { background: var(--sel-bg); color: var(--sel-fg); }
.tabs button[aria-selected="true"] i { outline: 2px solid rgba(255, 255, 255, 0.6); }
.panel[hidden], .tabs button[hidden] { display: none; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(330px, 100%), 1fr)); gap: 14px; }
.stack { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
/* A grid cell grows to its widest content by default (min-width: auto), so one wide
   table pushed the whole page past a phone screen. Cells may shrink; wide tables
   scroll inside their own .tbl-wrap instead. */
.tiles > *, .grid2 > *, .stack > *, .page > * { min-width: 0; }
.card, .note, .tile { overflow-wrap: anywhere; }

/* Filter chips (click-to-filter inside Doanh thu) */
.chips { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; min-height: 32px; margin-bottom: 12px; font-size: 13px; color: var(--ink-3); }
.chip { background: var(--card); border: 1px solid var(--hair); border-radius: 999px; padding: 4px 6px 4px 12px; display: inline-flex; gap: 6px; align-items: center; color: var(--ink); }
.chip button { border: 0; background: var(--tag-bg); color: var(--ink); border-radius: 50%; width: 20px; height: 20px; cursor: pointer; line-height: 1; }
.chips .clear { border: 0; background: transparent; color: var(--rev); cursor: pointer; }

/* Horizontal bar lists */
.hbars { display: grid; gap: 6px; }
.hbar {
  display: grid; grid-template-columns: minmax(120px, 1.5fr) 1.5fr auto; align-items: center; gap: 10px;
  padding: 4px 6px; border-radius: 10px; cursor: pointer; border: 0; background: transparent; text-align: left; width: 100%;
}
.hbar:hover { background: var(--hover); }
.hbar[aria-pressed="true"] { background: var(--pressed); }
.hbar .lbl { font-size: 13px; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar .lbl small { color: var(--ink-3); margin-left: 4px; }
.hbar .track { height: 10px; background: var(--track); border-radius: 5px; overflow: hidden; }
.hbar .track i { display: block; height: 100%; border-radius: 0 4px 4px 0; background: var(--rev); min-width: 2px; }
.hbar .val { font-size: 13px; text-align: right; white-space: nowrap; }
.hbar .val small { color: var(--ink-3); margin-left: 6px; }
.hbar.static { cursor: default; }
.hbar.pay-ota .lbl { padding-left: 16px; color: var(--ink-2); }
.hbar.pay-ota .track i { opacity: .6; }
.hbar.static:hover { background: transparent; }
.muted { color: var(--ink-3); }

/* Tables */
/* Tables never wrap a cell onto a second line (Brian, 2026-10-17): a table wider than
   its card scrolls sideways inside .tbl-wrap instead; the page itself stays screen-wide. */
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th, .tbl td { padding: 8px 8px; border-bottom: 1px solid var(--grid); text-align: left; vertical-align: top; white-space: nowrap; }
.tbl th { font-weight: 600; color: var(--ink-2); font-size: 12px; white-space: nowrap; cursor: pointer; user-select: none; }
.tbl th[aria-sort]::after { content: ""; margin-left: 4px; color: var(--ink-3); }
.tbl th[aria-sort="ascending"]::after { content: "↑"; }
.tbl th[aria-sort="descending"]::after { content: "↓"; }
.tbl td.r, .tbl th.r { text-align: right; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tfoot td { font-weight: 600; border-top: 1px solid var(--ink-3); }
.tbl .tag { display: inline-block; padding: 1px 7px; border-radius: 6px; font-size: 11px; font-weight: 600; background: var(--tag-bg); color: var(--ink-2); white-space: nowrap; }
.tag.BTX { background: var(--btx-bg); color: var(--btx-fg); }
.tag.TS { background: var(--ts-bg); color: var(--ts-fg); }
.tag.good { background: var(--good-bg); color: var(--good); }
.tag.bad { background: var(--bad-bg); color: var(--bad); }
.tag.warn { background: var(--warn-bg); color: var(--warn); }

/* Charts */
.chart { position: relative; }
.chart svg { width: 100%; display: block; overflow: visible; }
.chart .bar { transition: opacity 0.15s; cursor: pointer; }
.chart .bar.dim { opacity: 0.45; }
.chart .tip {
  position: absolute; pointer-events: none; z-index: 5;
  background: rgba(29, 29, 31, 0.94); color: #fff; border-radius: 10px; padding: 8px 10px; font-size: 12px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2); min-width: 150px; opacity: 0; transition: opacity 0.1s;
}
.chart .tip.show { opacity: 1; }
.tip .t { color: rgba(255, 255, 255, 0.7); margin-bottom: 4px; }
.tip .row { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.tip .row span:first-child { display: inline-flex; align-items: center; gap: 6px; color: rgba(255, 255, 255, 0.8); }
.tip .row b { font-weight: 600; }
.tip i { display: inline-block; width: 12px; height: 3px; border-radius: 2px; }
.axis text { fill: var(--ink-3); font-size: 11px; font-family: var(--sans); }
.axis line { stroke: var(--grid); stroke-width: 1; }
.axis .base { stroke: var(--axis-base); }

/* Meter (MTD) */
.meter { display: grid; gap: 8px; }
.meter .row { display: grid; grid-template-columns: 54px 1fr auto; gap: 12px; align-items: center; }
.meter .track { height: 12px; background: var(--meter-track); border-radius: 6px; position: relative; overflow: visible; }
.meter .track i { display: block; height: 100%; border-radius: 6px; background: var(--rev); }
.meter .track i.TS { background: var(--amen); }
.meter .track .pace { position: absolute; top: -4px; bottom: -4px; width: 2px; background: #c8a84b; }
.meter .fig { font-size: 13px; text-align: right; white-space: nowrap; }
.meter .fig small { color: var(--ink-3); display: block; font-size: 12px; }

/* Operation brief */
.ops-list { display: grid; gap: 10px; }
.note { padding: 12px 14px; border-radius: 12px; background: var(--soft); border: 1px solid var(--grid); font-size: 14px; }
.note .meta { font-size: 12px; color: var(--ink-3); margin-bottom: 4px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.note .body { white-space: pre-wrap; word-break: break-word; }
.note .rev { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--ink-2); }
.note .rev b { color: var(--ink); }
.empty { color: var(--ink-3); font-size: 14px; padding: 10px 0; }
.sev { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--ink-3); }
.sev.urgent { background: #d03b3b; } .sev.high { background: #ec835a; } .sev.normal { background: #fab219; } .sev.low { background: #0ca30c; }

.alert-card { border-left: 4px solid var(--alert-edge); background: var(--alert-bg); }
.alert-card .sub { color: var(--warn); }
.alerts { margin: 0; padding-left: 18px; font-size: 13px; overflow-wrap: anywhere; }
.alerts li { margin: 0 0 6px; line-height: 1.45; }
.alerts b.warn { color: var(--warn); } .alerts b.bad { color: var(--bad); } .alerts span.bad { color: var(--bad); white-space: nowrap; }
.error-banner { background: var(--bad-bg); color: var(--bad); padding: 12px 16px; border-radius: 12px; margin-bottom: 16px; }

@media (max-width: 640px) {
  .page { padding: 20px 16px 48px; }
  .card { padding: 16px; border-radius: 16px; }
  .tile { padding: 14px 14px 10px; min-height: 130px; }
  .tile .value { font-size: 24px; }
  .hbar { grid-template-columns: minmax(90px, 1.3fr) 1fr auto; }
  .topbar-inner { gap: 8px; }
  .user .name { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
@media print {
  .topbar, .tabs, .chips { display: none; }
  .panel[hidden] { display: block; }
  .card { box-shadow: none; border: 1px solid var(--grid); break-inside: avoid; }
}

/* Period views */
.linkbtn { border: 0; background: transparent; padding: 0; color: var(--rev); cursor: pointer; font: inherit; white-space: nowrap; }
.linkbtn:hover { text-decoration: underline; }
.tbl td .neg, .neg { color: var(--bad); }
details.note > summary { cursor: pointer; list-style: none; }
details.note > summary::-webkit-details-marker { display: none; }
details.note > summary .meta::before { content: "▸"; margin-right: 4px; color: var(--ink-3); }
details.note[open] > summary .meta::before { content: "▾"; }
details.note[open] > summary { margin-bottom: 4px; }
@media (max-width: 760px) { .topbar-inner .brand span { font-size: 15px; } .brand-logo { height: 38px; }
  /* Row 1: title left, Ngày / Tuần / Tháng right. Row 2: date, branch, user. */
  .topbar-inner .brand { flex: 1 1 auto; min-width: 0; margin-right: 0; }
  .topbar-inner .brand span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #period-seg { margin-left: auto; flex: 0 0 auto; }
  #period-seg button { padding: 6px 11px; }
  .topbar-break { display: block; flex-basis: 100%; height: 0; } }

/* Nhà cung cấp */
.sup-pick { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.sup-pick select { font: inherit; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--hair); background: var(--card); width: 100%; max-width: 420px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 14px; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
details.po { border: 1px solid var(--grid); border-radius: 12px; padding: 10px 14px; background: var(--soft); }
details.po + details.po { margin-top: 8px; }
details.po > summary { cursor: pointer; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; font-size: 14px; }
details.po[open] > summary { margin-bottom: 8px; }
@media (max-width: 380px) {
  .topbar-inner { gap: 8px; }
  .brand-logo { height: 32px; }
  .topbar-inner .brand { gap: 8px; }
  .topbar-inner .brand span { font-size: 14px; }
  #period-seg button { padding: 6px 8px; font-size: 14px; }
}
/* MTD meter: on narrow screens the figures go under the bar instead of beside it */
.meter .row { grid-template-columns: 54px minmax(0, 1fr) auto; }
@media (max-width: 420px) {
  .meter .row { grid-template-columns: 44px minmax(0, 1fr); row-gap: 4px; }
  .meter .fig { grid-column: 2; text-align: left; white-space: normal; }
}

/* ── Dark theme (toggle in the top bar; same surfaces as FO Dashboard) ───────── */
:root[data-theme="dark"] {
  color-scheme: dark;
  --plane: #0d0d0f;
  --card: #141417;
  --card-glass: rgba(20, 20, 23, 0.82);
  --ink: #f0ede8;
  --ink-2: #b4afa8;
  --ink-3: #8a857e;
  --hair: rgba(255, 255, 255, 0.10);
  --grid: rgba(255, 255, 255, 0.08);
  --rev: #3987e5; --exp: #d95926; --amen: #199e70; --rc: #c98500; --ops: #9085e9; --sup: #d55181;
  --good: #5ce08a; --good-bg: rgba(92, 224, 138, 0.12);
  --bad: #f07a7a; --bad-bg: rgba(224, 92, 92, 0.14);
  --warn: #e8c06d; --warn-bg: rgba(232, 192, 109, 0.14);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.5), 0 8px 24px rgba(0, 0, 0, 0.35);
  --hover: rgba(255, 255, 255, 0.06);
  --seg-bg: rgba(255, 255, 255, 0.07);
  --seg-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
  --card-edge: rgba(255, 255, 255, 0.06);
  --soft: #1c1c21;
  --track: #242429;
  --meter-track: #242429;
  --axis-base: #3a3a40;
  --sel-bg: #f01090; --sel-fg: #ffffff;
  --pressed: rgba(57, 135, 229, 0.16);
  --tag-bg: rgba(255, 255, 255, 0.08);
  --btx-bg: rgba(57, 135, 229, 0.18); --btx-fg: #8bb8f0;
  --ts-bg: rgba(25, 158, 112, 0.20); --ts-fg: #6fd3ad;
  --alert-bg: rgba(232, 192, 109, 0.08); --alert-edge: #c99a3d;
  --bars-muted: #3a3a40;
}
:root[data-theme="dark"] .seg button[aria-pressed="true"] { background: #2a2a30; }
:root[data-theme="dark"] .datenav input[type="date"] { background: var(--soft); }
:root[data-theme="dark"] .meter .track i { background: var(--rev); }
:root[data-theme="dark"] .meter .track i.TS { background: var(--amen); }
:root[data-theme="dark"] .error-banner { background: var(--bad-bg); }
/* Theme + language toggles */
.toggles { display: inline-flex; gap: 4px; align-items: center; }
.toggles button { border: 1px solid var(--hair); background: transparent; border-radius: 9px; padding: 5px 9px; cursor: pointer; color: var(--ink-2); font-weight: 600; font-size: 13px; line-height: 1; }
.toggles button:hover { background: var(--hover); color: var(--ink); }

/* P&L table */
.tbl.pl tr.pl-head td { font-size: 11px; font-weight: 700; letter-spacing: 1px; padding-top: 16px; border-bottom: 0; }
.tbl.pl tr.pl-strong td { font-weight: 700; }
.pos { color: var(--good); } .neg { color: var(--bad); }

/* Lịch làm việc (Vận hành, day view) */
.roster-pick { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.roster-pick .clear { margin: 0; min-height: 0; }
.roster-pick .clear[hidden] { display: none; }
.roster-branch { padding: 12px 14px; border-radius: 12px; background: var(--soft); border: 1px solid var(--grid); min-width: 0; }
.roster-head { margin-bottom: 8px; }
.roster-dept { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 10px; padding: 8px 0; border-top: 1px solid var(--grid); font-size: 14px; }
.roster-dname { font-weight: 600; color: var(--ink-2); font-size: 13px; }
.roster-staff { display: grid; gap: 4px; min-width: 0; }
.roster-person { display: flex; justify-content: space-between; gap: 12px; }
.roster-person > span:first-child { min-width: 0; overflow-wrap: anywhere; }
.roster-person > span:last-child { white-space: nowrap; font-size: 13px; }
.roster-off { font-size: 12px; }
@media (max-width: 520px) { .roster-dept { grid-template-columns: 1fr; gap: 4px; } }

/* Chuyên cần (attendance) — counts strip */
.att-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(92px, 1fr)); gap: 8px; margin: 4px 0 10px; }
.att-cell { padding: 10px 12px; border-radius: 12px; background: var(--soft); border: 1px solid var(--grid); min-width: 0; }
.att-cell.good .att-n { color: var(--good); }
.att-cell.warn .att-n { color: var(--warn); }
.att-cell.bad .att-n { color: var(--bad); }
.att-n { font-size: 22px; font-weight: 650; line-height: 1.1; }
.att-l { font-size: 12px; color: var(--ink-2); margin-top: 2px; overflow-wrap: anywhere; }
.att-h3 { font-size: 15px; margin: 18px 0 8px; }
