﻿/* Dispop app.css — Layout & app-specific styles. Requires tokens.css + components.css */

/* =============== GLOBAL =============== */
html, body { height: 100%; overflow: hidden; }
body { display: flex; flex-direction: column; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

/* Both screens fill the viewport */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
}

/* Auth screen centers its card */
#auth-screen {
  align-items: center; justify-content: center;
  padding: var(--s-6);
  background: radial-gradient(ellipse at top, oklch(28% 0.025 250), var(--bg-deep) 60%);
  z-index: 1;
}

/* App screen is a flex row (dock | sidebar | chat) */
#app-screen {
  flex-direction: row;
  z-index: 1;
  overflow: hidden;
}
#auth-starfield {
  position: fixed; inset: 0; width: 100%; height: 100%;
  z-index: 0; pointer-events: none;
}

.auth-card {
  position: relative; z-index: 2;
  width: 100%; max-width: 420px;
  background: oklch(from var(--surface) l c h / 0.92);
  backdrop-filter: blur(20px) saturate(140%);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow-3);
  padding: var(--s-6);
  display: flex; flex-direction: column; gap: var(--s-4);
}

.brand {
  display: flex; flex-direction: column; align-items: center;
  gap: var(--s-3); padding: var(--s-3) 0 var(--s-2);
  text-align: center;
}
.brand h1 {
  margin: var(--s-3) 0 0;
  font-family: var(--font-display);
  font-weight: 700; font-size: 28px;
  letter-spacing: -0.02em;
}
.brand-mark {
  width: 56px; height: 56px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  position: relative;
  box-shadow: inset 0 1px 0 oklch(100% 0 0 / 0.18), 0 6px 14px -6px var(--accent-soft);
}
.brand-mark::after {
  content: "";
  position: absolute;
  width: 20px; height: 20px;
  border-radius: 50% 50% 50% 8px;
  background: linear-gradient(135deg, var(--accent-strong), var(--accent));
  bottom: -6px; right: -6px;
  box-shadow: 0 2px 6px -2px oklch(0% 0 0 / 0.4);
}

.tabs {
  display: flex; padding: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
}
.tab {
  flex: 1; height: 36px;
  border: 0; background: transparent;
  border-radius: var(--r-md);
  color: var(--muted);
  font: inherit; font-weight: 600; font-size: var(--t-sm);
  cursor: pointer;
  transition: all var(--d-fast) var(--ease);
}
.tab.active {
  background: var(--surface);
  color: var(--fg-strong);
  box-shadow: var(--shadow-1);
}

.auth-form {
  display: flex; flex-direction: column; gap: var(--s-3);
}
.auth-form label {
  font-size: var(--t-xs); font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.auth-form input,
.auth-form textarea {
  width: 100%; height: 38px;
  padding: 0 var(--s-3);
  background: var(--surface);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  font: inherit;
  transition: border-color var(--d-fast) var(--ease);
}
.auth-form input:focus,
.auth-form textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.auth-form input::placeholder { color: var(--muted-2); }

.btn-primary {
  display: inline-flex; align-items: center; justify-content: center;
  height: 44px; padding: 0 var(--s-5);
  background: var(--accent); color: var(--accent-fg);
  border: 0; border-radius: var(--r-lg);
  font: inherit; font-weight: 600; font-size: var(--t-lg);
  cursor: pointer; margin-top: var(--s-2);
  transition: background var(--d-fast) var(--ease), transform var(--d-fast) var(--ease);
}
.btn-primary:hover { background: var(--accent-strong); }
.btn-primary:active { transform: translateY(0.5px); }

.btn-ghost {
  background: transparent; color: var(--muted);
  border: 1px solid var(--border);
  padding: 10px; border-radius: var(--r-md);
  margin-top: var(--s-2); cursor: pointer;
  font: inherit;
}
.btn-ghost:hover { background: var(--hover); color: var(--fg); }

.btn-danger {
  background: var(--danger); color: oklch(99% 0.003 25);
  border: 0; padding: 10px 14px;
  border-radius: var(--r-md); cursor: pointer;
  font: inherit; font-weight: 600;
}

.form-error {
  color: var(--danger); font-size: var(--t-sm);
  margin-top: var(--s-2); min-height: 18px;
}
.form-hint {
  display: block; font-size: var(--t-xs);
  color: var(--muted); margin-top: var(--s-1); min-height: 16px;
}
.form-hint.success { color: var(--success); }
.form-hint.error { color: var(--danger); }

/* =============== APP LAYOUT =============== */

/* Mobile: column layout so tabbar sits at bottom */
@media (max-width: 720px) {
  #app-screen {
    flex-direction: column;
  }
}

.mobile-tabbar { display: none; }

