
/* ══════════════════════════════════════════════
   M3 EXPRESSIVE DESIGN TOKENS
══════════════════════════════════════════════ */
:root {
  /* Primary — electric violet */
  --p: #6B21D8; --on-p: #fff;
  --pc: #EDE9FE; --on-pc: #3B0764;
  /* Secondary — cyan */
  --s: #0284C7; --on-s: #fff;
  --sc: #E0F2FE; --on-sc: #0C4A6E;
  /* Tertiary — coral */
  --t: #E11D48; --on-t: #fff;
  --tc: #FFE4E6; --on-tc: #881337;
  /* Surfaces */
  --bg: #FAFAFA; --on-bg: #1A1625;
  --surf: #FFFFFF; --on-surf: #1A1625;
  --surf-v: #EDE9FE; --on-surf-v: #49454F;
  --on-surf-variant: #49454F;
  --surf-lo: #F4F0FA; --surf-mid: #EEE9F5;
  --surf-hi: #E8E3F0; --surf-hst: #E2DCE9;
  /* Library Compatibility Layer */
  --md-sys-color-primary: var(--p);
  --md-sys-color-on-primary: var(--on-p);
  --md-sys-color-primary-container: var(--pc);
  --md-sys-color-on-primary-container: var(--on-pc);
  --md-sys-color-surface: var(--surf);
  --md-sys-color-on-surface: var(--on-surf);
  --md-sys-color-on-surface-variant: var(--on-surf-v);
  --md-sys-color-outline: var(--out-v);
  /* Outline */
  --out: #7C7589; --out-v: #CAC4D0;
  /* Error */
  --err: #B91C1C; --err-c: #FEE2E2;
  /* Sizing — M3E aligned */
  --r-pill: 9999px; --r-xl: 28px;
  --r-lg: 16px; --r-md: 12px;
  --r-sm: 8px; --r-xs: 4px;
  /* Shadows */
  --sh1: 0 1px 4px rgba(107,33,216,.1), 0 1px 2px rgba(0,0,0,.08);
  --sh2: 0 4px 16px rgba(107,33,216,.12), 0 2px 8px rgba(0,0,0,.1);
  --sh3: 0 8px 32px rgba(107,33,216,.15), 0 4px 16px rgba(0,0,0,.12);
  /* Motion — M3E tokens */
  --spring: cubic-bezier(0.05,0.7,0.1,1);
  --std: cubic-bezier(0.2,0,0,1);
  --decel: cubic-bezier(0,0,0,1);
  --accel: cubic-bezier(0.3,0,1,1);
  --dur-short: 200ms;
  --dur-med: 300ms;
  --dur-long: 500ms;
  /* Font */
  --font: 'Plus Jakarta Sans', system-ui, sans-serif;
  /* Layout */
  --side-w: 276px;
  --app-vh: 100vh;
  --safe-bottom: 0px;
}
[data-theme="dark"] {
  --p: #C4B5FD; --on-p: #3B0764;
  --pc: #4C1D95; --on-pc: #EDE9FE;
  --s: #7DD3FC; --on-s: #0C4A6E;
  --sc: #0C4A6E; --on-sc: #BAE6FD;
  --t: #FDA4AF; --on-t: #881337;
  --tc: #881337; --on-tc: #FFE4E6;
  --bg: #0D0A14; --on-bg: #EAE6F0;
  --surf: #14101F; --on-surf: #EAE6F0;
  --surf-v: #2D2540; --on-surf-v: #CAC4D0;
  --surf-lo: #181224; --surf-mid: #1E1730;
  --surf-hi: #252040; --surf-hst: #2D2848;
  --out: #9A94A8; --out-v: #3D3652;
  --err: #FCA5A5; --err-c: #7F1D1D;
  --sh1: 0 1px 4px rgba(0,0,0,.3), 0 1px 2px rgba(0,0,0,.4);
  --sh2: 0 4px 16px rgba(0,0,0,.35), 0 2px 8px rgba(0,0,0,.4);
  --sh3: 0 8px 32px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.45);
}

/* ══════════════════════════════════════════════ RESET */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--on-bg);
  -webkit-font-smoothing: antialiased;
}
/* M3E: Honor reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
button { font-family: var(--font); cursor: pointer; }
input, textarea { font-family: var(--font); }
a { color: var(--p); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Material Symbols */
.ms {
  font-family: 'Material Symbols Rounded';
  font-weight: normal; font-style: normal;
  font-size: 22px; line-height: 1;
  letter-spacing: normal; text-transform: none;
  display: inline-block; white-space: nowrap;
  word-wrap: normal; direction: ltr;
  -webkit-font-smoothing: antialiased;
  font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
  user-select: none; pointer-events: none;
  color: inherit;
}
.ms.fill { font-variation-settings: 'FILL' 1, 'wght' 500, 'GRAD' 0, 'opsz' 24; }
.ms.sm { font-size: 18px; }
.ms.lg { font-size: 26px; }
.ms.xl { font-size: 32px; }

/* ══════════════════════════════════════════════
   APP SHELL
══════════════════════════════════════════════ */
#app {
  display: flex;
  height: var(--app-vh) !important;
  position: relative;
  overflow: hidden;
}

/* ══════════════════════════════════════════════
   RESPONSIVE SHOW/HIDE & NAV RAIL
══════════════════════════════════════════════ */
.desktop-only { display: flex !important; }
.mobile-only { display: none !important; }

@media (max-width: 1280px) {
  .desktop-only { display: none !important; }
  .mobile-only { display: flex !important; }
}

#desktop-rail {
  border-right: 1px solid var(--out-v);
  background: var(--surf-lo);
  flex-shrink: 0;
  z-index: 10;
}

/* ══════════════════════════════════════════════
   SIDEBAR
══════════════════════════════════════════════ */
#sidebar {
  width: var(--side-w);
  min-width: var(--side-w);
  height: 100%;
  background: var(--surf-lo);
  border-right: 1px solid var(--out-v);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width .42s var(--std), min-width .42s var(--std),
              transform .42s var(--std), margin-left .42s var(--std),
              box-shadow .42s var(--std);
  position: relative;
  z-index: 10;
}
@media (min-width: 1201px) {
  #sidebar.closed { width: 0; min-width: 0; border-right: none; }
  #sidebar.desktop-collapsed { margin-left: calc(var(--side-w) * -1); border-right: none; }
}
@media (max-width: 1200px) {
  #sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 1000;
    transform: translateX(-100%);
  }
  #sidebar:not(.closed) {
    transform: translateX(0);
    box-shadow: var(--sh3);
  }
}

