* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; -webkit-user-select: none; user-select: none; }
input, textarea, [contenteditable] { -webkit-user-select: text; user-select: text; }

:root {
  --bg: #ffffff;
  --bg-2: #f2f2f7;
  --bg-3: #e5e5ea;
  --bg-4: #d1d1d6;
  --card: #ffffff;
  --card-hover: #f2f2f7;
  --border: rgba(0,0,0,0.08);
  --border-focus: rgba(0,122,255,0.5);
  --text: #1c1c1e;
  --text-2: #3a3a3c;
  --text-3: #8e8e93;
  --accent: #007aff;
  --accent-2: #5ac8fa;
  --accent-dim: rgba(0,122,255,0.08);
  --green: #34c759;
  --green-dim: rgba(52,199,89,0.1);
  --red: #ff3b30;
  --red-dim: rgba(255,59,48,0.1);
  --yellow: #ffcc00;
  --yellow-dim: rgba(255,204,0,0.1);
  --orange: #ff9500;
  --orange-dim: rgba(255,149,0,0.1);
  --glass: rgba(249,249,249,0.94);
  --shadow: rgba(0,0,0,0.06);
  --nav-h: 50px;
  --header-h: 46px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --bg-2: #1c1c1e;
    --bg-3: #2c2c2e;
    --bg-4: #3a3a3c;
    --card: #1c1c1e;
    --card-hover: #2c2c2e;
    --border: rgba(255,255,255,0.08);
    --border-focus: rgba(10,132,255,0.6);
    --text: #f5f5f7;
    --text-2: #d1d1d6;
    --text-3: #8e8e93;
    --accent: #0a84ff;
    --accent-2: #64d2ff;
    --accent-dim: rgba(10,132,255,0.15);
    --green: #30d158;
    --green-dim: rgba(48,209,88,0.15);
    --red: #ff453a;
    --red-dim: rgba(255,69,58,0.15);
    --yellow: #ffd60a;
    --yellow-dim: rgba(255,214,10,0.15);
    --orange: #ff9f0a;
    --orange-dim: rgba(255,159,10,0.15);
    --glass: rgba(28,28,30,0.88);
    --shadow: rgba(0,0,0,0.3);
  }
}

/* In standalone PWA, iOS handles safe area natively — no extra padding */
@media (display-mode: standalone) {
  :root { --safe-b: 0px; }
}

html, body {
  font-family: -apple-system, 'SF Pro Text', 'Helvetica Neue', sans-serif;
  background: var(--bg-2);
  color: var(--text);
  height: 100%;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ═══ ICONS ═══ */
.icon { display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; }
.icon svg { width: 100%; height: 100%; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ═══ NAV ═══ */
#nav-bottom {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: calc(var(--nav-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: var(--glass);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--border);
  display: flex; z-index: 100;
}
.nav-btn {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 1px;
  background: none; border: none; color: var(--text-3);
  font-size: 10px; cursor: pointer; font-family: inherit; font-weight: 500;
  transition: color 0.15s;
}
.nav-btn.active { color: var(--accent); }
.nav-btn .icon { width: 22px; height: 22px; }
.nav-badge {
  position: absolute; top: 2px; right: 16%;
  background: var(--red); color: #fff;
  font-size: 9px; font-weight: 700;
  min-width: 16px; height: 16px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center; padding: 0 4px;
}

/* ═══ VIEWS ═══ */
.view {
  position: fixed; top: 0; left: 0; right: 0;
  bottom: calc(var(--nav-h) + var(--safe-b));
  display: none; flex-direction: column; overflow: hidden;
  padding-top: var(--safe-t);
  background: var(--bg-2);
}
.view.active { display: flex; }

.view-header {
  height: var(--header-h); min-height: var(--header-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  background: var(--glass);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--border);
  z-index: 10;
}
.view-title { font-size: 17px; font-weight: 700; }
.header-actions { display: flex; gap: 2px; }

.icon-btn {
  background: none; border: none; color: var(--accent);
  cursor: pointer; padding: 6px;
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
}
.icon-btn:active { opacity: 0.5; }
.icon-btn.danger { color: var(--red); }
.icon-btn .icon { width: 20px; height: 20px; }

/* ═══ SEARCH ═══ */
.search-bar { padding: 6px 16px 8px; background: var(--bg-2); }
.search-bar input {
  width: 100%; padding: 8px 12px 8px 32px;
  background: var(--bg-3); border: none;
  border-radius: 10px; color: var(--text);
  font-size: 15px; font-family: inherit; outline: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='%238e8e93' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.3-4.3'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: 10px center;
}
.search-bar input::placeholder { color: var(--text-3); }

/* ═══ FILTERS ═══ */
.filter-bar {
  display: flex; gap: 6px; padding: 4px 16px 8px;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  background: var(--bg-2); flex-shrink: 0;
}
.filter-bar::-webkit-scrollbar { display: none; }
.filter-chip {
  flex-shrink: 0; padding: 6px 14px;
  border-radius: 16px; font-size: 13px;
  font-weight: 500; font-family: inherit; border: none;
  background: var(--card); color: var(--text-2);
  cursor: pointer; white-space: nowrap;
  box-shadow: 0 0.5px 1px var(--shadow);
}
.filter-chip.active { background: var(--accent); color: #fff; }
.filter-chip .count { opacity: 0.6; margin-left: 2px; }

/* ═══ CONVERSATION LIST ═══ */
.conversation-list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; background: var(--card); }

.conv-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  border-bottom: 0.5px solid var(--border);
  cursor: pointer;
}
.conv-item:active { background: var(--bg-2); }
.conv-item.unread { background: rgba(0,122,255,0.04); }

