/* Colors are chosen for at least 4.5:1 text contrast in both themes. */
:root {
  --bg: #ffffff; --surface: #f4f6fa; --text: #111827; --muted: #4b5563;
  --border: #c9d1de; --primary: #1d4ed8; --primary-text: #ffffff;
  --danger: #b91c1c; --ok: #166534; --warn: #92400e; --focus: #c2410c;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a; --surface: #172036; --text: #e5e9f2; --muted: #b6c2d9;
    --border: #3a4a6b; --primary: #1d4ed8; --primary-text: #ffffff;
    --danger: #fca5a5; --ok: #86efac; --warn: #fcd34d; --focus: #fdba74;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }  /* .button and .grid set display; hidden must still win */
html { font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; }
body { margin: 0; background: var(--bg); color: var(--text); }
a { color: inherit; text-underline-offset: 2px; }
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 .5rem; }
h2 { font-size: 1.4rem; margin-top: .5rem; }
h3 { font-size: 1.1rem; margin-top: 1.25rem; }
h4 { font-size: 1rem; }
.muted { color: var(--muted); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.skip { position: absolute; left: 1rem; top: -3rem; padding: .5rem 1rem; background: var(--primary); color: var(--primary-text); z-index: 10; }
.skip:focus { top: 1rem; }

header.site { display: flex; flex-wrap: wrap; gap: 1rem 2rem; align-items: center; padding: 1rem 1.5rem; border-bottom: 1px solid var(--border); background: var(--surface); }
.brand h1 { font-size: 1.5rem; margin: 0; }
.brand p { margin: 0; }
nav ul { display: flex; flex-wrap: wrap; gap: .25rem 1rem; list-style: none; margin: 0; padding: 0; }
nav a { display: inline-block; padding: .35rem .25rem; }
.header-actions { margin-left: auto; display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; }
.who { margin: 0; color: var(--muted); }

main { max-width: 1280px; margin: 0 auto; padding: 1rem 1.5rem 3rem; }
main:focus { outline: none; }
section { padding: 1.25rem 0; border-bottom: 1px solid var(--border); }
footer.site { padding: 1rem 1.5rem; border-top: 1px solid var(--border); }

button, .button { font: inherit; display: inline-block; padding: .5rem .9rem; border-radius: 6px; border: 1px solid var(--border); background: var(--bg); color: var(--text); cursor: pointer; text-decoration: none; min-height: 2.5rem; }
button.primary, .button.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
button.danger { border-color: var(--danger); color: var(--danger); }
button[aria-pressed="true"] { background: var(--text); color: var(--bg); }
button:disabled { opacity: .6; cursor: not-allowed; }

.field { display: flex; flex-direction: column; gap: .25rem; margin: .5rem 0; min-width: 0; }
.field.grow { flex: 1 1 18rem; }
label { font-weight: 600; }
input, select, textarea { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: .45rem .6rem; min-height: 2.5rem; }
textarea { font-family: var(--mono); font-size: .9rem; width: 100%; }
[aria-invalid="true"] { border-color: var(--danger); border-width: 2px; }
.hint { margin: 0; font-size: .875rem; color: var(--muted); }
.field-error { margin: 0; color: var(--danger); font-weight: 600; }
.controls { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: flex-end; }
.buttons { display: flex; flex-wrap: wrap; gap: .5rem; margin: .5rem 0; }
.status { min-height: 1.5rem; margin: .25rem 0; }
.status.ok { color: var(--ok); } .status.error { color: var(--danger); }
.notice { padding: .75rem 1rem; border-radius: 6px; border: 2px solid var(--danger); margin: 1rem 0; }

.grid { display: grid; gap: 1rem; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(20rem, 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 1rem; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); gap: .75rem; list-style: none; padding: 0; margin: .5rem 0 0; }
.cards li { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: .75rem 1rem; }
.state { font-weight: 700; }
.state.ok { color: var(--ok); } .state.bad { color: var(--danger); } .state.warn { color: var(--warn); }

.pairs { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: .5rem 0; }
.pairs dt { color: var(--muted); } .pairs dd { margin: 0; overflow-wrap: anywhere; }

.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; margin: .5rem 0; }
th, td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-weight: 700; }

