/* AMNESIA PULSE — visual system
   Palette per the dataviz reference instance; the two-hue categorical set
   (#2a78d6 / #eb6834 light, #3987e5 / #d95926 dark) passes all six checks
   in both modes. Status colors are the fixed reserved set. */

:root {
  color-scheme: light;
  --page:        #f9f9f7;
  --surface:     #fcfcfb;
  --surface-2:   #f2f1ed;
  --ink-1:       #0b0b0b;
  --ink-2:       #52514e;
  --ink-muted:   #898781;
  --grid:        #e1e0d9;
  --axis:        #c3c2b7;
  --border:      rgba(11,11,11,0.10);
  --s1:          #2a78d6;
  --s1-soft:     #cde2fb;
  --s2:          #eb6834;
  --good:        #0ca30c;
  --good-text:   #006300;
  --warning:     #fab219;
  --serious:     #ec835a;
  --critical:    #d03b3b;
  --brand-a:     #0d366b;
  --brand-b:     #256abf;
  --radius:      14px;
  --shadow:      0 1px 2px rgba(11,11,11,.05), 0 8px 24px -16px rgba(11,11,11,.18);
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page:      #0d0d0d;
    --surface:   #1a1a19;
    --surface-2: #232322;
    --ink-1:     #ffffff;
    --ink-2:     #c3c2b7;
    --ink-muted: #898781;
    --grid:      #2c2c2a;
    --axis:      #383835;
    --border:    rgba(255,255,255,0.10);
    --s1:        #3987e5;
    --s1-soft:   #184f95;
    --s2:        #d95926;
    --good-text: #0ca30c;
    --brand-a:   #0b243f;
    --brand-b:   #16436f;
    --shadow:    0 1px 2px rgba(0,0,0,.4), 0 8px 24px -16px rgba(0,0,0,.7);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page:      #0d0d0d;
  --surface:   #1a1a19;
  --surface-2: #232322;
  --ink-1:     #ffffff;
  --ink-2:     #c3c2b7;
  --ink-muted: #898781;
  --grid:      #2c2c2a;
  --axis:      #383835;
  --border:    rgba(255,255,255,0.10);
  --s1:        #3987e5;
  --s1-soft:   #184f95;
  --s2:        #d95926;
  --good-text: #0ca30c;
  --brand-a:   #0b243f;
  --brand-b:   #16436f;
  --shadow:    0 1px 2px rgba(0,0,0,.4), 0 8px 24px -16px rgba(0,0,0,.7);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink-1);
  font-family: system-ui, -apple-system, "Segoe UI", "Noto Sans Thai", "Sarabun", sans-serif;
  font-size: 14px;
  line-height: 1.55;
}
h1,h2,h3,h4 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--s1); }

.wrap { max-width: 1360px; margin: 0 auto; padding: 0 20px 64px; }

