/* ==========================================================================
   Plaintext — design system
   Mobile-first. Light + dark themes. No external fonts or images.
   ========================================================================== */

:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #f0f2f7;
  --surface-3: #e7eaf2;
  --border: #e2e5ee;
  --border-strong: #cfd4e1;
  --text: #11151f;
  --text-muted: #5a6273;
  --text-faint: #8a92a3;
  --accent: #4b45d6;
  --accent-hover: #3d37c0;
  --accent-soft: #ecebff;
  --accent-contrast: #ffffff;
  --danger: #c62f3c;
  --danger-soft: #fdecee;
  --success: #17804f;
  --success-soft: #e5f6ed;
  --warning: #9a6200;
  --warning-soft: #fff4dc;
  --online: #1fa463;
  --focus: #4b45d6;
  --shadow-sm: 0 1px 2px rgba(17, 21, 31, .06);
  --shadow: 0 1px 2px rgba(17, 21, 31, .05), 0 6px 20px rgba(17, 21, 31, .06);
  --shadow-lg: 0 20px 50px rgba(17, 21, 31, .18);
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 18px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --nav-h: 60px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0d12;
    --surface: #12151c;
    --surface-2: #181c25;
    --surface-3: #212633;
    --border: #232836;
    --border-strong: #323949;
    --text: #e8eaf0;
    --text-muted: #a0a8ba;
    --text-faint: #6f7789;
    --accent: #8f89ff;
    --accent-hover: #a39eff;
    --accent-soft: #24224a;
    --accent-contrast: #0b0d12;
    --danger: #ff6b76;
    --danger-soft: #3a1a1f;
    --success: #4fd08f;
    --success-soft: #12301f;
    --warning: #f2b53c;
    --warning-soft: #33280f;
    --online: #3fd47f;
    --focus: #a39eff;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 8px 24px rgba(0, 0, 0, .35);
    --shadow-lg: 0 24px 60px rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b0d12;
  --surface: #12151c;
  --surface-2: #181c25;
  --surface-3: #212633;
  --border: #232836;
  --border-strong: #323949;
  --text: #e8eaf0;
  --text-muted: #a0a8ba;
  --text-faint: #6f7789;
  --accent: #8f89ff;
  --accent-hover: #a39eff;
  --accent-soft: #24224a;
  --accent-contrast: #0b0d12;
  --danger: #ff6b76;
  --danger-soft: #3a1a1f;
  --success: #4fd08f;
  --success-soft: #12301f;
  --warning: #f2b53c;
  --warning-soft: #33280f;
  --online: #3fd47f;
  --focus: #a39eff;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 8px 24px rgba(0, 0, 0, .35);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, .6);
  color-scheme: dark;
}

/* ---------- reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
h1, h2, h3, h4 { margin: 0; line-height: 1.25; letter-spacing: -0.01em; }
h1 { font-size: 1.6rem; font-weight: 750; }
h2 { font-size: 1.2rem; font-weight: 700; }
h3 { font-size: 1rem; font-weight: 650; }
p { margin: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, textarea, select { font: inherit; color: inherit; }
img, svg { display: block; }
: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; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link { position: absolute; left: -999px; top: 8px; z-index: 100; background: var(--surface); padding: 8px 12px; border-radius: 8px; }
.skip-link:focus { left: 8px; }

/* ---------- utilities ---------- */
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack-sm { display: flex; flex-direction: column; gap: 6px; }
.stack-lg { display: flex; flex-direction: column; gap: 20px; }
.row { display: flex; align-items: center; gap: 10px; min-width: 0; }
.row-wrap { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.between { justify-content: space-between; }
.grow { flex: 1 1 auto; min-width: 0; }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.small { font-size: .875rem; }
.xsmall { font-size: .78rem; }
.mono { font-family: var(--mono); font-size: .85em; }
.center { text-align: center; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; }
.mt { margin-top: 12px; }
.mt-lg { margin-top: 24px; }
.divider { height: 1px; background: var(--border); border: 0; margin: 4px 0; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 8px 16px;
  border-radius: 999px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text);
  font-weight: 600; font-size: .95rem; line-height: 1.2;
  cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s, transform .05s;
  text-decoration: none;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.06); background: var(--danger); }
