/* DeepRWA — Universal responsive stylesheet (rev.3.5.0)
   Touch-safe on phones, tablets, foldables, touch laptops, pens, mice. */

/* ============ 1. TOKENS ============ */
:root {
  --bg: #000000;
  --surface: #0a0a0a;
  --surface-2: #121212;
  --surface-3: #1a1a1a;
  --surface-4: #232323;
  --border: rgba(255,255,255,0.08);
  --border-strong: rgba(255,255,255,0.14);
  --text: #e6e8eb;
  --text-muted: #8b9199;
  --text-dim: #5c636d;
  --rwa-blue: #00a1de;
  --rwa-yellow: #fad201;
  --rwa-green: #20603d;
  --accent: #3b6ef5;
  --accent-hover: #2f5ee0;
  --accent-dim: rgba(59,110,245,0.14);
  --danger: #ef5350;
  --danger-hover: #e53935;
  --danger-soft: rgba(239,83,80,0.14);
  --danger-border: rgba(239,83,80,0.4);
  --success: #4caf50;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 18px;
  --font: 'Inter', system-ui, -apple-system, sans-serif;
  --sidebar-w: 260px;

  --space-xs: clamp(4px, 0.8vw, 6px);
  --space-sm: clamp(6px, 1.2vw, 10px);
  --space-md: clamp(10px, 1.8vw, 14px);
  --space-lg: clamp(14px, 2.4vw, 20px);

  --fs-xs: clamp(11px, 0.85vw + 8px, 13px);
  --fs-sm: clamp(12px, 0.9vw + 9px, 14px);
  --fs-base: clamp(13px, 0.95vw + 10px, 15px);
  --fs-md: clamp(14px, 1vw + 11px, 16px);
  --fs-lg: clamp(16px, 1.2vw + 12px, 19px);
  --fs-xl: clamp(19px, 1.8vw + 13px, 24px);
}

/* ============ 2. RESET ============ */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.15) transparent;
}
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.24); }
::-webkit-scrollbar-corner { background: transparent; }

html, body {
  height: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--fs-base);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: none;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  overflow: hidden;
  overflow-x: hidden;
}

.hidden { display: none !important; }
img, svg, video { max-width: 100%; height: auto; display: block; }
button { font-family: inherit; }

/* ============ 3. UNIVERSAL TOUCH SYSTEM ============ */

button,
a,
[role="button"],
.chip,
.nav-item,
.chat-item,
.file-item,
.file-item-wrap,
.file-item-menu,
.chat-item-menu,
.msg-action,
.msg-file-btn,
.attach-btn,
.send-btn,
.icon-btn,
.new-chat-btn,
.auth-btn,
.files-ms-btn,
.link-btn,
.vs-btn,
.settings-tab,
.modal-close,
.input-toggle,
.file-checkbox,
.file-remove,
.account-info,
.edit-actions button,
.session-item button,
.dropdown button,
.chat-menu button,
.file-menu button {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

button,
[role="button"],
.chip,
.nav-item,
.file-item,
.file-item-menu,
.chat-item-menu,
.msg-action,
.attach-btn,
.send-btn,
.icon-btn,
.new-chat-btn,
.auth-btn,
.files-ms-btn,
.link-btn,
.vs-btn,
.settings-tab,
.modal-close,
.input-toggle,
.file-remove,
.dropdown button,
.chat-menu button,
.file-menu button {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;
}

button > svg,
button > i,
.chip > svg,
.chip > i,
.nav-item > svg,
.nav-item > i,
.chat-item > svg,
.chat-item > i,
.file-item > svg,
.file-item > i,
.settings-tab > svg,
.settings-tab > i,
.msg-action > svg,
.msg-action > i,
.attach-btn > svg,
.attach-btn > i,
.send-btn > svg,
.send-btn > i,
.icon-btn > svg,
.icon-btn > i,
.new-chat-btn > svg,
.new-chat-btn > i,
.auth-btn > svg,
.auth-btn > i,
.modal-close > svg,
.modal-close > i,
.input-toggle > svg,
.input-toggle > i,
.files-ms-btn > svg,
.files-ms-btn > i,
.link-btn > svg,
.link-btn > i,
.vs-btn > svg,
.vs-btn > i,
.file-item-menu > svg,
.file-item-menu > i,
.chat-item-menu > svg,
.chat-item-menu > i,
.file-remove > svg,
.file-remove > i,
.dropdown button > svg,
.dropdown button > i,
.chat-menu button > svg,
.chat-menu button > i,
.file-menu button > svg,
.file-menu button > i {
  pointer-events: none;
}

button:active:not(:disabled),
[role="button"]:active,
.chip:active,
.nav-item:active,
.chat-item:active,
.file-item:active,
.msg-action:active,
.attach-btn:active,
.send-btn:active:not(:disabled),
.icon-btn:active,
.new-chat-btn:active,
.auth-btn:active,
.files-ms-btn:active,
.link-btn:active,
.vs-btn:active:not(:disabled),
.settings-tab:active,
.modal-close:active,
.input-toggle:active,
.file-item-menu:active,
.chat-item-menu:active,
.file-remove:active,
.dropdown button:active,
.chat-menu button:active,
.file-menu button:active {
  opacity: 0.72;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible,
[role="button"]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

#input,
.modal-input,
.edit-textarea,
.code-input,
.share-link-row input {
  font-size: max(16px, var(--fs-md));
}

.bubble,
.assistant-text,
.modal-input,
.edit-textarea,
.share-link-row input {
  user-select: text;
  -webkit-user-select: text;
}

.bubble, .assistant-text, .file-item-name, .chat-item-title,
.account-email, .modal-body p, .modal-body h3 {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.app {
  display: flex;
  height: 100vh;
  height: 100dvh;
  height: var(--vvh, 100dvh);
  width: 100%;
  min-height: 0;
}

/* ============ 4. SIDEBAR ============ */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100%;
  transition: width 0.2s, transform 0.25s;
  overflow: hidden;
  min-width: 0;
}
body.sidebar-collapsed .sidebar { width: 0; border-right: none; }

.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md);
  border-bottom: 1px solid var(--border);
  gap: var(--space-sm);
  min-width: 0;
}
.brand { display: flex; align-items: center; gap: var(--space-sm); flex: 1; min-width: 0; }
.brand-logo { width: 30px; height: 30px; border-radius: 8px; flex-shrink: 0; }
.brand-name {
  font-weight: 700;
  font-size: var(--fs-md);
  display: inline-flex;
  align-items: baseline;
  white-space: nowrap;
}
.b-deep { color: var(--text); }
.b-r { color: var(--rwa-blue); }
.b-w { color: var(--rwa-yellow); }
.b-a { color: var(--rwa-green); }
.brand-name-lg { font-size: var(--fs-xl); font-weight: 800; letter-spacing: -0.02em; }

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; }