/* Desktop dock (left icon rail) */
.desktop-dock {
  width: 68px; flex: none;
  background: var(--bg-deep);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  align-items: center;
  padding: 12px 0 16px; gap: 8px;
  height: 100%;
  overflow: hidden;
}
.dock-btn {
  position: relative;
  width: 44px; height: 44px;
  border-radius: var(--r-lg);
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); cursor: pointer;
  background: transparent; border: 0;
  transition: all var(--d-fast) var(--ease);
}
.dock-btn:hover { color: var(--fg); background: var(--surface); }
.dock-btn.active { background: var(--accent-soft); color: var(--fg-strong); }
.dock-btn svg { width: 22px; height: 22px; }
.desktop-dock-main {
  display: flex; flex-direction: column;
  align-items: center; gap: 8px; flex: 1;
}
.dock-profile {
  background: transparent; border: 0; cursor: pointer; padding: 0;
}

/* Sidebar */
.sidebar {
  width: 340px; min-width: 340px; flex: none;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  height: 100%;
  overflow: hidden;
}
.side-head {
  padding: 18px 20px 12px;
  display: flex; align-items: center; gap: 10px;
  border-bottom: none; flex: none;
}
.side-head-copy { flex: 1; min-width: 0; }
.side-title {
  font-family: var(--font-display);
  font-weight: 700; font-size: var(--t-2xl);
  letter-spacing: -0.01em;
}
.side-head-actions { display: flex; gap: var(--s-1); }
.me { flex: 1; min-width: 0; }
.me-name {
  font-weight: 600; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.me-user { font-size: var(--t-xs); color: var(--muted); }

.search-bar { padding: 0 14px 12px; }
.search-bar input {
  width: 100%; height: 38px;
  padding: 0 var(--s-3) 0 36px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--fg);
  border-radius: var(--r-md);
  font: inherit; font-size: var(--t-sm);
  outline: none;
  transition: border-color var(--d-fast) var(--ease);
}
.search-bar input:focus { border-color: var(--accent); }

