:root {
  --bg: #ffffff; --fg: #0a0a0a; --surface: #f5f5f4; --line: #e6e6e4; --muted: #8a8a87; --soft: #4a4a48; --red: #c4321c;
  --sans: 'Geist', -apple-system, 'Helvetica Neue', Arial, sans-serif;
  --mono: 'Geist Mono', ui-monospace, Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0a0a0a; --fg: #f4f4f2; --surface: #141414; --line: #242424; --muted: #7c7c7a; --soft: #b5b5b2; --red: #ff6a52; color-scheme: dark; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 400 14px/1.5 var(--sans); -webkit-font-smoothing: antialiased; padding: 0 24px 64px; }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }

.top { display: flex; justify-content: space-between; align-items: center; padding: 18px 0; max-width: 1280px; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.brand svg { width: 20px; height: 20px; }
.who { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }

button { font: inherit; color: inherit; cursor: pointer; }
.link { background: none; border: 0; padding: 0; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; }
.link:hover { color: var(--fg); }
.btn { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--bg); border-radius: 999px; padding: 6px 12px; font-size: 12.5px; font-weight: 500; white-space: nowrap; }
.btn:hover { background: var(--surface); }
.btn.solid { background: var(--fg); color: var(--bg); border-color: transparent; padding: 12px 20px; font-size: 14px; }
.btn.solid:hover { opacity: 0.88; }
.btn.solid svg { width: 16px; height: 16px; }
.btn.danger { color: var(--red); }
.btn[disabled] { opacity: 0.4; cursor: default; }

.center { min-height: 70vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; }
.err { color: var(--red); font-size: 12px; min-height: 1em; margin: 0; }

main#app { max-width: 1280px; margin: 0 auto; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; margin: 8px 0 28px; }
.stat { background: var(--bg); padding: 14px 16px; }
.stat b { display: block; font: 500 24px/1.2 var(--mono); }
.stat span { font-size: 12px; color: var(--muted); }

.tabs { display: flex; gap: 4px; align-items: center; border-bottom: 1px solid var(--line); margin-bottom: 8px; }
.tabs [role=tab] { background: none; border: 0; padding: 10px 12px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 500; }
.tabs [aria-selected=true] { color: var(--fg); border-color: var(--fg); }
.refresh { margin-left: auto; font-size: 12px; }

.search { display: flex; gap: 8px; margin: 14px 0; max-width: 520px; }
.search input { flex: 1; font: 400 14px var(--mono); color: var(--fg); background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 8px 16px; outline: none; }
.search input:focus { border-color: var(--muted); }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font: 400 11.5px var(--mono); color: var(--muted); padding: 10px 10px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.num { text-align: right; font-family: var(--mono); }
td.when, td.date { font: 12px var(--mono); color: var(--muted); white-space: nowrap; }
td.text { max-width: 440px; }
td.text .t { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
td.text .m { font: 11px var(--mono); color: var(--muted); }
td.actions { text-align: right; white-space: nowrap; }
td.actions .btn + .btn { margin-left: 6px; }
.who-cell .uid { display: block; font: 11px var(--mono); color: var(--muted); }
.pill { display: inline-block; font: 11px/1 var(--mono); padding: 4px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.pill.live { color: var(--fg); border-color: var(--fg); }
.pill.bad { color: var(--red); border-color: var(--red); }
.empty { color: var(--muted); text-align: center; padding: 40px 0; font-family: var(--mono); font-size: 12px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 12.5px; transition: 0.25s; pointer-events: none; }
.toast.on { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--red); color: #fff; }

@media (max-width: 800px) {
  thead { display: none; }
  tr { display: grid; grid-template-columns: 1fr auto; border-bottom: 1px solid var(--line); padding: 8px 0; }
  td { border: 0; padding: 4px 0; }
  td.num, td:empty { display: none; }
  td.actions, td.text { grid-column: 1 / -1; text-align: left; }
}

/* ---------- charts ---------- */
.charts { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); margin: 0 0 32px; }
.chart { border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px 10px; }
.chart.wide { grid-column: 1 / -1; }
.chart h3 { margin: 0; font-size: 13px; font-weight: 500; }
.chart .total { font: 400 12px var(--mono); color: var(--muted); margin: 2px 0 8px; }
.chart svg { display: block; width: 100%; height: 120px; overflow: visible; }
.chart.wide svg { height: 140px; }
.chart .bar { fill: var(--fg); opacity: 0.82; }
.chart .hit:hover + .bar, .chart .bar.on { opacity: 1; }
.chart .hit { fill: transparent; cursor: default; }
.chart .base { stroke: var(--line); stroke-width: 1; }
.chart .grid { stroke: var(--line); stroke-width: 1; stroke-dasharray: 2 3; }
.chart .ax { font: 10.5px var(--mono); fill: var(--muted); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.tip { position: fixed; z-index: 20; pointer-events: none; background: var(--fg); color: var(--bg); font-size: 11.5px; padding: 6px 9px; border-radius: 8px; transform: translate(-50%, calc(-100% - 10px)); white-space: nowrap; }

/* ---------- rows open details ---------- */
#posts tr[data-id], #users tr[data-uid] { cursor: pointer; }
#posts tr[data-id]:hover td, #users tr[data-uid]:hover td { background: var(--surface); }

/* ---------- dialogs ---------- */
.dlg { border: 1px solid var(--line); border-radius: 20px; padding: 0; background: var(--bg); color: var(--fg); width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - 48px); box-shadow: 0 30px 80px -20px rgb(0 0 0 / 0.5); }
.dlg.small { width: min(440px, calc(100vw - 32px)); }
.dlg::backdrop { background: rgb(0 0 0 / 0.5); backdrop-filter: blur(2px); }
.dlg[open] { animation: pop 0.18s cubic-bezier(0.2, 0.7, 0.2, 1); }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
.dlg form, .dlg-body { padding: 22px 24px; }
.dlg h2 { font-size: 17px; font-weight: 600; letter-spacing: -0.01em; margin: 0 0 6px; }
.soft { color: var(--soft); margin: 0; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; }
.dlg-actions .btn { padding: 9px 16px; font-size: 13px; }
.btn.solid.danger { background: var(--red); color: #fff; }
.type { display: flex; flex-direction: column; gap: 6px; margin-top: 16px; font-size: 12.5px; color: var(--muted); }
.type input { font-size: 14px; color: var(--fg); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; outline: none; }
.type input:focus { border-color: var(--muted); }
.x { position: absolute; top: 14px; right: 14px; width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--line); background: var(--bg); color: var(--muted); display: grid; place-items: center; font-size: 15px; line-height: 1; }
.x:hover { color: var(--fg); }
.dlg-body { position: relative; }

.d-head { display: flex; align-items: center; gap: 12px; padding-right: 40px; margin-bottom: 16px; }
.d-av { width: 40px; height: 40px; border-radius: 50%; background: var(--surface); display: grid; place-items: center; font: 600 13px var(--sans); color: var(--soft); flex: none; }
.d-head .name { font-weight: 600; font-size: 15px; }
.d-head .sub { font: 11.5px var(--mono); color: var(--muted); display: block; word-break: break-all; }
.d-head .pill { margin-left: auto; }
.d-text { font-size: 16px; line-height: 1.5; margin: 0 0 14px; white-space: pre-wrap; word-break: break-word; }
.d-media { border-radius: 14px; overflow: hidden; background: var(--surface); margin-bottom: 14px; }
.d-media img, .d-media video { display: block; width: 100%; max-height: 420px; object-fit: contain; background: #000; }
.d-media .cap { font: 11px var(--mono); color: var(--muted); padding: 6px 10px; }
.d-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; margin-bottom: 18px; }
.d-grid div { background: var(--bg); padding: 10px 12px; }
.d-grid b { display: block; font: 500 16px var(--mono); }
.d-grid span { font-size: 11.5px; color: var(--muted); }
.d-sec { font: 400 11.5px var(--mono); color: var(--muted); margin: 18px 0 8px; }
.d-list { list-style: none; margin: 0; padding: 0; }
.d-list li { padding: 9px 0; border-top: 1px solid var(--line); font-size: 13.5px; display: flex; gap: 10px; align-items: baseline; }
.d-list li:last-child { border-bottom: 1px solid var(--line); }
.d-list .when { font: 11px var(--mono); color: var(--muted); white-space: nowrap; margin-left: auto; }
.d-list .who { font-weight: 500; white-space: nowrap; }
.d-list button.row { all: unset; display: flex; gap: 10px; align-items: baseline; width: 100%; cursor: pointer; }
.d-list button.row:hover .t { text-decoration: underline; text-underline-offset: 3px; }
.d-list .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.d-empty { font: 12px var(--mono); color: var(--muted); padding: 10px 0; }
.d-foot { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; border-top: 1px solid var(--line); margin: 20px -24px -22px; padding: 14px 24px; }
.d-foot .btn { padding: 9px 16px; font-size: 13px; }
.loading { font: 12px var(--mono); color: var(--muted); padding: 40px 0; text-align: center; }
.chart .axis { display: flex; justify-content: space-between; font-size: 10.5px; color: var(--muted); margin-top: 4px; }
.chart figure, figure.chart { margin: 0; }
.d-head .name { all: unset; font-weight: 600; font-size: 15px; cursor: pointer; }
.d-head button.name:hover { text-decoration: underline; text-underline-offset: 3px; }

.dlg:focus, .dlg:focus-visible { outline: none; }
.d-grid.g3 { grid-template-columns: repeat(3, 1fr); }
.d-grid.g4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 560px) { .d-grid.g3, .d-grid.g4 { grid-template-columns: repeat(2, 1fr); } }
