:root {
  --bg: #f4f5f7; --panel: #ffffff; --panel-2: #f0f2f5; --line: #e1e4ea; --text: #14171d; --muted: #646d80;
  --accent: #2f6fde; --accent-text: #ffffff; --new: #e7a326; --ok: #1f9d63; --warn: #b7791f; --danger: #d33a40;
  --radius: 12px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1014; --panel: #161920; --panel-2: #1c2029; --line: #262b36; --text: #e8eaef; --muted: #8b93a7;
    --accent: #5b9bff; --accent-text: #0b1220; --new: #f2b84b; --ok: #3ecf8e; --warn: #f0b44c; --danger: #ff6b70;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1014; --panel: #161920; --panel-2: #1c2029; --line: #262b36; --text: #e8eaef; --muted: #8b93a7;
  --accent: #5b9bff; --accent-text: #0b1220; --new: #f2b84b; --ok: #3ecf8e; --warn: #f0b44c; --danger: #ff6b70;
  --shadow: none; color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }
.hidden { display: none !important; }

.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--text);
  padding: 7px 14px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.small { padding: 3px 10px; font-size: 13px; }
.btn.ghost { background: none; }
.btn.danger:hover { color: var(--danger); border-color: var(--danger); }
.btn:disabled { opacity: .5; cursor: default; }
input[type=text], input[type=password], input[type=datetime-local], select {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; min-width: 0; }
input:focus-visible, select:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- gate (login) ---------- */
.gate { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.gate-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 32px 24px; text-align: center; box-shadow: var(--shadow); }
.gate-card h1 { font-size: 20px; margin: 0 0 4px; }
.gate-card p { color: var(--muted); margin: 0 0 22px; font-size: 14px; }
.digits { display: flex; gap: 8px; justify-content: center; margin-bottom: 16px; }
.digits input { width: 44px; height: 54px; text-align: center; font-size: 24px; font-weight: 600; padding: 0;
  border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); font-variant-numeric: tabular-nums; }
.digits input:focus { border-color: var(--accent); outline: none; background: var(--panel); }
.gate-card .err { color: var(--danger); font-size: 14px; min-height: 21px; margin-bottom: 8px; }
.gate-card .wide { width: 100%; justify-content: center; padding: 10px; }
.gate-card input[type=password] { width: 100%; margin-bottom: 12px; padding: 10px 12px; }
@media (max-width: 380px) { .digits { gap: 5px; } .digits input { width: 38px; height: 48px; font-size: 20px; } }