.side-head {
  padding: 20px 16px 12px;
  display: flex; align-items: center; gap: 10px;
  flex-shrink: 0;
}
.logo-mark {
  width: 44px; height: 44px;
  border-radius: var(--r-xl);
  background: linear-gradient(145deg, var(--p), var(--t));
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  box-shadow: var(--sh2);
  position: relative;
  overflow: hidden;
}
.logo-mark::after {
  content: '';
  position: absolute; inset: 0;
  background: radial-gradient(circle at 30% 30%, rgba(255,255,255,.35), transparent 60%);
}
.logo-mark .ms { color: #fff; font-size: 22px; }
.app-name {
  font-size: 19px; font-weight: 800;
  color: var(--on-surf);
  white-space: nowrap; overflow: hidden;
  letter-spacing: -.3px;
}
.app-name span { color: var(--p); }

/* New Chat Row */
.new-chat-row {
  display: flex; gap: 8px;
  padding: 0 16px 16px; align-items: center;
  flex-shrink: 0;
}
.new-chat-row m3e-button {
  --m3e-button-container-height: 40px;
}
.temp-btn {
  display: flex; align-items: center; justify-content: center;
  width: 40px; height: 40px;
  background: var(--sc); color: var(--on-sc);
  border: none; border-radius: 50%; /* Disabled = circle */
  cursor: pointer; position: relative;
  transition: background .2s var(--std), border-radius .25s var(--spring),
              box-shadow .2s var(--std), transform .2s var(--std);
}
.temp-btn .ms { font-size: 22px; }
.temp-btn:hover { background: color-mix(in srgb, var(--sc), #000 8%); transform: scale(1.04); }
.temp-btn.active,
#temp-btn[selected] {
  background: var(--tc); color: var(--t);
  border-radius: var(--r-md); /* Enabled = rounded square */
  box-shadow: var(--sh1);
}
.temp-btn.active .ms { font-variation-settings: 'FILL' 1; }
.new-chat-btn {
  flex: 1; display: flex; align-items: center; gap: 9px;
  padding: 0 18px;
  height: 40px;
  background: var(--p); color: var(--on-p);
  border: none; border-radius: var(--r-pill);
  font-size: 14px; font-weight: 700;
  transition: all .28s var(--spring);
  white-space: nowrap;
  box-shadow: var(--sh1);
}
.new-chat-btn:hover {
  transform: scale(1.04) translateY(-1px);
  box-shadow: var(--sh2);
}
.new-chat-btn:active { transform: scale(.96); box-shadow: none; }

.temp-dot-badge {
  position: absolute;
  top: 6px; right: 6px;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--t);
  border: 2px solid var(--surf);
  display: none;
}
.temp-btn.active .temp-dot-badge,
#temp-btn[selected] .temp-dot-badge { display: block; animation: tempPulse 1.6s ease-in-out infinite; }
@keyframes tempPulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.35); opacity: .6; }
}

/* History */
.hist-scroll {
  flex: 1; overflow-y: auto; padding: 0 8px 14px;
  min-height: 0;
  scrollbar-width: thin; scrollbar-color: var(--out-v) transparent;
}
.hist-scroll::-webkit-scrollbar { width: 4px; }
.hist-scroll::-webkit-scrollbar-thumb { background: var(--out-v); border-radius: 2px; }

.hist-label {
  padding: 10px 12px 4px;
  font-size: 10.5px; font-weight: 800;
  color: var(--out); text-transform: uppercase; letter-spacing: .1em;
}
.hist-item {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px;
  border-radius: var(--r-lg);
  cursor: pointer;
  transition: all .2s var(--std);
  position: relative; margin-bottom: 2px;
}
.hist-item:hover { background: var(--surf-mid); }
.hist-item.active {
  background: var(--pc);
}
.hist-item.active .hi-title { color: var(--on-pc); font-weight: 700; }
.hi-icon {
  width: 30px; height: 30px;
  border-radius: var(--r-sm);
  background: var(--surf-hi);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; font-size: 14px;
}
.hi-icon .ms {
  color: var(--on-surf-v);
  font-size: 16px;
}
.hi-icon.tmp {
  background: transparent;
  border: 1.5px dashed var(--out);
}
.hi-title {
  flex: 1; font-size: 13px; font-weight: 500;
  color: var(--on-surf);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.hi-del {
  opacity: 0; width: 24px; height: 24px;
  border-radius: 50%; border: none;
  background: transparent; color: var(--out);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; flex-shrink: 0;
  transition: all .2s;
}
.hist-item:hover .hi-del { opacity: 1; }
.hi-del:hover { background: var(--err-c); color: var(--err); }
.hi-del .ms { font-size: 16px; }
.hist-empty {
  text-align: center; padding: 32px 16px;
  color: var(--out); font-size: 13px; line-height: 1.6;
}

/* Sidebar Footer */
.side-foot {
  padding: 12px 16px;
  border-top: 1px solid var(--out-v);
  display: flex; align-items: center; gap: 8px;
  flex-shrink: 0;
}
#settings-btn, #rail-settings-btn {
  --m3e-icon-button-icon-color: var(--on-surf);
  --m3e-icon-button-container-color: transparent !important;
}

/* Global M3E component overrides for high-contrast accessibility in all states */
m3e-icon-button {
  --m3e-icon-button-icon-color: var(--on-surf);
  --m3e-icon-button-hover-icon-color: var(--on-surf);
  --m3e-icon-button-focus-icon-color: var(--on-surf);
  --m3e-icon-button-pressed-icon-color: var(--on-surf);
}
m3e-icon-button[variant="outlined"] {
  --m3e-icon-button-outline-color: var(--out);
}
m3e-button[variant="outlined"] {
  --m3e-button-label-color: var(--p);
  --m3e-button-label-text-color: var(--p);
  --m3e-button-icon-color: var(--p);
  --m3e-button-hover-label-color: var(--p);
  --m3e-button-hover-label-text-color: var(--p);
  --m3e-button-hover-icon-color: var(--p);
  --m3e-button-focus-label-color: var(--p);
  --m3e-button-pressed-label-color: var(--p);
  --m3e-button-outline-color: var(--out);
}

/* Improve legibility of disabled buttons (Voice/Agentic) in light mode */
m3e-button[disabled],
m3e-icon-button[disabled] {
  opacity: 1 !important; /* Disable double opacity penalty */
  --m3e-button-disabled-label-text-color: var(--on-surf-v) !important;
  --m3e-button-disabled-label-color: var(--on-surf-v) !important;
  --m3e-button-disabled-icon-color: var(--on-surf-v) !important;
  --m3e-button-disabled-outline-color: var(--out) !important;
  --m3e-icon-button-disabled-icon-color: var(--on-surf-v) !important;
}

/* Model Selector inner fixes */
.composer-segbar {
  --m3e-button-outline-color: var(--out);
}
#model-split-btn m3e-icon {
  color: var(--p) !important;
}

/* Force dark text for settings dialog and tabs in light mode */
m3e-dialog {
  --m3e-dialog-headline-color: var(--on-surf) !important;
  --m3e-dialog-supporting-text-color: var(--on-surf-v) !important;
  --m3e-dialog-icon-color: var(--on-surf) !important;
  --m3e-icon-button-icon-color: var(--on-surf) !important;
}
m3e-dialog::part(close-icon) {
  color: var(--on-surf) !important;
}
m3e-dialog span[slot="header"] {
  color: var(--on-surf) !important;
}
/* Tabs — using exact M3E token names from library source */
m3e-tabs {
  --m3e-tabs-active-indicator-color: var(--p) !important;
}
m3e-tab {
  --m3e-tab-unselected-color: var(--on-surf-v) !important;
  --m3e-tab-selected-color: var(--p) !important;
}
m3e-tab[selected], m3e-tab[active] {
  --m3e-tab-unselected-color: var(--p) !important;
  --m3e-tab-selected-color: var(--p) !important;
}

/* History Clear All Button — using exact M3E tonal-button token names */
#clear-btn {
  --m3e-tonal-button-label-text-color: var(--err) !important;
  --m3e-tonal-button-icon-color: var(--err) !important;
  --m3e-tonal-button-container-color: var(--err-c) !important;
  --m3e-tonal-button-hover-label-text-color: var(--err) !important;
  --m3e-tonal-button-hover-icon-color: var(--err) !important;
  --m3e-tonal-button-hover-container-color: var(--err-c) !important;
}
.user-mini {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surf-hi);
  border: 1px solid var(--out-v);
  color: var(--on-surf-v);
  flex-shrink: 0;
}
.user-mini .ms { color: var(--on-surf-v); }
.pow {
  flex: 1; font-size: 11px; color: var(--out);
  text-align: center; white-space: nowrap;
}
.pow a { color: var(--p); font-weight: 700; }

