:root {
  --bg: #F3F4F1; --card: #FFFFFF; --ink: #1B2421; --muted: #56625C; --line: #DDE2DC; --line2: #EEF0EC;
  --nav: #14382C; --nav2: #1F5A45; --navtext: #CFE0D7; --navmuted: #A9C2B6;
  --green: #1F6B4F; --bar: #2F7D5B; --barlight: #A8CDB9;
  --ok: #3D9A6E; --okbg: #E3F1EA; --okfg: #1F6B4F;
  --warn: #D99A2B; --warnbg: #FBEFD9; --warnfg: #8A5300;
  --crit: #C9443A; --critbg: #FBE4E1; --critfg: #A3241B;
  --off: #8A948F; --offbg: #ECEEEB; --offfg: #4B5550;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: 'IBM Plex Sans Thai', 'Noto Sans Thai', 'Sarabun', sans-serif; font-size: 14px; line-height: 1.5; }
a { color: var(--green); }
button, input, select { font: inherit; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.app { min-height: 100vh; display: flex; flex-wrap: wrap; }
.nav { flex: 1 1 220px; max-width: 100%; background: var(--nav); color: #E8F0EC; padding: 20px 14px; display: flex; flex-direction: column; gap: 20px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; }
.brand b { font-size: 18px; color: #fff; display: block; }
.brand span { font-size: 12px; color: var(--navmuted); }
.navlinks { display: flex; flex-direction: column; gap: 4px; }
.navlinks a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 8px; color: var(--navtext); text-decoration: none; min-height: 44px; }
.navlinks a.on { background: var(--nav2); color: #fff; font-weight: 600; }
.navlinks a:hover { color: #fff; }
.navlinks .badge { margin-left: auto; background: var(--crit); color: #fff; font-size: 11px; font-weight: 700; border-radius: 10px; padding: 0 7px; }
.navfoot { margin-top: auto; padding: 0 8px; font-size: 12px; color: var(--navmuted); }
.navfoot button { background: none; border: 1px solid #2E6450; color: var(--navtext); border-radius: 8px; padding: 6px 12px; cursor: pointer; margin-top: 6px; }
.main { flex: 999 1 560px; min-width: 0; padding: 28px; }
.wrap { max-width: 1240px; margin: 0 auto; display: flex; flex-direction: column; gap: 20px; }

.head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; }
.head h1 { margin: 0; font-size: 26px; line-height: 1.25; }
.head p { margin: 4px 0 0; color: var(--muted); }
.chip { display: inline-block; font-size: 12px; font-weight: 600; border-radius: 999px; padding: 3px 11px; }
.chip.ok { color: var(--okfg); background: var(--okbg); } .chip.warn { color: var(--warnfg); background: var(--warnbg); }
.chip.crit { color: var(--critfg); background: var(--critbg); } .chip.offline { color: var(--offfg); background: var(--offbg); }
.chip.demo { color: var(--warnfg); background: var(--warnbg); }

.btn { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; color: var(--ink); background: #fff; border: 1px solid #C9CFC8; border-radius: 8px; padding: 9px 16px; min-height: 42px; cursor: pointer; text-decoration: none; }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.danger { color: var(--critfg); border-color: #E9B9B4; }
.btn.small { min-height: 34px; padding: 5px 12px; font-size: 13px; }

.grid { display: grid; gap: 16px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(min(210px, 100%), 1fr)); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 18px; min-width: 0; }
.card h2 { margin: 0; font-size: 17px; }
.kpi .lab { color: var(--muted); font-size: 13px; }
.kpi .val { font-size: 28px; font-weight: 700; line-height: 1.25; font-variant-numeric: tabular-nums; }
.kpi .val small { font-size: 15px; font-weight: 500; color: var(--muted); }
.kpi .sub { font-size: 13px; color: var(--muted); }

.silos { grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr)); }
.silo { display: flex; gap: 14px; align-items: flex-start; text-decoration: none; color: inherit; }
.silo:hover { border-color: #9AC5AF; }
.silo .info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.silo .top { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.silo h3 { margin: 0; font-size: 16px; }
.silo .kg { font-size: 25px; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.silo .rows { border-top: 1px solid var(--line2); margin-top: 4px; padding-top: 8px; font-size: 13px; display: flex; flex-direction: column; gap: 2px; }

.split { grid-template-columns: repeat(auto-fit, minmax(min(340px, 100%), 1fr)); }
.span2 { grid-column: span 2; }
@media (max-width: 760px) { .span2 { grid-column: auto; } .main { padding: 16px; } }
/* phone / narrow: sidebar becomes a compact top bar with a scrollable row of links */
@media (max-width: 780px) {
  .nav { flex-basis: 100%; padding: 12px 16px; gap: 10px; }
  .navlinks { flex-direction: row; overflow-x: auto; }
  .navlinks a { flex: none; gap: 8px; padding: 8px 12px; min-height: 40px; }
  .navfoot { margin-top: 0; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
  .navfoot br { display: none; }
  .navfoot button { margin-top: 0; }
}

.alert { display: flex; gap: 10px; padding: 11px 12px; border-radius: 10px; margin-top: 10px; }
.alert svg { flex: none; }
.alert.crit { background: var(--critbg); } .alert.warn { background: var(--warnbg); }
.alert .t { font-weight: 600; } .alert.crit .t { color: var(--critfg); } .alert.warn .t { color: var(--warnfg); }

.tabs { display: inline-flex; background: #E6E9E4; border-radius: 10px; padding: 4px; gap: 4px; }
.tabs button { border: none; background: transparent; color: var(--muted); font-weight: 600; border-radius: 8px; padding: 7px 18px; min-height: 38px; cursor: pointer; }
.tabs button.on { background: #fff; color: var(--nav); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips button { border: 1px solid #C9CFC8; background: #fff; color: var(--ink); border-radius: 999px; padding: 7px 15px; min-height: 38px; font-size: 13px; font-weight: 600; cursor: pointer; }
.chips button.on { background: var(--nav); border-color: var(--nav); color: #fff; }
.toolbar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; }

.tablebox { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th { text-align: left; color: var(--muted); font-size: 12px; font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid var(--line2); vertical-align: top; }
td.r, th.r { text-align: right; }
.sharebar { width: 110px; height: 8px; background: #E6E9E4; border-radius: 4px; overflow: hidden; display: inline-block; vertical-align: middle; margin-right: 8px; }
.sharebar i { display: block; height: 8px; background: var(--bar); }

.chart svg { display: block; width: 100%; height: auto; }
.plot { overflow-x: auto; }
@media (max-width: 600px) { .plot svg { min-width: 600px; } } /* keep chart labels readable on phones; the chart scrolls sideways */
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }

form.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr)); gap: 12px; }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label.f input, label.f select { color: var(--ink); border: 1px solid #C9CFC8; border-radius: 8px; padding: 9px 10px; min-height: 42px; background: #fff; }
.inline-form { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.inline-form input { width: 110px; border: 1px solid #C9CFC8; border-radius: 6px; padding: 5px 8px; min-height: 34px; }

.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login .card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 14px; padding: 28px; }
.err { color: var(--critfg); font-size: 13px; min-height: 18px; }
.toast { position: fixed; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); left: 50%; transform: translateX(-50%); background: var(--nav); color: #fff; padding: 10px 18px; border-radius: 10px; font-size: 14px; z-index: 10; }
.empty { padding: 30px; text-align: center; color: var(--muted); }
:focus-visible { outline: 3px solid #8FD1B0; outline-offset: 2px; }