.log { max-height: 32rem; overflow: auto; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.messages { list-style: none; margin: 0; padding: 0; }
.messages li { padding: .6rem .9rem; border-bottom: 1px solid var(--border); font-family: var(--mono); font-size: .875rem; }
.messages .meta { display: flex; flex-wrap: wrap; gap: .25rem 1rem; color: var(--muted); }
.messages .payload { white-space: pre-wrap; overflow-wrap: anywhere; margin: .3rem 0 0; }

.chips { display: flex; flex-wrap: wrap; gap: .35rem; list-style: none; padding: 0; margin: .25rem 0; }
.chips li { font-family: var(--mono); font-size: .85rem; padding: .1rem .5rem; border: 1px solid var(--border); border-radius: 4px; }
.pipeline { display: flex; flex-wrap: wrap; gap: .5rem; padding: 0; list-style: none; counter-reset: step; }
.pipeline li { counter-increment: step; flex: 1 1 12rem; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: .6rem .8rem; }
.pipeline .step { display: block; font-weight: 700; }
.pipeline .step::before { content: counter(step) ". "; }

fieldset.channel, fieldset.board { border: 1px solid var(--border); border-radius: 8px; padding: .5rem 1rem 1rem; margin: .75rem 0; }
fieldset.channel legend, fieldset.board legend { font-weight: 700; padding: 0 .35rem; }
.channel-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); gap: 0 1rem; }

iframe.dashboard { width: 100%; height: 72rem; max-height: 85vh; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
iframe.panel { width: 100%; height: 18rem; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }

/* Board power switch. Off until a smart switch is installed. */
.section-head { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem; margin-bottom: .5rem; }
.section-head h2 { margin: 0; flex: 1 1 auto; }
.power-inline { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem .6rem; padding: .3rem .8rem;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface); }
.power-label { font-weight: 600; }
.power-inline .hint { font-size: .8rem; }
#command-slot { margin-top: 1rem; }
.grid > * { min-width: 0; }
select { max-width: 100%; }
.inline-action { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem; margin: .5rem 0; }
.switch { position: relative; width: 3.25rem; min-height: 0; height: 1.9rem; padding: 0; border-radius: 1rem; border: 1px solid var(--border); background: var(--border); }
.switch .knob { position: absolute; top: .2rem; left: .2rem; width: 1.4rem; height: 1.4rem; border-radius: 50%; background: var(--bg); box-shadow: 0 1px 2px rgba(0, 0, 0, .25); transition: left .15s; }
.switch[aria-checked="true"] { background: var(--ok); border-color: var(--ok); }
.switch[aria-checked="true"] .knob { left: 1.6rem; }
.brand-logo { display: none; }

/* Conekt theme (SITE_THEME=conekt): the TCU console's look and the Conekt logo colors.
   Light only, like the console. Text stays at 4.5:1 or better; the brand blue,
   green, and yellow are used only for decoration. */
:root[data-theme="conekt"] {
  --bg: #ffffff; --surface: #fafcfe; --page: #eef2f7; --text: #131a26; --muted: #5f6b7d;
  --border: #c4cede; --line: #dbe2ec; --primary: #2a6aa8; --primary-text: #ffffff;
  --danger: #b42318; --ok: #1f7a3a; --warn: #9a6500; --focus: #c2410c; --heading: #33405a;
  --cn-blue: #498fcb; --cn-green: #4aaf51; --cn-yellow: #fdc119;
  color-scheme: light;
}
[data-theme="conekt"] body { background: var(--page); font-size: .9375rem; }
[data-theme="conekt"] header.site { position: relative; background: var(--bg); border-bottom: 1px solid var(--line); padding-bottom: 1.25rem; }
[data-theme="conekt"] header.site::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 4px;
  background: linear-gradient(90deg, var(--cn-blue) 0 33.3%, var(--cn-green) 33.3% 66.6%, var(--cn-yellow) 66.6% 100%); }
