:root {
  --bg: #0E1014; --bar: #12151B; --card: #151920; --log: #0B0D11; --field: #0E1014;
  --chip: #1A1E26; --chip-hover: #232833;
  --border: #222733; --border2: #2E3441; --border3: #2A303C;
  --text: #E7EAF0; --text2: #C9CFD9; --muted: #9AA3B2; --dim: #7C8596;
  --accent: #2F6FEB; --accent-hover: #3D7CF5; --focus: #4C8DFF;
  --ok: #6FD39C; --ok-dot: #3FB97A; --err: #FF8A8E; --err-dot: #F2555A;
  --info: #8DB6FF; --info-dot: #4C8DFF; --idle-dot: #8A93A3; --warn: #E8B04A;
  --stop-off: #9E7479; --stop-border: #3A2A2E;
  --mono: 'JetBrains Mono', ui-monospace, Consolas, monospace;
  --sans: Inter, 'Segoe UI', system-ui, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--sans); font-size: 14px; }
a { color: #7FB0FF; } a:hover { color: #A9C9FF; }
button, input, textarea, select { font: inherit; color: inherit; }
input:focus-visible, textarea:focus-visible, button:focus-visible, .viewer:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }

/* ── top bar ── */
.topbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 16px;
  padding: 14px 24px; background: var(--bar); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.logo { width: 40px; height: 40px; border-radius: 10px; background: var(--accent); display: grid; place-items: center; flex: none; }
.brand h1 { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: -0.01em; display: flex; align-items: center; gap: 8px; }
.tag { font-size: 11px; font-weight: 600; color: #B9C0CC; background: var(--chip); border: 1px solid var(--border3); border-radius: 6px; padding: 2px 7px; }
.sub { font-size: 12px; color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.pill { display: inline-flex; align-items: center; gap: 8px; min-height: 36px; padding: 0 14px; border-radius: 999px;
  background: var(--chip); border: 1px solid var(--border3); font-size: 13px; color: var(--text2); max-width: 100%; }
.pill strong { color: var(--text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--idle-dot); flex: none; }
.dot.ok { background: var(--ok-dot); } .dot.err { background: var(--err-dot); } .dot.warn { background: var(--warn); } .dot.info { background: var(--info-dot); }

/* ── buttons ── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 16px;
  border-radius: 10px; border: 1px solid var(--border3); background: var(--chip); color: var(--text);
  font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--chip-hover); color: var(--text); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { background: transparent; border-color: #5A3036; color: var(--err); }
.btn.danger:hover { background: #22171A; }
.btn:disabled { cursor: not-allowed; opacity: 1; }
.btn.primary:disabled { background: #24365C; border-color: #24365C; color: #C8D7F5; }
.btn.danger:disabled { border-color: var(--stop-border); color: var(--stop-off); background: transparent; }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 12px; border-radius: 8px; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--chip-hover); color: var(--text); }
.btn.ghost.active { color: var(--text); border-color: var(--border2); background: var(--chip-hover); }
.icon-btn { width: 44px; padding: 0; }

/* ── layout ── */
main { max-width: 1400px; margin: 0 auto; padding: 20px 24px 28px; display: flex; flex-direction: column; gap: 16px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 14px; }
.controls { padding: 18px 20px; display: flex; flex-wrap: wrap; align-items: flex-end; gap: 14px 16px; }
.field { display: flex; flex-direction: column; gap: 6px; flex: 0 1 220px; min-width: 160px; }
.field-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 18px; }
.label { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--text2); cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; }
.input { height: 44px; padding: 0 14px; border-radius: 10px; background: var(--field); border: 1px solid var(--border2);
  color: var(--text); font-family: var(--mono); font-size: 15px; font-weight: 600; width: 100%; }
.input:disabled { color: var(--dim); }
.spacer { flex: 1 1 0; }
.hint { flex-basis: 100%; margin: 0; font-size: 13px; color: var(--muted); }
.progress { flex-basis: 100%; height: 6px; background: var(--log); border-radius: 99px; overflow: hidden; display: none; }
.progress.show { display: block; }
.progress > div { height: 100%; width: 0; background: var(--accent); transition: width .4s; }