/* ---------- header / tabs ---------- */
header.bar { position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.bar-top { display: flex; align-items: center; gap: 12px; padding: 12px 16px 0; max-width: 1200px; margin: 0 auto; }
.bar-top h1 { font-size: 16px; margin: 0; font-weight: 700; letter-spacing: -.01em; }
.bar-top .spacer { flex: 1; }
.bar-top h1 { white-space: nowrap; }
.pill { font-size: 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
@media (max-width: 480px) { .bar-top { gap: 8px; } .bar-top .spacer { display: none; } .pill { flex: 1; text-align: center; } }
nav.tabs { display: flex; gap: 2px; overflow-x: auto; padding: 10px 16px 0; max-width: 1200px; margin: 0 auto; scrollbar-width: none; }
nav.tabs::-webkit-scrollbar { display: none; }
nav.tabs button { flex: none; border: 0; background: none; color: var(--muted); padding: 8px 12px 10px; cursor: pointer;
  display: flex; gap: 8px; align-items: center; border-bottom: 2px solid transparent; }
nav.tabs button:hover { color: var(--text); }
nav.tabs button.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.count { font-size: 11px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 0 7px; font-weight: 500; font-variant-numeric: tabular-nums; }
.count.unread { background: var(--new); border-color: var(--new); color: #1b1300; font-weight: 700; }

main { max-width: 1200px; margin: 0 auto; padding: 20px 16px 64px; }

/* ---------- posts ---------- */
.feed { columns: 3 300px; column-gap: 16px; }
.post { break-inside: avoid; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 16px; overflow: hidden; box-shadow: var(--shadow); }
.post.fresh { animation: flash 2.4s ease-out; }
@keyframes flash { from { box-shadow: 0 0 0 3px var(--new); } to { box-shadow: var(--shadow); } }
.media { display: grid; gap: 2px; background: #000; }
.media.n2, .media.n4 { grid-template-columns: 1fr 1fr; }
.media.n3 { grid-template-columns: 1fr 1fr 1fr; }
.media img, .media video { width: 100%; display: block; max-height: 640px; object-fit: cover; }
.media img { cursor: zoom-in; }
.media.n1 img { object-fit: contain; }
.media:not(.n1) img { aspect-ratio: 1; }
.post .body { padding: 10px 12px; }
.post .text { white-space: pre-wrap; word-break: break-word; margin: 0 0 6px; }
.post .links { font-size: 13px; word-break: break-all; margin-bottom: 6px; }
.post .foot { display: flex; gap: 8px; color: var(--muted); font-size: 12px; align-items: center; }
.post .foot .author { font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.post .foot .btn { margin-left: auto; }
.more { display: flex; justify-content: center; margin-top: 8px; }
.empty { text-align: center; color: var(--muted); padding: 72px 16px; max-width: 520px; margin: 0 auto; }
.empty h2 { color: var(--text); font-size: 18px; margin: 0 0 6px; }

#lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.92); display: none; align-items: center; justify-content: center; z-index: 50; cursor: zoom-out; padding: 16px; }
#lightbox.open { display: flex; }
#lightbox img { max-width: 100%; max-height: 100%; }

/* ---------- admin ---------- */
.section { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 20px; box-shadow: var(--shadow); }
.section > h2 { font-size: 16px; margin: 0 0 4px; }
.section > .sub { color: var(--muted); font-size: 13px; margin: 0 0 14px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; align-items: end; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > span { font-size: 12px; color: var(--muted); font-weight: 600; }
.field .row { display: flex; gap: 6px; }
.field .row input { flex: 1; }
.code-input { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .2em; font-size: 16px !important; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; font-size: 13px; cursor: pointer; user-select: none; background: var(--panel-2); }
.chip input { margin: 0; accent-color: var(--accent); }
.msg { font-size: 13px; min-height: 20px; margin-top: 10px; }
.msg.err { color: var(--danger); }
.msg.ok { color: var(--ok); }

.table-wrap { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 16px; font-weight: 600; letter-spacing: .12em; white-space: nowrap; }
td.actions { white-space: nowrap; text-align: right; }
td.actions .btn + .btn { margin-left: 4px; }
.status { font-size: 12px; font-weight: 600; border-radius: 999px; padding: 2px 9px; white-space: nowrap; }
.status.active { color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, transparent); }
.status.expired { color: var(--warn); background: color-mix(in srgb, var(--warn) 16%, transparent); }
.status.revoked { color: var(--danger); background: color-mix(in srgb, var(--danger) 14%, transparent); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.edit-row td { background: var(--panel-2); }
.edit-row .inline { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.url-box { display: flex; gap: 6px; }
.url-box input { flex: 1; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
pre.payload { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px; font-size: 12px; overflow-x: auto; white-space: pre-wrap; word-break: break-all; max-height: 260px; margin: 6px 0 0; }
details.log { border-bottom: 1px solid var(--line); padding: 8px 0; }
details.log summary { cursor: pointer; font-size: 14px; display: flex; gap: 10px; flex-wrap: wrap; }
details.log:last-child { border-bottom: 0; }

/* ---------- listings ---------- */
.tab-sep { flex: none; width: 1px; background: var(--line); margin: 8px 6px 12px; }
.listings { max-width: 1000px; margin: 0 auto; }
.list-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.list-head h2 { margin: 0; font-size: 22px; }
.list-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.country-select { padding: 4px 8px !important; font-size: 13px; }
.day-chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 14px; scrollbar-width: none; }
.day-chips::-webkit-scrollbar { display: none; }
.chip-btn { flex: none; border: 1px solid var(--line); background: var(--panel); color: var(--muted); border-radius: 999px; padding: 5px 14px; cursor: pointer; font-size: 13px; }
.chip-btn:hover { color: var(--text); }
.chip-btn.active { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.note { font-size: 13px; color: var(--warn); margin-bottom: 10px; }
.comp { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 14px; overflow: hidden; box-shadow: var(--shadow); }
.comp h3 { margin: 0; padding: 10px 14px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); background: var(--panel-2); border-bottom: 1px solid var(--line); }
.ev { display: grid; grid-template-columns: 62px minmax(0, 1.1fr) minmax(0, 1.4fr) auto; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); align-items: start; }
.comp .ev:last-child { border-bottom: 0; }
.ev.is-hidden { opacity: .45; }
.ev-time { font-weight: 700; font-variant-numeric: tabular-nums; padding-top: 1px; }
.ev-name { font-weight: 600; }
.ev-name .score { color: var(--muted); font-weight: 500; }
.live { color: #fff; background: var(--danger); font-size: 11px; font-weight: 700; border-radius: 4px; padding: 1px 6px; }
.ev-ch { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.ch-line { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; font-size: 13px; }
.ch-flag { font-size: 15px; }
.ch-country { color: var(--muted); font-size: 12px; margin-right: 2px; }
.ch { background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 1px 7px; }
.ev-admin { display: flex; gap: 4px; }
.ev-edit { padding: 10px 14px 14px; background: var(--panel-2); border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.ev-edit textarea, .defaults-panel textarea { width: 100%; font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 8px; resize: vertical; }
.inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.defaults-panel { display: flex; flex-direction: column; gap: 8px; }
.defaults-panel h3 { margin: 0; font-size: 15px; }
.defaults-panel select { align-self: flex-start; }
.source-note { text-align: center; margin-top: 16px; }
@media (max-width: 720px) {
  .ev { grid-template-columns: 52px minmax(0, 1fr); }
  .ev-ch { grid-column: 2; }
  .ev-admin { grid-column: 2; }
}
