:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --ink: #f8fafc;
  --muted: #9fb5c4;
  --navy: #061b2b;
  --panel: #0b2a3e;
  --panel-2: #0f3449;
  --line: #245064;
  --lime: #c8ff66;
  --teal: #18c8ad;
  --amber: #ffc75a;
  --red: #ff7c70;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: radial-gradient(circle at 10% -10%, #174b5e 0, transparent 35%), var(--navy); color: var(--ink); }
button, input { font: inherit; }
button { border: 0; cursor: pointer; }
a { color: inherit; }

.safety-bar { min-height: 32px; display: flex; align-items: center; justify-content: center; gap: 10px; padding: 7px 16px; background: var(--lime); color: #17310b; font-size: 11px; font-weight: 900; letter-spacing: .12em; text-align: center; }
.pulse { width: 8px; height: 8px; border-radius: 50%; background: #3b8208; box-shadow: 0 0 0 4px #3b820825; }

main { width: min(1440px, calc(100% - 48px)); margin: 0 auto; padding: 54px 0 80px; }
.lab-nav { display: inline-flex; flex-wrap: wrap; gap: 6px; margin-bottom: 42px; padding: 6px; border: 1px solid var(--line); border-radius: 14px; background: #071f31; }
.lab-nav a { padding: 9px 13px; border-radius: 9px; color: var(--muted); font-size: 12px; font-weight: 800; text-decoration: none; }
.lab-nav a.active { background: var(--lime); color: #17310b; }
.hero { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 32px; align-items: end; margin-bottom: 36px; }
.eyebrow { margin: 0 0 8px; color: var(--lime); font-size: 11px; font-weight: 900; letter-spacing: .18em; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 18px; font-size: clamp(3rem, 7vw, 7.4rem); line-height: .86; letter-spacing: -.07em; }
h2 { margin-bottom: 0; font-size: 1.35rem; letter-spacing: -.035em; }
.lede { max-width: 660px; margin-bottom: 0; color: var(--muted); font-size: clamp(1rem, 1.8vw, 1.3rem); line-height: 1.55; }
.hero-status { min-width: 260px; display: flex; align-items: center; gap: 12px; padding: 16px 18px; border: 1px solid var(--line); border-radius: 18px; background: #071f31cc; }
.hero-status div { display: grid; gap: 3px; }
.hero-status span:last-child { color: var(--muted); font-size: 12px; }
.status-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 0 6px #ffc75a1b; }
.hero-status.online .status-dot { background: var(--teal); box-shadow: 0 0 0 6px #18c8ad1b; }
.hero-status.error .status-dot { background: var(--red); box-shadow: 0 0 0 6px #ff7c701b; }

.control-strip { display: grid; grid-template-columns: repeat(4, auto) 1fr auto auto auto; gap: 10px; align-items: stretch; padding: 12px; border: 1px solid var(--line); border-radius: 22px; background: #071f31; margin-bottom: 20px; }
.control-strip button { min-height: 52px; padding: 0 18px; border-radius: 13px; background: var(--panel-2); color: var(--ink); font-weight: 800; }
.control-strip button.primary { background: var(--lime); color: #17310b; }
.metric { min-width: 90px; display: grid; place-content: center; text-align: center; border-left: 1px solid var(--line); }
.metric span { font-size: 1.15rem; font-weight: 900; }
.metric small { color: var(--muted); }

.devices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.device { min-width: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 26px; background: linear-gradient(145deg, var(--panel), #082337); box-shadow: 0 22px 60px #0004; }
.device > header { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 14px; padding: 22px; border-bottom: 1px solid var(--line); }
.device-icon { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 14px; background: var(--lime); color: #17310b; font-size: 20px; font-weight: 1000; }
.device-body { padding: 26px 22px 22px; }
.document-chip { display: flex; align-items: center; gap: 12px; min-height: 58px; padding: 10px 14px; border-radius: 15px; background: #061b2b; }
.document-chip span { padding: 7px 9px; border-radius: 9px; background: #173f54; color: var(--lime); font-size: 11px; font-weight: 900; }
.state { min-height: 30px; margin: 24px 0 12px; color: var(--muted); }
.sign, .subtle { width: 100%; min-height: 52px; border-radius: 14px; font-weight: 900; }
.sign { background: var(--teal); color: #05261f; }
.sign:disabled { opacity: .45; cursor: not-allowed; }
.subtle { margin-top: 10px; background: transparent; color: var(--muted); border: 1px solid var(--line); }
.device > footer { display: flex; justify-content: space-between; gap: 12px; padding: 14px 22px; background: #061b2b; color: var(--muted); font-size: 12px; }

.switch { display: grid; grid-template-columns: auto auto; gap: 7px; align-items: center; cursor: pointer; }
.switch input { position: absolute; opacity: 0; }
.switch span { width: 38px; height: 22px; position: relative; border-radius: 999px; background: #31566a; transition: .2s; }
.switch span::after { content: ""; position: absolute; width: 16px; height: 16px; top: 3px; left: 3px; border-radius: 50%; background: white; transition: .2s; }
.switch input:checked + span { background: var(--red); }
.switch input:checked + span::after { transform: translateX(16px); }
.switch em { color: var(--muted); font-size: 11px; font-style: normal; }

.ledger-panel { margin-top: 20px; padding: 24px; border: 1px solid var(--line); border-radius: 26px; background: #071f31; }
.ledger-panel > header { display: flex; justify-content: space-between; gap: 20px; align-items: end; margin-bottom: 18px; }
.server-time { color: var(--muted); font-size: 12px; }
.ledger { display: grid; gap: 8px; }
.ledger-row { display: grid; grid-template-columns: 72px 1fr auto; gap: 14px; align-items: center; padding: 14px 16px; border-radius: 13px; background: var(--panel); }
.ledger-row .sequence { color: var(--lime); font-weight: 1000; }
.ledger-row small { color: var(--muted); }
.ledger-row time { color: var(--muted); font-size: 12px; }
.empty { color: var(--muted); }
.outbox { display: flex; justify-content: space-between; gap: 20px; margin-top: 14px; padding: 14px 16px; border: 1px dashed var(--line); border-radius: 13px; color: var(--muted); }
.outbox strong { color: var(--ink); }

.proof-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-top: 20px; }
.proof-grid article { min-height: 190px; padding: 20px; border-radius: 20px; background: #0b2a3e; }
.proof-grid article > span { color: var(--lime); font-weight: 1000; }
.proof-grid h3 { margin: 28px 0 8px; }
.proof-grid p { margin-bottom: 0; color: var(--muted); line-height: 1.5; }

.toast { position: fixed; right: 22px; bottom: 22px; max-width: min(420px, calc(100% - 44px)); padding: 14px 18px; border-radius: 14px; background: var(--lime); color: #17310b; font-weight: 900; opacity: 0; transform: translateY(12px); pointer-events: none; transition: .2s; }
.toast.show { opacity: 1; transform: none; }

.comms-page { width: min(1560px, calc(100% - 48px)); }
.comms-hero h1 { max-width: 1000px; }
.comms-controls { grid-template-columns: repeat(6, auto) 1fr repeat(5, auto); }
.comms-workspace { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(320px, .75fr); gap: 20px; }
.conversation-panel, .notification-panel { min-width: 0; border: 1px solid var(--line); border-radius: 26px; background: #071f31; box-shadow: 0 22px 60px #0003; }
.panel-heading { display: flex; justify-content: space-between; gap: 18px; align-items: end; padding: 22px; border-bottom: 1px solid var(--line); }
.conversation { min-height: 390px; max-height: 560px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 22px; }
.message-bubble { width: min(76%, 620px); padding: 14px 16px; border: 1px solid #2c5b70; border-radius: 18px 18px 18px 5px; background: var(--panel); }
.message-bubble.from-blair { align-self: flex-end; border-color: #298f80; border-radius: 18px 18px 5px 18px; background: #0a3b3c; }
.message-meta { display: flex; justify-content: space-between; gap: 18px; color: var(--lime); font-size: 12px; }
.message-bubble p { margin: 10px 0 8px; line-height: 1.45; overflow-wrap: anywhere; }
.message-bubble small { color: var(--muted); }
.notification-proof { min-height: 390px; display: grid; align-content: start; gap: 10px; padding: 22px; }
.notification-card { padding: 16px; border-left: 4px solid var(--amber); border-radius: 6px 15px 15px 6px; background: var(--panel); }
.notification-card p { margin: 9px 0; color: var(--muted); line-height: 1.45; }
.notification-card small { color: var(--lime); line-height: 1.4; }
.comms-devices { margin-top: 20px; }
.composer-label { display: block; margin-bottom: 8px; color: var(--lime); font-size: 12px; font-weight: 900; }
.message-device textarea { width: 100%; resize: vertical; min-height: 92px; padding: 14px; border: 1px solid var(--line); border-radius: 14px; outline: 0; background: #061b2b; color: var(--ink); font: inherit; line-height: 1.45; }
.message-device textarea:focus { border-color: var(--teal); box-shadow: 0 0 0 3px #18c8ad20; }
.device-actions { display: grid; grid-template-columns: 1.2fr .8fr; gap: 10px; margin-top: 12px; }
.device-actions .subtle { margin-top: 0; }
.retry-link { margin-top: 13px; padding: 0; background: transparent; color: var(--muted); font-size: 12px; text-decoration: underline; }
.retry-link:disabled { opacity: .45; cursor: not-allowed; }
.message-device .state { min-height: 24px; margin: 16px 0 0; }
.comms-proof-grid article { min-height: 160px; }

@media (max-width: 900px) {
  main { width: min(100% - 28px, 760px); padding-top: 34px; }
  .hero { grid-template-columns: 1fr; align-items: start; }
  .hero-status { width: 100%; }
  .control-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .control-strip button:first-child { grid-column: 1 / -1; }
  .control-strip .metric { border-left: 0; border-top: 1px solid var(--line); padding-top: 10px; }
  .devices { grid-template-columns: 1fr; }
  .proof-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .comms-page { width: min(100% - 28px, 820px); }
  .comms-controls { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .comms-controls button:first-child { grid-column: 1 / -1; }
  .comms-workspace { grid-template-columns: 1fr; }
  .notification-proof { min-height: 180px; }
}

@media (max-width: 560px) {
  .safety-bar { font-size: 9px; }
  main { width: min(100% - 20px, 520px); padding-top: 28px; }
  h1 { font-size: clamp(2.8rem, 15vw, 4.6rem); }
  .control-strip { grid-template-columns: 1fr; }
  .control-strip button:first-child { grid-column: auto; }
  .control-strip .metric { min-height: 58px; }
  .device > header { grid-template-columns: auto 1fr; }
  .switch { grid-column: 1 / -1; justify-self: stretch; display: flex; justify-content: flex-end; }
  .ledger-panel { padding: 18px; }
  .ledger-panel > header { align-items: start; flex-direction: column; }
  .ledger-row { grid-template-columns: 58px 1fr; }
  .ledger-row time { grid-column: 2; }
  .outbox { flex-direction: column; }
  .proof-grid { grid-template-columns: 1fr; }
  .lab-nav { width: 100%; display: grid; grid-template-columns: 1fr; margin-bottom: 30px; text-align: center; }
  .comms-page { width: min(100% - 20px, 520px); }
  .comms-controls { grid-template-columns: 1fr; }
  .comms-controls button:first-child { grid-column: auto; }
  .conversation-panel, .notification-panel { border-radius: 20px; }
  .conversation { min-height: 320px; padding: 14px; }
  .message-bubble { width: 91%; }
  .device-actions { grid-template-columns: 1fr; }
}