.new-chat-btn {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin: var(--space-md) var(--space-md) var(--space-xs);
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: var(--fs-sm);
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, border-color 0.15s;
  min-height: 44px;
}
.new-chat-btn:hover { background: var(--surface-3); border-color: var(--border-strong); }
.new-chat-btn svg { width: 17px; height: 17px; }

.sidebar-nav {
  display: flex;
  flex-direction: column;
  padding: var(--space-xs) var(--space-md);
  gap: 2px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 8px 12px;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--text-muted);
  font-size: var(--fs-sm);
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, color 0.15s;
  min-height: 44px;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--surface-2); color: var(--text); }
.nav-item svg { width: 16px; height: 16px; }

/* ============ 5. MULTI-SELECT BAR ============ */
.files-multiselect-bar,
.chats-multiselect-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  padding: 5px 8px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -ms-overflow-style: none;
  flex-shrink: 0;
}
.files-multiselect-bar::-webkit-scrollbar,
.chats-multiselect-bar::-webkit-scrollbar { display: none; }

.files-ms-right {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
.files-ms-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 0 10px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  min-height: 36px;
  height: 36px;
  white-space: nowrap;
  flex-shrink: 0;
}
.files-ms-btn:hover { background: var(--surface-3); border-color: var(--border-strong); }
.files-ms-btn.danger { color: var(--danger); border-color: var(--danger-border); }
.files-ms-btn.danger:hover { background: rgba(239,83,80,0.1); }
.files-ms-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.files-ms-btn svg { width: 13px; height: 13px; flex-shrink: 0; }

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--space-xs) var(--space-sm);
  min-height: 0;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.sidebar-empty {
  padding: var(--space-lg) var(--space-md);
  text-align: center;
  color: var(--text-dim);
  font-size: var(--fs-sm);
  line-height: 1.5;
}
.sidebar-empty p {
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 0.35rem;
  font-size: var(--fs-sm);
}

.sidebar-section {
  padding: var(--space-md) var(--space-md) var(--space-xs);
  font-size: var(--fs-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
  position: relative;
  min-height: 44px;
}
.chat-item:hover { background: var(--surface-2); }
.chat-item.active { background: var(--surface-3); }
.chat-item.selected { background: rgba(59,110,245,0.10); }
.chat-item.selected:hover { background: rgba(59,110,245,0.16); }
.chat-item-icon { width: 15px; height: 15px; color: var(--text-muted); flex-shrink: 0; pointer-events: none; }
.chat-item-title {
  flex: 1;
  font-size: var(--fs-sm);
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  pointer-events: none;
}
.chat-item-menu {
  background: transparent;
  border: none;
  color: var(--text-muted);
  width: 36px;
  height: 36px;
  min-width: 36px;
  min-height: 36px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  cursor: pointer;
  opacity: 1;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}
.chat-item-menu:hover { background: var(--surface-3); color: var(--text); }
.chat-item-menu svg { width: 15px; height: 15px; }

.chat-item .file-checkbox {
  width: 32px;
  height: 32px;
  min-width: 32px;
  min-height: 32px;
  margin-left: 0;
  margin-right: 0;
  position: relative;
  display: inline-block;
  flex-shrink: 0;
  cursor: pointer;
}
.chat-item .file-checkbox input { position: absolute; opacity: 0; width: 0; height: 0; }
.chat-item .file-checkbox-mark {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 20px; height: 20px;
  border: 1.5px solid var(--border-strong);
  border-radius: 5px;
  background: var(--surface);
  transition: background 0.15s, border-color 0.15s;
  pointer-events: none;
}
.chat-item .file-checkbox input:checked + .file-checkbox-mark {
  background: var(--accent);
  border-color: var(--accent);
}
.chat-item .file-checkbox input:checked + .file-checkbox-mark::after {
  content: '';
  position: absolute;
  left: 5px; top: 1px;
  width: 5px; height: 10px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.file-item-wrap {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-xs);
  border-radius: 8px;
  position: relative;
  transition: background 0.12s;
  min-height: 48px;
}
.file-item-wrap:hover { background: var(--surface-2); }
.file-item {
  flex: 1;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 8px;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  min-width: 0;
  min-height: 44px;
}
.file-thumb-sm {
  width: 38px; height: 38px;
  min-width: 38px; min-height: 38px;
  border-radius: 6px;
  object-fit: cover;
  background: var(--surface-3);
  flex-shrink: 0;
  display: grid;
  place-items: center;
  color: var(--text-muted);
}
.file-thumb-sm svg { width: 18px; height: 18px; }
.file-item-info { flex: 1; min-width: 0; }
.file-item-name { font-size: var(--fs-sm); color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-item-meta { font-size: var(--fs-xs); color: var(--text-dim); }
.file-item-menu {
  flex-shrink: 0;
  background: transparent;
  border: none;
  color: var(--text-muted);
  width: 36px; height: 36px;
  min-width: 36px; min-height: 36px;
  border-radius: 6px;
  display: grid; place-items: center;
  cursor: pointer;
  opacity: 1;
  transition: background 0.15s, color 0.15s;
}
.file-item-menu:hover { background: var(--surface-3); color: var(--text); }
.file-item-menu svg { width: 15px; height: 15px; }

.file-checkbox {
  position: relative;
  display: inline-block;
  width: 44px; height: 44px;
  min-width: 44px; min-height: 44px;
  flex-shrink: 0;
  cursor: pointer;
  margin-left: 0;
}
.file-checkbox input { position: absolute; opacity: 0; width: 0; height: 0; }
.file-checkbox-mark {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 22px; height: 22px;
  border: 1.5px solid var(--border-strong);
  border-radius: 5px;
  background: var(--surface);
  transition: background 0.15s, border-color 0.15s;
  pointer-events: none;
}
.file-checkbox input:checked + .file-checkbox-mark { background: var(--accent); border-color: var(--accent); }
.file-checkbox input:checked + .file-checkbox-mark::after {
  content: '';
  position: absolute;
  left: 6px; top: 2px;
  width: 5px; height: 10px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.chat-menu, .file-menu, .dropdown {
  position: fixed;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 4px;
  min-width: 180px;
  max-width: calc(100vw - 20px);
  z-index: 200;
  box-shadow: 0 10px 30px rgba(0,0,0,0.6);
}
.chat-menu button, .file-menu button, .dropdown button {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  padding: 10px 12px;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: var(--fs-sm);
  cursor: pointer;
  border-radius: 6px;
  text-align: left;
  transition: background 0.1s;
  min-height: 44px;
}
.chat-menu button:hover, .file-menu button:hover, .dropdown button:hover { background: var(--surface-3); }
.chat-menu button.danger, .file-menu button.danger, .dropdown button.danger { color: var(--danger); }
.chat-menu button svg, .file-menu button svg, .dropdown button svg { width: 14px; height: 14px; }
.dropdown-divider { height: 1px; background: var(--border); margin: 4px 0; }

.sidebar-footer {
  padding: var(--space-md);
  padding-bottom: calc(var(--space-md) + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
  position: relative;
  flex-shrink: 0;
}
.auth-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 10px 12px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: var(--fs-sm);
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  min-height: 44px;
}
.auth-btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
.auth-btn svg { width: 16px; height: 16px; }
.auth-btn.account { justify-content: space-between; }
.account-info { display: flex; align-items: center; gap: var(--space-sm); min-width: 0; flex: 1; }
.account-avatar {
  width: 28px; height: 28px;
  min-width: 28px; min-height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #7d5cff);
  display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: var(--fs-sm);
  flex-shrink: 0;
  pointer-events: none;
}
.account-email {
  font-size: var(--fs-sm);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
  min-width: 0;
  pointer-events: none;
}
.auth-btn.account > svg { pointer-events: none; }

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 40;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}
.sidebar-backdrop.show {
  opacity: 1;
  pointer-events: auto;
}

/* ============ 6. MAIN ============ */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100%;
  overflow: hidden;
}
.topbar {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-lg);
  padding-top: calc(var(--space-md) + env(safe-area-inset-top, 0px));
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
  min-height: 56px;
}
.menu-btn { display: none; }
.expand-btn { display: grid; }
.topbar-brand { display: flex; align-items: center; gap: var(--space-sm); min-width: 0; }
.topbar-logo { width: 26px; height: 26px; border-radius: 7px; flex-shrink: 0; }
.topbar-brand .brand-name { font-size: var(--fs-md); font-weight: 700; }

