/* Arbat Chat — family design (Helio-grade). Quiet, glass, no telegram clone. */
:root {
  /* Match panel-deep everywhere so PWA never paints a darker black band */
  --bg: #0c0d14;
  --bg-elevated: rgba(15, 17, 26, 0.92);
  --bg-inset: #0c0d14;
  --bg-panel: rgba(18, 20, 30, 0.72);
  --text: #f4f4f5;
  --muted: #a1a1aa;
  --border: rgba(255, 255, 255, 0.08);
  --accent: #818cf8;
  --accent-soft: #a5b4fc;
  --accent-dim: rgba(129, 140, 248, 0.16);
  --accent-glow: rgba(99, 102, 241, 0.22);
  --mine: rgba(99, 102, 241, 0.28);
  --mine-border: rgba(129, 140, 248, 0.28);
  --theirs: rgba(24, 26, 38, 0.9);
  --ok: #34d399;
  --danger: #f87171;
  --radius-lg: 20px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --side-w: min(340px, 34vw);
  /* iOS PWA: visualViewport sets --app-h; fallback fill-available */
  --app-h: 100dvh;
  /* Bottom dock — same UX tokens as Helio */
  --tab-bar-h: 52px;
  --tab-bar-pad-top: 6px;
  --tab-bar-pad-bottom: 6px;
  /* Outer dock: top pad + pill + bottom pad + home indicator (Helio formula) */
  --tab-bar-total: var(--tab-bar-measured, calc(
    var(--tab-bar-pad-top) + var(--tab-bar-h) + var(--tab-bar-pad-bottom) + var(--safe-b)
  ));
  /* Frosted pill only — outer zone transparent (Helio / FitTrack) */
  --tab-bar-bg: rgba(24, 26, 36, 0.55);
  /* Match tab-panel bottom so zone around pill is not a different black */
  --panel-deep: #0c0d14;
  --home-fill: #0c0d14;
}

* {
  box-sizing: border-box;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
*::-webkit-scrollbar { display: none; width: 0; height: 0; }

html {
  margin: 0;
  height: 100%;
  height: -webkit-fill-available;
  background: var(--panel-deep);
}

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  min-height: 100%;
  min-height: 100dvh;
  min-height: -webkit-fill-available;
  background: var(--panel-deep);
  color: var(--text);
  font-family: var(--font);
  overflow: hidden; /* PWA: avoid rubber-band black voids */
  overscroll-behavior: none;
  touch-action: manipulation;
  -ms-touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}

.hidden { display: none !important; }

/* visualViewport shell (pinned in JS) — all UI lives here */
#vv-root {
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--panel-deep);
  z-index: 1;
}

/* Atmospheric glow — like Helio; fills vv-root */
.bg-glow {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(ellipse 80% 50% at 50% -15%, rgba(99, 102, 241, 0.18), transparent 70%),
    radial-gradient(ellipse 55% 40% at 90% 90%, rgba(129, 140, 248, 0.08), transparent 60%),
    radial-gradient(ellipse 40% 30% at 10% 85%, rgba(52, 211, 153, 0.05), transparent 55%);
}

.app-shell {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  background: var(--panel-deep);
}

/* ——— Auth ——— */
.auth-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(24px, calc(var(--safe-t) + 16px)) 16px calc(24px + var(--safe-b));
}

/* Session boot — neutral, no login flash */
.boot-wrap {
  min-height: 100dvh;
}
.boot-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
}
.boot-mark {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  animation: boot-pulse 1.4s ease-in-out infinite;
}
.boot-text {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}
@keyframes boot-pulse {
  0%, 100% { opacity: 0.85; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.03); }
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 22px 22px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 10px;
}

.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: linear-gradient(145deg, #818cf8, #6366f1);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 1.15rem;
  color: #fff;
  box-shadow: 0 8px 24px rgba(99, 102, 241, 0.28);
}

