:root {
  --bg: #ffffff;
  --bg2: #f3f4f6;
  --line: #e5e7eb;
  --text: #111827;
  --muted: #6b7280;
  --accent: #1d72b8;
  --accent-text: #ffffff;
  --in: #f3f4f6;
  --out: #dcf0fb;
  --warn: #b45309;
  --ok: #047857;
  --err: #b91c1c;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111214;
    --bg2: #1c1d21;
    --line: #2a2c31;
    --text: #f3f4f6;
    --muted: #9ca3af;
    --accent: #4aa8e8;
    --accent-text: #0b1620;
    --in: #1f2024;
    --out: #173447;
    --warn: #f59e0b;
    --ok: #34d399;
    --err: #f87171;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }

.screen { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login { width: 100%; max-width: 320px; display: grid; gap: 10px; }
.login h1 { margin: 0 0 12px; font-size: 22px; }
.login label { color: var(--muted); font-size: 14px; }
input[type=password] {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg);
}
.primary {
  border: 0; border-radius: 8px; padding: 10px 16px; background: var(--accent); color: var(--accent-text); font-weight: 600;
}
.primary.quiet { background: var(--bg2); color: var(--text); }
.err { color: var(--err); min-height: 1.4em; margin: 0; font-size: 14px; }

#app { height: 100%; max-width: 720px; margin: 0 auto; }
.pane { height: 100%; display: flex; flex-direction: column; }
.bar {
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 12px 8px;
  border-bottom: 1px solid var(--line); background: var(--bg);
  position: sticky; top: 0; z-index: 2;
}
.bar h1 { margin: 0; font-size: 20px; flex: 1; }
.icon {
  width: 40px; height: 40px; display: grid; place-items: center; border: 0; background: none; border-radius: 8px; color: var(--text);
}
.icon:hover { background: var(--bg2); }
.icon svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon.spin svg { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.notice { margin: 10px 12px 0; padding: 10px 12px; background: var(--bg2); border-radius: 8px; font-size: 14px; }
.notice .row { display: flex; gap: 8px; margin-top: 8px; }
.notice input { flex: 1; min-width: 0; }

.tabs { display: flex; gap: 4px; padding: 8px 12px; }
.tabs button {
  border: 0; background: none; padding: 6px 12px; border-radius: 999px; color: var(--muted); font-weight: 600;
}
.tabs button[aria-selected=true] { background: var(--bg2); color: var(--text); }

.list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.list li button {
  width: 100%; display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; text-align: start;
  padding: 12px 16px; border: 0; border-bottom: 1px solid var(--line); background: none;
}
.list li button:hover { background: var(--bg2); }
.list .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .time { color: var(--muted); font-size: 13px; }
.list .snip { color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .waiting .name::before {
  content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-inline-end: 6px; vertical-align: middle;
}
.list .tag { font-size: 12px; color: var(--warn); white-space: nowrap; }
.list .tag.closed { color: var(--muted); }
.empty { color: var(--muted); text-align: center; padding: 32px 16px; margin: 0; }
.sync { color: var(--muted); font-size: 12px; padding: 8px 16px calc(env(safe-area-inset-bottom, 0px) + 8px); border-top: 1px solid var(--line); }
.sync .bad { color: var(--err); }

.who { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.who strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who span { color: var(--muted); font-size: 13px; text-align: right; }
.window { margin: 0; padding: 6px 16px; font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--line); }
.window.open { color: var(--ok); }

.msgs { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.day { align-self: center; color: var(--muted); font-size: 12px; margin: 8px 0 2px; }
.msg { max-width: 82%; padding: 7px 10px 5px; border-radius: 10px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.in { align-self: flex-start; background: var(--in); }
.msg.out { align-self: flex-end; background: var(--out); }
.msg .meta { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }
.msg .kind { color: var(--muted); font-style: italic; }
.msg.reaction { background: none; padding: 0 4px; font-size: 20px; }

.actions { padding: 10px 12px calc(env(safe-area-inset-bottom, 0px) + 10px); border-top: 1px solid var(--line); display: flex; }
.actions .primary { flex: 1; }