/* ============ 7. CHAT ============ */
.chat {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--space-lg) var(--space-md) var(--space-md);
  scroll-behavior: smooth;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
}
.chat > * {
  max-width: 780px;
  margin-left: auto;
  margin-right: auto;
}

.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 55vh;
  gap: var(--space-md);
  padding: var(--space-lg);
  user-select: none;
  -webkit-user-select: none;
}
.welcome-logo {
  width: clamp(64px, 12vw, 96px);
  height: auto;
  border-radius: 18px;
}
.welcome h1 { letter-spacing: -0.02em; line-height: 1.1; }
.welcome p {
  color: var(--text-muted);
  max-width: 520px;
  font-size: var(--fs-md);
  line-height: 1.55;
}
.welcome p strong { color: var(--text); font-weight: 600; }
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  justify-content: center;
  margin-top: var(--space-sm);
}
.chip {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: var(--fs-sm);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  min-height: 44px;
}
.chip:hover { background: var(--surface-2); color: var(--text); border-color: var(--border-strong); }

.msg { display: flex; margin-bottom: var(--space-lg); }
.msg-user {
  justify-content: flex-end;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--space-xs);
}
.msg-user .bubble {
  background: var(--surface-2);
  color: var(--text);
  padding: var(--space-md) var(--space-md);
  border-radius: 16px 16px 4px 16px;
  max-width: min(80%, 620px);
  line-height: 1.55;
  font-size: var(--fs-md);
  border: 1px solid var(--border);
  min-width: 0;
}
.msg-files {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
  max-width: min(80%, 620px);
  justify-content: flex-end;
}
.msg-file-thumb {
  width: clamp(72px, 14vw, 120px);
  height: clamp(72px, 14vw, 120px);
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
  pointer-events: none;
}
.msg-file-doc {
  width: clamp(60px, 12vw, 90px);
  height: clamp(60px, 12vw, 90px);
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  display: grid;
  place-items: center;
  color: var(--text-muted);
  cursor: pointer;
  transition: transform 0.15s, background 0.15s, border-color 0.15s;
}
.msg-file-doc svg { width: 28px; height: 28px; pointer-events: none; }
button.msg-file-btn { background: transparent; border: none; padding: 0; cursor: pointer; display: inline-block; }