/* Icon buttons removed — now using m3e-icon-button */
/* ══════════════════════════════════════════════
   MAIN AREA
══════════════════════════════════════════════ */
#main {
  flex: 1; display: flex; flex-direction: column;
  min-width: 0; background: var(--bg);
  position: relative;
}

/* Demo Banner */
#demo-banner {
  display: none; align-items: center; gap: 8px;
  padding: 8px 20px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--t) 18%, transparent), var(--tc));
  color: var(--on-tc);
  font-size: 12px; font-weight: 700;
  border-bottom: 1px solid color-mix(in srgb, var(--t) 32%, transparent);
  box-shadow: var(--sh1);
  max-height: 220px;
  opacity: 1;
  transform: translateY(0);
  overflow: hidden;
  transition: border-color .2s, box-shadow .2s, max-height .28s var(--std), opacity .22s var(--std), transform .28s var(--std), padding .22s var(--std), margin .22s var(--std), border-width .18s var(--std);
}
#demo-banner.show { display: flex; }
#demo-banner .ms { color: var(--on-tc); }
.demo-pill {
  margin-left: auto;
  transition: background .22s var(--std), border-color .22s var(--std), box-shadow .22s var(--std), padding .22s var(--std);
  padding: 3px 12px;
  background: var(--t); color: var(--on-t);
  border-radius: var(--r-pill);
  font-size: 12px; font-weight: 800;
}

/* Topbar */
#topbar {
  height: 64px; padding: 0 12px 0 8px;
  display: flex; align-items: center; gap: 8px;
  border-bottom: 1px solid var(--out-v);
  background: var(--surf); flex-shrink: 0;
  position: relative; z-index: 5;
}
.topbar-user {
  display: flex; align-items: center; gap: 6px;
  padding-right: 2px;
}
.topbar-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--p), var(--t));
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--sh1);
  flex-shrink: 0;
  font-weight: 800;
}
.topbar-avatar .ms { color: #fff; font-size: 18px; }
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}
.topbar-actions m3e-icon-button {
  --m3e-icon-button-state-layer-size: 38px;
}
.mobile-menu {
  position: fixed;
  top: 68px;
  right: 12px;
  background: var(--surf);
  border: 1px solid var(--out-v);
  border-radius: var(--r-lg);
  box-shadow: var(--sh2);
  padding: 8px;
  display: none;
  flex-direction: column;
  gap: 6px;
  min-width: 200px;
  z-index: 30;
}
.mobile-menu.open { display: flex; animation: fadeIn .2s var(--decel); }
.mobile-menu button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--r-md);
  border: 1px solid transparent;
  background: var(--surf-lo);
  color: var(--on-surf);
  font-size: 13px;
  font-weight: 700;
  text-align: left;
}
.mobile-menu button:hover { border-color: var(--p); background: color-mix(in srgb, var(--p) 10%, transparent); }
.mobile-menu button:disabled { opacity: .55; cursor: not-allowed; }
#mobile-menu-ov {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.18);
  display: none;
  z-index: 20;
}
#mobile-menu-ov.show { display: block; }
.chat-title-label {
  font-size: 11px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase;
  color: var(--out);
}
.chat-top-title {
  display: flex; flex-direction: column; gap: 4px;
  flex: 1;
}
.chat-top-title #chat-title {
  font-size: 18px; font-weight: 800; color: var(--on-surf);
  letter-spacing: -0.01em;
}
#chat-top {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--out-v);
  background: var(--surf);
  position: sticky;
  top: 0;
  z-index: 4;
}
.top-title {
  flex: 1; font-size: 17px; font-weight: 700;
  color: var(--on-surf);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.temp-pill,
.temp-mode-pill,
.demo-mode-pill {
  display: none;
  align-items: center; gap: 6px;
  padding: 3px 12px;
  background: var(--t);
  color: #fff;
  border-radius: var(--r-pill);
  font-size: 11px; font-weight: 800;
  animation: fadeIn .3s var(--decel);
  box-shadow: var(--sh1);
  height: 24px;
}
.temp-pill.show,
.temp-mode-pill.show,
.demo-mode-pill.show { display: inline-flex; }

.temp-mode-pill { 
  background: linear-gradient(145deg, #f43f5e, #be123c);
  margin-right: 4px;
}
.demo-mode-pill {
  background: linear-gradient(145deg, var(--p), var(--t));
  margin-right: 2px;
}
[data-theme="dark"] .temp-pill,
[data-theme="dark"] .temp-mode-pill {
  background: linear-gradient(145deg, #f43f5e, #7f1d1d);
  color: #ffe4e6;
}

/* Chat Container */
#chat-wrap {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  padding: 24px 0; display: flex; flex-direction: column;
  gap: 0;
  scrollbar-width: thin; scrollbar-color: var(--out-v) transparent;
}
#chat-wrap::-webkit-scrollbar { width: 6px; }
#chat-wrap::-webkit-scrollbar-thumb { background: var(--out-v); border-radius: 3px; }

.chat-inner {
  width: 100%; max-width: 820px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex; flex-direction: column; gap: 8px;
  flex: 1;
}

/* Welcome Screen */
#welcome {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center; gap: 20px;
  padding: 48px 24px 24px;
  min-height: 100%;
  animation: welcomeIn .6s var(--decel);
}
@keyframes welcomeIn {
  from { opacity: 0; transform: translateY(32px); }
  to { opacity: 1; transform: translateY(0); }
}
.w-logo {
  width: 88px; height: 88px;
  border-radius: 36px;
  background: linear-gradient(145deg, var(--p), var(--t));
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--sh3), 0 0 0 8px color-mix(in srgb, var(--p) 15%, transparent);
  position: relative; overflow: hidden;
  animation: logoPulse 3s ease-in-out infinite;
}
@keyframes logoPulse {
  0%, 100% { box-shadow: var(--sh3), 0 0 0 8px color-mix(in srgb, var(--p) 15%, transparent); }
  50% { box-shadow: var(--sh3), 0 0 0 16px color-mix(in srgb, var(--p) 8%, transparent); }
}
.w-logo::after {
  content: '';
  position: absolute; inset: 0;
  background: radial-gradient(circle at 30% 30%, rgba(255,255,255,.4), transparent 60%);
}
.w-logo .ms { color: #fff; font-size: 40px; }
.w-heading {
  font-size: 32px; font-weight: 800; letter-spacing: -.5px;
  background: linear-gradient(135deg, var(--p) 30%, var(--t) 100%);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
  padding-bottom: 6px;
  line-height: 1.2;
}
.w-sub {
  font-size: 15px; color: var(--out);
  max-width: 420px; line-height: 1.65;
}
.w-chips {
  display: flex; flex-wrap: wrap; gap: 8px;
  justify-content: center; max-width: 520px;
}
.w-chips m3e-assist-chip {
  --m3e-chip-label-color: var(--on-pc);
  --m3e-chip-label-text-color: var(--on-pc);
  --m3e-chip-hover-label-color: var(--on-pc);
  --m3e-chip-hover-label-text-color: var(--on-pc);
  --m3e-chip-container-color: color-mix(in srgb, var(--surf) 90%, var(--pc));
  --m3e-chip-hover-container-color: color-mix(in srgb, var(--pc) 30%, var(--surf));
  --m3e-chip-outline-color: color-mix(in srgb, var(--p) 24%, var(--out-v));
  --m3e-chip-focus-outline-color: var(--p);
  --m3e-chip-supporting-text-color: var(--on-pc);
  font-weight: 700;
  box-shadow: var(--sh1);
}
[data-theme="dark"] .w-chips m3e-assist-chip {
  --m3e-chip-container-color: color-mix(in srgb, var(--surf-mid) 90%, var(--surf));
  --m3e-chip-hover-container-color: color-mix(in srgb, var(--pc) 24%, var(--surf-mid));
  --m3e-chip-outline-color: var(--out-v);
  --m3e-chip-label-color: var(--on-surf);
}
/* Temporary Welcome Variant */
.temp-welcome-box {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; gap: 16px; width: 100%;
  padding-top: 60px; animation: fadeIn .4s ease;
}
.temp-welcome-box .w-logo {
  background: var(--surf-hi);
  border: 2px dashed var(--out-v);
  box-shadow: none;
  animation: none;
}
.temp-welcome-box .w-logo .ms { color: var(--out); }
.temp-welcome-box .w-heading {
  background: none;
  -webkit-text-fill-color: var(--on-surf);
  background-clip: unset;
  color: var(--on-surf);
}
.temp-welcome-box .w-sub {
  color: var(--out);
  max-width: 460px;
}

/* ══════════════════════════════════════════════
   DROPUP SYSTEM (Categories & Models)
══════════════════════════════════════════════ */

/* ══════════ MESSAGES ══════════ */
.msg-row {
  display: flex; gap: 10px;
  animation: msgIn .35s var(--decel);
  margin-bottom: 4px;
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}
.msg-row.user { justify-content: flex-end; }
.msg-row.assistant { justify-content: flex-start; }

.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; font-weight: 800; font-size: 14px;
  margin-top: 4px;
}
.avatar.user-av {
  background: var(--sc); color: var(--on-sc);
  order: 2;
}
.avatar.ai-av {
  background: linear-gradient(145deg, var(--p), var(--t));
  color: #fff;
  box-shadow: var(--sh1);
}
.avatar.ai-av .ms { font-size: 17px; color: #fff; }

.bubble {
  max-width: min(72%, 560px);
  position: relative;
}
.msg-row.user .bubble {
  background: var(--p); color: var(--on-p);
  padding: 13px 18px; border-radius: var(--r-xl) var(--r-xs) var(--r-xl) var(--r-xl);
  font-size: 15px; line-height: 1.6; white-space: pre-wrap; word-break: break-word;
}
.msg-row.assistant .bubble {
  background: var(--surf); color: var(--on-surf);
  border: 1px solid var(--out-v);
  padding: 13px 18px; border-radius: var(--r-xs) var(--r-xl) var(--r-xl) var(--r-xl);
  font-size: 15px; line-height: 1.6; white-space: pre-wrap; word-break: break-word;
  box-shadow: var(--sh1);
}
.msg-meta {
  font-size: 11px; color: var(--out);
  margin-top: 4px; padding: 0 4px;
}
.msg-row.user .msg-meta { text-align: right; }

/* Image message */
.msg-img {
  max-width: 100%; max-height: 340px;
  border-radius: var(--r-lg); object-fit: cover;
  display: block; cursor: pointer;
  transition: transform .2s var(--spring);
}
.msg-img:hover { transform: scale(1.02); }

.img-viewer {
  position: fixed;
  inset: 0;
  z-index: 420;
  display: none;
}

.img-viewer.open {
  display: block;
}

.img-viewer-bg {
  position: absolute;
  inset: 0;
  background: rgba(8, 7, 14, .86);
  backdrop-filter: blur(4px);
}

.img-viewer-card {
  position: relative;
  z-index: 1;
  width: min(1080px, calc(100vw - 28px));
  height: min(88vh, 920px);
  margin: max(16px, 5vh) auto;
  border-radius: var(--r-xl);
  border: 1px solid var(--out-v);
  background: color-mix(in srgb, var(--surf) 88%, black 12%);
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
  box-shadow: var(--sh3);
}

.img-viewer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--out-v);
}

