:root {
  --bg: #0e1116; --panel: #161b22; --panel2: #1c232d; --line: #2a3340; --text: #e6edf3; --muted: #8b98a8;
  --accent: #3b82f6; --live: #e5484d; --ok: #30a46c; --warn: #f5a524; --err: #ff6369;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.err { color: var(--err); }
h1, h3 { margin: 0 0 8px; }
input, select { background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; font: inherit; min-width: 0; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 12px; }
label input, label select { font-size: 14px; color: var(--text); }
.btn { border: 1px solid var(--line); background: var(--panel2); color: var(--text); border-radius: 6px; padding: 7px 14px; font: inherit; cursor: pointer; white-space: nowrap; }
.btn:hover { filter: brightness(1.15); }
.btn:disabled { opacity: .45; cursor: default; filter: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); }
.btn.live { background: var(--live); border-color: var(--live); font-weight: 700; letter-spacing: .04em; }
.btn.danger { background: transparent; border-color: var(--live); color: var(--live); font-weight: 700; }
.btn.ghost { background: transparent; }
.btn.small { padding: 3px 9px; font-size: 12px; }
.btn.big { padding: 11px 22px; font-size: 15px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px; margin-bottom: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; margin-top: 14px; }
.row > input:first-child { flex: 3 1 260px; }
.row > input:nth-child(2) { flex: 1 1 140px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; margin-bottom: 12px; }
.keywrap { display: flex; gap: 6px; } .keywrap input { flex: 1; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { width: min(340px, 100%); display: flex; flex-direction: column; gap: 10px; }

header { display: flex; align-items: center; gap: 16px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
.brand { font-weight: 700; color: var(--live); }
nav { display: flex; gap: 2px; }
nav button { white-space: nowrap; background: none; border: 0; color: var(--muted); padding: 7px 12px; border-radius: 6px; cursor: pointer; font: inherit; }
nav button.active { background: var(--panel2); color: var(--text); }
.sys { margin-left: auto; display: flex; gap: 14px; color: var(--muted); font-size: 12px; flex-wrap: wrap; }
.sys b { color: var(--text); font-weight: 600; }
main { padding: 16px; max-width: 1500px; margin: 0 auto; }

.toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar label { flex-direction: row; align-items: center; gap: 6px; font-size: 13px; }
#estimate { margin-left: auto; font-size: 13px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 12px; }
.ch { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 9px; }
.ch.s-live { border-color: var(--live); box-shadow: 0 0 0 1px var(--live) inset; }
.ch.s-reconnecting, .ch.s-starting { border-color: var(--warn); }
.ch.s-error { border-color: var(--err); }
.ch.off { opacity: .55; }
.ch-head { display: flex; align-items: center; gap: 8px; }
.ch-name { font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plat { font-size: 11px; color: var(--muted); }
.pill { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--panel2); color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.pill.live { background: var(--live); color: #fff; animation: pulse 1.6s infinite; }
.pill.starting, .pill.reconnecting, .pill.stopping { background: var(--warn); color: #111; }
.pill.error { background: var(--err); color: #111; }
.pill.ended { background: var(--ok); color: #111; }
@keyframes pulse { 50% { opacity: .65; } }
.ch-cfg { display: grid; grid-template-columns: 1fr auto auto; gap: 6px; }
.ch-cfg input[type=number] { width: 64px; }
.bar { height: 6px; background: var(--panel2); border-radius: 3px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .8s linear; }
.ch.s-live .bar > i { background: var(--live); }
.stats { display: grid; grid-template-columns: 1.5fr 1fr 1fr .8fr; gap: 4px; font-size: 12px; color: var(--muted); }
.stats b { display: block; color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.msg { font-size: 12px; color: var(--muted); min-height: 1.4em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.s-error .msg, .s-reconnecting .msg { color: var(--warn); }
.ch-actions { display: flex; gap: 6px; align-items: center; }
.ch-actions .sp { flex: 1; }
.check { flex-direction: row; align-items: center; font-size: 12px; gap: 5px; }

table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: 12px; background: var(--panel2); }
tr:last-child td { border-bottom: 0; }
.tablewrap { overflow-x: auto; }
.badge { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 4px; text-transform: uppercase; }
.badge.ready { background: var(--ok); color: #111; } .badge.needs_convert { background: var(--warn); color: #111; }
.badge.failed { background: var(--err); color: #111; } .badge.downloading, .badge.converting, .badge.probing { background: var(--accent); color: #fff; }
.issues { margin: 4px 0 0; padding-left: 16px; font-size: 12px; } .issues .i { color: var(--warn); } .issues .w { color: var(--muted); }
.meta { font-size: 12px; color: var(--muted); }
.diskbar { height: 8px; margin-top: 6px; } .diskbar > i { background: var(--ok); }
.acts { display: flex; gap: 6px; flex-wrap: wrap; }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 12px; width: min(640px, calc(100vw - 32px)); max-height: 80vh; }
dialog::backdrop { background: #000a; }
pre.log { background: #0a0d12; padding: 10px; border-radius: 6px; font-size: 12px; max-height: 50vh; overflow: auto; white-space: pre-wrap; word-break: break-all; }
.res { list-style: none; padding: 0; } .res li { padding: 4px 0; } .res .ok { color: var(--ok); } .res .no { color: var(--err); }
.toast { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: var(--panel2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 8px; opacity: 0; transition: opacity .2s; pointer-events: none; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; }
@media (max-width: 640px) { header { position: static; gap: 8px; } nav { overflow-x: auto; max-width: 100%; } .sys { margin-left: 0; } .cards { grid-template-columns: 1fr; } .stats { grid-template-columns: repeat(2, 1fr); } #estimate { margin-left: 0; } }

.hp { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 99px; }
.hp.good { color: var(--ok); background: color-mix(in srgb, var(--ok) 15%, transparent); }
.hp.fair { color: var(--warn); background: color-mix(in srgb, var(--warn) 15%, transparent); }
.hp.poor { color: var(--err); background: color-mix(in srgb, var(--err) 18%, transparent); }
.stats.net { padding-top: 6px; border-top: 1px dashed var(--line); }
.msg.fair { color: var(--warn); } .msg.poor { color: var(--err); }
.hgood { color: var(--ok) !important; } .hfair { color: var(--warn) !important; } .hpoor { color: var(--err) !important; }
dialog h4 { margin: 14px 0 4px; font-size: 12px; color: var(--muted); font-weight: 500; }
.chart { width: 100%; height: 78px; display: block; background: #0a0d12; border-radius: 6px; }
.chart .cl { fill: var(--muted); font-size: 11px; }
.chart-cap { display: flex; justify-content: space-between; font-size: 12px; margin-top: 2px; }
.hstats { margin: 10px 0; }
