:root {
  --bg: #f6f7f9; --panel: #ffffff; --text: #1d2330; --muted: #677085; --line: #e2e5eb;
  --accent: #2f5fd0; --accent-soft: #e8eefc; --ok: #1f8a4c; --ok-soft: #e4f4ea;
  --warn: #a86400; --warn-soft: #fbf0dc; --bad: #c0362c; --bad-soft: #fbe6e4;
  --other: #7a6a9e; --other-soft: #efebf7; --radius: 8px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171d; --panel: #1c2028; --text: #e5e8ee; --muted: #9aa3b5; --line: #2c323d;
    --accent: #7ea2ff; --accent-soft: #23304d; --ok: #5fcf8d; --ok-soft: #1c3426;
    --warn: #f0b45a; --warn-soft: #3a2f1c; --bad: #ff8a80; --bad-soft: #3d2220;
    --other: #b8a6e6; --other-soft: #2c2640;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.topbar { background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.topbar-inner { max-width: 1280px; margin: 0 auto; padding: 0 16px; display: flex; gap: 20px; align-items: center;
  height: 52px; overflow-x: auto; }
.brand { font-weight: 700; color: var(--text); white-space: nowrap; }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a { padding: 6px 10px; border-radius: 6px; color: var(--muted); white-space: nowrap; }
.topbar nav a.on, .topbar nav a:hover { background: var(--accent-soft); color: var(--accent); text-decoration: none; }
.logout { margin-left: auto; color: var(--muted); white-space: nowrap; }

.page { max-width: 1280px; margin: 0 auto; padding: 20px 16px 60px; }
.head { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; justify-content: space-between; margin-bottom: 16px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.grid2 { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 16px; }
@media (max-width: 900px) { .grid2 { grid-template-columns: minmax(0, 1fr); } }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; }
td.num, th.num { text-align: right; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.badge.ok, .badge.published { background: var(--ok-soft); color: var(--ok); }
.badge.warn, .badge.draft { background: var(--warn-soft); color: var(--warn); }
.badge.bad, .badge.failed { background: var(--bad-soft); color: var(--bad); }
.badge.other { background: var(--other-soft); color: var(--other); }
.badge.muted, .badge.unpublished, .badge.discarded { background: var(--line); color: var(--muted); }

button, .button { font: inherit; padding: 7px 12px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); cursor: pointer; white-space: nowrap; display: inline-block; }
button:hover, .button:hover { border-color: var(--accent); text-decoration: none; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: var(--bad); }
button:disabled { opacity: .55; cursor: progress; }
button.small, .button.small { padding: 3px 8px; font-size: 12px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

input[type=text], input[type=date], input[type=number], input[type=password], select, textarea {
  font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line);
  border-radius: 6px; padding: 7px 9px; width: 100%; }
textarea { min-height: 80px; resize: vertical; }
textarea.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin: 12px 0 4px; }
.field-row { display: flex; gap: 12px; flex-wrap: wrap; }
.field-row > div { flex: 1 1 180px; }
.counter { font-weight: 400; float: right; }
.counter.over { color: var(--bad); }
.inline { display: inline-flex; gap: 6px; align-items: center; font-weight: 400; color: var(--text); margin: 0; }

.flash { position: fixed; right: 16px; bottom: 16px; max-width: 460px; padding: 10px 14px; border-radius: 8px;
  background: var(--text); color: var(--bg); z-index: 50; box-shadow: 0 4px 18px rgba(0,0,0,.2); white-space: pre-wrap; }
.flash.error { background: var(--bad); color: #fff; }
.banner { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner.bad { background: var(--bad-soft); color: var(--bad); }

/* calendar */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
.cal .dow { font-size: 12px; color: var(--muted); padding: 6px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); background: var(--panel); }
.cal .day { min-height: 110px; padding: 6px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); background: var(--panel); overflow: hidden; }
.cal .day.blank { background: transparent; }
.cal .day.today { outline: 2px solid var(--accent); outline-offset: -2px; }
.cal .dnum { font-size: 12px; color: var(--muted); }
.ev { display: block; font-size: 11.5px; line-height: 1.3; padding: 2px 5px; margin-top: 3px; border-radius: 4px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text); }
.ev.ours { background: var(--ok-soft); }
.ev.other { background: var(--other-soft); }
.ev.scheduled { background: var(--accent-soft); }
.legend { display: flex; gap: 12px; font-size: 12px; color: var(--muted); }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }
.legend .l-ours::before { background: var(--ok-soft); border: 1px solid var(--ok); }
.legend .l-other::before { background: var(--other-soft); border: 1px solid var(--other); }
.legend .l-scheduled::before { background: var(--accent-soft); border: 1px solid var(--accent); }
@media (max-width: 700px) {
  .cal { grid-template-columns: 1fr; }
  .cal .dow, .cal .day.blank { display: none; }
  .cal .day { min-height: 0; }
}

/* editor */
.tabs { display: flex; gap: 4px; margin: 12px 0 0; }
.tabs button { border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.tabs button.on { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.preview { border: 1px solid var(--line); border-radius: 0 6px 6px 6px; padding: 4px 16px; min-height: 300px; background: var(--panel); }
.preview h2 { font-size: 18px; margin: 18px 0 8px; }
.preview h3 { font-size: 15px; margin: 14px 0 6px; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin-top: 10px; }
.thumb { border: 2px solid transparent; border-radius: 6px; overflow: hidden; cursor: pointer; background: var(--line); padding: 0; text-align: left; }
.thumb:hover { border-color: var(--accent); }
.thumb img { display: block; width: 100%; height: 100px; object-fit: cover; }
.thumb .cap { font-size: 11px; padding: 3px 6px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chosen img { max-width: 100%; border-radius: 6px; display: block; }
.matches li { margin-bottom: 4px; }
.topic { border-bottom: 1px solid var(--line); padding: 12px 0; }
.topic:last-child { border-bottom: 0; }
.spinner::after { content: " …"; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .3; } }

.login-body { display: grid; place-items: center; min-height: 100vh; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 28px; width: min(360px, 92vw); }
.login-card button { width: 100%; margin-top: 10px; }
.error { color: var(--bad); margin-top: 8px; }

/* review */
.review-card { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 16px; }
.review-img img { width: 100%; aspect-ratio: 3 / 2; object-fit: cover; border-radius: 6px; display: block; }
.review-img .noimg { aspect-ratio: 3 / 2; display: grid; place-items: center; background: var(--line); border-radius: 6px; }
.review-frame { width: 100%; height: 520px; margin-top: 10px; border-radius: 6px; }
@media (max-width: 700px) { .review-card { grid-template-columns: minmax(0, 1fr); } }
