:root {
  --bg: #f4f5f7; --panel: #ffffff; --text: #1d2330; --muted: #6b7280; --line: #e3e6eb;
  --accent: #2563eb; --accent-text: #ffffff; --ok: #15803d; --ok-bg: #dcfce7; --warn: #a16207; --warn-bg: #fef3c7;
  --bad: #b91c1c; --bad-bg: #fee2e2; --info-bg: #e0e7ff; --info: #3730a3; --chip: #eef0f3;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1218; --panel: #171b23; --text: #e6e8ec; --muted: #9aa3b2; --line: #2a303b;
    --accent: #3b82f6; --ok: #4ade80; --ok-bg: #133a22; --warn: #fbbf24; --warn-bg: #3b2f0b;
    --bad: #f87171; --bad-bg: #3f1717; --info-bg: #1e2550; --info: #c7d2fe; --chip: #222833;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans SC", sans-serif; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; }
h2 { font-size: 15px; }
.muted { color: var(--muted); font-size: 12px; }
a { color: var(--accent); }

.topbar { position: sticky; top: 0; z-index: 5; display: flex; flex-wrap: wrap; gap: 8px; justify-content: space-between; align-items: center;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { font-weight: 600; font-size: 16px; }
.status { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.pill { padding: 3px 10px; border-radius: 999px; background: var(--chip); font-size: 12px; white-space: nowrap; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }

.tabs { display: flex; gap: 4px; padding: 8px 16px 0; overflow-x: auto; border-bottom: 1px solid var(--line); background: var(--panel); }
.tabs button { border: 0; background: none; color: var(--muted); padding: 8px 12px; cursor: pointer; font: inherit; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.badge { background: var(--bad); color: #fff; border-radius: 999px; padding: 0 6px; font-size: 11px; }

main { padding: 16px; max-width: 1400px; margin: 0 auto; }
.tab { display: flex; flex-direction: column; gap: 16px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px; min-width: 0; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.grid2 { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 16px; }
.side { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
@media (max-width: 900px) { .grid2 { grid-template-columns: 1fr; } }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.card .num { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; }
.card .lbl { color: var(--muted); font-size: 12px; }

.feed, .activity, .list, .board { list-style: none; margin: 0; padding: 0; }
.feed { max-height: 70vh; overflow-y: auto; }
.feed li { padding: 8px 4px; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; }
.feed li.deleted .text { text-decoration: line-through; color: var(--muted); }
.feed .who { font-weight: 600; }
.feed .meta { color: var(--muted); font-size: 12px; }
.feed .text { grid-column: 1 / -1; white-space: pre-wrap; word-break: break-word; }
.feed .row-actions { display: flex; gap: 4px; align-items: flex-start; }
.tag { display: inline-block; padding: 0 7px; border-radius: 999px; font-size: 11px; background: var(--chip); color: var(--muted); margin-left: 4px; }
.tag.counted { background: var(--ok-bg); color: var(--ok); }
.tag.removed { background: var(--bad-bg); color: var(--bad); }
.tag.warn { background: var(--warn-bg); color: var(--warn); }
.tag.admin { background: var(--info-bg); color: var(--info); }

.board li { display: flex; justify-content: space-between; padding: 5px 2px; border-bottom: 1px solid var(--line); }
.board .pts { font-weight: 650; font-variant-numeric: tabular-nums; }
.activity { max-height: 40vh; overflow-y: auto; }
.activity li { padding: 5px 2px; border-bottom: 1px solid var(--line); font-size: 13px; }
.list li { padding: 8px 2px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 8px; align-items: center; flex-wrap: wrap; }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { color: var(--muted); font-weight: 500; font-size: 12px; }
.table td.wrap { max-width: 320px; word-break: break-word; }

.btn { display: inline-block; border: 1px solid var(--line); background: var(--panel); color: var(--text); padding: 7px 12px; border-radius: 8px; cursor: pointer; font: inherit; text-decoration: none; }
.btn:hover { border-color: var(--accent); }
.btn.small { padding: 3px 8px; font-size: 12px; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.danger { background: var(--bad); color: #fff; border-color: var(--bad); }
.btn:disabled { opacity: .5; cursor: default; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.actions.right { justify-content: flex-end; }

input, textarea, select { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; width: 100%; }
textarea { resize: vertical; }
.inline { display: flex; gap: 6px; flex-wrap: wrap; }
.inline input { width: auto; flex: 1 1 200px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 6px; color: var(--text); }
label.check input { width: auto; }
.preview-wrap { border: 1px dashed var(--line); border-radius: 8px; padding: 8px; }
.preview { white-space: pre-wrap; word-break: break-word; min-height: 1.5em; }
.danger-zone { border-color: var(--bad); }
.error { color: var(--bad); margin: 0; }
.alert { background: var(--bad-bg); color: var(--bad); border-radius: 8px; padding: 8px 12px; margin-bottom: 8px; }

dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--text); width: min(520px, calc(100vw - 32px)); padding: 16px; }
dialog::backdrop { background: rgba(0,0,0,.45); }
.quote { background: var(--bg); border-radius: 8px; padding: 8px; white-space: pre-wrap; word-break: break-word; max-height: 40vh; overflow: auto; }
.toast { position: fixed; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 8px; z-index: 20; max-width: calc(100vw - 32px); }

.login-body { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 24px; width: min(380px, 100%); }
.login-card h1 { font-size: 18px; margin-bottom: 16px; }
.login-card form { display: flex; flex-direction: column; gap: 12px; }