.msg-assistant { gap: var(--space-sm); align-items: flex-start; }
.avatar {
  flex-shrink: 0;
  width: 30px; height: 30px;
  min-width: 30px; min-height: 30px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  margin-top: 2px;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
.assistant-body { flex: 1; min-width: 0; }
.assistant-name {
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
}
.assistant-text {
  line-height: 1.65;
  font-size: var(--fs-md);
  color: var(--text);
  min-width: 0;
}
.assistant-text p { margin: 0 0 0.75rem; }
.assistant-text p:last-child { margin-bottom: 0; }
.assistant-text strong { color: #fff; font-weight: 600; }
.assistant-text ul, .assistant-text ol { margin: 0 0 0.75rem 1.25rem; }
.assistant-text li { margin-bottom: 0.25rem; }
.assistant-text a { color: var(--accent); }
.assistant-text code {
  background: var(--surface);
  padding: 0.1rem 0.35rem;
  border-radius: 5px;
  font-family: ui-monospace, monospace;
  font-size: 0.86em;
}
.assistant-text pre {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: var(--space-md);
  overflow-x: auto;
  margin: 0 0 0.75rem;
  font-size: var(--fs-sm);
  max-width: 100%;
}
.assistant-text pre code { background: transparent; padding: 0; }
.assistant-text table {
  border-collapse: collapse;
  width: 100%;
  margin: 0 0 0.75rem;
  font-size: var(--fs-sm);
  display: block;
  overflow-x: auto;
  max-width: 100%;
}
.assistant-text th, .assistant-text td {
  border: 1px solid var(--border);
  padding: 0.4rem 0.65rem;
  text-align: left;
  white-space: nowrap;
}
.assistant-text th { background: var(--surface); font-weight: 600; }
.assistant-text blockquote {
  border-left: 3px solid var(--border-strong);
  padding-left: 0.9rem;
  color: var(--text-muted);
  margin: 0 0 0.75rem;
}

/* ============================================================
   MESSAGE ACTIONS
   Buttons are 44×44 (Apple HIG minimum). The .active / .copied
   variants are declared with the SAME or HIGHER specificity than
   :hover so they cannot be clobbered by the touch-device hover
   reset (this was the like-button bug).
   ============================================================ */
.msg-actions {
  display: flex;
  gap: 2px;
  margin-top: 0.35rem;
  opacity: 1;
  flex-wrap: wrap;
}
.msg-actions-user { justify-content: flex-end; }
.msg-action {
  background: transparent;
  border: none;
  color: var(--text-dim);
  width: 44px; height: 44px;
  min-width: 44px; min-height: 44px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.msg-action:hover { background: var(--surface-2); color: var(--text); }
.msg-action.active,
.msg-action.active:hover { color: var(--accent); }
.msg-action.active[data-action="dislike"],
.msg-action.active[data-action="dislike"]:hover { color: var(--danger); }
.msg-action.copied,
.msg-action.copied:hover { color: var(--rwa-green); }
.msg-action svg { width: 16px; height: 16px; }

.version-switcher {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  margin-top: 0.35rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 6px;
  font-size: var(--fs-xs);
  color: var(--text-muted);
}
.vs-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  width: 36px; height: 36px;
  min-width: 36px; min-height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.vs-btn:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.vs-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.vs-btn svg { width: 13px; height: 13px; }
.vs-label { font-weight: 500; padding: 0 0.2rem; }

.edit-area { width: min(80%, 620px); max-width: 100%; }
.edit-textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  color: var(--text);
  font-family: inherit;
  font-size: max(16px, var(--fs-md));
  padding: var(--space-md);
  resize: none;
  outline: none;
  line-height: 1.55;
  min-height: 60px;
}
.edit-textarea:focus { border-color: var(--accent); }
.edit-actions {
  display: flex;
  gap: var(--space-xs);
  justify-content: flex-end;
  margin-top: var(--space-sm);
  flex-wrap: wrap;
}
.edit-actions .btn-primary,
.edit-actions .btn-secondary {
  width: auto;
  padding: 0.55rem 1rem;
  font-size: var(--fs-sm);
  margin: 0;
  min-height: 44px;
}
.edit-actions svg { width: 14px; height: 14px; }

.thinking {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.35rem;
  color: var(--text-muted);
  font-size: var(--fs-sm);
}
.thinking .dot {
  width: 5px; height: 5px;
  background: var(--text-dim);
  border-radius: 50%;
  animation: pulse 1.2s infinite ease-in-out;
}
.thinking .dot:nth-child(2) { animation-delay: 0.15s; }
.thinking .dot:nth-child(3) { animation-delay: 0.3s; }
.thinking-label { margin-left: 0.3rem; }
@keyframes pulse {
  0%, 80%, 100% { transform: scale(0.55); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* ============ 8. COMPOSER ============ */
.composer {
  padding: var(--space-md) var(--space-md);
  padding-bottom: calc(var(--space-md) + env(safe-area-inset-bottom, 0px));
  background: var(--bg);
  flex-shrink: 0;
}
.composer > * {
  max-width: 780px;
  margin-left: auto;
  margin-right: auto;
}
.file-previews {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
  padding-bottom: var(--space-sm);
}
.file-chip {
  position: relative;
  width: 62px; height: 62px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.file-thumb { width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
.file-icon { color: var(--text-muted); }
.file-icon svg { width: 22px; height: 22px; }
.file-remove {
  position: absolute;
  top: 3px; right: 3px;
  width: 26px; height: 26px;
  min-width: 26px; min-height: 26px;
  border-radius: 50%;
  background: rgba(0,0,0,0.75);
  border: none;
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
}
.file-remove:hover { background: rgba(0,0,0,0.9); }
.file-remove svg { width: 13px; height: 13px; }

.composer-inner {
  display: flex;
  align-items: flex-end;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 6px;
  gap: var(--space-xs);
}
.attach-btn {
  flex-shrink: 0;
  width: 44px; height: 44px;
  min-width: 44px; min-height: 44px;
  border-radius: 50%;
  background: transparent;
  border: none;
  color: var(--text-muted);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.attach-btn:hover { background: var(--surface-2); color: var(--text); }
.attach-btn svg { width: 18px; height: 18px; }

#input {
  flex: 1;
  min-width: 0;
  background: transparent !important;
  border: none !important;
  outline: none !important;
  box-shadow: none !important;
  color: var(--text);
  font-family: inherit;
  font-size: max(16px, var(--fs-md));
  padding: var(--space-sm) var(--space-xs);
  resize: none;
  max-height: 400px;
  line-height: 1.5;
  -webkit-appearance: none;
}
#input:focus, #input:active {
  outline: none !important;
  box-shadow: none !important;
  border: none !important;
}
#input::placeholder { color: var(--text-dim); }

.send-btn {
  flex-shrink: 0;
  width: 44px; height: 44px;
  min-width: 44px; min-height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.15s;
}
.send-btn:hover:not(:disabled):not(.generating) { background: var(--accent-hover); }
.send-btn:disabled { background: var(--surface-2); color: var(--text-dim); cursor: not-allowed; }
.send-btn.generating {
  background: var(--danger-soft);
  border: 1px solid var(--danger-border);
  color: var(--danger);
  animation: pulse-stop 1.4s ease-in-out infinite;
}
.send-btn.generating:hover { background: rgba(239,83,80,0.22); }
@keyframes pulse-stop {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239,83,80,0.25); }
  50% { box-shadow: 0 0 0 6px rgba(239,83,80,0); }
}
.send-btn svg { width: 18px; height: 18px; }

.composer-disclaimer {
  font-size: var(--fs-xs);
  color: var(--text-dim);
  text-align: center;
  margin-top: var(--space-sm);
  line-height: 1.4;
  padding: 0 var(--space-sm);
  user-select: none;
}

/* ============ 9. MODALS ============ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.72);
  display: grid;
  place-items: center;
  z-index: 100;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  padding: var(--space-md);
  padding-top: calc(var(--space-md) + env(safe-area-inset-top, 0px));
  padding-bottom: calc(var(--space-md) + env(safe-area-inset-bottom, 0px));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  max-width: 420px;
  width: 100%;
  position: relative;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
  max-height: calc(100vh - 2 * var(--space-md));
  max-height: calc(100dvh - 2 * var(--space-md));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.modal-settings { max-width: 720px; padding: 0; }
.modal-close {
  position: absolute;
  top: var(--space-sm);
  right: var(--space-sm);
  background: transparent;
  border: none;
  color: var(--text-muted);
  width: 44px; height: 44px;
  min-width: 44px; min-height: 44px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  cursor: pointer;
  z-index: 2;
  transition: background 0.15s, color 0.15s;
}
.modal-close:hover { background: var(--surface-2); color: var(--text); }
.modal-close svg { width: 18px; height: 18px; }
.modal-body h3 {
  font-size: var(--fs-lg);
  margin-bottom: var(--space-xs);
}
.modal-sub {
  color: var(--text-muted);
  font-size: var(--fs-sm);
  margin-bottom: var(--space-lg);
  line-height: 1.5;
}
.modal-input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  font-size: max(16px, var(--fs-md));
  padding: var(--space-md);
  outline: none;
  margin-bottom: var(--space-sm);
  transition: border-color 0.15s;
  min-height: 44px;
}
.modal-input:focus { border-color: var(--accent); }
.input-wrap { position: relative; margin-bottom: var(--space-sm); }
.input-wrap .modal-input { margin-bottom: 0; padding-right: 3rem; }
.input-toggle {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  color: var(--text-muted);
  width: 36px; height: 36px;
  min-width: 36px; min-height: 36px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.input-toggle:hover { color: var(--text); background: var(--surface-3); }
.input-toggle svg { width: 16px; height: 16px; }
.code-input {
  text-align: center;
  font-size: max(16px, var(--fs-xl));
  letter-spacing: 6px;
  font-weight: 700;
  padding-left: var(--space-md);
  padding-right: var(--space-md);
}
.btn-primary {
  width: 100%;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: var(--space-md);
  font-size: var(--fs-md);
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  margin-top: var(--space-xs);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  min-height: 44px;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: var(--space-md) var(--space-lg);
  font-size: var(--fs-md);
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  min-height: 44px;
  transition: background 0.15s;
}
.btn-secondary:hover { background: var(--surface-3); }
.btn-danger {
  background: var(--danger);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: var(--space-md) var(--space-lg);
  font-size: var(--fs-md);
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
  transition: background 0.15s;
}
.btn-danger:hover { background: var(--danger-hover); }
.modal-switch {
  text-align: center;
  font-size: var(--fs-sm);
  color: var(--text-muted);
  margin-top: var(--space-md);
}
.modal-switch a { color: var(--accent); text-decoration: none; cursor: pointer; }
.modal-actions {
  display: flex;
  gap: var(--space-sm);
  justify-content: flex-end;
  margin-top: var(--space-md);
  flex-wrap: wrap;
}
.modal-actions .btn-primary,
.modal-actions .btn-danger,
.modal-actions .btn-secondary {
  width: auto;
  min-width: 100px;
  padding: 10px 20px;
  margin: 0;
  flex: 0 0 auto;
}
.link-btn {
  background: transparent;
  border: none;
  color: var(--accent);
  font-size: var(--fs-sm);
  cursor: pointer;
  padding: var(--space-sm) 0;
  margin-top: var(--space-sm);
  text-align: center;
  display: block;
  margin-left: auto;
  margin-right: auto;
  transition: opacity 0.15s;
  min-height: 44px;
}
.link-btn:hover:not(:disabled) { text-decoration: underline; }
.link-btn:disabled { opacity: 0.35; cursor: not-allowed; text-decoration: none; pointer-events: none; }
.share-link-row { display: flex; gap: var(--space-sm); margin-top: var(--space-md); flex-wrap: wrap; }
.share-link-row input {
  flex: 1;
  min-width: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: ui-monospace, monospace;
  font-size: max(16px, var(--fs-sm));
  padding: var(--space-md);
  outline: none;
}
.share-link-row .btn-primary { width: auto; padding: var(--space-md) var(--space-lg); margin: 0; }

/* ============ 10. SETTINGS ============ */
.settings-layout {
  display: flex;
  min-height: 480px;
  min-height: min(480px, calc(100vh - 2 * var(--space-md)));
  min-height: min(480px, calc(100dvh - 2 * var(--space-md)));
}
.settings-sidebar {
  width: 180px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  padding: var(--space-md) var(--space-xs);
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--surface);
  border-radius: var(--radius-lg) 0 0 var(--radius-lg);
}
.settings-tab {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 10px 12px;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--text-muted);
  font-size: var(--fs-sm);
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, color 0.15s;
  min-height: 44px;
}
.settings-tab:hover { background: var(--surface-2); color: var(--text); }
.settings-tab.active { background: var(--surface-3); color: var(--text); }
.settings-tab svg { width: 15px; height: 15px; }
.settings-content {
  flex: 1;
  padding: var(--space-lg);
  overflow-y: auto;
  max-height: 70vh;
  max-height: min(70vh, calc(100dvh - 2 * var(--space-md)));
  min-width: 0;
  -webkit-overflow-scrolling: touch;
}
.settings-section { margin-bottom: var(--space-lg); }
.settings-section h4 {
  font-size: var(--fs-md);
  font-weight: 600;
  margin-bottom: 0.35rem;
}
.settings-section p {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  margin-bottom: var(--space-md);
  line-height: 1.5;
}
.settings-section .btn-secondary,
.settings-section .btn-primary,
.settings-section .btn-danger {
  width: auto;
  padding: var(--space-sm) var(--space-md);
  font-size: var(--fs-sm);
  margin: 0;
  min-height: 44px;
}
.settings-divider { height: 1px; background: var(--border); margin: var(--space-lg) 0; }
.danger-zone {
  border: 1px solid var(--danger-border);
  border-radius: 10px;
  padding: var(--space-md);
  background: rgba(239,83,80,0.04);
}
.danger-zone h4 { color: var(--danger); }
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: var(--fs-xs);
  font-weight: 600;
}
.status-badge.on { background: rgba(76,175,80,0.15); color: var(--success); }
.status-badge.off { background: rgba(255,255,255,0.06); color: var(--text-muted); }
.session-item {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: var(--space-sm);
  flex-wrap: wrap;
}
.session-info { flex: 1; min-width: 0; }
.session-device { font-size: var(--fs-sm); color: var(--text); margin-bottom: 0.15rem; }
.session-meta { font-size: var(--fs-xs); color: var(--text-dim); }
.session-current { background: rgba(76,175,80,0.08); border-color: rgba(76,175,80,0.3); }
.qr-wrap {
  text-align: center;
  margin: var(--space-md) 0;
  padding: var(--space-md);
  background: var(--surface-2);
  border-radius: 12px;
}
.qr-wrap img { background: #fff; padding: 8px; border-radius: 8px; margin: 0 auto; max-width: 240px; }
.secret-box {
  display: flex;
  gap: var(--space-sm);
  align-items: center;
  margin-top: var(--space-sm);
  background: var(--surface-2);
  padding: var(--space-md);
  border-radius: 8px;
  font-family: ui-monospace, monospace;
  font-size: var(--fs-xs);
  word-break: break-all;
  flex-wrap: wrap;
}
.secret-box code { flex: 1; color: var(--text-muted); min-width: 0; }
.secret-box button { flex-shrink: 0; }

/* ============ 11. FILE VIEW MODAL ============ */
.modal-file-view {
  max-width: 90vw;
  width: 900px;
  padding: var(--space-md);
}
.file-view-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  max-height: 85vh;
  max-height: 85dvh;
}
.file-view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  padding-bottom: var(--space-sm);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.file-view-name {
  font-weight: 600;
  font-size: var(--fs-md);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  flex: 1;
}
.file-view-content {
  flex: 1;
  overflow: auto;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  -webkit-overflow-scrolling: touch;
}
.file-view-img {
  max-width: 100%;
  max-height: 70vh;
  max-height: 70dvh;
  border-radius: 10px;
  margin: 0 auto;
}
.file-view-pdf {
  width: 100%;
  height: 70vh;
  height: 70dvh;
  border: 1px solid var(--border);
  border-radius: 10px;
}
.file-view-other { text-align: center; color: var(--text-muted); padding: var(--space-lg); }
.file-view-other svg { width: 48px; height: 48px; margin: 0 auto var(--space-md); }
.file-view-other p { margin-bottom: var(--space-md); }