[data-theme="conekt"] .brand { display: flex; align-items: center; gap: .75rem; }
[data-theme="conekt"] .brand-logo { display: block; height: 2.25rem; width: auto; }
[data-theme="conekt"] .brand h1 { font-size: 1.25rem; }
[data-theme="conekt"] nav a { color: var(--heading); font-weight: 600; text-decoration: none; border-bottom: 2px solid transparent; }
[data-theme="conekt"] nav a:hover { border-bottom-color: var(--cn-blue); }
[data-theme="conekt"] a { color: var(--primary); }
[data-theme="conekt"] main { max-width: 1180px; }
[data-theme="conekt"] main > section { background: var(--bg); border: 1px solid var(--line); border-top: 3px solid var(--cn-blue); border-radius: 12px; padding: 1rem 1.25rem; margin: 0 0 .9rem; }
[data-theme="conekt"] main > section h2 { font-size: .85rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--heading); margin-top: 0; }
[data-theme="conekt"] main > section h3 { font-size: .95rem; }
[data-theme="conekt"] .card, [data-theme="conekt"] .cards li, [data-theme="conekt"] .log, [data-theme="conekt"] .pipeline li { background: var(--surface); border-color: var(--line); }
[data-theme="conekt"] button, [data-theme="conekt"] .button, [data-theme="conekt"] input, [data-theme="conekt"] select, [data-theme="conekt"] textarea { border-radius: 8px; }
[data-theme="conekt"] button:not(.primary):not(.danger):not(.switch):not(:disabled):hover { background: #f0f5fb; }
[data-theme="conekt"] button.primary:hover, [data-theme="conekt"] .button.primary:hover { background: #235a8f; }
[data-theme="conekt"] input:focus, [data-theme="conekt"] select:focus, [data-theme="conekt"] textarea:focus { border-color: var(--primary); }
[data-theme="conekt"] iframe.dashboard { background: var(--bg); border-color: var(--line); }
[data-theme="conekt"] footer.site { border-top-color: var(--line); }

@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; } }
@media (max-width: 700px) { header.site { padding: .75rem 1rem; } main { padding: .75rem 1rem 2rem; } .header-actions { margin-left: 0; } }
.http-fields { margin-top: 1rem; padding-top: .75rem; border-top: 1px dashed var(--border); }
.mono { font-family: var(--mono); overflow-wrap: anywhere; }

