:root {
  --bg: #0f1012;
  --surface: #17181b;
  --surface-2: #1f2024;
  --line: #2a2c31;
  --text: #ececee;
  --muted: #9a9ca3;
  --faint: #6b6e76;
  --accent: #c6f36b;
  --accent-ink: #15180f;
  --live: #ff5a4e;
  --warn: #f3b552;
  --error: #ff7a70;
  --radius: 10px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
img { display: block; }
[hidden] { display: none !important; }

/* ---------- кнопки и поля ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface-2);
  cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s, transform .1s;
}
.btn:hover { background: #26282d; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: default; transform: none; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
.btn-primary:hover { background: #d4f88b; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { color: var(--error); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; }

input[type=text], input[type=password], select {
  height: 36px; padding: 0 10px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--bg); outline: none; min-width: 0;
}
input:focus, select:focus { border-color: #4a4d55; }
select { padding-right: 28px; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%239a9ca3' fill='none' stroke-width='1.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; }

.field { display: grid; gap: 6px; }
.field > span { color: var(--muted); font-size: 13px; }
.form-error { color: var(--error); margin: 0; font-size: 13px; }

.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; color: var(--muted); }
.switch input { appearance: none; width: 32px; height: 18px; border-radius: 9px; background: var(--line); position: relative; cursor: pointer; transition: background .15s; margin: 0; flex: none; }
.switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #cfd0d4; transition: transform .15s; }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(14px); background: var(--accent-ink); }

/* ---------- вход ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(340px, 100%); display: grid; gap: 16px; padding: 28px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }

/* ---------- шапка ---------- */
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; font-size: 15px; letter-spacing: -.01em; }
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--live); box-shadow: 0 0 0 4px rgba(255, 90, 78, .15); }
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 20px;
  padding: 12px max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right));
  background: rgba(15, 16, 18, .88); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.tabs { display: flex; gap: 4px; }
.tabs a { padding: 6px 12px; border-radius: 7px; color: var(--muted); transition: color .15s, background .15s; }
.tabs a:hover { color: var(--text); }
.tabs a.active { color: var(--text); background: var(--surface-2); }
.disk { margin-left: auto; display: grid; gap: 4px; min-width: 180px; font-size: 12px; color: var(--muted); }
.disk-bar { height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; display: flex; }
.disk-bar i { display: block; height: 100%; }
.disk-bar .a { background: var(--accent); }
.disk-bar .o { background: #4a4d55; }
.disk.low .disk-bar .a { background: var(--warn); }

.view { max-width: 1280px; margin: 0 auto; padding: 24px 16px 64px; }
.view-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.view-head h1 { font-size: 20px; margin: 0; letter-spacing: -.01em; }
.empty { padding: 48px 16px; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius); }
.empty .btn { margin-top: 14px; }