/* ---------- header ---------- */
.masthead {
  background: linear-gradient(135deg, var(--brand-a), var(--brand-b));
  color: #fff;
  padding: 18px 0 16px;
  border-bottom: 1px solid var(--border);
}
.masthead .wrap { padding-bottom: 0; display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.logo { display: flex; align-items: center; gap: 12px; margin-right: auto; }
.logo .mark {
  width: 38px; height: 38px; border-radius: 11px; flex: none;
  background: rgba(255,255,255,.14);
  border: 1px solid rgba(255,255,255,.22);
  display: grid; place-items: center;
}
.logo .mark svg { display: block; }
.logo h1 { font-size: 17px; line-height: 1.2; }
.logo .sub { font-size: 11.5px; opacity: .72; letter-spacing: .06em; text-transform: uppercase; }
.head-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.acct-select {
  background: rgba(255,255,255,.13);
  border: 1px solid rgba(255,255,255,.3);
  color: #fff; border-radius: 9px; padding: 7px 11px; font-size: 13px; font-weight: 550;
}
.acct-select option { color: #111; }
.stamp { font-size: 12px; opacity: .78; }
.icon-btn {
  background: rgba(255,255,255,.13); border: 1px solid rgba(255,255,255,.3);
  color: #fff; border-radius: 9px; width: 34px; height: 34px; display: grid; place-items: center;
}
.icon-btn:hover { background: rgba(255,255,255,.24); }

/* ---------- tabs + filter row ---------- */
.control-bar {
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
  padding: 14px 0 4px; position: sticky; top: 0; z-index: 40;
  background: linear-gradient(var(--page) 78%, transparent);
}
.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 11px; }
.tab {
  border: 0; background: transparent; color: var(--ink-2);
  padding: 8px 15px; border-radius: 8px; font-weight: 600; font-size: 13.5px;
  display: flex; align-items: center; gap: 7px;
}
.tab[aria-selected="true"] { background: var(--surface); color: var(--ink-1); box-shadow: var(--shadow); }
.tab .pill {
  background: var(--critical); color: #fff; border-radius: 99px;
  font-size: 11px; font-weight: 700; padding: 0 6px; min-width: 18px; text-align: center;
}
.seg { display: flex; gap: 6px; margin-right: auto; }
.seg button {
  border: 1px solid var(--border); background: var(--surface); color: var(--ink-2);
  border-radius: 9px; padding: 7px 14px; font-size: 13px; font-weight: 550;
}
.seg button:hover { border-color: var(--s1); color: var(--ink-1); }
.seg button[aria-pressed="true"] { background: var(--s1); border-color: var(--s1); color: #fff; }
.range-note { font-size: 12px; color: var(--ink-muted); }

/* ---------- cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-head {
  display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap;
  padding: 15px 18px 0;
}
.card-head h3 { font-size: 14.5px; }
.card-head .hint { font-size: 12px; color: var(--ink-muted); margin-left: auto; }

.kpis { display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; margin: 14px 0 16px; }
.kpi { padding: 14px 15px 13px; }
.kpi .k-label { font-size: 11.5px; color: var(--ink-2); font-weight: 600; letter-spacing: .01em; display:flex; align-items:center; gap:5px; }
.kpi .k-val { font-size: 25px; font-weight: 680; letter-spacing: -.02em; margin: 4px 0 2px; line-height: 1.1; }
.kpi .k-sub { font-size: 11.5px; color: var(--ink-muted); }
.delta { font-size: 11.5px; font-weight: 650; display: inline-flex; align-items: center; gap: 3px; }
.delta.up   { color: var(--good-text); }
.delta.down { color: var(--critical); }
.delta.flat { color: var(--ink-muted); }

.grid-2 { display: grid; grid-template-columns: 1.55fr 1fr; gap: 12px; margin-bottom: 12px; }
.grid-2b { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }

/* ---------- charts ---------- */
.chart-body { padding: 8px 14px 14px; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; }
.chart .axis-line { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--ink-muted); font-size: 10.5px; font-variant-numeric: tabular-nums; }
.chart .bar { fill: var(--s1); }
.chart .bar.zero { fill: var(--grid); }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .hit:hover + .bar, .chart .bar.on { fill: var(--brand-b); }
.chart .line { fill: none; stroke: var(--s1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .line.alt { stroke: var(--s2); }
.chart .dot { fill: var(--s1); stroke: var(--surface); stroke-width: 2; }
.chart .dot.alt { fill: var(--s2); }
.chart .endlabel { fill: var(--ink-1); font-size: 11px; font-weight: 650; }
.chart .hlabel { fill: var(--ink-2); font-size: 11.5px; }
.chart .hval { fill: var(--ink-1); font-size: 11.5px; font-weight: 650; font-variant-numeric: tabular-nums; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; padding: 0 18px 12px; font-size: 12px; color: var(--ink-2); }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-right: 6px; vertical-align: -1px; }

#tip {
  position: fixed; z-index: 100; pointer-events: none; opacity: 0;
  transition: opacity .1s; background: var(--ink-1); color: var(--page);
  padding: 8px 11px; border-radius: 9px; font-size: 12px; line-height: 1.45;
  box-shadow: 0 8px 24px -8px rgba(0,0,0,.5); max-width: 260px;
}
#tip b { font-weight: 700; }
#tip .t-row { display: flex; justify-content: space-between; gap: 14px; font-variant-numeric: tabular-nums; }

.linkbtn {
  background: none; border: 0; color: var(--s1); font-size: 12px; font-weight: 600;
  padding: 0; text-decoration: underline; text-underline-offset: 2px;
}

/* ---------- tables ---------- */
.tbl-scroll { overflow-x: auto; padding: 4px 6px 6px; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th, table.data td { padding: 9px 11px; text-align: right; white-space: nowrap; }
table.data th:first-child, table.data td:first-child { text-align: left; white-space: normal; min-width: 230px; }
table.data thead th {
  font-size: 11.5px; color: var(--ink-2); font-weight: 650; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--surface); cursor: pointer; user-select: none;
}
table.data thead th:hover { color: var(--s1); }
table.data thead th .arw { opacity: .45; font-size: 9px; }
table.data tbody tr { border-bottom: 1px solid var(--grid); }
table.data tbody tr:last-child { border-bottom: 0; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data td.num { font-variant-numeric: tabular-nums; }
table.data td.name { font-weight: 550; }
.obj-tag {
  display: inline-block; font-size: 10.5px; font-weight: 650; letter-spacing: .02em;
  padding: 1px 7px; border-radius: 99px; background: var(--surface-2); color: var(--ink-2);
  border: 1px solid var(--border); margin-top: 3px;
}
.dot-status { width: 7px; height: 7px; border-radius: 99px; display: inline-block; margin-right: 6px; }
.dot-status.ACTIVE { background: var(--good); }
.dot-status.PAUSED { background: var(--ink-muted); }
.flag { font-weight: 650; }
.flag.bad  { color: var(--critical); }
.flag.warn { color: var(--serious); }
.flag.ok   { color: var(--good-text); }

.notice {
  display: flex; gap: 10px; align-items: flex-start;
  margin: 0 0 12px; padding: 11px 14px; border-radius: 11px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 12.5px; color: var(--ink-2);
}
.notice svg { flex: none; margin-top: 2px; }

/* ---------- agency report ---------- */
.report-head {
  display: flex; gap: 14px; align-items: flex-start; flex-wrap: wrap;
  padding: 18px; margin-bottom: 12px;
}
.report-head .rh-main { flex: 1 1 380px; }
.report-head h2 { font-size: 19px; margin-bottom: 4px; }
.report-head .meta { font-size: 12.5px; color: var(--ink-muted); }
.exports { display: flex; gap: 8px; flex-wrap: wrap; }
.btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--ink-1);
  border-radius: 9px; padding: 8px 13px; font-size: 13px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 7px;
}
.btn:hover { border-color: var(--s1); color: var(--s1); }
.btn.primary { background: var(--s1); border-color: var(--s1); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); color: #fff; }