.img-viewer-zoom {
  font-size: 12px;
  font-weight: 800;
  color: var(--on-surf-v);
  padding: 5px 10px;
  border: 1px solid var(--out-v);
  border-radius: var(--r-pill);
}

.img-view.compose-actions {
  display: flex; justify-content: space-between; align-items: center; width: 100%;
}
.btn-row {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}

.img-viewer-stage {
  overflow: hidden;
  display: grid;
  place-items: center;
  padding: 14px;
  cursor: default;
  touch-action: none;
  user-select: none;
}

.img-viewer-stage.pannable {
  cursor: grab;
}

.img-viewer-stage.dragging {
  cursor: grabbing;
}

#img-viewer-img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  display: block;
  transform-origin: center center;
  transition: transform .2s var(--std);
  user-select: none;
  pointer-events: none;
  -webkit-user-drag: none;
  will-change: transform;
}

.img-viewer-stage.dragging #img-viewer-img {
  transition: none;
}

/* Attachment chip in message */
.msg-attach-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px;
  background: color-mix(in srgb, var(--on-p) 15%, transparent);
  border-radius: var(--r-pill);
  font-size: 12px; font-weight: 600; margin-bottom: 8px;
}
.msg-attach-chip .ms { font-size: 14px; }

/* Typing indicator — now using m3e-loading-indicator */
.typing-row { display: flex; gap: 10px; align-items: center; margin-bottom: 4px; }

/* ══════════════════════════════════════════════
   INPUT AREA
══════════════════════════════════════════════ */
#input-area {
  padding: 10px 20px calc(18px + var(--safe-bottom));
  background: var(--bg);
  border-top: 1px solid var(--out-v);
  flex-shrink: 0;
}
.input-area-inner {
  max-width: 820px; width: 100%; margin: 0 auto;
  display: flex; flex-direction: column; gap: 8px;
}