.list { flex: 1; overflow-y: auto; padding: 0 8px 12px; }
.list-item {
  display: flex; align-items: center; gap: var(--s-3);
  padding: 10px var(--s-4);
  border-radius: var(--r-lg);
  cursor: pointer;
  transition: background var(--d-fast) var(--ease);
}
.list-item:hover { background: var(--hover); }
.list-item.active { background: var(--accent-soft); }
.list-item .info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.list-item .title {
  font-weight: 600; font-size: var(--t-base); color: var(--fg-strong);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.list-item .subtitle {
  font-size: var(--t-sm); color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.list-item .right-col { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.list-item .time { font-size: var(--t-xs); color: var(--muted); font-variant-numeric: tabular-nums; }
.list-empty {
  text-align: center; padding: 30px 20px;
  color: var(--muted); font-size: var(--t-sm);
}

.unread-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 6px;
  border-radius: var(--r-pill);
  background: var(--accent); color: var(--accent-fg);
  font-size: var(--t-xs); font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* =============== AVATAR =============== */
.avatar {
  --as: 40px;
  width: var(--as); height: var(--as);
  flex-shrink: 0; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, oklch(60% 0.06 220), oklch(45% 0.08 280));
  color: oklch(98% 0.003 250);
  font-weight: 600; font-size: calc(var(--as) * 0.4);
  text-transform: uppercase;
  position: relative; overflow: hidden;
  user-select: none;
}
.avatar.sm { --as: 28px; }
.avatar.xl { --as: 96px; font-size: 32px; }
.avatar.has-img { background: var(--surface-2); }
.avatar .av-img {
  width: 100%; height: 100%;
  border-radius: inherit; object-fit: cover; display: block;
}
.avatar.online::after {
  content: "";
  position: absolute; right: 0; bottom: 0;
  width: 28%; height: 28%; min-width: 8px; min-height: 8px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 2.5px var(--surface);
}
.avatar .status-badge {
  position: absolute; right: -2px; bottom: -2px;
  width: 32%; min-width: 16px; aspect-ratio: 1;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface-2); border-radius: 50%;
  font-size: 10px; border: 2px solid var(--bg);
}
.avatar .status-badge.image img {
  width: 100%; height: 100%; border-radius: inherit; object-fit: cover;
}

/* =============== ICON BUTTON =============== */
.icon-btn {
  width: 36px; height: 36px; border-radius: var(--r-md);
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; color: var(--muted); border: 0; cursor: pointer;
  transition: all var(--d-fast) var(--ease);
  padding: 0;
}
.icon-btn:hover { background: var(--hover); color: var(--fg); }
.icon-btn svg { width: 20px; height: 20px; }

/* =============== CHAT =============== */
.chat {
  flex: 1; display: flex; flex-direction: column;
  background: var(--chat-bg);
  min-width: 0; min-height: 0;
  overflow: hidden;
}
.chat-empty {
  flex: 1; display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
#empty-starfield {
  position: absolute; inset: 0; width: 100%; height: 100%;
  pointer-events: none; z-index: 0;
}
.placeholder {
  text-align: center; max-width: 340px;
  position: relative; z-index: 1;
}
.placeholder h2 { margin: 16px 0 6px; font-weight: 600; }
.ph-mark {
  width: 72px; height: 72px; margin: 0 auto;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  opacity: 0.7;
}

.chat-view {
  flex: 1; display: flex; flex-direction: column; min-height: 0;
}
.chat-head {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex: none;
}
.peer { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; cursor: pointer; }
.peer-name { font-weight: 600; font-size: var(--t-base); color: var(--fg-strong); }
.peer-status { font-size: var(--t-xs); color: var(--muted); }
.peer-status.online { color: var(--success); }
.head-actions { display: flex; gap: 4px; }

/* Messages stream */
.messages {
  flex: 1; overflow-y: auto;
  padding: 20px 24px; min-height: 0;
}
.msg-row {
  display: block; width: 100%; margin: 1px 0;
}
.msg-row.me { text-align: right; }
.msg-row.peer { text-align: left; }

.msg {
  display: inline-block; text-align: left;
  max-width: min(560px, 72%); width: auto;
  padding: 8px 12px 6px;
  border-radius: 16px;
  position: relative;
  line-height: 1.4; font-size: var(--t-base);
  white-space: normal; overflow-wrap: anywhere;
  word-break: normal; vertical-align: top;
  box-shadow: var(--shadow-1);
}
.msg-row.me .msg {
  background: var(--bub-mine-bg);
  color: var(--bub-mine-fg);
  border-bottom-right-radius: 4px;
}
.msg-row.peer .msg {
  background: var(--bub-them-bg);
  color: var(--bub-them-fg);
  border-bottom-left-radius: 4px;
}
.msg-row.sibling-top.me .msg { border-top-right-radius: 4px; }
.msg-row.sibling-top.peer .msg { border-top-left-radius: 4px; }

.msg .text {
  display: inline; white-space: pre-wrap;
  overflow-wrap: anywhere; word-break: normal;
}
.msg .time {
  font-size: var(--t-xs); opacity: 0.8;
  margin-left: 8px; white-space: nowrap;
  display: inline-block; vertical-align: baseline;
  position: relative; bottom: -1px;
  user-select: none; font-variant-numeric: tabular-nums;
}
.msg-row.peer .msg .time { color: var(--muted); }

.msg.image, .msg.voice { padding: 4px; }
.msg.image img {
  display: block; max-width: 320px; max-height: 360px;
  border-radius: 12px; cursor: zoom-in;
}
.msg.image .time {
  position: absolute; right: 10px; bottom: 10px;
  background: oklch(0% 0 0 / 0.55); color: oklch(99% 0.003 250);
  padding: 2px 8px; border-radius: var(--r-pill);
  margin: 0; backdrop-filter: blur(4px);
}
.msg.voice { min-width: 260px; padding: 8px 10px; }

/* Video round messages */
.msg.video {
  padding: 4px;
  background: transparent !important;
  box-shadow: none !important;
}
.msg.video video {
  display: block;
  width: 240px; height: 240px;
  border-radius: 50%;
  object-fit: cover;
  cursor: pointer;
}
.msg.video .time {
  display: block; text-align: center;
  margin-top: 4px; margin-bottom: 2px;
}
.msg.video .duration-badge {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: 28px;
  background: oklch(0% 0 0 / 0.55); color: oklch(99% 0.003 250);
  padding: 2px 8px; border-radius: var(--r-pill);
  font-size: var(--t-xs); font-variant-numeric: tabular-nums;
  backdrop-filter: blur(4px);
}

.msg.sticker {
  background: transparent !important;
  box-shadow: none !important;
  padding: 0 !important;
  border-radius: 0;
}

.edited-badge {
  font-size: var(--t-xs); font-style: italic;
  opacity: 0.7; margin-right: 4px;
}

.read-state { display: inline-flex; vertical-align: middle; margin-left: 2px; }
.read-state svg { width: 14px; height: 14px; }
.read-state.read { color: oklch(99% 0.003 250); }
.read-state.sent { opacity: 0.6; }

/* Day divider */
.day-divider {
  display: flex; justify-content: center;
  margin: 16px 0 8px;
}
.day-divider span {
  background: oklch(from var(--bg) l c h / 0.6);
  backdrop-filter: blur(4px);
  padding: 4px 12px; border-radius: var(--r-pill);
  font-size: var(--t-xs); color: var(--muted);
  border: 1px solid var(--border);
}

/* Typing indicator */
.typing {
  display: block; font-size: var(--t-xs);
  color: var(--muted); padding: 4px 10px; margin-top: 4px;
}
.typing .dots::after {
  content: "...";
  animation: blink 1.2s infinite;
}
@keyframes blink {
  0% { opacity: 0.2; } 30% { opacity: 1; } 100% { opacity: 0.2; }
}

/* =============== VOICE PLAYER =============== */
.voice-player {
  display: grid;
  grid-template-columns: 36px 1fr;
  grid-template-rows: auto auto;
  grid-template-areas: "play wave" "play meta";
  gap: 2px 10px; align-items: center; min-width: 220px;
}
.voice-play {
  grid-area: play;
  width: 36px; height: 36px; border-radius: 50%;
  border: 0; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent); color: var(--accent-fg);
  transition: background var(--d-fast) var(--ease), transform var(--d-fast) var(--ease);
  padding: 0;
}
.voice-play:hover { filter: brightness(1.1); }
.voice-play:active { transform: scale(0.94); }
.msg-row.me .voice-play { background: oklch(100% 0 0 / 0.18); color: oklch(99% 0.003 250); }
.voice-wave { grid-area: wave; height: 36px; cursor: pointer; display: flex; align-items: center; }
.voice-wave canvas { width: 100%; height: 30px; display: block; }
.voice-meta {
  grid-area: meta;
  display: flex; justify-content: space-between; align-items: center;
  font-size: var(--t-xs); opacity: 0.85; font-variant-numeric: tabular-nums;
}
.voice-meta .time { margin: 0; bottom: 0; }

