/* Dashboard — mobile-first, dark theme, bottom nav */
* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, -apple-system, sans-serif; background: var(--bg); color: var(--text); padding-bottom: var(--safe-bottom); }

.screen { min-height: 100vh; min-height: 100dvh; }
.hidden { display: none !important; }

/* Login */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  padding-top: calc(1.5rem + var(--safe-top));
}
.login-box {
  width: 100%;
  max-width: 360px;
}
.login-box h1 { margin: 0 0 0.25rem; font-size: 1.5rem; }
.login-subtitle { color: var(--text-muted); margin: 0 0 1.5rem; font-size: 0.9rem; }
#login-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
#login-form input {
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel);
  color: var(--text);
  font-size: 1rem;
}
.btn-primary {
  padding: 0.75rem 1.25rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 600;
  min-height: var(--tap-min);
  cursor: pointer;
}
.btn-block { width: 100%; }
.login-create { margin-top: 0.75rem; font-size: 0.9rem; color: var(--text-muted); }
.btn-link { background: none; border: none; color: var(--accent); cursor: pointer; font-size: inherit; text-decoration: underline; padding: 0; }
.error { color: var(--danger); font-size: 0.9rem; margin-top: 0.5rem; }
.email-not-confirmed {
  margin-top: 1rem;
  padding: 1rem;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
}
.email-not-confirmed p { margin: 0 0 0.5rem; }
.btn-resend { margin-top: 0.5rem; width: 100%; }
.resend-message { margin-top: 0.5rem; font-size: 0.85rem; color: var(--accent2); }
.resend-message.error { color: var(--danger); }
.config-required {
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
  text-align: left;
}
.config-required p { margin: 0 0 0.5rem; }
.config-required ol { margin: 0.5rem 0 0; padding-left: 1.25rem; }
.config-required li { margin-bottom: 0.25rem; }
.config-required code { background: var(--panel); padding: 0.15rem 0.4rem; border-radius: 4px; font-size: 0.85rem; }
.config-required a { color: var(--accent); }

/* App shell */
#app-screen {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding-top: var(--safe-top);
}
#app-screen.app-layout { flex-direction: column; padding-top: 0; }
#app-screen.with-top-bar .main-wrap #main-content { padding-top: 0; }

/* App header — all pages */
.app-header {
  position: sticky;
  top: 0;
  z-index: 150;
  flex-shrink: 0;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  min-height: var(--tap-min);
}
.header-inner {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  min-height: var(--tap-min);
}
.header-inner.hidden { display: none !important; }
.app-header .btn-icon {
  width: var(--tap-min);
  height: var(--tap-min);
  min-width: var(--tap-min);
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 1.25rem;
  cursor: pointer;
  border-radius: var(--radius-sm);
}
.app-title {
  flex: 1;
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.header-user-wrap { position: relative; flex-shrink: 0; }
.header-user-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 50%;
}
.header-user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--panel2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
  overflow: hidden;
}
.header-user-avatar img { width: 100%; height: 100%; object-fit: cover; }
.header-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 0.25rem;
  min-width: 160px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.5rem 0;
  z-index: 200;
}
.header-dropdown.hidden { display: none !important; }
.header-dropdown-item {
  display: block;
  width: 100%;
  padding: 0.6rem 1rem;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 0.95rem;
  text-decoration: none;
  cursor: pointer;
  font-family: inherit;
}
.header-dropdown-item:hover, .header-dropdown-item:focus { background: var(--panel2); }
.header-dropdown-action { width: 100%; }

/* Chat header (when in chat view) */
.header-chat .chat-header-avatar {
  width: 36px;
  height: 36px;
  min-width: 36px;
  border-radius: 50%;
  background: var(--panel2);
  overflow: hidden;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
}
.header-chat .chat-header-avatar img { width: 100%; height: 100%; object-fit: cover; }
.header-chat .top-bar-title { flex: 1; font-weight: 600; font-size: 1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }

/* Header search (desktop: search bar + filters in header when on search page) */
.header-search {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
}
.header-search.hidden { display: none !important; }
.header-search-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}
.header-search-input {
  flex: 1;
  min-width: 120px;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel2);
  color: var(--text);
  font-size: 0.95rem;
}
.header-search-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  flex-shrink: 0;
}
.header-search-filters .chip {
  padding: 0.35rem 0.6rem;
  font-size: 0.8rem;
}

/* On desktop, hide the search bar inside the page (it's in the header) */
@media (min-width: 769px) {
  .page-search .search-page-header { display: none !important; }
}

.badge { font-size: 0.7rem; background: var(--warning); color: #000; padding: 0.15rem 0.4rem; border-radius: 4px; margin-left: 0.25rem; }
.pill { font-size: 0.75rem; background: var(--panel2); padding: 0.2rem 0.5rem; border-radius: 999px; color: var(--text-muted); }

/* Sidebar */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 260px;
  max-width: 85vw;
  height: 100vh;
  height: 100dvh;
  background: var(--panel);
  border-right: 1px solid var(--border);
  z-index: 160;
  display: flex;
  flex-direction: column;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
  padding-top: var(--safe-top);
}
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar-title { font-weight: 700; font-size: 1rem; color: var(--text); }
.sidebar-close { display: none; }
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0;
}
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.95rem;
  transition: background 0.15s, color 0.15s;
}
.sidebar-link:hover { background: var(--panel2); color: var(--text); }
.sidebar-link.active { background: var(--panel2); color: var(--accent); font-weight: 600; }
.sidebar-icon {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.sidebar-icon .icon { width: 20px; height: 20px; }
.sidebar-link span:last-of-type { flex: 1; }
.sidebar-badge {
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  background: var(--danger);
  color: #fff;
  font-size: 0.7rem;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.sidebar-badge.hidden { display: none !important; }
.sidebar-section { margin-top: 0.5rem; padding-top: 0.5rem; border-top: 1px solid var(--border); }
.sidebar-section-title {
  padding: 0.5rem 1rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}
.sidebar-footer {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem;
  border-top: 1px solid var(--border);
  background: var(--bg);
}
.sidebar-user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--panel2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
  overflow: hidden;
  flex-shrink: 0;
}
.sidebar-user-avatar img { width: 100%; height: 100%; object-fit: cover; }
.sidebar-user-info { min-width: 0; }
.sidebar-user-name { display: block; font-weight: 600; font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user-role { display: block; font-size: 0.8rem; color: var(--text-muted); }

.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 155;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}
.sidebar-overlay.open { opacity: 1; visibility: visible; }
.sidebar-overlay.hidden { display: none !important; }

.main-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Desktop: sidebar always visible, bottom nav hidden */
@media (min-width: 769px) {
  .sidebar {
    transform: none;
    box-shadow: none;
  }
  .sidebar-close { display: none !important; }
  .main-wrap { margin-left: 260px; }
  .bottom-nav { display: none !important; }
  #main-content { padding-bottom: 1rem; }
}

/* Mobile: sidebar overlay when open */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.3);
  }
  .sidebar-close { display: flex !important; align-items: center; justify-content: center; width: var(--tap-min); height: var(--tap-min); background: transparent; border: none; color: var(--text); cursor: pointer; }
  .main-wrap { margin-left: 0; }
}

.top-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  min-height: var(--tap-min);
}
.top-bar.hidden { display: none !important; }
.top-bar .btn-icon {
  width: var(--tap-min);
  height: var(--tap-min);
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 1.25rem;
  cursor: pointer;
}
.top-bar .chat-header-avatar {
  width: 36px;
  height: 36px;
  min-width: 36px;
  border-radius: 50%;
  background: var(--panel2);
  overflow: hidden;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
}
.top-bar .chat-header-avatar img { width: 100%; height: 100%; object-fit: cover; }
.top-bar-title { flex: 1; font-weight: 600; font-size: 1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }

/* Mobile-friendly: touch targets and spacing */
@media (max-width: 480px) {
  .page { padding: 0.75rem; }
  .stats-grid { grid-template-columns: 1fr; gap: 0.5rem; }
  .list-item { padding: 0.6rem 0.75rem; }
  .bottom-nav .nav-btn, #bottom-nav-admin .nav-btn { padding: 0.4rem 0.5rem; font-size: 0.7rem; }
  .sheet-content { padding: 1rem 0.75rem; padding-bottom: calc(1rem + var(--safe-bottom)); }
  .form-card { padding: 0.75rem; }
}
@media (min-width: 481px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 768px) {
  .stats-grid { grid-template-columns: repeat(4, 1fr); }
}

/* Main content */
#main-content {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(60px + var(--safe-bottom));
}

/* Settings page */
.settings-sections { display: flex; flex-direction: column; gap: 1rem; }
.settings-card .form-title { margin: 0 0 0.35rem; }
.settings-card label { display: block; margin: 0.5rem 0 0.25rem; font-size: 0.9rem; color: var(--text-muted); }
.settings-card label:first-of-type { margin-top: 0; }
.settings-card input, .settings-card select, .settings-card textarea {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel2);
  color: var(--text);
  font-size: 1rem;
  margin-bottom: 0;
}
.settings-card textarea { min-height: 80px; resize: vertical; }
.settings-card .form-actions { margin-top: 1rem; }

/* Tickets */
.ticket-detail-back { margin-bottom: 0.5rem; }
.ticket-detail-back .btn-icon {
  width: var(--tap-min);
  height: var(--tap-min);
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text);
  cursor: pointer;
  border-radius: var(--radius-sm);
}
.ticket-detail-header {
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}
.ticket-detail-subject { margin: 0 0 0.35rem; font-size: 1.1rem; }
.ticket-detail-meta { font-size: 0.85rem; color: var(--text-muted); }
.ticket-detail-actions { margin-top: 0.75rem; }
.ticket-detail-actions label { display: block; margin-bottom: 0.25rem; font-size: 0.85rem; color: var(--text-muted); }
.ticket-detail-actions select {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel2);
  color: var(--text);
  font-size: 0.95rem;
}
.ticket-detail-body {
  padding: 0.75rem 0;
  font-size: 0.95rem;
  white-space: pre-wrap;
  word-break: break-word;
}
.ticket-replies {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}
.ticket-reply-item {
  padding: 0.75rem 1rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
}
.ticket-reply-item .ticket-reply-meta { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.35rem; }
.ticket-reply-composer {
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.ticket-reply-composer textarea {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel2);
  color: var(--text);
  font-size: 1rem;
  resize: vertical;
  min-height: 80px;
}
.list-item .ticket-priority { font-size: 0.75rem; padding: 0.15rem 0.4rem; border-radius: 4px; }
.list-item .ticket-priority.urgent { background: var(--danger); color: #fff; }
.list-item .ticket-priority.high { background: var(--warning); color: #000; }
.list-item .ticket-priority.normal { background: var(--panel2); color: var(--text-muted); }
.list-item .ticket-priority.low { background: var(--panel2); color: var(--text-muted); }

.page {
  display: none;
  flex: 1;
  flex-direction: column;
  overflow: hidden;
  padding: 1rem;
}
.page.active { display: flex; }

.page-header {
  margin-bottom: 1rem;
}
.page-header h2 { margin: 0 0 0.5rem; font-size: 1.25rem; }
.page-header-row { display: flex; justify-content: flex-end; align-items: center; }
.btn-sm { padding: 0.5rem 1rem; font-size: 0.9rem; }

/* Stats / admin dashboard */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.stat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
}
.stat-card .stat-value { display: block; font-size: 1.5rem; font-weight: 700; color: var(--accent); }
.stat-card .stat-label { font-size: 0.8rem; color: var(--text-muted); }
.analytics-section { margin-top: 1rem; }
.analytics-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}
.chart-placeholder {
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.9rem;
}
.stats-detail { margin-top: 0.75rem; font-size: 0.85rem; color: var(--text-muted); }