.brand h1 {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.brand .sub {
  margin: 2px 0 0;
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 400;
}

.lead {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.5;
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(52, 211, 153, 0.12);
  color: #6ee7b7;
  border: 1px solid rgba(52, 211, 153, 0.18);
}

label.field {
  display: block;
  margin-bottom: 12px;
}

label.field > span {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 6px;
  font-weight: 500;
}

input, textarea {
  width: 100%;
  background: var(--bg-inset);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input::placeholder, textarea::placeholder {
  color: var(--muted);
  opacity: 0.8;
}

input:focus, textarea:focus {
  border-color: rgba(129, 140, 248, 0.45);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  background: var(--accent);
  color: #0b0b14;
  transition: opacity 0.15s, transform 0.1s, background 0.15s;
  touch-action: manipulation;
}

.btn:hover { background: var(--accent-soft); }
.btn:active { transform: scale(0.98); }
.btn.full { width: 100%; }
.btn.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}
.btn.ghost:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}
.btn.compact {
  padding: 8px 12px;
  font-size: 0.85rem;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.err-text {
  color: var(--danger);
  font-size: 0.85rem;
  min-height: 1.2em;
  margin: 4px 0 10px;
}

.lock-note {
  margin-top: 16px;
  padding: 12px 14px;
  font-size: 0.8rem;
  line-height: 1.45;
  color: var(--muted);
  background: var(--accent-dim);
  border: 1px solid rgba(129, 140, 248, 0.15);
  border-radius: var(--radius-sm);
}

.lock-note a { color: var(--accent-soft); text-decoration: none; }

.auth-foot {
  margin: 14px 0 0;
  text-align: center;
  font-size: 0.75rem;
  color: var(--muted);
}

/* ——— Main layout ——— */
/*
 * Absolute fill of #vv-root (not position:fixed to the flaky layout viewport).
 * vv-root is pinned to visualViewport → first paint matches after-rotate.
 */
.main {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  max-height: none;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding-bottom: 0;
  box-sizing: border-box;
  background: var(--panel-deep);
  overflow: hidden;
}

.app-body {
  flex: 1;
  min-height: 0;
  height: 100%;
  display: grid;
  grid-template-columns: var(--side-w) 1fr;
  gap: 0;
  /* NO padding-bottom here — that left a black empty slab around the floating pill.
     Content draws full-bleed; lists pad themselves so items clear the pill. */
  padding-bottom: 0;
  box-sizing: border-box;
}

.main.chat-open .app-body {
  padding-bottom: 0;
}

@media (max-width: 800px) {
  .app-body { grid-template-columns: 1fr; }
  .main.chat-open .tab-panel { display: none !important; }
  .main:not(.chat-open) .thread { display: none; }
  /* Dock is body-level; hide while reading a chat on phone */
  body.chat-open #tab-bar,
  body.chat-open #dock-fill {
    display: none !important;
  }
}

/* Tab panels (left column on desktop) */
.tab-panel {
  display: none;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  /* Solid panel to bottom edge — peeks around floating pill (looks transparent/clear) */
  background: linear-gradient(180deg, #12141e 0%, var(--panel-deep) 72%, var(--panel-deep) 100%);
  border-right: 1px solid var(--border);
  overflow: hidden;
}
.tab-panel.active {
  display: flex;
}
.tab-panel[hidden] {
  display: none !important;
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: calc(18px + var(--safe-t)) 16px 6px 18px;
  border-bottom: none;
  flex-shrink: 0;
}
.panel-pad { padding: 8px 16px 10px; }

/* Profile photo button (top-right) */
.profile-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.14);
  padding: 0;
  margin: 0;
  overflow: hidden;
  flex-shrink: 0;
  cursor: pointer;
  background: linear-gradient(145deg, #6366f1, #818cf8);
  position: relative;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.28);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.12s, box-shadow 0.15s;
}
.profile-btn:active { transform: scale(0.94); }
.profile-btn-fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.95rem;
  color: #fff;
  letter-spacing: 0.02em;
}
.profile-btn-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.profile-btn.has-photo .profile-btn-fallback { display: none; }

