/* NationCam Streamer UI. Dark by default; [data-theme=light] on <html> switches. */

:root {
  --bg: #0f1217;
  --surface: #171b22;
  --surface-2: #1f252e;
  --border: #2c3440;
  --text: #e7eaef;
  --muted: #9ba5b3;
  --accent: #4b8df8;
  --accent-text: #fff;
  --ok: #2fb56a;
  --warn: #e0a23a;
  --err: #ef5a5f;
  --idle: #8a93a0;
  --focus: #8fbaff;
  --shadow: 0 2px 10px rgb(0 0 0 / .35);
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #f3f5f8;
  --surface: #fff;
  --surface-2: #eef1f5;
  --border: #d3d9e1;
  --text: #19202a;
  --muted: #5a6574;
  --accent: #1b62d6;
  --ok: #17803f;
  --warn: #9a6200;
  --err: #c42b31;
  --idle: #5f6875;
  --focus: #1b62d6;
  --shadow: 0 1px 4px rgb(0 0 0 / .08);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

h1 { font-size: 1.45rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 1rem 0 .5rem; }
p { margin: .5rem 0; }
a { color: var(--accent); }
code, .ro, .log { font-family: var(--mono); font-size: .85em; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
main:focus { outline: none; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.boot { padding: 2rem; color: var(--muted); }
.sr-only, .offscreen {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.ico { flex: none; vertical-align: -4px; }

/* ---------------------------------------------------------------- buttons */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  min-height: 2.25rem; padding: .4rem .9rem;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface-2); color: var(--text);
  font: inherit; font-weight: 500; text-decoration: none; cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.1); }
.btn.danger { color: var(--err); border-color: color-mix(in srgb, var(--err) 50%, var(--border)); }
.btn.small { min-height: 1.9rem; padding: .2rem .6rem; font-size: .85rem; }
.btn.icon { min-width: 2rem; padding: .2rem .4rem; }
.btn.block { width: 100%; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 2.25rem; min-height: 2.25rem; padding: 0;
  border: 0; border-radius: 6px; background: transparent; color: inherit; font-size: 1.2rem; cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }

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

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: .75rem;
  padding: .5rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .5rem; color: var(--text); font-weight: 600; text-decoration: none; }
.spacer { flex: 1; }
.menu-btn { display: none; }
.who { color: var(--muted); font-size: .9rem; }
.conn { font-size: .8rem; padding: .1rem .5rem; border-radius: 999px; border: 1px solid var(--border); }
.conn::before { content: "● "; }
.conn.ok { color: var(--ok); }
.conn.off { color: var(--warn); }

.layout { display: flex; min-height: calc(100vh - 3.3rem); }
.nav { flex: none; width: 13rem; padding: 1rem .5rem; background: var(--surface); border-right: 1px solid var(--border); }
.nav ul { list-style: none; margin: 0; padding: 0; }
.nav a {
  display: block; padding: .55rem .8rem; border-radius: 6px;
  color: var(--text); text-decoration: none;
}
.nav a:hover { background: var(--surface-2); }
.nav a[aria-current="page"] { background: var(--surface-2); box-shadow: inset 3px 0 0 var(--accent); font-weight: 600; }
.content { flex: 1; min-width: 0; padding: 1rem 1.25rem 3rem; }
main { max-width: 1400px; }

.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; margin: .25rem 0 1rem; }
.page-actions { display: flex; flex-wrap: wrap; gap: .5rem; }

/* ------------------------------------------------------- banners, notices */

.banners:empty { display: none; }
.banners { margin-bottom: 1rem; display: grid; gap: .5rem; }
.banner {
  margin: .5rem 0; padding: .6rem .9rem; border-radius: 6px;
  border: 1px solid var(--border); border-left: 4px solid var(--idle); background: var(--surface);
}
.banner.info { border-left-color: var(--accent); }
.banner.warn { border-left-color: var(--warn); }
.banner.error { border-left-color: var(--err); }
.banner ul { margin: .25rem 0 0; padding-left: 1.2rem; }
.note { padding: .5rem .75rem; border-radius: 6px; background: var(--surface-2); color: var(--muted); font-size: .9rem; }
.err-line { color: var(--err); font-size: .9rem; overflow-wrap: anywhere; }
.warnings { margin: .25rem 0; padding-left: 1.2rem; color: var(--warn); font-size: .9rem; }

