/* ═══════════════════════ SEXT-AI — MATCHING QT APP EXACTLY ═══════════════════════ */

:root {
  --bg-app: #111b21;
  --bg-chat: #0b141a;
  --bg-sidebar: #111b21;
  --bg-header: #1f2c34;
  --bg-input-pill: #2a3942;
  --bg-bubble-out: #005c4b;
  --bg-bubble-in: #202c33;
  --bg-bubble-system: rgba(255, 255, 255, 0.05);
  --bg-hover: #202c33;
  --bg-active: #2a3942;
  --bg-search: #202c33;
  --bg-modal: #1f2c34;
  --bg-menu: #233138;
  --bg-nav: #0B1014;

  --text-primary: #e9edef;
  --text-secondary: #8696a0;
  --text-bubble: #e9edef;
  --text-time: rgba(255, 255, 255, 0.45);
  --text-time-out: rgba(255, 255, 255, 0.55);
  --text-unread: #00a884;
  --text-system: #8696a0;

  --accent: #00a884;
  --accent-hover: #06cf9c;
  --receipt-blue: #53bdeb;
  --danger: #ea4335;

  --border: #2a3942;
  --border-light: rgba(134, 150, 160, 0.15);
  --divider: #222d34;

  --header-h: 56px;
  --avatar-sm: 40px;
  --avatar-list: 50px;
  --avatar-lg: 80px;

  --radius: 8px;
  --radius-bubble: 7.5px;
  --radius-round: 50%;
  --radius-pill: 21px;

  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-size: 15px;
  --font-size-sm: 12px;
  --font-size-xs: 11px;
  --transition: 150ms ease;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 4px 20px rgba(0, 0, 0, 0.5);

  /* CSS filter that produces approx #8696a0 tint on white PNGs */
  --icon-tint: brightness(0) saturate(100%) invert(60%) sepia(6%) saturate(614%) hue-rotate(167deg) brightness(92%) contrast(88%);
  --icon-tint-accent: brightness(0) saturate(100%) invert(60%) sepia(70%) saturate(500%) hue-rotate(120deg) brightness(95%) contrast(90%);
}

/* ═══════════════════════ RESET ═══════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: var(--font), "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
  font-size: var(--font-size);
  color: var(--text-primary);
  background: var(--bg-app);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
input, textarea, button, select { font: inherit; color: inherit; border: none; outline: none; background: none; }
button { cursor: pointer; }
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-thumb { background: rgba(134, 150, 160, 0.25); border-radius: 2px; }

/* ═══════════════════════ APP / VIEW SYSTEM ═══════════════════════ */
#app {
  width: 100%;
  height: 100vh;
  height: 100dvh;
  height: var(--vh, 100vh);
  position: relative;
  overflow: hidden;
  background: var(--bg-app);
}
.view {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg-app);
  transform: translateX(100%);
  transition: transform 0.25s ease;
  z-index: 1;
  overflow: hidden;
}
.view.active { transform: translateX(0); z-index: 2; }

/* ═══════════════════════ CONNECTION BANNER ═══════════════════════ */
.banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  padding: 6px 16px;
  background: #f0b429; color: #1a1a1a;
  text-align: center; font-size: var(--font-size-sm); font-weight: 500;
  transition: transform 0.3s ease;
}
.banner.hidden { transform: translateY(-100%); }
.banner.error { background: var(--danger); color: white; }
.banner.connected { background: var(--accent); color: white; animation: bannerFade 2s forwards; }
@keyframes bannerFade { 0%,70% { transform: translateY(0); } 100% { transform: translateY(-100%); } }

