:root {
  --bg: #f3f4f0;
  --surface: #ffffff;
  --surface-2: #f8f9f6;
  --ink: #13171d;
  --muted: #5c6370;
  --faint: #8a909a;
  --line: #e1e3dd;
  --line-strong: #cfd2ca;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #dcefeb;
  --accent-line: #a7d6cd;
  --ok: #157f3c;
  --ok-soft: #dff3e6;
  --warn: #a14d07;
  --warn-soft: #fbeedb;
  --danger: #b42318;
  --danger-soft: #fbe4e1;
  --code-bg: #10151b;
  --code-ink: #d9e1e8;
  --shadow: 0 1px 2px rgba(20, 24, 30, .05), 0 4px 16px rgba(20, 24, 30, .05);
  --radius: 12px;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1013;
    --surface: #151a1f;
    --surface-2: #1a2026;
    --ink: #e7eaee;
    --muted: #a0a8b2;
    --faint: #737c87;
    --line: #252c33;
    --line-strong: #323a43;
    --accent: #2cc5b1;
    --accent-ink: #062320;
    --accent-soft: #11332f;
    --accent-line: #1e5a52;
    --ok: #4ad37b;
    --ok-soft: #12301e;
    --warn: #f0a650;
    --warn-soft: #34250f;
    --danger: #f2776b;
    --danger-soft: #3a1714;
    --code-bg: #0a0d10;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 Manrope, system-ui, -apple-system, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
code, .mono { font-family: var(--mono); font-size: .88em; }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
[hidden] { display: none !important; }

/* ---------- login ---------- */
.login {
  min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
  background:
    radial-gradient(1200px 500px at 85% -10%, var(--accent-soft), transparent 60%),
    var(--bg);
}
.login-card {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 18px; padding: 32px 28px; box-shadow: var(--shadow);
}
.login-card h1 { font-size: 22px; margin: 18px 0 4px; }
.login-card p { color: var(--muted); margin: 0 0 22px; font-size: 14px; }
.login-card .field { margin-bottom: 14px; }
.login-card .btn { width: 100%; justify-content: center; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 280px 1fr; min-height: 100vh; }
.side {
  border-right: 1px solid var(--line); background: var(--surface);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; flex: none;
}
.brand-mark svg.i { width: 20px; height: 20px; }
.login-card .brand-mark { width: 44px; height: 44px; border-radius: 12px; }
.login-card .brand-mark svg.i { width: 26px; height: 26px; }
.brand-name { font-weight: 800; font-size: 15px; line-height: 1.1; }
.brand-sub { font-size: 12px; color: var(--muted); }
.side-actions { padding: 4px 14px 12px; }
.side-label { padding: 8px 18px 6px; font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--faint); }
.site-list { list-style: none; margin: 0; padding: 0 8px; overflow: auto; flex: 1; }
.site-item {
  width: 100%; text-align: left; border: 0; background: none; cursor: pointer;
  padding: 10px 10px; border-radius: 9px; display: grid; grid-template-columns: 1fr auto; gap: 2px 8px;
}
.site-item:hover { background: var(--surface-2); }
.site-item.active { background: var(--accent-soft); }
.site-item .n { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.site-item .m { font-size: 12px; color: var(--muted); grid-column: 1 / -1; }
.side-foot { border-top: 1px solid var(--line); padding: 10px 14px; display: flex; gap: 6px; }
.empty-side { color: var(--muted); font-size: 13px; padding: 6px 18px; }

.main { min-width: 0; padding: 26px 32px 120px; max-width: 1180px; }
.topbar-mobile { display: none; }

/* ---------- site header ---------- */
.site-head { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 14px 20px; margin-bottom: 18px; }
.site-title { flex: 1; min-width: 260px; }
.site-title input {
  border: 1px solid transparent; background: transparent; font-size: 26px; font-weight: 800;
  letter-spacing: -.02em; padding: 2px 6px; margin-left: -7px; border-radius: 8px; width: 100%;
}
.site-title input:hover { border-color: var(--line); }
.site-title input:focus { outline: none; border-color: var(--accent); background: var(--surface); }
.site-meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 6px; color: var(--muted); font-size: 13px; }