/* Bottom sheet for avatar actions */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 20000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet.hidden { display: none !important; }
.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}
.sheet-card {
  position: relative;
  z-index: 1;
  width: min(100%, 420px);
  margin: 0 10px calc(12px + env(safe-area-inset-bottom, 0px));
  padding: 18px 14px 12px;
  border-radius: 20px;
  background: #1a1c28;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  gap: 6px;
  animation: sheet-up 0.22s ease;
}
@keyframes sheet-up {
  from { transform: translateY(18px); opacity: 0.6; }
  to { transform: translateY(0); opacity: 1; }
}
.sheet-preview {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 4px 8px 12px;
}
.sheet-avatar {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  overflow: hidden;
  background: linear-gradient(145deg, #6366f1, #818cf8);
  border: 3px solid rgba(255, 255, 255, 0.12);
  position: relative;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}
.sheet-avatar span {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 1.6rem;
  color: #fff;
}
.sheet-avatar img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.sheet-avatar.has-photo span { display: none; }
.sheet-title {
  margin: 8px 0 0;
  font-size: 1.05rem;
  font-weight: 650;
  color: var(--text);
}
.sheet-lead {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
}
.sheet-action {
  width: 100%;
  border: none;
  border-radius: 14px;
  padding: 14px 16px;
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  text-align: center;
  touch-action: manipulation;
  transition: background 0.12s;
}
.sheet-action:hover { background: rgba(255, 255, 255, 0.1); }
.sheet-action:active { background: rgba(255, 255, 255, 0.08); }
.sheet-action.danger { color: #fca5a5; }
.sheet-action.ghost {
  background: transparent;
  color: var(--muted);
  font-weight: 500;
  margin-top: 2px;
}
.sheet-action.hidden { display: none !important; }

.panel-head .titles h1,
.side-top .titles h1 {
  margin: 0;
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.panel-head .titles small,
.side-top .titles small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 450;
}

.side-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/*
 * Bottom nav — Helio UX:
 * - outer shell transparent (content peeks around pill)
 * - only .tab-bar-inner is frosted glass
 * - padding = pad-top + full safe-bottom + pad-bottom
 * position:absolute inside #vv-root (stable on iOS PWA)
 */
.dock-fill {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  height: 0;
  background: transparent;
  pointer-events: none;
}

.tab-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  top: auto;
  z-index: 50;
  width: 100%;
  margin: 0;
  /* Helio formula */
  padding: var(--tab-bar-pad-top) 12px calc(var(--safe-b) + var(--tab-bar-pad-bottom));
  border: none;
  box-sizing: border-box;
  pointer-events: none; /* only the pill receives taps */
  background: transparent !important;
  background-color: transparent !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  box-shadow: none !important;
}
.tab-bar-inner {
  width: 100%;
  max-width: 400px; /* 3 tabs; Helio uses 480 for 4 */
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  align-items: center;
  min-height: var(--tab-bar-h);
  padding: 4px;
  background: var(--tab-bar-bg);
  backdrop-filter: blur(22px) saturate(1.4);
  -webkit-backdrop-filter: blur(22px) saturate(1.4);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 18px;
  box-shadow:
    0 6px 20px rgba(0, 0, 0, 0.22),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
  box-sizing: border-box;
  pointer-events: auto;
}
.nav-tab {
  border: none;
  background: none;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  width: 100%;
  padding: 8px 4px;
  border-radius: 14px;
  transition: color 0.15s ease, background 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.nav-tab svg {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  opacity: 1;
}
.nav-tab.active {
  color: var(--accent);
  background: var(--accent-dim);
}
.nav-tab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* More tab cards */
.more-scroll {
  flex: 1;
  overflow: auto;
  padding: 12px 16px;
  padding-bottom: calc(var(--tab-bar-total) + 20px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}
.more-card {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 18px;
  box-shadow: none;
}
.more-card.quiet {
  background: transparent;
  box-shadow: none;
  border-style: dashed;
}
.more-card-title {
  margin: 0 0 6px;
  font-size: 1rem;
  font-weight: 650;
}
.more-card-lead {
  margin: 0 0 14px;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.45;
}
.more-line {
  margin: 0 0 8px;
  font-size: 0.92rem;
}
.more-line.muted,
.more-line .muted { color: var(--muted); }
.more-link {
  display: inline-block;
  margin: 4px 0 12px;
  color: var(--accent-soft);
  text-decoration: none;
  font-size: 0.9rem;
}
.more-btn { margin-top: 8px; }
.more-status {
  margin: 10px 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}
.more-card-about .more-card-lead {
  margin-bottom: 10px;
}
.more-version {
  margin: 0;
  font-size: 0.75rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.more-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  cursor: pointer;
}
.more-toggle-text { font-weight: 550; font-size: 0.95rem; }
.more-switch-input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}
.more-switch {
  width: 46px;
  height: 28px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid var(--border);
  position: relative;
  flex-shrink: 0;
  transition: background 0.15s;
}
.more-switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s;
}
.more-switch-input:checked + .more-switch {
  background: rgba(129, 140, 248, 0.55);
  border-color: rgba(129, 140, 248, 0.4);
}
.more-switch-input:checked + .more-switch::after {
  transform: translateX(18px);
}

.icon-btn {
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-inset);
  color: var(--muted);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 1rem;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
  touch-action: manipulation;
}