/* ============ 12. PROFILE ============ */
.profile-header { text-align: center; padding-bottom: var(--space-md); }
.profile-avatar {
  width: 72px; height: 72px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #7d5cff);
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 700;
  font-size: var(--fs-xl);
  margin: 0 auto var(--space-sm);
}
.profile-header h3 { font-size: var(--fs-lg); margin-bottom: var(--space-xs); }
.profile-header .modal-sub { margin-bottom: 0; }

/* ============ 13. TOASTS ============ */
.toast-container {
  position: fixed;
  top: calc(var(--space-md) + env(safe-area-inset-top, 0px));
  right: var(--space-md);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  pointer-events: none;
  max-width: calc(100vw - 2 * var(--space-md));
}
.toast {
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: var(--space-md) var(--space-md);
  font-size: var(--fs-sm);
  color: var(--text);
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  max-width: 340px;
  animation: slideIn 0.2s ease;
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  word-break: break-word;
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.info { border-left: 3px solid var(--accent); }
.toast svg { width: 16px; height: 16px; flex-shrink: 0; }
@keyframes slideIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: none; }
}

.spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   14. HOVER-NONE OVERRIDES (touch / pen)
   Neutralises hover so the FIRST tap fires the action.
   Every stateful class (.active, .copied, .selected) has its own
   matching :hover rule with EQUAL OR HIGHER specificity, so the
   generic hover reset can never override the state colour.
   ============================================================ */