/* ── stats ── */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.stat { padding: 14px 16px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.stat .label { display: flex; align-items: center; gap: 6px; }
.stat .val { font-family: var(--mono); font-size: 24px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat .unit { font-family: var(--sans); font-size: 13px; color: var(--muted); font-weight: 500; }
.stat .note { font-size: 12px; color: var(--muted); }
.c-ok { color: var(--ok); } .c-err { color: var(--err); } .c-info { color: var(--info); } .c-warn { color: var(--warn); }

/* ── tabs ── */
.tabs-card { display: flex; flex-direction: column; min-height: 520px; overflow: hidden; }
.tabbar { display: flex; gap: 4px; padding: 0 16px; border-bottom: 1px solid var(--border); background: var(--bar); overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.tab { min-height: 48px; padding: 0 14px; background: none; border: none; border-bottom: 2px solid transparent;
  color: var(--muted); font-weight: 600; cursor: pointer; white-space: nowrap; margin-bottom: -1px; }
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--focus); }
.panel { display: none; flex: 1; flex-direction: column; min-height: 0; }
.panel.show { display: flex; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--bar); }
.sep { width: 1px; height: 20px; background: var(--border3); margin: 0 4px; }

/* log */
.log { flex: 1; min-height: 360px; max-height: 62vh; overflow: auto; margin: 0; padding: 12px 18px; background: var(--log);
  font-family: var(--mono); font-size: 13px; line-height: 1.75; }
.log .line { white-space: pre; color: #D5DAE3; }
.log .tm { color: var(--dim); }
.log .ok { color: var(--ok); } .log .err { color: var(--err); } .log .info { color: var(--info); }
.log.only-errors .line:not(.is-err) { display: none; }

/* browser */
.viewer-wrap { padding: 14px; background: var(--log); display: flex; flex-direction: column; gap: 10px; align-items: center; }
.viewer { position: relative; width: 100%; max-width: 1280px; border: 1px solid var(--border2); border-radius: 10px; overflow: hidden;
  background: #000; cursor: default; touch-action: none; aspect-ratio: 1280 / 800; }
.viewer img { display: block; width: 100%; height: 100%; object-fit: contain; user-select: none; -webkit-user-drag: none; }
.viewer .overlay { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 20px;
  color: var(--muted); background: rgba(11,13,17,.85); }
.viewer:focus { border-color: var(--focus); }
.typebar { display: flex; flex-wrap: wrap; gap: 6px; width: 100%; max-width: 1280px; }
.typebar .input { flex: 1 1 220px; font-family: var(--sans); font-weight: 500; font-size: 14px; }
.url { flex: 1 1 260px; min-width: 160px; height: 34px; font-size: 13px; font-family: var(--mono); font-weight: 500; border-radius: 8px; }

/* results */
.table-wrap { flex: 1; overflow: auto; max-height: 62vh; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { position: sticky; top: 0; background: var(--bar); color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; z-index: 1; }
td.mono { font-family: var(--mono); }
tbody tr:hover { background: #181C24; }
.empty { padding: 40px; text-align: center; color: var(--muted); }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px; border-top: 1px solid var(--border); color: var(--muted); font-size: 13px; flex-wrap: wrap; }

/* settings */
.settings { padding: 20px; display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; align-content: start; }
.box { background: var(--bar); border: 1px solid var(--border); border-radius: 12px; padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.box h3 { margin: 0; font-size: 15px; }
.box p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.55; }
.radio { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.radio input { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; }
textarea.input { height: 110px; padding: 10px 12px; font-size: 12px; font-weight: 500; resize: vertical; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.row .input { width: 120px; text-align: center; }
.save-row { grid-column: 1 / -1; display: flex; justify-content: flex-end; }

/* footer + toast */
.statusbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 20px;
  padding: 10px 24px; border-top: 1px solid var(--border); background: var(--bar); font-size: 12px; color: var(--muted); }
.statusbar b { color: var(--text); font-weight: 500; font-family: var(--mono); }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); max-width: calc(100% - 32px);
  background: #2A1E22; border: 1px solid #5A3036; color: #FFD4D6; padding: 12px 18px; border-radius: 10px; display: none; z-index: 10; }
.toast.ok { background: #16261E; border-color: #2D5A40; color: #C9F2DA; }
.toast.show { display: block; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { width: 100%; max-width: 380px; padding: 28px; display: flex; flex-direction: column; gap: 16px; }
.login .err { color: var(--err); font-size: 13px; min-height: 18px; margin: 0; }

@media (max-width: 640px) {
  .topbar, main, .statusbar { padding-left: 16px; padding-right: 16px; }
  .field { flex: 1 1 100%; }
  .controls .spacer { display: none; }
  .controls .btn { flex: 1 1 auto; }
  .stat .val { font-size: 20px; }
}
