/* KillSwitch, dressed as Jozary IQ.
 *
 * The palette, typography and shell are lifted from
 * JozaryIQ/governiq/web_settings/templates/web_settings/theme.html so the two
 * products read as one estate. Two rules are carried over deliberately:
 *
 *   - Dark mode is opt-in via data-theme on <html>, never prefers-color-scheme.
 *     This is a work tool that sits beside other windows and should not change
 *     appearance on its own.
 *   - Page-local variables are prefixed (--ks-*). Redefining a shared token
 *     name here would be silently overridden, or would leak out and restyle
 *     something else.
 *
 * KillSwitch keeps its own governing rule on top: colour is reserved for
 * consequence, and --bad means destruction and nothing else.
 */

:root{
  --brand-primary:#000040;
  --brand-accent:#8c6a34;

  --primary:var(--brand-primary);
  --accent:var(--brand-accent);
  --on-primary:#ffffff;
  --on-accent:#ffffff;
  --primary-hover:color-mix(in srgb, var(--primary) 82%, #000);

  --sidebar-bg:#0f1219;
  --sidebar-text:#ffffff;

  --surface:#ffffff;
  --surface-2:#f4f6fa;
  --surface-3:#ffffff;
  --surface-sunk:#eef1f6;
  --border:#e4e8ef;
  --border-2:#d3d9e3;
  /* Borders that outline a control you must perceive to operate need 3:1.
     --border-2 is 1.42:1 on white, which is right for a decorative rule
     and wrong for a button edge, so controls use their own token. */
  --control-border:#828a9c;
  --text-strong:#0f1729;
  --text-body:#3a4557;
  /* Jozary IQ has #6b7688; it measures 4.25:1 on --surface-2, just under
     the 4.5:1 body threshold, and this UI puts muted text on that ground
     in every table header. Darkened one step: 5.07:1 on white, 4.69:1 on
     surface-2. */
  --text-muted:#656f80;
  --shadow-color:rgba(15,23,41,.09);

  --ok:#0f6b3e;      --ok-bg:#e6f4ec;
  --warn:#8a6011;    --warn-bg:#fdf3e2;
  --bad:#b42318;     --bad-bg:#fef3f2;
  --info:#0b5aa8;    --info-bg:#eaf3fc;

  --font-display:'Plus Jakarta Sans','Segoe UI',system-ui,-apple-system,sans-serif;
  --font-body:'Inter','Segoe UI',system-ui,-apple-system,sans-serif;
  --font-mono:'IBM Plex Mono',ui-monospace,SFMono-Regular,Menlo,monospace;

  --sidebar-width:248px;
  --navbar-height:60px;
  color-scheme:light;
}

:root[data-theme="dark"]{
  /* Jozary IQ lifts the brand 37% towards #b9cdf2, which lands at 4.44:1
     on this surface - a hair under. Lifted a little further to clear it. */
  --primary:color-mix(in srgb, var(--brand-primary) 26%, #b9cdf2);
  --accent:color-mix(in srgb, var(--brand-accent) 62%, #ffe6a8);
  --on-primary:#0b1220;
  --on-accent:#17130a;
  --primary-hover:color-mix(in srgb, var(--primary) 82%, #fff);

  --sidebar-bg:#0b1120;
  --surface:#161d2b;
  --surface-2:#0e1420;
  --surface-3:#1e2636;
  --surface-sunk:#121927;
  --border:#293345;
  --border-2:#38445a;
  --control-border:#647291;
  --text-strong:#eaf0f7;
  --text-body:#c2cddb;
  --text-muted:#8a97a9;
  --shadow-color:rgba(0,0,0,.55);

  --ok:#4ec98a;      --ok-bg:#12281d;
  --warn:#e0ac4d;    --warn-bg:#2b2214;
  --bad:#f08a80;     --bad-bg:#2e1917;
  --info:#7fb4ee;    --info-bg:#12203a;
  color-scheme:dark;
}

*{box-sizing:border-box}
html{-webkit-text-size-adjust:100%}
body{
  margin:0;
  background:var(--surface-2);
  color:var(--text-body);
  font:400 15px/1.55 var(--font-body);
  font-feature-settings:'tnum' 1;
}
h1,h2,h3,.mark,.fig b{font-family:var(--font-display);color:var(--text-strong)}
a{color:var(--primary);text-decoration:none}
a:hover{text-decoration:underline}
:focus-visible{outline:2px solid var(--primary);outline-offset:2px;border-radius:4px}

/* ---------- shell: fixed dark sidebar, sticky light navbar ---------- */
.app-layout{display:flex;min-height:100vh}

.sidebar{
  width:var(--sidebar-width);flex-shrink:0;
  background:var(--sidebar-bg);color:var(--sidebar-text);
  position:fixed;top:0;left:0;height:100vh;z-index:200;
  display:flex;flex-direction:column;
  border-right:1px solid rgba(255,255,255,.06);
  transition:transform .3s ease;
}
.sidebar-brand{
  display:flex;align-items:baseline;gap:8px;
  padding:18px 20px;border-bottom:1px solid rgba(255,255,255,.08);
}
.sidebar-brand b{font:700 17px/1 var(--font-display);color:#fff;letter-spacing:-.3px}
.sidebar-brand span{font:500 11.5px/1 var(--font-mono);color:rgba(255,255,255,.5)}
.sidebar-menu{flex:1 1 auto;overflow-y:auto;min-height:0;padding:12px 10px}
.sidebar-label{
  font:600 10.5px/1 var(--font-body);letter-spacing:.9px;text-transform:uppercase;
  color:rgba(255,255,255,.38);padding:14px 10px 7px;
}
.nav-link{
  display:flex;align-items:center;gap:11px;
  padding:10px 12px;margin-bottom:2px;border-radius:8px;
  color:rgba(255,255,255,.76);font-size:14.5px;font-weight:500;
  transition:background .15s ease,color .15s ease;
}
.nav-link:hover{background:rgba(255,255,255,.07);color:#fff;text-decoration:none}
.nav-link[aria-current="page"]{background:rgba(255,255,255,.12);color:#fff;font-weight:600}
.nav-link i{width:17px;text-align:center;font-size:14px;opacity:.85}
.sidebar-foot{
  padding:12px 16px;border-top:1px solid rgba(255,255,255,.08);
  font-size:12px;color:rgba(255,255,255,.45);
}

.app-main{flex:1;min-width:0;margin-left:var(--sidebar-width)}
.navbar{
  height:var(--navbar-height);
  background:var(--surface);
  border-bottom:1px solid var(--border);
  box-shadow:0 1px 4px rgba(0,0,0,.05);
  position:sticky;top:0;z-index:100;
  display:flex;align-items:center;gap:14px;padding:0 26px;
}
.navbar h1{font-size:16.5px;font-weight:700;margin:0;letter-spacing:-.2px}
.nav-tools{margin-left:auto;display:flex;align-items:center;gap:12px;
           font-size:13.5px;color:var(--text-muted)}
.icon-btn{
  display:inline-flex;align-items:center;justify-content:center;
  width:36px;height:36px;border-radius:8px;
  border:1px solid var(--control-border);background:var(--surface);
  color:var(--text-body);cursor:pointer;font-size:14px;
}
.icon-btn:hover{background:var(--surface-sunk);color:var(--primary)}
.sidebar-toggle{display:none}

.main-content{padding:26px;max-width:1240px}

/* ---------- ribbon: the one thing you opened the page to learn ---------- */
.ribbon{
  display:flex;align-items:center;gap:18px;flex-wrap:wrap;
  padding:20px 22px;margin-bottom:22px;
  background:var(--surface);
  border:1px solid var(--border);
  border-left:4px solid var(--ok);
  border-radius:12px;
  box-shadow:0 1px 3px var(--shadow-color);
}
.ribbon[data-state="attention"]{border-left-color:var(--warn)}
.ribbon[data-state="busy"]{border-left-color:var(--info)}
.ribbon h1{margin:0;font-size:20px;font-weight:700;letter-spacing:-.3px;line-height:1.25}
.ribbon p{margin:4px 0 0;color:var(--text-muted);font-size:14px}
.ribbon-figs{display:flex;gap:30px;margin-left:auto}
.fig{text-align:right}
.fig b{display:block;font-size:23px;font-weight:700;line-height:1.1;font-variant-numeric:tabular-nums}
.fig small{display:block;color:var(--text-muted);font-size:12.5px;margin-top:2px}

.sec{
  margin:26px 0 11px;font:600 12px/1 var(--font-body);
  letter-spacing:.7px;text-transform:uppercase;color:var(--text-muted);
}

/* ---------- board of systems ---------- */
.board{
  border:1px solid var(--border);border-radius:12px;overflow:hidden;
  background:var(--surface);box-shadow:0 1px 3px var(--shadow-color);
}
.unit{
  display:grid;
  grid-template-columns:12px minmax(0,.95fr) minmax(0,1fr) 424px;
  align-items:center;gap:18px;
  min-height:66px;padding:13px 22px 13px 18px;
  border-bottom:1px solid var(--border);
}
.unit:last-child{border-bottom:none}
.unit:hover{background:var(--surface-2)}
.unit-2col{grid-template-columns:12px minmax(0,1fr) auto}

.lamp{
  width:9px;height:9px;border-radius:50%;
  background:var(--text-muted);box-shadow:0 0 0 3px var(--surface-sunk);
}
.lamp[data-s="ok"]{background:var(--ok);box-shadow:0 0 0 3px var(--ok-bg)}
.lamp[data-s="warn"]{background:var(--warn);box-shadow:0 0 0 3px var(--warn-bg)}
.lamp[data-s="live"]{background:var(--info);box-shadow:0 0 0 3px var(--info-bg);
                     animation:breathe 1.6s ease-in-out infinite}
.lamp[data-s="off"]{background:transparent;box-shadow:inset 0 0 0 1.5px var(--border-2)}
@keyframes breathe{0%,100%{opacity:1}50%{opacity:.3}}
@media (prefers-reduced-motion:reduce){.lamp[data-s="live"]{animation:none}}

.unit-id{min-width:0}
.unit-id strong{display:block;font-size:15px;font-weight:600;color:var(--text-strong)}
.unit-id .where{
  display:block;margin-top:2px;color:var(--text-muted);font-size:12.5px;
  font-family:var(--font-mono);overflow:hidden;text-overflow:ellipsis;white-space:nowrap;
}
.unit-state{min-width:0;font-size:13.5px;color:var(--text-body);line-height:1.5}
.unit-state .never{color:var(--warn);font-weight:600}
.unit-state .when{color:var(--text-muted)}
.unit-actions{display:flex;gap:6px;align-items:center;justify-content:flex-end}
.unit-actions .row-actions{justify-content:flex-end;flex-wrap:nowrap}
.guard-slot{display:inline-flex;justify-content:flex-end;width:112px;flex:0 0 112px}

/* ---------- controls ---------- */
.btn{
  font:600 13.5px/1 var(--font-body);
  padding:9px 14px;min-height:38px;
  display:inline-flex;align-items:center;gap:7px;
  background:var(--surface);color:var(--text-body);
  border:1px solid var(--control-border);border-radius:8px;
  cursor:pointer;white-space:nowrap;text-decoration:none;
  transition:background .15s ease,border-color .15s ease,color .15s ease;
}
.btn:hover{background:var(--surface-sunk);border-color:var(--primary);
           color:var(--primary);text-decoration:none}
.btn-quiet{background:transparent;color:var(--text-muted)}
.btn-quiet:hover{background:var(--surface-sunk);color:var(--primary)}
.btn-go{background:var(--primary);border-color:var(--primary);color:var(--on-primary)}
.btn-go:hover{background:var(--primary-hover);border-color:var(--primary-hover);
              color:var(--on-primary)}
.btn-stop{background:var(--bad);border-color:var(--bad);color:#fff}
.btn-stop:hover{background:color-mix(in srgb,var(--bad) 84%,#000);
                border-color:color-mix(in srgb,var(--bad) 84%,#000);color:#fff}
:root[data-theme="dark"] .btn-stop{color:#2e1917}
.btn[disabled]{opacity:.5;cursor:not-allowed}

/* The guarded teardown. Kept from KillSwitch's own design: an emergency
   control should not be a button you can brush past. */
.guard{position:relative;display:inline-block}
.guard input{position:absolute;opacity:0;width:0;height:0}
.guard-cover{
  display:inline-flex;align-items:center;gap:8px;
  min-height:38px;padding:9px 13px;white-space:nowrap;
  font:700 12.5px/1 var(--font-body);color:#3d2c05;
  border:1px solid #b8892a;border-radius:8px;cursor:pointer;
  background-color:#e8b84b;
  background-image:repeating-linear-gradient(-45deg,transparent 0 7px,
                   rgba(61,44,5,.34) 7px 14px);
  transition:filter .15s ease;
}
.guard-cover:hover{filter:brightness(1.07)}
.guard input:focus-visible + .guard-cover{outline:2px solid var(--primary);outline-offset:2px}
.guard-inner{display:none;gap:6px;align-items:center}
.guard input:checked ~ .guard-cover{display:none}
.guard input:checked ~ .guard-inner{display:inline-flex}

/* ---------- badges ---------- */
.tag{
  display:inline-block;font-size:11.5px;font-weight:600;line-height:1;
  padding:5px 9px;border-radius:20px;white-space:nowrap;
  border:1px solid var(--border-2);color:var(--text-muted);background:var(--surface-sunk);
}
.tag-dry{color:var(--warn);border-color:transparent;background:var(--warn-bg)}
.tag-armed{color:var(--bad);border-color:transparent;background:var(--bad-bg)}
.tag-ok{color:var(--ok);border-color:transparent;background:var(--ok-bg)}
.tag-live{color:var(--info);border-color:transparent;background:var(--info-bg)}

/* ---------- messages ---------- */
.note{
  padding:13px 16px;margin-bottom:12px;border-radius:10px;font-size:14px;
  background:var(--surface);border:1px solid var(--border);border-left:4px solid var(--primary);
}
.note.error{border-left-color:var(--bad);background:var(--bad-bg);color:var(--bad)}
.note.success{border-left-color:var(--ok);background:var(--ok-bg);color:var(--ok)}
.note.warning{border-left-color:var(--warn);background:var(--warn-bg);color:var(--warn)}

/* ---------- panels, tables, log ---------- */
.slab{
  background:var(--surface);border:1px solid var(--border);border-radius:12px;
  padding:22px;margin-bottom:16px;box-shadow:0 1px 3px var(--shadow-color);
}
.slab h2{margin:0 0 5px;font-size:17px;font-weight:700;letter-spacing:-.2px}
.slab p{margin:0 0 14px;color:var(--text-muted);font-size:14px;max-width:66ch}
.slab p:last-child{margin-bottom:0}
.slab-danger{border-left:4px solid var(--warn)}

.grid{width:100%;border-collapse:collapse;font-size:14px}
.grid th{
  text-align:left;font:600 11.5px/1 var(--font-body);letter-spacing:.6px;
  text-transform:uppercase;color:var(--text-muted);
  padding:12px 16px;border-bottom:1px solid var(--border);background:var(--surface-2);
}
.grid td{padding:12px 16px;border-bottom:1px solid var(--border);vertical-align:middle}
.grid tr:last-child td{border-bottom:none}
.grid tbody tr:hover{background:var(--surface-2)}
.num{font-variant-numeric:tabular-nums}
.right{text-align:right}

.log{
  background:var(--surface-sunk);border:1px solid var(--border);border-radius:10px;
  padding:16px;margin:0;font:400 12.5px/1.65 var(--font-mono);color:var(--text-body);
  white-space:pre-wrap;word-break:break-word;max-height:560px;overflow:auto;
}
.log:empty::before{content:'No output yet.';color:var(--text-muted)}

.kv{display:grid;grid-template-columns:auto 1fr;gap:10px 22px;font-size:14px;margin:0}
.kv dt{color:var(--text-muted)}
.kv dd{margin:0;color:var(--text-body)}
.mono{font-family:var(--font-mono);font-size:13px}
.muted{color:var(--text-muted)}

/* ---------- systems ---------- */
.sysrow{padding:18px 22px;border-bottom:1px solid var(--border)}
.sysrow:last-child{border-bottom:none}
.sysrow-head{display:flex;align-items:center;gap:10px;flex-wrap:wrap;margin-bottom:12px}
.sysrow-head strong{font-size:15.5px;font-weight:700;color:var(--text-strong)}
.sysrow-sub{color:var(--text-muted);font-size:13.5px}
.sysrow-edit{margin-left:auto}
.sysrow-facts{display:grid;grid-template-columns:136px minmax(0,1fr);gap:7px 20px;
              margin:0;font-size:13.5px}
.sysrow-facts dt{color:var(--text-muted)}
.sysrow-facts dd{margin:0;color:var(--text-body);min-width:0;word-break:break-word}
.cap-bit{
  display:inline-block;margin:0 6px 5px 0;padding:4px 10px;border-radius:20px;
  background:var(--surface-sunk);border:1px solid var(--border);
  font-size:12.5px;color:var(--text-body);
}
.cap-none{color:var(--warn);background:var(--warn-bg);border-color:transparent;font-weight:600}

/* ---------- forms ---------- */
.fieldgrid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:18px 22px}
.fld{min-width:0}
.fld-wide{grid-column:1 / -1}
.fld label{display:block;font-size:13.5px;font-weight:500;margin-bottom:7px;color:var(--text-strong)}
.field{
  font:400 14px/1.4 var(--font-body);
  padding:11px 13px;min-height:44px;width:100%;
  background:var(--surface);color:var(--text-body);
  border:1px solid var(--control-border);border-radius:8px;
}
.field:focus{border-color:var(--primary);outline:none;
             box-shadow:0 0 0 3px color-mix(in srgb,var(--primary) 18%,transparent)}
.field::placeholder{color:var(--text-muted)}
.fld textarea.field{line-height:1.55;resize:vertical}
.fld select.field{appearance:none;
  background-image:linear-gradient(45deg,transparent 50%,var(--text-muted) 50%),
                   linear-gradient(135deg,var(--text-muted) 50%,transparent 50%);
  background-position:calc(100% - 18px) 20px,calc(100% - 13px) 20px;
  background-size:5px 5px,5px 5px;background-repeat:no-repeat;padding-right:36px;}
.fld-help{margin:7px 0 0;font-size:12.5px;line-height:1.5;color:var(--text-muted);max-width:70ch}
.fld-err{margin:7px 0 0;font-size:12.5px;color:var(--bad);font-weight:500}
.fld-bad .field{border-color:var(--bad)}
.fld-check{
  display:flex;align-items:center;gap:11px;min-height:46px;padding:0 14px;
  background:var(--surface);border:1px solid var(--control-border);border-radius:8px;cursor:pointer;
}
.fld-check span{font-size:14px;color:var(--text-body);font-weight:500}
.switch{width:17px;height:17px;accent-color:var(--primary);cursor:pointer;flex:0 0 17px}

.empty{text-align:center;padding:54px 22px;color:var(--text-muted)}
.empty h2{color:var(--text-strong);margin:0 0 7px;font-size:18px;font-weight:700}
.empty p{max-width:52ch;margin:0 auto 18px}
.row-actions{display:flex;gap:9px;flex-wrap:wrap;align-items:center}
.spacer{margin-top:18px}
.nowrap{white-space:nowrap}
form.inline{display:inline}

@media (max-width:1000px){
  .sidebar{transform:translateX(-100%)}
  body.sidebar-open .sidebar{transform:translateX(0)}
  .app-main{margin-left:0}
  .sidebar-toggle{display:inline-flex}
  .sidebar-overlay{position:fixed;inset:0;background:rgba(15,23,41,.45);z-index:150;display:none}
  body.sidebar-open .sidebar-overlay{display:block}
}
@media (max-width:820px){
  .unit{grid-template-columns:12px minmax(0,1fr);gap:10px 14px;padding:15px 16px}
  .unit-state,.unit-actions{grid-column:2}
  .unit-actions{justify-content:flex-start}
  .unit-actions .row-actions{justify-content:flex-start;flex-wrap:wrap}
  .guard-slot{width:auto;flex:0 0 auto}
  .ribbon-figs{margin-left:0;width:100%;justify-content:space-between;gap:14px}
  .fig{text-align:left}
  .main-content{padding:16px}
  .navbar{padding:0 16px}
  .fieldgrid{grid-template-columns:minmax(0,1fr)}
  .sysrow-facts{grid-template-columns:minmax(0,1fr);gap:2px}
  .sysrow-facts dt{margin-top:9px;font-size:12.5px}
  .sysrow-edit{margin-left:0}
  .board{overflow-x:auto}
  .grid{min-width:580px}
  .btn,.guard-cover{min-height:44px}
}

/* Grouped board: the machine a system sits on is the first thing you need
   when something is wrong, so it heads its own group rather than being
   repeated on every row. */
.sec{display:flex;align-items:baseline;gap:10px}
.sec-count{font-weight:500;letter-spacing:0;text-transform:none;
           font-size:12px;color:var(--text-muted);opacity:.85}

/* One line each, so every row is the same height and the board scans. The
   full text is the title attribute, and Systems carries the detail. */
.unit-state .when,.unit-state .never,.unit-state .cap{
  display:block;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;
}
.unit-state .cap{color:var(--text-muted);font-size:13px;margin-top:1px}
.unit-tags{display:inline-flex;gap:5px;margin-top:5px}