.btn-danger-ghost { color: var(--danger); border-color: transparent; background: transparent; }
.btn-danger-ghost:hover { background: var(--danger-soft); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-soft { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.btn-soft:hover { background: var(--accent-soft); filter: brightness(.97); }
.btn-sm { min-height: 32px; padding: 5px 12px; font-size: .85rem; }
.btn-block { width: 100%; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: 999px;
  border: 0; background: transparent; color: var(--text-muted); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.active { color: var(--accent); }
.icon { width: 20px; height: 20px; flex: none; }
.icon-sm { width: 16px; height: 16px; flex: none; }

.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: spin .7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .label { font-weight: 600; font-size: .9rem; }
.input, .textarea, .select {
  width: 100%; min-height: 44px;
  padding: 10px 14px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  transition: border-color .15s, box-shadow .15s;
}
.textarea { resize: vertical; min-height: 96px; line-height: 1.5; }
.input:focus, .textarea:focus, .select:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.input[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--danger); }
.hint { font-size: .82rem; color: var(--text-muted); }
.error-text { font-size: .85rem; color: var(--danger); }
.success-text { font-size: .85rem; color: var(--success); }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: .92rem; }
.check input { margin-top: 4px; width: 18px; height: 18px; accent-color: var(--accent); }
.radio-group { display: grid; gap: 8px; }
.radio-card {
  display: flex; gap: 10px; align-items: center;
  padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  cursor: pointer; background: var(--surface);
}
.radio-card:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.radio-card input { accent-color: var(--accent); width: 18px; height: 18px; }
.char-count { font-size: .8rem; color: var(--text-faint); font-variant-numeric: tabular-nums; }
.char-count.over { color: var(--danger); font-weight: 600; }

/* ---------- cards / lists ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card-pad { padding: 16px; }
.card-header { padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.card-body { padding: 16px; }
.list { list-style: none; margin: 0; padding: 0; }
.list-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  min-width: 0;
}
.list-item:last-child { border-bottom: 0; }
a.list-item { color: inherit; }
a.list-item:hover { background: var(--surface-2); text-decoration: none; }
.section-title { font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-faint); padding: 0 4px; }

/* ---------- avatar / presence ---------- */
.avatar {
  --av: #6d64f5;
  position: relative; flex: none;
  width: 40px; height: 40px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--av) 18%, var(--surface));
  color: color-mix(in srgb, var(--av) 85%, var(--text));
  font-weight: 700; font-size: .95rem; letter-spacing: .02em;
  user-select: none;
}
.avatar-sm { width: 32px; height: 32px; font-size: .8rem; }
.avatar-lg { width: 76px; height: 76px; font-size: 1.6rem; }
.avatar .presence-dot { position: absolute; right: -1px; bottom: -1px; }
.presence-dot {
  width: 11px; height: 11px; border-radius: 50%;
  background: var(--online); border: 2px solid var(--surface);
}
.presence-text { font-size: .82rem; color: var(--text-muted); }
.presence-text.online { color: var(--online); font-weight: 600; }

/* ---------- badges / pills ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 9px; border-radius: 999px;
  font-size: .75rem; font-weight: 650; line-height: 1.6;
  background: var(--surface-3); color: var(--text-muted);
  white-space: nowrap;
}
.badge-accent { background: var(--accent-soft); color: var(--accent); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.count-badge {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
  background: var(--danger); color: #fff; font-size: .7rem; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; line-height: 1;
}

/* ---------- alerts / states ---------- */
.alert {
  padding: 12px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-2);
  font-size: .92rem; display: flex; gap: 10px; align-items: flex-start;
}
.alert-danger { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.alert-success { background: var(--success-soft); border-color: transparent; color: var(--success); }
.alert-warning { background: var(--warning-soft); border-color: transparent; color: var(--warning); }
.alert-info { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.state {
  padding: 40px 20px; text-align: center; color: var(--text-muted);
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.state .icon { width: 34px; height: 34px; color: var(--text-faint); }
.state h3 { color: var(--text); }
.skeleton {
  border-radius: 6px;
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 37%, var(--surface-2) 63%);
  background-size: 400% 100%; animation: shimmer 1.3s ease infinite;
  height: 12px;
}
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---------- tabs ---------- */
.tabs {
  display: flex; gap: 4px; padding: 4px;
  background: var(--surface-2); border-radius: 999px;
  overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 1 0 auto; border: 0; background: transparent; cursor: pointer;
  padding: 8px 14px; border-radius: 999px; font-weight: 600; font-size: .9rem;
  color: var(--text-muted); display: inline-flex; gap: 6px; align-items: center; justify-content: center;
}
.tab[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* ==========================================================================
   App shell
   ========================================================================== */
.topbar {
  position: sticky; top: 0; z-index: 30;
  height: 56px; padding: 0 12px;
  display: flex; align-items: center; gap: 8px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.1rem; color: var(--text); letter-spacing: -0.02em; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent); color: var(--accent-contrast);
  font-weight: 800; font-size: 1.15rem; font-family: Georgia, "Times New Roman", serif;
}
.topbar .page-title { font-weight: 700; font-size: 1.05rem; }

.shell { display: block; }
.sidebar { display: none; }
.main {
  width: 100%; max-width: 640px; margin: 0 auto;
  padding: 16px 16px calc(var(--nav-h) + var(--safe-bottom) + 24px);
  min-width: 0;
}
.main-wide { max-width: 1100px; }
.aside { display: none; }

.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
}
.bottom-nav a {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--text-faint); font-size: .68rem; font-weight: 600;
}
.bottom-nav a:hover { text-decoration: none; color: var(--text); }
.bottom-nav a[aria-current="page"] { color: var(--accent); }
.bottom-nav .count-badge, .nav-link .count-badge { position: absolute; top: 6px; left: calc(50% + 4px); }

