/* Quiet Precision (light) + Midnight Precision (dark) */
:root, [data-theme="light"] {
  --bg: #faf9f5;
  --surface: #faf9f5;
  --surface-low: #f4f4f0;
  --surface-container: #efeeea;
  --surface-high: #e9e8e4;
  --surface-lowest: #ffffff;
  --ink: #1b1c1a;
  --muted: #64748b;
  --outline: #e2e8f0;
  --primary: #0b2447;
  --on-primary: #ffffff;
  --bubble-mine: #f0f4f8;
  --bubble-peer: #f1f1f1;
  --accent-soft: #d0e1fb;
  --danger: #ba1a1a;
  --nav-bg: rgba(250, 249, 245, 0.92);
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.04);
  --radius: 8px;
  --radius-lg: 16px;
  --font-display: "Outfit", system-ui, sans-serif;
  --font-body: "Hanken Grotesk", system-ui, sans-serif;
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #131313;
  --surface: #131313;
  --surface-low: #1c1b1b;
  --surface-container: #201f1f;
  --surface-high: #2a2a2a;
  --surface-lowest: #0e0e0e;
  --ink: #e5e2e1;
  --muted: #94a3b8;
  --outline: #424754;
  --primary: #4d8eff;
  --on-primary: #00285d;
  --bubble-mine: #3a4a5f;
  --bubble-peer: #262626;
  --accent-soft: rgba(77, 142, 255, 0.15);
  --danger: #ffb4ab;
  --nav-bg: rgba(19, 19, 19, 0.94);
  --shadow: 0 2px 16px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
#app { height: 100%; }
.hidden { display: none !important; }
.screen { min-height: 100%; }

/* Auth */
.auth-screen {
  display: flex; align-items: center; justify-content: center;
  padding: 24px 20px;
  background: radial-gradient(900px 500px at 50% 20%, var(--surface-low), var(--bg));
}
.auth-hero, .auth-card {
  width: 100%; max-width: 400px; text-align: center;
}
.brand-mark { color: var(--primary); margin-bottom: 12px; }
.brand {
  font-family: var(--font-display); font-size: 2rem; font-weight: 600;
  letter-spacing: -0.02em; margin: 0 0 8px; color: var(--primary);
}
[data-theme="dark"] .brand { color: var(--primary); }
.headline {
  font-family: var(--font-display); font-size: 1.35rem; font-weight: 600;
  margin: 0 0 8px; letter-spacing: -0.01em;
}
.subhead { color: var(--muted); margin: 0 0 28px; font-size: 0.95rem; line-height: 1.45; }
.auth-card { text-align: left; background: var(--surface-lowest);
  border: 1px solid var(--outline); border-radius: var(--radius-lg); padding: 20px; box-shadow: var(--shadow); }