.conv-avatar {
  width: 44px; height: 44px; border-radius: 22px;
  background: var(--bg-2);
  display: flex; align-items: center; justify-content: center;
  font-size: 17px; flex-shrink: 0; color: var(--text-2); font-weight: 600;
}
.conv-info { flex: 1; min-width: 0; }
.conv-name { font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.stage-dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.conv-preview { font-size: 13px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
.conv-tags { display: flex; gap: 4px; margin-top: 3px; }
.conv-tag { font-size: 10px; padding: 1px 6px; border-radius: 4px; background: var(--bg-2); color: var(--text-3); font-weight: 500; }
.conv-score {
  display: inline-flex; font-size: 11px; font-weight: 700;
  padding: 1px 5px; border-radius: 4px; margin-left: auto;
}
.conv-score.hot { background: var(--red-dim); color: var(--red); }
.conv-score.warm { background: var(--orange-dim); color: var(--orange); }
.conv-score.cold { background: var(--accent-dim); color: var(--accent); }
.conv-meta { text-align: right; flex-shrink: 0; }
.conv-time { font-size: 11px; color: var(--text-3); }
.conv-unread {
  background: var(--accent); color: #fff; font-size: 11px; font-weight: 700;
  min-width: 20px; height: 20px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  margin-top: 4px; margin-left: auto;
}
.conv-cold { font-size: 11px; color: var(--orange); margin-top: 2px; font-weight: 500; }

/* ═══ CHAT ═══ */
#view-chat { bottom: 0 !important; padding-top: var(--safe-t); background: var(--bg-2); z-index: 1000; }
.chat-header {
  height: var(--header-h); min-height: var(--header-h);
  display: flex; align-items: center; gap: 8px; padding: 0 6px;
  background: var(--glass);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--border);
}
.chat-header-info { flex: 1; min-width: 0; }
.chat-name { font-size: 15px; font-weight: 600; }
.chat-stage { font-size: 11px; color: var(--text-3); }

.messages-container {
  flex: 1; overflow-y: auto; padding: 6px 8px;
  display: flex; flex-direction: column;
  -webkit-overflow-scrolling: touch;
  background: var(--bg-2);
}

/* ── Date separator ── */
.date-sep {
  align-self: center; margin: 12px 0 6px;
  padding: 4px 12px; border-radius: 16px;
  background: var(--bg-3);
  font-size: 12px; font-weight: 600; color: var(--text-3);
  user-select: none;
}

/* ── Message bubbles ── */
.msg {
  max-width: 78%; padding: 7px 11px 4px;
  font-size: 15px; line-height: 1.35;
  word-break: break-word; position: relative;
  animation: msgIn 0.15s ease;
}
@keyframes msgIn { from { opacity:0; transform:translateY(4px); } }

/* Incoming */
.msg.in {
  align-self: flex-start;
  background: var(--card);
  border-radius: 18px 18px 18px 6px;
  box-shadow: 0 0.5px 1px rgba(0,0,0,0.06);
  margin-right: 48px;
}
/* Outgoing */
.msg.out {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-radius: 18px 18px 6px 18px;
  margin-left: 48px;
}

/* ── Message grouping ── */
.msg { margin-top: 1px; }
.msg.group-first { margin-top: 6px; }
.msg.in.group-mid, .msg.in.group-last { border-radius: 6px 18px 18px 6px; }
.msg.out.group-mid, .msg.out.group-last { border-radius: 18px 6px 6px 18px; }
.msg.in.group-first { border-radius: 18px 18px 18px 6px; }
.msg.out.group-first { border-radius: 18px 18px 6px 18px; }
.msg.in.group-single { border-radius: 18px 18px 18px 6px; }
.msg.out.group-single { border-radius: 18px 18px 6px 18px; }


/* ── Message content ── */
.msg-text { white-space: pre-wrap; }
.msg-text a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.msg.in .msg-text a { color: var(--accent); }

/* ── Meta row (time + checkmarks + edited) ── */
.msg-meta {
  display: flex; align-items: center; justify-content: flex-end;
  gap: 3px; margin-top: 2px;
  font-size: 11px; opacity: 0.5;
  user-select: none; white-space: nowrap;
}
.msg.in .msg-meta { justify-content: flex-start; }
.msg-edited { font-style: italic; margin-right: 2px; }
.msg-checks { font-size: 13px; letter-spacing: -3px; }
.msg-checks.read { color: #34c759; opacity: 1; }
.msg.out .msg-checks.read { color: rgba(255,255,255,0.85); }

/* ── Reply preview ── */
.msg-reply {
  padding: 5px 10px; margin-bottom: 4px;
  border-left: 3px solid rgba(255,255,255,0.5);
  border-radius: 4px;
  background: rgba(255,255,255,0.12);
  font-size: 13px; line-height: 1.3;
  cursor: pointer; max-height: 42px; overflow: hidden;
}
.msg.in .msg-reply {
  border-left-color: var(--accent);
  background: rgba(0,122,255,0.06);
  color: var(--text-2);
}
.msg-reply-name { font-weight: 600; font-size: 12px; margin-bottom: 1px; }
.msg.out .msg-reply-name { color: rgba(255,255,255,0.8); }
.msg.in .msg-reply-name { color: var(--accent); }

/* ── Voice message waveform ── */
.voice-player {
  display: flex; align-items: center; gap: 8px;
  min-width: 180px; padding: 2px 0;
}
.voice-play-btn {
  width: 32px; height: 32px; border-radius: 16px;
  background: rgba(255,255,255,0.2); border: none;
  color: inherit; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; font-size: 14px;
}
.msg.in .voice-play-btn { background: rgba(0,0,0,0.06); }
.voice-bars {
  display: flex; align-items: center; gap: 1.5px;
  flex: 1; height: 28px;
}
.voice-bar {
  width: 3px; border-radius: 1.5px;
  background: rgba(255,255,255,0.35);
  transition: background 0.1s;
}
.voice-bar.played { background: rgba(255,255,255,0.9); }
.msg.in .voice-bar { background: rgba(0,0,0,0.12); }
.msg.in .voice-bar.played { background: var(--accent); }
.voice-duration { font-size: 11px; flex-shrink: 0; opacity: 0.6; }

/* ── Media in bubbles ── */
.msg-media-img {
  max-width: 100%; border-radius: 12px;
  display: block; margin-bottom: 4px;
  cursor: pointer;
}
.msg-media-video {
  max-width: 100%; border-radius: 12px;
  display: block; margin-bottom: 4px;
}

/* ── Deleting animation ── */
.msg.deleting { animation: msgOut 0.2s ease forwards; }
@keyframes msgOut { to { opacity:0; transform:scale(0.9); height:0; padding:0; margin:0; } }

/* ── Action sheet (long press) ── */
.msg-action-sheet {
  position: absolute; top: -4px; right: 0;
  transform: translateY(-100%);
  background: var(--card);
  border-radius: 12px; overflow: hidden;
  box-shadow: 0 4px 24px rgba(0,0,0,0.18);
  animation: sheetIn 0.12s ease; z-index: 10;
  min-width: 200px;
}
@keyframes sheetIn { from { opacity:0; transform:translateY(-90%) scale(0.95); } }
.msg.in .msg-action-sheet { left: 0; right: auto; }
.msg-action-btn {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 12px 16px; background: none; border: none;
  font-size: 15px; font-family: inherit; font-weight: 500;
  color: var(--text); text-align: left; cursor: pointer;
  border-bottom: 0.5px solid var(--border);
}
.msg-action-btn:last-child { border: none; }
.msg-action-btn:active { background: var(--bg-2); }
.msg-action-btn .action-icon { font-size: 18px; width: 22px; text-align: center; }
.msg-action-danger { color: var(--red); }

/* ── Scroll-to-bottom FAB ── */
.scroll-fab {
  position: absolute; bottom: 80px; right: 16px;
  width: 40px; height: 40px; border-radius: 20px;
  background: var(--card); border: none;
  box-shadow: 0 2px 12px rgba(0,0,0,0.15);
  display: none; align-items: center; justify-content: center;
  cursor: pointer; z-index: 20;
  color: var(--text-3); font-size: 18px;
  transition: transform 0.15s;
}
.scroll-fab:active { transform: scale(0.9); }
.scroll-fab.visible { display: flex; }
.scroll-fab-badge {
  position: absolute; top: -4px; right: -4px;
  background: var(--accent); color: #fff;
  font-size: 10px; font-weight: 700;
  min-width: 18px; height: 18px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 4px;
}

/* ── Reply bar (above input) ── */
.reply-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px; background: var(--card);
  border-top: 0.5px solid var(--border);
  border-left: 3px solid var(--accent);
  animation: slideUp 0.15s ease;
}
.reply-bar-content { flex: 1; min-width: 0; }
.reply-bar-name { font-size: 12px; font-weight: 600; color: var(--accent); }
.reply-bar-text { font-size: 13px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reply-bar-close {
  width: 28px; height: 28px; border-radius: 14px;
  background: var(--bg-2); border: none;
  color: var(--text-3); cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
}

/* ═══ QUICK BAR ═══ */
.quick-bar {
  display: flex; gap: 6px; padding: 8px 12px;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  background: var(--bg-2); border-top: 0.5px solid var(--border); flex-shrink: 0;
}
.quick-bar::-webkit-scrollbar { display: none; }
.quick-chip {
  flex-shrink: 0; padding: 7px 14px;
  border-radius: 16px; font-size: 13px;
  font-weight: 500; font-family: inherit;
  background: var(--card); border: none;
  color: var(--accent); cursor: pointer;
  white-space: nowrap; box-shadow: 0 0.5px 1px rgba(0,0,0,0.06);
}
.quick-chip:active { background: var(--accent); color: #fff; transform: scale(0.95); }

.chat-toolbar {
  display: flex; gap: 6px; padding: 6px 12px;
  background: var(--bg-2);
}
.toolbar-btn {
  padding: 6px 12px; border-radius: 16px;
  background: var(--card); border: none;
  color: var(--text-3); font-size: 12px; font-family: inherit;
  font-weight: 500; cursor: pointer;
  display: flex; align-items: center; gap: 4px;
  box-shadow: 0 0.5px 1px rgba(0,0,0,0.06);
}
.toolbar-btn:active { background: var(--accent); color: #fff; }
.toolbar-btn .icon { width: 14px; height: 14px; }

/* Panels */
.panel-overlay { position: absolute; inset: 0; background: rgba(0,0,0,0.3); z-index: 1049; display: none; }
.slide-panel {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: var(--card); border-radius: 12px 12px 0 0;
  max-height: 55vh; overflow-y: auto; z-index: 1050;
  animation: slideUp 0.25s ease; display: none;
  padding-bottom: var(--safe-b);
  box-shadow: 0 -4px 20px rgba(0,0,0,0.1);
}
@keyframes slideUp { from { transform: translateY(100%); } }
.panel-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 16px; font-weight: 600; font-size: 14px;
  border-bottom: 0.5px solid var(--border);
  position: sticky; top: 0; background: var(--card); z-index: 1;
}
.panel-item {
  padding: 13px 16px; border-bottom: 0.5px solid var(--border);
  cursor: pointer; font-size: 15px;
}
.panel-item:active { background: var(--bg-2); }
.panel-item.active { background: var(--accent-dim); }
.panel-item-label { font-weight: 500; }
.panel-item-sub { font-size: 12px; color: var(--text-3); margin-top: 2px; }

/* Input */
.chat-input-area {
  display: flex; align-items: flex-end; gap: 6px;
  padding: 10px 14px;
  padding-bottom: calc(4px + var(--safe-b));
  background: var(--glass);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  border-top: 0.5px solid var(--border);
}

/* Voice recording */
.recording-indicator {
  display: flex; align-items: center; gap: 8px;
  flex: 1; padding: 9px 14px;
  background: var(--red-dim); border-radius: 20px;
  font-size: 14px; color: var(--red); font-weight: 500;
}
.recording-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--red); animation: recPulse 1s infinite;
}
@keyframes recPulse { 0%,100% { opacity:1; transform: scale(1); } 50% { opacity:0.4; transform: scale(0.8); } }
.recording-timer { font-variant-numeric: tabular-nums;
}
.rec-overlay {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px;
  background: var(--red-dim);
  font-size: 14px; color: var(--red); font-weight: 500;
  border-bottom: 0.5px solid var(--border);
  animation: slideUp 0.15s ease;
}
.rec-timer { font-variant-numeric: tabular-nums; }
.mic-btn {
  width: 34px; height: 34px; border-radius: 17px;
  background: var(--bg-2); border: none; color: var(--accent);
  cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.mic-btn:active, .mic-btn.recording { background: var(--red); color: #fff; transform: scale(1.15);
}
.mic-btn .icon { width: 18px; height: 18px; }
#chat-input {
  flex: 1; padding: 9px 14px;
  background: var(--bg-2); border: 0.5px solid var(--border);
  border-radius: 20px; color: var(--text);
  font-size: 15px; font-family: inherit;
  resize: none; outline: none; max-height: 100px; line-height: 1.35;
}
#chat-input:focus { border-color: var(--border-focus); }
#chat-input::placeholder { color: var(--text-3); }
.send-btn {
  width: 34px; height: 34px; border-radius: 17px;
  background: var(--accent); border: none; color: #fff;
  cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.send-btn:active { transform: scale(0.9); }
.send-btn .icon { width: 16px; height: 16px; }

/* ═══ DETAIL ═══ */
.detail-content { flex: 1; overflow-y: auto; padding: 20px 16px; padding-bottom: calc(20px + var(--safe-b)); }
.detail-avatar {
  width: 72px; height: 72px; border-radius: 36px;
  background: var(--bg-3); margin: 0 auto 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 28px; font-weight: 700;
}
.detail-name { text-align: center; font-size: 22px; font-weight: 700; }
.detail-username { text-align: center; font-size: 14px; color: var(--text-3); margin-top: 2px; }
.detail-section { margin-top: 16px; background: var(--card); border-radius: 12px; overflow: hidden; }
.detail-section h4 { font-size: 12px; color: var(--text-3); padding: 12px 16px 6px; text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600; }
.detail-field { display: flex; justify-content: space-between; padding: 12px 16px; border-bottom: 0.5px solid var(--border); font-size: 15px; }
.detail-field:last-child { border: none; }
.detail-field-label { color: var(--text-3); }
.detail-field-value { font-weight: 500; }
.detail-notes { width: 100%; min-height: 60px; padding: 12px 16px; background: transparent; border: none; color: var(--text); font-size: 15px; font-family: inherit; resize: vertical; outline: none; }
.detail-tags { display: flex; gap: 6px; flex-wrap: wrap; padding: 8px 16px 12px; }
.detail-tag { padding: 4px 10px; border-radius: 6px; font-size: 12px; font-weight: 600; }
.lead-score-badge { display: inline-flex; padding: 5px 12px; border-radius: 8px; font-size: 14px; font-weight: 700; }

/* ═══ STATS ═══ */
.stats-scroll { flex: 1; overflow-y: auto; padding: 12px 16px; padding-bottom: calc(16px + var(--safe-b)); }
.stats-period { display: flex; gap: 0; padding: 0 0 14px; background: var(--bg-3); border-radius: 8px; overflow: hidden; }
.period-chip {
  flex: 1; padding: 7px 0; font-size: 13px; font-weight: 600;
  font-family: inherit; background: transparent; border: none;
  color: var(--text-3); cursor: pointer; text-align: center;
}
.period-chip.active { background: var(--accent); color: #fff; border-radius: 6px; margin: 2px; }
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.stat-card { background: var(--card); border-radius: 12px; padding: 14px; box-shadow: 0 0.5px 1px rgba(0,0,0,0.04); }
.stat-value { font-size: 26px; font-weight: 800; }
.stat-label { font-size: 12px; color: var(--text-3); margin-top: 2px; font-weight: 500; }
.chart-card { background: var(--card); border-radius: 12px; padding: 14px; margin-bottom: 10px; box-shadow: 0 0.5px 1px rgba(0,0,0,0.04); }
.chart-card h3 { font-size: 14px; font-weight: 600; margin-bottom: 10px; }
.chart-card canvas { width: 100% !important; max-height: 200px; }
.pipeline-bar { display: flex; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 0.5px solid var(--border); font-size: 14px; }
.pipeline-bar:last-child { border: none; }
.pipeline-bar-name { flex: 1; }
.pipeline-bar-fill { width: 60px; height: 4px; border-radius: 2px; background: var(--bg-3); overflow: hidden; }
.pipeline-bar-fill-inner { height: 100%; border-radius: 2px; }
.pipeline-bar-count { font-weight: 700; font-size: 15px; width: 30px; text-align: right; }

/* ═══ SETTINGS ═══ */
.settings-content { flex: 1; overflow-y: auto; padding: 8px 16px; padding-bottom: calc(16px + var(--safe-b)); }
.settings-section { background: var(--card); border-radius: 12px; overflow: hidden; margin-bottom: 10px; }
.settings-section h3 { font-size: 12px; color: var(--text-3); padding: 12px 16px 4px; text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600; }
.settings-desc { font-size: 13px; color: var(--text-3); padding: 4px 16px 8px; line-height: 1.4; }
.tg-status { display: flex; align-items: center; gap: 8px; padding: 4px 16px 10px; font-size: 13px; color: var(--text-3); }
.dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.dot-red { background: var(--red); }
.dot-green { background: var(--green); animation: pulse 2s infinite; }
@keyframes pulse { 0%,100% { opacity:1; } 50% { opacity:0.4; } }
.settings-item { padding: 12px 16px; border-bottom: 0.5px solid var(--border); font-size: 15px; }
.settings-item:last-child { border: none; }
.settings-item-label { font-weight: 500; }
.settings-item-sub { font-size: 12px; color: var(--text-3); margin-top: 2px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 18px; border-radius: 10px; font-size: 15px;
  font-weight: 600; font-family: inherit; border: none; cursor: pointer; margin: 8px 16px;
}
.btn:active { opacity: 0.7; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-secondary { background: var(--bg-2); color: var(--accent); }
.btn-danger { background: var(--red-dim); color: var(--red); }

/* ═══ MODAL ═══ */
.modal-overlay {
  position: fixed; inset: 0; z-index: 1100;
  background: rgba(0,0,0,0.3); display: none;
  align-items: flex-end; justify-content: center;
}
.modal {
  width: 100%; max-width: 480px; max-height: 85vh;
  background: var(--card); border-radius: 14px 14px 0 0;
  padding: 20px 16px; padding-bottom: calc(20px + var(--safe-b));
  overflow-y: auto; animation: slideUp 0.25s ease;
}
.modal-header { font-size: 18px; font-weight: 700; margin-bottom: 16px; }
.modal-body { margin-bottom: 16px; }
.modal-body input, .modal-body textarea, .modal-body select {
  width: 100%; padding: 12px 14px; margin-bottom: 10px;
  background: var(--bg-2); border: 0.5px solid var(--border);
  border-radius: 10px; color: var(--text);
  font-size: 15px; font-family: inherit; outline: none;
}
.modal-body input:focus, .modal-body textarea:focus { border-color: var(--accent); }
.modal-body textarea { min-height: 80px; resize: vertical; }
.modal-body label { display: block; font-size: 12px; color: var(--text-3); margin-bottom: 4px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.3px; }
.modal-actions { display: flex; gap: 10px; }
.modal-actions .btn { flex: 1; text-align: center; margin: 0; padding: 13px; border-radius: 12px; }

/* ═══ EMPTY ═══ */
.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 60px 24px; color: var(--text-3); }
.empty-state .icon { width: 48px; height: 48px; margin-bottom: 14px; opacity: 0.3; }
.empty-text { font-size: 16px; font-weight: 600; }
.empty-sub { font-size: 13px; margin-top: 4px; }

/* ═══ MEDIA PANEL ═══ */
.media-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 10px 16px; }
.media-item {
  background: var(--bg-2); border-radius: 10px; padding: 12px;
  cursor: pointer; text-align: center; font-size: 12px;
  color: var(--text-2); font-weight: 500;
}
.media-item:active { background: var(--accent-dim); }
.media-item .media-icon { font-size: 24px; margin-bottom: 4px; }
.media-item .media-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ═══ TOAST NOTIFICATION ═══ */
.toast {
  position: fixed; bottom: calc(70px + var(--safe-b)); left: 50%;
  transform: translateX(-50%) translateY(20px); opacity: 0;
  background: var(--text); color: var(--bg); padding: 10px 20px;
  border-radius: 20px; font-size: 14px; font-weight: 500;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2); z-index: 9999;
  transition: all 0.25s ease; pointer-events: none;
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ═══ PULL-TO-REFRESH ═══ */
.pull-indicator {
  display: flex; align-items: center; justify-content: center;
  height: 0; overflow: hidden; transition: height 0.2s ease;
  color: var(--text-3); font-size: 13px; font-weight: 500;
}
.pull-indicator.pulling { height: 40px; }
.pull-indicator.refreshing { height: 40px; }
.pull-spinner {
  width: 18px; height: 18px; border: 2px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin 0.6s linear infinite; margin-right: 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ═══ RELANCE BUTTON (in contact list) ═══ */
.conv-relance {
  display: flex; align-items: center; gap: 4px;
  padding: 5px 12px; margin-top: 4px;
  border-radius: 12px; border: none;
  background: var(--orange-dim); color: var(--orange);
  font-size: 12px; font-weight: 600; font-family: inherit;
  cursor: pointer; width: fit-content;
  transition: all 0.15s;
}
.conv-relance:active { background: var(--orange); color: #fff; transform: scale(0.95); }
.conv-relance.urgent {
  padding: 7px 16px;
  font-size: 14px;
  font-weight: 700;
  background: var(--red-dim); color: var(--red);
  border-radius: 14px;
  animation: pulseUrgent 2s infinite;
}
.conv-relance.urgent:active { background: var(--red); color: #fff; }
@keyframes pulseUrgent { 0%,100% { box-shadow: 0 0 0 0 rgba(255,59,48,0.3); } 50% { box-shadow: 0 0 0 6px rgba(255,59,48,0); } }

/* ═══ QUICK ACTIONS BAR ═══ */
.quick-actions {
  display: flex; gap: 6px; padding: 6px 12px;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  flex-shrink: 0;
}
.quick-actions::-webkit-scrollbar { display: none; }
.quick-action-btn {
  flex-shrink: 0; padding: 6px 14px;
  border-radius: 14px; font-size: 12px;
  font-weight: 600; font-family: inherit;
  background: var(--card); border: none;
  color: var(--text-2); cursor: pointer;
  white-space: nowrap; box-shadow: 0 0.5px 1px rgba(0,0,0,0.06);
  transition: all 0.15s;
}
.quick-action-btn:active { transform: scale(0.95); }
.quick-action-btn.active { background: var(--accent); color: #fff; }
.quick-action-btn .qa-count {
  display: inline-block; min-width: 16px; height: 16px;
  line-height: 16px; text-align: center; border-radius: 8px;
  font-size: 10px; font-weight: 700; margin-left: 4px;
  background: rgba(0,0,0,0.08);
}
.quick-action-btn.active .qa-count { background: rgba(255,255,255,0.3); }

/* ═══ DESKTOP ═══ */
@media (min-width: 768px) {
  #nav-bottom { left: 0; right: auto; top: 0; bottom: 0; width: 72px; height: 100%; flex-direction: column; padding: 16px 0 calc(16px + var(--safe-b)); border-top: none; border-right: 0.5px solid var(--border); }
  .view { left: 72px; bottom: 0; }
  #view-chat { left: 72px; }
  .nav-btn { flex: none; padding: 14px 0; }
  .stats-grid { grid-template-columns: repeat(4, 1fr); }
  .msg { max-width: 50%; }
}