/* ═══════════════════════ TOPBAR ═══════════════════════ */
.topbar {
  height: var(--header-h);
  background: var(--bg-header);
  display: flex; align-items: center;
  padding: 0 6px;
  flex-shrink: 0;
  z-index: 5;
}
.topbar-list { padding: 0 16px 0 16px; }
.topbar-title {
  font-size: 20px; font-weight: 600;
  flex: 1;
  letter-spacing: -0.3px;
}
.topbar-info {
  flex: 1;
  display: flex; flex-direction: column;
  gap: 1px;
  padding-left: 10px;
  min-width: 0;
}
.topbar-name {
  font-size: 16px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar-subtitle {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar-subtitle.online { color: var(--accent); }
.topbar-subtitle.typing-anim { color: var(--accent); animation: typingPulse 1.2s ease-in-out infinite; }
@keyframes typingPulse { 0%,100% { opacity: 1; } 50% { opacity: 0.5; } }
.topbar-actions { display: flex; gap: 0; }

/* ═══════════════════════ ICON BUTTONS ═══════════════════════ */
.icon-btn {
  width: 40px; height: 40px;
  border-radius: var(--radius-round);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background var(--transition);
}
.icon-btn:active { background: rgba(255, 255, 255, 0.08); }
.icon {
  width: 22px; height: 22px;
  object-fit: contain;
  filter: var(--icon-tint);
}
.icon-back { /* rotation via inline style on img */ }
.kebab-over-budget.over-budget .icon { filter: brightness(0) saturate(100%) invert(72%) sepia(98%) saturate(500%); }

/* ═══════════════════════ SEARCH BAR ═══════════════════════ */
.search-bar { padding: 8px 16px; background: var(--bg-sidebar); }
.search-wrapper {
  display: flex; align-items: center;
  background: var(--bg-search);
  border-radius: 20px;
  padding: 0 12px; height: 38px;
}
.search-icon {
  width: 18px; height: 18px;
  margin-right: 10px;
  filter: var(--icon-tint);
}
#search-input {
  flex: 1; height: 100%; background: transparent;
  font-size: 14px; color: var(--text-secondary);
}
#search-input::placeholder { color: var(--text-secondary); font-size: 14px; }

/* ═══════════════════════ FILTER BAR (All / Unread / Favorites / Groups) ═══════════════════════ */
.filter-bar {
  display: flex; gap: 8px;
  padding: 4px 16px;
  background: var(--bg-sidebar);
  height: 44px;
  align-items: center;
}
.filter-pill {
  padding: 6px 14px;
  border-radius: 14px;
  font-size: 13px; font-weight: 500;
  color: var(--text-primary);
  background: transparent;
  border: 1px solid var(--border);
  transition: all var(--transition);
}
.filter-pill.active {
  background: var(--accent);
  color: #111b21;
  border-color: var(--accent);
}
.filter-plus {
  width: 28px; height: 28px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; color: var(--text-secondary);
  border: 1px solid var(--border);
  flex-shrink: 0;
}

/* ═══════════════════════ ARCHIVED ROW ═══════════════════════ */
.archived-row {
  display: flex; align-items: center;
  gap: 14px;
  padding: 0 18px;
  height: 52px;
  background: var(--bg-sidebar);
  font-size: 16px; color: var(--text-primary);
}
.archived-icon {
  width: 24px; height: 24px;
  filter: var(--icon-tint);
}

/* Divider */
.divider {
  height: 1px;
  background: var(--divider);
}

/* ═══════════════════════ CONTACT LIST ═══════════════════════ */
.contact-list { flex: 1; overflow-y: auto; background: var(--bg-sidebar); }

.contact-row {
  display: flex; align-items: center;
  padding: 10px 16px; gap: 14px;
  cursor: pointer; position: relative;
  transition: background var(--transition);
}
.contact-row:active { background: var(--bg-hover); }
.contact-row.active { background: var(--bg-active); }
.contact-row::after {
  content: '';
  position: absolute;
  bottom: 0; left: 78px; right: 16px;
  height: 1px;
  background: var(--border-light);
}

.avatar-list {
  width: var(--avatar-list); height: var(--avatar-list);
  border-radius: var(--radius-round);
  background: var(--bg-active);
  flex-shrink: 0;
  overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  position: relative;
}
.avatar-list img {
  width: 100%; height: 100%; object-fit: cover; border-radius: inherit;
}
.avatar-fallback {
  width: 100%; height: 100%;
  display: none; align-items: center; justify-content: center;
  font-size: 20px; color: var(--text-secondary);
  background: var(--bg-active);
}
.avatar-sm {
  width: var(--avatar-sm); height: var(--avatar-sm);
  border-radius: var(--radius-round);
  background: var(--bg-active);
  flex-shrink: 0;
  overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  position: relative;
}
.avatar-sm img {
  width: 100%; height: 100%; object-fit: cover; border-radius: inherit;
}
.avatar-sm .avatar-fallback { font-size: 16px; }
.avatar-lg {
  width: var(--avatar-lg); height: var(--avatar-lg);
  border-radius: var(--radius-round);
  background: var(--bg-active);
  overflow: hidden; margin: 0 auto 16px;
  display: flex; align-items: center; justify-content: center;
  position: relative;
}
.avatar-lg img {
  width: 100%; height: 100%; object-fit: cover; border-radius: inherit;
}
.avatar-lg .avatar-fallback { font-size: 32px; }

.contact-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.contact-name {
  font-size: 16px; font-weight: 400; color: var(--text-primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.contact-preview {
  font-size: 14px; color: var(--text-secondary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.contact-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; flex-shrink: 0; }
.contact-time { font-size: var(--font-size-xs); color: var(--text-secondary); }
.contact-time.unread { color: var(--text-unread); }
.unread-badge {
  background: var(--accent); color: white;
  font-size: 11px; font-weight: 600;
  min-width: 20px; height: 20px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center; padding: 0 5px;
}
.pin-icon {
  width: 14px; height: 14px; object-fit: contain;
  filter: var(--icon-tint);
}

/* ═══════════════════════ FAB ═══════════════════════ */
.fab {
  position: absolute; bottom: 76px; right: 16px;
  width: 56px; height: 56px;
  border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  z-index: 5;
  background: transparent;
}
.fab-icon { width: 56px; height: 56px; border-radius: 16px; }

/* ═══════════════════════ BOTTOM NAVIGATION (matches Qt: #0B1014 bg, 4 tabs) ═══════════════════════ */
.bottom-nav {
  background: var(--bg-nav);
  display: flex;
  border-top: 1px solid var(--bg-nav);
  flex-shrink: 0;
  height: 60px;
}
.nav-tab {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 2px;
  font-size: 12px; font-weight: 400;
  color: var(--text-secondary);
  padding: 4px 0;
  transition: color var(--transition);
  background: transparent;
}
.nav-tab.active { color: var(--accent); }
.nav-icon {
  width: 26px; height: 26px;
  object-fit: contain;
  filter: brightness(0) saturate(100%) invert(93%) sepia(3%) saturate(30%) hue-rotate(169deg) brightness(107%) contrast(89%);
  /* produces approx #e9edef for inactive */
}
.nav-tab.active .nav-icon {
  /* active tab: keep the original icon colors (green from chat_tab.png) */
  filter: none;
}
.nav-icon-lg { width: 28px; height: 28px; }

/* ═══════════════════════ MESSAGES ═══════════════════════ */
#messages-container {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 0;
  background: var(--bg-chat);
  background-image: url('assets/bg.png');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  position: relative;
}
/* Conversation view: give messages area explicit height so it never collapses on mobile */
#view-conv #messages-container {
  position: absolute;
  top: var(--header-h);
  left: 0;
  right: 0;
  bottom: 0;
  flex: none;
  min-height: 40vh; /* fallback so messages area is never zero on mobile */
}
#view-conv.active #messages-container {
  bottom: 56px; /* space for fixed input bar; safe-area added below */
}
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  #view-conv.active #messages-container {
    bottom: calc(56px + env(safe-area-inset-bottom, 0px));
  }
}
/* Only drop wallpaper on very short viewports where it often breaks */
@media (max-height: 500px) {
  #messages-container {
    background-image: none;
    background: var(--bg-chat);
  }
}
#messages-list {
  display: flex; flex-direction: column;
  padding: 8px 12px; min-height: 100%;
  justify-content: flex-end;
}

