/* edgectl operator interface
   ------------------------------------------------------------------
   One stylesheet, no framework, no web fonts. Everything is served from
   this origin so the Content-Security-Policy can stay strict.

   Layout: fixed sidebar, fluid content. Colour carries meaning only in
   combination with text or shape, never on its own.                    */

:root {
  --bg:        #0b0e14;
  --bg-soft:   #111621;
  --surface:   #151b27;
  --surface-2: #1b2231;
  --line:      #232b3b;
  --line-soft: #1a2130;

  --text:      #e8edf5;
  --text-dim:  #9aa7bd;
  --text-mute: #6b7789;

  --accent:    #4f8cff;
  --accent-dim:#2f5fbf;
  --ok:        #35d07f;
  --warn:      #f0b429;
  --bad:       #ff5f57;
  --violet:    #a78bfa;

  --radius:    10px;
  --radius-sm: 6px;
  --shadow:    0 1px 2px rgba(0,0,0,.4), 0 8px 24px -12px rgba(0,0,0,.6);

  --sidebar-w: 232px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6fa; --bg-soft: #ffffff; --surface: #ffffff; --surface-2: #f7f9fc;
    --line: #dfe4ec; --line-soft: #eaeef4;
    --text: #131722; --text-dim: #56607a; --text-mute: #7b8598;
    --shadow: 0 1px 2px rgba(16,24,40,.06), 0 8px 24px -16px rgba(16,24,40,.3);
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font: 400 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
  font-feature-settings: "tnum" 0;
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--accent); color: #fff; }

/* ---------------------------------------------------------------- shell */

.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--bg-soft);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 18px 16px;
  border-bottom: 1px solid var(--line-soft);
}
.brand-mark {
  width: 26px; height: 26px; border-radius: 7px;
  background: linear-gradient(135deg, var(--accent), var(--violet));
  display: grid; place-items: center;
  font-weight: 700; font-size: 13px; color: #fff; letter-spacing: -.02em;
}
.brand-name { font-weight: 600; letter-spacing: -.01em; }
.brand-ver { font-size: 11px; color: var(--text-mute); font-family: var(--mono); }

.nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav-label {
  font-size: 10px; text-transform: uppercase; letter-spacing: .09em;
  color: var(--text-mute); padding: 14px 8px 6px; font-weight: 600;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--text-dim); font-size: 13.5px; font-weight: 500;
  background: none; border: 0; width: 100%; text-align: left;
  cursor: pointer; font-family: inherit; position: relative;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--surface-2); color: var(--text); }
.nav-item.active::before {
  content: ""; position: absolute; left: -10px; top: 8px; bottom: 8px;
  width: 3px; border-radius: 0 3px 3px 0; background: var(--accent);
}
.nav-item svg { width: 16px; height: 16px; flex: 0 0 16px; opacity: .85; }
.nav-item .count {
  margin-left: auto; font-size: 11px; font-family: var(--mono);
  color: var(--text-mute); background: var(--surface); padding: 1px 6px;
  border-radius: 999px; border: 1px solid var(--line);
}

.sidebar-foot { padding: 12px; border-top: 1px solid var(--line-soft); display: grid; gap: 8px; }

/* ---------------------------------------------------------------- main */

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: 56px; display: flex; align-items: center; gap: 14px;
  padding: 0 24px; border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  position: sticky; top: 0; z-index: 20; backdrop-filter: blur(8px);
}
.page-title { font-size: 15px; font-weight: 600; letter-spacing: -.01em; }
.page-sub { font-size: 12.5px; color: var(--text-mute); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.content { padding: 22px 24px 60px; max-width: 1440px; width: 100%; }
.panel { display: none; }
.panel.active { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }

.section-head {
  display: flex; align-items: baseline; gap: 12px;
  margin: 28px 0 12px;
}
.section-head:first-child { margin-top: 0; }
.section-head h2 { font-size: 13px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--text-dim); }
.section-head p { font-size: 12.5px; color: var(--text-mute); }
.section-head .spacer { flex: 1; }

/* ---------------------------------------------------------------- cards */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 12px; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.card-head h3 { font-size: 14px; font-weight: 600; }
.card-head .spacer { flex: 1; }

.grid-cards { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.grid-2 { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }

/* KPI tiles */
.kpis { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.kpi {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px; position: relative; overflow: hidden;
}
.kpi-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-mute); font-weight: 600; display: flex; align-items: center; gap: 6px;
}
.kpi-value {
  font-size: 26px; font-weight: 650; letter-spacing: -.02em; margin-top: 6px;
  font-variant-numeric: tabular-nums; line-height: 1.1;
}
.kpi-unit { font-size: 13px; color: var(--text-mute); font-weight: 500; margin-left: 3px; }
.kpi-foot { font-size: 12px; color: var(--text-mute); margin-top: 4px; }
.kpi.is-bad .kpi-value { color: var(--bad); }
.kpi.is-warn .kpi-value { color: var(--warn); }
.kpi.is-ok .kpi-value { color: var(--ok); }
.kpi-spark { position: absolute; right: 0; bottom: 0; left: 0; height: 34px; opacity: .5; pointer-events: none; }

