/* G-NMS UI. Fonts ship with the app so it works on networks with no internet access. */

@font-face { font-family: "Chakra Petch"; font-weight: 500; font-display: swap; src: url(fonts/chakra-petch-latin-500-normal.woff2) format("woff2"); }
@font-face { font-family: "Chakra Petch"; font-weight: 600; font-display: swap; src: url(fonts/chakra-petch-latin-600-normal.woff2) format("woff2"); }
@font-face { font-family: "Chakra Petch"; font-weight: 500; font-display: swap; unicode-range: U+0E00-0E7F; src: url(fonts/chakra-petch-thai-500-normal.woff2) format("woff2"); }
@font-face { font-family: "Chakra Petch"; font-weight: 600; font-display: swap; unicode-range: U+0E00-0E7F; src: url(fonts/chakra-petch-thai-600-normal.woff2) format("woff2"); }
@font-face { font-family: "Sarabun"; font-weight: 400; font-display: swap; src: url(fonts/sarabun-latin-400-normal.woff2) format("woff2"); }
@font-face { font-family: "Sarabun"; font-weight: 600; font-display: swap; src: url(fonts/sarabun-latin-600-normal.woff2) format("woff2"); }
@font-face { font-family: "Sarabun"; font-weight: 400; font-display: swap; unicode-range: U+0E00-0E7F; src: url(fonts/sarabun-thai-400-normal.woff2) format("woff2"); }
@font-face { font-family: "Sarabun"; font-weight: 600; font-display: swap; unicode-range: U+0E00-0E7F; src: url(fonts/sarabun-thai-600-normal.woff2) format("woff2"); }
@font-face { font-family: "JetBrains Mono"; font-weight: 400; font-display: swap; src: url(fonts/jetbrains-mono-latin-400-normal.woff2) format("woff2"); }

:root {
  color-scheme: light;
  --rail: #12323b;
  --rail-ink: #dbe7e6;
  --rail-active: #1e4955;
  --page: #eef1ef;
  --surface: #fafbfa;
  --surface-2: #e3e8e6;
  --ink: #14252b;
  --muted: #526569;
  --line: #d3dbd8;
  --action: #0f6b78;
  --action-ink: #ffffff;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --bar: #2a78d6;
  --good: #0ca30c;
  --warning: #e0a100;
  --serious: #dd6a1f;
  --critical: #d03b3b;
  --unknown: #8a9a9d;
  --shadow: 0 12px 40px rgb(10 35 45 / 0.28);
  --title: "Chakra Petch", "Sarabun", sans-serif;
  --body: "Sarabun", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "Cascadia Mono", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --rail: #0b2027;
    --rail-active: #1a3c47;
    --page: #0f2229;
    --surface: #16303a;
    --surface-2: #1f3f4a;
    --ink: #e8eeec;
    --muted: #a5b6b9;
    --line: #2b4a54;
    --action: #57b9c8;
    --action-ink: #08232b;
    --series-1: #3987e5;
    --series-2: #d95926;
    --bar: #3987e5;
    --shadow: 0 12px 40px rgb(0 0 0 / 0.5);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --rail: #0b2027;
  --rail-active: #1a3c47;
  --page: #0f2229;
  --surface: #16303a;
  --surface-2: #1f3f4a;
  --ink: #e8eeec;
  --muted: #a5b6b9;
  --line: #2b4a54;
  --action: #57b9c8;
  --action-ink: #08232b;
  --series-1: #3987e5;
  --series-2: #d95926;
  --bar: #3987e5;
  --shadow: 0 12px 40px rgb(0 0 0 / 0.5);
}