/* Board simulator */
#sim-msg-form, #sim-boards { margin: .75rem 0; }
.sim-board h3 { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-top: 0; }
.bearer-tag { font-size: .85rem; font-weight: 700; padding: .1rem .55rem; border-radius: 999px; border: 2px solid var(--border); }
.bearer-tag[data-bearer="lte"] { border-color: #498fcb; }
.bearer-tag[data-bearer="wifi"] { border-color: #4aaf51; }
.bearer-tag[data-bearer^="sidewalk"] { border-color: #c48a00; }
.segmented { border: 0; padding: 0; margin: .5rem 0; display: flex; flex-wrap: wrap; gap: .35rem; }
.segmented legend { font-weight: 600; margin-bottom: .35rem; padding: 0; }
.segmented input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.segmented label { display: inline-block; padding: .45rem .8rem; min-height: 2.5rem; box-sizing: border-box; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); cursor: pointer; }
.segmented input:checked + label { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.segmented input:focus-visible + label { outline: 3px solid var(--focus); outline-offset: 2px; }
.sim-conn { margin: .5rem 0; padding: .5rem .75rem; border-left: 4px solid var(--border); background: var(--bg); }
.sim-conn.open { border-left-color: var(--ok); }
.sim-conn.closed { border-left-color: var(--warn); }
.sim-ids { display: grid; grid-template-columns: max-content 1fr; gap: .15rem .75rem; margin: .5rem 0; font-size: .9rem; }
.sim-ids dt { color: var(--muted); }
.sim-ids dd { margin: 0; font-family: var(--mono); overflow-wrap: anywhere; }
.sim-received { list-style: none; padding: 0; margin: .25rem 0; font-family: var(--mono); font-size: .85rem; max-height: 8rem; overflow-y: auto; }
.sim-received li { padding: .15rem 0; border-bottom: 1px solid var(--border); overflow-wrap: anywhere; }
.inline-checks { border: 0; padding: 0; margin: .5rem 0; display: flex; flex-wrap: wrap; gap: .25rem 1rem; }
.inline-checks legend { font-weight: 600; padding: 0; margin-bottom: .25rem; }
.inline-checks span, .check-row { display: flex; align-items: center; gap: .35rem; min-height: 2rem; }
.check-row { margin: .75rem 0 .25rem; font-weight: 600; }
.inline-checks input, .check-row input { width: 1.1rem; height: 1.1rem; }

/* Live traffic connection status */
.conn-status { margin: .75rem 0; padding: .75rem 1rem; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.conn-status dl { display: grid; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); gap: .5rem 1.5rem; margin: 0; }
.conn-status dt { font-size: .85rem; color: var(--muted); }
.conn-status dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.conn-status dd.ok { color: var(--ok); } .conn-status dd.error { color: var(--danger); }
.conn-status .hint { margin: .75rem 0 0; }
.chips li.ok { border-color: var(--ok); }
.chips li.bad { border-color: var(--danger); }
.meta .origin strong { font-family: var(--mono); }

/* Demo view (policy "view": "demo", or ?view=demo): the stage layout for presenters.
   Dashboard on the left, the board, Send, and the live conversation on the right. */
body.demo-mode nav, body.demo-mode #pause-all, body.demo-mode #manual-link, body.demo-mode #grafana-link,
body.demo-mode main > section:not(#demo) { display: none !important; }
body.demo-mode header.site { padding: .6rem 1.25rem .9rem; gap: .5rem 1.5rem; }
body.demo-mode main { max-width: none; padding: .75rem 1rem 1rem; }
.demo-live { display: inline-flex; align-items: center; gap: .4rem; font-weight: 600; font-size: .9rem; }
.demo-live .dot { width: .65rem; height: .65rem; border-radius: 50%; background: var(--muted); }
.demo-live.ok .dot { background: #2e7d32; box-shadow: 0 0 0 3px rgba(46,125,50,.18); }
.demo-live.bad .dot { background: var(--danger); }
#demo { display: grid; grid-template-columns: minmax(0, 3fr) minmax(22rem, 2fr); gap: 1rem;
  height: calc(100vh - var(--demo-head, 5.5rem) - 1.75rem); min-height: 34rem;
  background: none !important; border: 0 !important; padding: 0 !important; margin: 0 !important; }
#demo[hidden] { display: none; }
.demo-dash { position: relative; min-height: 0; background: var(--bg); border: 1px solid var(--line, var(--border)); border-radius: 12px; overflow: hidden; }
.demo-dash iframe { width: 100%; height: 100%; border: 0; display: block; }
.demo-side { display: flex; flex-direction: column; gap: .75rem; min-height: 0; }
.demo-card { background: var(--bg); border: 1px solid var(--line, var(--border)); border-radius: 12px; padding: .9rem 1rem; }
.demo-label { display: block; font-size: .8rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--heading, var(--muted)); margin-bottom: .35rem; }
.demo-board-row { display: flex; align-items: center; gap: .75rem; }
.demo-board-row .demo-label { margin: 0; }
.demo-board-row select { flex: 1; font-size: 1rem; font-weight: 600; }
.demo-bearer-row { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem .9rem; margin-top: .7rem; }
/* Brand colors are decoration only (border and dot); the text stays dark for contrast. */
.demo-bearer { display: inline-flex; align-items: center; gap: .5rem; font-size: 1.35rem; font-weight: 800; padding: .25rem .9rem;
  border-radius: 999px; background: var(--bg); color: var(--muted); border: 3px solid var(--line, var(--border)); }
.demo-bearer::before { content: ""; width: .8rem; height: .8rem; border-radius: 50%; background: var(--line, var(--border)); }
.demo-bearer[data-bearer]:not([data-bearer=""]) { color: var(--text); }
.demo-bearer[data-bearer="lte"] { border-color: #498fcb; } .demo-bearer[data-bearer="lte"]::before { background: #498fcb; }
.demo-bearer[data-bearer="wifi"] { border-color: #4aaf51; } .demo-bearer[data-bearer="wifi"]::before { background: #4aaf51; }
.demo-bearer[data-bearer="sidewalk"] { border-color: #fdc119; } .demo-bearer[data-bearer="sidewalk"]::before { background: #fdc119; }
.demo-bearer[data-bearer="lora"] { border-color: #1d1d1b; } .demo-bearer[data-bearer="lora"]::before { background: #1d1d1b; }
.demo-detail { color: var(--muted); font-size: .9rem; }
.demo-send-row { display: flex; gap: .5rem; }
.demo-send-row { flex-wrap: wrap; }
.demo-send-row input { flex: 1 1 12rem; min-width: 0; font-size: 1.15rem; min-height: 3rem; }
.demo-send-row button { font-size: 1.1rem; font-weight: 700; min-width: 7rem; min-height: 3rem; }
.demo-presets { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .6rem; }
.chip { border-radius: 999px !important; padding: .3rem .8rem; min-height: 2.25rem; font-size: .9rem; background: var(--surface); }
.demo-status { min-height: 1.4rem; margin: .5rem 0 0; font-weight: 600; }
.demo-status.ok { color: var(--ok); } .demo-status.error { color: var(--danger); }
.demo-feed { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.demo-feed-head { display: flex; align-items: center; justify-content: space-between; }
.demo-feed-head h2 { margin: 0; font-size: .8rem !important; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
button.link { background: none !important; border: 0; color: var(--primary); min-height: 0; padding: .25rem .5rem; }
.demo-bubbles { list-style: none; margin: .5rem 0 0; padding: 0 .25rem 0 0; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: .6rem; }
.demo-bubbles li { max-width: 85%; }
.demo-bubbles li.up { align-self: flex-start; }
.demo-bubbles li.down { align-self: flex-end; text-align: right; }
.demo-bubbles li.note { align-self: center; max-width: 100%; color: var(--muted); font-size: .85rem; text-align: center; }
.demo-bubbles .bubble { display: inline-block; text-align: left; padding: .55rem .85rem; border-radius: 14px; font-size: 1.05rem;
  overflow-wrap: anywhere; white-space: pre-wrap; background: var(--surface); border-left: 5px solid var(--border); }
.demo-bubbles li.up[data-bearer="lte"] .bubble { border-left-color: #498fcb; }
.demo-bubbles li.up[data-bearer="wifi"] .bubble { border-left-color: #4aaf51; }
.demo-bubbles li.up[data-bearer="sidewalk"] .bubble { border-left-color: #fdc119; }
.demo-bubbles li.up[data-bearer="lora"] .bubble { border-left-color: #1d1d1b; }
.demo-bubbles li.down .bubble { background: #1d1d1b; color: #fff; border-left: 0; border-right: 5px solid var(--cn-blue, #498fcb); }
.demo-bubbles .meta { font-size: .8rem; color: var(--muted); margin-top: .2rem; }
.demo-bubbles .tag { font-weight: 700; }
.demo-bubbles li.fresh .bubble { animation: demo-in .5s ease-out; }
@keyframes demo-in { from { transform: translateY(6px); opacity: .2; } to { transform: none; opacity: 1; } }
@media (max-width: 1000px) {
  #demo { grid-template-columns: minmax(0, 1fr); height: auto; }
  .demo-board-row select { min-width: 0; }
  .demo-dash { height: 70vh; }
  .demo-feed { min-height: 24rem; }
}

/* Admin / Presenter toggle in the header */
.view-toggle { display: inline-flex; border: 1px solid var(--line, var(--border)); border-radius: 999px; padding: 3px; background: var(--surface); }
.view-toggle a { padding: .35rem .95rem; border-radius: 999px; font-weight: 600; text-decoration: none; color: var(--text); min-height: 2rem; display: inline-flex; align-items: center; }
.view-toggle a:hover { background: var(--bg); }
.view-toggle a[aria-current="page"] { background: var(--primary); color: var(--primary-text); }