/* ---------------------------------------------------------------- bits */

.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; flex: 0 0 7px; }
.dot.ok   { background: var(--ok);   box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 18%, transparent); }
.dot.bad  { background: var(--bad);  box-shadow: 0 0 0 3px color-mix(in srgb, var(--bad) 18%, transparent); }
.dot.warn { background: var(--warn); box-shadow: 0 0 0 3px color-mix(in srgb, var(--warn) 18%, transparent); }
.dot.idle { background: var(--text-mute); }

.tag {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 600; letter-spacing: .02em;
  padding: 2px 8px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--text-dim); background: var(--surface-2);
  white-space: nowrap;
}
.tag.ok   { color: var(--ok);   border-color: color-mix(in srgb, var(--ok) 40%, var(--line)); }
.tag.bad  { color: var(--bad);  border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
.tag.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, var(--line)); }
.tag.info { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }

.mono { font-family: var(--mono); font-size: 12.5px; }
.dim { color: var(--text-dim); }
.mute { color: var(--text-mute); font-size: 12.5px; }
.nowrap { white-space: nowrap; }

.banner {
  border-radius: var(--radius); padding: 12px 14px; font-size: 13px;
  border: 1px solid var(--line); background: var(--surface-2);
  display: flex; gap: 10px; align-items: flex-start; margin-bottom: 12px;
}
.banner.warn { border-color: color-mix(in srgb, var(--warn) 45%, var(--line)); background: color-mix(in srgb, var(--warn) 8%, var(--surface)); }
.banner.bad  { border-color: color-mix(in srgb, var(--bad) 45%, var(--line));  background: color-mix(in srgb, var(--bad) 8%, var(--surface)); }
.banner strong { display: block; margin-bottom: 2px; }

/* ---------------------------------------------------------------- forms */

button {
  font: 500 13px/1 inherit; font-family: inherit;
  padding: 8px 14px; border-radius: var(--radius-sm);
  background: var(--accent); color: #fff; border: 1px solid transparent;
  cursor: pointer; display: inline-flex; align-items: center; gap: 7px;
  transition: background .12s, border-color .12s;
}
button:hover { background: var(--accent-dim); }
button:active { transform: translateY(.5px); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.ghost { background: transparent; color: var(--text); border-color: var(--line); }
button.ghost:hover { background: var(--surface-2); border-color: var(--text-mute); }
button.danger { background: transparent; color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
button.danger:hover { background: color-mix(in srgb, var(--bad) 12%, transparent); }
button.sm { padding: 5px 10px; font-size: 12px; }
button svg { width: 14px; height: 14px; }

label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--text-dim); font-weight: 500; }
label.inline { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 13px; font-weight: 400; }
label .hint { font-weight: 400; color: var(--text-mute); font-size: 11.5px; }

input, select, textarea {
  font: 400 13px inherit; font-family: inherit;
  background: var(--bg-soft); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 7px 10px; width: 100%;
  transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}
input[type=checkbox] { width: 15px; height: 15px; accent-color: var(--accent); }
input::placeholder { color: var(--text-mute); }
textarea { resize: vertical; min-height: 70px; font-family: var(--mono); font-size: 12.5px; }
select { cursor: pointer; }

.form-grid { display: grid; gap: 12px 16px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.form-grid.narrow { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); max-width: 720px; }
.form-row { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; }
.actions.end { justify-content: flex-end; }

fieldset { border: 0; margin-top: 20px; }
legend {
  font-size: 11px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-mute); font-weight: 600; margin-bottom: 10px;
  padding-bottom: 6px; border-bottom: 1px solid var(--line-soft); width: 100%;
}
legend .legend-hint { text-transform: none; letter-spacing: 0; font-weight: 400; margin-left: 8px; }

/* ---------------------------------------------------------------- table */

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left; font-size: 11px; font-weight: 600; letter-spacing: .06em;
  text-transform: uppercase; color: var(--text-mute);
  padding: 10px 14px; border-bottom: 1px solid var(--line);
  background: var(--surface-2); white-space: nowrap; position: sticky; top: 0;
}
tbody td { padding: 10px 14px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
td.num { font-variant-numeric: tabular-nums; text-align: right; font-family: var(--mono); font-size: 12.5px; }
.empty { padding: 28px; text-align: center; color: var(--text-mute); font-size: 13px; }

/* ---------------------------------------------------------------- charts */

.chart { width: 100%; height: 150px; display: block; }
.chart-legend { display: flex; gap: 16px; font-size: 12px; color: var(--text-dim); margin-top: 8px; flex-wrap: wrap; }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }

