@font-face { font-family: "Plex Thai"; font-weight: 400; font-display: swap; src: url(fonts/plex-thai-thai-400.woff2) format("woff2"); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: "Plex Thai"; font-weight: 400; font-display: swap; src: url(fonts/plex-thai-latin-400.woff2) format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+20AC, U+2122; }
@font-face { font-family: "Plex Thai"; font-weight: 500; font-display: swap; src: url(fonts/plex-thai-thai-500.woff2) format("woff2"); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: "Plex Thai"; font-weight: 500; font-display: swap; src: url(fonts/plex-thai-latin-500.woff2) format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+20AC, U+2122; }
@font-face { font-family: "Plex Thai"; font-weight: 600; font-display: swap; src: url(fonts/plex-thai-thai-600.woff2) format("woff2"); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: "Plex Thai"; font-weight: 600; font-display: swap; src: url(fonts/plex-thai-latin-600.woff2) format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+20AC, U+2122; }
@font-face { font-family: "Plex Thai"; font-weight: 700; font-display: swap; src: url(fonts/plex-thai-thai-700.woff2) format("woff2"); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: "Plex Thai"; font-weight: 700; font-display: swap; src: url(fonts/plex-thai-latin-700.woff2) format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+20AC, U+2122; }

:root {
  color-scheme: light;
  /* brand: Bangkok Hospital Pattaya navy/red, SN Service Solutions red/navy */
  --brand-navy: #092d74;
  --brand-red: #b11e29;
  --sn-red: #cf0024;
  --sn-navy: #282a75;
  --bg: #f3f5f9;
  --surface-1: #ffffff;
  --surface-2: #f7f8fb;
  --border: #e1e5ee;
  --text-primary: #0e1626;
  --text-secondary: #4a5468;
  --text-muted: #737d92;
  --grid: #edf0f5;
  --tab-active: var(--brand-navy);
  --good: #0ca30c; --warning: #fab219; --serious: #ec835a; --critical: #d03b3b;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #008300; --s7: #6250d6;
  --seq-100: #cde2fb; --seq-250: #86b6ef; --seq-400: #3987e5; --seq-550: #1c5cab; --seq-700: #0d366b;
  --bar-single: #092d74;
  --shadow: 0 1px 2px rgba(14, 22, 38, .05), 0 4px 14px rgba(14, 22, 38, .05);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #06112b; --surface-1: #0c1a3d; --surface-2: #102250; --border: #1d3266;
    --text-primary: #eef3ff; --text-secondary: #b6c4e6; --text-muted: #8597c2; --grid: #172a57;
    --tab-active: #8fb2ff;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #0ca30c; --s7: #9085e9;
    --bar-single: #5b8ef0;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #06112b; --surface-1: #0c1a3d; --surface-2: #102250; --border: #1d3266;
  --text-primary: #eef3ff; --text-secondary: #b6c4e6; --text-muted: #8597c2; --grid: #172a57;
  --tab-active: #8fb2ff;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #0ca30c; --s7: #9085e9;
  --bar-single: #5b8ef0;
  --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text-primary);
  font-family: "Plex Thai", "Leelawadee UI", "Segoe UI", Tahoma, sans-serif; font-size: 15px; line-height: 1.5;
}
h1, h2, h3 { margin: 0; line-height: 1.3; }
h2 { font-size: 16px; font-weight: 600; }
h3 { font-size: 14px; font-weight: 600; margin: 18px 0 8px; color: var(--text-secondary); }