.icon-btn:hover {
  color: var(--text);
  border-color: rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.04);
}

.search-wrap input {
  border-radius: 14px;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid transparent;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.search-wrap input:focus {
  background: rgba(255, 255, 255, 0.07);
  border-color: rgba(129, 140, 248, 0.35);
  box-shadow: 0 0 0 3px rgba(129, 140, 248, 0.12);
}

.search-results {
  max-height: 220px;
  overflow: auto;
  margin: 0 10px;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.18);
}

.search-hit {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.12s;
  touch-action: manipulation;
  border-radius: 12px;
}

.search-hit:hover { background: rgba(255, 255, 255, 0.05); }
.search-hit:disabled { opacity: 0.4; cursor: not-allowed; }
.search-hit .hit-body { min-width: 0; flex: 1; }
.search-hit .hit-name { font-weight: 600; font-size: 0.95rem; }
.search-hit .muted { color: var(--muted); font-size: 0.78rem; }

.conv-list {
  flex: 1;
  overflow: auto;
  min-height: 0;
  padding: 4px 10px;
  /* Clear floating pill + home indicator (content continues behind pill) */
  padding-bottom: calc(var(--tab-bar-total) + 12px);
}

.conv-item {
  width: 100%;
  display: grid;
  grid-template-columns: 48px 1fr auto;
  grid-template-rows: auto auto;
  column-gap: 12px;
  row-gap: 2px;
  align-items: center;
  padding: 11px 12px;
  margin-bottom: 2px;
  border: 1px solid transparent;
  border-radius: 16px;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.14s, border-color 0.14s, transform 0.1s;
  touch-action: manipulation;
}

.conv-item:hover {
  background: rgba(255, 255, 255, 0.045);
}

.conv-item:active {
  transform: scale(0.99);
}

.conv-item.active {
  background: rgba(129, 140, 248, 0.14);
  border-color: rgba(129, 140, 248, 0.18);
}

.avatar {
  width: 48px;
  height: 48px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  font-weight: 650;
  font-size: 0.92rem;
  color: #fff;
  grid-row: 1 / span 2;
  letter-spacing: 0.02em;
  user-select: none;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  overflow: hidden;
  position: relative;
}
.avatar.has-photo {
  background: transparent !important;
}
.avatar-photo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.avatar.sm {
  width: 36px;
  height: 36px;
  font-size: 0.8rem;
  border-radius: 12px;
}

.avatar.xs {
  width: 32px;
  height: 32px;
  font-size: 0.72rem;
  border-radius: 10px;
}

.conv-name {
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  grid-column: 2;
}

.conv-time {
  color: var(--muted);
  font-size: 0.72rem;
  grid-column: 3;
  white-space: nowrap;
  align-self: start;
  padding-top: 2px;
}

.conv-preview {
  color: var(--muted);
  font-size: 0.84rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  grid-column: 2 / span 2;
}

.empty-hint {
  margin: 0;
  padding: 12px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
}
.empty-hint.subtle { opacity: 0.75; padding: 14px; }

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex: 1;
  min-height: 40vh;
  padding: 32px 22px calc(var(--tab-bar-total) + 24px);
  text-align: center;
}
.empty-state.inline {
  margin: auto;
  padding: 40px 16px;
  min-height: 0;
  flex: 0 0 auto;
}
.empty-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 650;
  color: var(--text);
  letter-spacing: -0.02em;
}