/* Bubbles */
.message-row { display: flex; margin: 1px 0; animation: bubbleIn 0.15s ease-out; }
@keyframes bubbleIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.message-row.from-user { justify-content: flex-end; }
.message-row.from-ai { justify-content: flex-start; }

.bubble {
  max-width: 75%;
  padding: 6px 8px 6px 9px;
  border-radius: var(--radius-bubble);
  position: relative; line-height: 1.35;
  word-wrap: break-word; overflow-wrap: break-word;
}
.bubble.out { background: var(--bg-bubble-out); border-top-right-radius: 0; }
.bubble.in { background: var(--bg-bubble-in); border-top-left-radius: 0; }

/* Tails */
.message-row.from-user .bubble.out::before {
  content: ''; position: absolute; top: 0; right: -8px;
  border-top: 0 solid transparent; border-bottom: 13px solid transparent;
  border-left: 8px solid var(--bg-bubble-out);
}
.message-row.from-ai .bubble.in::before {
  content: ''; position: absolute; top: 0; left: -8px;
  border-top: 0 solid transparent; border-bottom: 13px solid transparent;
  border-right: 8px solid var(--bg-bubble-in);
}
.message-row.continued .bubble::before { display: none; }
.message-row.continued .bubble.out { border-top-right-radius: var(--radius-bubble); }
.message-row.continued .bubble.in { border-top-left-radius: var(--radius-bubble); }

.bubble-text { color: var(--text-bubble); white-space: pre-wrap; }
.bubble-sender {
  font-size: var(--font-size-sm); font-weight: 500;
  color: var(--accent); margin-bottom: 2px; display: block;
}
.bubble-footer {
  display: flex; align-items: center; justify-content: flex-end;
  gap: 4px; margin-top: 2px; float: right; margin-left: 12px; padding-top: 3px;
}
.bubble-time { font-size: var(--font-size-xs); color: var(--text-time); }
.bubble.out .bubble-time { color: var(--text-time-out); }
.receipt { font-size: 14px; line-height: 1; }
.receipt.sent { color: var(--text-time-out); }
.receipt.delivered { color: var(--text-time-out); }
.receipt.read { color: var(--receipt-blue); }

/* System messages */
.system-message { text-align: center; padding: 4px 0; margin: 6px 0; }
.system-message .system-text {
  display: inline-block;
  background: var(--bg-bubble-system);
  color: var(--text-system);
  padding: 6px 14px; border-radius: 8px;
  font-size: var(--font-size-sm);
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
}

/* Tag header strip — matches Qt MessageBubble::paintEvent() tag rendering */
.bubble-tag-header {
  background: rgba(0, 0, 0, 0.15);
  margin: -6px -8px 6px -9px;
  padding: 4px 9px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  border-radius: var(--radius-bubble) var(--radius-bubble) 0 0;
}
.bubble.out .bubble-tag-header { margin: -6px -8px 6px -9px; border-radius: var(--radius-bubble) 0 0 0; }
.bubble.in .bubble-tag-header { margin: -6px -8px 6px -9px; border-radius: 0 var(--radius-bubble) 0 0; }
.tag-icon { margin-right: 2px; }
.bubble-caption { margin-top: 4px; font-style: normal; color: var(--text-bubble); }

/* Voice — no longer uses play button/waveform, uses tag header instead */

/* ═══════════════════════ TYPING INDICATOR (match desktop: bubble + 3 bouncing dots) ═══════════════════════ */
#typing-indicator { padding: 4px 12px; }
.typing-bubble {
  background: var(--bg-bubble-in); border-radius: var(--radius-bubble);
  border-top-left-radius: 0; display: inline-block; padding: 12px 18px;
  position: relative; min-height: 36px; box-sizing: border-box;
}
.typing-bubble::before {
  content: ''; position: absolute; top: 0; left: -8px;
  border-top: 0 solid transparent; border-bottom: 13px solid transparent;
  border-right: 8px solid var(--bg-bubble-in);
}
.typing-dots {
  display: flex; gap: 6px; align-items: center; justify-content: center;
  height: 20px;
}
.typing-dots span {
  width: 8px; height: 8px;
  background: var(--text-secondary); border-radius: 50%;
  animation: typingBounce 1.2s ease-in-out infinite;
}
.typing-dots span:nth-child(1) { animation-delay: 0s; }
.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes typingBounce {
  0%, 50%, 100% { transform: translateY(0); opacity: 0.5; }
  25% { transform: translateY(-5px); opacity: 1; }
}
/* Top bar: "typing..." pulse so it's clear AI is generating */
.topbar-subtitle.typing-anim { color: var(--accent); }