/* Consultant form */
.form-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}
.form-title { margin: 0 0 0.75rem; font-size: 1rem; }
.form-card input,
.form-card select {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel2);
  color: var(--text);
  margin-bottom: 0.5rem;
  font-size: 1rem;
}
.form-actions { display: flex; gap: 0.5rem; margin-top: 0.75rem; }
.form-actions .btn-primary,
.form-actions .btn-secondary { flex: 1; }
.segmented {
  display: inline-flex;
  background: var(--panel);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.segmented-btn {
  padding: 0.5rem 1rem;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.9rem;
  cursor: pointer;
}
.segmented-btn.active { background: var(--accent); color: #fff; }
.search-input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel);
  color: var(--text);
  font-size: 1rem;
  margin-bottom: 0.5rem;
}
.filter-chips { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.5rem; }
.chip {
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
}

/* Lists */
.list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.list-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--panel);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  cursor: pointer;
  min-height: var(--tap-min);
  text-decoration: none;
  color: inherit;
}
.list-item:active { background: var(--panel2); }
.list-item .avatar {
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  border-radius: 50%;
  background: var(--panel2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  flex-shrink: 0;
  overflow: hidden;
}
.list-item .avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.list-item .avatar-placeholder { font-size: 1rem; color: var(--text-muted); }
.list-item .body { flex: 1; min-width: 0; }
.list-item .name { font-weight: 600; margin: 0 0 0.2rem; }
.list-item .preview { font-size: 0.85rem; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .meta { display: flex; gap: 0.5rem; margin-top: 0.25rem; font-size: 0.75rem; color: var(--text-muted); }
.list-item .time { margin-left: auto; font-size: 0.8rem; color: var(--text-muted); flex-shrink: 0; }
.cards .list-item { flex-direction: column; align-items: stretch; }
.empty { text-align: center; color: var(--text-muted); padding: 2rem; font-size: 0.95rem; }

/* Profile */
.profile-card {
  text-align: center;
  padding: 1.5rem;
  background: var(--panel);
  border-radius: var(--radius);
  margin-bottom: 1rem;
}
.profile-avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--panel2);
  margin: 0 auto 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 600;
  overflow: hidden;
}
.profile-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.profile-name { margin: 0 0 0.2rem; font-weight: 600; font-size: 1.1rem; }
.profile-role { margin: 0; color: var(--text-muted); font-size: 0.9rem; }
.profile-section {
  margin-bottom: 1rem;
}
.profile-section label { display: block; margin-bottom: 0.35rem; font-size: 0.9rem; color: var(--text-muted); }
.profile-section select {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel);
  color: var(--text);
  font-size: 1rem;
}
.profile-section input[type="checkbox"] { margin-right: 0.5rem; }
.profile-hint { font-size: 0.85rem; color: var(--text-muted); margin: 0.25rem 0 0.5rem; }
.shortcuts-section .shortcuts-list { margin-top: 0.5rem; display: flex; flex-direction: column; gap: 0.5rem; }
.shortcuts-section .shortcut-item-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
}
.shortcuts-section .shortcut-item-row .shortcut-key { color: var(--accent); font-weight: 600; margin-right: 0.25rem; }
.shortcuts-section .shortcut-item-row .shortcut-title { flex: 1; }
.shortcuts-section .shortcut-item-row .shortcut-preview { font-size: 0.8rem; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 120px; }
.btn-secondary {
  padding: 0.75rem 1.25rem;
  background: var(--panel2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  min-height: var(--tap-min);
  cursor: pointer;
  width: 100%;
}

/* Chat page */
.chat-page {
  padding: 0;
  display: none;
  flex-direction: column;
}
.chat-page.active { display: flex; }
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.chat-msg {
  max-width: 85%;
  padding: 0.6rem 0.9rem;
  border-radius: var(--radius);
  font-size: 0.95rem;
  word-break: break-word;
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
}
.chat-msg .msg-avatar {
  width: 28px;
  height: 28px;
  min-width: 28px;
  border-radius: 50%;
  background: var(--panel2);
  overflow: hidden;
  flex-shrink: 0;
}
.chat-msg .msg-avatar img { width: 100%; height: 100%; object-fit: cover; }
.chat-msg .msg-avatar .initial { font-size: 0.75rem; font-weight: 600; display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; color: var(--text-muted); }
.chat-msg .msg-body { flex: 1; min-width: 0; }
.chat-msg.visitor { align-self: flex-start; background: transparent; flex-direction: row; }
.chat-msg.visitor .msg-body { background: var(--bubble-user); padding: 0.6rem 0.9rem; border-radius: var(--radius); }
.chat-msg.consultant { align-self: flex-end; flex-direction: row-reverse; background: transparent; }
.chat-msg.consultant .msg-body { background: var(--bubble-agent); padding: 0.6rem 0.9rem; border-radius: var(--radius); }
.chat-msg.system { align-self: center; background: var(--panel2); color: var(--text-muted); font-size: 0.85rem; flex-direction: column; align-items: center; }
.chat-msg.system .msg-avatar { display: none; }
.chat-msg .time { font-size: 0.7rem; color: var(--text-muted); margin-top: 0.25rem; }
.typing-line { padding: 0.5rem 1rem; font-size: 0.85rem; color: var(--text-muted); }
.chat-composer {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  padding-bottom: calc(0.5rem + var(--safe-bottom));
  background: var(--panel);
  border-top: 1px solid var(--border);
  position: relative;
}
.chat-composer .shortcut-wrap { position: relative; flex-shrink: 0; }
.chat-composer .shortcut-picker {
  position: absolute;
  bottom: 100%;
  left: 0;
  margin-bottom: 0.25rem;
  min-width: 220px;
  max-width: 90vw;
  max-height: 240px;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 50;
  display: none;
}
.chat-composer .shortcut-picker.open { display: block; }
.chat-composer .shortcut-picker .shortcut-item {
  display: block;
  width: 100%;
  padding: 0.6rem 0.9rem;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 0.9rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.chat-composer .shortcut-picker .shortcut-item:last-child { border-bottom: none; }
.chat-composer .shortcut-picker .shortcut-item:hover,
.chat-composer .shortcut-picker .shortcut-item:focus { background: var(--panel2); }
.chat-composer .shortcut-picker .shortcut-item .shortcut-key { color: var(--accent); font-size: 0.8rem; margin-right: 0.5rem; }
.chat-composer .shortcut-picker .shortcut-item .shortcut-title { font-weight: 500; }
.chat-composer .shortcut-picker .shortcut-item .shortcut-preview { font-size: 0.8rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-composer .btn-icon {
  width: var(--tap-min);
  height: var(--tap-min);
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 1.25rem;
  cursor: pointer;
  flex-shrink: 0;
}
#chat-input {
  flex: 1;
  min-height: var(--tap-min);
  max-height: 120px;
  padding: 0.6rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel2);
  color: var(--text);
  font-size: 1rem;
  resize: none;
  font-family: inherit;
}
.chat-composer .btn-send {
  padding: 0.6rem 1rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 600;
  min-height: var(--tap-min);
  min-width: 56px;
  cursor: pointer;
  flex-shrink: 0;
}

/* Bottom nav */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-around;
  padding: 0.5rem;
  padding-bottom: calc(0.5rem + var(--safe-bottom));
  background: var(--panel);
  border-top: 1px solid var(--border);
  z-index: 100;
}
.nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  padding: 0.5rem 0.75rem;
  min-width: var(--tap-min);
  min-height: var(--tap-min);
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.75rem;
  cursor: pointer;
  position: relative;
}
.nav-btn.active { color: var(--accent); }
.nav-icon { font-size: 1.25rem; }
.nav-badge {
  position: absolute;
  top: 0;
  right: 0;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  background: var(--danger);
  color: #fff;
  font-size: 0.7rem;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Bottom sheet */
.bottom-sheet {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: flex-end;
  padding-bottom: var(--safe-bottom);
}
.bottom-sheet.hidden { display: none; }
.sheet-handle {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  width: 40px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
}
.sheet-content {
  width: 100%;
  background: var(--panel);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.sheet-content button {
  padding: 0.75rem 1rem;
  text-align: left;
  background: var(--panel2);
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
  min-height: var(--tap-min);
}
