:root {
  --bg: #f0f2f8;
  --sidebar: #151929;
  --sidebar-text: #a8b0c8;
  --sidebar-active: #ffffff;
  --card: #ffffff;
  --border: #e5e8f0;
  --text: #1e2433;
  --muted: #6b7280;
  --primary: #6366f1;
  --green: #10b981;
  --blue: #3b82f6;
  --yellow: #f59e0b;
  --pink: #ec4899;
  --red: #ef4444;
  --radius: 14px;
  --shadow: 0 4px 24px rgba(15, 23, 42, 0.06);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html {
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}
body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
}

.hidden { display: none !important; }

.login-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(1rem, env(safe-area-inset-top)) 1rem max(1rem, env(safe-area-inset-bottom));
  background: linear-gradient(135deg, #151929 0%, #1e293b 100%);
}
.login-card {
  background: var(--card);
  padding: 2.5rem;
  border-radius: var(--radius);
  width: min(400px, 92vw);
  text-align: center;
  box-shadow: var(--shadow);
}
.logo-mark {
  font-size: 2rem;
  width: 56px; height: 56px;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 1rem;
}
.logo-mark.sm { width: 40px; height: 40px; font-size: 1.25rem; }

.notif-prompt {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(1rem, env(safe-area-inset-top)) 1rem max(1rem, env(safe-area-inset-bottom));
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px);
}
.notif-prompt.hidden { display: none !important; }
.notif-prompt-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1.5rem 1.35rem;
  width: min(380px, 94vw);
  box-shadow: var(--shadow);
  text-align: center;
}
.notif-prompt-icon { font-size: 2rem; margin-bottom: 0.5rem; }
.notif-prompt-card h3 { margin: 0 0 0.5rem; font-size: 1.05rem; }
.notif-prompt-card p {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.875rem;
  line-height: 1.45;
}
.notif-ios-hint {
  font-size: 0.85rem;
  color: var(--accent, #f5c842);
  margin-top: 0.35rem;
}
.notif-ios-hint.hidden { display: none !important; }
.inbox-toolbar .toolbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.notif-prompt-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  flex-wrap: wrap;
}

.app { display: flex; min-height: 100vh; min-height: 100dvh; }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 90;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.sidebar-overlay.visible {
  display: block;
  opacity: 1;
}

.sidebar {
  width: 260px;
  background: var(--sidebar);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 1.25rem 0;
  flex-shrink: 0;
  z-index: 100;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1.25rem 1.5rem;
  color: #fff;
}
.sidebar-brand small { display: block; color: var(--sidebar-text); font-size: 0.75rem; }