/* ══════════════════════════════════════════════
   TOAST
══════════════════════════════════════════════ */
#toast-host {
  position: fixed;
  bottom: calc(80px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 10000;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--surf-hi);
  border: 1px solid var(--out-v);
  color: var(--on-surf);
  padding: 10px 18px;
  border-radius: var(--r-pill);
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: var(--sh2);
  animation: toastIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.toast .ms {
  font-size: 18px;
  color: var(--p);
}
.toast.out {
  animation: toastOut 0.3s forwards;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateY(20px) scale(0.9); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes toastOut {
  from { opacity: 1; transform: scale(1); }
  to { opacity: 0; transform: scale(0.9); }
}
/* Toolbar below textarea */
.input-toolbar {
  display: flex; align-items: center; gap: 8px;
  flex-wrap: wrap; min-height: 36px;
}




/* Model categories */
.cat-badge {
  padding: 3px 10px;
  border-radius: var(--r-pill);
  font-size: 10.5px; font-weight: 800;
  text-transform: uppercase; letter-spacing: .06em;
  flex-shrink: 0;
}
.cb-text { background: #EDE9FE; color: #5B21B6; }
.cb-image { background: #FCE7F3; color: #9D174D; }
.cb-video { background: #FEF3C7; color: #92400E; }
.cb-audio { background: #D1FAE5; color: #065F46; }
.cb-transcription { background: #DBEAFE; color: #1E40AF; }
[data-theme="dark"] .cb-text { background: #3B0764; color: #DDD6FE; }
[data-theme="dark"] .cb-image { background: #500724; color: #FBCFE8; }
[data-theme="dark"] .cb-video { background: #431407; color: #FDE68A; }
[data-theme="dark"] .cb-audio { background: #022C22; color: #A7F3D0; }
[data-theme="dark"] .cb-transcription { background: #172554; color: #BFDBFE; }

/* Enhance Button removed since it is now an m3e-button */

.tools-pop {
  position: absolute;
  left: -4px;
  bottom: calc(100% + 12px);
  width: min(660px, calc(100vw - 28px));
  border-radius: var(--r-lg);
  border: 1px solid var(--out-v);
  background: var(--surf);
  box-shadow: var(--sh2);
  padding: 12px;
  display: none;
  z-index: 16;
  overflow: hidden;
}

.tools-pop.open {
  display: block;
  animation: fadeIn .2s var(--decel);
}
@media (max-width: 720px) {
  .tools-pop {
    width: min(640px, calc(100vw - 24px));
    left: auto;
    right: 0;
    max-height: 80vh;
  }
}
body.tools-open .input-toolbar { overflow: visible !important; }

.tools-pop-title {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--out);
  margin-bottom: 10px;
}

.tools-split { display: flex; gap: 12px; }
.tools-nav {
  width: 200px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.tool-nav-item {
  width: 100%;
  border: 1px solid var(--out-v);
  border-radius: var(--r-md);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--surf-lo);
  color: var(--on-surf);
  transition: all .2s var(--std);
}
.tool-nav-item:hover { border-color: var(--p); }
.tool-nav-item.active {
  border-color: var(--p);
  background: color-mix(in srgb, var(--p) 12%, transparent);
}
.tool-nav-meta { display: flex; align-items: center; gap: 8px; }
.tool-nav-titles { display: flex; flex-direction: column; gap: 2px; align-items: flex-start; }
.tool-nav-title { font-size: 13px; font-weight: 700; }
.tool-nav-sub { font-size: 11px; color: var(--out); }

.tools-models {
  flex: 1;
  border: 1px solid var(--out-v);
  border-radius: var(--r-md);
  padding: 10px 12px;
  background: var(--surf-lo);
  min-width: 0;
}
.tools-models-head { margin-bottom: 8px; }
.tools-models-title { font-size: 13px; font-weight: 800; color: var(--on-surf); }
.tools-models-hint { font-size: 11px; color: var(--out); }
.tools-model-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 240px;
  overflow-y: auto;
}
.tool-model-row {
  width: 100%;
  border: 1px solid var(--out-v);
  border-radius: var(--r-md);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--surf);
  text-align: left;
  transition: all .2s var(--std);
}
.tool-model-row:hover { border-color: var(--p); }
.tool-model-row.sel {
  border-color: var(--p);
  background: color-mix(in srgb, var(--p) 12%, transparent);
}
.tool-model-name { font-size: 13px; font-weight: 700; color: var(--on-surf); }
.tool-model-desc { font-size: 11px; color: var(--out); margin-top: 2px; }
.tool-model-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: var(--r-pill);
  background: var(--surf-hi);
  color: var(--on-surf-v);
  white-space: nowrap;
}
.tool-model-empty {
  padding: 16px;
  border: 1px dashed var(--out-v);
  border-radius: var(--r-md);
  color: var(--out);
  font-size: 12px;
  background: var(--surf);
}

/* Attachment Previews */
#attach-preview {
  display: flex; flex-wrap: wrap; gap: 6px;
}
.att-chip {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 10px;
  background: var(--surf); border: 1px solid var(--out-v);
  border-radius: var(--r-pill);
  font-size: 12px; font-weight: 600; color: var(--on-surf);
  animation: chipIn .3s var(--spring);
}
@keyframes chipIn {
  from { opacity: 0; transform: scale(.7); }
  to { opacity: 1; transform: scale(1); }
}
.att-chip .ms { font-size: 14px; color: var(--p); }
.att-chip-del {
  width: 18px; height: 18px; border-radius: 50%;
  border: none; background: var(--surf-hi);
  display: flex; align-items: center; justify-content: center;
  color: var(--out); font-size: 12px; line-height: 1;
  transition: all .2s;
}
.att-chip-del:hover { background: var(--err-c); color: var(--err); }

/* Input Row */
.input-row {
  display: flex; align-items: center; gap: 8px;
  background: var(--surf);
  border: 2px solid var(--out-v);
  border-radius: var(--r-xl);
  padding: 6px 6px 6px 15px;
  min-height: 48px;
  transition: border-color .2s, box-shadow .2s;
}
.input-row:focus-within {
  border-color: var(--p);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--p) 12%, transparent);
}
#msg-input {
  flex: 1; border: none; background: transparent; outline: none;
  font-size: 18px; color: var(--on-surf); line-height: 24px;
  resize: none; height: 30px; min-height: 32px; max-height: 200px;
  padding: 3px 0; margin: 0;
  scrollbar-width: thin;
  overflow-y: hidden;
}
#msg-input::placeholder { color: var(--out); }
.input-acts { 
  display: flex; align-items: center; gap: 4px; align-self: flex-end; padding-bottom: 2px;
}
.input-acts m3e-icon-button {
  --m3e-icon-button-state-layer-size: 40px;
  --m3e-icon-button-icon-size: 22px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
@media (min-width: 721px) {
  .input-acts m3e-icon-button {
    --m3e-icon-button-container-shape: 9999px !important;
  }
}
#send-btn { 
  transition: transform .24s var(--spring);
}
#send-btn:not([disabled]):hover { transform: scale(1.1); }
#send-btn:not([disabled]):active { transform: scale(0.8); }
.input-row.expanded {
  border-color: var(--p);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--p) 14%, transparent);
}
body.composer-expanded #msg-input {
  max-height: 360px;
  min-height: 36px;
}
/* Hide expand button until content exceeds 5 lines */
#composer-expand-btn { display: none; }
#composer-expand-btn.show-expand { display: flex; }
.compose-actions {
  display: flex; justify-content: space-between; align-items: center; width: 100%; margin-top: 8px;
}
.btn-row {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}

/* ══════════════════════════════════════════════
   MODEL DROPUP
══════════════════════════════════════════════ */
#dropup-wrap {
  position: fixed; inset: 0;
  z-index: 50; pointer-events: none;
}
#dropup-wrap.open { pointer-events: all; }
#dropup-bg {
  position: absolute; inset: 0;
  background: rgba(0,0,0,.35);
  opacity: 0; transition: opacity .3s var(--std);
}
#dropup-wrap.open #dropup-bg { opacity: 1; }
#dropup-panel {
  position: absolute;
  bottom: calc(90px + var(--safe-bottom));
  left: 50%; transform: translateX(-50%) translateY(24px);
  width: min(740px, calc(100vw - 32px));
  max-height: 460px;
  background: var(--surf);
  border-radius: var(--r-xl);
  border: 1px solid var(--out-v);
  box-shadow: var(--sh3);
  display: flex; overflow: hidden;
  opacity: 0; transition: all .38s var(--spring);
}
#dropup-wrap.open #dropup-panel {
  opacity: 1; transform: translateX(-50%) translateY(0);
}
.du-cats {
  display: flex;
  flex-direction: column;
  width: 148px; flex-shrink: 0;
  border-right: 1px solid var(--out-v);
  padding: 12px 8px; overflow-y: auto;
  background: var(--surf-lo);
}
.du-cat {
  display: flex; align-items: center; gap: 9px;
  padding: 10px 12px; border-radius: var(--r-md);
  cursor: pointer; font-size: 13px; font-weight: 600;
  color: var(--on-surf-v); transition: all .2s var(--std);
  user-select: none;
}
.du-cat:hover { background: var(--surf-mid); color: var(--on-surf); }
.du-cat.active { background: var(--pc); color: var(--on-pc); }
.du-cat .ms { font-size: 17px; }
.du-models {
  flex: 1; display: flex; flex-direction: column;
  overflow: hidden; padding: 12px;
}
.du-search {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 14px;
  background: var(--surf-lo); border: 1.5px solid var(--out-v);
  border-radius: var(--r-pill); margin-bottom: 10px;
  transition: border-color .2s;
  flex-shrink: 0;
}
.du-search:focus-within { border-color: var(--p); }
.du-search input {
  flex: 1; border: none; background: transparent; outline: none;
  font-size: 13px; color: var(--on-surf);
}
.du-search input::placeholder { color: var(--out); }
.du-list { overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 4px; }
.du-list::-webkit-scrollbar { width: 4px; }
.du-list::-webkit-scrollbar-thumb { background: var(--out-v); border-radius: 2px; }

