:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --fg: #16181d;
  --muted: #6b7280;
  --line: #e5e7eb;
  --soft: #f4f5f7;
  --accent: #2f5bea;
  --accent-fg: #ffffff;
  --ours: #eef2ff;
  --error: #c0262d;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --fg: #e8eaed;
    --muted: #9aa0a6;
    --line: #2a2e35;
    --soft: #1a1d22;
    --accent: #6c8cff;
    --accent-fg: #0b0d10;
    --ours: #1c2340;
    --error: #ff6b6b;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--fg); }
button, input, textarea { font: inherit; color: inherit; }
button, .button {
  border: 1px solid var(--line);
  background: var(--soft);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
button:disabled { opacity: 0.6; cursor: default; }
.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.link { background: none; border: none; padding: 4px 6px; color: var(--accent); }
.muted { color: var(--muted); }
.error { color: var(--error); min-height: 1.2em; margin: 6px 0 0; }
.empty { padding: 24px 16px; }

.login { max-width: 360px; margin: 12vh auto; padding: 0 16px; display: grid; gap: 16px; }
.login h1 { font-size: 22px; margin: 0 0 8px; }
.login .code { font-size: 32px; letter-spacing: 6px; margin: 4px 0 12px; font-variant-numeric: tabular-nums; }
.login form { display: flex; gap: 8px; margin-top: 10px; }
.login input { flex: 1; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }

.app { display: grid; grid-template-columns: minmax(280px, 380px) 1fr; height: 100vh; height: 100dvh; }
.list-pane { border-right: 1px solid var(--line); overflow-y: auto; }
.thread-pane { overflow-y: auto; }
.bar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 12px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: var(--bg); z-index: 1;
}
.tabs { display: flex; gap: 4px; }
.tab { background: none; border-color: transparent; }
.tab.active { background: var(--soft); border-color: var(--line); }
.me { display: flex; align-items: center; gap: 4px; color: var(--muted); font-size: 13px; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { border-bottom: 1px solid var(--line); }
.list a { display: block; padding: 10px 12px; color: inherit; text-decoration: none; }
.list a:hover, .list a.current { background: var(--soft); }
.list .top { display: flex; justify-content: space-between; gap: 8px; }
.list .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .time { color: var(--muted); font-size: 13px; white-space: nowrap; }
.list .preview { color: var(--muted); font-size: 14px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.badge { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--accent); color: var(--accent-fg); font-size: 12px; text-align: center; margin-left: 6px; }
.tag { font-size: 12px; color: var(--muted); margin-left: 6px; }

.thread-head .who { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.thread-head .who span { font-size: 13px; overflow-wrap: anywhere; }
.back { display: none; }

.messages { list-style: none; margin: 0; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.message { max-width: 760px; padding: 10px 12px; border-radius: 10px; background: var(--soft); white-space: pre-wrap; overflow-wrap: anywhere; }
.message.ours { background: var(--ours); align-self: flex-end; }
.message .meta { font-size: 12px; color: var(--muted); margin-bottom: 4px; white-space: normal; }
.message .shots { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.message .shots img { max-width: 220px; max-height: 220px; border-radius: 6px; border: 1px solid var(--line); }

.drafts { padding: 0 12px; display: grid; gap: 10px; }
.draft { border: 1px dashed var(--line); border-radius: 10px; padding: 10px 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.draft .meta { font-size: 12px; color: var(--muted); white-space: normal; }
.draft .note { font-size: 13px; color: var(--muted); margin-top: 6px; }
.draft .actions { margin-top: 8px; }

.reply { padding: 12px; display: grid; gap: 8px; border-top: 1px solid var(--line); margin-top: 12px; }
.reply textarea, .reply input { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); resize: vertical; }
.reply p { margin: 0; font-size: 13px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .app.reading .list-pane { display: none; }
  .app:not(.reading) .thread-pane { display: none; }
  .list-pane { border-right: none; }
  .back { display: inline-block; }
  .message { max-width: 100%; }
}