.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 700; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted);
  white-space: nowrap;
}
.chip.accent { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }
.chip.ok { background: var(--ok-soft); border-color: transparent; color: var(--ok); }
.chip.warn { background: var(--warn-soft); border-color: transparent; color: var(--warn); }
.chip.danger { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.url-box {
  display: flex; align-items: stretch; border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
  overflow: hidden; max-width: 100%; box-shadow: var(--shadow);
}
.url-box .lbl { padding: 8px 12px; font-size: 12px; font-weight: 700; color: var(--muted); border-right: 1px solid var(--line); display: flex; align-items: center; white-space: nowrap; }
.url-box code { padding: 8px 12px; display: flex; align-items: center; overflow-x: auto; white-space: nowrap; min-width: 0; }
.url-box button { border: 0; border-left: 1px solid var(--line); background: var(--surface-2); padding: 0 14px; cursor: pointer; font-weight: 700; font-size: 13px; }
.url-box button:hover { color: var(--accent); }

/* ---------- tabs ---------- */
.tabs {
  display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin: 6px 0 22px; overflow-x: auto;
  scrollbar-width: none; position: sticky; top: 0; background: var(--bg); z-index: 5;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  border: 0; background: none; padding: 11px 14px; cursor: pointer; font-weight: 650; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; display: flex; gap: 6px; align-items: center;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--ink); border-bottom-color: var(--accent); }
.tab .count { font-size: 11px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 0 7px; }
.tab .bad { width: 7px; height: 7px; border-radius: 50%; background: var(--danger); }

/* ---------- cards & forms ---------- */
.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-head { padding: 16px 20px 0; display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; }
.card-head h2 { font-size: 16px; }
.card-head p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.card-body { padding: 16px 20px 20px; }
.card + .card { margin-top: 16px; }
.section-gap { height: 16px; }

.fields { display: grid; gap: 14px 16px; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.fields.wide { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field.span2 { grid-column: span 2; }
.field.full { grid-column: 1 / -1; }
.field > label, .label { font-size: 13px; font-weight: 650; }
.hint { font-size: 12px; color: var(--muted); line-height: 1.45; }
.param { font-family: var(--mono); font-size: 11px; color: var(--faint); }

.input, select.input, textarea.input {
  width: 100%; border: 1px solid var(--line-strong); background: var(--surface); border-radius: 9px;
  padding: 9px 11px; min-height: 40px; transition: border-color .12s, box-shadow .12s;
}
textarea.input { min-height: 120px; font-family: var(--mono); font-size: 13px; resize: vertical; }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input.mono { font-family: var(--mono); font-size: 13.5px; }
.input.invalid { border-color: var(--danger); }

.seg { align-self: flex-start; display: inline-flex; border: 1px solid var(--line-strong); border-radius: 10px; padding: 3px; background: var(--surface-2); flex-wrap: wrap; gap: 2px; }
.seg button { border: 0; background: none; padding: 6px 12px; border-radius: 7px; cursor: pointer; font-weight: 650; font-size: 13px; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.seg.srtp button.on[data-v="2"] { background: var(--accent); color: var(--accent-ink); }

.switch { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; }
.switch input { appearance: none; width: 38px; height: 22px; border-radius: 999px; background: var(--line-strong); position: relative; flex: none; cursor: pointer; transition: background .15s; margin: 1px 0 0; }
.switch input::after { content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(16px); }
.switch input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch .t { font-weight: 650; font-size: 14px; }

.btn {
  display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--line-strong); background: var(--surface);
  padding: 8px 14px; border-radius: 9px; cursor: pointer; font-weight: 700; font-size: 14px; min-height: 38px; text-decoration: none; color: var(--ink);
}
.btn:hover { border-color: var(--faint); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 10px; min-height: 30px; font-size: 13px; }
.btn.block { width: 100%; justify-content: center; }
.icon-btn { border: 0; background: none; cursor: pointer; padding: 6px; border-radius: 7px; color: var(--muted); display: inline-grid; place-items: center; }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn.danger:hover { color: var(--danger); background: var(--danger-soft); }
svg.i { width: 16px; height: 16px; flex: none; }

/* ---------- alerts ---------- */
.alerts { display: grid; gap: 8px; margin-bottom: 18px; }
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 10px 14px; border-radius: 10px; font-size: 14px; }
.alert.error { background: var(--danger-soft); color: var(--danger); }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.info { background: var(--accent-soft); color: var(--ink); }
.alert svg { margin-top: 2px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; font-weight: 700; color: var(--muted); padding: 8px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td .input { min-height: 36px; padding: 6px 9px; }
td.num { color: var(--faint); font-family: var(--mono); font-size: 13px; width: 34px; }
.pw { position: relative; }
.pw .input { padding-right: 34px; }
.pw button { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); }
.ipui-state { font-size: 11px; margin-top: 3px; display: flex; gap: 6px; align-items: center; white-space: nowrap; }

/* ---------- bases ---------- */
.base-card { border: 1px solid var(--line); border-radius: 10px; padding: 14px; background: var(--surface-2); }
.base-card + .base-card { margin-top: 12px; }
.base-card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 8px; }
.base-card-head strong { display: flex; align-items: center; gap: 8px; }
.badge-n { width: 24px; height: 24px; border-radius: 7px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-size: 12px; font-weight: 800; }

