:root {
  --bg: #0d0f13;
  --panel: #161a21;
  --panel-2: #1d222b;
  --line: #2a303b;
  --text: #e8ebf0;
  --muted: #9aa3b2;
  --accent: #4ea1ff;
  --accent-2: #2f7fe0;
  --rec: #2fbf8f;
  --rec-dim: #1f6f57;
  --live: #ff5a5f;
  --sel: #ffb547;
  --danger: #ff6b6b;
  --ok: #3ccf91;
  --radius: 10px;
  --tap: 44px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }
[hidden] { display: none !important; }
svg.i { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
svg.i.fill { fill: currentColor; stroke: none; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: var(--tap); min-width: var(--tap); padding: 0 12px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel-2); cursor: pointer; user-select: none; white-space: nowrap;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: #252b36; }
.btn:active { background: #2c3340; }
.btn:focus-visible, .seg button:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent-2); border-color: var(--accent-2); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--accent); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.small { min-height: 34px; padding: 0 10px; font-size: 14px; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--panel-2); }
.seg button { min-height: var(--tap); min-width: 46px; padding: 0 10px; border: 0; background: transparent; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--accent-2); color: #fff; font-weight: 600; }
.seg button:disabled { opacity: .4; cursor: default; }

input[type=text], input[type=password], input[type=date], select {
  min-height: var(--tap); padding: 0 12px; border-radius: var(--radius);
  border: 1px solid var(--line); background: #0f1218; width: 100%;
}
label { display: block; color: var(--muted); font-size: 14px; margin: 14px 0 6px; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 30px); opacity: 0; pointer-events: none;
  background: #222834; border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 16px;
  max-width: calc(100vw - 32px); transition: opacity .2s, transform .2s; z-index: 50;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { border-color: var(--danger); }
#toast.ok { border-color: var(--ok); }

/* ---------- login ---------- */
.login-page { display: grid; place-items: center; min-height: 100%; padding: 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px 24px; }
.login-card h1 { margin: 0 0 4px; font-size: 22px; display: flex; align-items: center; gap: 10px; }
.login-card p.sub { margin: 0 0 8px; color: var(--muted); }
.login-card .btn { width: 100%; margin-top: 20px; }
.err { color: var(--danger); min-height: 1.4em; margin-top: 12px; }
.site-login { border-top: 1px solid var(--line); margin-top: 12px; padding-top: 4px; text-align: center; }
.site-login .or { display: block; color: var(--muted); font-size: 13px; margin-top: 8px; }
.site-login .btn { margin-top: 8px; justify-content: center; }

