/* Tokens */
:root {
  --bg: #f4f4f1;
  --surface: #ffffff;
  --surface-2: #f8f8f5;
  --ink: #141412;
  --muted: #62625b;
  --line: #e3e3dd;
  --line-strong: #cfcfc7;
  --ok: #17703a;
  --ok-bg: #e6f4ea;
  --warn: #8f5200;
  --warn-bg: #fdf1dc;
  --bad: #b3261e;
  --bad-bg: #fce8e6;
  --bad-ink: #ffffff;
  --idle: #6f6f68;
  --idle-bg: #efefea;
  --focus: #2457d6;
  --shadow: 0 1px 2px rgb(20 20 18 / 0.06), 0 12px 28px -16px rgb(20 20 18 / 0.18);
  --r-lg: 16px;
  --r-md: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e0e0d;
    --surface: #171715;
    --surface-2: #1c1c19;
    --ink: #f2f2ee;
    --muted: #a6a69f;
    --line: #2b2b27;
    --line-strong: #3d3d37;
    --ok: #55d487;
    --ok-bg: #112619;
    --warn: #f2b455;
    --warn-bg: #2a2111;
    --bad: #ff8a80;
    --bad-bg: #2d1614;
    --bad-ink: #1a0908;
    --idle: #9a9a93;
    --idle-bg: #20201d;
    --focus: #9db9ff;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 12px 28px -16px rgb(0 0 0 / 0.7);
  }
}

/* Base */
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 400 1rem/1.5 var(--font);
  font-variant-numeric: tabular-nums;
  min-height: 100vh;
  -webkit-text-size-adjust: 100%;
}
::selection { background: color-mix(in srgb, var(--focus) 28%, transparent); color: inherit; }
input { caret-color: var(--focus); accent-color: var(--ink); }
* { scrollbar-color: var(--line-strong) transparent; scrollbar-width: thin; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
svg.i { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* Top bar */
.top {
  max-width: 1040px;
  margin: 0 auto;
  padding: 18px 16px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 1.0625rem; letter-spacing: -0.01em; }
.brand .mark { width: 30px; height: 30px; border-radius: 9px; background: var(--ink); color: var(--bg); display: grid; place-items: center; }
.brand .mark svg { width: 17px; height: 17px; }

/* Layout */
.layout { max-width: 1040px; margin: 0 auto; padding: 0 16px 56px; display: grid; gap: 16px; }
.stack { display: grid; gap: 16px; }
@media (min-width: 900px) {
  .layout { grid-template-columns: minmax(340px, 410px) 1fr; align-items: start; }
  .status { position: sticky; top: 16px; }
}

/* Panels */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow); padding: 20px; }
.panel h2 { font-size: 1.25rem; font-weight: 650; letter-spacing: -0.01em; margin: 0; }
.panel .hint { color: var(--muted); font-size: 0.875rem; margin: 4px 0 0; }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.panel-head .count { color: var(--muted); font-size: 0.875rem; }

