:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --success: #15803d;
  --success-bg: #f0fdf4;
  --error: #b91c1c;
  --error-bg: #fef2f2;
  --new-bg: #eff6ff;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 4px 16px rgba(15, 23, 42, .06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120;
    --surface: #111827;
    --text: #e5e7eb;
    --muted: #94a3b8;
    --border: #1f2937;
    --accent: #3b82f6;
    --success: #4ade80;
    --success-bg: #052e16;
    --error: #f87171;
    --error-bg: #2a0a0a;
    --new-bg: #172554;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
/* Author display rules (e.g. .form { display: grid }) beat the browser's
   built-in [hidden] style, so re-assert it — the tabs and cards rely on it. */
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--accent); }
.wrap { width: 100%; max-width: 640px; margin: 0 auto; padding: 0 16px; }
main.wrap { flex: 1; padding-top: 28px; padding-bottom: 40px; }
.stack > * + * { margin-top: 16px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.h2 { font-size: 1.35rem; margin: 0 0 8px; }

.site-header { background: var(--surface); border-bottom: 1px solid var(--border); }
.header-inner { display: flex; align-items: center; justify-content: space-between; height: 56px; }
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); text-decoration: none; }
.brand svg { color: var(--accent); }
.site-header nav a { text-decoration: none; font-weight: 500; }

.site-footer { border-top: 1px solid var(--border); background: var(--surface); }
.footer-bottom { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding-top: 14px; padding-bottom: 14px; font-size: .85rem; color: var(--muted); }
.footer-bottom a { color: inherit; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.notice { padding: 12px 14px; border-radius: 10px; }
.notice-error { background: var(--error-bg); color: var(--error); }

.tabs { display: flex; gap: 4px; background: var(--bg); padding: 4px; border-radius: 10px; margin-bottom: 18px; }
.tab { flex: 1; border: 0; background: transparent; padding: 8px; border-radius: 8px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; }
.tab.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.form { display: grid; gap: 12px; }
.form .row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 480px) { .form .row { grid-template-columns: 1fr; } }
label { display: grid; gap: 4px; font-size: .9rem; font-weight: 500; }
input {
  font: inherit; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg); color: var(--text); width: 100%;
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.form-error { color: var(--error); margin: 0; min-height: 0; font-size: .9rem; }
.form-error:empty { display: none; }

.btn { font: inherit; font-weight: 600; border: 0; border-radius: 10px; padding: 11px 16px; background: var(--accent); color: var(--accent-ink); cursor: pointer; }
.btn:disabled { opacity: .6; cursor: progress; }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }

.lock-head { display: flex; gap: 12px; align-items: center; }
.lock-icon { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 12px; background: var(--new-bg); color: var(--accent); }
.lock-id { font-weight: 700; font-size: 1.1rem; word-break: break-all; }
.lock-status { margin: 14px 0 10px; padding: 10px 12px; border-radius: 10px; background: var(--bg); }
.lock-status[data-kind="success"] { background: var(--success-bg); color: var(--success); font-weight: 600; }
.lock-status[data-kind="error"] { background: var(--error-bg); color: var(--error); }

.history-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: .85rem; color: var(--muted); white-space: nowrap; }
.live .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.live[data-state="live"] .dot { background: #22c55e; box-shadow: 0 0 0 3px rgba(34, 197, 94, .2); }
.live[data-state="offline"] .dot { background: var(--error); }

.list-card { padding: 4px 0; }
.events { list-style: none; margin: 0; padding: 0; }
.event { display: flex; justify-content: space-between; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--border); }
.event:last-child { border-bottom: 0; }
.event-label { font-weight: 500; }
.event-time { font-size: .85rem; font-variant-numeric: tabular-nums; }
.event.is-new { animation: flash 2.4s ease-out; }
@keyframes flash { from { background: var(--new-bg); } to { background: transparent; } }
.empty { padding: 16px 20px; margin: 0; }