/* =============== COMPOSER =============== */
.composer {
  display: flex; align-items: flex-end; gap: var(--s-2);
  padding: var(--s-3) var(--s-4);
  background: var(--surface);
  border-top: 1px solid var(--border);
  position: relative;
}
.composer textarea {
  flex: 1;
  min-height: 40px; max-height: 120px;
  padding: 10px 14px;
  background: var(--surface-2);
  color: var(--fg); border: 1px solid var(--border);
  border-radius: 22px;
  font: inherit; font-size: var(--t-base);
  resize: none; line-height: 1.4;
  outline: none;
  transition: border-color var(--d-fast) var(--ease);
}
.composer textarea:focus { border-color: var(--accent); }
.composer textarea::placeholder { color: var(--muted-2); }

.send-btn {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--accent); color: var(--accent-fg);
  border: 0; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex: none;
  transition: transform var(--d-fast) var(--ease), background var(--d-fast) var(--ease);
}
.send-btn:hover { background: var(--accent-strong); }
.send-btn:active { transform: scale(0.95); }
.send-btn svg { width: 18px; height: 18px; }

/* Send button states */
.send-btn[data-mode="mic"] .sb-send { display: none; }
.send-btn[data-mode="send"] .sb-mic { display: none; }
.send-btn:not([data-mode="send"]) .sb-send { display: none; }
.send-btn[data-mode="send"] .sb-mic { display: none; }

/* Recorder */
.recorder {
  position: absolute; left: 0; right: 0; top: 0; bottom: 0;
  background: var(--surface);
  display: flex; align-items: center; gap: 12px;
  padding: var(--s-3) var(--s-4);
  border-top: 1px solid var(--border);
}
.rec-cancel { color: var(--danger); }
.rec-live {
  flex: 1; display: flex; align-items: center; gap: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 22px; padding: 8px 14px; min-height: 40px;
}
.rec-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--danger); flex-shrink: 0;
  animation: rec-pulse 1.6s ease-in-out infinite;
}
@keyframes rec-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.82); }
}
.rec-time {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: var(--t-base); color: var(--fg); min-width: 44px;
}
.rec-wave { flex: 1; height: 28px; }
.rec-send { flex-shrink: 0; }
.rec-lock {
  position: absolute; right: 60px; bottom: 100%;
  display: flex; flex-direction: column; align-items: center;
  padding: 8px; color: var(--muted);
}

/* Reply bar */
.reply-bar {
  display: flex; align-items: center; gap: var(--s-3);
  padding: 8px 14px;
  background: var(--surface-2);
  border-top: 1px solid var(--border);
  border-left: 3px solid var(--accent);
}
.reply-bar .reply-icon { color: var(--accent); flex: none; }
.reply-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
#reply-from { font-size: var(--t-xs); font-weight: 600; color: var(--accent); }
#reply-text { font-size: var(--t-sm); color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Edit bar */
.edit-bar {
  display: flex; align-items: center; gap: var(--s-3);
  padding: 8px 14px;
  background: var(--surface-2);
  border-top: 1px solid var(--border);
  border-left: 3px solid var(--warn);
}
.edit-bar .eb-icon { color: var(--warn); flex: none; }
#edit-label { font-size: var(--t-sm); font-weight: 600; color: var(--warn); flex: 1; }

/* Sticker panel */
.sticker-panel {
  position: absolute; bottom: 100%; right: 56px;
  margin-bottom: 8px;
  width: 380px; max-height: 380px;
  background: var(--elev);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-3);
  display: flex; flex-direction: column; overflow: hidden;
}
.sticker-panel-head {
  display: flex; gap: 2px; padding: 8px 8px 4px;
  overflow-x: auto; border-bottom: 1px solid var(--border); flex: none;
}
.sticker-panel-head::-webkit-scrollbar { display: none; }
.pack-tabs { display: flex; gap: 2px; flex: 1; overflow-x: auto; }
.pack-tabs::-webkit-scrollbar { display: none; }
.sticker-grid {
  display: grid; grid-template-columns: repeat(5, 1fr);
  gap: 4px; padding: 10px; overflow-y: auto;
}