.auth-card h2 { font-family: var(--font-display); margin: 0 0 16px; font-size: 1.35rem; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; font-size: 13px; color: var(--muted); font-weight: 500; }
.field input, .search-wrap input, .composer input[type=text], .settings-block input, .settings-block select {
  font: inherit; color: var(--ink); background: var(--surface-low);
  border: 1px solid var(--outline); border-radius: var(--radius); padding: 12px 14px;
}
.field input:focus, .search-wrap input:focus, .composer input:focus {
  outline: none; border-color: var(--primary);
}
.hint { color: var(--muted); font-size: 13px; }
.btn {
  font-family: var(--font-display); font-weight: 600; font-size: 0.95rem;
  border-radius: var(--radius); padding: 12px 16px; border: 1px solid transparent;
  cursor: pointer; background: transparent; color: var(--ink);
}
.btn.block { width: 100%; margin-bottom: 10px; }
.btn.primary { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.btn.secondary { border-color: var(--primary); color: var(--primary); background: transparent; }
[data-theme="dark"] .btn.secondary { border-color: var(--outline); color: var(--ink); background: var(--surface-high); }
.btn.ghost { border: 0; color: var(--muted); }
.btn.sm { padding: 6px 10px; font-size: 12px; }
.btn.back { margin-bottom: 8px; }

/* Shell */
.shell {
  height: 100%; display: grid; grid-template-columns: 1fr; min-height: 0;
}
.sidebar {
  display: flex; flex-direction: column; min-height: 0; background: var(--surface);
  border-right: 1px solid var(--outline);
}
.side-header {
  display: flex; align-items: center; gap: 10px; padding: 14px 16px;
  border-bottom: 1px solid var(--outline);
}
.side-title {
  flex: 1; margin: 0; font-family: var(--font-display); font-size: 1.15rem; font-weight: 600;
  letter-spacing: -0.02em;
}
.icon-btn {
  width: 40px; height: 40px; border-radius: var(--radius); border: 0;
  background: transparent; color: var(--ink); font-size: 1.2rem; cursor: pointer;
}
.search-wrap { padding: 8px 16px 0; }
.search-wrap input { width: 100%; }
.side-panels { flex: 1; overflow: auto; min-height: 0; }
.panel-pane { padding-bottom: 8px; }

.bottom-nav {
  display: flex; border-top: 1px solid var(--outline); background: var(--nav-bg);
  backdrop-filter: blur(10px); padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}
.nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  border: 0; background: transparent; color: var(--muted); padding: 8px;
  font-family: var(--font-body); font-size: 11px; font-weight: 500; cursor: pointer;
  border-radius: var(--radius);
}
.nav-item.active { color: var(--ink); background: var(--accent-soft); font-weight: 600; }
.nav-ico { font-size: 1.1rem; line-height: 1; }

/* Lists */
.row {
  display: flex; gap: 12px; align-items: center; padding: 14px 16px;
  border-bottom: 1px solid var(--outline); cursor: pointer;
}
.row:hover, .row.active { background: var(--surface-low); }
.row .meta { margin-left: auto; text-align: right; flex-shrink: 0; }
.row .name { font-weight: 600; font-family: var(--font-display); font-size: 0.95rem; }
.row .preview { color: var(--muted); font-size: 0.85rem; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; }
.row.unread .preview { color: var(--ink); font-weight: 600; }
.row .time { color: var(--muted); font-size: 11px; letter-spacing: 0.02em; }
.badge-dot {
  display: inline-flex; min-width: 8px; height: 8px; border-radius: 999px;
  background: var(--primary); margin-top: 6px;
}
.badge-num {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px;
  background: var(--primary); color: var(--on-primary); font-size: 11px; font-weight: 600; margin-top: 4px;
}
.empty-state {
  color: var(--muted); text-align: center; padding: 48px 24px; font-size: 0.95rem;
}
.panel-actions { padding: 12px 16px; display: flex; flex-direction: column; gap: 8px; }

/* Avatar */
.avatar {
  position: relative; flex-shrink: 0; border-radius: 50%;
  background: var(--surface-high); color: var(--ink);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-weight: 600; overflow: hidden;
  background-size: cover; background-position: center;
}
.avatar.sm { width: 36px; height: 36px; font-size: 13px; }
.avatar.md { width: 48px; height: 48px; font-size: 16px; }
.avatar.lg { width: 72px; height: 72px; font-size: 24px; }
.avatar .online {
  position: absolute; right: 0; bottom: 0; width: 10px; height: 10px;
  border-radius: 50%; background: var(--primary); border: 2px solid var(--surface);
}