.model-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 11px 13px; border-radius: var(--r-lg);
  cursor: pointer; transition: all .2s var(--std);
  border: 1.5px solid transparent;
}
.model-item:hover { background: var(--surf-lo); }
.model-item.sel { background: var(--pc); border-color: var(--p); }
.model-item.sel .mi-name { color: var(--on-pc); }
.mi-info { flex: 1; min-width: 0; }
.mi-name-row { display: flex; align-items: center; gap: 6px; }
.mi-name { font-size: 14px; font-weight: 700; color: var(--on-surf); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mi-pro {
  padding: 2px 8px;
  border-radius: var(--r-pill);
  background: linear-gradient(135deg, var(--p), var(--t));
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .05em;
  text-transform: uppercase;
}
.mi-desc { font-size: 12px; color: var(--out); margin-top: 2px; }
.mi-caps { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 6px; }
.cap-chip {
  display: flex; align-items: center; gap: 3px;
  padding: 3px 9px;
  background: var(--surf-hi);
  border-radius: var(--r-pill);
  font-size: 11px; font-weight: 700; color: var(--out);
  white-space: nowrap;
}
.cap-chip .ms { font-size: 13px; }
.model-item.sel .cap-chip {
  background: color-mix(in srgb, var(--p) 18%, transparent);
  color: var(--on-pc);
}

/* ══════════════════════════════════════════════
   DIALOGS — now using m3e-dialog
══════════════════════════════════════════════ */
m3e-dialog {
  --m3e-dialog-container-color: var(--surf);
  --m3e-dialog-headline-color: var(--on-surf);
  --m3e-dialog-supporting-text-color: var(--on-surf);
  color: var(--on-surf);
}

/* Settings panel inner spacing */
.settings-panel-inner {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 4px;
}

/* Settings shell removed — m3e-tabs handles layout */
/* .settings-nav, .settings-nav-item, .settings-section, .settings-content removed */
.sec-title {
  font-size: 11px; font-weight: 800;
  color: var(--p); text-transform: uppercase;
  letter-spacing: .1em; margin-bottom: 6px;
}
.srow {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px;
  background: var(--surf-lo);
  border-radius: var(--r-lg);
}
.srow .ms { color: var(--p); font-size: 20px; flex-shrink: 0; }
.srow-info { flex: 1; min-width: 0; }
.srow-label { font-size: 14px; font-weight: 700; color: var(--on-surf); word-break: break-word; }
.srow-desc { font-size: 12px; color: var(--out); margin-top: 2px; word-break: break-word; }
.srow-col {
  flex-direction: column; align-items: flex-start; gap: 8px;
}
.srow-col .srow-head { display: flex; align-items: center; gap: 10px; width: 100%; min-width: 0; }
.srow-col > * { width: 100%; max-width: 100%; }

.key-mode-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.key-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: var(--r-pill);
  font-size: 12px;
  font-weight: 800;
  background: color-mix(in srgb, var(--p) 14%, transparent);
  color: var(--on-pc);
}

.mode-cards {
  display: grid;
  gap: 10px;
}

.mode-card {
  border: 1.5px solid var(--out-v);
  border-radius: var(--r-lg);
  padding: 12px;
  background: var(--surf);
  transition: border-color .2s var(--std), background .2s var(--std), box-shadow .22s var(--std), transform .18s var(--std);
}

.mode-card:hover {
  border-color: color-mix(in srgb, var(--p) 35%, var(--out-v));
}

.mode-card.active {
  border-color: var(--p);
  background: color-mix(in srgb, var(--pc) 72%, var(--surf));
  box-shadow: var(--sh1);
}

.mode-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.mode-card-title {
  font-size: 14px;
  font-weight: 800;
  color: var(--on-surf);
}

.mode-radio {
  display: inline-flex;
  align-items: center;
  gap: 0;
  font-size: 0;
  padding: 0;
  border-radius: 0;
  border: none;
  background: transparent;
}

.mode-radio input {
  accent-color: var(--p);
  width: 18px;
  height: 18px;
  cursor: pointer;
}

.mode-card-short {
  margin-top: 6px;
  font-size: 12px;
  color: var(--out);
}

.mode-card-expanded {
  margin-top: 10px;
  border-top: 1px dashed color-mix(in srgb, var(--out-v) 75%, transparent);
  padding-top: 10px;
  display: none;
  gap: 10px;
}

.mode-card-expanded p {
  font-size: 12px;
  line-height: 1.55;
  color: var(--on-surf-v);
}

.mode-card.active .mode-card-expanded {
  display: grid;
  animation: fadeIn .2s var(--decel);
}

.s-input {
  width: 100%;
  border: 1.5px solid var(--out-v);
  border-radius: var(--r-md);
  background: var(--surf);
  color: var(--on-surf);
  padding: 10px 12px;
  font-size: 13px;
  outline: none;
  transition: border-color .2s;
}

.s-input:focus {
  border-color: var(--p);
}

.s-input:disabled {
  opacity: .65;
}

.pwa-nudge {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 20px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--s) 18%, transparent), var(--sc));
  color: var(--on-sc);
  border-bottom: 1px solid color-mix(in srgb, var(--s) 32%, transparent);
  box-shadow: var(--sh1);
}

.pwa-nudge-copy {
  display: grid;
  gap: 2px;
  flex: 1;
}

.pwa-nudge-copy strong {
  font-size: 12px;
  font-weight: 800;
  color: var(--on-sc);
}

.pwa-nudge-copy span {
  font-size: 11px;
  color: var(--on-sc);
  opacity: 0.85;
}

.pwa-nudge-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.pwa-nudge .btn {
  padding: 6px 10px;
  font-size: 12px;
}

@media (max-width: 720px) {
  .pwa-nudge {
    flex-wrap: wrap;
    padding: 10px 12px;
  }
  .pwa-nudge-copy {
    flex-basis: 100%;
  }
  .pwa-nudge-actions {
    width: 100%;
    justify-content: flex-end;
  }
}

/* Toggle styles removed — now using m3e-switch */

/* Textarea */
.stxt {
  width: 100%;
  padding: 12px 16px;
  background: var(--surf-lo); border: 1.5px solid var(--out-v);
  border-radius: var(--r-lg);
  font-size: 14px; color: var(--on-surf);
  resize: vertical; min-height: 100px; outline: none;
  transition: border-color .2s;
}
.stxt:focus { border-color: var(--p); }