/* =============== REPLY QUOTE (in bubble) =============== */
.reply-quote {
  display: flex; gap: 8px; padding: 6px 8px; margin-bottom: 6px;
  border-left: 3px solid var(--accent-strong);
  background: oklch(0% 0 0 / 0.16);
  border-radius: var(--r-sm);
  font-size: var(--t-sm);
}
.msg-row.me .reply-quote { background: oklch(100% 0 0 / 0.12); border-left-color: oklch(100% 0 0 / 0.7); }
.reply-quote .rq-name { font-weight: 600; }
.reply-quote .rq-text { color: var(--muted); }
.msg-row.me .reply-quote .rq-text { color: oklch(99% 0.003 250 / 0.8); }

/* =============== REACTIONS =============== */
.reactions-row {
  display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px;
}
.rxn-chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: var(--r-pill);
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: var(--t-xs); font-weight: 600; color: var(--fg);
  cursor: pointer;
}
.rxn-chip.mine { background: var(--accent-soft); border-color: var(--accent); }
.rxn-chip .count { font-variant-numeric: tabular-nums; color: var(--muted); }
.rxn-chip.mine .count { color: var(--fg-strong); }

/* =============== MODAL =============== */
.modal {
  position: fixed; inset: 0;
  background: oklch(0% 0 0 / 0.55);
  backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  z-index: var(--z-modal); padding: var(--s-6);
}
.modal-card {
  width: 100%; max-width: 520px; max-height: calc(100vh - 48px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-3);
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--s-5) var(--s-5) var(--s-4);
  border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-weight: 600; font-size: var(--t-xl); }
.modal-body { padding: var(--s-5); overflow-y: auto; }

/* =============== SETTINGS OVERLAY =============== */
.settings-overlay {
  position: fixed; inset: 0;
  z-index: var(--z-overlay);
  display: flex;
  background: var(--bg);
}
.settings-bg {
  position: absolute; inset: 0; width: 100%; height: 100%;
  pointer-events: none; z-index: 0;
}
.settings-nav {
  width: 280px; flex: none;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: relative; z-index: 1;
}
.settings-nav-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--s-5) var(--s-4);
}
.settings-title { font-weight: 700; font-size: var(--t-xl); }
.settings-me {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-3) var(--s-4) var(--s-4);
}
.settings-me .me-info { flex: 1; min-width: 0; }
.settings-me .me-name { font-weight: 600; }
.settings-me .me-username { font-size: var(--t-xs); color: var(--muted); }

.settings-menu {
  display: flex; flex-direction: column; gap: 2px;
  padding: 0 var(--s-2); flex: 1; overflow-y: auto;
}
.sm-item {
  display: flex; align-items: center; gap: var(--s-3);
  padding: 10px var(--s-3); border-radius: var(--r-md);
  background: transparent; border: 0; color: var(--fg);
  font: inherit; font-size: var(--t-base); cursor: pointer;
  transition: background var(--d-fast) var(--ease);
}
.sm-item:hover { background: var(--hover); }
.sm-item.active { background: var(--accent-soft); color: var(--fg-strong); }
.sm-item svg { width: 20px; height: 20px; color: var(--muted); }
.sm-item.active svg { color: var(--fg-strong); }

.settings-content {
  flex: 1; overflow-y: auto;
  position: relative; z-index: 1;
}
.settings-pane { display: none; padding: var(--s-6); }
.settings-pane.active { display: block; }
.pane-head { margin-bottom: var(--s-5); }
.pane-head h2 { margin: 0 0 var(--s-1); font-weight: 700; font-size: var(--t-2xl); }
.pane-head p { margin: 0; }

.settings-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: var(--s-5);
}
.settings-card .field { display: flex; flex-direction: column; gap: var(--s-2); margin-bottom: var(--s-4); }
.settings-card .field label { font-size: var(--t-sm); font-weight: 600; color: var(--fg); }
.settings-card .field input,
.settings-card .field textarea {
  width: 100%; padding: 10px var(--s-3);
  background: var(--surface); color: var(--fg);
  border: 1px solid var(--border); border-radius: var(--r-md);
  font: inherit; outline: none;
  transition: border-color var(--d-fast) var(--ease);
}
.settings-card .field input:focus,
.settings-card .field textarea:focus { border-color: var(--accent); }

.pane-actions { display: flex; align-items: center; gap: var(--s-3); margin-top: var(--s-4); }

.settings-mobile-head { display: none; }
.settings-close { display: inline-flex; }

/* Banner & avatar editors */
.banner-editor { margin-bottom: var(--s-4); }
.banner-preview {
  height: 100px; border-radius: var(--r-lg);
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  margin-bottom: var(--s-3);
}
.banner-buttons { display: flex; gap: var(--s-2); }
.avatar-editor {
  display: flex; gap: var(--s-3); align-items: center;
  padding: var(--s-1) 0 var(--s-3);
}
.avatar-editor .av-buttons { display: flex; flex-direction: column; gap: var(--s-2); }