/* Chat pane */
.chat-pane {
  display: flex; flex-direction: column; min-height: 0; background: var(--bg);
}
.chat-header {
  display: flex; align-items: center; gap: 10px; padding: 12px 16px;
  border-bottom: 1px solid var(--outline); background: var(--surface);
}
.chat-peer { flex: 1; min-width: 0; }
.peer-name { font-family: var(--font-display); font-weight: 600; }
.peer-sub { color: var(--muted); font-size: 13px; }
.typing-bar {
  padding: 6px 16px; font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--outline);
}
.msgs {
  flex: 1; overflow: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px;
}
.msg {
  max-width: min(78%, 420px); padding: 10px 12px; border-radius: var(--radius);
  background: var(--bubble-peer); align-self: flex-start;
}
.msg.mine { align-self: flex-end; background: var(--bubble-mine); }
.msg .meta { font-size: 11px; color: var(--muted); margin-top: 4px; display: flex; gap: 6px; justify-content: flex-end; }
.msg-img { max-width: 220px; border-radius: var(--radius); display: block; }
.file-card, .maps-link, .poll {
  display: block; text-decoration: none; color: inherit;
  background: var(--surface); border: 1px solid var(--outline); border-radius: var(--radius);
  padding: 10px 12px;
}
.maps-link { display: flex; gap: 10px; align-items: center; }
.poll-opts { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.poll-opt {
  display: flex; justify-content: space-between; gap: 8px; cursor: pointer;
  text-align: left; background: var(--surface-low); border: 1px solid var(--outline);
  border-radius: var(--radius); padding: 10px 12px; color: var(--ink); font: inherit;
}
.poll-opt:hover { border-color: var(--primary); }
.poll-add { display: flex; gap: 6px; margin-top: 8px; }
.poll-add input { flex: 1; min-width: 0; }

.composer {
  position: relative; display: flex; gap: 8px; align-items: center;
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--outline); background: var(--surface);
}
.composer input[type=text] { flex: 1; min-width: 0; }
.composer .send { width: 44px; height: 44px; padding: 0; border-radius: var(--radius); }
.plus-menu {
  position: absolute; bottom: 64px; left: 12px; z-index: 5;
  background: var(--surface-low); border: 1px solid var(--outline); border-radius: var(--radius-lg);
  box-shadow: var(--shadow); padding: 6px; display: flex; flex-direction: column; min-width: 160px;
}
.plus-menu button {
  border: 0; background: transparent; text-align: left; padding: 10px 12px;
  color: var(--ink); font: inherit; cursor: pointer; border-radius: var(--radius);
}
.plus-menu button:hover { background: var(--accent-soft); }

.call-bar {
  display: flex; gap: 8px; align-items: center; padding: 8px 12px;
  background: var(--surface-low); border-top: 1px solid var(--outline);
}
video { width: 140px; height: 100px; background: #000; border-radius: var(--radius); object-fit: cover; }

/* Settings */
.settings-block {
  padding: 16px 20px; border-bottom: 1px solid var(--outline);
  display: flex; flex-direction: column; gap: 10px;
}
.settings-block h3 {
  margin: 0; font-family: var(--font-display); font-size: 0.85rem;
  letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); font-weight: 600;
}
.settings-row { display: flex; gap: 12px; align-items: center; }

.toast {
  position: fixed; left: 50%; bottom: 88px; transform: translateX(-50%);
  background: var(--primary); color: var(--on-primary); padding: 10px 16px;
  border-radius: var(--radius-lg); z-index: 40; font-size: 14px; box-shadow: var(--shadow);
  max-width: 90%;
}
.mobile-only { display: inline-flex; }

@media (min-width: 800px) {
  .shell { grid-template-columns: 360px 1fr; }
  .mobile-only { display: none !important; }
  .bottom-nav {
    flex-direction: column; border-top: 0; border-right: 1px solid var(--outline);
    position: absolute; left: 0; top: 57px; bottom: 0; width: 64px; padding: 8px;
  }
  .sidebar { padding-left: 64px; position: relative; }
  .nav-item span:last-child { display: none; }
  .nav-item { padding: 14px 8px; }
  .chat-pane { display: flex !important; }
}
@media (max-width: 799px) {
  .shell.chat-open .sidebar { display: none; }
  .shell:not(.chat-open) .chat-pane { display: none; }
}