.nav-link {
  position: relative;
  display: flex; align-items: center; gap: 14px;
  padding: 10px 14px; border-radius: 999px;
  color: var(--text); font-weight: 600; font-size: 1rem;
}
button.nav-link { width: 100%; border: 0; background: transparent; cursor: pointer; font: inherit; text-align: left; }
.nav-link:hover { background: var(--surface-2); text-decoration: none; }
.nav-link[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.nav-link .count-badge { position: static; margin-left: auto; }

.menu { position: relative; }
.menu-panel {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 50;
  min-width: 200px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
}
.menu-panel button, .menu-panel a {
  display: flex; width: 100%; align-items: center; gap: 10px;
  padding: 9px 12px; border: 0; background: none; border-radius: 8px;
  color: var(--text); font-size: .92rem; text-align: left; cursor: pointer;
}
.menu-panel button:hover, .menu-panel a:hover { background: var(--surface-2); text-decoration: none; }
.menu-panel .danger { color: var(--danger); }

@media (min-width: 768px) {
  .bottom-nav { display: none; }
  .topbar-mobile-only { display: none !important; }
  .shell {
    display: grid;
    grid-template-columns: 76px minmax(0, 1fr);
    max-width: 1240px; margin: 0 auto;
  }
  .sidebar {
    display: flex; flex-direction: column; gap: 4px;
    position: sticky; top: 0; height: 100vh; padding: 16px 10px;
    border-right: 1px solid var(--border);
  }
  .sidebar .brand { padding: 4px 8px 16px; }
  .sidebar .brand-text, .sidebar .nav-text { display: none; }
  .sidebar .nav-link { justify-content: center; padding: 12px; }
  .sidebar .nav-link .count-badge { position: absolute; top: 4px; right: 4px; margin: 0; }
  .sidebar-footer { margin-top: auto; display: flex; flex-direction: column; gap: 4px; }
  .main { padding: 20px 24px 48px; }
  .topbar { display: none; }
  .topbar.always { display: flex; }
}
@media (min-width: 1100px) {
  .shell { grid-template-columns: 240px minmax(0, 1fr) 300px; }
  .shell.no-aside { grid-template-columns: 240px minmax(0, 1fr); }
  .sidebar .brand-text, .sidebar .nav-text { display: inline; }
  .sidebar .nav-link { justify-content: flex-start; padding: 10px 14px; }
  .sidebar .nav-link .count-badge { position: static; margin-left: auto; }
  .aside {
    display: flex; flex-direction: column; gap: 16px;
    position: sticky; top: 0; height: 100vh; overflow-y: auto;
    padding: 20px 16px; border-left: 1px solid var(--border);
  }
}

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head p { color: var(--text-muted); font-size: .92rem; }

/* ==========================================================================
   Feed
   ========================================================================== */
.composer { padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.composer .textarea { border: 0; padding: 4px 0; min-height: 72px; box-shadow: none; resize: none; font-size: 1.05rem; background: transparent; }
.composer .textarea:focus { box-shadow: none; }
.composer-foot { display: flex; align-items: center; gap: 10px; justify-content: space-between; border-top: 1px solid var(--border); padding-top: 10px; flex-wrap: wrap; }
.select-inline { min-height: 34px; padding: 4px 30px 4px 12px; border-radius: 999px; font-size: .85rem; width: auto; }

.feed { display: flex; flex-direction: column; gap: 12px; }
.post { padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.post-head { display: flex; align-items: center; gap: 10px; min-width: 0; }
.post-author { font-weight: 700; color: var(--text); }
.post-author:hover { text-decoration: underline; }
.post-meta { color: var(--text-faint); font-size: .84rem; }
.post-body { font-size: 1.02rem; white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; }
.post-actions { display: flex; align-items: center; gap: 4px; margin-left: -8px; }
.action {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 10px; border-radius: 999px; border: 0; background: none; cursor: pointer;
  color: var(--text-muted); font-size: .88rem; font-weight: 600; font-variant-numeric: tabular-nums;
}
.action:hover { background: var(--surface-2); color: var(--text); }
.action.liked { color: #e0245e; }
.action.liked svg { fill: currentColor; }
.removed-note { font-size: .85rem; color: var(--danger); background: var(--danger-soft); padding: 6px 10px; border-radius: 8px; }

.comments { border-top: 1px solid var(--border); padding-top: 10px; display: flex; flex-direction: column; gap: 10px; }
.comment { display: flex; gap: 10px; }
.comment-bubble { background: var(--surface-2); border-radius: 14px; padding: 8px 12px; min-width: 0; flex: 1; }
.comment-form { display: flex; gap: 8px; align-items: flex-end; }
.comment-form .textarea { min-height: 42px; height: 42px; padding: 9px 12px; border-radius: 20px; resize: none; }

/* ==========================================================================
   Profile
   ========================================================================== */
.profile-hero { padding: 20px 16px; display: flex; flex-direction: column; gap: 14px; }
.profile-top { display: flex; gap: 16px; align-items: center; }
.profile-name { font-size: 1.35rem; font-weight: 750; }
.profile-stats { display: flex; gap: 18px; font-size: .92rem; color: var(--text-muted); }
.profile-stats strong { color: var(--text); }

/* ==========================================================================
   Chat
   ========================================================================== */
.main.chat-main { max-width: none; padding: 0; }
.chat-layout { display: grid; grid-template-columns: 1fr; height: calc(100dvh - 56px - var(--nav-h) - var(--safe-bottom)); }
.chat-list { overflow-y: auto; border-right: 1px solid var(--border); background: var(--surface); }
.chat-thread { display: flex; flex-direction: column; min-height: 0; background: var(--bg); }
.chat-layout.thread-open .chat-list { display: none; }
.chat-layout:not(.thread-open) .chat-thread { display: none; }
.chat-head {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.chat-scroll { flex: 1; overflow-y: auto; padding: 16px 12px; display: flex; flex-direction: column; gap: 4px; overscroll-behavior: contain; }
.bubble-row { display: flex; flex-direction: column; align-items: flex-start; max-width: 100%; }
.bubble-row.mine { align-items: flex-end; }
.bubble {
  max-width: min(78%, 520px); padding: 8px 12px; border-radius: 18px;
  background: var(--surface); border: 1px solid var(--border);
  white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word;
  position: relative; cursor: default;
}
.bubble-row.mine .bubble { background: var(--accent); color: var(--accent-contrast); border-color: transparent; border-bottom-right-radius: 6px; }
.bubble-row:not(.mine) .bubble { border-bottom-left-radius: 6px; }
.bubble.deleted { font-style: italic; opacity: .7; background: transparent !important; color: var(--text-muted) !important; border: 1px dashed var(--border-strong) !important; }
.bubble-meta { font-size: .72rem; color: var(--text-faint); padding: 2px 6px 6px; display: inline-flex; gap: 6px; align-items: center; }
.bubble-meta .icon-sm { width: 14px; height: 14px; }
.bubble-meta .read { color: var(--accent); }
.day-sep { align-self: center; font-size: .75rem; color: var(--text-faint); background: var(--surface-2); padding: 3px 10px; border-radius: 999px; margin: 10px 0; }
.chat-compose { display: flex; gap: 8px; align-items: flex-end; padding: 10px 12px; background: var(--surface); border-top: 1px solid var(--border); }
.chat-compose .textarea { min-height: 44px; max-height: 160px; height: 44px; border-radius: 22px; resize: none; padding: 11px 16px; }
.chat-blocked { padding: 14px; text-align: center; font-size: .9rem; color: var(--text-muted); background: var(--surface); border-top: 1px solid var(--border); }
.conv-item.unread .conv-name { font-weight: 800; }
.conv-item[aria-current="true"] { background: var(--accent-soft); }

@media (min-width: 768px) {
  .chat-layout { grid-template-columns: 320px 1fr; height: 100dvh; }
  .chat-layout .chat-list, .chat-layout .chat-thread { display: flex !important; flex-direction: column; }
  .chat-head .back-btn { display: none; }
  .main.chat-main { max-width: none; padding: 0; }
}

/* ==========================================================================
   Voice call panel
   ========================================================================== */
.call-panel {
  position: fixed; z-index: 90;
  left: 16px; right: 16px; bottom: calc(var(--nav-h) + var(--safe-bottom) + 16px);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 24px 20px 20px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  animation: toast-in .2s ease;
}
@media (min-width: 768px) { .call-panel { left: auto; right: 24px; bottom: 24px; width: 320px; } }
.call-name { font-weight: 750; font-size: 1.15rem; text-align: center; }
.call-status { color: var(--text-muted); font-size: .92rem; font-variant-numeric: tabular-nums; min-height: 1.4em; }
.call-actions { display: flex; gap: 20px; margin-top: 10px; }
.call-btn {
  width: 56px; height: 56px; border-radius: 50%; border: 0; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface-3); color: var(--text);
}
.call-btn .icon { width: 24px; height: 24px; }
.call-btn-accept { background: #1fa463; color: #fff; }
.call-btn-end { background: #e0384a; color: #fff; }
.call-btn-end .icon { transform: rotate(135deg); }
.call-btn-mute.on { background: var(--text); color: var(--bg); }
.call-btn:hover { filter: brightness(1.08); }

/* ==========================================================================
   Dialog / toast
   ========================================================================== */
dialog.modal {
  width: min(520px, calc(100vw - 32px)); max-height: calc(100dvh - 48px);
  padding: 0; border: 1px solid var(--border); border-radius: var(--radius-lg);
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
}
dialog.modal::backdrop { background: rgba(8, 10, 16, .5); backdrop-filter: blur(2px); }
.modal-form { display: flex; flex-direction: column; gap: 14px; padding: 20px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; margin-top: 4px; }

.toasts {
  position: fixed; z-index: 100; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 12px);
  display: flex; flex-direction: column; gap: 8px; align-items: center;
  width: min(440px, calc(100vw - 32px)); pointer-events: none;
}
@media (min-width: 768px) { .toasts { bottom: 24px; } }
.toast {
  pointer-events: auto;
  padding: 10px 16px; border-radius: 12px; font-size: .92rem; font-weight: 550;
  background: var(--text); color: var(--bg); box-shadow: var(--shadow-lg);
  animation: toast-in .2s ease;
}
.toast.error { background: var(--danger); color: #fff; }
.toast.success { background: var(--success); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ==========================================================================
   Public pages (landing / auth / legal)
   ========================================================================== */
.public-header {
  max-width: 1100px; margin: 0 auto; padding: 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.public-header .row { gap: 6px; }
@media (max-width: 480px) {
  .public-header { padding: 12px; }
  .public-header .brand > span:last-child { display: none; }
  .public-header .btn { min-height: 34px; padding: 6px 12px; font-size: .85rem; }
}
.public-footer {
  max-width: 1100px; margin: 0 auto; padding: 32px 16px 40px;
  display: flex; flex-wrap: wrap; gap: 16px; justify-content: space-between;
  color: var(--text-faint); font-size: .88rem; border-top: 1px solid var(--border);
}
.public-footer nav { display: flex; gap: 16px; flex-wrap: wrap; }
.public-footer a { color: var(--text-muted); }

.hero { max-width: 1100px; margin: 0 auto; padding: 48px 16px 40px; display: grid; gap: 40px; align-items: center; }
.hero h1 { font-size: clamp(2.1rem, 6vw, 3.6rem); font-weight: 800; letter-spacing: -0.035em; line-height: 1.05; }
.hero h1 em { font-style: normal; color: var(--accent); }
.hero .lead { font-size: 1.15rem; color: var(--text-muted); max-width: 34rem; margin-top: 16px; }
.hero-cta { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 28px; }
.hero-cta .btn { min-height: 48px; padding: 12px 22px; font-size: 1rem; }
.hero-visual { display: flex; flex-direction: column; gap: 12px; }
.hero-visual .card { padding: 14px 16px; }
.hero-visual .card:nth-child(2) { margin-left: 24px; }
.hero-visual .bubble { max-width: 90%; }
@media (min-width: 900px) { .hero { grid-template-columns: 1.1fr 1fr; padding-top: 72px; } }
.features { max-width: 1100px; margin: 0 auto; padding: 24px 16px 56px; display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.feature { padding: 20px; }
.feature .icon { color: var(--accent); width: 24px; height: 24px; margin-bottom: 12px; }
.feature p { color: var(--text-muted); font-size: .95rem; margin-top: 6px; }

.auth-wrap { min-height: calc(100dvh - 72px); display: flex; align-items: flex-start; justify-content: center; padding: 24px 16px 48px; }
@media (min-height: 700px) { .auth-wrap { align-items: center; } }
.auth-card { width: 100%; max-width: 420px; padding: 28px 22px; }
@media (min-width: 480px) { .auth-card { padding: 32px; } }
.auth-card h1 { font-size: 1.5rem; }
.auth-card .sub { color: var(--text-muted); margin-top: 6px; }
.auth-alt { text-align: center; font-size: .92rem; color: var(--text-muted); }
.pw-wrap { position: relative; }
.pw-wrap .input { padding-right: 48px; }
.pw-wrap .icon-btn { position: absolute; right: 3px; top: 3px; }
.strength { height: 4px; border-radius: 4px; background: var(--surface-3); overflow: hidden; }
.strength > span { display: block; height: 100%; width: 0; transition: width .2s, background .2s; }

.prose { max-width: 720px; margin: 0 auto; padding: 24px 16px 56px; }
.prose h1 { font-size: 2rem; margin-bottom: 8px; }
.prose h2 { font-size: 1.2rem; margin: 32px 0 10px; }
.prose p, .prose li { color: var(--text-muted); line-height: 1.7; }
.prose p + p { margin-top: 12px; }
.prose ul { padding-left: 20px; }
.prose li + li { margin-top: 6px; }
.prose strong { color: var(--text); }

.centered-page { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.centered-page .card { max-width: 480px; width: 100%; padding: 28px; }

.setup-banner { background: var(--warning-soft); color: var(--warning); padding: 10px 16px; font-size: .9rem; text-align: center; }
.setup-banner code { font-family: var(--mono); }

/* ==========================================================================
   Admin
   ========================================================================== */
.admin-badge { background: var(--danger); color: #fff; font-size: .68rem; padding: 2px 8px; border-radius: 999px; font-weight: 800; letter-spacing: .06em; }
.stat-grid { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 900px) { .stat-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.stat { padding: 16px; }
.stat-label { font-size: .8rem; color: var(--text-muted); font-weight: 600; }
.stat-value { font-size: 1.7rem; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; margin-top: 4px; }
.stat-note { font-size: .75rem; color: var(--text-faint); margin-top: 2px; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.data th, table.data td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
table.data th { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-faint); font-weight: 700; white-space: nowrap; background: var(--surface-2); }
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: var(--surface-2); }
.bars { display: flex; align-items: flex-end; gap: 4px; height: 140px; padding-top: 8px; }
.bars .bar-col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px; height: 100%; min-width: 0; }
.bars .bar { width: 100%; max-width: 28px; border-radius: 4px 4px 0 0; background: var(--accent); min-height: 2px; }
.bars .bar-label { font-size: .65rem; color: var(--text-faint); white-space: nowrap; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: .9rem; }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.snapshot { background: var(--surface-2); border-radius: 8px; padding: 10px 12px; font-size: .9rem; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 280px; overflow-y: auto; }
.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0; }
.timeline li { padding: 10px 0 10px 18px; border-left: 2px solid var(--border); position: relative; font-size: .9rem; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 15px; width: 10px; height: 10px; border-radius: 50%; background: var(--border-strong); }
.timeline li.danger::before { background: var(--danger); }
.timeline li.success::before { background: var(--success); }
.grid-2 { display: grid; gap: 16px; }
@media (min-width: 900px) { .grid-2 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }
.qr-box { background: #fff; padding: 12px; border-radius: 12px; width: 200px; height: 200px; margin: 0 auto; }
.qr-box img { width: 100%; height: 100%; }