.meter { height: 5px; border-radius: 3px; background: var(--surface-2); overflow: hidden; margin-top: 6px; }
.meter > i { display: block; height: 100%; border-radius: 3px; background: var(--accent); }
.meter.warn > i { background: var(--warn); }
.meter.bad > i { background: var(--bad); }

/* ---------------------------------------------------------------- node */

.node-card { display: flex; flex-direction: column; gap: 10px; }
.node-head { display: flex; align-items: center; gap: 8px; }
.node-name { font-weight: 600; font-size: 14px; }
.node-meta { font-size: 12px; color: var(--text-mute); }
.stat-row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; font-size: 12.5px; }
.stat-row > div { display: flex; justify-content: space-between; gap: 8px; padding: 3px 0; border-bottom: 1px dotted var(--line-soft); }
.stat-row b { font-weight: 600; font-variant-numeric: tabular-nums; font-family: var(--mono); font-size: 12px; }

/* ---------------------------------------------------------------- modal */

dialog {
  border: 1px solid var(--line); border-radius: 14px; padding: 0;
  background: var(--surface); color: var(--text);
  width: min(940px, 94vw); max-height: 88vh; box-shadow: 0 24px 64px -16px rgba(0,0,0,.7);
}
dialog::backdrop { background: rgba(4,6,12,.66); backdrop-filter: blur(3px); }
.modal-head {
  padding: 18px 22px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 10px; position: sticky; top: 0; background: var(--surface); z-index: 2;
}
.modal-head h3 { font-size: 15px; font-weight: 600; }
.modal-body { padding: 20px 22px; overflow-y: auto; max-height: calc(88vh - 132px); }
.modal-foot {
  padding: 14px 22px; border-top: 1px solid var(--line);
  display: flex; gap: 8px; align-items: center; position: sticky; bottom: 0; background: var(--surface);
}
.modal-foot .spacer { flex: 1; }

pre.snippet {
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 12px 14px; font-family: var(--mono); font-size: 12px; overflow-x: auto;
  color: var(--text-dim); line-height: 1.6;
}

/* ---------------------------------------------------------------- toast */

.toast-stack { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast {
  background: var(--surface); border: 1px solid var(--line); border-left: 3px solid var(--ok);
  border-radius: var(--radius-sm); padding: 10px 14px; font-size: 13px;
  box-shadow: var(--shadow); animation: slide .2s ease; max-width: 380px;
}
.toast.bad { border-left-color: var(--bad); }
@keyframes slide { from { opacity: 0; transform: translateX(12px); } to { opacity: 1; transform: none; } }

.hidden { display: none !important; }

/* ---------------------------------------------------------------- login */

.login-page { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.login-card {
  width: min(380px, 100%); background: var(--surface);
  border: 1px solid var(--line); border-radius: 14px; padding: 30px 28px;
  box-shadow: 0 20px 60px -20px rgba(0,0,0,.7);
}
.login-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.login-card h1 { font-size: 17px; font-weight: 600; }
.login-card label { margin-top: 14px; }
.login-card button { width: 100%; justify-content: center; margin-top: 20px; padding: 10px; }
.login-card .error { color: var(--bad); font-size: 13px; margin-top: 12px; min-height: 18px; }
.login-foot { margin-top: 18px; font-size: 11.5px; color: var(--text-mute); text-align: center; line-height: 1.5; }

/* ---------------------------------------------------------------- small */

@media (max-width: 900px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; flex: none; height: auto; position: static; border-right: 0; border-bottom: 1px solid var(--line); }
  .nav { flex-direction: row; overflow-x: auto; padding: 8px; }
  .nav-label, .nav-item .count { display: none; }
  .nav-item.active::before { left: 8px; right: 8px; top: auto; bottom: -8px; width: auto; height: 2px; border-radius: 2px 2px 0 0; }
  .sidebar-foot { display: none; }
  .content { padding: 16px; }
}

/* --------------------------------------------------------------- utility
   The page ships with `style-src 'self'` and no 'unsafe-inline', which
   blocks inline style="" attributes as well as <style> blocks. These few
   utilities exist so the markup never needs one. (Styles set from
   JavaScript through element.style are unaffected by CSP.)              */

.mt-6  { margin-top: 6px; }
.mt-10 { margin-top: 10px; }
.mt-12 { margin-top: 12px; }
.mt-14 { margin-top: 14px; }
.mt-16 { margin-top: 16px; }
.self-end { align-self: end; }
.span-all { grid-column: 1 / -1; }
.flex-1 { flex: 1; min-width: 180px; }
.w-140 { width: 140px; }
.w-port { width: 110px; }
.w-prio { width: 100px; }
.w-on   { width: 70px; }
.w-x    { width: 50px; }
.err { color: var(--bad); font-size: 13px; min-height: 18px; }
.dot.accent { background: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
.swatch.sw-fwd  { background: #4f8cff; }
.swatch.sw-drop { background: #ff5f57; }