/* ═══════════════════════ STREAMING ═══════════════════════ */
#stream-preview { padding: 4px 12px; background: transparent; }
.stream-bubble {
  background: var(--bg-bubble-in); border-radius: var(--radius-bubble);
  border-top-left-radius: 0; display: inline-block;
  padding: 6px 9px; max-width: 75%;
  position: relative; word-wrap: break-word; line-height: 1.35;
}
.stream-bubble::before {
  content: ''; position: absolute; top: 0; left: -8px;
  border-top: 0 solid transparent; border-bottom: 13px solid transparent;
  border-right: 8px solid var(--bg-bubble-in);
}
#stream-sender { font-size: var(--font-size-sm); font-weight: 500; color: var(--accent); display: block; margin-bottom: 2px; }
#stream-content { color: var(--text-bubble); white-space: pre-wrap; }
.stream-cursor { color: var(--accent); animation: cursorBlink 1s step-end infinite; }
@keyframes cursorBlink { 0%,100% { opacity: 1; } 50% { opacity: 0; } }

/* ═══════════════════════ INPUT BAR ═══════════════════════ */
#view-conv.active #input-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding-bottom: calc(4px + env(safe-area-inset-bottom, 0px));
  z-index: 50;
}
#input-bar {
  display: flex;
  align-items: center;
  padding: 4px 6px;
  padding-bottom: calc(4px + env(safe-area-inset-bottom, 0px));
  gap: 4px;
  flex-shrink: 0;
  background: var(--bg-app);
  z-index: 10;
}
.input-pill {
  flex: 1;
  display: flex; align-items: center;
  background: var(--bg-input-pill);
  border-radius: var(--radius-pill);
  height: 42px;
  padding: 0 4px;
}
.pill-btn { width: 36px; height: 36px; }
.pill-btn .icon { width: 22px; height: 22px; }
#message-input {
  flex: 1; height: 100%; background: transparent;
  color: var(--text-primary); font-size: var(--font-size);
  padding: 0 4px;
}
#message-input::placeholder { color: var(--text-secondary); }

.emoji-picker {
  position: absolute; bottom: 56px; left: 12px; right: 72px;
  max-height: 200px; overflow-y: auto;
  background: var(--bg-menu); border: 1px solid var(--bg-active);
  border-radius: 8px; box-shadow: var(--shadow-lg);
  padding: 8px; display: grid; grid-template-columns: repeat(8, 1fr);
  gap: 4px; z-index: 150;
  font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", "Android Emoji", sans-serif;
}
.emoji-picker.hidden { display: none !important; }
.emoji-picker span {
  font-size: 22px; padding: 6px; cursor: pointer; text-align: center;
  border-radius: 6px;
  font-family: inherit;
}
.emoji-picker span:hover { background: var(--bg-active); }

/* Send button — green circle with arrow (matches Qt) */
.send-circle {
  width: 44px; height: 44px;
  border-radius: var(--radius-round);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background var(--transition);
}
.send-circle.has-text { background: var(--accent); color: #0b1014; }
.send-circle.no-text { background: var(--bg-input-pill); color: var(--text-secondary); }
.send-circle:active { opacity: 0.85; }
.send-circle svg { pointer-events: none; }

/* Scroll to bottom */
#scroll-bottom {
  position: absolute; bottom: 62px; right: 12px;
  width: 38px; height: 38px;
  background: var(--bg-header); border-radius: var(--radius-round);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; color: var(--text-secondary);
  cursor: pointer; box-shadow: var(--shadow); z-index: 5;
}