.btn-secondary {
  display: inline-flex; align-items: center; justify-content: center;
  height: 36px; padding: 0 var(--s-4);
  background: var(--surface); color: var(--fg);
  border: 1px solid var(--border); border-radius: var(--r-md);
  font: inherit; font-size: var(--t-sm); font-weight: 500;
  cursor: pointer;
  transition: background var(--d-fast) var(--ease);
}
.btn-secondary:hover { background: var(--hover); }

/* Color swatches */
.color-swatches { display: flex; gap: 8px; flex-wrap: wrap; margin-top: var(--s-1); }
.color-swatch {
  width: 28px; height: 28px; border-radius: 50%;
  cursor: pointer; border: 2px solid transparent;
  transition: transform var(--d-fast) var(--ease), border-color var(--d-fast) var(--ease);
}
.color-swatch:hover { transform: scale(1.1); }
.color-swatch.active { border-color: var(--fg); }

/* Emoji picker */
.emoji-picker { display: flex; gap: 6px; flex-wrap: wrap; margin-top: var(--s-1); }
.emoji-chip {
  background: var(--surface); border: 1px solid var(--border);
  width: 34px; height: 34px; border-radius: var(--r-md);
  font-size: 18px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.emoji-chip.active { border-color: var(--accent); background: var(--accent-soft); }

/* Status picker */
.status-picker { display: flex; gap: var(--s-3); align-items: flex-start; }
.status-image-slot {
  width: 56px; height: 56px; border-radius: var(--r-md);
  background: var(--surface); border: 1px dashed var(--border);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: var(--t-xs);
}

/* =============== TOAST =============== */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  display: inline-flex; align-items: center; gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  background: var(--elev);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-2);
  z-index: var(--z-toast);
  font-size: var(--t-sm);
  animation: toast-in 0.2s var(--ease);
}
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* =============== IMAGE VIEWER =============== */
#image-viewer {
  background: oklch(0% 0 0 / 0.92);
  cursor: zoom-out;
}
#image-viewer img {
  max-width: 96vw; max-height: 92vh;
  object-fit: contain; border-radius: var(--r-sm);
}

/* =============== PROFILE MODAL =============== */
.profile-head {
  position: relative; padding: 24px 16px 16px;
  text-align: center; overflow: hidden;
}
.profile-head::before {
  content: ""; position: absolute; inset: 0 0 auto 0;
  height: 100px;
  background: linear-gradient(135deg, var(--profile-accent, var(--accent)), var(--profile-accent-2, var(--accent-strong)));
  z-index: 0;
}
.profile-head > * { position: relative; z-index: 1; }
.profile-head .avatar { margin-top: 20px; box-shadow: 0 0 0 4px var(--surface); }
.profile-head h3 { margin: 10px 0 2px; }
.profile-head .profile-username { color: var(--muted); font-size: var(--t-sm); }
.profile-head .profile-bio {
  margin-top: 10px; color: var(--fg); font-size: var(--t-sm);
  white-space: pre-wrap; word-break: break-word;
  max-width: 360px; margin-left: auto; margin-right: auto;
}
.profile-actions {
  display: flex; gap: 8px; justify-content: center;
  padding: 0 16px 16px; border-bottom: 1px solid var(--border);
}
.profile-actions button { flex: 1; max-width: 140px; }
.profile-meta { font-size: var(--t-xs); color: var(--muted); text-align: center; padding: 8px 0; }

/* =============== CALL OVERLAY =============== */
#call-overlay {
  position: fixed; inset: 0; z-index: 300;
  display: flex; flex-direction: column;
  background:
    radial-gradient(1200px 700px at 20% 15%, oklch(40% 0.04 250 / 0.22), transparent 55%),
    radial-gradient(900px 700px at 80% 95%, oklch(50% 0.04 250 / 0.18), transparent 55%),
    oklch(14% 0.02 250);
  animation: fade-in 0.2s;
  overflow: hidden; color: oklch(99% 0.003 250);
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.call-bg { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 0; pointer-events: none; }
.call-top {
  position: relative; z-index: 2;
  display: flex; align-items: center; gap: 12px;
  padding: 14px 20px;
  padding-top: calc(14px + env(safe-area-inset-top));
}
.call-top .avatar { width: 40px; height: 40px; font-size: 14px; }
.call-top-info { flex: 1; min-width: 0; }
.call-top-info .peer-name { font-size: 16px; font-weight: 600; line-height: 1.1; }
.call-top .call-timer { font-size: var(--t-xs); color: oklch(99% 0 0 / 0.55); font-variant-numeric: tabular-nums; }
.call-top-actions { display: flex; gap: 8px; align-items: center; }

.chip-btn {
  display: inline-flex; align-items: center; gap: var(--s-2);
  height: 28px; padding: 0 var(--s-3); border-radius: var(--r-pill);
  background: oklch(100% 0 0 / 0.08); color: oklch(99% 0.003 250);
  border: 1px solid oklch(100% 0 0 / 0.08);
  font-size: var(--t-sm); font-weight: 500; cursor: pointer;
  backdrop-filter: blur(12px);
}
.chip-btn:hover { background: oklch(100% 0 0 / 0.14); }