/* Status hero */
.hero { display: flex; gap: 14px; align-items: flex-start; padding: 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--idle-bg); transition: background 0.2s, border-color 0.2s; }
.hero[data-tone="ok"] { background: var(--ok-bg); border-color: color-mix(in srgb, var(--ok) 30%, transparent); }
.hero[data-tone="warn"] { background: var(--warn-bg); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.hero[data-tone="bad"] { background: var(--bad-bg); border-color: color-mix(in srgb, var(--bad) 30%, transparent); }
.light { width: 16px; height: 16px; border-radius: 50%; background: var(--idle); margin-top: 8px; flex: none; position: relative; }
.hero[data-tone="ok"] .light { background: var(--ok); box-shadow: 0 0 0 5px color-mix(in srgb, var(--ok) 20%, transparent); }
.hero[data-tone="warn"] .light { background: var(--warn); box-shadow: 0 0 0 5px color-mix(in srgb, var(--warn) 20%, transparent); }
.hero[data-tone="bad"] .light { background: var(--bad); box-shadow: 0 0 0 5px color-mix(in srgb, var(--bad) 20%, transparent); }
.hero[data-tone="idle"] .light { box-shadow: 0 0 0 5px color-mix(in srgb, var(--idle) 18%, transparent); }
.hero h2 { font-size: 1.75rem; line-height: 1.15; font-weight: 700; letter-spacing: -0.02em; margin: 0; }
.hero .lead { margin: 6px 0 0; color: var(--muted); font-size: 0.9375rem; max-width: 34ch; }
.hero[data-tone="ok"] .lead, .hero[data-tone="warn"] .lead, .hero[data-tone="bad"] .lead { color: var(--ink); opacity: 0.8; }
@media (prefers-reduced-motion: no-preference) {
  .hero[data-pulse="1"] .light::after { content: ""; position: absolute; inset: 0; border-radius: 50%; border: 2px solid var(--warn); animation: ping 1.6s cubic-bezier(0.2, 0.6, 0.3, 1) infinite; }
  @keyframes ping { from { transform: scale(1); opacity: 0.9; } to { transform: scale(2.6); opacity: 0; } }
}

/* Facts */
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; margin: 18px 0 0; }
.facts div { min-width: 0; }
.facts dt { font-size: 0.8125rem; color: var(--muted); margin: 0 0 4px; }
.facts dd { margin: 0; font-size: 0.9375rem; font-weight: 550; overflow-wrap: anywhere; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px 2px 8px; border-radius: 999px; font-size: 0.8125rem; font-weight: 600; background: var(--idle-bg); color: var(--idle); }
.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.chip.ok { background: var(--ok-bg); color: var(--ok); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.bad { background: var(--bad-bg); color: var(--bad); }

/* Wipe timer */
.timer { margin-top: 16px; }
.timer .row { display: flex; justify-content: space-between; gap: 12px; font-size: 0.8125rem; color: var(--muted); margin-bottom: 6px; }
.timer .row strong { color: var(--ink); font-weight: 600; }
.bar { height: 6px; border-radius: 999px; background: var(--idle-bg); overflow: hidden; }
.bar span { display: block; height: 100%; width: 0; background: var(--ink); border-radius: 999px; transition: width 1s linear; }

/* QR */
.qr { margin-top: 16px; padding: 16px; border: 1px dashed var(--line-strong); border-radius: 12px; background: var(--surface-2); }
.qr ol { margin: 0 0 14px; padding-left: 20px; color: var(--muted); font-size: 0.875rem; display: grid; gap: 4px; }
.qr .code { display: grid; place-items: center; }
.qr .code img { width: 100%; max-width: 232px; height: auto; background: #fff; padding: 10px; border-radius: 12px; border: 1px solid var(--line); }

/* Buttons */
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 20px; }
button { font: inherit; font-weight: 600; min-height: 48px; padding: 0 18px; border-radius: var(--r-md); border: 1px solid var(--ink); background: var(--ink); color: var(--bg); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; transition: background 0.15s, border-color 0.15s, opacity 0.15s, transform 0.1s; }
button:hover:not(:disabled) { opacity: 0.88; }
button:active:not(:disabled) { transform: translateY(1px); }
button.secondary { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
button.secondary:hover:not(:disabled) { background: var(--surface-2); opacity: 1; }
button.danger { background: var(--bad); border-color: var(--bad); color: var(--bad-ink); }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); min-height: 40px; padding: 0 12px; font-weight: 500; }
button.ghost:hover:not(:disabled) { color: var(--ink); background: var(--idle-bg); opacity: 1; }
button.full { width: 100%; }
button:disabled { opacity: 0.38; cursor: not-allowed; }

/* Messages */
.error { color: var(--bad); font-size: 0.875rem; min-height: 1.3em; margin: 10px 0 0; }
.ok-text { color: var(--ok); font-size: 0.875rem; min-height: 1.3em; margin: 10px 0 0; }

/* Forms */
label { display: block; font-size: 0.875rem; font-weight: 550; margin: 14px 0 6px; }
input[type="password"], input[type="text"] { width: 100%; min-height: 48px; padding: 0 14px; font: inherit; color: var(--ink); background: var(--surface-2); border: 1px solid var(--line-strong); border-radius: var(--r-md); }
input::placeholder { color: var(--muted); }
.field { position: relative; }
.field input { padding-right: 70px; }
.field button.toggle { position: absolute; right: 4px; top: 4px; min-height: 40px; padding: 0 12px; }