/* ---------- фильтр ---------- */
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 10px 0 4px; border-radius: 15px; border: 1px solid var(--line); background: transparent; cursor: pointer; color: var(--muted); }
.chip.all { padding-left: 12px; }
.chip img { width: 22px; height: 22px; border-radius: 50%; }
.chip.active { color: var(--text); border-color: #4a4d55; background: var(--surface-2); }

/* ---------- карточки записей ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 20px 16px; }
.card { display: grid; gap: 10px; min-width: 0; }
.thumb { position: relative; aspect-ratio: 16 / 9; border-radius: var(--radius); overflow: hidden; background: var(--surface); border: 1px solid var(--line); }
.thumb img { width: 100%; height: 100%; object-fit: cover; transition: transform .25s; }
a.thumb:hover img { transform: scale(1.03); }
.thumb .placeholder { position: absolute; inset: 0; display: grid; place-items: center; color: var(--faint); font-size: 13px; text-align: center; padding: 12px; }
.badge { position: absolute; padding: 2px 6px; border-radius: 5px; font-size: 12px; font-weight: 600; background: rgba(0, 0, 0, .75); font-variant-numeric: tabular-nums; }
.badge.br { right: 8px; bottom: 8px; }
.badge.tl { left: 8px; top: 8px; }
.badge.tr { right: 8px; top: 8px; }
.badge.rec { background: var(--live); color: #fff; }
.badge.rec::before { content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: #fff; margin-right: 5px; vertical-align: 1px; animation: blink 1.4s infinite; }
.badge.kind { background: rgba(0, 0, 0, .6); color: #d6d7da; font-weight: 500; }
.badge.pin { background: var(--accent); color: var(--accent-ink); }
@keyframes blink { 50% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .badge.rec::before { animation: none; } a.thumb:hover img { transform: none; } }

.card-body { display: grid; grid-template-columns: 32px 1fr auto; gap: 10px; align-items: start; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--surface-2); }
.card-title { font-weight: 600; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; word-break: break-word; }
.card-meta { color: var(--muted); font-size: 13px; }
.card-error { color: var(--warn); font-size: 12px; margin-top: 2px; word-break: break-word; }
.card-error.bad { color: var(--error); }

.menu { position: relative; }
.menu-btn { width: 30px; height: 30px; padding: 0; }
.menu-list { position: absolute; right: 0; top: 34px; z-index: 5; min-width: 180px; padding: 6px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 12px 32px rgba(0, 0, 0, .45); display: grid; transform-origin: top right; animation: pop .14s ease-out; }
.menu-list button, .menu-list a { text-align: left; padding: 8px 10px; border-radius: 6px; border: 0; background: none; cursor: pointer; }
.menu-list button:hover, .menu-list a:hover { background: #2a2c31; }
@keyframes pop { from { opacity: 0; transform: scale(.96); } }

/* ---------- стримеры ---------- */
.add-form { display: flex; gap: 8px; flex-wrap: wrap; padding: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 18px; }
.add-form input { flex: 1 1 220px; }
.list { display: grid; gap: 10px; }
.streamer { padding: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); display: grid; gap: 12px; }
.streamer.off { opacity: .6; }
.streamer-head { display: grid; grid-template-columns: 44px 1fr auto; gap: 12px; align-items: center; }
.streamer-head .avatar { width: 44px; height: 44px; }
.streamer-name { font-weight: 600; font-size: 15px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.live-pill { font-size: 11px; font-weight: 700; letter-spacing: .04em; padding: 2px 6px; border-radius: 4px; background: var(--live); color: #fff; }
.rec-pill { font-size: 11px; font-weight: 600; padding: 2px 6px; border-radius: 4px; background: rgba(255, 90, 78, .15); color: var(--live); }
.streamer-sub { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.streamer-controls { display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center; }
.ctl { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.ctl select { height: 30px; font-size: 13px; }
.streamer-actions { display: flex; gap: 6px; margin-left: auto; }

.vods { border-top: 1px solid var(--line); padding-top: 12px; display: grid; gap: 8px; }
.vod-row { display: grid; grid-template-columns: 128px 1fr auto; gap: 12px; align-items: center; }
.vod-row img { width: 128px; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 6px; background: var(--surface-2); }
.vod-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vod-state { font-size: 13px; color: var(--muted); }
.vod-state.ok { color: var(--accent); }

/* ---------- плеер ---------- */
.watch { display: grid; gap: 16px; }
.watch video, .watch audio { width: 100%; max-height: 78vh; background: #000; border-radius: var(--radius); }
.watch audio { background: transparent; }
.watch-head { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; }
.watch-head h1 { font-size: 19px; margin: 0 0 4px; word-break: break-word; }
.watch-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.back { color: var(--muted); display: inline-flex; gap: 6px; align-items: center; }
.back:hover { color: var(--text); }
.notice { padding: 12px 14px; border-radius: var(--radius); background: rgba(243, 181, 82, .1); color: var(--warn); border: 1px solid rgba(243, 181, 82, .25); }

/* ---------- журнал ---------- */
.log { display: grid; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.log-row { display: grid; grid-template-columns: 120px 1fr; gap: 12px; padding: 10px 14px; border-top: 1px solid var(--line); }
.log-row:first-child { border-top: 0; }
.log-row time { color: var(--faint); font-variant-numeric: tabular-nums; font-size: 13px; }
.log-row.warn span { color: var(--warn); }
.log-row.error span { color: var(--error); }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50; max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 10px; background: #2a2c31; border: 1px solid #3a3c42; box-shadow: 0 10px 30px rgba(0, 0, 0, .4); animation: rise .2s ease-out; }
.toast.error { border-color: rgba(255, 122, 112, .5); }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 8px); } }

@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; gap: 10px 14px; }
  .tabs { order: 3; width: 100%; overflow-x: auto; }
  .disk { min-width: 0; flex: 1; }
  .grid { grid-template-columns: 1fr; }
  .vod-row { grid-template-columns: 96px 1fr; }
  .vod-row img { width: 96px; }
  .vod-row > :last-child { grid-column: 1 / -1; justify-self: start; }
  .streamer-actions { margin-left: 0; }
  .log-row { grid-template-columns: 1fr; gap: 2px; }
}
.avatar-fallback { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--surface-2); color: var(--muted); font-size: 12px; font-weight: 600; flex: none; }
.avatar.avatar-fallback { width: 32px; height: 32px; font-size: 14px; }
.streamer-head .avatar.avatar-fallback { width: 44px; height: 44px; font-size: 17px; }
