:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --ink: #0f1b2d;
  --ink-2: #4a5872;
  --ink-3: #8592a8;
  --line: #e2e7ef;
  --brand: #0b5cd6;
  --brand-ink: #ffffff;
  --brand-soft: #e7f0fd;
  --ok: #12805c;
  --ok-soft: #e3f5ee;
  --warn: #a75b00;
  --warn-soft: #fff2de;
  --bad: #c62f2f;
  --bad-soft: #fde8e8;
  --muted-soft: #eef1f5;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(15, 27, 45, .06), 0 4px 16px rgba(15, 27, 45, .06);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c121c;
    --surface: #141c29;
    --surface-2: #19222f;
    --ink: #e8edf5;
    --ink-2: #a8b4c7;
    --ink-3: #6f7d93;
    --line: #253043;
    --brand: #4d8ff5;
    --brand-soft: #172a47;
    --ok: #3cc290;
    --ok-soft: #143229;
    --warn: #f0a94a;
    --warn-soft: #3a2a12;
    --bad: #f07070;
    --bad-soft: #3a1919;
    --muted-soft: #1d2634;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--brand); }
h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -0.01em; }
button, input, select, textarea { font: inherit; color: inherit; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px; }
.narrow { max-width: 560px; margin: 0 auto; padding: 0 16px; }

/* top bar */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topbar .wrap, .topbar .narrow { display: flex; align-items: center; gap: 12px; height: 58px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; text-decoration: none; color: var(--ink); }
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px; background: var(--brand); color: #fff;
  display: grid; place-items: center; font-weight: 800; font-size: 13px; letter-spacing: .02em;
}
.brand small { display: block; font-weight: 500; font-size: 12px; color: var(--ink-3); margin-top: 1px; }
.spacer { flex: 1; }

/* cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px; }
.card-head { display: flex; align-items: center; gap: 10px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.card-head h2 { font-size: 16px; }

/* forms */
label.f { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin: 0 0 6px; }
.input, select.input, textarea.input {
  width: 100%; height: 44px; padding: 0 12px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); outline: none; transition: border-color .15s, box-shadow .15s;
}
textarea.input { height: auto; min-height: 80px; padding: 10px 12px; resize: vertical; }
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.input.mono { font-family: var(--mono); }
.field { margin-bottom: 14px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap-row { flex-wrap: wrap; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 44px; padding: 0 16px; border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--surface); font-weight: 600; cursor: pointer; text-decoration: none; color: var(--ink);
  white-space: nowrap; transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--bad); }
.btn.sm { height: 34px; padding: 0 11px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--muted-soft); }
.btn svg { width: 18px; height: 18px; flex: none; }
.btn.sm svg { width: 16px; height: 16px; }
.icon-btn { width: 34px; padding: 0; }

/* badges */
.badge { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 9px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--muted-soft); color: var(--ink-2); white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .85; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--brand-soft); color: var(--brand); }

.muted { color: var(--ink-3); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); }
.hidden { display: none !important; }

/* chips */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip { border: 1px solid var(--line); background: var(--surface-2); border-radius: 99px; height: 30px; padding: 0 11px; font-size: 12.5px; cursor: pointer; color: var(--ink-2); }
.chip:hover { border-color: var(--brand); color: var(--brand); }

/* copy field */
.copybox { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-2); padding: 5px 5px 5px 12px; }
.copybox code { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--mono); font-size: 13px; }

/* toast */
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: var(--ink); color: var(--surface); padding: 11px 16px; border-radius: 10px; font-weight: 600; font-size: 14px; opacity: 0; pointer-events: none; transition: all .2s; z-index: 100; max-width: calc(100% - 32px); }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.bad { background: var(--bad); color: #fff; }

/* progress */
.bar { height: 6px; background: var(--muted-soft); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0; background: var(--brand); border-radius: 99px; transition: width .2s; }
.bar.ok > i { background: var(--ok); }
.bar.bad > i { background: var(--bad); }

.spin { width: 18px; height: 18px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

.empty { text-align: center; padding: 48px 16px; color: var(--ink-3); }
.empty svg { width: 40px; height: 40px; opacity: .5; margin-bottom: 8px; }

/* media grid (viewer + admin drawer) */
.mgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.mitem { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; display: flex; flex-direction: column; }
.mthumb { position: relative; aspect-ratio: 4 / 3; background: #0b1220; display: grid; place-items: center; cursor: pointer; overflow: hidden; }
.mthumb img, .mthumb video { width: 100%; height: 100%; object-fit: contain; display: block; }
.mthumb .play { position: absolute; width: 52px; height: 52px; border-radius: 50%; background: rgba(0,0,0,.55); display: grid; place-items: center; color: #fff; backdrop-filter: blur(3px); }
.mthumb .play svg { width: 22px; height: 22px; margin-left: 3px; }
.mthumb .dur { position: absolute; right: 8px; bottom: 8px; background: rgba(0,0,0,.65); color: #fff; font-size: 12px; font-weight: 600; padding: 2px 7px; border-radius: 6px; }
.mthumb .kind { position: absolute; left: 8px; top: 8px; background: rgba(0,0,0,.6); color: #fff; font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 6px; letter-spacing: .03em; text-transform: uppercase; }
.mthumb .proc { color: #cfd8e6; font-size: 13px; display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; padding: 10px; }
.mmeta { padding: 10px 12px; display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--ink-3); }
.mmeta .grow { flex: 1; min-width: 0; }

/* lightbox */
.lightbox { position: fixed; inset: 0; background: rgba(5,9,16,.94); z-index: 90; display: flex; flex-direction: column; }
.lightbox .lb-top { display: flex; align-items: center; gap: 8px; padding: 10px 12px; color: #fff; }
.lightbox .lb-top .btn { background: rgba(255,255,255,.1); color: #fff; border-color: transparent; }
.lightbox .lb-body { flex: 1; display: grid; place-items: center; min-height: 0; padding: 0 8px 12px; position: relative; }
.lightbox .lb-body img, .lightbox .lb-body video { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 6px; }
.lightbox .nav { position: absolute; top: 50%; transform: translateY(-50%); width: 46px; height: 46px; border-radius: 50%; border: 0; background: rgba(255,255,255,.12); color: #fff; display: grid; place-items: center; cursor: pointer; }
.lightbox .nav svg { width: 22px; height: 22px; }
.lightbox .nav.prev { left: 12px; }
.lightbox .nav.next { right: 12px; }

@media (max-width: 640px) {
  .mgrid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .card-pad { padding: 14px; }
  .lightbox .nav { display: none; }
}