.scorestrip { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 12px; }
.score { padding: 13px 15px; }
.score .s-label { font-size: 11.5px; font-weight: 650; display: flex; align-items: center; gap: 6px; }
.score .s-val { font-size: 24px; font-weight: 680; letter-spacing: -.02em; margin-top: 3px; }
.score .s-sub { font-size: 11.5px; color: var(--ink-muted); }
.sev-dot { width: 9px; height: 9px; border-radius: 99px; display: inline-block; }
.sev-critical .sev-dot { background: var(--critical); }
.sev-serious  .sev-dot { background: var(--serious); }
.sev-warning  .sev-dot { background: var(--warning); }
.sev-good     .sev-dot { background: var(--good); }

.finding {
  display: grid; grid-template-columns: 26px 1fr; gap: 12px;
  padding: 15px 18px; border-bottom: 1px solid var(--grid);
}
.finding:last-child { border-bottom: 0; }
.finding.off { opacity: .42; }
.finding input[type="checkbox"] { width: 16px; height: 16px; margin-top: 3px; accent-color: var(--s1); }
.f-top { display: flex; gap: 9px; align-items: baseline; flex-wrap: wrap; }
.f-badge {
  font-size: 10.5px; font-weight: 750; letter-spacing: .05em; text-transform: uppercase;
  padding: 2px 8px; border-radius: 99px; color: #fff; flex: none;
}
.f-badge.critical { background: var(--critical); }
.f-badge.serious  { background: var(--serious); color: #3a1a0c; }
.f-badge.warning  { background: var(--warning); color: #3d2a00; }
.f-badge.good     { background: var(--good); }
.f-title { font-weight: 650; font-size: 14px; }
.f-cat { font-size: 11.5px; color: var(--ink-muted); }
.f-money { margin-left: auto; font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; }
.f-money.risk { color: var(--critical); }
.f-money.win  { color: var(--good-text); }
.f-ev { margin: 8px 0 0; padding: 0; list-style: none; font-size: 12.5px; color: var(--ink-2); }
.f-ev li { padding-left: 15px; position: relative; margin-bottom: 2px; }
.f-ev li::before { content: ""; position: absolute; left: 3px; top: 8px; width: 4px; height: 4px; border-radius: 99px; background: var(--axis); }
.f-ev b { color: var(--ink-1); font-variant-numeric: tabular-nums; }
.f-action {
  margin-top: 9px; padding: 9px 12px; border-radius: 9px;
  background: var(--surface-2); font-size: 13px; border-left: 3px solid var(--s1);
}
.f-action b { font-weight: 700; }
.f-assign { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 9px; }
.f-assign label { font-size: 11.5px; color: var(--ink-muted); font-weight: 600; }
.f-assign input, .f-assign select {
  font: inherit; font-size: 12.5px; padding: 4px 8px; border-radius: 7px;
  border: 1px solid var(--border); background: var(--page); color: var(--ink-1);
}
.f-assign input[type="text"] { width: 150px; }

.bench-note { font-size: 12px; color: var(--ink-muted); padding: 0 18px 14px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
/* The table-view twin of a chart holds a wide table — it needs the same
   horizontal containment as .tbl-scroll or it pushes the whole page sideways
   on a phone. */
.tableview { display: none; }
.tableview.on { display: block; overflow-x: auto; padding: 4px 6px 6px; }

.foot {
  margin-top: 26px; padding-top: 16px; border-top: 1px solid var(--border);
  font-size: 12px; color: var(--ink-muted); display: flex; gap: 16px; flex-wrap: wrap;
}

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 14px);
  background: var(--ink-1); color: var(--page); padding: 10px 18px; border-radius: 99px;
  font-size: 13px; font-weight: 600; opacity: 0; pointer-events: none; transition: .18s; z-index: 200;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 1120px) {
  .kpis { grid-template-columns: repeat(3, 1fr); }
  .grid-2, .grid-2b { grid-template-columns: 1fr; }
  .scorestrip { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .kpi .k-val { font-size: 21px; }
  .control-bar { gap: 12px; }
  .seg button { padding: 6px 11px; font-size: 12.5px; }
}

@media print {
  @page { margin: 12mm; size: A4; }
  body { background: #fff; font-size: 11px; }
  .masthead { background: #0d366b !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .control-bar, .exports, .icon-btn, .acct-select, .f-assign select, .linkbtn, #tip, .toast { display: none !important; }
  .card { box-shadow: none; break-inside: avoid; }
  .finding { break-inside: avoid; }
  .finding.off { display: none; }
  .panel[hidden] { display: block !important; }
  .tbl-scroll { overflow: visible; }
}

/* impeccable unifier — browser surfaces + shared mark */
::selection{background:var(--s1);color:#fff}
::-webkit-scrollbar{width:12px;height:12px}
::-webkit-scrollbar-thumb{background:var(--axis);border-radius:7px;border:3px solid var(--page)}
::-webkit-scrollbar-thumb:hover{background:var(--ink-muted)}
html{scrollbar-color:var(--axis) transparent}
:where(a,button,select,input,[tabindex]):focus-visible{outline:2px solid var(--s1);outline-offset:2px;border-radius:7px}
.masthead .mark{background:var(--ink-1)!important}
.masthead .mark svg{stroke:var(--surface)!important}

/* impeccable: unify masthead to plane header (match fb/ig/hub) */
.masthead{background:transparent!important;color:var(--ink-1)!important;border-bottom:1px solid var(--border)!important;padding:22px 0 16px}
.masthead .mark{background:var(--ink-1)!important;border:none!important;width:42px!important;height:42px!important;border-radius:12px!important}
.masthead .mark svg{stroke:var(--surface)!important;width:23px;height:23px}
.logo h1{color:var(--ink-1);font-size:20px}
.logo .sub{color:var(--ink-muted);opacity:1}
.stamp{color:var(--ink-2)!important;opacity:1}
.acct-select{background:var(--surface)!important;border:1px solid var(--border)!important;color:var(--ink-1)!important}
.acct-select option{color:var(--ink-1)}
.icon-btn{background:var(--surface)!important;border:1px solid var(--border)!important;color:var(--ink-2)!important}
.icon-btn:hover{color:var(--ink-1)!important;background:var(--surface-2)!important}

.update-banner{display:flex;align-items:center;gap:9px;font-size:12.5px;color:var(--ink-2);background:var(--surface-2);
  border:1px solid var(--border);border-radius:10px;padding:9px 13px;font-weight:500}
.update-banner svg.ic{width:15px;height:15px;color:var(--s1);flex:none}
.update-banner b{color:var(--s1);font-weight:700}
.update-banner{margin:14px 0 2px}