@media (hover: none) {
  /* --- Generic resets: cancel the visual change on non-state elements --- */
  .icon-btn:hover { background: transparent; color: var(--text-muted); }
  .chat-item:hover { background: transparent; }
  .file-item-wrap:hover { background: transparent; }
  .chip:hover { background: var(--surface); border-color: var(--border); color: var(--text-muted); }
  .nav-item:hover { background: transparent; color: var(--text-muted); }
  .settings-tab:hover { background: transparent; color: var(--text-muted); }
  .msg-action:hover { background: transparent; color: var(--text-dim); }
  .files-ms-btn:hover { background: transparent; border-color: var(--border); }
  .files-ms-btn.danger:hover { background: transparent; }
  .new-chat-btn:hover { background: var(--surface-2); border-color: var(--border); }
  .auth-btn:hover { background: transparent; border-color: var(--border); }
  .attach-btn:hover { background: transparent; color: var(--text-muted); }
  .modal-close:hover { background: transparent; color: var(--text-muted); }
  .input-toggle:hover { color: var(--text-muted); background: transparent; }
  .file-item-menu:hover { background: transparent; color: var(--text-muted); }
  .chat-item-menu:hover { background: transparent; color: var(--text-muted); }
  .file-remove:hover { background: rgba(0,0,0,0.75); }
  .btn-primary:hover:not(:disabled) { background: var(--accent); }
  .btn-secondary:hover { background: var(--surface-2); }
  .btn-danger:hover { background: var(--danger); }
  .dropdown button:hover,
  .chat-menu button:hover,
  .file-menu button:hover { background: transparent; }
  .link-btn:hover:not(:disabled) { text-decoration: none; }
  .assistant-text a:hover { text-decoration: none; }
  .msg-file-thumb:hover,
  .msg-file-doc:hover { transform: none; border-color: var(--border); }
  .vs-btn:hover:not(:disabled) { background: transparent; color: var(--text-muted); }

  /* --- State-preserving rules: MUST come after the resets above. ---
     These keep the state colour even while the browser holds a
     sticky :hover on a tapped element. This is what fixes the
     like button on touch devices. */
  .msg-action.active,
  .msg-action.active:hover { color: var(--accent); }
  .msg-action.active[data-action="dislike"],
  .msg-action.active[data-action="dislike"]:hover { color: var(--danger); }
  .msg-action.copied,
  .msg-action.copied:hover { color: var(--rwa-green); }
  .chat-item.active:hover { background: var(--surface-3); }
  .chat-item.selected:hover { background: rgba(59,110,245,0.10); }
  .nav-item.active:hover { background: var(--surface-2); color: var(--text); }
  .settings-tab.active:hover { background: var(--surface-3); color: var(--text); }
}