.skeleton-list { padding: 8px; display: grid; gap: 8px; }
.skeleton-row {
  height: 64px;
  border-radius: var(--radius-md);
  background: linear-gradient(90deg, rgba(255,255,255,0.03), rgba(255,255,255,0.07), rgba(255,255,255,0.03));
  background-size: 200% 100%;
  animation: sk 1.2s ease-in-out infinite;
}
@keyframes sk {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

.msg-loading {
  margin: auto;
  color: var(--muted);
  font-size: 0.9rem;
  padding: 40px;
  text-align: center;
}

.conn-status {
  position: sticky;
  top: 0;
  z-index: 35;
  text-align: center;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 8px 12px;
  background: rgba(245, 158, 11, 0.14);
  color: #fcd34d;
  border-bottom: 1px solid rgba(245, 158, 11, 0.2);
}
.conn-status.err {
  background: rgba(248, 113, 113, 0.14);
  color: #fecaca;
  border-color: rgba(248, 113, 113, 0.25);
}
.conn-status.warn {
  background: rgba(245, 158, 11, 0.12);
  color: #fde68a;
}

.bubble.pending { opacity: 0.72; }
.bubble.pending .bubble-meta { color: var(--accent-soft); }

/* Thread */
.thread {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  background:
    radial-gradient(ellipse 80% 50% at 50% 0%, rgba(99, 102, 241, 0.1), transparent 55%),
    radial-gradient(ellipse 60% 40% at 80% 100%, rgba(129, 140, 248, 0.06), transparent 50%),
    var(--bg);
  position: relative;
}

.chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 40px 28px calc(40px + var(--tab-bar-total));
  text-align: center;
  color: var(--muted);
}

.chat-empty .mark {
  width: 72px;
  height: 72px;
  border-radius: 22px;
  background: linear-gradient(145deg, #818cf8, #6366f1);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 1.55rem;
  color: #fff;
  box-shadow: 0 14px 40px rgba(99, 102, 241, 0.32);
  margin-bottom: 12px;
}

.chat-empty strong {
  color: var(--text);
  font-size: 1.2rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.chat-empty span {
  max-width: 260px;
  font-size: 0.9rem;
  line-height: 1.5;
  line-height: 1.5;
}

#chat-panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.thread-head {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 58px;
  padding: calc(10px + var(--safe-t)) 14px 10px;
  background: rgba(15, 17, 26, 0.82);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(16px);
  flex-shrink: 0;
}

.thread-head .peer {
  flex: 1;
  min-width: 0;
}

.thread-head h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.thread-head .meta {
  margin-top: 2px;
  font-size: 0.75rem;
  color: var(--muted);
}

.thread-head .meta.live {
  color: #6ee7b7;
}

.btn-back {
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-inset);
  color: var(--muted);
  cursor: pointer;
  display: none;
  place-items: center;
  font-size: 1.1rem;
  flex-shrink: 0;
  touch-action: manipulation;
}

@media (max-width: 800px) {
  .btn-back { display: grid; }
}