.badge {
  display: inline-block; padding: .05rem .5rem; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface-2); font-size: .8rem; font-weight: 600; white-space: nowrap;
}
.badge.st-ok { color: var(--ok); border-color: var(--ok); }
.badge.st-warn { color: var(--warn); border-color: var(--warn); }
.badge.st-err { color: var(--err); border-color: var(--err); }
.badge.st-idle { color: var(--idle); }
.badge.st-ok::before { content: "● "; }
.badge.st-warn::before { content: "◐ "; }
.badge.st-err::before { content: "▲ "; }
.badges { display: flex; flex-wrap: wrap; gap: .35rem; margin-bottom: .5rem; }

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

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card.pad { padding: 1rem 1.1rem; }
.empty { text-align: center; }
.sections { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 30rem), 1fr)); align-items: start; }
.sections .wide { grid-column: 1 / -1; }

.cards { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 22rem), 1fr)); align-items: start; }
.stream-card { overflow: hidden; }
.thumb { position: relative; aspect-ratio: 16 / 9; background: #000; }
.thumb img { display: block; width: 100%; height: 100%; object-fit: contain; }
.thumb-msg { display: none; }
.thumb.err img { visibility: hidden; }
.thumb.err .thumb-msg { display: flex; position: absolute; inset: 0; align-items: center; justify-content: center; color: #aab; font-size: .9rem; }
.card-body { padding: .8rem 1rem 1rem; }
.card-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: .25rem .75rem; margin-bottom: .5rem; }
.card-head h2 { margin: 0; overflow-wrap: anywhere; }
.platform { display: inline-flex; align-items: center; gap: .3rem; color: var(--muted); font-size: .9rem; }
.metrics { display: grid; grid-template-columns: repeat(auto-fill, minmax(6.5rem, 1fr)); gap: .4rem .75rem; margin: 0 0 .5rem; }
.metrics dt { color: var(--muted); font-size: .75rem; }
.metrics dd { margin: 0; font-variant-numeric: tabular-nums; font-weight: 600; }
.target code { overflow-wrap: anywhere; }
.link-row { display: flex; flex-wrap: wrap; align-items: center; gap: .25rem .5rem; margin: .35rem 0; font-size: .9rem; }
.link-row .url { min-width: 0; overflow-wrap: anywhere; font-family: var(--mono); font-size: .8rem; }
.card-actions { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .75rem; }

/* ----------------------------------------------------------------- tables */

.table-wrap { position: relative; overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { padding: .5rem .6rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.table thead th { color: var(--muted); font-weight: 600; font-size: .8rem; white-space: nowrap; }
.table.kv th { width: 40%; color: var(--muted); font-weight: 500; }
.table .title-cell { min-width: 10rem; }
.table.kv td { overflow-wrap: anywhere; }
.table.compact td { padding: .3rem .4rem; }
.table.compact select, .table.compact input[type=time] { min-width: 7rem; }

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

.field { margin: 0 0 .9rem; min-width: 0; }
.field > label, .label { display: block; margin-bottom: .25rem; font-weight: 500; font-size: .9rem; }
.field.check > label { display: flex; align-items: flex-start; gap: .5rem; font-weight: 400; cursor: pointer; }
.field.check input { margin-top: .2rem; }
input, select, textarea {
  width: 100%; min-height: 2.25rem; padding: .4rem .6rem;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg); color: var(--text); font: inherit;
}
textarea { resize: vertical; font-family: var(--mono); font-size: .85rem; }
input[type=checkbox] { width: 1.1rem; height: 1.1rem; min-height: 0; padding: 0; accent-color: var(--accent); flex: none; }
input[type=file] { padding: .3rem; }
input:disabled, select:disabled, textarea:disabled { opacity: .6; cursor: not-allowed; }
[aria-invalid="true"] { border-color: var(--err); }
.inline { display: flex; gap: .4rem; }
.inline > input { flex: 1; min-width: 0; }
.hint { margin: .3rem 0 .9rem; color: var(--muted); font-size: .82rem; }
.field .hint { margin-bottom: 0; }
.hint.gated::before { content: "⊘ "; }
.field-err, .form-err { color: var(--err); font-size: .88rem; font-weight: 500; }
.field-err::before, .form-err::before { content: "▲ "; }
.form-err { margin: 0 0 .75rem; padding: .5rem .75rem; border: 1px solid var(--err); border-radius: 6px; }
.form-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; margin-top: 1rem; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .75rem; }
.ro {
  display: block; padding: .45rem .6rem; min-height: 2.25rem; border: 1px dashed var(--border); border-radius: 6px;
  background: var(--surface-2); overflow-wrap: anywhere;
}
.grid2 { display: grid; gap: 0 1rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 16rem), 1fr)); }
.checks { display: flex; flex-wrap: wrap; gap: 0 1.5rem; }
fieldset.group { margin: .5rem 0 1rem; padding: .75rem 1rem .25rem; border: 1px solid var(--border); border-radius: var(--radius); }
fieldset.group legend { padding: 0 .35rem; font-weight: 600; }
fieldset.plain { border: 0; margin: 0; padding: 0; min-width: 0; }
.toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .5rem .75rem; }
.toolbar .field { margin-bottom: 0; }
.toolbar .grow { flex: 1 1 14rem; }
.toolbar .narrow { width: 6.5rem; }
.toolbar .check { align-self: center; }
.toolbar.card { margin-bottom: 1rem; }
.src-row { display: grid; grid-template-columns: 1fr 2fr auto; gap: 0 .75rem; align-items: end; }
.src-row > .btn { margin-bottom: .9rem; }
main > .card + .card, main > .banner + .card { margin-top: 1rem; }
.plain-list { list-style: none; padding: 0; margin: 0 0 .75rem; }
.plain-list li { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; padding: .35rem 0; border-bottom: 1px solid var(--border); }
.plain-list li .btn { margin-left: auto; }
.upload progress { width: 100%; height: .6rem; margin-bottom: .5rem; accent-color: var(--accent); }