/* ---------- top bar ---------- */
.bar {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10;
}
.bar .brand { font-weight: 700; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.bar .brand svg { color: var(--accent); }
.bar .spacer { flex: 1; }
.bar select { width: auto; min-width: 0; max-width: 40vw; }
.bar .btn .lbl { display: inline; }

/* ---------- player ---------- */
.layout {
  max-width: 1440px; margin: 0 auto; padding: 0 0 24px;
  display: grid; grid-template-columns: minmax(0, 1fr); grid-template-areas: "player" "side" "dl";
}
.area-player { grid-area: player; min-width: 0; }
.area-side { grid-area: side; margin: 10px 12px 0; min-width: 0; }
.area-dl { grid-area: dl; }
.side-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.side-cal { display: none; }
.days-title { color: var(--muted); font-size: 13px; margin: 0 0 8px; }
.days { position: relative; display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: thin; }
.day {
  flex: none; display: flex; flex-direction: column; align-items: flex-start; gap: 1px;
  min-height: var(--tap); padding: 6px 10px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--panel-2); cursor: pointer; text-align: left;
}
.day:hover { background: #252b36; }
.day .d1 { font-weight: 600; white-space: nowrap; }
.day .d2 { font-size: 12px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.day.cur { border-color: var(--accent); background: #1b2a3d; }
.day.cur .d1 { color: #fff; }
#dateBtn .caret { width: 16px; height: 16px; opacity: .7; }

@media (min-width: 1100px) {
  .layout {
    grid-template-columns: minmax(0, 1fr) 300px; grid-template-areas: "player side" "dl side";
    column-gap: 16px; padding: 12px 16px 24px; align-items: start;
  }
  .stage { border-radius: 12px; }
  .area-side { margin: 0; display: grid; gap: 12px; position: sticky; top: 72px; }
  .side-cal { display: block; }
  .days { flex-direction: column; overflow-x: hidden; overflow-y: auto; max-height: calc(100vh - 520px); min-height: 140px; }
  .day { flex-direction: row; justify-content: space-between; align-items: center; width: 100%; }
  .area-dl { margin: 12px 0 0; }
}
.stage { position: relative; background: #000; aspect-ratio: 16 / 9; width: 100%; overflow: hidden; }
.stage video { width: 100%; height: 100%; display: block; object-fit: contain; background: #000; }
.stage:fullscreen { aspect-ratio: auto; }
.clock {
  position: absolute; left: 10px; top: 10px; padding: 4px 10px; border-radius: 8px;
  background: rgba(0, 0, 0, .55); font-variant-numeric: tabular-nums; font-weight: 600; letter-spacing: .3px;
  pointer-events: none;
}
.clock .d { color: var(--muted); font-weight: 500; margin-right: 6px; }
.badge {
  position: absolute; right: 10px; top: 10px; padding: 3px 8px; border-radius: 6px; font-size: 13px; font-weight: 700;
  background: rgba(0, 0, 0, .55); pointer-events: none;
}
.state {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 16px;
  color: var(--muted); pointer-events: none; background: rgba(0, 0, 0, .25);
}
.spinner { width: 34px; height: 34px; border: 3px solid rgba(255, 255, 255, .2); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; margin: 0 auto 10px; }
@keyframes spin { to { transform: rotate(360deg); } }
.bigplay {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 72px; height: 72px; border-radius: 50%;
  border: 0; background: rgba(0, 0, 0, .55); color: #fff; display: grid; place-items: center; cursor: pointer;
}
.bigplay svg { width: 34px; height: 34px; }

.controls { padding: 10px 12px 4px; display: grid; gap: 8px; }
.controls .row { display: flex; gap: 6px; align-items: center; justify-content: center; flex-wrap: wrap; }
.controls .row.main .btn { flex: 1 1 0; padding: 0 4px; max-width: 110px; }
.controls .row.main .btn.play { flex-basis: 0; background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
.controls .row.main .btn.play:hover { background: var(--accent); }
.controls .row.opts { justify-content: space-between; }
.controls .row.opts .grp { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

.timeline-wrap { padding: 4px 12px 0; }
.tl-head { display: flex; align-items: center; gap: 6px; margin: 4px 0 6px; }
.tl-head .now { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 14px; flex: 1; text-align: center; }
.tl-box { position: relative; }
#timeline {
  width: 100%; height: 84px; display: block; border-radius: var(--radius); background: var(--panel);
  border: 1px solid var(--line); touch-action: none; cursor: grab;
}
#timeline.dragging { cursor: grabbing; }
.tl-preview {
  position: absolute; bottom: calc(100% + 8px); transform: translateX(-50%); pointer-events: none; z-index: 5;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 4px; text-align: center;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .5); font-variant-numeric: tabular-nums; font-size: 13px;
}
.tl-preview img { display: block; width: 192px; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 5px; background: #000; }
.tl-preview img[hidden] + span { padding: 2px 6px; }
.tl-legend { display: flex; gap: 14px; color: var(--muted); font-size: 12px; margin-top: 6px; flex-wrap: wrap; }
.tl-legend i { display: inline-block; width: 12px; height: 8px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }
.tl-legend .lg-rec { background: var(--rec); }
.tl-legend .lg-live { background: var(--live); }
.tl-legend .lg-sel { background: var(--sel); }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.panel { margin: 12px; padding: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
.panel h2 { font-size: 16px; margin: 0 0 10px; }
.dl-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.dl-field { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px; }
.dl-field .k { color: var(--muted); font-size: 13px; }
.dl-field .v { font-variant-numeric: tabular-nums; font-weight: 600; margin: 2px 0 6px; }
.dl-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; align-items: center; }
.progress { height: 8px; background: var(--panel-2); border-radius: 4px; overflow: hidden; flex: 1 1 160px; }
.progress > div { height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.hint { color: var(--muted); font-size: 13px; margin: 8px 0 0; }

/* ---------- calendar ---------- */
.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .6); display: grid; place-items: center; z-index: 30; padding: 16px; }
.modal .card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px; width: 100%; max-width: 360px; }
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cal-head strong { font-size: 16px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-grid .wd { text-align: center; color: var(--muted); font-size: 12px; padding: 4px 0; }
.cal-grid button {
  aspect-ratio: 1; border: 1px solid transparent; border-radius: 8px; background: transparent; cursor: pointer;
  color: #59616e; position: relative; min-height: 38px;
}
.cal-grid button.has { color: var(--text); background: var(--panel-2); border-color: var(--line); font-weight: 600; }
.cal-grid button.has::after { content: ""; position: absolute; left: 50%; bottom: 5px; width: 5px; height: 5px; margin-left: -2.5px; border-radius: 50%; background: var(--rec); }
.cal-grid button.cur { border-color: var(--accent); }
.cal-grid button.today { text-decoration: underline; text-underline-offset: 3px; }
.cal-grid button:disabled { cursor: default; }
.cal-foot { display: flex; justify-content: space-between; margin-top: 12px; }

/* ---------- admin ---------- */
.admin main { max-width: 1100px; margin: 0 auto; padding: 12px; }
.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--line); margin-bottom: 14px; scrollbar-width: none; }
.tabs button { border: 0; background: transparent; padding: 12px 14px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; min-height: var(--tap); }
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 14px; }
.card h2 { margin: 0 0 12px; font-size: 17px; }
.card h3 { margin: 18px 0 8px; font-size: 15px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 12px; align-items: end; }
.form-actions { margin-top: 14px; display: flex; gap: 8px; flex-wrap: wrap; }
.tbl-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 500; white-space: nowrap; }
td.num, td.when { font-variant-numeric: tabular-nums; white-space: nowrap; }
td .btn { margin: 0 4px 4px 0; }
.tag { display: inline-block; padding: 1px 7px; border-radius: 6px; font-size: 12px; background: var(--panel-2); border: 1px solid var(--line); white-space: nowrap; }
.tag.ok { color: var(--ok); border-color: #245c45; }
.tag.bad { color: var(--danger); border-color: #6a2b2b; }
.tag.warn { color: var(--sel); border-color: #6a4f20; }
.qr { background: #fff; padding: 10px; border-radius: 10px; display: inline-block; line-height: 0; }
.qr svg { width: 200px; height: 200px; }
#totpCode { max-width: 220px; font-size: 20px; letter-spacing: 4px; }
.secret { font-family: ui-monospace, Consolas, monospace; letter-spacing: 1px; word-break: break-all; background: var(--panel-2); padding: 6px 8px; border-radius: 6px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.notice { border-left: 3px solid var(--sel); padding: 8px 12px; background: var(--panel-2); border-radius: 6px; margin-bottom: 14px; }
.ua { color: var(--muted); font-size: 12px; max-width: 320px; }

dialog {
  background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 14px;
  padding: 18px; width: min(420px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(0, 0, 0, .6); }
dialog h2 { margin: 0 0 8px; font-size: 17px; }
.tabs button:disabled { opacity: .4; cursor: default; }

@media (max-width: 640px) {
  .bar { padding: 6px 8px; gap: 6px; }
  .bar .brand .name, .bar .btn .lbl { display: none; }
  .controls { padding: 8px 8px 2px; }
  .controls .row.main { gap: 4px; }
  .controls .row.main .btn { font-size: 13px; }
  .controls .row.opts { justify-content: center; }
  .timeline-wrap { padding: 4px 8px 0; }
  .clock { font-size: 13px; left: 6px; top: 6px; }
  .tl-preview img { width: 160px; }
  .panel { margin: 10px 8px; }
  .dl-grid { grid-template-columns: 1fr; }
}
@media (orientation: landscape) and (max-height: 500px) {
  .bar { display: none; }
  .stage { aspect-ratio: auto; height: 70vh; }
}