/* Messages */
.msg-list {
  flex: 1;
  overflow: auto;
  min-height: 0;
  padding: 16px 16px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.date-chip {
  align-self: center;
  margin: 10px 0 6px;
  padding: 5px 12px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  background: rgba(15, 17, 26, 0.75);
  border: 1px solid var(--border);
  border-radius: 999px;
  backdrop-filter: blur(8px);
}

.bubble-row {
  display: flex;
  width: 100%;
}

.bubble-row.mine { justify-content: flex-end; }
.bubble-row.theirs { justify-content: flex-start; }

.bubble {
  max-width: min(78%, 420px);
  padding: 10px 12px 8px;
  border-radius: 16px 16px 16px 6px;
  background: var(--theirs);
  border: 1px solid var(--border);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}

.bubble.mine {
  background: var(--mine);
  border-color: var(--mine-border);
  border-radius: 16px 16px 6px 16px;
}

.bubble.failed { opacity: 0.7; }

.bubble-text {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.95rem;
  line-height: 1.45;
  color: var(--text);
}

.bubble-meta {
  margin-top: 4px;
  text-align: right;
  font-size: 0.68rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.typing {
  min-height: 1.1em;
  padding: 0 18px 4px;
  font-size: 0.8rem;
  color: var(--accent-soft);
}

/* Composer */
.composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 10px 12px calc(10px + var(--kb-inset, 0px));
  background: rgba(15, 17, 26, 0.9);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(16px);
  flex-shrink: 0;
}
/* Full-screen mobile chat (dock hidden): clear home indicator */
.main.chat-open .composer {
  padding-bottom: calc(12px + var(--safe-b) + var(--kb-inset, 0px));
}

.composer-inner {
  flex: 1;
  min-width: 0;
}

.composer textarea {
  min-height: 44px;
  max-height: 140px;
  resize: none;
  line-height: 1.4;
  padding: 12px 16px;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.composer textarea:focus {
  border-color: rgba(129, 140, 248, 0.3);
  box-shadow: 0 0 0 3px rgba(129, 140, 248, 0.1);
}

.composer .send-btn {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(145deg, #818cf8, #6366f1);
  color: #fff;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.35);
  transition: transform 0.12s, box-shadow 0.15s, opacity 0.15s;
  touch-action: manipulation;
}

.composer .send-btn:hover {
  box-shadow: 0 6px 18px rgba(99, 102, 241, 0.45);
}
.composer .send-btn:active { transform: scale(0.94); }
.composer .send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* Toast */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-b));
  transform: translateX(-50%) translateY(12px);
  z-index: 60;
  max-width: min(90vw, 360px);
  padding: 12px 16px;
  border-radius: 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.88rem;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: 0.2s ease;
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

#toast.err {
  border-color: rgba(248, 113, 113, 0.35);
  color: #fecaca;
}

/* Install */
.install-banner {
  position: sticky;
  top: 0;
  z-index: 40;
  padding: calc(8px + var(--safe-t)) 14px 8px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(16px);
}

.install-content {
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.install-text {
  margin: 0;
  flex: 1 1 200px;
  font-size: 0.88rem;
  color: var(--text);
  line-height: 1.4;
}

.install-actions {
  display: flex;
  gap: 8px;
}

@media (display-mode: standalone) {
  .install-banner { display: none !important; }
}

@media (min-width: 1100px) {
  :root { --side-w: 380px; }
}

/* Desktop: always show thread; tab panels swap left column */
@media (min-width: 801px) {
  .thread {
    display: flex !important;
  }
  /* Keep dock visible while chat is open (side-by-side layout) */
  body.chat-open #tab-bar {
    display: block !important;
  }
  body.chat-open #dock-fill {
    display: none !important;
  }
  .btn-back {
    display: none !important;
  }
}

/* Desktop: no home-indicator plate */
@media (min-width: 801px) {
  .dock-fill {
    display: none !important;
  }
  .tab-bar {
    padding-bottom: 14px;
  }
}

/* Standalone PWA — same Helio dock formula */
@media (display-mode: standalone) {
  html, body, #vv-root, .main, .app-shell {
    background: var(--panel-deep) !important;
  }
  .dock-fill {
    background: transparent !important;
  }
  .tab-bar {
    background: transparent !important;
    padding: var(--tab-bar-pad-top) 12px calc(var(--safe-b) + var(--tab-bar-pad-bottom));
  }
}

/*
 * Landscape: compact dock; keep shell fill so no black band.
 */
@media (orientation: landscape) and (max-height: 520px) {
  html, body, #vv-root, .main, .app-shell {
    background: var(--panel-deep) !important;
  }
  .dock-fill {
    display: none !important;
  }
  .tab-bar {
    padding-top: 4px;
    padding-left: max(12px, env(safe-area-inset-left, 0px));
    padding-right: max(12px, env(safe-area-inset-right, 0px));
    padding-bottom: calc(4px + env(safe-area-inset-bottom, 0px));
  }
  .tab-bar-inner {
    min-height: 44px;
    max-width: 420px;
  }
  .nav-tab {
    padding: 6px 4px;
    font-size: 0.6rem;
  }
  .nav-tab svg {
    width: 20px;
    height: 20px;
  }
}