/* ═══════════════════════ DROPDOWN MENU (matches Qt QMenu style exactly) ═══════════════════════ */
.dropdown-menu {
  position: fixed; z-index: 200;
  background: var(--bg-menu);
  border: 1px solid var(--bg-active);
  border-radius: 4px;
  box-shadow: var(--shadow-lg);
  padding: 4px 0;
  min-width: 180px;
  animation: menuIn 0.12s ease-out;
}
@keyframes menuIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }
.dropdown-menu button {
  display: block; width: 100%;
  padding: 10px 24px; text-align: left;
  font-size: 13px; color: var(--text-primary);
  transition: background var(--transition);
}
.dropdown-menu button:hover { background: #182229; }
.dropdown-menu button:active { background: #182229; }
.menu-separator {
  height: 1px;
  background: var(--divider);
  margin: 4px 0;
}
.menu-danger { color: #f0b429 !important; }

/* Continue menu enhancements */
.dropdown-menu { max-height: 70vh; overflow-y: auto; }
.menu-section-label {
  padding: 6px 24px 2px; font-size: 11px; font-weight: 600;
  color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px;
}
.directive-btn.active { color: var(--accent) !important; }
.modifier-toggle {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 24px; font-size: 13px; color: var(--text-primary);
  cursor: pointer; transition: background var(--transition);
}
.modifier-toggle:hover { background: #182229; }
.modifier-toggle input[type="checkbox"] {
  appearance: none; -webkit-appearance: none;
  width: 18px; height: 18px; border: 2px solid var(--text-secondary);
  border-radius: 3px; background: transparent; cursor: pointer; flex-shrink: 0;
}
.modifier-toggle input[type="checkbox"]:checked {
  background: var(--accent); border-color: var(--accent);
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 16 16' fill='white' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M13.485 3.515a1.25 1.25 0 010 1.77l-6 6a1.25 1.25 0 01-1.77 0l-3-3a1.25 1.25 0 011.77-1.77L6.6 8.63l5.115-5.115a1.25 1.25 0 011.77 0z'/%3E%3C/svg%3E");
  background-size: 12px; background-position: center; background-repeat: no-repeat;
}
.menu-manage-btn {
  display: block; width: 100%;
  padding: 10px 24px; text-align: left;
  font-size: 13px; color: var(--text-secondary) !important;
  transition: background var(--transition);
}
.menu-manage-btn:hover { background: #182229; }

/* ═══════════════════════ CALL OVERLAY (chat stays visible and usable during call) ═══════════════════════ */
#view-conv {
  position: relative;
  min-height: 0;
}
/* No full-screen blur or darkening: chat stays readable, input bar usable */
.call-overlay-in-conv {
  position: absolute;
  top: 0; left: 0; right: 0;
  bottom: auto;
  height: fit-content;
  min-height: 0;
  z-index: 90;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  padding: 0;
  pointer-events: none;
  background: transparent;
}
.call-overlay-in-conv.hidden { display: none !important; }
.call-overlay-in-conv .call-header { pointer-events: auto; }
.call-overlay-spacer {
  display: none;
}
.call-bg {
  display: none; /* do not blur the chat */
}
/* Compact top bar: avatar + name + timer + hang up */
.call-header {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 12px;
  text-align: left;
  background: rgba(31, 44, 52, 0.98);
  padding: 10px 12px 10px 16px;
  min-width: 0;
  border-radius: 0 0 12px 12px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.call-header .avatar-lg {
  width: 44px; height: 44px;
  border-radius: 50%;
  margin: 0;
  overflow: hidden;
  border: 2px solid rgba(255,255,255,0.2);
  background: var(--bg-bubble-in);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; color: var(--text-secondary);
  flex-shrink: 0;
}
.call-header .avatar-lg img { width: 100%; height: 100%; object-fit: cover; }
.call-header .avatar-lg .call-avatar-fallback {
  font-size: 20px; font-weight: 600; color: var(--text-secondary);
  display: none; width: 100%; height: 100%; align-items: center; justify-content: center;
}
.call-header .avatar-lg .call-avatar-fallback[style*="flex"] { display: flex !important; }
.call-header .call-header-text { flex: 1; min-width: 0; }
.call-header h2 { color: #e9edef; font-size: 16px; font-weight: 500; margin-bottom: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#call-type { color: #8696a0; font-size: 12px; margin-bottom: 0; }
.call-timer { color: #8696a0; font-size: 14px; font-variant-numeric: tabular-nums; margin-top: 0; }
/* Top-right actions: hang up (active) or deny + accept (ringing) */
.call-header-actions { flex-shrink: 0; display: flex; align-items: center; }
.call-header-actions .call-actions { display: flex; gap: 10px; align-items: center; }
.call-btn-header {
  width: 44px; height: 44px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.15s; cursor: pointer; border: none;
  flex-shrink: 0;
}
.call-btn-header:active { transform: scale(1.05); }
.call-btn-header.accept { background: var(--accent); }
.call-btn-header.deny { background: var(--danger); }
.call-btn-header.kebab { background: #2a3942; }
.call-btn-header.kebab .call-icon-sm { filter: var(--icon-tint); }
.call-icon-sm { width: 24px; height: 24px; object-fit: contain; pointer-events: none; }

/* Transparent bubbles during calls */
.bubble.transparent-mode { background: rgba(0,0,0,0.25) !important; }
.bubble.transparent-mode .bubble-text,
.bubble.transparent-mode .msg-time { color: rgba(255,255,255,0.8) !important; }

/* CALL_EVENT banners */
.message-row.system-message-row { justify-content: center; }
.message-row.system-message-row .system-message { margin: 0; }
.call-event-banner {
  text-align: center; color: #8696a0; font-size: 12px;
  background: rgba(25, 40, 50, 0.85);
  border-radius: 8px; padding: 6px 16px; margin: 4px auto;
  max-width: 80%; display: inline-block;
}
@keyframes callSlideIn { from { transform: scale(0.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* Keep .overlay for other modals */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 50; backdrop-filter: blur(10px);
}
.call-card {
  background: var(--bg-modal); border-radius: 16px;
  padding: 32px 40px; text-align: center;
  box-shadow: var(--shadow-lg);
  animation: callSlideIn 0.3s ease;
}
.call-card h2 { font-size: 22px; font-weight: 500; margin-bottom: 6px; }

/* ═══════════════════════ MODAL ═══════════════════════ */
.modal-card {
  background: var(--bg-modal); border-radius: 12px;
  width: 90%; max-width: 400px; max-height: 80vh;
  overflow-y: auto; box-shadow: var(--shadow-lg);
}
.modal-sm { max-width: 340px; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 18px; font-weight: 500; }
.modal-close {
  font-size: 20px; color: var(--text-secondary);
  width: 32px; height: 32px; border-radius: var(--radius-round);
  display: flex; align-items: center; justify-content: center;
}
.modal-body { padding: 20px; }

/* Context Overview — matches Qt desktop layout */
.context-overview-card { max-width: 420px; max-height: 90vh; }
#context-body { padding: 20px; }
.context-header-row {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 12px;
}
.context-header-label { color: #e0e0e0; font-size: 14px; font-weight: 600; }
.context-header-tokens { font-size: 14px; font-weight: bold; }
.context-header-tokens.over { color: #ff4444; }
.context-header-tokens.ok { color: #aebac1; }
.context-bar-stacked {
  height: 24px; border-radius: 6px; background: #2a2a3e;
  display: flex; overflow: hidden; margin-bottom: 12px;
}
.context-bar-segment { min-width: 2px; }
.context-rows-container {
  background: #16213e; border-radius: 8px;
  padding: 12px 12px 8px; margin-bottom: 12px;
}
.context-section-row {
  display: flex; align-items: center; padding: 8px 0;
  font-size: 13px;
}
.context-section-dot { width: 20px; flex-shrink: 0; font-size: 10px; }
.context-section-name { color: #e0e0e0; font-weight: 500; flex: 1; }
.context-section-tokens { color: #8696a0; font-weight: 500; }
.context-section-chevron { color: #4a4a5a; font-size: 16px; padding-left: 8px; }
.context-section-sep { height: 1px; background: #1e2d4a; margin: 0; }
.context-cards-sub { margin: 0 0 4px 20px; font-size: 11px; color: #6b7b8a; word-wrap: break-word; }
.context-over-budget {
  color: #ff4444; font-size: 13px; font-weight: bold; text-align: center;
  background: #2a1a1a; border: 1px solid #ff4444; border-radius: 6px; padding: 8px;
  margin-bottom: 8px;
}
.context-recommend {
  color: #FFD700; font-size: 12px; text-align: center; margin-bottom: 16px;
}
.context-close-wrap { text-align: center; }
.context-close-btn {
  background: #2a3942; color: #e9edef; border: none; border-radius: 6px;
  padding: 10px 24px; font-size: 13px; cursor: pointer;
}
.context-close-btn:hover { background: #3b4a54; }

/* ═══════════════════════ SETTINGS PANEL ═══════════════════════ */
.panel-body { flex: 1; overflow-y: auto; padding: 16px; }
.settings-group {
  margin-bottom: 20px; padding-bottom: 16px;
  border-bottom: 1px solid var(--border-light);
}
.settings-group:last-child { border-bottom: none; }
.settings-group h3 {
  font-size: 13px; font-weight: 600; color: var(--accent);
  text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 10px;
}
.settings-group label { display: block; font-size: 13px; color: var(--text-secondary); margin-bottom: 8px; }
.settings-group label.disabled { opacity: 0.6; pointer-events: none; }
.settings-group label span { float: right; color: var(--text-primary); font-weight: 500; }
.settings-group select {
  width: 100%; background: var(--bg-input-pill); color: var(--text-primary);
  padding: 10px 12px; border-radius: 6px; margin-bottom: 8px; font-size: 14px;
  border: 1px solid var(--border);
}
input[type="range"] {
  width: 100%; margin-top: 4px;
  -webkit-appearance: none; appearance: none;
  height: 4px; background: var(--border); border-radius: 2px; outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 18px; height: 18px;
  border-radius: 50%; background: var(--accent); cursor: pointer;
}
.toggle-row { display: flex !important; align-items: center; gap: 10px; }
.toggle-row input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); }
.btn-primary {
  background: var(--accent); color: white;
  padding: 12px 20px; border-radius: 6px;
  font-size: 15px; font-weight: 500; width: 100%;
  transition: background var(--transition);
}
.btn-primary:active { background: var(--accent-hover); }
.btn-danger {
  background: var(--danger); color: white;
  padding: 12px 20px; border-radius: 6px;
  font-size: 15px; font-weight: 500; width: 100%;
}

/* Form inputs */
.form-row { display: flex; gap: 8px; align-items: center; }
.form-input {
  background: var(--bg-input-pill); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 10px 12px; font-size: 14px;
}
.form-input:focus { border-color: var(--accent); }
.form-input.sm { width: 80px; }
.radio-label {
  display: flex; align-items: center; gap: 6px;
  font-size: 14px; color: var(--text-primary); cursor: pointer;
}
.radio-label input[type="radio"] { accent-color: var(--accent); }

/* ═══════════════════════ DROPDOWN MENUS ═══════════════════════ */
.dropdown-menu {
  position: fixed;
  z-index: 1000;
  background: #233138;
  border: 1px solid #2a3942;
  border-radius: 8px;
  padding: 6px 0;
  min-width: 200px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.5);
}
.dropdown-menu button {
  display: block;
  width: 100%;
  padding: 12px 20px;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 15px;
  text-align: left;
  cursor: pointer;
}
.dropdown-menu button:hover { background: #182229; }
.dropdown-menu .menu-separator {
  height: 1px;
  background: #222d34;
  margin: 4px 0;
}
.dropdown-menu .menu-danger { color: #f15c6d; }

/* ═══════════════════════ PHOTO / MEDIA FRAME ═══════════════════════ */
.bubble-media { padding: 3px !important; }
.bubble-media .bubble-sender { padding: 4px 6px 2px; }
.photo-frame {
  position: relative;
  background: linear-gradient(145deg, #0a1a14, #1a2e28);
  border-radius: 6px;
  min-height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  overflow: hidden;
}
.photo-attach-img {
  max-width: 100%; max-height: 240px; border-radius: 6px; display: block;
}
.photo-icon {
  position: absolute;
  top: 8px;
  left: 10px;
  font-size: 18px;
  opacity: 0.6;
}
.photo-desc {
  font-style: italic;
  color: #a0b8a8;
  font-size: 13px;
  line-height: 1.45;
  text-align: center;
}
.photo-footer {
  position: absolute;
  bottom: 4px;
  right: 8px;
  background: rgba(0,0,0,0.5);
  border-radius: 8px;
  padding: 2px 6px;
}
.photo-caption {
  padding: 6px 6px 0;
  color: var(--text-primary);
  font-size: 14.5px;
  line-height: 1.35;
}
/* ═══════════════════════ STREAMING BUBBLE ═══════════════════════ */
.streaming-bubble { min-width: 120px; }
.streaming-cursor { color: var(--accent); font-weight: bold; animation: blink 0.6s infinite; }
@keyframes blink { 0%,50% { opacity: 1; } 51%,100% { opacity: 0; } }

/* ═══════════════════════ ERROR TEXT ═══════════════════════ */
.error-text { color: #f15c6d !important; background: rgba(241,92,109,0.1) !important; border: 1px solid rgba(241,92,109,0.3) !important; }

/* ═══════════════════════ VOICE PLAYER ═══════════════════════ */
.bubble-voice { padding: 8px 10px !important; }
.voice-player { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.voice-play { font-size: 18px; color: var(--accent); cursor: pointer; user-select: none; }
.voice-waveform { display: flex; align-items: center; gap: 2px; height: 28px; flex: 1; }
.voice-bar { width: 3px; border-radius: 2px; background: var(--accent); opacity: 0.5; }
.voice-bar:nth-child(1) { height: 8px; } .voice-bar:nth-child(2) { height: 16px; }
.voice-bar:nth-child(3) { height: 22px; } .voice-bar:nth-child(4) { height: 12px; }
.voice-bar:nth-child(5) { height: 26px; } .voice-bar:nth-child(6) { height: 18px; }
.voice-bar:nth-child(7) { height: 10px; } .voice-bar:nth-child(8) { height: 20px; }
.voice-bar:nth-child(9) { height: 14px; } .voice-bar:nth-child(10) { height: 6px; }
.voice-dur { font-size: 11px; color: var(--text-secondary); min-width: 30px; text-align: right; }

/* ═══════════════════════ TOAST NOTIFICATION ═══════════════════════ */
.toast-notification {
  position: fixed; top: -80px; left: 50%; transform: translateX(-50%);
  background: #233138; border-radius: 12px; padding: 10px 16px;
  display: flex; align-items: center; gap: 10px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5); z-index: 9999;
  cursor: pointer; transition: top 0.3s ease; max-width: 90vw;
}
.toast-notification.visible { top: 16px; }
.toast-avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; }
.toast-body { display: flex; flex-direction: column; gap: 2px; }
.toast-body strong { color: #e9edef; font-size: 13px; }
.toast-body span { color: #8696a0; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }

/* ═══════════════════════ TURN HISTORY MODAL ═══════════════════════ */
.turn-history-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center; z-index: 9000;
}
.turn-history-modal {
  background: #111b21; border-radius: 12px; width: 90vw; max-width: 420px;
  max-height: 80vh; overflow: hidden; display: flex; flex-direction: column;
}
.turn-history-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid #2a3942;
}
.turn-history-header h3 { color: #e9edef; margin: 0; font-size: 16px; }
.turn-history-body { overflow-y: auto; padding: 12px 16px; }
.turn-group { margin-bottom: 16px; }
.turn-group-label { color: #8696a0; font-size: 12px; margin-bottom: 6px; }
.turn-entry { padding: 8px 10px; border-radius: 8px; margin-bottom: 4px; }
.turn-active { background: rgba(0,168,132,0.15); border: 1px solid rgba(0,168,132,0.3); }
.turn-inactive { background: #1a2730; }
.turn-entry-header { display: flex; align-items: center; justify-content: space-between; }
.turn-label { color: #e9edef; font-size: 13px; }
.turn-activate {
  background: var(--accent); color: #111b21; border: none; border-radius: 6px;
  padding: 4px 12px; font-size: 12px; cursor: pointer; font-weight: 600;
}

/* ═══════════════════════ SETTINGS NUMBER INPUTS ═══════════════════════ */
.settings-num {
  width: 80px;
  padding: 6px 8px;
  background: var(--bg-input-pill);
  color: var(--text-primary);
  border: 1px solid #3b4a54;
  border-radius: 6px;
  font-size: 14px;
  text-align: right;
  float: right;
  appearance: textfield;
  -moz-appearance: textfield;
}
.settings-num::-webkit-inner-spin-button,
.settings-num::-webkit-outer-spin-button { opacity: 1; }

/* ═══════════════════════ UTILITIES ═══════════════════════ */
.hidden { display: none !important; }

/* ═══════════════════════ SCENARIO EDITORS ═══════════════════════ */
.scenario-editor {
  width: 100%; box-sizing: border-box;
  background: #1a2730; color: var(--text-primary);
  border: 1px solid #2a3942; border-radius: 6px;
  padding: 8px; font-family: 'Consolas', 'Courier New', monospace;
  font-size: 12px; resize: vertical; margin-bottom: 8px;
}
.editor-label { display: block; color: var(--text-secondary); font-weight: 600; margin: 8px 0 4px; font-size: 13px; }
.photo-gen-image-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 6px 0; }
.photo-gen-image-status { color: var(--text-secondary); font-size: 13px; }
.profile-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; }
.profile-grid label { display: flex; flex-direction: column; gap: 2px; color: var(--text-secondary); font-size: 12px; }
.profile-grid select, .profile-grid input { background: var(--bg-secondary); color: var(--text-primary); border: 1px solid var(--border); border-radius: 4px; padding: 5px 8px; font-size: 13px; }
.editor-btns { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }
.btn-secondary {
  background: #2a3942; color: var(--text-primary); border: none; border-radius: 6px;
  padding: 8px 16px; font-size: 13px; cursor: pointer;
}
.btn-secondary:hover { background: #3b4a54; }
.settings-note { color: var(--text-secondary); font-size: 12px; margin-bottom: 8px; }

/* (old in-call bar removed — replaced by full-screen call overlay) */

/* ═══════════════════════ MANAGE CONTACTS ═══════════════════════ */
.manage-section { padding: 16px; }
.manage-section h4 { color: var(--text-primary); margin: 12px 0 8px; font-size: 14px; }
.manage-add-row { display: flex; gap: 8px; margin-bottom: 12px; }
.manage-add-row select {
  flex: 1; background: #1f2c34; color: var(--text-primary);
  border: 1px solid #2a3942; border-radius: 6px; padding: 6px 10px; font-size: 13px;
}
.manage-row {
  display: flex; align-items: center; gap: 8px;
  padding: 8px; background: #1a2730; border-radius: 6px; margin-bottom: 4px;
}
.manage-name { flex: 1; color: var(--text-primary); font-size: 14px; }
.manage-via { color: var(--text-secondary); font-size: 11px; }
.btn-danger { background: #ea0038; color: white; border: none; border-radius: 6px; padding: 8px 16px; font-size: 13px; cursor: pointer; font-weight: 600; }
.btn-danger:hover { background: #cc0030; }
.btn-sm { padding: 4px 10px !important; font-size: 12px !important; }
.empty-state { color: var(--text-secondary); font-size: 13px; text-align: center; padding: 16px; }

/* ═══════════════════════ PROFILE OVERLAY ═══════════════════════ */
#profile-overlay {
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.85); z-index: 10000; cursor: pointer;
}
.profile-overlay-inner { text-align: center; pointer-events: none; }
#profile-overlay-img {
  max-width: 80vw; max-height: 70vh; border-radius: 50%;
  object-fit: cover; box-shadow: 0 8px 40px rgba(0,0,0,0.6);
  width: 300px; height: 300px;
}
#profile-overlay-name {
  color: #e9edef; font-size: 20px; font-weight: 600;
  margin-top: 16px; text-shadow: 0 1px 4px rgba(0,0,0,0.5);
}

/* Make avatars clickable */
#conv-avatar, .contact-avatar { cursor: pointer; }

/* ═══════════════════════ SETTINGS PANEL ═══════════════════════ */

#view-settings {
  background: var(--bg-chat);
  display: flex;
  flex-direction: column;
  height: 100%;
}
#view-settings .panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px 24px;
}

/* --- Groups & Headers --- */
.settings-group {
  background: var(--bg-bubble-in);
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 10px;
}
.settings-group h3 {
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 0 0 10px;
}

/* --- Labels with number inputs --- */
.settings-group label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--text-primary);
  font-size: 14px;
  padding: 6px 0;
}
.settings-num {
  width: 90px;
  background: var(--bg-input-pill);
  color: var(--accent);
  border: 1px solid #3b4a54;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  outline: none;
  -moz-appearance: textfield;
}
.settings-num::-webkit-inner-spin-button,
.settings-num::-webkit-outer-spin-button {
  opacity: 1;
}
.settings-num:focus {
  border-color: var(--accent);
}

/* --- Selects (model/provider dropdowns) --- */
.settings-group select {
  width: 100%;
  background: var(--bg-input-pill);
  color: var(--text-primary);
  border: 1px solid #3b4a54;
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 14px;
  margin-bottom: 6px;
  outline: none;
  cursor: pointer;
}
.settings-group select:focus {
  border-color: var(--accent);
}

/* --- Toggle rows (checkboxes) --- */
.toggle-row {
  display: flex !important;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  padding: 4px 0;
}
.toggle-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}
.toggle-row span {
  color: var(--text-primary);
  font-size: 14px;
}

/* --- Save button --- */
.settings-group .btn-primary {
  width: 100%;
  background: var(--accent);
  color: #111b21;
  border: none;
  border-radius: 8px;
  padding: 12px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
}
.settings-group .btn-primary:hover {
  background: var(--accent-hover);
}

/* --- Scenario editors --- */
.settings-note {
  color: var(--text-secondary);
  font-size: 12px;
  margin: 0 0 8px;
}
.editor-label {
  display: block;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
  margin: 10px 0 4px;
}
.scenario-editor {
  width: 100%;
  background: var(--bg-input-pill);
  color: var(--text-primary);
  border: 1px solid #3b4a54;
  border-radius: 6px;
  padding: 10px;
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 12px;
  resize: vertical;
  outline: none;
  box-sizing: border-box;
}
.scenario-editor:focus {
  border-color: var(--accent);
}