.nav-section {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 1rem 1.25rem 0.35rem;
  color: #5c6478;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  border: none;
  background: transparent;
  color: var(--sidebar-text);
  text-align: left;
  padding: 0.65rem 1.25rem;
  cursor: pointer;
  font-size: 0.92rem;
}
.nav-item:hover { background: rgba(255,255,255,0.05); color: #fff; }
.nav-item.active {
  background: rgba(99, 102, 241, 0.2);
  color: var(--sidebar-active);
  border-left: 3px solid var(--primary);
}
.badge {
  margin-left: auto;
  background: var(--red);
  color: #fff;
  font-size: 0.7rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
}
.sidebar-foot { margin-top: auto; padding: 1rem 1.25rem; opacity: 0.6; font-size: 0.7rem; }

.main { flex: 1; padding: 1.5rem 2rem; overflow: auto; min-width: 0; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}
.topbar-left {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
  flex: 1;
}
.topbar h1 {
  font-size: 1.5rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-actions { display: flex; gap: 0.5rem; flex-shrink: 0; }

.btn-menu {
  display: none;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  font-size: 1.25rem;
  cursor: pointer;
  flex-shrink: 0;
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 0.55rem 1rem;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  min-height: 44px;
  -webkit-tap-highlight-color: transparent;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-accent { background: var(--green); color: #fff; }
.btn-ghost { background: var(--card); border: 1px solid var(--border); color: var(--text); }
.btn-danger-outline { background: transparent; border: 1px solid var(--red); color: var(--red); }
.btn-icon { background: transparent; border: none; font-size: 1.25rem; cursor: pointer; color: var(--muted); }

.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}
.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  box-shadow: var(--shadow);
  border-left: 4px solid var(--accent, var(--primary));
}
.stat-card .num { font-size: 1.75rem; font-weight: 700; }
.stat-card .lbl { font-size: 0.8rem; color: var(--muted); margin-top: 0.25rem; }
.stat-card.purple { --accent: var(--primary); }
.stat-card.green { --accent: var(--green); }
.stat-card.blue { --accent: var(--blue); }
.stat-card.yellow { --accent: var(--yellow); }
.stat-card.pink { --accent: var(--pink); }

.section-title { font-size: 1.1rem; margin-bottom: 1rem; color: var(--muted); }

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  border: 1px solid transparent;
}
.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 32px rgba(15, 23, 42, 0.1);
  border-color: var(--border);
}
.card h4 { font-size: 0.95rem; margin-bottom: 0.35rem; }
.card p { font-size: 0.82rem; color: var(--muted); line-height: 1.45; }
.card .meta { font-size: 0.75rem; color: var(--muted); margin-top: 0.5rem; }
.card.unread { border-left: 3px solid var(--red); }
.card.dead { opacity: 0.65; border-left: 3px solid #666; }

.split { display: grid; grid-template-columns: 220px 1fr; gap: 1.5rem; }
.accounts-layout {
  grid-template-columns: minmax(160px, 200px) minmax(220px, 1fr) minmax(280px, 1.2fr);
}
.accounts-layout.show-chats .accounts-panel { display: none; }
.accounts-layout.show-chats .account-chats-panel { display: flex !important; }
.panel-left, .panel-right, .panel-mid {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
  min-width: 0;
}
.account-chats-panel {
  flex-direction: column;
  min-height: 420px;
}
.account-chats-panel.hidden { display: none !important; }
.accounts-grid .card.has-pending {
  border-left: 3px solid var(--red);
  box-shadow: 0 0 0 1px rgba(239, 68, 68, 0.08);
}
.accounts-grid .card.selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.15);
}
.accounts-grid .card.has-restriction:not(.dead) {
  border-left: 3px solid #f59e0b;
  box-shadow: 0 0 0 1px rgba(245, 158, 11, 0.1);
}
.restriction-badge {
  display: inline-block;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  padding: 0.12rem 0.4rem;
  border-radius: 4px;
  margin-left: 0.25rem;
  vertical-align: middle;
  white-space: nowrap;
}
.restriction-badge.sev-warn { background: #fef3c7; color: #b45309; border: 1px solid #fcd34d; }
.restriction-badge.sev-error { background: #ffedd5; color: #c2410c; border: 1px solid #fdba74; }
.restriction-badge.sev-fatal { background: #fee2e2; color: #b91c1c; border: 1px solid #fca5a5; }
.restriction-badge.sev-muted { background: #f1f5f9; color: #64748b; border: 1px solid #cbd5e1; }
.chat-restriction-banner {
  padding: 0.55rem 0.85rem;
  font-size: 0.78rem;
  line-height: 1.35;
  border-bottom: 1px solid var(--border);
}
.chat-restriction-banner.sev-warn { background: #fffbeb; color: #92400e; }
.chat-restriction-banner.sev-error { background: #fff7ed; color: #9a3412; }
.chat-restriction-banner.sev-fatal { background: #fef2f2; color: #991b1b; }
.chat-restriction-banner.sev-muted { background: #f8fafc; color: #475569; }
.account-pending-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.35rem;
  height: 1.35rem;
  padding: 0 0.35rem;
  border-radius: 999px;
  background: var(--red);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  margin-left: 0.35rem;
}
.btn-back { padding: 0.45rem 0.75rem; min-height: auto; }

.tg-chat-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  margin-top: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
}
.tg-chat-item {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  width: 100%;
  border: none;
  border-bottom: 1px solid var(--border);
  background: transparent;
  text-align: left;
  padding: 0.85rem 0.95rem;
  cursor: pointer;
  font: inherit;
}
.tg-chat-item:last-child { border-bottom: none; }
.tg-chat-item:hover { background: var(--bg); }
.tg-chat-item.unread { background: rgba(99, 102, 241, 0.06); }
.tg-chat-item.unread .tg-chat-name { font-weight: 700; }
.tg-chat-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  flex-shrink: 0;
}
.tg-chat-body { flex: 1; min-width: 0; }
.tg-chat-top {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  align-items: baseline;
  margin-bottom: 0.2rem;
}
.tg-chat-name {
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tg-chat-time {
  font-size: 0.68rem;
  color: var(--muted);
  flex-shrink: 0;
}
.tg-chat-preview {
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.tg-chat-preview.unread-preview { color: var(--text); }
.tg-chat-empty {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.875rem;
}
.list { list-style: none; }
.list li {
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.875rem;
}
.list li:hover { background: var(--bg); }
.list li.active { background: rgba(99,102,241,0.12); color: var(--primary); font-weight: 600; }

.toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.muted { color: var(--muted); font-size: 0.875rem; }
.pager { display: flex; gap: 0.35rem; align-items: center; font-size: 0.85rem; }
.pager button { padding: 0.3rem 0.6rem; }

.upload-zone {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 160px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--card);
  cursor: pointer;
  color: var(--muted);
}
.info-banner {
  background: rgba(99,102,241,0.08);
  border: 1px solid rgba(99,102,241,0.2);
  padding: 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.875rem;
}

.form-row, .form-actions { display: flex; flex-direction: column; gap: 0.75rem; max-width: 520px; }
input, textarea, select {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.65rem 0.85rem;
  font: inherit;
  width: 100%;
}
.code-block {
  background: #1e2433;
  color: #e2e8f0;
  padding: 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.8rem;
  white-space: pre-wrap;
}

.modal { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.45); }
.modal-box {
  position: relative;
  background: var(--card);
  width: min(720px, 96vw);
  max-height: 90vh;
  max-height: 90dvh;
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 64px rgba(0,0,0,0.2);
}
.chat-modal-box { width: min(720px, 96vw); }
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-head strong {
  display: block;
  font-size: 1rem;
  line-height: 1.3;
  word-break: break-word;
}
.modal-head small {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
  margin-top: 0.2rem;
  word-break: break-all;
}
.chat-history {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.25rem;
  min-height: 280px;
  max-height: 50vh;
  max-height: 50dvh;
  background: #fafbfc;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
}
.msg { margin-bottom: 0.85rem; max-width: 88%; display: flex; flex-direction: column; }
.msg.peer { align-self: flex-start; align-items: flex-start; }
.msg.self { align-self: flex-end; align-items: flex-end; margin-left: auto; }
.msg-label {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 0.2rem;
  padding: 0 0.15rem;
}
.msg.peer .msg-label { color: #4f46e5; }
.msg.self .msg-label { color: #059669; }
.msg .bubble {
  display: inline-block;
  padding: 0.6rem 0.9rem;
  border-radius: 14px;
  font-size: 0.875rem;
  line-height: 1.45;
  white-space: pre-wrap;
  text-align: left;
  word-break: break-word;
  max-width: 100%;
}
.msg.peer .bubble {
  background: #fff;
  border: 1px solid var(--border);
  border-left: 3px solid #6366f1;
  border-bottom-left-radius: 4px;
}
.msg.self .bubble {
  background: #dcfce7;
  border: 1px solid #bbf7d0;
  border-right: 3px solid #10b981;
  border-bottom-right-radius: 4px;
}
.msg-time {
  font-size: 0.68rem;
  color: var(--muted);
  margin-top: 0.2rem;
  padding: 0 0.15rem;
}
.msg.self .msg-time { text-align: right; }
.pool-actions { margin-top: 1rem; }
#btn-notify.active { color: #fbbf24; }
.chat-media-wrap {
  display: block;
  margin-bottom: 0.35rem;
  max-width: min(100%, 320px);
}
.chat-media {
  display: block;
  max-width: 100%;
  border-radius: 12px;
  background: #000;
}
.chat-photo {
  cursor: zoom-in;
  object-fit: cover;
}
.chat-video {
  width: min(100%, 320px);
  max-height: 360px;
}
.muted-bubble {
  color: var(--muted);
  font-style: italic;
}
.chat-compose {
  padding: 1rem 1.25rem;
  padding-bottom: max(1rem, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--card);
}
.chat-input-row {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
}
.chat-input-row textarea {
  flex: 1;
  min-width: 0;
  resize: vertical;
}
.btn-attach {
  flex-shrink: 0;
  min-width: 44px;
  padding: 0.55rem 0.65rem;
  font-size: 1.1rem;
}
.chat-attach-preview {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin-bottom: 0.65rem;
  padding: 0.5rem 0.65rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.chat-attach-preview.hidden { display: none !important; }
.chat-attach-preview img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 8px;
}
.chat-attach-preview .attach-name {
  flex: 1;
  font-size: 0.8rem;
  color: var(--muted);
  word-break: break-all;
}
.chat-attach-preview .attach-remove {
  border: none;
  background: transparent;
  color: var(--red);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 0.25rem 0.5rem;
}
.chat-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.5rem; }
.chat-actions .btn { flex: 1 1 calc(50% - 0.25rem); min-width: 120px; }

.offline-banner {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #b91c1c;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.875rem;
  line-height: 1.45;
}
.chat-offline-note {
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.35);
  color: #92400e;
  padding: 0.55rem 0.85rem;
  border-radius: 10px;
  margin-bottom: 0.65rem;
  font-size: 0.8rem;
}

.bottom-nav {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 80;
  background: var(--card);
  border-top: 1px solid var(--border);
  padding: 0.35rem 0.5rem;
  padding-bottom: max(0.35rem, env(safe-area-inset-bottom));
  box-shadow: 0 -4px 24px rgba(15, 23, 42, 0.08);
}
.bottom-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.65rem;
  padding: 0.4rem 0.25rem;
  min-height: 56px;
  cursor: pointer;
  position: relative;
  -webkit-tap-highlight-color: transparent;
}
.bottom-nav-item.active { color: var(--primary); font-weight: 600; }
.bottom-nav-icon { font-size: 1.25rem; line-height: 1; }
.bottom-nav-label { line-height: 1.1; }
.bottom-badge {
  position: absolute;
  top: 0.2rem;
  right: calc(50% - 1.4rem);
  background: var(--red);
  color: #fff;
  font-size: 0.6rem;
  min-width: 1.1rem;
  height: 1.1rem;
  padding: 0 0.25rem;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.bottom-badge:empty,
.bottom-badge[data-zero="1"] { display: none; }

.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  left: auto;
  background: #1e2433;
  color: #fff;
  padding: 0.75rem 1.25rem;
  border-radius: 10px;
  z-index: 300;
  font-size: 0.875rem;
  max-width: min(420px, calc(100vw - 2rem));
}

/* Tablet */
@media (max-width: 900px) {
  .main { padding: 1.25rem 1rem; }
  .split { grid-template-columns: 1fr; }
  .accounts-layout { grid-template-columns: 1fr; }
  .accounts-layout.show-chats .accounts-panel { display: none; }
  .account-chats-panel { min-height: 55vh; }
  .cards-grid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
}

/* Phone */
@media (max-width: 768px) {
  .app { flex-direction: column; }

  .btn-menu { display: inline-flex; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(280px, 86vw);
    transform: translateX(-105%);
    transition: transform 0.25s ease;
    box-shadow: 8px 0 32px rgba(0, 0, 0, 0.2);
  }
  .sidebar.open { transform: translateX(0); }

  .main {
    padding: 0.85rem 0.85rem 5.5rem;
    padding-top: calc(0.85rem + env(safe-area-inset-top, 0px));
    padding-bottom: calc(5.5rem + env(safe-area-inset-bottom, 0px));
    width: 100%;
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    background: var(--bg);
    margin: 0 -0.85rem 1rem;
    padding: calc(0.65rem + env(safe-area-inset-top, 0px)) 0.85rem 0.65rem;
    border-bottom: 1px solid var(--border);
  }
  .topbar h1 { font-size: 1.15rem; }
  .topbar-actions .btn-label { display: none; }
  .topbar-actions .btn { padding: 0.55rem 0.75rem; min-width: 44px; }

  .bottom-nav { display: flex; }

  .stats-row {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.65rem;
    margin-bottom: 1.25rem;
  }
  .stat-card { padding: 0.85rem 1rem; }
  .stat-card .num { font-size: 1.45rem; }
  .stat-card .lbl { font-size: 0.72rem; }

  .cards-grid { grid-template-columns: 1fr; gap: 0.65rem; }
  .card { padding: 1rem; }
  .card:active { transform: scale(0.98); }

  .split { gap: 0.75rem; }
  .panel-left, .panel-right { padding: 0.85rem; }
  .panel-left h3, .panel-right h3 { font-size: 0.95rem; margin-bottom: 0.5rem; }

  .list {
    display: flex;
    gap: 0.5rem;
    overflow-x: auto;
    padding-bottom: 0.25rem;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .list::-webkit-scrollbar { display: none; }
  .list li {
    flex: 0 0 auto;
    white-space: nowrap;
    padding: 0.55rem 0.9rem;
    border: 1px solid var(--border);
    background: var(--bg);
  }
  .list li.active {
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.12);
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }
  .pager { justify-content: center; }
  .pager button { min-width: 44px; min-height: 44px; }

  .form-row, .form-actions { max-width: none; }
  .code-block { font-size: 0.72rem; padding: 0.75rem; }

  .login-card { padding: 1.75rem 1.25rem; }

  /* Full-screen chat on phone */
  .modal {
    align-items: stretch;
    justify-content: stretch;
  }
  .chat-modal-box {
    width: 100%;
    max-width: none;
    max-height: none;
    height: 100%;
    height: 100dvh;
    border-radius: 0;
    margin: 0;
  }
  .chat-history {
    max-height: none;
    min-height: 0;
    flex: 1;
  }
  .chat-compose textarea { font-size: 16px; }
  input, textarea, select { font-size: 16px; }

  .toast {
    left: 1rem;
    right: 1rem;
    bottom: calc(4.5rem + env(safe-area-inset-bottom));
    text-align: center;
  }

  body.chat-open .bottom-nav { display: none; }
  body.chat-open .main { padding-bottom: 0.85rem; }
}

@media (max-width: 380px) {
  .stats-row { grid-template-columns: 1fr; }
  .chat-actions .btn { flex: 1 1 100%; }
}

/* Mobile chat/account picker */
.picker-sheet {
  position: fixed;
  inset: 0;
  z-index: 250;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.picker-sheet.hidden { display: none !important; }
.picker-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
}
.picker-panel {
  position: relative;
  width: 100%;
  max-height: 70dvh;
  background: var(--card);
  border-radius: 16px 16px 0 0;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.15);
}
.picker-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1rem 0.75rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.picker-head strong {
  font-size: 1rem;
  word-break: break-word;
  padding-right: 0.5rem;
}
.picker-list {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.picker-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  border: none;
  border-bottom: 1px solid var(--border);
  background: transparent;
  text-align: left;
  padding: 1rem;
  font: inherit;
  font-size: 0.95rem;
  min-height: 52px;
  cursor: pointer;
}
.picker-item:active { background: var(--bg); }
.picker-unread {
  background: var(--red);
  color: #fff;
  font-size: 0.7rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  margin-left: 0.5rem;
  flex-shrink: 0;
}
