/* Magistrala Edge Console - light theme */
:root {
  color-scheme: light;
  --page: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --ink: #0f1a2a;
  --ink-2: #475467;
  --muted: #7a8494;
  --line: #e3e8ef;
  --line-2: #d4dae3;
  --grid: #eceff4;
  --axis: #c9cfd8;
  --brand: #0b6bcb;
  --brand-ink: #0a5aab;
  --brand-soft: #e8f1fc;
  --series: #2a78d6;
  --series-wash: rgba(42, 120, 214, 0.1);
  --on: #16a34a;
  --on-soft: #e7f6ec;
  --good: #0ca30c;
  --good-ink: #006300;
  --warn: #fab219;
  --warn-ink: #8a5a00;
  --warn-soft: #fef6e4;
  --crit: #d03b3b;
  --crit-soft: #fdecec;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 2px 8px rgba(16, 24, 40, 0.04);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, 0.16);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body.kiosk { user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; overscroll-behavior: none; }
body.kiosk .btn, body.kiosk .switch, body.kiosk .nav a { touch-action: manipulation; }
html, body { margin: 0; min-height: 100%; background: var(--page); color: var(--ink); font: 15px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--brand-ink); }
h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -0.01em; }
h1 { font-size: 24px; font-weight: 700; }
h2 { font-size: 17px; font-weight: 650; }
h3 { font-size: 15px; font-weight: 650; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* ------------------------------------------------------------ shell */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--line); padding: 18px 14px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.brand svg { width: 34px; height: 34px; flex: none; }
.brand b { display: block; font-size: 16px; }
.brand span { display: block; font-size: 12px; color: var(--muted); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 9px;
  color: var(--ink-2); text-decoration: none; font-weight: 550;
}
.nav a svg { width: 19px; height: 19px; flex: none; }
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--brand-soft); color: var(--brand-ink); }
.side-foot { margin-top: auto; border-top: 1px solid var(--line); padding-top: 12px; }
.who { display: flex; align-items: center; gap: 10px; padding: 6px 8px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--brand-soft); color: var(--brand-ink);
  display: grid; place-items: center; font-weight: 700; flex: none; text-transform: uppercase;
}
.who-name { font-weight: 600; line-height: 1.2; }
.side-actions { display: flex; gap: 6px; padding: 6px 8px 0; }