.switch { display: inline-flex; align-items: center; gap: .4rem; cursor: pointer; }
.switch input { appearance: none; width: 2.3rem; height: 1.3rem; border-radius: 999px; background: var(--idle); position: relative; cursor: pointer; border: 0; }
.switch input::after { content: ""; position: absolute; top: .15rem; left: .15rem; width: 1rem; height: 1rem; border-radius: 50%; background: #fff; transition: left .15s; }
.switch input:checked { background: var(--ok); }
.switch input:checked::after { left: 1.15rem; }
.switch span { font-size: .85rem; min-width: 1.8rem; }

/* ------------------------------------------------------- editor, wizard */

.tabs { position: relative; display: flex; gap: .25rem; overflow-x: auto; border-bottom: 1px solid var(--border); margin-bottom: 1rem; }
.tabs [role=tab] {
  flex: none; padding: .55rem .9rem; border: 0; border-bottom: 3px solid transparent;
  background: none; color: var(--muted); font: inherit; font-weight: 500; cursor: pointer;
}
.tabs [role=tab][aria-selected=true] { color: var(--text); border-bottom-color: var(--accent); }
.panel { max-width: 56rem; }
.platform-line { display: flex; align-items: center; gap: .4rem; margin-top: 0; }

.steps { display: flex; flex-wrap: wrap; gap: .25rem .5rem; list-style: none; padding: 0; margin: 0 0 1rem; counter-reset: step; }
.steps li { counter-increment: step; color: var(--muted); font-size: .85rem; }
.steps li::before { content: counter(step) ". "; }
.steps li:not(:last-child)::after { content: " ›"; margin-left: .5rem; }
.steps li.done { color: var(--text); }
.steps li.done::before { content: "✓ "; }
.steps li[aria-current=step] { color: var(--accent); font-weight: 700; }

.picker { display: grid; gap: .6rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 11rem), 1fr)); }
.pick {
  display: flex; flex-direction: column; align-items: center; gap: .4rem; padding: .9rem .6rem; min-height: 5.5rem;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); color: var(--text);
  font: inherit; text-align: center; cursor: pointer;
}
.pick .ico { width: 28px; height: 28px; }
.pick:hover:not(:disabled) { border-color: var(--accent); }
.pick[aria-pressed=true] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.pick[aria-pressed=true]::after { content: "✓"; color: var(--accent); font-weight: 700; }
.pick:disabled { opacity: .55; cursor: not-allowed; }
.pick small { color: var(--muted); font-size: .75rem; }

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