.call-stage {
  position: relative; z-index: 1; flex: 1;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
video#call-remote-video.remote-video {
  width: 100%; height: 100%; object-fit: contain;
  background: #000; position: absolute; inset: 0;
}
.audio-only { text-align: center; padding: 20px; position: relative; z-index: 1; }
.audio-avatar-wrap { position: relative; display: inline-block; margin-bottom: 18px; }
.audio-avatar-wrap .avatar {
  width: 200px; height: 200px; font-size: 72px;
  position: relative; z-index: 2;
  box-shadow: 0 20px 60px oklch(0% 0 0 / 0.4);
}
.audio-avatar-wrap::before, .audio-avatar-wrap::after {
  content: ""; position: absolute; inset: -6px; border-radius: 50%;
  background: radial-gradient(circle, oklch(100% 0 0 / 0.18), transparent 70%); z-index: 1;
}
.call-stage.speaking .audio-avatar-wrap::before { animation: ring-pulse 1.6s ease-out infinite; }
.call-stage.speaking .audio-avatar-wrap::after { animation: ring-pulse 1.6s 0.6s ease-out infinite; }
@keyframes ring-pulse { 0% { opacity: 0.9; transform: scale(1); } 100% { opacity: 0; transform: scale(1.6); } }
.audio-name { font-size: 22px; font-weight: 700; letter-spacing: -0.3px; margin-bottom: 2px; }
.audio-sub { color: oklch(99% 0 0 / 0.55); font-size: var(--t-sm); margin-bottom: 18px; }

.call-quality-pill {
  display: inline-flex; align-items: center; gap: 8px;
  background: oklch(100% 0 0 / 0.06); border: 1px solid oklch(100% 0 0 / 0.08);
  backdrop-filter: blur(12px); padding: 6px 14px; border-radius: var(--r-pill);
  font-size: var(--t-sm); color: oklch(99% 0 0 / 0.9);
}
.call-quality { display: inline-flex; gap: 2px; align-items: flex-end; height: 12px; }
.call-quality i { display: block; width: 3px; border-radius: 1px; background: oklch(100% 0 0 / 0.3); }
.call-quality i:nth-child(1) { height: 4px; }
.call-quality i:nth-child(2) { height: 8px; }
.call-quality i:nth-child(3) { height: 12px; }
.call-quality.good i { background: var(--success); }

.call-volume {
  position: absolute; left: 20px; bottom: 20px; z-index: 4;
  display: flex; align-items: center; gap: 10px;
  background: oklch(0% 0 0 / 0.35); backdrop-filter: blur(16px);
  padding: 10px 16px; border-radius: var(--r-pill);
  color: oklch(99% 0.003 250); font-size: var(--t-sm);
  border: 1px solid oklch(100% 0 0 / 0.08);
}
.call-volume input[type="range"] {
  width: 140px; -webkit-appearance: none; appearance: none;
  background: transparent; cursor: pointer; height: 16px;
}
.call-volume input[type="range"]::-webkit-slider-runnable-track {
  height: 4px; background: linear-gradient(to right, #fff var(--vol, 66%), oklch(100% 0 0 / 0.2) var(--vol, 66%));
  border-radius: 2px;
}
.call-volume input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px;
  background: #fff; border-radius: 50%; margin-top: -5px;
  box-shadow: 0 2px 6px oklch(0% 0 0 / 0.4);
}

.pip {
  position: absolute; right: 20px; bottom: 20px;
  width: 180px; height: 240px;
  background: #000; border-radius: var(--r-xl); overflow: hidden;
  box-shadow: var(--shadow-3); border: 1px solid oklch(100% 0 0 / 0.1); z-index: 3;
}
.pip video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.pip.hidden { display: none; }
.pip-label {
  position: absolute; left: 8px; bottom: 8px;
  background: oklch(0% 0 0 / 0.55); color: oklch(99% 0.003 250);
  font-size: var(--t-xs); padding: 3px 7px; border-radius: var(--r-sm);
}