/* ============================================================
   15. BREAKPOINTS
   ============================================================ */

@media (max-width: 1100px) {
  :root { --sidebar-w: 240px; }
}

@media (max-width: 900px) {
  :root { --sidebar-w: 220px; }
  .topbar-brand { display: flex; }
  .topbar-brand .brand-name { font-size: var(--fs-sm); }
}

@media (max-width: 820px) {
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 50;
    transform: translateX(-105%);
    box-shadow: 4px 0 24px rgba(0,0,0,0.5);
    width: min(320px, 85vw);
    transition: transform 0.22s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-collapse-btn { display: none; }
  .sidebar-backdrop { display: block; }
  .menu-btn { display: grid; }
  .expand-btn { display: none !important; }
  .topbar-brand { display: flex; }
  body.sidebar-collapsed .sidebar { width: min(320px, 85vw); transform: translateX(-105%); }
  .modal-settings { max-width: 100%; margin: 0; height: 100%; height: 100dvh; border-radius: 0; max-height: 100dvh; }
  .settings-layout { flex-direction: column; min-height: auto; height: 100%; }
  .settings-sidebar {
    width: 100%;
    flex-direction: row;
    overflow-x: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    padding: var(--space-sm);
    flex-shrink: 0;
    scrollbar-width: none;
  }
  .settings-sidebar::-webkit-scrollbar { display: none; }
  .settings-tab {
    white-space: nowrap;
    padding: 10px 12px;
    flex-shrink: 0;
  }
  .settings-content { max-height: none; flex: 1; }
  .modal-file-view { width: 100vw; height: 100dvh; max-width: 100%; border-radius: 0; margin: 0; padding: var(--space-md); }
  .file-view-pdf { height: 60dvh; }
  .msg-user .bubble { max-width: 92%; }
  .msg-files { max-width: 92%; }
}

@media (max-width: 600px) {
  .chat { padding: var(--space-md) var(--space-md) var(--space-sm); }
  .composer { padding: var(--space-sm) var(--space-md); padding-bottom: calc(var(--space-sm) + env(safe-area-inset-bottom, 0px)); }
  .msg-user .bubble { max-width: 94%; font-size: var(--fs-base); }
  .msg-files { max-width: 94%; }
  .msg-file-thumb {
    width: clamp(64px, 20vw, 90px);
    height: clamp(64px, 20vw, 90px);
  }
  .msg-file-doc { width: clamp(56px, 18vw, 76px); height: clamp(56px, 18vw, 76px); }
  .welcome { min-height: 50vh; padding: var(--space-md); }
  .toast-container {
    top: auto;
    bottom: calc(var(--space-md) + env(safe-area-inset-bottom, 0px));
    right: var(--space-sm);
    left: var(--space-sm);
    max-width: none;
  }
  .toast { max-width: none; }
  .modal { padding: var(--space-md); max-width: 100%; }
  .code-input { letter-spacing: 4px; font-size: max(16px, var(--fs-lg)); }
}

@media (max-width: 380px) {
  .brand-name { font-size: var(--fs-sm); }
  .brand-tag { display: none; }
  .chips { gap: 4px; }
  .chip { padding: 8px 12px; font-size: var(--fs-xs); }
  .send-btn, .attach-btn { width: 42px; height: 42px; min-width: 42px; min-height: 42px; }
  .send-btn svg, .attach-btn svg { width: 17px; height: 17px; }
  .icon-btn { width: 42px; height: 42px; min-width: 42px; min-height: 42px; }
  .msg-action { width: 40px; height: 40px; min-width: 40px; min-height: 40px; }
  .msg-action svg { width: 15px; height: 15px; }
  .composer-inner { padding: 5px; }
  #input { padding: 4px 2px; }
  .files-ms-btn span { display: none; }
}

@media (max-height: 500px) and (orientation: landscape) {
  .welcome { min-height: 40vh; gap: var(--space-sm); padding: var(--space-md); }
  .welcome-logo { width: 48px; }
  .welcome p { display: none; }
  .chips { margin-top: 0.25rem; }
  .chat { padding: var(--space-sm) var(--space-md); }
  #input { max-height: min(38vh, 200px); }
  .modal { max-height: calc(100dvh - 2 * var(--space-sm)); }
}

@media (min-width: 1000px) and (max-height: 600px) {
  .welcome { gap: var(--space-sm); min-height: 40vh; }
  .welcome-logo { width: 64px; }
  #input { max-height: min(38vh, 220px); }
}

@media (min-width: 1440px) {
  :root { --fs-base: 15px; --fs-md: 16px; }
  .chat > * { max-width: 860px; }
}

/* ============ 16. ACCESSIBILITY ============ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

@media (prefers-color-scheme: light) {
  /* DeepRWA is designed dark — respect OS preference minimally. */
}

/* ============================================================
   VOICE INPUT (mic button)
   ============================================================ */
.mic-btn {
  flex-shrink: 0;
  width: 44px; height: 44px;
  min-width: 44px; min-height: 44px;
  border-radius: 50%;
  background: transparent;
  border: none;
  color: var(--text-muted);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.mic-btn:hover { background: var(--surface-2); color: var(--text); }
.mic-btn svg { width: 18px; height: 18px; pointer-events: none; }
.mic-btn:active { opacity: 0.72; }
.mic-btn.listening {
  background: var(--danger-soft);
  color: var(--danger);
  animation: mic-pulse 1.4s ease-in-out infinite;
}
.mic-btn.listening svg { color: var(--danger); }
@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239,83,80,0.35); }
  50% { box-shadow: 0 0 0 8px rgba(239,83,80,0); }
}

@media (max-width: 380px) {
  .mic-btn { width: 40px; height: 40px; min-width: 40px; min-height: 40px; }
  .mic-btn svg { width: 17px; height: 17px; }
}

/* Voice output (speak button on messages) */
.msg-action.speaking,
.msg-action.speaking:hover { color: var(--accent); }

@media (hover: none) {
  .mic-btn:hover { background: transparent; color: var(--text-muted); }
  .mic-btn.listening:hover { background: var(--danger-soft); color: var(--danger); }
}

