:root {
  --bg: #0f1419;
  --panel: #1a2129;
  --panel2: #232c36;
  --fg: #e6edf3;
  --muted: #8b98a5;
  --border: #2d3742;
  --accent: #2f81f7;
  --ok: #2ea043;
  --off: #6e7681;
  --danger: #da3633;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--fg);
  font-size: 14px;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 22px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 18px; margin: 0; }
.actions { display: flex; gap: 8px; align-items: center; }
main { padding: 22px; max-width: 1200px; margin: 0 auto; }

.btn {
  display: inline-block; padding: 6px 12px; border-radius: 6px;
  background: var(--panel2); color: var(--fg); border: 1px solid var(--border);
  cursor: pointer; font-size: 13px; line-height: 1.4;
}
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger:hover { border-color: var(--danger); color: #ff7b72; }
.btn.small { padding: 4px 9px; font-size: 12px; }
.btn.disabled { opacity: .4; cursor: not-allowed; }
.btn.disabled:hover { border-color: var(--border); }
.inline { display: inline; margin: 0; }
.file-label { position: relative; overflow: hidden; }
.file-label input[type=file] { position: absolute; left: -9999px; }

table.channels { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.channels th, .channels td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.channels th { background: var(--panel2); color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.channels tr:last-child td { border-bottom: none; }
.channels .name { font-weight: 600; }
.channels .url a, .channels .dest { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.channels .url { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* The icons sit in a box of fixed width - exactly four per row - so a value
   changing width elsewhere in the row (the live bitrate, the uptime) can
   never re-wrap them and make the row jump between two and three lines. */
.row-actions { display: flex; flex-wrap: wrap; gap: 5px; max-width: 200px; align-content: flex-start; }
.channels .row-actions { width: 135px; max-width: none; }
.channels td.bitrate { width: 9em; }
.channels td.st-uptime, .channels td.st-restarts { width: 5.5em; white-space: nowrap; font-variant-numeric: tabular-nums; }
.row-actions form.inline { display: inline-flex; }
.actions-col { width: 135px; }

/* compact icon action buttons */
.iconbtn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; padding: 0; border-radius: 7px;
  background: var(--panel2); border: 1px solid var(--border); color: var(--fg);
  cursor: pointer; transition: border-color .12s, background .12s, color .12s;
}
.iconbtn svg { width: 16px; height: 16px; stroke-linecap: round; stroke-linejoin: round; }
.iconbtn:hover { border-color: var(--accent); color: var(--accent); background: #232d3a; text-decoration: none; }
.iconbtn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.iconbtn.primary:hover { color: #fff; filter: brightness(1.1); }
.iconbtn.danger:hover { border-color: var(--danger); color: #ff7b72; background: rgba(218,54,51,.12); }
.iconbtn.disabled { opacity: .3; cursor: not-allowed; pointer-events: none; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 700; text-transform: uppercase; }
.badge.ok { background: rgba(46,160,67,.18); color: #3fb950; }
.badge.off { background: rgba(110,118,129,.2); color: var(--off); }
.pid { color: var(--muted); font-size: 11px; }
/* The warning on another sender: its command line would widen the State
   column past the window. Its first lines (destination, pid) show; the whole
   text is on hover and in the log. */
.channels .others { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 4; line-clamp: 4; overflow: hidden; overflow-wrap: anywhere; }
.empty { color: var(--muted); }

.error { background: rgba(218,54,51,.15); border: 1px solid var(--danger); color: #ff7b72; padding: 10px 14px; border-radius: 6px; margin-bottom: 16px; }
.hint { color: var(--muted); font-size: 12px; margin: -4px 0 6px; }
.hint.warn { color: #e3b341; }

.channel-form { max-width: 720px; }
fieldset { border: 1px solid var(--border); border-radius: 8px; margin: 0 0 18px; padding: 14px 16px; background: var(--panel); }
legend { color: var(--accent); font-weight: 600; padding: 0 6px; }
.channel-form label { display: block; margin: 10px 0; color: var(--muted); font-size: 13px; }
.channel-form label.check { display: flex; align-items: center; gap: 8px; color: var(--fg); }
.channel-form input[type=text], .channel-form input[type=number],
.channel-form input[type=password], .channel-form input[type=email],
.channel-form select {
  display: block; width: 100%; margin-top: 4px; padding: 7px 9px;
  background: var(--bg); color: var(--fg); border: 1px solid var(--border); border-radius: 6px; font-size: 13px;
}
.channel-form input::placeholder { color: #5a6672; }
.channel-form input:focus, .channel-form select:focus { outline: none; border-color: var(--accent); }
/* A value the panel sets (the TS bitrate): shown, not edited. */
.channel-form input[readonly] { background: var(--panel2); color: var(--muted); cursor: default; }
.channel-form input[readonly]:focus { border-color: var(--border); }
.channel-form input.check, .channel-form label.check input { width: auto; margin: 0; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.form-actions { display: flex; gap: 10px; margin-top: 8px; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; }
.modal.hidden { display: none; }
.modal-box { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; width: min(760px, 92vw); max-height: 84vh; display: flex; flex-direction: column; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font-size: 15px; }
.modal-tools { display: flex; gap: 6px; flex-wrap: wrap; margin: 0 10px 0 auto; }
.modal-tools.hidden { display: none; }
.modal-tools .btn.active { border-color: var(--accent); color: var(--accent); }
.modal-body { margin: 0; padding: 14px 16px; overflow: auto; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; white-space: pre-wrap; word-break: break-word; }

/* --- topbar / brand --- */
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; }
.brand:hover { text-decoration: none; }
.logo { height: 38px; width: auto; display: block; }
.appname { font-size: 16px; font-weight: 600; color: var(--fg); white-space: nowrap; }
.topright { display: flex; align-items: center; gap: 18px; }

.sysstats { display: flex; gap: 14px; padding: 5px 12px; background: var(--panel2); border: 1px solid var(--border); border-radius: 8px; }
.sysstats .stat { display: flex; flex-direction: column; align-items: center; line-height: 1.15; min-width: 42px; }
.sysstats .stat#stat-total-bitrate { min-width: 86px; }
.channels td.bitrate { white-space: nowrap; font-variant-numeric: tabular-nums; }
.sysstats .lbl { font-size: 9px; letter-spacing: .08em; color: var(--muted); }
.sysstats .val { font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; }

.usernav { display: flex; align-items: center; gap: 12px; }
.usernav a { color: var(--muted); font-size: 13px; }
.usernav a:hover { color: var(--accent); }
.usernav .who { color: var(--fg); }
.usernav .role { font-size: 10px; text-transform: uppercase; background: var(--panel2); border: 1px solid var(--border); border-radius: 8px; padding: 1px 6px; color: var(--muted); }

/* --- banners / toolbar / page head --- */
.banner { padding: 9px 14px; border-radius: 6px; margin-bottom: 14px; font-size: 13px; }
.banner.error { background: rgba(218,54,51,.15); border: 1px solid var(--danger); color: #ff7b72; }
.banner.warn { background: rgba(210,153,34,.15); border: 1px solid #9e6a00; color: #e3b341; }
.banner.info { background: rgba(47,129,247,.12); border: 1px solid var(--accent); color: #79c0ff; }
.banner a { color: inherit; text-decoration: underline; }
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 16px; }
.toolbar form.inline { display: inline-flex; }
.pagehead { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.pagehead h2 { margin: 0; font-size: 18px; }

/* --- login --- */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 30px 28px; width: min(360px, 92vw); text-align: center; }
.login-logo { height: 48px; margin-bottom: 10px; }
.login-card h1 { font-size: 16px; font-weight: 600; margin: 0 0 18px; color: var(--muted); }
.login-card label { display: block; text-align: left; margin: 12px 0; color: var(--muted); font-size: 13px; }
.login-card input { display: block; width: 100%; margin-top: 4px; padding: 9px 10px; background: var(--bg); color: var(--fg); border: 1px solid var(--border); border-radius: 6px; font-size: 14px; }
.btn.block { width: 100%; margin-top: 8px; padding: 9px; }

/* --- narrow form --- */
.channel-form.narrow { max-width: 460px; }
.channel-form + .hint { margin-top: 20px; }

/* --- user manual --- */
.manual { max-width: 820px; line-height: 1.55; }
.manual .toc { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 12px 16px; margin-bottom: 22px; display: flex; flex-wrap: wrap; gap: 6px 18px; }
.manual .toc strong { width: 100%; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; margin-bottom: 4px; }
.manual .toc a { font-size: 13px; }
.manual section { margin: 0 0 22px; }
.manual h3 { color: var(--accent); font-size: 16px; margin: 0 0 8px; padding-top: 6px; border-top: 1px solid var(--border); }
.manual section:first-of-type h3 { border-top: none; }
.manual p { margin: 8px 0; color: #c4ccd4; }
.manual ul, .manual ol { margin: 8px 0; padding-left: 22px; }
.manual li { margin: 5px 0; color: #c4ccd4; }
.manual code { background: var(--panel2); border: 1px solid var(--border); border-radius: 4px; padding: 1px 5px; font-size: 12px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.manual b { color: var(--fg); }
.manual h4 { color: var(--fg); font-size: 14px; margin: 18px 0 6px; }
.manual figure { margin: 12px 0 16px; }
.manual figure img { display: block; width: 100%; height: auto; border: 1px solid var(--border); border-radius: 8px; }
.manual figcaption { margin-top: 6px; font-size: 12px; color: var(--muted); }
.manual table { width: 100%; border-collapse: collapse; margin: 10px 0 14px; font-size: 13px; }
.manual th, .manual td { text-align: left; vertical-align: top; padding: 6px 10px; border-bottom: 1px solid var(--border); color: #c4ccd4; }
.manual th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.manual .note { background: var(--panel); border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: 6px; padding: 10px 14px; margin: 12px 0; }
.manual .note ul { margin: 6px 0 0; }

/* --- license page --- */
.lic-card { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px; margin-bottom: 14px; max-width: 820px; }
.lic-card h3 { margin: 0 0 10px; font-size: 15px; }
.lic-card label { display: block; margin-bottom: 8px; }
.lic-card textarea { width: 100%; box-sizing: border-box; }
.lic-state { display: flex; gap: 10px; align-items: baseline; }
.lic-facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 12px 0 4px; font-size: 13px; }
.lic-facts dt { color: var(--muted); }
.lic-facts dd { margin: 0; }
.copyrow { display: flex; gap: 8px; align-items: center; margin-top: 4px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.offscreen { position: absolute; left: -9999px; width: 1px; height: 1px; }
.check { display: flex !important; gap: 8px; align-items: center; }
.check input { width: auto; }
.pending { margin: 4px 0 6px 20px; font-size: 13px; }
.muted { color: var(--muted); }
.badge.warn { background: rgba(210,153,34,.18); color: #e3b341; }
.badge.err { background: rgba(218,54,51,.18); color: #ff7b72; }
.usernav a.alert { color: #ff7b72; font-weight: 700; }

/* license countdown (top bar + License page) */
.sysstats a.stat { color: inherit; text-decoration: none; }
.sysstats a.stat:hover .lbl { color: var(--accent); }
.sysstats .stat[hidden] { display: none; }
.sysstats .stat#stat-license { min-width: 64px; }
.lic-warn .val, .lic-left.lic-warn { color: #e3b341; }
.lic-grace .val, .lic-left.lic-grace { color: #ff7b72; }

/* Scripts toggle `hidden`; it must win over any display rule (flex rows). */
[hidden] { display: none !important; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:disabled:hover { border-color: var(--border); }

/* network change on trial (top bar, every page) */
.sysstats .stat#stat-net { min-width: 48px; }
.sysstats .stat#stat-net a.lbl { color: var(--muted); text-decoration: none; }
.sysstats .stat#stat-net a.lbl:hover { color: var(--accent); }
.net-trial .val { color: #e3b341; }
.net-trial.net-urgent .val { color: #ff7b72; }
.sysstats .stat#stat-netlast a.lbl { color: var(--muted); text-decoration: none; }
.sysstats .stat#stat-netlast a.lbl:hover { color: var(--accent); }
.net-alert .val { color: #ff7b72; font-weight: 600; }
.netbtns { display: flex; align-items: center; gap: 4px; }
.iconbtn.tiny { width: 24px; height: 24px; border-radius: 6px; }
.iconbtn.tiny svg { width: 14px; height: 14px; }

/* --- network page --- */
.net-card { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px; margin-bottom: 14px; }
.net-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.net-head h3 { margin: 0; font-size: 15px; }
.net-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px 26px; align-items: start; }
@media (max-width: 900px) { .net-body { grid-template-columns: minmax(0, 1fr); } }
.net-facts { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 5px 14px; margin: 0; font-size: 13px; }
.net-facts dt { color: var(--muted); }
.net-facts dd { margin: 0; overflow-wrap: anywhere; }
.channel-form.net-form { max-width: none; }
.net-form label { margin: 8px 0; }
.net-mode { display: flex; gap: 20px; }
.channel-form .net-mode label.check { margin: 0 0 4px; }
.net-addr { display: grid; grid-template-columns: minmax(0, 1fr) auto 5.5em 30px; gap: 6px; align-items: center; margin: 6px 0; }
.channel-form .net-addr input, .channel-form .net-dns-row input { margin-top: 0; }
.net-label { display: block; margin: 12px 0 4px; color: var(--muted); font-size: 13px; }
.net-dns-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.net-dns .hint { margin: 5px 0 0; }
.channel-form input:disabled { opacity: .55; cursor: not-allowed; }
.net-plan { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border); }
.net-result { margin-top: 10px; }
.net-result .error { margin: 0; white-space: pre-line; }
.net-plan h4, .net-pending h4 { margin: 10px 0 4px; font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.net-list { margin: 0 0 6px; padding-left: 20px; font-size: 13px; }
.net-list li { margin: 3px 0; }
.net-errors li { color: #ff7b72; }
.net-warnings li { color: #e3b341; }
.channel-form label.net-ack { margin: 8px 0; }
.net-steps summary { cursor: pointer; color: var(--muted); font-size: 12px; margin-top: 8px; }
.net-steps pre { margin: 6px 0 0; padding: 8px 10px; max-height: 260px; overflow: auto; background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11.5px; white-space: pre-wrap; word-break: break-word; }
.net-readonly .banner { margin: 0; }
.net-pending { border-color: #9e6a00; background: linear-gradient(rgba(210,153,34,.06), rgba(210,153,34,.06)), var(--panel); }
.net-pending-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.net-pending-head h3 { margin: 0 0 4px; font-size: 15px; }
.net-clock { min-width: 3.4em; font-size: 30px; font-weight: 700; line-height: 1; text-align: right; color: #e3b341; font-variant-numeric: tabular-nums; }
.net-links { margin: 0 0 6px; padding-left: 20px; }
.net-links li { margin: 5px 0; }
.badge.net-probe { min-width: 9.5em; text-align: center; }
.net-problems { margin: 6px 0 0; }
.net-problems ul { margin: 4px 0 0; padding-left: 20px; }
.net-problems li { margin: 2px 0; }
.net-notes { margin: 6px 0 0; }
.net-notes ul { margin: 4px 0 0; padding-left: 20px; }
.net-notes li { margin: 2px 0; }
.net-dns .hint.net-over { color: #e3b341; }