/* Button styles removed — now using m3e-button */
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* Enhance model select inside settings */
.eml {
  display: block;
  max-height: 200px; overflow-y: auto;
  width: 100%;
  padding-right: 2px;
  scrollbar-gutter: stable;
  scrollbar-width: thin; scrollbar-color: var(--out-v) transparent;
}
.eml::-webkit-scrollbar { width: 6px; }
.eml::-webkit-scrollbar-thumb { background: var(--out-v); border-radius: 2px; }
.em-opt {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 14px; border-radius: var(--r-md);
  background: var(--surf-lo); border: 1.5px solid transparent;
  cursor: pointer; transition: all .2s;
  font-size: 13px; font-weight: 600; color: var(--on-surf);
  width: 100%;
  margin-bottom: 6px;
}
.em-opt:hover { background: var(--surf-mid); }
.em-opt.sel { border-color: var(--p); background: var(--pc); color: var(--on-pc); }

/* Toast styles removed — now using M3eSnackbar */

/* Sidebar overlay (mobile) */
#side-ov {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  opacity: 0;
  transition: opacity .24s var(--std);
  z-index: 9;
}

/* ══════════════════════════════════════════════
   RESPONSIVE
══════════════════════════════════════════════ */
@media (max-width: 1280px) {
  #sidebar {
    position: fixed; top: 0; left: 0; height: 100%;
    z-index: 20; box-shadow: var(--sh3);
    transform: translateX(0);
  }
  #sidebar.closed {
    transform: translateX(-100%);
    width: var(--side-w); min-width: var(--side-w);
  }
  #side-ov { display: block; pointer-events: none; opacity: 0; }
  #side-ov.show { pointer-events: all; opacity: 1; }
  .bubble { max-width: min(88%, 500px); }
  /* Tablet: dropup becomes column layout with horiz scrollable cats on top */
  #dropup-panel {
    flex-direction: column;
    bottom: calc(80px + var(--safe-bottom));
    max-height: 65vh;
  }
  .du-cats {
    display: flex;
    width: 100%; min-width: unset;
    flex-direction: row;
    overflow-x: auto; overflow-y: hidden;
    border-right: none;
    border-bottom: 1px solid var(--out-v);
    padding: 10px 10px 8px;
    gap: 6px;
    max-height: none;
    height: auto;
    justify-content: center;
  }
  .du-cat {
    flex-shrink: 0;
    padding: 8px 14px;
    border-radius: var(--r-pill);
    white-space: nowrap;
  }
  .du-models { min-height: 0; }
  .mi-caps { display: none; }
  .chat-inner { padding: 0 12px; }
  #input-area { padding: 8px 12px calc(14px + var(--safe-bottom)); }

  /* Compact model selector on smaller screens */
  .model-label {
    max-width: 110px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* Adjust quick modes for smaller screens */
  .quick-modes.qm-segment {
    flex-shrink: 0;
  }
  .hide-mobile {
    display: none !important;
  }
}
@media (max-width: 1024px) {
  .qm-pill {
    padding: 6px 8px;
  }
  .qm-pill span + span {
    display: none;
  }
}
@media (max-width: 720px) {
  #input-area { padding: 6px 10px calc(12px + var(--safe-bottom)); }
  .input-area-inner { gap: 6px; }
  .input-row {
    border-radius: var(--r-md);
    padding: 6px 10px 6px 10px;
    border-width: 1.5px;
  }
  .input-acts m3e-icon-button {
    --m3e-icon-button-container-shape: var(--r-sm) !important;
    border-radius: var(--r-sm) !important;
  }
  .input-toolbar {
    gap: 4px;
    align-items: center;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .input-toolbar::-webkit-scrollbar { display: none; }
  .composer-segbar {
    width: auto;
    flex: 0 0 auto;
    min-height: 0;
  }
  .seg-btn.model-btn { padding: 0 8px; font-size: 0; gap: 0; }
  .seg-btn.model-btn .ms { margin: 0; font-size: 18px; }
  .w-heading {
    font-size: 24px;
  }
  .seg-btn {
    padding: 6px 10px;
    height: 34px;
    font-size: 12px;
  }
  .seg-btn.icon-btn { width: 36px; padding: 0 8px; }
  .seg-btn.model-btn { min-width: 0; flex: 1 1 auto; }
  .quick-modes {
    order: unset;
    width: auto;
    display: flex;
    gap: 4px;
    flex-shrink: 0;
  }
  .quick-modes.qm-segment {
    border: 1.5px solid var(--out-v);
    border-radius: var(--r-pill);
    background: var(--surf-lo);
    padding: 2px;
  }
  .quick-modes.qm-segment .qm-pill {
    border: none;
    border-radius: var(--r-pill);
    justify-content: center;
  }
  .qm-pill {
    padding: 6px 10px;
    font-size: 12px;
  }
  .hist-scroll { padding-bottom: 80px; }
  .input-toolbar > m3e-icon-button#attach-btn { margin-left: auto; }
}
@media (max-width: 565px) {
  #model-name-display, #cat-badge { display: none !important; }
  .input-toolbar {
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
  }
  #topbar { padding: 0 8px; }
  .w-heading { font-size: 26px; }
  .msg-row.user .bubble,
  .msg-row.assistant .bubble { max-width: 94%; }
  .quick-modes {
    order: unset;
    width: auto;
  }
  .tools-pop {
    width: min(340px, calc(100vw - 20px));
    left: 0;
    right: auto;
  }
  /* Mobile: dropup fits screen, categories are icon-only except active */
  #dropup-panel {
    max-height: 80vh;
    bottom: calc(10px + var(--safe-bottom));
  }
  .du-cats {
    gap: 4px;
    padding: 8px 6px 6px;
    overflow-x: hidden;
    justify-content: center;
  }
  .du-cat {
    padding: 8px;
    font-size: 0; /* hide text by default */
    border-radius: var(--r-pill);
    min-width: 38px;
    justify-content: center;
  }
  .du-cat .ms { font-size: 18px; }
  .du-cat.active {
    font-size: 12px; /* show text for active */
    padding: 8px 14px;
    gap: 6px;
  }

  /* Compact toolbar on mobile */
  .composer-segbar {
    flex-wrap: wrap;
    gap: 4px;
  }

  .seg-btn.model-btn {
    flex: 1;
    min-width: 140px;
  }

  .model-label {
    max-width: 80px;
  }

  /* Ensure chat title stays visible */
  .chat-title-label {
    display: block;
  }

  /* Settings dialog mobile fixes */
  m3e-dialog::part(panel) {
    max-width: 100vw;
    max-height: 100vh;
    border-radius: 0;
  }

  .settings-panel-inner {
    padding: 12px 12px;
  }

  /* Tool calling UI mobile fixes */
  .tools-split {
    flex-direction: column;
  }

  .tools-nav {
    width: 100%;
    flex-direction: row;
    overflow-x: auto;
    border-right: none;
    border-bottom: 1px solid var(--out-v);
    padding: 8px;
  }

  .tool-nav-item {
    flex-direction: column;
    min-width: 100px;
    padding: 8px;
    text-align: center;
  }

  .tool-nav-meta {
    flex-direction: column;
    gap: 4px;
  }

  .tool-nav-titles {
    align-items: center;
  }

  .tool-nav-sub {
    font-size: 10px;
  }
}

@supports (height: 100dvh) {
  :root {
    --app-vh: 100dvh;
  }
}

@supports (padding: max(0px)) {
  :root {
    --safe-bottom: max(env(safe-area-inset-bottom, 0px), 0px);
  }
}

/* Mobile settings layout removed — m3e-tabs handles responsive */

@keyframes fadeIn {
  from { opacity: 0; } to { opacity: 1; }
}
@keyframes slideInL {
  from { transform: translateX(-100%); } to { transform: translateX(0); }
}