* { box-sizing: border-box; }
html { font-size: 15px; }
body { margin: 0; background: var(--page); color: var(--ink); font-family: var(--body); line-height: 1.45; }
a { color: var(--action); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { font-family: var(--title); font-weight: 600; margin: 0; line-height: 1.2; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 0.95rem; }
p { margin: 0; }
code, .mono { font-family: var(--mono); font-size: 0.88em; overflow-wrap: anywhere; }
:focus-visible { outline: 2px solid var(--action); outline-offset: 2px; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 196px minmax(0, 1fr); min-height: 100vh; }
.rail { background: var(--rail); color: var(--rail-ink); padding: 18px 10px; display: flex; flex-direction: column; gap: 2px; position: sticky; top: 0; height: 100vh; }
.brand { font-family: var(--title); font-weight: 600; font-size: 1.25rem; padding: 0 10px 16px; display: flex; align-items: center; gap: 9px; color: #fff; }
.brand img { width: 24px; height: 24px; }
.rail a.nav { color: var(--rail-ink); padding: 8px 10px; border-radius: 3px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.rail a.nav:hover { background: var(--rail-active); text-decoration: none; }
.rail a.nav[aria-current="page"] { background: var(--rail-active); color: #fff; box-shadow: inset 3px 0 0 #6fd0dd; }
.rail .pill { background: var(--critical); color: #fff; border-radius: 9px; font-size: 0.75rem; padding: 0 7px; font-weight: 600; }
.rail-foot { margin-top: auto; padding: 10px; font-size: 0.87rem; display: flex; flex-direction: column; gap: 6px; border-top: 1px solid rgb(255 255 255 / 0.13); }
.rail-foot button { all: unset; cursor: pointer; color: var(--rail-ink); text-decoration: underline; text-underline-offset: 2px; }
.rail-foot button:focus-visible { outline: 2px solid #6fd0dd; outline-offset: 2px; }
main { padding: 22px 26px 60px; min-width: 0; }
.page-head { display: flex; flex-wrap: wrap; gap: 10px 16px; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* ---------- controls ---------- */
button.btn, a.btn { font: inherit; font-weight: 600; padding: 6px 12px; border: 1px solid var(--line); border-radius: 3px; background: var(--surface); color: var(--ink); cursor: pointer; display: inline-block; }
button.btn:hover, a.btn:hover { border-color: var(--action); text-decoration: none; }
button.btn.primary { background: var(--action); border-color: var(--action); color: var(--action-ink); }
button.btn.danger { color: var(--critical); }
button.btn.small { padding: 2px 8px; font-size: 0.87rem; font-weight: 400; }
button.btn:disabled { opacity: 0.55; cursor: default; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 3px; padding: 6px 8px; max-width: 100%; }
textarea { width: 100%; min-height: 110px; font-family: var(--mono); font-size: 0.86rem; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; align-items: center; }
.filters input[type="search"], .filters input[type="text"] { min-width: 180px; }
.tabs { display: flex; flex-wrap: wrap; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tabs button { all: unset; cursor: pointer; padding: 7px 13px; border-bottom: 3px solid transparent; color: var(--muted); font-weight: 600; }
.tabs button[aria-selected="true"] { border-color: var(--action); color: var(--ink); }
.tabs button:focus-visible { outline: 2px solid var(--action); }

/* ---------- panels, tables ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); padding: 14px 16px; }
.panel > h2 { margin-bottom: 10px; }
.section { margin-bottom: 18px; }
.panel-head { display: flex; flex-wrap: wrap; gap: 8px; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); }
.panel .table-wrap { border: 0; margin: 0 -16px -14px; }
table { border-collapse: collapse; width: 100%; font-size: 0.93rem; }
th { text-align: left; font-weight: 600; color: var(--muted); padding: 7px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 6px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
.empty { padding: 26px 16px; text-align: center; color: var(--muted); }
.empty p + p { margin-top: 6px; }
.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 16px; margin: 0; }
.kv.section { margin-bottom: 18px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

/* ---------- status marks: colour always comes with a glyph and a word ---------- */
.mark { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.mark::before { content: ""; width: 10px; height: 10px; flex: none; background: var(--mark, var(--unknown)); }
.mark.round::before { border-radius: 50%; }
.mark.tri::before { clip-path: polygon(50% 0, 100% 100%, 0 100%); width: 11px; height: 11px; }
.mark.diamond::before { clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%); width: 12px; height: 12px; }
.mark.hollow::before { background: transparent; border: 2px solid var(--unknown); border-radius: 50%; }
.s-good { --mark: var(--good); }
.s-info { --mark: var(--series-1); }
.s-warning { --mark: var(--warning); }
.s-minor { --mark: var(--warning); }
.s-major { --mark: var(--serious); }
.s-critical { --mark: var(--critical); }
.s-unknown { --mark: var(--unknown); }

/* ---------- the panel wall: one lamp per device, the page's signature ---------- */
.wall-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 18px; align-items: baseline; margin-bottom: 12px; }
.wall-title { font-family: var(--title); font-weight: 600; font-size: 1.7rem; line-height: 1.15; }
.wall { display: grid; grid-template-columns: repeat(auto-fill, minmax(21px, 1fr)); gap: 4px; background: var(--rail); padding: 12px; }
.lamp { aspect-ratio: 1; display: grid; place-items: center; background: #2b6a4f; border-radius: 2px; color: #fff; font-size: 11px; line-height: 1; position: relative; }
.lamp.up { background: #1fae63; }
.lamp.down { background: #e24b4b; }
.lamp.down::after { content: "✕"; font-weight: 600; }
.lamp.unknown { background: transparent; box-shadow: inset 0 0 0 2px #7f979c; }
.lamp.maint { background: repeating-linear-gradient(45deg, #7f979c 0 3px, #385660 3px 6px); }
.lamp.has-alert::before { content: ""; position: absolute; top: -2px; right: -2px; width: 7px; height: 7px; background: #ffc53d; border-radius: 50%; box-shadow: 0 0 0 1.5px var(--rail); }
.lamp:hover, .lamp:focus-visible { outline: 2px solid #fff; outline-offset: 1px; text-decoration: none; z-index: 1; }
.wall-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 8px; font-size: 0.87rem; color: var(--muted); }
.legend-lamp { display: inline-block; width: 12px; height: 12px; vertical-align: -2px; margin-right: 5px; border-radius: 2px; }
.legend-lamp.up { background: #1fae63; }
.legend-lamp.down { background: #e24b4b; }
.legend-lamp.unknown { box-shadow: inset 0 0 0 2px #7f979c; }
.legend-lamp.maint { background: repeating-linear-gradient(45deg, #7f979c 0 3px, #385660 3px 6px); }
.overview { display: grid; grid-template-columns: minmax(0, 3fr) minmax(280px, 2fr); gap: 16px; align-items: start; }
.overview .wide { grid-column: 1 / -1; }
.facts { display: flex; flex-wrap: wrap; gap: 4px 22px; }
.facts b { font-family: var(--title); font-weight: 600; font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.alert-row { padding: 8px 0; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; }
.alert-row:last-child { border-bottom: 0; }
.alert-row .detail { grid-column: 1 / -1; color: var(--muted); font-size: 0.87rem; overflow-wrap: anywhere; }

/* ---------- charts ---------- */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; font-family: var(--body); }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .s1 { stroke: var(--series-1); }
.chart .s2 { stroke: var(--series-2); }
.chart .dot1 { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }
.chart .dot2 { fill: var(--series-2); stroke: var(--surface); stroke-width: 2; }
.chart .crosshair { stroke: var(--muted); stroke-width: 1; }
.chart .barmark { fill: var(--bar); }
.chart .barmark:hover { opacity: 0.8; }
.chart-tip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--line); box-shadow: 0 4px 14px rgb(10 35 45 / 0.2); padding: 5px 9px; font-size: 0.85rem; white-space: nowrap; z-index: 5; font-variant-numeric: tabular-nums; }
.chart-legend { display: flex; gap: 16px; font-size: 0.87rem; margin-bottom: 6px; color: var(--muted); flex-wrap: wrap; }
.swatch { display: inline-block; width: 14px; height: 3px; vertical-align: 3px; margin-right: 6px; }
.swatch.s1 { background: var(--series-1); }
.swatch.s2 { background: var(--series-2); }
.range button { all: unset; cursor: pointer; padding: 2px 9px; color: var(--muted); border: 1px solid var(--line); margin-left: -1px; font-size: 0.87rem; }
.range button[aria-pressed="true"] { background: var(--action); border-color: var(--action); color: var(--action-ink); }
.range button:focus-visible { outline: 2px solid var(--action); }

/* ---------- dialogs, toasts ---------- */
dialog { border: 1px solid var(--line); background: var(--surface); color: var(--ink); padding: 0; width: min(620px, calc(100vw - 32px)); box-shadow: var(--shadow); }
dialog::backdrop { background: rgb(8 28 35 / 0.5); }
dialog.drawer { width: min(760px, calc(100vw - 32px)); }
.dlg-head { padding: 14px 18px 0; display: flex; justify-content: space-between; gap: 12px; align-items: start; }
.dlg-body { padding: 12px 18px; max-height: 70vh; overflow-y: auto; }
.dlg-foot { padding: 10px 18px 16px; display: flex; justify-content: flex-end; gap: 8px; }
.field { margin-bottom: 11px; display: block; }
.field > span { display: block; font-weight: 600; margin-bottom: 3px; }
.field input:not([type="checkbox"]), .field select { width: 100%; }
.field .hint { display: block; font-size: 0.87rem; color: var(--muted); margin-top: 3px; font-weight: 400; }
.field.check { display: flex; gap: 8px; align-items: baseline; }
.field.check > span { font-weight: 400; margin: 0; }
.form-error { color: var(--critical); margin-bottom: 10px; font-weight: 600; overflow-wrap: anywhere; }
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--rail); color: #fff; padding: 9px 14px; box-shadow: var(--shadow); border-left: 4px solid #6fd0dd; }
.toast.error { border-left-color: var(--critical); }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; background: var(--rail); padding: 16px; }
.login form { background: var(--surface); padding: 26px; width: min(380px, 100%); }
.login h1 { margin-bottom: 4px; }
.login p { margin-bottom: 16px; color: var(--muted); }
.login .btn { width: 100%; margin-top: 4px; }

@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .rail { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 8px; }
  .brand { padding: 4px 8px; width: 100%; }
  .rail-foot { margin: 0; border: 0; padding: 8px; flex-direction: row; flex-wrap: wrap; width: 100%; gap: 14px; }
  main { padding: 16px 16px 48px; }
  .overview { grid-template-columns: minmax(0, 1fr); }
}
@media (prefers-reduced-motion: no-preference) {
  .toast { animation: toast-in 0.16s ease-out; }
  @keyframes toast-in { from { transform: translateY(6px); opacity: 0; } }
}
@media (forced-colors: active) {
  .lamp { border: 1px solid CanvasText; }
}