.content { min-width: 0; }
.scrim { display: none; }
.main { min-width: 0; padding: 26px 32px 48px; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.page-head p { margin: 4px 0 0; color: var(--muted); }

.topbar { display: none; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side {
    position: fixed; z-index: 40; left: 0; top: 0; width: 272px; transform: translateX(-102%);
    transition: transform 0.2s ease; box-shadow: var(--shadow-lg);
  }
  .shell.nav-open .side { transform: none; }
  .scrim { position: fixed; inset: 0; z-index: 30; background: rgba(15, 26, 42, 0.35); }
  .shell.nav-open .scrim { display: block; }
  .topbar {
    display: flex; position: sticky; top: 0; z-index: 20; align-items: center; gap: 10px;
    background: var(--surface); border-bottom: 1px solid var(--line); padding: 10px 16px;
  }
  .topbar .brand { padding: 0; }
  .topbar .brand span { display: none; }
  .topbar .pill { margin-left: auto; }
  .main { padding: 18px 16px 40px; }
  h1 { font-size: 21px; }
}

/* ------------------------------------------------------------ primitives */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 16px 20px 0; }
.card-head + .card-body { padding-top: 12px; }
.card-body { padding: 16px 20px 18px; }
.grid { display: grid; gap: 16px; }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spacer { flex: 1; }
.grow { flex: 1; min-width: 0; }
.row > .input { flex: 1; width: auto; min-width: 0; }
@media (max-width: 1200px) { .g-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 700px) { .g-2, .g-3, .g-4 { grid-template-columns: 1fr; } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 38px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line-2);
  background: var(--surface); color: var(--ink); font-weight: 600; cursor: pointer; white-space: nowrap;
  text-decoration: none;
}
.btn svg { width: 17px; height: 17px; }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-ink); }
.btn-danger { color: var(--crit); border-color: #f1c4c4; }
.btn-danger:hover { background: var(--crit-soft); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { min-height: 32px; padding: 0 10px; font-size: 13.5px; border-radius: 8px; }
.icon-btn { width: 38px; padding: 0; }

.pill { display: inline-flex; align-items: center; gap: 7px; padding: 4px 11px; border-radius: 999px; font-size: 13px; font-weight: 600; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.pill svg { width: 14px; height: 14px; }
.pill-good { background: #e8f6e8; color: var(--good-ink); }
.pill-warn { background: var(--warn-soft); color: var(--warn-ink); }
.pill-crit { background: var(--crit-soft); color: #a52828; }
.pill-brand { background: var(--brand-soft); color: var(--brand-ink); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; }

.segmented { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 2px; }
.segmented button { border: 0; background: transparent; padding: 6px 12px; border-radius: 7px; font-weight: 600; color: var(--ink-2); cursor: pointer; font-size: 13.5px; }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(16, 24, 40, 0.1); }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.field small { color: var(--muted); font-size: 12.5px; }
.input, select.input {
  min-height: 40px; border: 1px solid var(--line-2); border-radius: 10px; padding: 0 12px; background: var(--surface);
  width: 100%;
}
.input:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
.check { display: flex; align-items: center; gap: 9px; font-weight: 550; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--brand); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 600px) { .form-grid { grid-template-columns: 1fr; } }
.error-box { background: var(--crit-soft); color: #9b2121; border-radius: 10px; padding: 10px 12px; font-size: 14px; }
.note { background: var(--brand-soft); color: var(--brand-ink); border-radius: 10px; padding: 10px 12px; font-size: 14px; }
.note-warn { background: var(--warn-soft); color: var(--warn-ink); }

.days { display: flex; gap: 6px; flex-wrap: wrap; }
.days button { width: 44px; height: 36px; border-radius: 9px; border: 1px solid var(--line-2); background: var(--surface); cursor: pointer; font-weight: 600; font-size: 13px; }
.days button[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: #fff; }

/* switch (relay + rule toggles) */
.switch { position: relative; width: 50px; height: 28px; border-radius: 999px; background: #d3d9e2; border: 0; cursor: pointer; flex: none; transition: background 0.15s; padding: 0; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2); transition: transform 0.15s; }
.switch[aria-checked="true"] { background: var(--on); }
.switch[aria-checked="true"]::after { transform: translateX(22px); }
.switch:disabled { opacity: 0.55; cursor: not-allowed; }

/* ------------------------------------------------------------ dashboard */
.node { display: flex; gap: 14px; align-items: flex-start; }
.node-ico { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; background: var(--surface-2); color: var(--ink-2); flex: none; }
.node-ico svg { width: 22px; height: 22px; }
.node h3 { margin-bottom: 4px; }
.node .meta { color: var(--muted); font-size: 13px; margin-top: 6px; }

.tile { padding: 16px 18px 12px; display: flex; flex-direction: column; gap: 2px; }
.tile-label { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.tile-value { display: flex; align-items: baseline; gap: 5px; margin-top: 4px; }
.tile-value b { font-size: 34px; font-weight: 700; letter-spacing: -0.02em; }
.tile-value span { color: var(--muted); font-weight: 600; }
.tile-spark { height: 40px; margin-top: 6px; }
.tile-foot { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.tile.stale .tile-value b { color: var(--muted); }

.relays-wrap { container-type: inline-size; }
.relays { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@container (min-width: 760px) { .relays { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.relay {
  border: 1.5px solid var(--line); border-radius: 12px; padding: 14px; display: flex; flex-direction: column; gap: 12px;
  background: var(--surface); transition: border-color 0.15s, background 0.15s;
}
.relay.on { border-color: var(--on); background: var(--on-soft); }
.relay.pending { border-color: var(--warn); }
.relay-top { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; }
.relay-top b { font-size: 16px; }
.relay-state { font-weight: 700; font-size: 13px; letter-spacing: 0.04em; color: var(--muted); }
.relay.on .relay-state { color: var(--on); }
.relay.pending .relay-state { color: var(--warn-ink); }
.tag { font-size: 12px; font-weight: 600; color: var(--ink-2); background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: 1px 7px; white-space: nowrap; }

.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: flex; gap: 12px; padding: 11px 0; border-top: 1px solid var(--line); align-items: flex-start; }
.feed li:first-child { border-top: 0; }
.feed-ico { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; flex: none; background: var(--surface-2); color: var(--ink-2); }
.feed-ico svg { width: 17px; height: 17px; }
.feed-ico.c-relay { background: #eaf2fc; color: var(--brand-ink); }
.feed-ico.c-rule { background: #f1eefc; color: #4a3aa7; }
.feed-ico.c-auth { background: #eef6ee; color: var(--good-ink); }
.feed-ico.c-auth-bad { background: var(--crit-soft); color: #a52828; }
.feed-ico.c-device { background: #fdf3ea; color: #9a4a17; }
.feed-ico.c-user { background: #eef0f3; color: var(--ink-2); }
.feed-text { min-width: 0; flex: 1; }
.feed-text .sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.feed-time { color: var(--muted); font-size: 12.5px; white-space: nowrap; }

/* ------------------------------------------------------------ charts */
.chart-card .card-head p { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); }
.chart { position: relative; height: 210px; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart .base-line { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.chart .tick { fill: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.chart .band { fill: var(--series-wash); }
.chart .line { fill: none; stroke: var(--series); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .end-dot { fill: var(--series); stroke: var(--surface); stroke-width: 2; }
.chart .end-label { fill: var(--ink); font-size: 12px; font-weight: 650; }
.chart .cross { stroke: var(--ink-2); stroke-width: 1; shape-rendering: crispEdges; }
.chart .cross-dot { fill: var(--series); stroke: var(--surface); stroke-width: 2; }
.chart .lane-label { fill: var(--ink-2); font-size: 12px; font-weight: 600; }
.chart .lane-bg { fill: var(--surface-2); }
.chart .seg { fill: var(--series); }
.chart .seg:hover, .chart .seg:focus { fill: var(--brand-ink); outline: none; }
.chart .empty { fill: var(--muted); font-size: 13px; }
.chart.loading svg { opacity: 0.45; transition: opacity 0.2s; }
.chart-tip {
  position: absolute; pointer-events: none; z-index: 5; min-width: 130px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow-lg);
  padding: 8px 10px; font-size: 12.5px; opacity: 0; transition: opacity 0.1s;
}
.chart-tip.show { opacity: 1; }
.chart-tip .t { color: var(--muted); margin-bottom: 4px; }
.chart-tip .v { display: flex; align-items: center; gap: 7px; }
.chart-tip .v b { font-size: 15px; }
.chart-tip .key { width: 12px; height: 2px; background: var(--series); border-radius: 1px; }
.chart-tip .r { color: var(--ink-2); margin-top: 2px; }
.timeline { height: 190px; }

.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }

table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th { text-align: left; font-weight: 600; color: var(--ink-2); border-bottom: 1px solid var(--line-2); padding: 9px 10px; white-space: nowrap; background: var(--surface-2); position: sticky; top: 0; }
table.data td { border-bottom: 1px solid var(--line); padding: 9px 10px; vertical-align: middle; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow: auto; max-height: 520px; border-radius: 0 0 var(--radius) var(--radius); }

/* ------------------------------------------------------------ lists */
.list-item { display: flex; gap: 14px; align-items: center; padding: 16px 20px; border-top: 1px solid var(--line); }
.list-item:first-child { border-top: 0; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { font-weight: 650; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.list-item .desc { color: var(--ink-2); margin-top: 3px; }
.list-item .meta { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
@media (max-width: 640px) { .list-item { flex-wrap: wrap; } .list-item .actions { width: 100%; } }

.device-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 13.5px; margin: 14px 0 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.kv dd.row { flex-wrap: nowrap; gap: 4px; }
.kv dd.row .mono { min-width: 0; }

.empty-state { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty-state svg { width: 36px; height: 36px; color: var(--axis); margin-bottom: 8px; }

/* ------------------------------------------------------------ login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(180deg, #eaf2fc 0%, var(--page) 55%); }
.login-card { width: 100%; max-width: 400px; padding: 30px 28px; }
.login-card .brand { padding: 0 0 20px; }
.login-card form { display: flex; flex-direction: column; gap: 14px; }
.login-foot { margin-top: 18px; display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 12.5px; }
.login-foot svg { width: 16px; height: 16px; flex: none; }

/* ------------------------------------------------------------ modal + toasts */
.modal-back { position: fixed; inset: 0; z-index: 60; background: rgba(15, 26, 42, 0.4); display: grid; place-items: center; padding: 16px; }
.modal { width: 100%; max-width: 560px; max-height: calc(100vh - 32px); overflow: auto; background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px 0; }
.modal-body { padding: 16px 22px; display: flex; flex-direction: column; gap: 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 0 22px 20px; flex-wrap: wrap; }
.secret { display: flex; gap: 8px; align-items: center; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.secret code { flex: 1; overflow-wrap: anywhere; font-size: 13px; }

.toasts { position: fixed; z-index: 80; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; max-width: min(380px, calc(100vw - 36px)); }
.toast { background: var(--ink); color: #fff; padding: 11px 14px; border-radius: 11px; box-shadow: var(--shadow-lg); font-weight: 550; font-size: 14px; }
.toast.bad { background: #a52828; }
.toast.good { background: #14532d; }