/* Data list */
.contacts { display: grid; margin: 0 -8px; }
a.row { display: flex; align-items: center; gap: 12px; padding: 10px 8px; border-radius: 10px; color: inherit; text-decoration: none; }
a.row:hover { background: var(--surface-2); }
a.row + a.row { border-top: 1px solid var(--line); border-radius: 0; }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--idle-bg); color: var(--muted); display: grid; place-items: center; font-weight: 650; font-size: 0.9375rem; flex: none; }
.who-line { min-width: 0; flex: 1; }
.who-line b { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who-line small { color: var(--muted); font-size: 0.8125rem; }
.badge { font-size: 0.8125rem; font-weight: 600; color: var(--muted); background: var(--idle-bg); padding: 2px 10px; border-radius: 999px; white-space: nowrap; }
a.row svg.i { color: var(--muted); }
.empty { text-align: center; padding: 20px 8px 8px; color: var(--muted); }
.empty svg { width: 28px; height: 28px; margin-bottom: 6px; }
.note { color: var(--muted); font-size: 0.8125rem; margin: 14px 0 0; max-width: 60ch; }

/* Details (change PIN) */
details summary { cursor: pointer; list-style: none; display: flex; align-items: center; justify-content: space-between; gap: 12px; font-weight: 650; font-size: 1.25rem; letter-spacing: -0.01em; }
details summary::-webkit-details-marker { display: none; }
details summary svg.i { transition: transform 0.2s; color: var(--muted); }
details[open] summary svg.i { transform: rotate(180deg); }
details .body { margin-top: 4px; }

/* Danger zone */
.danger-zone { border-color: color-mix(in srgb, var(--bad) 35%, var(--line)); }
.danger-zone h2 { color: var(--bad); }
#del-form { margin-top: 12px; }

/* Contact page */
.page { max-width: 640px; margin: 0 auto; padding: 0 16px 56px; }
.page-head { position: sticky; top: 0; z-index: 2; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px); padding: 14px 16px 12px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--line); margin: 0 -16px 16px; }
.page-head .avatar { width: 42px; height: 42px; }
.page-head h1 { font-size: 1.125rem; margin: 0; line-height: 1.25; letter-spacing: -0.01em; }
.page-head p { margin: 0; color: var(--muted); font-size: 0.8125rem; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); text-decoration: none; font-size: 0.875rem; padding: 8px 8px 8px 0; }
.back:hover { color: var(--ink); }
.thread { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.thread li { max-width: 82%; padding: 8px 12px; border-radius: 14px; font-size: 0.9375rem; overflow-wrap: anywhere; white-space: pre-wrap; line-height: 1.45; }
.thread li.them { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.thread li.me { align-self: flex-end; background: var(--ink); color: var(--bg); border-bottom-right-radius: 4px; }
.thread li.media { font-style: italic; opacity: 0.75; }
.thread-top { display: grid; place-items: center; margin-bottom: 14px; }
.thread-top .done { color: var(--muted); font-size: 0.8125rem; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 380px; }
.login-card h1 { font-size: 1.75rem; letter-spacing: -0.02em; margin: 0 0 6px; display: flex; align-items: center; gap: 10px; }
.login-card h1 svg { width: 26px; height: 26px; }
.login-card .sub { color: var(--muted); margin: 0 0 6px; font-size: 0.9375rem; }
.mt14 { margin-top: 14px; }
.mt16 { margin-top: 16px; }
.first { margin-top: 0; }

/* Two-step sign-in */
.steps { margin: 14px 0; padding-left: 20px; color: var(--muted); font-size: 0.875rem; display: grid; gap: 4px; }
#tf-enroll { margin-top: 14px; }
#tf-qr { display: grid; place-items: center; margin: 12px 0; }
#tf-qr img { width: 100%; max-width: 232px; height: auto; background: #fff; padding: 10px; border-radius: 12px; border: 1px solid var(--line); }
code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 0.8125rem; background: var(--idle-bg); padding: 2px 6px; border-radius: 6px; overflow-wrap: anywhere; user-select: all; }
#tf-enable-form input, #tf-disable-form input { width: 100%; min-height: 48px; padding: 0 14px; font: inherit; color: var(--ink); background: var(--surface-2); border: 1px solid var(--line-strong); border-radius: var(--r-md); }
#tf-disable-form { margin-top: 4px; }
#tf-recovery { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
#tf-recovery h3 { font-size: 1rem; margin: 0 0 4px; }
.codes { list-style: none; margin: 12px 0 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.codes li { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 0.9375rem; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; text-align: center; user-select: all; }