.call-footer {
  position: relative; z-index: 2;
  display: grid; grid-template-columns: 1fr auto 1fr;
  align-items: center; gap: 16px;
  padding: 20px 24px calc(24px + env(safe-area-inset-bottom));
}
.call-controls { display: flex; gap: 10px; align-items: flex-start; justify-content: center; }
.call-action {
  display: flex; flex-direction: column; align-items: center;
  gap: 6px; font-size: var(--t-xs); color: oklch(99% 0 0 / 0.7); user-select: none;
}
.call-btn {
  width: 54px; height: 54px; border-radius: 50%; border: 0; cursor: pointer;
  font-size: 20px; background: oklch(100% 0 0 / 0.1); color: oklch(99% 0.003 250);
  display: inline-flex; align-items: center; justify-content: center;
  transition: all var(--d-fast) var(--ease);
  backdrop-filter: blur(12px); border: 1px solid oklch(100% 0 0 / 0.08);
}
.call-btn:hover { background: oklch(100% 0 0 / 0.18); }
.call-btn:active { transform: scale(0.94); }
.call-btn.active { background: oklch(99% 0.003 250); color: oklch(14% 0.02 250); border-color: transparent; }
.call-btn.hangup { background: var(--danger); border-color: transparent; box-shadow: 0 8px 24px oklch(60% 0.18 25 / 0.45); }
.call-btn.hangup:hover { filter: brightness(1.1); }
.call-btn.accept { background: var(--success); border-color: transparent; box-shadow: 0 6px 18px oklch(50% 0.14 155 / 0.45); }
.call-btn[disabled] { opacity: 0.35; cursor: not-allowed; }

/* =============== MOBILE =============== */
.only-mobile { display: none; }

.mobile-tab {
  appearance: none; background: transparent; border: 0;
  color: var(--muted);
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; min-width: 0; padding: 6px;
  font: inherit; font-size: var(--t-xs); font-weight: 500; cursor: pointer;
}
.mobile-tab svg { width: 22px; height: 22px; }
.mobile-tab.active { color: var(--accent-strong); }

@media (max-width: 720px) {
  .desktop-dock { display: none; }
  .sidebar { width: 100%; min-width: 0; }

  /* Mobile: app is column — sidebar/chat take remaining space above tabbar */
  #app-screen { flex-direction: column; }
  #app-screen > .sidebar,
  #app-screen > .chat { flex: 1; min-height: 0; }

  /* Show/hide panels */
  #app-screen.show-chat .sidebar { display: none; }
  #app-screen:not(.show-chat) .chat { display: none; }

  .only-mobile { display: inline-flex; }
  .msg { max-width: 85%; }
  .modal-card { max-height: 95vh; }

  .mobile-tabbar {
    display: flex; justify-content: space-around; align-items: stretch;
    flex: none;
    padding: 6px 0 max(6px, env(safe-area-inset-bottom));
    background: var(--surface);
    border-top: 1px solid var(--border);
  }

  .side-head { padding: 10px; padding-top: calc(10px + env(safe-area-inset-top)); }
  .chat-head {
    padding: 8px 10px;
    padding-top: calc(8px + env(safe-area-inset-top));
    gap: 6px;
  }
  .chat-head .peer { gap: 8px; }
  .chat-head .peer .avatar { --as: 36px; }
  .messages { padding: 12px; }
  .composer { padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); gap: 6px; }
  .composer textarea { padding: 9px 12px; font-size: 16px; }
  .send-btn { width: 38px; height: 38px; }
  .recorder { padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); }

  .settings-overlay { flex-direction: column; }
  .settings-nav { width: 100%; border-right: 0; border-bottom: 1px solid var(--border); }
  .settings-mobile-head { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-3) var(--s-4); }
}

/* =============== THEME EDITOR =============== */
.theme-editor { display: flex; flex-direction: column; gap: var(--s-4); }
.theme-preview {
  background: var(--chat-bg); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: var(--s-4);
  display: flex; flex-direction: column; gap: var(--s-2);
}
.prev-bubble {
  padding: 8px 12px; border-radius: 14px;
  font-size: var(--t-sm); max-width: 200px;
}
.prev-bubble.peer { background: var(--bub-them-bg); color: var(--bub-them-fg); align-self: flex-start; }
.prev-bubble.me { background: var(--bub-mine-bg); color: var(--bub-mine-fg); align-self: flex-end; }
.theme-controls { display: flex; flex-direction: column; gap: var(--s-3); }
.theme-presets { display: flex; gap: var(--s-2); flex-wrap: wrap; }

/* =============== QR / 2FA =============== */
.qr-wrap {
  display: flex; gap: 12px; align-items: center;
  background: var(--surface); padding: 10px;
  border-radius: var(--r-md); margin: 10px 0;
}
.qr-wrap img {
  width: 140px; height: 140px;
  background: #fff; padding: 6px; border-radius: var(--r-md);
}
.qr-wrap code {
  font-size: var(--t-xs); word-break: break-all;
  user-select: all; color: var(--muted);
  font-family: var(--font-mono);
}

/* =============== CONTEXT MENU =============== */
.ctx-menu {
  position: fixed; z-index: var(--z-overlay);
  background: var(--elev);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-3);
  padding: 6px; min-width: 200px;
}
.ctx-item {
  display: flex; align-items: center; gap: var(--s-3);
  padding: 8px 10px; border-radius: var(--r-sm);
  font-size: var(--t-sm); color: var(--fg);
  cursor: pointer; user-select: none;
}
.ctx-item:hover { background: var(--hover); }
.ctx-item.danger { color: var(--danger); }
.ctx-item svg { width: 16px; height: 16px; color: var(--muted); }
.ctx-item.danger svg { color: var(--danger); }