/* ============ VOICE LANGUAGE PICKER ============ */
.voice-lang-btn {
  flex-shrink: 0;
  width: 42px;
  height: 44px;
  min-width: 42px;
  min-height: 44px;
  border-radius: 22px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.02em;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.voice-lang-btn:hover { background: var(--surface-2); color: var(--text); }
.voice-lang-btn:active { opacity: 0.72; }
.voice-lang-btn span { pointer-events: none; }

.voice-lang-menu {
  padding: 4px;
  min-width: 220px;
}
.voice-lang-menu button {
  gap: 0.5rem;
  padding: 8px 10px;
  min-height: 40px;
  font-size: var(--fs-sm);
}
.voice-lang-menu button svg {
  width: 14px;
  height: 14px;
  color: var(--accent);
  margin-left: auto;
}

@media (max-width: 380px) {
  .voice-lang-btn {
    width: 36px;
    min-width: 36px;
    height: 40px;
    min-height: 40px;
    font-size: 10px;
  }
}

@media (hover: none) {
  .voice-lang-btn:hover { background: transparent; color: var(--text-muted); }
}

/* ============================================================
   GENERATED IMAGES — wrapper, download button
   ============================================================ */
.generated-image-wrap {
  position: relative;
  margin-top: 0.75rem;
  max-width: min(100%, 560px);
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface);
  line-height: 0;
}
.generated-image {
  width: 100%;
  height: auto;
  display: block;
  cursor: zoom-in;
  transition: opacity 0.15s;
}
.generated-image:hover { opacity: 0.96; }
.gen-download-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background: rgba(0,0,0,0.6);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 8px;
  padding: 0.4rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  min-width: 36px;
  min-height: 36px;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: background 0.15s, transform 0.06s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.gen-download-btn:hover { background: rgba(0,0,0,0.85); }
.gen-download-btn:active { transform: scale(0.95); }
.gen-download-btn svg { width: 16px; height: 16px; pointer-events: none; }

@media (hover: none) {
  .gen-download-btn:hover { background: rgba(0,0,0,0.6); }
}

/* ============================================================
   LIGHTBOX
   ============================================================ */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.92);
  z-index: 9000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  opacity: 0;
  transition: opacity 0.2s ease;
  cursor: zoom-out;
}
.lightbox.open {
  display: flex;
  opacity: 1;
}
.lightbox img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
  cursor: default;
}
.lightbox-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  border-radius: 50%;
  background: rgba(255,255,255,0.1);
  color: #fff;
  border: none;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.15s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.lightbox-close:hover { background: rgba(255,255,255,0.2); }
.lightbox-close svg { width: 20px; height: 20px; pointer-events: none; }

/* ============================================================
   VOICE MODE (rev.3.7.0) — send button variants, voice pill
   ============================================================ */

.send-btn.voice-entry {
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.send-btn.voice-entry:hover:not(:disabled) {
  background: var(--surface-3);
  color: var(--text);
  border-color: var(--border-strong);
}

.send-btn.voice-exit {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid var(--danger-border);
}
.send-btn.voice-exit:hover {
  background: rgba(239,83,80,0.22);
}

.voice-status {
  flex: 1;
  display: none;
  align-items: center;
  gap: 12px;
  padding: var(--space-sm) var(--space-md);
  min-height: 44px;
  min-width: 0;
}
.voice-indicator {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
.voice-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: voice-pulse 1.2s ease-in-out infinite;
}
.voice-dot:nth-child(2) { animation-delay: 0.15s; }
.voice-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes voice-pulse {
  0%, 100% { transform: scale(0.6); opacity: 0.5; }
  50% { transform: scale(1); opacity: 1; }
}
.voice-label {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

body.voice-mode .composer-inner {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
body.voice-mode .composer-inner #input,
body.voice-mode .composer-inner .attach-btn {
  display: none;
}
body.voice-mode .composer-inner .voice-status {
  display: flex;
}

body[data-voice-phase="thinking"] .voice-dot { background: var(--rwa-yellow); }
body[data-voice-phase="speaking"] .voice-dot { background: var(--rwa-green); }
body[data-voice-phase="transcribing"] .voice-dot { background: var(--text-muted); }

@media (hover: none) {
  .send-btn.voice-entry:hover { background: var(--surface-2); color: var(--text-muted); border-color: var(--border); }
  .send-btn.voice-exit:hover { background: var(--danger-soft); }
}

@media (max-width: 380px) {
  .voice-status { padding: 4px 8px; gap: 8px; }
  .voice-dot { width: 5px; height: 5px; }
}

/* ============================================================
   Universal device support — rev.4.2.0
   ============================================================ */

/* Inline SVG voice-entry icon must match Lucide sizing */
.send-btn > svg.icon-voice {
  width: 18px;
  height: 18px;
  display: block;
}
.send-btn > svg.icon-voice.hidden { display: none !important; }

/* On very small phones, keep the voice entry visible and generous */
@media (max-width: 380px) {
  .send-btn > svg.icon-voice { width: 17px; height: 17px; }
}

/* Android and other touch devices: prevent hover styles from
   sticking on the send button after a tap */
@media (hover: none) {
  .send-btn.voice-entry:hover {
    background: var(--surface-2);
    color: var(--text-muted);
    border-color: var(--border);
  }
  .send-btn.voice-exit:hover { background: var(--danger-soft); }
}

/* Ensure voice-status pill never overflows the composer */
.voice-status {
  min-width: 0;
  overflow: hidden;
}
.voice-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ============================================================
   Voice entry icon — universal rendering fallback (rev.4.3.0)
   ============================================================ */

/* Explicit size attributes on the SVG element are ignored by some
   in-app browsers. Force size via CSS with !important so no other
   rule can override. */
.send-btn > svg.icon-voice {
  display: block !important;
  width: 20px !important;
  height: 20px !important;
  min-width: 20px;
  min-height: 20px;
  stroke: currentColor;
  fill: none;
  flex-shrink: 0;
}
.send-btn > svg.icon-voice.hidden {
  display: none !important;
}

/* Make the voice-entry button's color obvious so it's not confused
   with the disabled send button. */
.send-btn.voice-entry {
  background: var(--surface-2) !important;
  color: var(--text) !important;
  border: 1px solid var(--border-strong) !important;
}

@media (max-width: 380px) {
  .send-btn > svg.icon-voice {
    width: 18px !important;
    height: 18px !important;
    min-width: 18px;
    min-height: 18px;
  }
}