/* ══════════════════════════════════════════════
   SETTINGS
══════════════════════════════════════════════ */
m3e-dialog { max-width: 100vw; }
[data-theme="dark"] m3e-dialog { color-scheme: dark; }
m3e-dialog::part(panel) {
  max-width: 96vw;
  background: var(--surf) !important;
  color: var(--on-surf) !important;
  border: 1.5px solid var(--out-v) !important;
  box-shadow: var(--sh3);
  max-height: calc(var(--app-vh) - 12px);
  overflow: hidden;
  border-radius: var(--r-lg);
}
m3e-dialog::part(body) {
  background: var(--surf) !important;
  color: var(--on-surf) !important;
  padding: 0 0 calc(8px + var(--safe-bottom));
}
m3e-dialog::part(header),
m3e-dialog::part(footer) {
  background: var(--surf) !important;
  color: var(--on-surf) !important;
  border-color: var(--out-v) !important;
  padding: 12px 16px;
}
m3e-dialog::part(footer) { padding-top: 10px; }
m3e-dialog m3e-tab-panel {
  max-height: calc(var(--app-vh) - 210px - var(--safe-bottom));
  overflow-y: auto;
  padding: 0 10px calc(10px + var(--safe-bottom));
}

.settings-panel-inner {
  padding: 10px 12px; width: 100%; box-sizing: border-box; overflow-x: hidden;
}
.sec-title {
  font-size: 13px; font-weight: 800; color: var(--p);
  text-transform: uppercase; letter-spacing: .08em;
  margin: 10px 0 6px;
}
.srow {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 11px; background: var(--surf-lo);
  border-radius: var(--r-lg); border: 1px solid var(--out-v);
  margin-bottom: 6px;
}
.du-model.active { background: color-mix(in srgb, var(--p) 10%, transparent); }

@media (max-width: 600px) {
  m3e-dialog::part(panel) {
    max-width: calc(100vw - 8px);
    width: calc(100vw - 8px);
    max-height: calc(var(--app-vh) - 8px);
    border-radius: var(--r-md);
  }
  m3e-dialog m3e-tab-panel {
    max-height: calc(var(--app-vh) - 190px - var(--safe-bottom));
  }
  #settings-tabs {
    --m3e-tabs-paginator-button-icon-size: 1rem;
  }
  #settings-tabs m3e-tab {
    --m3e-tab-padding-start: .75rem;
    --m3e-tab-padding-end: .75rem;
    --m3e-tab-font-size: 12px;
    --m3e-tab-icon-size: 1.125rem;
    --m3e-tab-spacing: .3rem;
  }
  .settings-panel-inner {
    padding: 10px 10px;
  }
}

@media (max-width: 430px) {
  #settings-tabs m3e-tab {
    --m3e-tab-padding-start: .55rem;
    --m3e-tab-padding-end: .55rem;
    --m3e-tab-font-size: 11px;
    --m3e-tab-icon-size: 1rem;
    --m3e-tab-spacing: .2rem;
  }
}

/* ══════════════════════════════════════════════
   SIDEBAR QUICK NAV
══════════════════════════════════════════════ */
.side-quicknav {
  border-top: 1px solid var(--out-v);
  padding: 12px 8px 12px;
  margin-top: 0;
  flex-shrink: 0;
}
.qn-label {
  font-size: 10px; font-weight: 800;
  text-transform: uppercase; letter-spacing: .1em;
  color: var(--out); padding: 0 10px 6px;
}
.qn-item {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 10px; border-radius: var(--r-md);
  cursor: pointer; font-size: 13px; font-weight: 600;
  color: var(--on-surf-v); transition: all .2s var(--std);
  margin-bottom: 2px;
}
.qn-item:hover { background: var(--surf-mid); color: var(--on-surf); }
.qn-item:active { transform: scale(.97); }
.qn-item .ms { flex-shrink: 0; }
.qn-text { flex: 1; }
.qn-badge {
  font-size: 10px; font-weight: 800;
  padding: 2px 8px; border-radius: var(--r-pill);
}
.qn-badge.soon {
  background: color-mix(in srgb, var(--p) 15%, transparent);
  color: var(--p);
}

/* ══════════════════════════════════════════════
   DEMO MODE BADGE
══════════════════════════════════════════════ */
.demo-mode-pill {
  display: none; align-items: center; gap: 6px;
  padding: 3px 12px;
  background: var(--tc); color: var(--on-tc);
  border-radius: var(--r-pill);
  font-size: 11px; font-weight: 800;
  margin-left: auto;
}
.demo-mode-pill.show { display: flex; }

/* ══════════════════════════════════════════════
   DEMO MODE SECTION IN SETTINGS
══════════════════════════════════════════════ */
.demo-ui-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 10px; border-radius: var(--r-pill);
  background: color-mix(in srgb, var(--p) 15%, transparent);
  color: var(--p); font-size: 11px; font-weight: 800;
  margin-left: 8px;
}

/* ══════════════════════════════════════════════
   DEMO DATA BANNER
══════════════════════════════════════════════ */
#demo-data-banner {
  display: none; align-items: center; gap: 8px;
  padding: 8px 20px;
  background: var(--sc); color: var(--on-sc);
  font-size: 12px; font-weight: 700;
  border-bottom: 1px solid color-mix(in srgb, var(--s) 30%, transparent);
}
#demo-data-banner.show { display: flex; }
#demo-data-banner .demo-data-label {
  display: flex; align-items: center; gap: 6px;
  flex: 1;
}
#demo-data-banner .demo-data-exit {
  padding: 4px 14px; border-radius: var(--r-pill);
  border: 1.5px solid currentColor; background: transparent;
  color: inherit; font-size: 11px; font-weight: 800;
  cursor: pointer; transition: all var(--dur-short) var(--std);
  white-space: nowrap;
}
#demo-data-banner .demo-data-exit:hover {
  background: var(--on-sc); color: var(--sc);
}

/* ══════════════════════════════════════════════
   INSTALL GUIDE
══════════════════════════════════════════════ */
.install-guide {
  display: grid; gap: 12px;
}
.install-browser {
  background: var(--surf-lo);
  border: 1.5px solid var(--out-v);
  border-radius: var(--r-lg);
  padding: 14px 16px;
  transition: border-color var(--dur-short) var(--std);
}
.install-browser:hover {
  border-color: color-mix(in srgb, var(--p) 40%, var(--out-v));
}
.install-browser-head {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 10px;
}
.install-browser-icon {
  width: 32px; height: 32px; border-radius: var(--r-sm);
  background: var(--pc); color: var(--on-pc);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.install-browser-icon .ms { font-size: 18px; }
.install-browser-name {
  font-size: 14px; font-weight: 700; color: var(--on-surf);
}
.install-steps {
  display: grid; gap: 6px;
  padding-left: 42px;
}
.install-step {
  display: flex; align-items: flex-start; gap: 8px;
  font-size: 13px; color: var(--on-surf-v); line-height: 1.5;
}
.install-step-num {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--pc); color: var(--on-pc);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 800; flex-shrink: 0;
  margin-top: 1px;
}

/* ══════════════════════════════════════════════
   COLOR PALETTE RANDOMIZER
══════════════════════════════════════════════ */
.palette-row {
  display: flex; align-items: center; gap: 8px;
  flex-wrap: wrap;
}
.palette-btn {
  width: 24px; height: 24px; border-radius: 50%;
  cursor: pointer; border: 2px solid var(--out-v);
  background-clip: padding-box;
  transition: transform 0.2s, border-color 0.2s;
  box-shadow: var(--sh1);
}
.palette-btn:hover { transform: scale(1.15); border-color: var(--p); }

.mobile-only-btn { display: none; }
@media (max-width: 1200px) {
  .mobile-only-btn { display: inline-flex; }
}
