/* Rack Control — design tokens follow the approved mockups (light first, dark via system or toggle). */
:root {
  --bg: #F5F5F7; --side: #FBFBFD; --card: #FFFFFF; --sunk: #F5F5F7; --line: #E5E5EA; --line2: #F0F0F2;
  --ink: #1D1D1F; --ink2: #6E6E73; --ink3: #8E8E93; --active: #E8E8ED;
  --blue: #0066CC; --blue-ink: #004C99; --blue-tint: #EAF2FC;
  --green: #34C759; --green-ink: #1A7F37; --green-tint: #E8F6EC;
  --amber: #FF9F0A; --amber-ink: #A35200; --amber-tint: #FFF4E5;
  --red: #FF3B30; --red-ink: #C4161C; --red-tint: #FDECEC;
  --track: #E8E8ED; --rack: #1C1C1E; --rack-dev: #2C2C2E; --rack-sel: #48484A;
  --shadow: 0 1px 2px rgba(0,0,0,.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000; --side: #0B0B0C; --card: #161618; --sunk: #1E1E21; --line: #2C2C2E; --line2: #232326;
    --ink: #F5F5F7; --ink2: #A1A1A6; --ink3: #8E8E93; --active: #2C2C2E;
    --blue: #4DA3FF; --blue-ink: #8CC2FF; --blue-tint: #0F2740;
    --green: #30D158; --green-ink: #4CD97B; --green-tint: #0E2A17;
    --amber: #FF9F0A; --amber-ink: #FFB340; --amber-tint: #33230A;
    --red: #FF453A; --red-ink: #FF6961; --red-tint: #3A1412;
    --track: #2C2C2E; --rack: #0E0E10; --rack-dev: #232326; --rack-sel: #3A3A3C;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #000000; --side: #0B0B0C; --card: #161618; --sunk: #1E1E21; --line: #2C2C2E; --line2: #232326;
  --ink: #F5F5F7; --ink2: #A1A1A6; --ink3: #8E8E93; --active: #2C2C2E;
  --blue: #4DA3FF; --blue-ink: #8CC2FF; --blue-tint: #0F2740;
  --green: #30D158; --green-ink: #4CD97B; --green-tint: #0E2A17;
  --amber: #FF9F0A; --amber-ink: #FFB340; --amber-tint: #33230A;
  --red: #FF453A; --red-ink: #FF6961; --red-tint: #3A1412;
  --track: #2C2C2E; --rack: #0E0E10; --rack-dev: #232326; --rack-sel: #3A3A3C;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 14px/1.5 Inter, "Noto Sans Thai", system-ui, sans-serif; -webkit-font-smoothing: antialiased; }
a { color: var(--blue); text-decoration: none; } a:hover { color: var(--blue-ink); }
button, input, select, textarea { font: inherit; color: inherit; }
.mono { font-family: "JetBrains Mono", ui-monospace, monospace; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink2); } .small { font-size: 12px; } .tiny { font-size: 11px; }
.hidden { display: none !important; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

/* ---------- shell ---------- */
.shell { display: flex; flex-wrap: wrap; min-height: 100vh; }
.side { flex: 1 1 220px; max-width: 260px; background: var(--side); border-right: 1px solid var(--line); padding: 20px 12px; display: flex; flex-direction: column; gap: 2px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 20px; }
.brand-mark { width: 32px; height: 32px; border-radius: 9px; background: var(--ink); color: var(--bg); display: grid; place-items: center; }
.brand b { font-size: 15px; letter-spacing: -.01em; display: block; }
.nav-sec { font-size: 11px; font-weight: 600; color: var(--ink2); padding: 12px 10px 4px; letter-spacing: .04em; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 0 10px; min-height: 40px; border-radius: 9px; color: var(--ink); }
.nav a svg { stroke: var(--ink2); flex: 0 0 18px; }
.nav a:hover { background: var(--line2); }
.nav a.on { background: var(--active); font-weight: 600; }
.nav a.on svg { stroke: var(--blue); }
.badge { margin-left: auto; font-size: 11px; font-weight: 600; border-radius: 10px; padding: 1px 7px; background: var(--line); color: var(--ink); }
.badge.red { background: var(--red-ink); color: #fff; }
.me { margin-top: auto; display: flex; align-items: center; gap: 10px; padding: 12px 10px; border-top: 1px solid var(--line); }
.avatar { width: 32px; height: 32px; border-radius: 16px; background: var(--blue); color: #fff; font-weight: 600; display: grid; place-items: center; flex: 0 0 32px; }
.main:focus { outline: none; }
.main { flex: 999 1 560px; min-width: 0; padding: 24px 32px 56px; display: flex; flex-direction: column; gap: 20px; }
@media (max-width: 820px) { .side { position: static; height: auto; max-width: none; } .main { padding: 16px; } }

/* ---------- page header ---------- */
.ph { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 16px; }
.ph h1 { margin: 0; font-size: 30px; font-weight: 700; letter-spacing: -.025em; }
.ph .sub { font-size: 13px; color: var(--ink2); }
.tools { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }

/* ---------- primitives ---------- */
.card { background: var(--card); border-radius: 18px; padding: 22px 24px; box-shadow: var(--shadow); min-width: 0; }
.card h2 { margin: 0; font-size: 17px; font-weight: 600; }
.card-h { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.grid { display: grid; gap: 20px; grid-template-columns: repeat(auto-fit, minmax(min(380px, 100%), 1fr)); }
.row { display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start; }
.grow { flex: 999 1 600px; min-width: 0; } .aside { flex: 1 1 340px; min-width: 0; }
.btn { min-height: 40px; padding: 0 16px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); font-size: 13px; font-weight: 500; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; }
.btn:hover { background: var(--line2); }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { background: var(--red-tint); border-color: transparent; color: var(--red-ink); font-weight: 600; }
.btn.pill { border-radius: 20px; border: 0; background: var(--line2); font-weight: 600; min-height: 34px; }
.btn.small { min-height: 32px; padding: 0 12px; font-size: 12px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.seg { display: inline-flex; padding: 3px; border-radius: 10px; background: var(--active); }
.seg button { min-height: 32px; padding: 0 12px; border: 0; border-radius: 8px; background: transparent; font-size: 13px; cursor: pointer; }
.seg button.on { background: var(--card); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.pill-status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 12px; }
.dot { width: 8px; height: 8px; border-radius: 4px; display: inline-block; flex: 0 0 8px; }
.t-ok { color: var(--green-ink); background: var(--green-tint); } .t-warn { color: var(--amber-ink); background: var(--amber-tint); }
.t-crit { color: var(--red-ink); background: var(--red-tint); } .t-info { color: var(--blue); background: var(--blue-tint); } .t-mute { color: var(--ink2); background: var(--line2); }
.d-ok { background: var(--green); } .d-warn { background: var(--amber); } .d-crit { background: var(--red); } .d-info { background: var(--blue); } .d-mute { background: var(--ink3); }
.sev { flex: 0 0 44px; align-self: flex-start; text-align: center; font-size: 11px; font-weight: 700; border-radius: 8px; padding: 4px 0; }
.list-row { display: flex; align-items: center; gap: 14px; padding: 12px 0; border-top: 1px solid var(--line2); }
.list-row:first-child { border-top: 0; }
.stack { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.t-title { font-size: 15px; font-weight: 600; } .t-desc { font-size: 13px; color: var(--ink2); line-height: 1.45; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.kpi { background: var(--sunk); border-radius: 14px; padding: 16px 18px; display: flex; flex-direction: column; gap: 6px; }
.kpi.raised { background: var(--card); box-shadow: var(--shadow); }
.kpi .v { font-size: 30px; font-weight: 600; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi .u { font-size: 15px; font-weight: 500; color: var(--ink2); margin-left: 4px; }
.bar { flex: 1 1 auto; height: 6px; border-radius: 3px; background: var(--track); overflow: hidden; }
.bar > i { display: block; height: 6px; border-radius: 3px; }
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; min-width: 640px; }
table.t th { text-align: left; font-size: 12px; font-weight: 500; color: var(--ink2); padding: 0 12px 8px 0; white-space: nowrap; }
table.t td { padding: 11px 12px 11px 0; border-top: 1px solid var(--line2); vertical-align: middle; }
table.t td.r, table.t th.r { text-align: right; }
.empty { padding: 24px 0; text-align: center; color: var(--ink2); font-size: 13px; }
input.in, select.in, textarea.in { min-height: 40px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); width: 100%; }
textarea.in { min-height: 220px; font-family: "JetBrains Mono", ui-monospace, monospace; font-size: 12px; }
label.f { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 500; }
.form { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); align-items: end; }
.switch { width: 44px; height: 26px; border: 0; border-radius: 13px; background: #D1D1D6; padding: 3px; display: flex; justify-content: flex-start; cursor: pointer; flex: 0 0 44px; }
.switch[aria-pressed="true"] { background: var(--green); justify-content: flex-end; }
.switch i { width: 20px; height: 20px; border-radius: 10px; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.2); display: block; }
pre.cli { background: var(--sunk); border-radius: 10px; padding: 12px 14px; font: 12px/1.5 "JetBrains Mono", monospace; overflow-x: auto; margin: 8px 0 0; white-space: pre; }
.banner { border-radius: 12px; padding: 12px 16px; font-size: 14px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.chip { display: inline-block; font-size: 11px; font-weight: 600; border-radius: 6px; padding: 2px 7px; background: var(--line2); color: var(--ink); }

/* ---------- overview ---------- */
.summary p { margin: 6px 0; font-size: 20px; line-height: 1.5; font-weight: 500; letter-spacing: -.01em; max-width: 820px; }
.ev { display: flex; gap: 14px; padding: 9px 0; }
.ev .when { flex: 0 0 44px; font-size: 12px; color: var(--ink2); padding-top: 2px; }
.ev .dot { margin-top: 7px; }

/* ---------- rack ---------- */
.rack { margin: 0; flex: 0 1 400px; min-width: 300px; background: var(--rack); border-radius: 16px; padding: 16px 14px 18px 8px; box-shadow: 0 10px 30px rgba(0,0,0,.12); }
.slot { display: flex; gap: 8px; padding-bottom: 3px; }
.slot .u { flex: 0 0 24px; font: 10px "JetBrains Mono", monospace; color: #8E8E93; text-align: right; padding-top: 5px; }
.rdev { flex: 1 1 auto; height: 100%; min-width: 0; display: flex; align-items: center; gap: 10px; padding: 0 12px; border: 0; border-radius: 5px; background: var(--rack-dev); color: #fff; text-align: left; cursor: pointer; box-shadow: inset 0 1px 0 rgba(255,255,255,.06); }
.rdev.on { background: var(--rack-sel); box-shadow: 0 0 0 2px #0A84FF; }
.rdev .nm { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rdev .rl { font: 10px "JetBrains Mono", monospace; color: #AEAEB2; letter-spacing: .06em; }
.rdev .ip { margin-left: auto; font: 11px "JetBrains Mono", monospace; color: #AEAEB2; }
.rempty { flex: 1 1 auto; height: 100%; border: 1px dashed #48484A; border-radius: 5px; display: grid; place-items: center; font-size: 11px; color: #8E8E93; }
.led { width: 7px; height: 7px; border-radius: 4px; flex: 0 0 7px; }
.led.green { background: #30D158; } .led.amber { background: #FF9F0A; } .led.red { background: #FF453A; } .led.grey { background: #8E8E93; }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; }
.kv > div { background: var(--sunk); border-radius: 10px; padding: 10px 14px; display: flex; flex-direction: column; gap: 2px; }
.kv span:first-child { font-size: 12px; color: var(--ink2); }
.kv span:last-child { font-size: 15px; font-weight: 500; }

/* ---------- network ---------- */
.flow { display: grid; grid-template-columns: minmax(220px,1.2fr) 28px minmax(170px,.9fr) 28px minmax(170px,.9fr) 28px minmax(260px,1.4fr); align-items: center; min-width: 1000px; }
.nbox { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; }
.nbox.dark { background: #1D1D1F; color: #fff; border: 0; border-radius: 16px; padding: 18px 16px; }
.nbox.dash { background: var(--sunk); border: 1px dashed var(--ink3); border-radius: 16px; padding: 18px 16px; }

/* ---------- overlays ---------- */
.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 50; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; box-shadow: 0 10px 30px rgba(0,0,0,.15); display: flex; gap: 10px; align-items: flex-start; font-size: 13px; }
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: grid; place-items: center; z-index: 60; padding: 16px; }
.modal { background: var(--card); border-radius: 18px; padding: 24px; width: min(440px, 100%); box-shadow: 0 20px 60px rgba(0,0,0,.25); display: flex; flex-direction: column; gap: 14px; }
.modal h3 { margin: 0; font-size: 18px; }
.palette { position: fixed; inset: 0; background: rgba(0,0,0,.3); z-index: 70; display: flex; justify-content: center; padding-top: 12vh; }
.palette .box { background: var(--card); border-radius: 16px; width: min(560px, calc(100vw - 32px)); max-height: 60vh; overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.palette input { border: 0; border-bottom: 1px solid var(--line); border-radius: 0; min-height: 52px; font-size: 16px; padding: 0 18px; width: 100%; background: transparent; }
.palette .item { display: flex; gap: 10px; padding: 10px 18px; cursor: pointer; }
.palette .item:hover, .palette .item.on { background: var(--line2); }