.log {
  height: 65vh; overflow: auto; padding: .5rem .75rem; line-height: 1.35;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.log-line { white-space: pre-wrap; overflow-wrap: anywhere; }
.log-line.lvl-debug { color: var(--muted); }
.log-line.lvl-warn { color: var(--warn); }
.log-line.lvl-error { color: var(--err); font-weight: 600; }

.diag-form { margin-bottom: 1rem; }
.diag-form h3 { margin-top: 0; }
.diag-out { font-family: var(--mono); font-size: .85rem; overflow-wrap: anywhere; }
.diag-out:empty { display: none; }

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

.login-wrap { display: grid; place-items: center; min-height: 100vh; padding: 1rem; max-width: none; }
.login { width: min(100%, 26rem); padding: 1.5rem; }
.brand-block { display: flex; align-items: center; gap: .75rem; margin-bottom: .75rem; }
.brand-block .ico { width: 40px; height: 40px; color: var(--accent); }
.brand-block h1, .brand-block h2 { margin: 0; }
.brand-block p { margin: 0; }

/* --------------------------------------------------------------- dialogs */

.dlg {
  width: min(calc(100vw - 2rem), 34rem); max-height: calc(100vh - 2rem); padding: 1.25rem;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
.dlg.wide { width: min(calc(100vw - 2rem), 60rem); }
.dlg::backdrop { background: rgb(0 0 0 / .6); }
.dlg-actions { display: flex; flex-direction: row-reverse; flex-wrap: wrap; gap: .5rem; margin-top: 1rem; }
.dlg .form-err:not([hidden]) { margin-top: .75rem; }
.preview video { display: block; width: 100%; aspect-ratio: 16 / 9; background: #000; border-radius: 6px; }
.preview-msg:empty { display: none; }
.user-code { font: 700 2rem/1.2 var(--mono); letter-spacing: .15em; text-align: center; padding: .5rem; border: 1px dashed var(--border); border-radius: 6px; }

/* ---------------------------------------------------------------- toasts */

.toasts { position: fixed; right: 1rem; bottom: 1rem; z-index: 100; display: grid; gap: .5rem; width: min(calc(100vw - 2rem), 24rem); }
.toast {
  display: flex; align-items: flex-start; gap: .5rem; padding: .6rem .6rem .6rem .9rem;
  border: 1px solid var(--border); border-left: 4px solid var(--accent); border-radius: 6px; background: var(--surface); box-shadow: var(--shadow);
}
.toast span { flex: 1; overflow-wrap: anywhere; }
.toast.ok { border-left-color: var(--ok); }
.toast.error { border-left-color: var(--err); }
.toast .icon-btn { min-width: 1.6rem; min-height: 1.6rem; font-size: 1rem; }

/* ------------------------------------------------------------ responsive */

@media (max-width: 800px) {
  .menu-btn { display: inline-flex; }
  .who { display: none; }
  .layout { display: block; }
  .nav {
    display: none; position: fixed; top: 3.2rem; left: 0; bottom: 0; z-index: 20; width: min(80vw, 16rem);
    box-shadow: var(--shadow); overflow-y: auto;
  }
  .nav.open { display: block; }
  .content { padding: .75rem .75rem 3rem; }
  .src-row { grid-template-columns: 1fr; }
}

@media (max-width: 420px) {
  body { font-size: 14px; }
  .topbar { gap: .4rem; padding: .4rem .5rem; }
  .brand span { display: none; }
  .conn { font-size: .72rem; }
  .card.pad { padding: .8rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}

/* the hidden attribute always wins over component display rules */
[hidden] { display: none !important; }
