/* ShamCore Agent — local UI. Targets Chrome 109 / Firefox ESR 115 (Windows 7 lab PCs): CSS variables, flexbox and
   grid only — no :has(), nesting or container queries. Lab colours come from /branding.css (--brand-*). */

@font-face { font-family: "Kufi"; font-weight: 400; font-display: swap; src: url(fonts/NotoKufiArabic-Regular.woff2) format("woff2"); }
@font-face { font-family: "Kufi"; font-weight: 500; font-display: swap; src: url(fonts/NotoKufiArabic-Medium.woff2) format("woff2"); }
@font-face { font-family: "Kufi"; font-weight: 600; font-display: swap; src: url(fonts/NotoKufiArabic-SemiBold.woff2) format("woff2"); }
@font-face { font-family: "Kufi"; font-weight: 700; font-display: swap; src: url(fonts/NotoKufiArabic-Bold.woff2) format("woff2"); }
@font-face { font-family: "JBMono"; font-weight: 400 700; font-display: swap; src: url(fonts/JetBrainsMono-latin.woff2) format("woff2"); }

:root {
  --brand-dark: #0f766e; --brand-mid: #0d9488; --brand-soft: #ccfbf1; --brand-tint: #f0fdfa;
  --brand-ink: #0a4d48; --brand-line: #a9e3da;
  --paper: #f4f6f5; --surface: #ffffff; --sunk: #f8faf9; --ink: #16201f; --muted: #5d6b69; --faint: #8a9997;
  --line: #dfe6e4; --line-strong: #c7d1cf;
  --ok: #157a3f; --ok-bg: #e3f4e9; --warn: #8f5200; --warn-bg: #fcefd6;
  --err: #b42318; --err-bg: #fde7e4; --idle: #4b5a67; --idle-bg: #eceff2; --off: #7b8794; --off-bg: #f0f2f4;
  --sans: "Kufi", "Segoe UI", Tahoma, Arial, sans-serif;
  --mono: "JBMono", Consolas, "Courier New", monospace;
  --r-s: 7px; --r-m: 12px;
  --shadow-pop: 0 12px 40px rgba(16, 40, 38, .18);
  --gap: 20px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--paper); color: var(--ink);
  font: 400 14px/1.75 var(--sans);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand-dark); }
:focus-visible { outline: 2px solid var(--brand-mid); outline-offset: 2px; }
[hidden] { display: none !important; }
h1, h2, h3 { letter-spacing: 0; }
.mono, code, kbd { font-family: var(--mono); font-size: .9em; direction: ltr; unicode-bidi: isolate; }
.ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.grow { flex: 1; min-width: 0; }
.offscreen { position: fixed; top: -100px; opacity: 0; }

/* ------------------------------------------------------------------ frame */