/* ---- brand header ---- */
.brandbar {
  display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 12px 28px; background: #ffffff; color: #0e1626;
}
.brand-left, .brand-right { display: flex; align-items: center; gap: 18px; }
.logo-bph { height: 46px; width: auto; }
.logo-sn { height: 52px; width: 52px; }
.brand-title { border-left: 1px solid #e1e5ee; padding-left: 18px; }
.brand-title h1 { font-size: 20px; font-weight: 700; color: var(--brand-navy); letter-spacing: .2px; }
.brand-title p { margin: 0; font-size: 13px; color: #4a5468; }
.strip { height: 5px; background: linear-gradient(90deg, #ff0000 0%, #b11e29 25%, #701236 50%, #282a75 75%, #002060 100%); }
.icon-btn { border: 1px solid #e1e5ee; background: #fff; color: #092d74; border-radius: 8px; width: 34px; height: 34px; cursor: pointer; font-size: 16px; }

.status { padding: 6px 14px; border-radius: 999px; font-size: 13px; font-weight: 600; border: 1px solid #e1e5ee; background: #fff; color: #0e1626; }
.status::before { content: "●  "; }
.status--ok::before { color: var(--good); }
.status--wait::before { color: #9aa3b5; }
.status--late::before { color: var(--warning); }
.status--down { background: var(--critical); color: #fff; border-color: var(--critical); }
.status--down::before { content: "⚠  "; }

/* ---- tabs ---- */
.tabs {
  display: flex; gap: 4px; align-items: center; padding: 0 20px; background: var(--surface-1);
  border-bottom: 1px solid var(--border); overflow-x: auto; position: sticky; top: 0; z-index: 5;
}
.tabs button {
  font: inherit; font-weight: 500; color: var(--text-secondary); background: none; border: 0;
  padding: 14px 14px 12px; border-bottom: 3px solid transparent; cursor: pointer; white-space: nowrap;
}
.tabs button:hover { color: var(--text-primary); }
.tabs button.active { color: var(--tab-active); border-bottom-color: var(--brand-red); font-weight: 600; }
.tabs-right { margin-left: auto; padding-left: 12px; }
.month-pick { font-size: 13px; color: var(--text-secondary); white-space: nowrap; }

main { max-width: 1440px; margin: 0 auto; padding: 22px 28px; }
.tab { display: none; gap: 20px; }
.tab.active { display: grid; }

/* ---- cards & kpis ---- */
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px; padding: 18px 20px; min-width: 0; box-shadow: var(--shadow); }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.card > h2 { margin-bottom: 12px; }
.hint { font-size: 12px; color: var(--text-muted); }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.grid-2--wide-left { grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.kpi { background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; display: grid; gap: 2px; box-shadow: var(--shadow); position: relative; overflow: hidden; }
.kpi::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--brand-navy); }
.kpi--hero::before { background: var(--brand-red); }
.kpi-label { color: var(--text-secondary); font-size: 13px; }
.kpi-value { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.3px; }
.kpi-sub { color: var(--text-muted); font-size: 12px; }
.up { color: var(--critical); font-weight: 600; }
.down { color: var(--good); font-weight: 600; }

.chart-box { position: relative; height: 300px; }
.chart-box--tall { height: 360px; }
.note { color: var(--text-muted); font-size: 12px; margin: 10px 0 0; }
.controls { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; font-size: 13px; color: var(--text-secondary); }
select, input[type=month], input[type=number], input[type=text], input[type=password], textarea {
  font: inherit; font-size: 14px; color: var(--text-primary); background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 5px 9px;
}
textarea { width: 100%; font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
.chk { display: flex; gap: 6px; align-items: center; }

/* ---- tables ---- */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; text-align: left; }
th { color: var(--text-secondary); font-weight: 600; font-size: 13px; background: var(--surface-2); }
table.num td:not(:first-child), table.num th:not(:first-child) { text-align: right; }
table.compact td, table.compact th { padding: 5px 8px; font-size: 13px; }
tr.total td { font-weight: 700; border-top: 2px solid var(--text-secondary); }
tr.sub td { color: var(--text-secondary); }
tr.grand td { font-weight: 700; font-size: 16px; background: color-mix(in srgb, var(--brand-navy) 7%, transparent); }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 8px; vertical-align: 0; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; border: 1px solid var(--border); color: var(--text-secondary); }
.flag { font-weight: 600; }
.flag--ok { color: var(--good); } .flag--warn { color: #b77c00; } .flag--bad { color: var(--critical); }
:root[data-theme="dark"] .flag--warn { color: var(--warning); }
.stale { color: var(--critical); font-weight: 600; }

/* ---- overview bars ---- */
.hbars { display: grid; gap: 10px; }
.hbar { display: grid; grid-template-columns: 90px 1fr 130px; align-items: center; gap: 10px; font-size: 14px; }
.hbar-track { height: 14px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.hbar-fill { height: 100%; border-radius: 0 4px 4px 0; }
.hbar-val { text-align: right; font-variant-numeric: tabular-nums; color: var(--text-secondary); }
.hbar-val b { color: var(--text-primary); }

.insights { margin: 0; padding: 0; list-style: none; display: grid; gap: 10px; }
.insights li { padding: 10px 12px; border-radius: 8px; background: var(--surface-2); border-left: 3px solid var(--brand-navy); font-size: 14px; }
.insights li.warn { border-left-color: var(--warning); }
.insights li.bad { border-left-color: var(--critical); }
.insights li.good { border-left-color: var(--good); }
.method { margin: 0; padding-left: 18px; display: grid; gap: 8px; font-size: 14px; color: var(--text-secondary); }

/* ---- heatmap ---- */
.heatmap { display: grid; gap: 2px; font-size: 11px; overflow-x: auto; }
.hm-row { display: grid; grid-template-columns: 64px repeat(24, minmax(18px, 1fr)); gap: 2px; align-items: center; }
.hm-day { color: var(--text-secondary); white-space: nowrap; }
.hm-cell { height: 16px; border-radius: 3px; }
.hm-head { color: var(--text-muted); text-align: center; }
.heat-legend { display: flex; align-items: center; gap: 10px; margin-top: 10px; font-size: 12px; color: var(--text-muted); }
.heat-ramp { width: 220px; height: 10px; border-radius: 3px; background: linear-gradient(90deg, var(--seq-100), var(--seq-250), var(--seq-400), var(--seq-550), var(--seq-700)); }

/* ---- simulator ---- */
.sim label { font-size: 14px; color: var(--text-secondary); }
.sim input[type=range] { width: 100%; accent-color: var(--brand-navy); margin: 8px 0 12px; }
.sim-out { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.sim-out div { background: var(--surface-2); border-radius: 8px; padding: 10px; display: grid; }
.sim-out span { font-size: 12px; color: var(--text-muted); }
.sim-out b { font-size: 22px; font-variant-numeric: tabular-nums; }
.sim-out small { color: var(--text-muted); font-size: 12px; }

/* ---- meters ---- */
.meters { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.meter { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; background: var(--surface-2); }
.meter h3 { margin: 0 0 2px; font-size: 15px; color: var(--text-primary); }
.meter .meta { color: var(--text-muted); font-size: 12px; margin-bottom: 8px; }
.meter table th, .meter table td { padding: 4px 6px; font-size: 13px; background: none; }

/* ---- settings ---- */
.form { display: grid; grid-template-columns: 1fr 140px; gap: 8px 12px; align-items: center; font-size: 14px; }
.form input { text-align: right; }
.form .wide { grid-column: 1 / -1; }
.form .wide input { width: 100%; text-align: left; }
table.edit input { width: 120px; text-align: right; }
table.edit input.m { width: 165px; text-align: left; }
.btn, .btn-light { font: inherit; border-radius: 8px; padding: 8px 16px; cursor: pointer; font-weight: 600; }
.btn { background: var(--brand-navy); color: #fff; border: 0; }
.btn-light { background: var(--surface-2); color: var(--text-primary); border: 1px solid var(--border); margin-top: 10px; }
.del { background: none; border: 0; color: var(--critical); cursor: pointer; font-size: 16px; }
.save-bar { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
#save-msg.ok { color: var(--good); font-weight: 600; } #save-msg.err { color: var(--critical); font-weight: 600; }

/* ---- tooltip ---- */
.tip { position: fixed; pointer-events: none; z-index: 50; background: var(--surface-1); color: var(--text-primary); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 10px; font-size: 12px; box-shadow: 0 4px 16px rgba(0,0,0,.15); display: none; white-space: nowrap; }

.foot { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; max-width: 1440px; margin: 0 auto; padding: 4px 28px 28px; color: var(--text-muted); font-size: 12px; }

@media screen and (max-width: 980px) {
  .grid-2, .grid-2--wide-left { grid-template-columns: minmax(0, 1fr); }
}
@media screen and (max-width: 600px) {
  .brandbar, main, .foot { padding-left: 16px; padding-right: 16px; }
  .brand-title { display: none; }
  .logo-bph { height: 36px; }
  .logo-sn { height: 40px; width: 40px; }
  .kpi-value { font-size: 24px; }
  .chart-box { height: 260px; }
  .hbar { grid-template-columns: 70px 1fr 100px; }
  .sim-out { grid-template-columns: 1fr; }
}