/* ---------- codecs ---------- */
.codecs { display: grid; gap: 6px; max-width: 520px; }
.codec { display: grid; grid-template-columns: auto 1fr auto auto; gap: 10px; align-items: center; padding: 7px 10px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); }
.codec.off { opacity: .55; }
.codec .rank { font-family: var(--mono); font-size: 12px; color: var(--faint); width: 18px; text-align: center; }

/* ---------- files ---------- */
.file { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.file + .file { margin-top: 12px; }
.file-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px; background: var(--surface-2); flex-wrap: wrap; }
.file-head .nm { font-family: var(--mono); font-weight: 500; }
.file-head .lb { color: var(--muted); font-size: 13px; }
pre.code {
  margin: 0; padding: 14px 16px; background: var(--code-bg); color: var(--code-ink); font: 12.5px/1.6 var(--mono);
  max-height: 420px; overflow: auto; white-space: pre;
}
pre.code .c { color: #7d8b99; }
pre.code .k { color: #7fd8c9; }
pre.code .v { color: #f3d99b; }

.steps { counter-reset: s; list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; }
.steps li { counter-increment: s; display: grid; grid-template-columns: 30px 1fr; gap: 12px; }
.steps li::before { content: counter(s); width: 28px; height: 28px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 800; display: grid; place-items: center; font-size: 13px; }
.steps b { display: block; margin-bottom: 2px; }
.steps p { margin: 0; color: var(--muted); font-size: 14px; }

/* ---------- log ---------- */
.log td { font-size: 13px; white-space: nowrap; }
.log td.ua { white-space: normal; color: var(--muted); font-size: 12px; min-width: 200px; }

/* ---------- save bar ---------- */
.savebar {
  position: fixed; bottom: 18px; left: calc(280px + 32px); right: 32px; max-width: 1116px;
  background: var(--ink); color: var(--bg); border-radius: 12px; padding: 10px 12px 10px 18px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.25);
  transform: translateY(140%); transition: transform .2s ease, visibility .2s; z-index: 20; visibility: hidden;
}
.savebar.show { transform: none; visibility: visible; }
.savebar .btn { border-color: transparent; }
.savebar .btn.ghost { color: var(--bg); }
.savebar .btn.ghost:hover { background: rgba(127,127,127,.2); }

#toast {
  position: fixed; top: 16px; left: 50%; transform: translate(-50%, -150%); background: var(--ink); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; font-weight: 650; font-size: 14px; transition: transform .2s, visibility .2s; z-index: 50; max-width: calc(100% - 32px); visibility: hidden;
}
#toast.show { transform: translate(-50%, 0); visibility: visible; }
#toast.err { background: var(--danger); color: #fff; }

/* ---------- welcome / modal ---------- */
.welcome { max-width: 720px; margin: 40px auto; text-align: center; }
.welcome h1 { font-size: 30px; margin-bottom: 10px; letter-spacing: -.02em; }
.welcome > p { color: var(--muted); margin: 0 auto 28px; max-width: 540px; }
.model-pick { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; text-align: left; }
.model-card { border: 1.5px solid var(--line); border-radius: 14px; padding: 18px; background: var(--surface); cursor: pointer; display: block; }
.model-card:hover { border-color: var(--accent-line); }
.model-card.on { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.model-card input { position: absolute; opacity: 0; pointer-events: none; }
.model-card h3 { font-size: 17px; margin-bottom: 4px; }
.model-card p { margin: 0; color: var(--muted); font-size: 13.5px; }
.model-card ul { margin: 10px 0 0; padding-left: 18px; color: var(--muted); font-size: 13px; }

.modal-bg { position: fixed; inset: 0; background: rgba(10, 14, 18, .45); display: grid; place-items: center; padding: 16px; z-index: 40; }
.modal { background: var(--surface); border-radius: 16px; width: 100%; max-width: 560px; max-height: calc(100vh - 32px); overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal-head { padding: 20px 22px 0; display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 16px 22px; }
.modal-foot { padding: 0 22px 20px; display: flex; justify-content: flex-end; gap: 8px; }

.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row.between { justify-content: space-between; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.spacer { flex: 1; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 290px; z-index: 30; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .shell.nav-open .side { transform: none; }
  .shell.nav-open::after { content: ''; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 25; }
  .topbar-mobile { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; z-index: 10; }
  .main { padding: 18px 16px 120px; }
  .tabs { top: 57px; }
  .savebar { left: 16px; right: 16px; }
  .grid.two, .model-pick { grid-template-columns: 1fr; }
  .field.span2 { grid-column: auto; }
  .site-title input { font-size: 22px; }
}
@media (max-width: 520px) {
  .fields, .fields.wide { grid-template-columns: 1fr; }
  .url-box { flex-wrap: wrap; }
  .url-box .lbl { border-right: 0; border-bottom: 1px solid var(--line); width: 100%; }
  .url-box code { flex: 1; }
}