.frame { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.side {
  background: var(--brand-dark); color: #fff;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.lab { display: flex; align-items: center; gap: 12px; padding: 20px 16px 16px; }
.lab-mark {
  width: 44px; height: 44px; border-radius: 12px; flex: none;
  background: #fff; color: var(--brand-dark); display: grid; place-items: center;
  font-weight: 700; font-size: 21px; overflow: hidden;
}
.lab-mark img { width: 100%; height: 100%; object-fit: contain; padding: 4px; }
.lab-mark.agent { background: transparent; }
.lab-mark.agent img { padding: 0; }
.lab-name { font-weight: 700; font-size: 14.5px; line-height: 1.45; }
.lab-sub { font-size: 12px; opacity: .78; }
.nav { list-style: none; margin: 6px 0 0; padding: 0 10px; flex: 1; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px; margin-bottom: 2px;
  color: rgba(255,255,255,.86); text-decoration: none; border-radius: var(--r-s); font-weight: 500;
}
.nav a:hover { background: rgba(255,255,255,.1); color: #fff; }
.nav a.on { background: #fff; color: var(--brand-dark); font-weight: 600; }
.nav svg { width: 18px; height: 18px; flex: none; }
.nav .count {
  margin-inline-start: auto; font-size: 11.5px; font-weight: 700; min-width: 22px; text-align: center;
  padding: 0 6px; border-radius: 10px; line-height: 1.7;
}
.nav .count.alert { background: #fde68a; color: #4a2c00; }
.side-foot { padding: 12px 16px 16px; font-size: 12px; color: rgba(255,255,255,.75); border-top: 1px solid rgba(255,255,255,.14); }
.side-foot .who { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; color: #fff; }
.side-foot .who svg { width: 15px; height: 15px; }
.side-foot button {
  margin-inline-start: auto; background: rgba(255,255,255,.14); border: 0; color: #fff; padding: 1px 10px;
  border-radius: 999px; cursor: pointer; font-size: 12px;
}
.side-foot button:hover { background: rgba(255,255,255,.24); }

.main { min-width: 0; padding: 26px 32px 64px; max-width: 1120px; outline: none; }
.page-head { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h1 { font-size: 24px; line-height: 1.4; margin: 0; font-weight: 700; }
.page-head p { margin: 2px 0 0; color: var(--muted); max-width: 70ch; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

.banner {
  border-radius: var(--r-m); padding: 10px 16px; margin-bottom: 16px; display: flex; gap: 12px; align-items: flex-start;
  border: 1px solid transparent;
}
.banner.warn { background: var(--warn-bg); border-color: #f1d29a; color: #573300; }
.banner.err { background: var(--err-bg); border-color: #f3b9b1; color: #6f1710; }
.banner.inset { margin: 12px 18px 0; }
.ip-line { margin: -6px 0 16px; color: var(--ink); }

/* ------------------------------------------------------------------ controls */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  padding: 7px 15px; border-radius: var(--r-s); cursor: pointer; font-weight: 500; line-height: 1.5;
  text-decoration: none; white-space: nowrap; min-height: 38px;
}
.btn:hover { border-color: var(--brand-mid); color: var(--brand-dark); }
.btn.primary { background: var(--brand-dark); border-color: var(--brand-dark); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--brand-ink); border-color: var(--brand-ink); color: #fff; }
.btn.danger { color: var(--err); }
.btn.danger:hover { border-color: var(--err); color: var(--err); }
.btn.danger-solid { background: var(--err); border-color: var(--err); color: #fff; font-weight: 600; }
.btn.danger-solid:hover { background: #8f1c13; color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--brand-tint); }
.btn.sm { padding: 3px 11px; font-size: 13px; min-height: 32px; }
.btn.icon-only { padding: 3px 8px; }
.btn[disabled] { opacity: .5; cursor: default; }
.btn svg { width: 16px; height: 16px; flex: none; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.field { margin-bottom: 16px; }
.field > label, .field > .label { display: block; font-weight: 600; margin-bottom: 5px; }
.field .hint { color: var(--muted); font-size: 12.5px; margin-top: 5px; line-height: 1.65; }
.field .error { color: var(--err); font-size: 12.5px; margin-top: 4px; font-weight: 500; }
.field .error:empty { display: none; }
.field.bad input, .field.bad select, .field.bad textarea { border-color: var(--err); background: #fffafa; }
.field.narrow-input input { max-width: 200px; }
input[type=text], input[type=password], input[type=number], input[type=url], input[type=search], select, textarea {
  width: 100%; border: 1px solid var(--line-strong); border-radius: var(--r-s); background: #fff;
  padding: 7px 11px; line-height: 1.5; min-height: 38px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand-mid); box-shadow: 0 0 0 3px var(--brand-soft); }
input.mono, input[dir=ltr] { text-align: left; }
input::placeholder { color: var(--faint); }
.row { display: flex; gap: 14px; flex-wrap: wrap; }
.row > .field { flex: 1 1 160px; }
.row > .field.narrow { flex: 0 1 140px; }
.keybox { display: flex; gap: 8px; align-items: flex-start; }
.keybox input, .keybox select { flex: 1; min-width: 0; }

.seg { display: inline-flex; flex-wrap: wrap; max-width: 100%; border: 1px solid var(--line-strong); border-radius: var(--r-s); overflow: hidden; background: #fff; }
.seg button { border: 0; background: none; padding: 6px 14px; cursor: pointer; border-inline-start: 1px solid var(--line); font-weight: 500; }
.seg button:first-child { border-inline-start: 0; }
.seg button.on { background: var(--brand-dark); color: #fff; font-weight: 600; }

.choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 14px; }
.choice {
  text-align: start; border: 1px solid var(--line-strong); border-radius: var(--r-m); background: #fff;
  padding: 9px 12px; cursor: pointer; line-height: 1.5;
}
.choice:hover { border-color: var(--brand-mid); }
.choice[disabled] { opacity: .45; cursor: not-allowed; border-color: var(--line); }
.proto-opts:not(:empty) { margin-top: 12px; }
.choice b { display: block; font-weight: 600; }
.choice span { color: var(--muted); font-size: 12.5px; }
.choice.on { border-color: var(--brand-dark); background: var(--brand-tint); box-shadow: inset 0 0 0 1px var(--brand-dark); }

.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { width: 38px; height: 22px; border-radius: 11px; background: var(--line-strong); position: relative; transition: background .15s; flex: none; }
.switch .track::after { content: ""; position: absolute; top: 3px; right: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: right .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + .track { background: var(--brand-mid); }
.switch input:checked + .track::after { right: 19px; }
.switch input:focus-visible + .track { outline: 2px solid var(--brand-mid); outline-offset: 2px; }

details.more { margin: 4px 0 6px; }
details.more > summary {
  cursor: pointer; color: var(--brand-dark); font-weight: 600; font-size: 13.5px; padding: 4px 0; width: max-content;
  list-style: none; display: flex; align-items: center; gap: 6px;
}
details.more > summary::-webkit-details-marker { display: none; }
details.more > summary::before { content: ""; width: 7px; height: 7px; border: solid currentColor; border-width: 0 0 2px 2px; transform: rotate(45deg); transition: transform .15s; margin-top: -3px; }
details.more[open] > summary::before { transform: rotate(-45deg); margin-top: 3px; }
details.more[open] > summary { margin-bottom: 12px; }
details.more h3 { font-size: 14px; margin: 18px 0 10px; color: var(--muted); font-weight: 600; }
details.more h3:first-of-type { margin-top: 4px; }
details.panel-like { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-m); padding: 10px 18px; }

/* ------------------------------------------------------------------ status: one vocabulary everywhere */

.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600; white-space: nowrap; padding: 1px 10px 1px 9px; border-radius: 999px; line-height: 1.8; }
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; }
.pill.ok { color: var(--ok); background: var(--ok-bg); } .pill.warn { color: var(--warn); background: var(--warn-bg); }
.pill.err { color: var(--err); background: var(--err-bg); } .pill.idle { color: var(--idle); background: var(--idle-bg); }
.pill.off { color: var(--off); background: var(--off-bg); }
.pill.live::before, .dot.live { animation: pulse 2.4s ease-out infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(21,122,63,.45); } 70% { box-shadow: 0 0 0 7px rgba(21,122,63,0); } 100% { box-shadow: 0 0 0 0 rgba(21,122,63,0); } }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; background: var(--idle); }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.err { background: var(--err); } .dot.off { background: var(--line-strong); }
.tag { display: inline-block; padding: 0 9px; border-radius: 999px; font-size: 12px; font-weight: 600; line-height: 1.9; white-space: nowrap; text-decoration: none; }
.tag.ok { background: var(--ok-bg); color: var(--ok); } .tag.warn { background: var(--warn-bg); color: var(--warn); }
.tag.err { background: var(--err-bg); color: var(--err); } .tag.idle { background: var(--idle-bg); color: var(--idle); }

/* ------------------------------------------------------------------ panels & tables */

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-m); margin-bottom: var(--gap); }
.panel > header { display: flex; align-items: center; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.panel > header h2 { margin: 0; font-size: 16px; font-weight: 700; }
.panel > header .aside { margin-inline-start: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.panel .body { padding: 16px 18px 6px; }
.panel .body > h2 { font-size: 17px; margin: 0 0 12px; }
.panel > footer { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; flex-wrap: wrap; background: var(--sunk); border-radius: 0 0 var(--r-m) var(--r-m); }
.empty { padding: 30px 18px; color: var(--muted); text-align: center; }
.empty b { display: block; color: var(--ink); font-weight: 600; font-size: 15px; }
.empty p { margin: 2px 0 12px; }
.foot-note { margin: 0; padding: 10px 18px; color: var(--muted); font-size: 12.5px; border-top: 1px solid var(--line); }

.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: start; font-size: 12.5px; font-weight: 600; color: var(--muted); padding: 8px 16px; border-bottom: 1px solid var(--line); background: var(--sunk); white-space: nowrap; }
.tbl td { padding: 10px 16px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl td.num { white-space: nowrap; color: var(--muted); }
.tbl td.end { text-align: end; white-space: nowrap; }
.tbl td.end .btn-row { justify-content: flex-end; flex-wrap: nowrap; }
.tbl .sub { color: var(--muted); font-size: 12.5px; }
.tbl .reason { color: var(--err); }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs button {
  border: 0; background: none; padding: 6px 12px; border-radius: var(--r-s); cursor: pointer; font-weight: 500; color: var(--muted);
  display: inline-flex; align-items: center; gap: 7px;
}
.tabs button:hover { background: var(--sunk); color: var(--ink); }
.tabs button.on { background: var(--brand-tint); color: var(--brand-ink); font-weight: 700; box-shadow: inset 0 -2px 0 var(--brand-dark); border-radius: var(--r-s) var(--r-s) 0 0; }
.badge { font-size: 11.5px; font-weight: 700; padding: 0 7px; border-radius: 999px; line-height: 1.7; background: var(--idle-bg); color: var(--idle); }
.badge.warn { background: var(--warn-bg); color: var(--warn); } .badge.err { background: var(--err-bg); color: var(--err); }
.tab-head { padding-bottom: 0 !important; }
.tab-head .aside { padding-bottom: 8px; }

/* ------------------------------------------------------------------ dashboard */

.health {
  display: flex; align-items: center; gap: 16px; margin-bottom: var(--gap); padding: 16px 20px;
  background: var(--surface); border: 1px solid var(--line); border-inline-start: 5px solid var(--idle); border-radius: var(--r-m);
}
.health h1 { font-size: 21px; margin: 0; line-height: 1.5; }
.health p { margin: 0; color: var(--muted); }
.health .beacon { width: 14px; height: 14px; border-radius: 50%; background: var(--idle); flex: none; }
.health.ok { border-inline-start-color: var(--ok); } .health.ok .beacon { background: var(--ok); animation: pulse 2.4s ease-out infinite; } .health.ok h1 { color: var(--ok); }
.health.warn { border-inline-start-color: #d48a1a; } .health.warn .beacon { background: #d48a1a; } .health.warn h1 { color: var(--warn); }
.health.err { border-inline-start-color: var(--err); background: #fffbfa; } .health.err .beacon { background: var(--err); } .health.err h1 { color: var(--err); }

.path {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-m);
  padding: 20px 22px 18px; margin-bottom: var(--gap);
  display: grid; grid-template-columns: minmax(200px, 1.3fr) 84px minmax(150px, .8fr) 84px minmax(180px, 1fr);
  align-items: stretch;
}
.node { min-width: 0; }
.node h2 { margin: 0 0 8px; font-size: 13px; font-weight: 600; color: var(--muted); }
.node .title { font-size: 16.5px; font-weight: 700; line-height: 1.45; margin-bottom: 4px; }
.node .meta { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.node .figure { font-size: 34px; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; color: var(--ink); }
.node .figure.busy { color: var(--brand-dark); }
.node .figure-label { color: var(--muted); font-size: 12.5px; margin-bottom: 4px; }
.pc { border-inline: 1px dashed var(--line-strong); padding: 0 16px; text-align: center; }
.instruments { list-style: none; margin: 0; padding: 0; }
.instruments li { display: flex; align-items: center; gap: 9px; padding: 4px 0; }
.instruments li + li { border-top: 1px solid var(--line); }
.instruments .nm { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.instruments .st-text { color: var(--muted); font-size: 12px; white-space: nowrap; }
.instruments li.none { color: var(--muted); }
.wire { position: relative; display: flex; align-items: center; }
.wire::before { content: ""; position: absolute; inset-inline: 8px; top: 50%; height: 3px; border-radius: 2px; background: var(--line-strong); }
.wire::after { /* arrow head pointing left (data flows right → left in RTL) */
  content: ""; position: absolute; left: 4px; top: calc(50% - 6px);
  border-style: solid; border-width: 7.5px 9px 7.5px 0; border-color: transparent var(--line-strong) transparent transparent;
}
.wire.ok::before { background: var(--ok); } .wire.ok::after { border-right-color: var(--ok); }
.wire.warn::before { background: repeating-linear-gradient(to left, var(--warn) 0 8px, transparent 8px 13px); }
.wire.warn::after { border-right-color: var(--warn); }
.wire.err::before { background: repeating-linear-gradient(to left, var(--err) 0 4px, transparent 4px 10px); }
.wire.err::after { border-right-color: var(--err); }
.wire.ok .pulse { position: absolute; top: calc(50% - 4px); width: 8px; height: 8px; border-radius: 50%; background: var(--ok); animation: travel 2.6s linear infinite; }
@keyframes travel { from { right: 8px; opacity: 0; } 15% { opacity: 1; } 85% { opacity: 1; } to { right: calc(100% - 16px); opacity: 0; } }
.wire .lbl { position: absolute; top: calc(50% + 9px); inset-inline: 0; text-align: center; font-size: 11.5px; color: var(--muted); line-height: 1.4; }

.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: grid; grid-template-columns: 52px minmax(0, 1fr) auto; gap: 2px 14px; padding: 9px 18px; align-items: center; }
.feed li + li { border-top: 1px solid var(--line); }
.feed .who { min-width: 0; display: flex; gap: 4px 12px; flex-wrap: wrap; align-items: baseline; }
.feed .who .sub { color: var(--muted); font-size: 12.5px; }
.feed li.feed-empty { display: block; text-align: center; color: var(--muted); padding: 28px 18px; }
.feed .t { color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------ analyzers */

.cards { display: grid; gap: 12px; margin-bottom: var(--gap); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-m); padding: 14px 18px; }
.card.bad { border-color: #f0b4ab; }
.card.off { background: var(--sunk); }
.card.off h3 { color: var(--muted); }
.analyzer .top { display: flex; gap: 16px; align-items: flex-start; }
.analyzer .title-line { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.analyzer h3 { margin: 0; font-size: 16px; font-weight: 700; line-height: 1.5; }
.analyzer .facts { display: flex; flex-wrap: wrap; gap: 2px 20px; color: var(--muted); font-size: 13px; margin-top: 2px; overflow-wrap: anywhere; }
.analyzer .facts b { color: var(--ink); font-weight: 600; }
.analyzer .sub-facts { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); font-size: 12.5px; }
.analyzer .sub-facts .signed { color: var(--ok, #1a7f37); font-weight: 600; }
.analyzer .sub-facts .unsigned { color: var(--warn, #9a6700); }
.analyzer .acts { display: flex; gap: 6px; flex: none; }

.menu {
  position: fixed; z-index: 45; min-width: 180px; background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--r-s); box-shadow: var(--shadow-pop); padding: 4px; display: flex; flex-direction: column;
}
.menu button { text-align: start; border: 0; background: none; padding: 7px 12px; border-radius: 5px; cursor: pointer; white-space: nowrap; }
.menu button:hover, .menu button:focus-visible { background: var(--brand-tint); outline: none; }
.menu button.danger { color: var(--err); }
.menu button.danger:hover { background: var(--err-bg); }

.note { border-radius: var(--r-s); padding: 8px 12px; font-size: 13px; margin-top: 8px; line-height: 1.65; }
.note.ok { background: var(--ok-bg); color: #0e4f29; } .note.err { background: var(--err-bg); color: #6f1710; }
.note.warn { background: var(--warn-bg); color: #573300; } .note.wait { background: var(--idle-bg); color: var(--idle); }

/* side sheet (add / edit analyzer) */
.scrim { position: fixed; inset: 0; background: rgba(15, 30, 29, .38); z-index: 40; }
.sheet {
  position: fixed; top: 0; bottom: 0; left: 0; width: min(580px, 100%); background: var(--surface); z-index: 41;
  box-shadow: var(--shadow-pop); display: flex; flex-direction: column; animation: sheet-in .18s ease-out;
}
@keyframes sheet-in { from { transform: translateX(-24px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet > header { padding: 14px 22px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.sheet > header h2 { margin: 0; font-size: 18px; }
.sheet > header .x { margin-inline-start: auto; }
.sheet .content { padding: 18px 22px; overflow-y: auto; flex: 1; }
.sheet > footer { padding: 12px 22px; border-top: 1px solid var(--line); display: flex; gap: 8px; background: var(--sunk); }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend { font-weight: 600; margin-bottom: 6px; padding: 0; }
.group { padding-bottom: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--line); }
.type-area { min-height: 10px; }

/* modal (raw message, login, confirm) */
.modal {
  position: fixed; z-index: 51; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: min(760px, calc(100% - 32px)); max-height: calc(100vh - 48px); background: var(--surface);
  border-radius: var(--r-m); box-shadow: var(--shadow-pop); display: flex; flex-direction: column;
}
.modal.narrow { width: min(440px, calc(100% - 32px)); }
.modal > header { padding: 16px 20px 4px; }
.modal > header h2 { margin: 0; font-size: 17px; }
.modal .content { padding: 6px 20px 14px; overflow: auto; }
.modal .content > p:first-child { margin-top: 0; }
.modal > footer { padding: 12px 20px 16px; display: flex; gap: 8px; }
.modal-scrim { z-index: 50; }
pre.raw {
  margin: 0; padding: 14px; background: var(--sunk); border: 1px solid var(--line); border-radius: var(--r-s);
  font: 12.5px/1.65 var(--mono); direction: ltr; text-align: left; white-space: pre-wrap; word-break: break-all;
  max-height: 56vh; overflow: auto;
}

/* ------------------------------------------------------------------ logs */

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.toolbar.foot { border-bottom: 0; border-top: 1px solid var(--line); padding: 6px 16px; }
.toolbar select, .toolbar input[type=search] { width: auto; min-width: 160px; min-height: 34px; padding: 3px 10px; }
.toolbar input[type=search] { min-width: 220px; flex: 0 1 280px; }
.log { font: 12.5px/1.7 var(--mono); direction: ltr; text-align: left; height: calc(100vh - 300px); min-height: 300px; overflow: auto; padding: 6px 0; background: #fbfcfc; }
.log .ln { display: grid; grid-template-columns: 70px 52px minmax(0, 1fr); gap: 10px; padding: 1px 16px; white-space: pre-wrap; word-break: break-word; }
.log .ln:hover { background: #eef3f3; }
.log .ts { color: var(--faint); }
.log .lv { font-weight: 700; font-size: 11.5px; }
.log .lv.INFO { color: var(--brand-dark); } .log .lv.WARNING { color: var(--warn); } .log .lv.SEVERE { color: var(--err); }
.log .lv.FINE, .log .lv.FINER, .log .lv.FINEST, .log .lv.CONFIG { color: var(--faint); }
.log .ln.SEVERE { background: #fff4f2; } .log .ln.WARNING { background: #fffaf0; }
.log .src { color: var(--faint); }
.log .more-text { grid-column: 3; color: var(--muted); font-size: 11.5px; }
.log .empty { font-family: var(--sans); direction: rtl; }
.files { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-m); }
.files li { display: flex; gap: 12px; align-items: center; padding: 8px 16px; }
.files li + li { border-top: 1px solid var(--line); }
.files .nm { flex: 1; }

/* ------------------------------------------------------------------ settings, about */

.settings { max-width: 860px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }
.form-grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0 12px; }
dl.facts { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 8px 24px; margin: 0 0 12px; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; overflow-wrap: anywhere; }

/* ------------------------------------------------------------------ first run: the setup wizard (no sidebar) */

.setup-page { min-height: 100vh; padding: 40px 16px 60px; background: linear-gradient(180deg, var(--brand-tint), var(--paper) 320px); }
.wizard { max-width: 660px; margin: 0 auto; }
.wz-head { display: flex; align-items: center; gap: 16px; margin-bottom: 22px; }
.wz-head h1 { margin: 0; font-size: 24px; line-height: 1.4; }
.wz-head p { margin: 0; }
.lab-mark.big { width: 60px; height: 60px; border-radius: 16px; font-size: 28px; background: var(--brand-dark); color: #fff; }
.lab-mark.big.agent { background: transparent; }
.steps { list-style: none; display: flex; gap: 8px; padding: 0; margin: 0 0 16px; }
.steps li { flex: 1; display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; padding-bottom: 8px; border-bottom: 3px solid var(--line-strong); }
.steps .n { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 12px; background: var(--surface); border: 2px solid var(--line-strong); flex: none; }
.steps li.on { color: var(--ink); font-weight: 600; border-bottom-color: var(--brand-dark); }
.steps li.on .n { border-color: var(--brand-dark); color: var(--brand-dark); }
.steps li.done { border-bottom-color: var(--brand-dark); }
.steps li.done .n { background: var(--brand-dark); border-color: var(--brand-dark); color: #fff; }
.wizard .panel { box-shadow: 0 2px 10px rgba(16, 40, 38, .05); }
.wizard .body.done .lead { font-size: 16px; }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 60;
  background: var(--ink); color: #fff; padding: 9px 18px; border-radius: var(--r-s); box-shadow: var(--shadow-pop);
  max-width: calc(100% - 32px);
}
.toast.err { background: var(--err); }

.legacy { max-width: 560px; margin: 60px auto; padding: 24px; background: #fff; border: 1px solid #dce4e3; border-radius: 10px; font-family: Tahoma, Arial, sans-serif; line-height: 1.8; }
.legacy h1 { font-size: 20px; margin: 0 0 8px; color: #0f766e; }

/* ------------------------------------------------------------------ smaller windows */

/* add sheet / wizard: register · link · key */
.sheet-tabs { padding: 10px 22px 0; border-bottom: 1px solid var(--line); }
.mode-tabs { margin-bottom: -1px; flex-wrap: nowrap; overflow-x: auto; }
.mode-tabs button { white-space: nowrap; flex: none; }
.wizard .mode-tabs { border-bottom: 1px solid var(--line); margin: 6px 0 16px; }
.wz-discover { margin-bottom: 12px; }
.identity-note b { font-weight: 700; }
.global-alert { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }
.note.unlinked { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.note.unlinked > div { flex: 1 1 280px; }
.remote-list { list-style: none; margin: 0; padding: 4px 18px 12px; }
.remote-list li { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 8px 0; border-bottom: 1px solid var(--line); }
.remote-list li:last-child { border-bottom: 0; }
.remote-list li > :first-child { flex: 1 1 200px; }
.panel .body .remote-list { padding: 0; }

/* device detection */
.discovery { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 var(--gap); align-items: start; }
.discovery .serial-panel { grid-column: 1 / -1; }
.discovery-session .session-message { margin: 0 0 10px; font-weight: 500; }
.discovery-session .verdict { margin: 6px 0 10px; }
.discovery-session dl.facts { margin-top: 12px; }
.progress { height: 6px; border-radius: 3px; background: var(--sunk); border: 1px solid var(--line); overflow: hidden; margin: 6px 0 12px; }
.progress span { display: block; height: 100%; background: var(--brand-mid); transition: width .3s; }
.enroll-panel dl.facts { margin-top: 2px; }
.switch-row { margin-bottom: 16px; }
.panel > header .aside select { width: auto; }

@media (max-width: 1180px) {
  .frame { grid-template-columns: 208px minmax(0, 1fr); }
  .main { padding: 22px 24px 56px; }
}
@media (max-width: 1000px) {
  .path { grid-template-columns: 1fr; gap: 8px; }
  .pc { border-inline: 0; border-block: 1px dashed var(--line-strong); padding: 12px 0; text-align: start; }
  .wire { height: 34px; }
  .wire::before { inset-inline: auto; right: 24px; width: 3px; height: auto; top: 0; bottom: 6px; }
  .wire::after { left: auto; right: 18px; top: auto; bottom: 0; border-width: 9px 7.5px 0 7.5px; border-color: var(--line-strong) transparent transparent transparent; }
  .wire.ok::after { border-color: var(--ok) transparent transparent transparent; }
  .wire.warn::after { border-color: var(--warn) transparent transparent transparent; }
  .wire.err::after { border-color: var(--err) transparent transparent transparent; }
  .wire.warn::before { background: repeating-linear-gradient(to bottom, var(--warn) 0 6px, transparent 6px 10px); }
  .wire.err::before { background: repeating-linear-gradient(to bottom, var(--err) 0 4px, transparent 4px 8px); }
  .wire .pulse { display: none; }
  .wire .lbl { top: 8px; right: 40px; left: auto; text-align: start; }
}
@media (max-width: 780px) {
  .discovery { grid-template-columns: minmax(0, 1fr); }
  .page-head .grow { flex-basis: 100%; }
  .mode-tabs button { padding-left: 7px; padding-right: 7px; font-size: 12.5px; }
  .mode-tabs { gap: 0; }
  .frame { grid-template-columns: 1fr; }
  .side { position: static; height: auto; }
  .lab { padding: 12px 16px 6px; }
  .nav { display: flex; flex-wrap: wrap; gap: 4px; padding-bottom: 10px; }
  .nav a { margin: 0; padding: 6px 10px; }
  .side-foot { display: none; }
  .main { padding: 18px 16px 40px; }
  .form-grid, .choices { grid-template-columns: 1fr; }
  .form-grid.four { grid-template-columns: 1fr 1fr; }
  .analyzer .top { flex-direction: column; gap: 8px; }
  .log .ln { grid-template-columns: 1fr; gap: 0; }
  .keybox { flex-wrap: wrap; }
  .health { flex-wrap: wrap; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
