/* =========================================================
   Nexus Chat — stylesheet
   ========================================================= */

/* -------- Design tokens (dark default) -------- */
:root {
  --bg: #09090b;
  --bg-grad: #09090b;
  --surface: #111113;
  --surface-2: #18181b;
  --surface-3: #222225;
  --border: rgba(255, 255, 255, 0.07);
  --border-strong: rgba(255, 255, 255, 0.13);
  --text: #ececef;
  --text-muted: #8b8d98;
  --text-dim: #5c5e6a;

  --brand: #6e6eff;
  --brand-2: #8b8bff;
  --brand-grad: linear-gradient(135deg, #6e6eff 0%, #8b8bff 100%);
  --accent: #00c2a8;
  --success: #34d399;
  --warn: #fbbf24;
  --danger: #ef4444;

  --user-bg: rgba(110, 110, 255, 0.08);
  --user-border: rgba(110, 110, 255, 0.20);
  --bot-bg: #16161a;
  --bot-border: rgba(255, 255, 255, 0.08);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 24px 48px rgba(0, 0, 0, 0.5);

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  --sidebar-w: 280px;
  --maxw: 740px;

  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* -------- Light theme -------- */
[data-theme="light"] {
  --bg: #fafafa;
  --bg-grad: #fafafa;
  --surface: #ffffff;
  --surface-2: #f4f4f5;
  --surface-3: #e4e4e7;
  --border: rgba(0, 0, 0, 0.06);
  --border-strong: rgba(0, 0, 0, 0.12);
  --text: #09090b;
  --text-muted: #52525b;
  --text-dim: #a1a1aa;

  --user-bg: rgba(110, 110, 255, 0.06);
  --user-border: rgba(110, 110, 255, 0.18);
  --bot-bg: #ffffff;
  --bot-border: rgba(0, 0, 0, 0.06);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
}

/* -------- Base -------- */
* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--bg-grad);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
  /* Safe area for notch devices */
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
html {
  -webkit-text-size-adjust: 100%;
}
button { font-family: inherit; color: inherit; }
input, textarea, select { font-family: inherit; color: inherit; }
a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-2); }
::selection { background: rgba(124, 140, 255, 0.35); color: inherit; }

/* -------- Layout -------- */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
  overflow: hidden;
  transition: grid-template-columns 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

/* =========================================================
   SIDEBAR
   ========================================================= */
.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 14px;
  gap: 12px;
  min-height: 0;
  width: var(--sidebar-w);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), padding 0.3s cubic-bezier(0.16, 1, 0.3, 1), width 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
}
.logo { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo-icon {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: var(--brand);
  color: white;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.logo-name { font-weight: 700; letter-spacing: 0.2px; font-size: 14px; }
.logo-sub { font-size: 10px; color: var(--text-muted); letter-spacing: 0.6px; text-transform: uppercase; }

.new-chat-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 11px 14px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: transform 0.08s, background 0.15s, border-color 0.15s;
  position: relative;
}
.new-chat-btn:hover { background: var(--surface-3); border-color: var(--border-strong); }
.new-chat-btn:active { transform: translateY(1px); }
.new-chat-btn .kbd {
  margin-left: auto;
  background: rgba(255, 255, 255, 0.2);
  color: white;
  border: 0;
}

.search-box {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  color: var(--text-muted);
}
.search-box:focus-within {
  border-color: rgba(124, 140, 255, 0.55);
  box-shadow: 0 0 0 3px rgba(124, 140, 255, 0.12);
}
.search-box input {
  flex: 1;
  background: transparent;
  border: 0; outline: 0;
  font-size: 13px;
  color: var(--text);
  min-width: 0;
}
.search-box input::placeholder { color: var(--text-dim); }

.sidebar-section {
  display: flex; flex-direction: column; gap: 6px;
  flex: 1; min-height: 0;
}
.sidebar-label {
  color: var(--text-muted);
  font-size: 10px;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  padding: 0 6px;
  font-weight: 600;
}

.history {
  display: flex; flex-direction: column; gap: 2px;
  overflow-y: auto;
  padding: 2px;
  min-height: 0;
}
.history-empty {
  color: var(--text-dim);
  font-size: 13px;
  padding: 16px 8px;
  text-align: center;
}

.history-item {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 14px;
  border: 1px solid transparent;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  min-width: 0;
}
.history-item:hover { background: var(--surface-2); color: var(--text); }
.history-item.active {
  background: var(--surface-2);
  border-color: var(--border-strong);
  color: var(--text);
}
.history-item .icon { flex-shrink: 0; color: currentColor; opacity: 0.7; }
.history-item .title {
  flex: 1;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  min-width: 0;
  font-size: 13.5px;
}
.history-busy {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 194, 168, 0.14);
  flex-shrink: 0;
  animation: pulse-busy 1.4s ease-in-out infinite;
}
.history-item .pin-icon { color: var(--brand); flex-shrink: 0; }
.history-actions {
  display: flex; gap: 2px;
  opacity: 0;
  transition: opacity 0.15s;
}
.history-item:hover .history-actions,
.history-item.active .history-actions { opacity: 1; }
.history-actions button {
  background: transparent;
  border: 0;
  padding: 4px;
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.history-actions button:hover { background: var(--surface-3); color: var(--text); }
.history-actions .del:hover { color: var(--danger); background: rgba(248, 113, 113, 0.12); }

.sidebar-foot {
  display: grid;
  gap: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.sidebar-foot-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.account-dock {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  text-align: left;
  background: linear-gradient(180deg, rgba(110, 110, 255, 0.08), transparent), var(--surface-2);
  border: 1px solid rgba(110, 110, 255, 0.18);
  border-radius: 14px;
  padding: 10px 12px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.08s;
}
.account-dock:hover {
  border-color: rgba(110, 110, 255, 0.32);
  background: linear-gradient(180deg, rgba(110, 110, 255, 0.12), transparent), var(--surface-2);
}
.account-dock:active { transform: translateY(1px); }
.account-dock-copy {
  display: grid;
  gap: 2px;
  min-width: 0;
}
.account-dock-label {
  font-size: 10px;
  color: var(--brand-2);
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
}
.account-dock strong {
  font-size: 13px;
  color: var(--text);
  line-height: 1.2;
}
.account-dock span:last-child:not(.auth-badge) {
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.4;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.status-row {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  min-width: 0;
  flex: 1;
}
.status-row:hover { color: var(--text); }
.status-row span:not(.dot) {
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.18);
  animation: pulse 2s ease-in-out infinite;
  flex-shrink: 0;
}
.dot.offline {
  background: var(--danger);
  box-shadow: 0 0 0 3px rgba(248, 113, 113, 0.18);
  animation: none;
}
@keyframes pulse-busy {
  0%, 100% { transform: scale(1); opacity: 0.9; }
  50% { transform: scale(1.15); opacity: 1; }
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.18); }
  50%      { box-shadow: 0 0 0 6px rgba(52, 211, 153, 0.04); }
}

.foot-actions { display: flex; gap: 4px; flex-shrink: 0; }

.ghost-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.ghost-btn:hover { color: var(--text); border-color: var(--border-strong); background: var(--surface-2); }
.ghost-btn:active { transform: translateY(1px); }

.primary-btn {
  background: var(--brand);
  color: white;
  border: 0;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
  transition: filter 0.15s, transform 0.08s;
}
.primary-btn:hover { filter: brightness(1.15); }
.primary-btn:active { transform: translateY(1px); }
.primary-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.danger-btn {
  background: rgba(248, 113, 113, 0.10);
  color: var(--danger);
  border: 1px solid rgba(248, 113, 113, 0.28);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.danger-btn:hover { background: rgba(248, 113, 113, 0.18); }

.kbd {
  font-family: var(--font-mono);
  font-size: 10px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 5px;
  color: var(--text-muted);
  letter-spacing: 0.4px;
}

/* =========================================================
   MAIN
   ========================================================= */
.main {
  display: flex; flex-direction: column;
  min-width: 0; min-height: 0;
  position: relative;
}

.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 24px 0;
  background: transparent;
  border-bottom: none;
  position: sticky; top: 0; z-index: 5;
  min-height: 56px;
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.title-wrap {
  flex: 0 1 auto;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 8px 16px;
  border-radius: 16px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  justify-content: center;
  margin-right: auto;
}
.title {
  font-weight: 600;
  font-size: 14px;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 6px;
  margin-left: -4px;
  transition: background 0.15s;
}
.title:hover { background: var(--surface-2); }
.title-input {
  font-weight: 600;
  font-size: 15px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 2px 6px;
  margin-left: -6px;
  outline: none;
  color: var(--text);
  width: 100%;
  max-width: 400px;
}
.subtitle {
  font-size: 11px;
  color: var(--text-muted);
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  padding: 0 4px;
  margin-top: 1px;
}

.topbar-actions {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 4px;
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
}

/* =========================================================
   Custom Model Picker Dropdown
   ========================================================= */
.model-picker-custom {
  position: relative;
  display: inline-block;
}
.model-picker-trigger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 12px;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  min-width: 150px;
  justify-content: space-between;
}
.model-picker-trigger:hover {
  border-color: var(--border-strong);
  background: var(--surface-3);
}
.model-picker-trigger .model-icon {
  color: var(--text-muted);
  flex-shrink: 0;
}
.model-picker-trigger #model-selected-text {
  flex-grow: 1;
  text-align: left;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  margin-right: 4px;
}
.model-picker-trigger .chevron {
  color: var(--text-muted);
  transition: transform 0.2s ease;
  flex-shrink: 0;
}
.model-picker-custom.open .model-picker-trigger .chevron {
  transform: rotate(180deg);
}

.model-picker-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: 260px;
  max-height: 380px;
  overflow-y: auto;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  box-shadow: 0 10px 25px -5px rgba(0,0,0,0.3), 0 8px 16px -6px rgba(0,0,0,0.3);
  z-index: 1000;
  display: none;
  flex-direction: column;
  padding: 6px;
  animation: dropdown-fade-in 0.15s cubic-bezier(0.16, 1, 0.3, 1);
  transform-origin: top right;
}
.dropdown-container {
  position: relative;
}
.dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 180px;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  box-shadow: 0 10px 25px -5px rgba(0,0,0,0.3), 0 8px 16px -6px rgba(0,0,0,0.3);
  z-index: 1000;
  display: none;
  flex-direction: column;
  padding: 6px;
  animation: dropdown-fade-in 0.15s cubic-bezier(0.16, 1, 0.3, 1);
  transform-origin: top right;
}
.dropdown-item {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  color: var(--text-muted);
  font-size: 13px;
  gap: 10px;
  background: transparent;
  border: none;
  outline: none;
  width: 100%;
  text-align: left;
}
.dropdown-item:focus {
  outline: none;
}
.dropdown-item:hover {
  background: var(--surface-2);
  color: var(--text);
}
.dropdown-item.danger:hover {
  background: rgba(248, 113, 113, 0.12);
  color: var(--danger);
}
.dropdown-container.open .dropdown-menu {
  display: flex;
}
.model-picker-custom.open .model-picker-menu {
  display: flex;
}

@keyframes dropdown-fade-in {
  from { opacity: 0; transform: scale(0.96) translateY(-4px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.model-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  color: var(--text-muted);
  font-size: 13px;
  gap: 8px;
}
.model-item:hover {
  background: var(--surface-2);
  color: var(--text);
}
.model-item.active {
  background: rgba(124, 140, 255, 0.12);
  color: var(--brand-2);
  font-weight: 500;
}
.model-item-name {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.model-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 6px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.model-badge.flash {
  background: rgba(148, 163, 184, 0.12);
  color: var(--text-muted);
}
.model-badge.pro {
  background: rgba(59, 130, 246, 0.15);
  color: #60a5fa;
}
.model-badge.proplus {
  background: rgba(168, 85, 247, 0.15);
  color: #c084fc;
}
.model-badge.max {
  background: rgba(249, 115, 22, 0.15);
  color: #fb923c;
}

.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 36px; height: 36px;
  border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  flex-shrink: 0;
}
.icon-btn:hover { color: var(--text); border-color: var(--border-strong); background: var(--surface-2); }
.icon-btn.danger:hover { color: var(--danger); border-color: rgba(248, 113, 113, 0.28); background: rgba(248, 113, 113, 0.10); }

/* =========================================================
   CHAT AREA
   ========================================================= */
.chat {
  flex: 1;
  overflow-y: auto;
  padding: 32px 28px 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  scroll-behavior: smooth;
}
.chat > * { width: 100%; max-width: var(--maxw); margin: 0 auto; }

/* Welcome */
.welcome {
  margin: auto;
  text-align: center;
  padding: 30px 20px;
  animation: fade-up 0.4s ease both;
}
.welcome-badge {
  width: 56px; height: 56px;
  margin: 0 auto 16px;
  border-radius: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--brand);
  display: flex; align-items: center; justify-content: center;
}
.welcome h2 {
  margin: 0 0 6px;
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
}
.welcome p { color: var(--text-muted); margin: 0 0 24px; }

.suggestions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  max-width: 620px;
  margin: 0 auto;
}
.suggest {
  text-align: left;
  background: rgba(255, 255, 255, 0.02) !important;
  backdrop-filter: blur(8px) !important;
  -webkit-backdrop-filter: blur(8px) !important;
  border: 1px solid rgba(255, 255, 255, 0.06) !important;
  padding: 16px 18px !important;
  border-radius: 16px !important;
  cursor: pointer;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  column-gap: 12px; row-gap: 2px;
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), border-color 0.2s, background-color 0.2s !important;
}
.suggest:hover {
  transform: translateY(-2px) !important;
  border-color: rgba(255, 255, 255, 0.12) !important;
  background: rgba(255, 255, 255, 0.05) !important;
}
.suggest-icon { grid-row: 1 / span 2; font-size: 20px; align-self: center; }
.suggest-title { font-weight: 600; font-size: 14px; color: var(--text); }
.suggest-sub { color: var(--text-muted); font-size: 13px; }

@keyframes fade-up {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Messages */
.msg {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  animation: fade-up 0.25s ease both;
}
.msg.user { flex-direction: row-reverse; }

.avatar {
  flex: 0 0 36px;
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700;
  letter-spacing: 0.3px;
}
.msg.user .avatar {
  background: linear-gradient(135deg, #ff8e53 0%, #ff4b91 100%) !important;
  border: 1px solid rgba(255, 255, 255, 0.15) !important;
  color: #fff !important;
  box-shadow: 0 0 10px rgba(255, 75, 145, 0.2);
}
.msg.bot .avatar {
  background: linear-gradient(135deg, #8b8bff 0%, #6e6eff 100%) !important;
  border: 1px solid rgba(255, 255, 255, 0.15) !important;
  box-shadow: 0 0 10px rgba(110, 110, 255, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
}

.bubble-wrap {
  max-width: calc(100% - 48px);
  display: flex; flex-direction: column; gap: 6px;
  min-width: 0;
}
.msg.user .bubble-wrap { align-items: flex-end; }

.bubble {
  background: var(--bot-bg);
  border: 1px solid var(--bot-border);
  padding: 12px 16px;
  border-radius: 14px;
  border-top-left-radius: 4px;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  box-shadow: var(--shadow-sm);
  min-width: 0;
  max-width: 100%;
  line-height: 1.6;
}
.bubble.is-streaming-preview {
  contain: content;
}
.stream-preview {
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  min-height: 1.4em;
}
.msg.user .bubble {
  background: var(--user-bg);
  border-color: var(--user-border);
  border-top-left-radius: 16px;
  border-top-right-radius: 4px;
}

.msg-meta {
  display: flex; align-items: center; gap: 10px;
  font-size: 11px;
  color: var(--text-dim);
  padding: 0 2px;
  opacity: 0;
  transition: opacity 0.15s;
}
.msg:hover .msg-meta { opacity: 1; }
.msg-actions { display: flex; gap: 2px; }
.msg-action {
  background: transparent;
  border: 0;
  color: var(--text-muted);
  cursor: pointer;
  padding: 3px 6px;
  border-radius: 5px;
  font-size: 11px;
  display: inline-flex; align-items: center; gap: 4px;
  transition: color 0.15s, background 0.15s;
}
.msg-action:hover { color: var(--text); background: var(--surface-2); }
.msg-action.success { color: var(--success); }

/* Markdown inside bubble */
.bubble p { margin: 0 0 12px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble h1, .bubble h2, .bubble h3, .bubble h4 {
  margin: 18px 0 10px; line-height: 1.3;
  color: var(--text);
}
.bubble h1 { font-size: 1.35em; font-weight: 700; }
.bubble h2 { font-size: 1.2em; font-weight: 700; }
.bubble h3 { font-size: 1.08em; font-weight: 600; }
.bubble h1:first-child, .bubble h2:first-child, .bubble h3:first-child { margin-top: 0; }
.bubble ul, .bubble ol { margin: 8px 0 12px; padding-left: 24px; }
.bubble li { margin: 4px 0; line-height: 1.6; }
.bubble li > p { margin: 0; }
.bubble strong { color: var(--text); font-weight: 600; }
.bubble a { border-bottom: 1px dashed currentColor; }
.bubble blockquote {
  margin: 10px 0;
  padding: 10px 14px;
  border-left: 3px solid var(--brand);
  background: var(--surface-2);
  border-radius: 0 8px 8px 0;
  color: var(--text-muted);
  font-size: 14px;
}
.bubble hr {
  border: 0; border-top: 1px solid var(--border);
  margin: 16px 0;
}
.bubble :not(pre) > code {
  background: var(--surface-3);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 0.88em;
}

.bubble pre {
  background: rgba(9, 9, 11, 0.65) !important;
  border: 1px solid rgba(255, 255, 255, 0.06) !important;
  padding: 0;
  border-radius: 12px;
  margin: 12px 0;
  position: relative;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35) !important;
}
[data-theme="light"] .bubble pre {
  background: var(--surface-2) !important;
  border: 1px solid var(--border-strong) !important;
  box-shadow: var(--shadow-sm) !important;
}

.bubble pre .code-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.02) !important;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06) !important;
  color: #a1a1aa;
  font-size: 11px;
  font-family: var(--font-mono);
  letter-spacing: 0.4px;
  text-transform: uppercase;
}
[data-theme="light"] .bubble pre .code-head {
  background: var(--surface-3) !important;
  border-bottom: 1px solid var(--border-strong) !important;
  color: var(--text-muted);
}

.bubble pre code {
  display: block;
  padding: 12px 14px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.5;
  color: #e6edf3;
  background: transparent;
}
[data-theme="light"] .bubble pre code {
  color: var(--text);
}

.copy-btn {
  background: rgba(255, 255, 255, 0.03) !important;
  color: #a1a1aa !important;
  border: 1px solid rgba(255, 255, 255, 0.06) !important;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 11.5px;
  cursor: pointer;
  display: inline-flex; align-items: center; gap: 5px;
  font-family: var(--font-sans);
  text-transform: none;
  letter-spacing: 0;
  transition: color 0.15s, border-color 0.15s, background-color 0.15s;
}
.copy-btn:hover { color: #fff !important; border-color: rgba(255, 255, 255, 0.15) !important; background-color: rgba(255, 255, 255, 0.08) !important; }
.copy-btn.copied { color: var(--success) !important; border-color: rgba(52, 211, 153, 0.35) !important; }

[data-theme="light"] .copy-btn {
  background: var(--surface) !important;
  color: var(--text-muted) !important;
  border-color: var(--border-strong) !important;
}
[data-theme="light"] .copy-btn:hover {
  background: var(--surface-2) !important;
  color: var(--text) !important;
}
.copy-btn.icon-only {
  width: 28px;
  min-width: 28px;
  padding: 0;
  justify-content: center;
}

.bubble table {
  border-collapse: collapse;
  width: 100%;
  margin: 12px 0;
  font-size: 13.5px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  display: block;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.bubble th, .bubble td {
  border: 1px solid var(--border);
  padding: 10px 12px;
  text-align: left;
  line-height: 1.5;
}
.bubble th {
  background: var(--surface-3);
  font-weight: 600;
  font-size: 12.5px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--text-muted);
}
.bubble tr:nth-child(even) td { background: var(--surface-2); }

/* Editing a message */
.edit-area {
  width: 100%;
  min-height: 60px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  line-height: 1.5;
  resize: vertical;
  outline: none;
}
.edit-actions { display: flex; gap: 6px; margin-top: 6px; justify-content: flex-end; }

/* Typing */
.bubble.typing-caret::after {
  content: "";
  display: inline-block;
  width: 8px; height: 14px;
  background: var(--brand);
  margin-left: 2px;
  vertical-align: -2px;
  border-radius: 1px;
  animation: caret 1s step-end infinite;
}
@keyframes caret { 50% { opacity: 0; } }

.typing-dots { display: inline-flex; gap: 4px; align-items: center; height: 18px; }
.typing-dots span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-muted);
  animation: dot 1.2s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes dot {
  0%, 80%, 100% { opacity: 0.3; transform: translateY(0); }
  40%           { opacity: 1;   transform: translateY(-3px); }
}

/* =========================================================
   JUMP TO BOTTOM
   ========================================================= */
.jump-bottom {
  position: absolute;
  right: max(28px, calc(50% - var(--maxw) / 2 + 28px));
  bottom: calc(100% + 16px);
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  display: none;
  align-items: center; justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow);
  z-index: 6;
  transition: transform 0.12s;
}
.jump-bottom:hover { transform: translateY(-2px); }
.jump-bottom.show { display: inline-flex; }

/* =========================================================
   COMPOSER
   ========================================================= */
.composer {
  position: relative;
  border-top: none;
  padding: 10px 28px 8px;
  background: transparent;
  backdrop-filter: none;
}
.composer.is-image-mode {
  background: color-mix(in srgb, var(--surface) 70%, transparent);
  backdrop-filter: blur(12px);
}
#form {
  max-width: var(--maxw);
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas:
    "reply-preview reply-preview"
    "attachments   attachments"
    "textarea      actions";
  row-gap: 2px;
  align-items: end;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 6px 8px 6px 14px;
  box-shadow: var(--shadow);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.composer.is-image-mode #form {
  background: var(--surface);
}
#form:focus-within {
  border-color: rgba(110, 110, 255, 0.45);
  box-shadow: 0 0 0 3px rgba(110, 110, 255, 0.08), var(--shadow);
}
#form > #reply-preview { grid-area: reply-preview; }
#form > #attachments { grid-area: attachments; }
#form > #input { grid-area: textarea; }
#form > .composer-actions { grid-area: actions; display: flex; gap: 6px; align-items: center; padding-bottom: 1px; }
#input {
  flex: 1;
  background: transparent;
  color: var(--text);
  border: 0; outline: 0;
  resize: none;
  font-family: inherit;
  font-size: 14px;
  max-height: 220px;
  line-height: 1.4;
  padding: 8px 0;
}
#input::placeholder { color: var(--text-dim); }

.composer-actions { display: flex; gap: 6px; align-items: center; }
.send-btn {
  background: var(--brand);
  color: white;
  border: 0;
  width: 36px; height: 36px;
  border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: filter 0.15s, opacity 0.15s, transform 0.08s;
}
.send-btn:hover { filter: brightness(1.15); }
.send-btn:active { transform: translateY(1px); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.stop-btn {
  background: rgba(248, 113, 113, 0.12);
  color: var(--danger);
  border: 1px solid rgba(248, 113, 113, 0.3);
  width: 36px; height: 36px;
  border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background 0.15s;
}
.stop-btn:hover { background: rgba(248, 113, 113, 0.22); }

.foot-row {
  max-width: var(--maxw);
  margin: 4px auto 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 11px;
}
.status { color: var(--text-muted); min-height: 14px; }
.status.err { color: var(--danger); }
.foot-hint { color: var(--text-dim); font-size: 10.5px; }

/* =========================================================
   MODAL
   ========================================================= */
.modal {
  position: fixed; inset: 0;
  display: none;
  z-index: 100;
  align-items: center; justify-content: center;
  padding: 20px;
}
.modal.show { display: flex; }
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  animation: fade 0.15s ease both;
}
.modal-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 680px;
  max-height: calc(100vh - 40px);
  display: flex;
  flex-direction: column;
  animation: pop 0.2s ease both;
  overflow: hidden;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop  { from { opacity: 0; transform: scale(0.96) translateY(10px); } to { opacity: 1; transform: scale(1) translateY(0); } }

.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 16px; font-weight: 600; }

.tabs {
  display: flex;
  gap: 2px;
  padding: 4px 12px 0;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.tab {
  background: transparent;
  border: 0;
  color: var(--text-muted);
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--brand); }

.modal-body {
  padding: 18px 20px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}
.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fade 0.2s ease both; }

.field { margin-bottom: 16px; display: flex; flex-direction: column; gap: 6px; }
.field > label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: flex; align-items: center; justify-content: space-between;
}
.field .hint { color: var(--text-dim); font-weight: 400; text-transform: none; letter-spacing: 0; font-size: 11px; }
.field small { color: var(--text-dim); font-size: 12px; }

.field input[type="text"],
.field input[type="number"],
.field textarea,
.field select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  width: 100%;
}
.field textarea { resize: vertical; min-height: 70px; font-family: inherit; line-height: 1.5; }
.field input:focus,
.field textarea:focus,
.field select:focus {
  border-color: rgba(124, 140, 255, 0.55);
  box-shadow: 0 0 0 3px rgba(124, 140, 255, 0.15);
}

.field input[type="range"] {
  width: 100%;
  -webkit-appearance: none; appearance: none;
  height: 4px;
  background: var(--surface-3);
  border-radius: 4px;
  outline: none;
}
.field input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 16px; height: 16px;
  background: var(--brand-grad);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(124, 140, 255, 0.4);
}
.field input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px;
  background: #7c8cff;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
}

.value-badge {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 2px 8px;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: none;
  font-weight: 600;
  letter-spacing: 0;
}

.field-row {
  display: flex; flex-wrap: wrap; gap: 10px 20px;
  padding: 12px;
  background: var(--surface-2);
  border-radius: 10px;
  border: 1px solid var(--border);
}
.account-shell {
  display: grid;
  gap: 16px;
}
.account-compact-card {
  display: grid;
  gap: 12px;
  padding: 18px;
  border-radius: 16px;
  border: 1px solid rgba(110, 110, 255, 0.16);
  background:
    radial-gradient(circle at top left, rgba(110, 110, 255, 0.14), transparent 42%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.015), transparent),
    var(--surface-2);
}
.account-compact-copy {
  display: grid;
  gap: 6px;
}
.auth-hero {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(280px, 0.9fr);
  gap: 14px;
  align-items: stretch;
}
.auth-hero-copy {
  padding: 18px 20px;
  border-radius: 16px;
  border: 1px solid rgba(110, 110, 255, 0.18);
  background:
    radial-gradient(circle at top left, rgba(110, 110, 255, 0.16), transparent 42%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.02), transparent),
    var(--surface-2);
}
.auth-eyebrow,
.auth-pane-kicker,
.auth-status-kicker {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  line-height: 1;
  color: var(--brand-2);
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
}
.auth-hero-copy h4,
.auth-pane-head h5 {
  margin: 10px 0 6px;
  font-size: 20px;
  line-height: 1.2;
  color: var(--text);
}
.auth-pane-head h5 {
  font-size: 17px;
}
.auth-hero-copy p,
.auth-pane-head p {
  margin: 0;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.65;
}
.auth-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: var(--shadow-sm);
}
.auth-status-card {
  justify-content: center;
  min-height: 100%;
  position: relative;
  background:
    linear-gradient(135deg, rgba(110, 110, 255, 0.15) 0%, transparent 60%),
    linear-gradient(225deg, rgba(0, 194, 168, 0.1) 0%, transparent 60%),
    var(--surface-2);
  border: 1px solid rgba(110, 110, 255, 0.25);
  box-shadow: 0 4px 20px rgba(110, 110, 255, 0.08);
}
[data-theme="light"] .auth-status-card {
  background:
    linear-gradient(135deg, rgba(110, 110, 255, 0.08) 0%, transparent 60%),
    linear-gradient(225deg, rgba(0, 194, 168, 0.06) 0%, transparent 60%),
    var(--surface-2);
  border-color: rgba(110, 110, 255, 0.2);
  box-shadow: 0 4px 16px rgba(110, 110, 255, 0.05);
}
.auth-status-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.auth-status-main {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.auth-status-main strong {
  font-size: 18px;
  line-height: 1.2;
  color: var(--text);
}
.auth-status-sub {
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.65;
}
.auth-badge {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-3);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}
.auth-badge.is-auth {
  color: #dbeafe;
  border-color: rgba(59, 130, 246, 0.35);
  background: rgba(59, 130, 246, 0.16);
}
.auth-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.auth-pane {
  display: grid;
  gap: 14px;
  padding: 18px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.015), transparent), var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 16px;
}
.auth-pane-register {
  border-color: rgba(110, 110, 255, 0.18);
}
.auth-pane-head {
  display: grid;
  gap: 6px;
}
.auth-form {
  display: grid;
  gap: 10px;
}
.auth-form-pro {
  gap: 12px;
}
.auth-input-group {
  display: grid;
  gap: 6px;
}
.auth-input-group label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
}
.auth-input-shell {
  display: flex;
  align-items: center;
  min-height: 48px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.02), transparent),
    rgba(255, 255, 255, 0.02);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.03),
    0 8px 18px rgba(0, 0, 0, 0.14);
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
.auth-input-shell:focus-within {
  border-color: rgba(110, 110, 255, 0.55);
  background:
    linear-gradient(180deg, rgba(110, 110, 255, 0.05), transparent),
    rgba(255, 255, 255, 0.03);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.04),
    0 0 0 4px rgba(110, 110, 255, 0.10),
    0 10px 24px rgba(0, 0, 0, 0.18);
}
.auth-input-shell input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  padding: 0;
  font-size: 14px;
  font-weight: 500;
  box-shadow: none !important;
}
.auth-input-shell input::placeholder {
  color: color-mix(in srgb, var(--text-dim) 82%, white 18%);
  font-weight: 400;
}
.auth-field-note {
  margin-top: 1px;
  color: var(--text-dim);
  font-size: 11.5px;
  line-height: 1.5;
}
.auth-toggle {
  min-height: 40px;
  align-items: flex-start;
  margin-top: 2px;
}
.auth-btn-row {
  justify-content: flex-start;
  margin-top: 4px;
}
.auth-submit-btn {
  min-width: 120px;
  justify-content: center;
  min-height: 42px;
  border-radius: 11px;
  box-shadow: 0 12px 24px rgba(110, 110, 255, 0.18);
}
.auth-pane-logout {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}
.auth-pane-logout small {
  grid-column: 1 / -1;
}
.auth-pane-modal {
  display: none;
}
.auth-pane-modal.active {
  display: grid;
}
.auth-form .btn-row {
  margin-top: 2px;
}
.toggle {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 500;
}
.toggle input {
  appearance: none; -webkit-appearance: none;
  width: 32px; height: 18px;
  background: var(--surface-3);
  border-radius: 10px;
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
  border: 1px solid var(--border);
}
.toggle input::before {
  content: "";
  position: absolute;
  left: 2px; top: 50%;
  transform: translateY(-50%);
  width: 12px; height: 12px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: left 0.2s, background 0.2s;
}
.toggle input:checked { background: rgba(124, 140, 255, 0.35); border-color: rgba(124, 140, 255, 0.55); }
.toggle input:checked::before { left: 16px; background: var(--brand); }

/* Model manager */
.pull-row { display: flex; gap: 8px; }
.pull-row input { flex: 1; }
.pull-progress { margin-top: 10px; }
.pull-status { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.pull-bar {
  height: 6px;
  background: var(--surface-3);
  border-radius: 4px;
  overflow: hidden;
}
.pull-fill {
  height: 100%;
  width: 0;
  background: var(--brand-grad);
  border-radius: 4px;
  transition: width 0.2s ease;
}

.model-list {
  display: flex; flex-direction: column; gap: 6px;
  max-height: 260px;
  overflow-y: auto;
  padding: 2px;
}
.model-list-empty {
  text-align: center;
  color: var(--text-dim);
  padding: 20px;
  font-size: 13px;
}
.model-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}
.model-row .info { flex: 1; min-width: 0; }
.model-row .name { font-weight: 600; font-size: 13.5px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.model-row .meta { color: var(--text-muted); font-size: 11.5px; margin-top: 2px; display: flex; gap: 10px; flex-wrap: wrap; }
.model-row .meta span { font-family: var(--font-mono); }

/* Stats grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
}
.stat-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
}
.stat-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  font-weight: 600;
}
.stat-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  margin-top: 4px;
  font-family: var(--font-mono);
}

/* Danger zone */
.danger-zone {
  background: rgba(248, 113, 113, 0.05);
  border: 1px solid rgba(248, 113, 113, 0.2);
  border-radius: 10px;
  padding: 14px;
  margin-top: 6px;
}
.danger-label { color: var(--danger) !important; }

/* Buttons inline */
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.btn-row label.ghost-btn { cursor: pointer; }

/* About panel */
.about { text-align: center; padding: 8px 4px 4px; }
.about-logo {
  width: 56px; height: 56px;
  margin: 0 auto 12px;
  border-radius: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--brand);
  display: flex; align-items: center; justify-content: center;
}
.about h3 { margin: 0 0 8px; font-size: 18px; }
.about .muted { color: var(--text-muted); font-size: 13px; max-width: 460px; margin: 0 auto 18px; }
.shortcuts {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 8px;
  max-width: 480px;
  margin: 0 auto;
  font-size: 12.5px;
  color: var(--text-muted);
  text-align: left;
}
.shortcuts > div {
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 8px 10px;
  border-radius: 8px;
  display: flex; align-items: center; gap: 6px;
}

.modal-foot {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.auth-modal-card {
  max-width: 540px;
}
.auth-modal-head {
  align-items: flex-start;
}
.auth-modal-subtitle {
  margin-top: 4px;
  font-size: 13px;
  color: var(--text-muted);
}
.auth-modal-body {
  padding: 16px 20px 18px;
  overflow-y: auto;
  display: grid;
  gap: 16px;
}
.auth-hero-compact {
  grid-template-columns: 1fr;
}
.auth-switch {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: fit-content;
}
.auth-switch-btn {
  background: transparent;
  border: 0;
  color: var(--text-muted);
  padding: 8px 14px;
  border-radius: 9px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.auth-switch-btn.active {
  background: var(--brand);
  color: #fff;
}
.auth-modal-panels {
  display: grid;
}
.auth-modal-foot {
  justify-content: space-between;
}
[data-theme="light"] .auth-input-shell {
  border-color: rgba(0, 0, 0, 0.08);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(255, 255, 255, 0.82)),
    var(--surface);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.65),
    0 8px 20px rgba(0, 0, 0, 0.05);
}
[data-theme="light"] .auth-input-shell:focus-within {
  border-color: rgba(110, 110, 255, 0.45);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.75),
    0 0 0 4px rgba(110, 110, 255, 0.10),
    0 10px 24px rgba(0, 0, 0, 0.07);
}

/* =========================================================
   TOASTS
   ========================================================= */
.toasts {
  position: fixed;
  bottom: 20px; right: 20px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 200;
  pointer-events: none;
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--brand);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  min-width: 240px;
  max-width: 360px;
  pointer-events: auto;
  animation: toast-in 0.25s ease both;
}
.toast.success { border-left-color: var(--success); }
.toast.error   { border-left-color: var(--danger); }
.toast.warn    { border-left-color: var(--warn); }
.toast.hide    { animation: toast-out 0.2s ease both; }
@keyframes toast-in  { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }
@keyframes toast-out { to   { opacity: 0; transform: translateX(20px); } }

/* =========================================================
   SCROLLBARS
   ========================================================= */
.chat::-webkit-scrollbar,
.history::-webkit-scrollbar,
.modal-body::-webkit-scrollbar,
.model-list::-webkit-scrollbar,
.bubble pre::-webkit-scrollbar {
  width: 10px; height: 10px;
}
.chat::-webkit-scrollbar-thumb,
.history::-webkit-scrollbar-thumb,
.modal-body::-webkit-scrollbar-thumb,
.model-list::-webkit-scrollbar-thumb,
.bubble pre::-webkit-scrollbar-thumb {
  background: var(--surface-3);
  border-radius: 10px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
.chat::-webkit-scrollbar-thumb:hover,
.history::-webkit-scrollbar-thumb:hover { background: var(--border-strong); background-clip: padding-box; }

/* =========================================================
   BACKDROP (mobile sidebar)
   ========================================================= */
.backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s;
  z-index: 20;
}
.backdrop.show { opacity: 1; pointer-events: auto; }

/* =========================================================
   RESPONSIVE
   ========================================================= */
.mobile-only { display: none; }

/* Tablet (860px and below) */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    top: 0; bottom: 0; left: 0;
    width: 300px;
    max-width: 85vw;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 30;
    background: var(--surface);
  }
  .sidebar.open { transform: translateX(0); box-shadow: 20px 0 50px rgba(0,0,0,0.4); }
  .mobile-only { display: inline-flex; }
  #sidebar-close-btn { display: none !important; }
  .suggestions { grid-template-columns: 1fr; }
  .chat { padding: 20px 16px 10px; gap: 16px; }
  .composer { padding: 12px 16px 14px; }
  .topbar { padding: 10px 16px; min-height: 52px; }
  .topbar-actions .icon-btn:not(.mobile-keep) { display: none; }
  .model-picker select { min-width: 90px; font-size: 12px; }
  .model-picker { padding: 5px 8px 5px 10px; }
  .jump-bottom { right: 16px; bottom: calc(100% + 12px); }
  .modal { padding: 10px; }
  .modal-card { max-height: calc(100vh - 20px); border-radius: var(--radius-lg); }
  .tabs { padding: 4px 8px 0; }
  .tab { padding: 8px 10px; font-size: 12px; }
  .bubble { padding: 14px 16px; }
  .bubble pre code { font-size: 12px; padding: 10px 12px; }
  .mermaid-diagram { padding: 12px; }
  .sources-grid { grid-template-columns: 1fr; }
  .bubble pre .code-head { gap: 8px; flex-wrap: wrap; }
  .bubble pre .code-head > div:last-child { display: flex; flex-wrap: wrap; gap: 6px; }
  .msg { gap: 10px; }
  .attachments { gap: 5px; }
  .auth-hero,
  .auth-grid {
    grid-template-columns: 1fr;
  }
  .auth-pane-logout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  .topbar {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas:
      "menu title actions";
    align-items: center;
  }
  #sidebar-open { grid-area: menu; }
  .title-wrap { grid-area: title; }
  .topbar-actions {
    grid-area: actions;
    min-width: 0;
  }
  .title {
    font-size: 14px;
  }
  .subtitle {
    max-width: 100%;
  }
  .composer {
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }
  #form {
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "reply-preview reply-preview"
      "attachments   attachments"
      "textarea      actions";
    padding: 8px 10px;
    row-gap: 4px;
    column-gap: 8px;
  }
  #form > .composer-actions {
    justify-content: flex-end;
    padding-bottom: 0;
  }
  #input {
    min-height: 36px;
    padding: 6px 0;
  }
  .foot-row {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }
  .bubble {
    line-height: 1.62;
  }
  .attach-chip {
    max-width: 100%;
  }
}

/* Phone (520px and below) */
@media (max-width: 520px) {
  :root { --maxw: 100%; }
  .chat { padding: 14px 10px 8px; gap: 14px; }
  .composer {
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  }
  .jump-bottom { right: 8px; }
  .topbar { padding: 8px 12px; min-height: 48px; gap: 8px; }
  .title { font-size: 14px; }
  .subtitle { font-size: 10px; }
  .model-picker {
    padding: 4px 6px 4px 8px;
    border-radius: 8px;
    min-width: 0;
    max-width: 45vw;
  }
  .model-picker svg { display: none; }
  .model-picker select {
    min-width: 0;
    width: 100%;
    font-size: 11px;
    max-width: 100%;
  }
  .topbar-actions { gap: 4px; }

  .avatar { flex: 0 0 30px; width: 30px; height: 30px; font-size: 11px; }
  .bubble-wrap { max-width: calc(100% - 38px); }
  .bubble { padding: 12px 14px; border-radius: 14px; font-size: 14px; line-height: 1.6; }
  .msg.user .bubble { border-top-right-radius: 4px; border-top-left-radius: 14px; }
  .msg.bot .bubble { border-top-left-radius: 4px; }

  .bubble h1 { font-size: 1.2em; }
  .bubble h2 { font-size: 1.1em; }
  .bubble h3 { font-size: 1.05em; }
  .bubble pre { margin: 8px -6px; border-radius: 10px; }
  .bubble pre code { font-size: 11.5px; padding: 10px; }
  .bubble table { font-size: 12px; }
  .bubble th, .bubble td { padding: 6px 8px; }
  .bubble ul, .bubble ol { padding-left: 20px; }
  .bubble blockquote { font-size: 13px; padding: 8px 10px; }

  #form { padding: 6px 8px; border-radius: 12px; }
  #input { font-size: 14px; padding: 6px 0; min-height: 36px; }
  .send-btn { width: 32px; height: 32px; border-radius: 8px; }
  .stop-btn { width: 32px; height: 32px; border-radius: 8px; }
  .tool-btn { width: 32px; height: 32px; border-radius: 8px; }
  .composer-actions {
    width: auto;
    justify-content: flex-end;
    gap: 4px;
  }

  .mode-switch { margin: 0 auto 6px; }
  .mode-btn { padding: 5px 10px; font-size: 11px; }

  .welcome { padding: 20px 10px; }
  .welcome h2 { font-size: 20px; }
  .welcome p { font-size: 13px; }
  .welcome-badge { width: 48px; height: 48px; border-radius: 12px; }
  .welcome-badge svg { width: 22px; height: 22px; }
  .suggest { padding: 10px; }
  .suggest-icon { font-size: 16px; }
  .suggest-title { font-size: 13px; }
  .suggest-sub { font-size: 12px; }

  .foot-row { font-size: 11px; flex-wrap: wrap; gap: 4px; margin-top: 2px; }
  .foot-hint { display: none; }
  .status { min-height: 0; }
  .status:empty { display: none; }
  .foot-row:has(.status:empty) { display: none; }

  .msg-meta { font-size: 10px; }
  .msg-action { font-size: 10px; padding: 2px 4px; }
  .msg-action span { display: none; }
  .msg-actions { gap: 4px; }

  .mermaid-wrapper { margin: 8px -6px; }
  .mermaid-toolbar { padding: 6px 10px; flex-wrap: wrap; gap: 6px; }
  .mermaid-label { font-size: 11px; }
  .mermaid-diagram { padding: 10px; min-height: 60px; }
  .mermaid-fullscreen-card { inset: 10px; border-radius: 14px; }
  .mermaid-fullscreen-head { padding: 10px; flex-wrap: wrap; }
  .mermaid-fullscreen-diagram { padding: 14px; }

  .sources { padding: 8px 10px; }
  .source-pill { padding: 6px 8px; font-size: 11px; }
  .source-n { width: 18px; height: 18px; font-size: 10px; }

  .search-progress { font-size: 11px; padding: 5px 10px; }

  .think-block { font-size: 12px; }
  .think-head { padding: 6px 10px; }
  .think-body { padding: 4px 10px 10px; font-size: 11px; max-height: 200px; }

  .img-card img { max-width: 100%; }

  /* Preview modal full screen on phone */
  .preview-card { inset: 0; border-radius: 0; }
  .preview-head { padding: 6px 8px; }
  .preview-tabs { margin-left: 0; order: 3; width: 100%; }
  .ptab { padding: 5px 10px; font-size: 11px; }
  .modal {
    padding: 0;
    align-items: stretch;
  }
  .modal-card {
    max-height: 100vh;
    border-radius: 0;
    min-height: 100vh;
  }
  .modal-head,
  .modal-body {
    padding-left: 14px;
    padding-right: 14px;
  }
  .tabs {
    padding-left: 10px;
    padding-right: 10px;
  }
  .sidebar {
    width: min(300px, 88vw);
    padding-bottom: calc(14px + env(safe-area-inset-bottom));
  }
  .auth-hero-copy,
  .auth-pane,
  .auth-status-card {
    padding: 14px;
    border-radius: 14px;
  }
  .auth-hero-copy h4,
  .auth-pane-head h5 {
    font-size: 16px;
  }
  .auth-modal-card {
    max-width: none;
  }
}

/* Very small phones (360px and below) */
@media (max-width: 360px) {
  .topbar { padding: 6px 8px; }
  .title { font-size: 13px; max-width: 100%; }
  .model-picker { max-width: 42vw; }
  .model-picker select { min-width: 0; font-size: 10.5px; }
  .chat { padding: 10px 8px 6px; }
  .composer { padding: 8px 8px 10px; }
  #form { padding: 6px 6px 6px 10px; }
  .bubble { padding: 10px 12px; font-size: 13.5px; }
  .avatar { flex: 0 0 26px; width: 26px; height: 26px; font-size: 10px; }
  .bubble-wrap { max-width: calc(100% - 34px); }
  .sidebar { width: 260px; }
  .mode-btn { padding: 5px 8px; }
}


/* =========================================================
   MODE SWITCH (Chat / Image)
   ========================================================= */
.mode-switch {
  max-width: var(--maxw);
  margin: 0 auto 6px;
  display: flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 2px;
  gap: 2px;
  width: fit-content;
}
.composer .mode-switch { display: flex; }
.mode-btn {
  background: transparent;
  border: 0;
  color: var(--text-muted);
  padding: 5px 10px;
  border-radius: 7px;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
  transition: background 0.15s, color 0.15s;
}
.mode-btn:hover { color: var(--text); }
.mode-btn.active {
  background: var(--brand);
  color: white;
}

/* =========================================================
   IMAGE CARD in messages
   ========================================================= */
.img-card {
  position: relative;
  margin: 6px 0;
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface-3);
  border: 1px solid var(--border);
  display: inline-block;
  max-width: 100%;
}
.img-card img {
  display: block;
  width: 100%;
  max-width: 520px;
  height: auto;
}
.img-card-meta {
  position: absolute;
  bottom: 8px; left: 8px; right: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.img-card-meta > * { pointer-events: auto; }
.img-tag {
  background: rgba(0, 0, 0, 0.6);
  color: white;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-family: var(--font-mono);
  backdrop-filter: blur(4px);
}
.img-actions { display: flex; gap: 4px; }
.img-act {
  background: rgba(0, 0, 0, 0.6);
  color: white;
  border: 0;
  padding: 5px 8px;
  border-radius: 6px;
  font-size: 11px;
  cursor: pointer;
  display: inline-flex; align-items: center; gap: 4px;
  backdrop-filter: blur(4px);
  transition: background 0.15s;
}
.img-act:hover { background: rgba(0, 0, 0, 0.85); }

/* Image skeleton */
.img-skeleton {
  width: 320px;
  max-width: 100%;
  aspect-ratio: 1/1;
  background: linear-gradient(110deg, var(--surface-2) 30%, var(--surface-3) 50%, var(--surface-2) 70%);
  background-size: 200% 100%;
  animation: shimmer 1.6s ease-in-out infinite;
  border-radius: 12px;
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
  font-size: 13px;
  flex-direction: column; gap: 10px;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* =========================================================
   IMAGE SETTINGS
   ========================================================= */
.size-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.size-opt {
  display: inline-flex;
  cursor: pointer;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 500;
}
.size-opt input { display: none; }
.size-opt span {
  padding: 6px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.size-opt input:checked + span {
  background: rgba(124, 140, 255, 0.15);
  border-color: rgba(124, 140, 255, 0.5);
  color: var(--text);
}

.field code {
  background: var(--surface-3);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 5px;
  font-family: var(--font-mono);
  font-size: 11.5px;
}

/* Image lightbox */
.lightbox {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
  display: none;
  align-items: center; justify-content: center;
  z-index: 300;
  padding: 20px;
  cursor: zoom-out;
}
.lightbox.show { display: flex; animation: fade 0.2s ease both; }
.lightbox img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
}


/* =========================================================
   RUN PROJECT BAR (inside AI bubble with multi web blocks)
   ========================================================= */
.run-project {
  margin-top: 10px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--brand);
  color: white;
  border-radius: 10px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: filter 0.15s, transform 0.08s;
  user-select: none;
}
.run-project:hover { filter: brightness(1.15); }
.run-project:active { transform: translateY(1px); }

/* =========================================================
   HTML PREVIEW MODAL
   ========================================================= */
.preview-modal {
  position: fixed; inset: 0;
  display: none;
  z-index: 250;
}
.preview-modal.show { display: block; animation: fade 0.15s ease both; }
.preview-backdrop {
  position: absolute; inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
}
.preview-card {
  position: absolute;
  inset: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column;
  overflow: hidden;
  animation: pop 0.2s ease both;
}
.preview-head {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-wrap: wrap;
}
.preview-title {
  display: inline-flex; align-items: center; gap: 8px;
  font-weight: 600;
  font-size: 14px;
}
.preview-title svg { color: var(--brand); }
.preview-tabs {
  display: inline-flex;
  gap: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  margin-left: 8px;
}
.ptab {
  background: transparent;
  border: 0;
  color: var(--text-muted);
  padding: 6px 14px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.ptab:hover { color: var(--text); }
.ptab.active {
  background: var(--brand);
  color: white;
}
.preview-actions {
  display: inline-flex; gap: 4px;
  margin-left: auto;
}
.preview-body {
  flex: 1; min-height: 0;
  position: relative;
  background: #fff;
}
[data-theme="dark"] .preview-body { background: #1a1d26; }
.preview-body iframe {
  width: 100%; height: 100%;
  border: 0;
  background: #fff;
  display: block;
}
.preview-editor {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  resize: none;
  border: 0; outline: 0;
  background: #0d1117;
  color: #e6edf3;
  padding: 16px 20px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  tab-size: 2;
}
[data-theme="light"] .preview-editor {
  background: #fafafa;
  color: #24292e;
}

@media (max-width: 860px) {
  .preview-card { inset: 10px; }
  .preview-head { padding: 8px 10px; }
  .preview-tabs { margin-left: 0; order: 3; width: 100%; justify-content: space-between; }
  .preview-title { font-size: 13px; }
}


/* =========================================================
   COMPOSER TOOL BUTTONS (web search toggle)
   ========================================================= */
.tool-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 36px; height: 36px;
  border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  position: relative;
}
.tool-btn:hover { color: var(--text); background: var(--surface-2); border-color: var(--border-strong); }
.tool-btn.active {
  background: linear-gradient(135deg, rgba(34, 211, 238, 0.18), rgba(52, 211, 153, 0.18));
  color: var(--accent);
  border-color: rgba(34, 211, 238, 0.4);
}
.tool-btn.active::after {
  content: "";
  position: absolute;
  top: 4px; right: 4px;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
}

/* =========================================================
   SOURCES (citations)
   ========================================================= */
.sources {
  margin-top: 8px;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.sources-head {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 8px;
  display: flex; align-items: center; gap: 6px;
}
.sources-head svg { color: var(--accent); }
.sources-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 6px;
}
.source-pill {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  text-decoration: none;
  color: inherit;
  font-size: 12px;
  transition: border-color 0.15s, transform 0.08s;
  min-width: 0;
}
.source-pill:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
  color: inherit;
}
.source-n {
  flex-shrink: 0;
  width: 22px; height: 22px;
  border-radius: 6px;
  background: rgba(110, 110, 255, 0.12);
  color: var(--brand);
  display: inline-flex;
  align-items: center; justify-content: center;
  font-size: 11px;
  font-weight: 700;
  font-family: var(--font-mono);
}
.source-n.news { background: rgba(251, 191, 36, 0.12); color: var(--warn); }
.source-n.reddit { background: rgba(255, 69, 0, 0.12); color: #ff4500; }
.source-n.hackernews { background: rgba(255, 102, 0, 0.12); color: #ff6600; }
.source-n.twitter { background: rgba(29, 155, 240, 0.12); color: #1d9bf0; }
.source-body { min-width: 0; flex: 1; }
.source-title {
  font-weight: 500;
  font-size: 12.5px;
  color: var(--text);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  line-height: 1.3;
}
.source-domain {
  color: var(--text-dim);
  font-size: 11px;
  margin-top: 2px;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}

/* Inline citation [1][2] in AI text */
.bubble .cite {
  display: inline-flex;
  vertical-align: baseline;
  min-width: 18px;
  height: 16px;
  padding: 0 4px;
  margin: 0 1px;
  border-radius: 4px;
  background: rgba(34, 211, 238, 0.14);
  color: var(--accent);
  font-size: 10px;
  font-weight: 700;
  align-items: center; justify-content: center;
  font-family: var(--font-mono);
  text-decoration: none;
  border: 1px solid rgba(34, 211, 238, 0.28);
}
.bubble .cite:hover { background: rgba(34, 211, 238, 0.28); color: var(--accent); }

/* Search progress pill that appears above bubble while searching */
.search-progress {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 12px;
  margin-bottom: 4px;
}
.search-progress .spinner {
  width: 12px; height: 12px;
  border: 2px solid var(--surface-3);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* =========================================================
   THINKING BLOCK (collapsible reasoning)
   ========================================================= */
.think-block {
  margin: 4px 0 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  font-size: 13px;
}
.think-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  color: var(--text-muted);
  font-weight: 500;
  user-select: none;
  transition: background 0.15s;
}
.think-head:hover { background: var(--surface-3); }
.think-head .chev {
  transition: transform 0.2s;
}
.think-block[open] .think-head .chev { transform: rotate(90deg); }
.think-head .brain { color: var(--brand-2); }
.think-head .label {
  flex: 1;
  font-size: 12px;
  letter-spacing: 0.3px;
}
.think-head .duration {
  font-size: 11px;
  color: var(--text-dim);
  font-family: var(--font-mono);
}
.think-body {
  padding: 4px 14px 12px;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.6;
  border-top: 1px solid var(--border);
  max-height: 360px;
  overflow-y: auto;
  white-space: pre-wrap;
  font-family: var(--font-mono);
  font-size: 12px;
}
.think-block:not([open]) .think-body { display: none; }


/* =========================================================
   ATTACHMENTS (composer)
   ========================================================= */

.attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px 0 2px;
  border-bottom: 1px dashed var(--border);
  margin-bottom: 6px;
}
.attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px 6px 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 12px;
  max-width: 240px;
  overflow: hidden;
  position: relative;
}
.attach-chip.loading { opacity: 0.7; }
.attach-chip .thumb {
  width: 28px; height: 28px;
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--surface-3);
  display: flex; align-items: center; justify-content: center;
  color: var(--brand);
}
.attach-chip .thumb img { width: 100%; height: 100%; object-fit: cover; border-radius: 6px; }
.attach-chip .info { min-width: 0; flex: 1; display: flex; flex-direction: column; }
.attach-chip .name {
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  font-weight: 500;
  color: var(--text);
  font-size: 12.5px;
}
.attach-chip .sub { font-size: 10.5px; color: var(--text-dim); font-family: var(--font-mono); }
.attach-chip .remove {
  background: transparent; border: 0;
  color: var(--text-muted);
  cursor: pointer;
  padding: 3px;
  border-radius: 5px;
}
.attach-chip .remove:hover { color: var(--danger); background: rgba(248, 113, 113, 0.12); }
.attach-chip.error {
  border-color: rgba(248, 113, 113, 0.4);
  background: rgba(248, 113, 113, 0.08);
}
.attach-chip .spinner {
  width: 14px; height: 14px;
  border: 2px solid var(--surface-3);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* Drop zone overlay */
.drop-overlay {
  position: fixed; inset: 0;
  background: rgba(124, 140, 255, 0.08);
  border: 3px dashed var(--brand);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 400;
  display: flex; align-items: center; justify-content: center;
}
.drop-overlay.show { opacity: 1; }
.drop-overlay .msg {
  background: var(--surface);
  border: 1px solid var(--brand);
  padding: 20px 28px;
  border-radius: 14px;
  color: var(--text);
  font-weight: 600;
  box-shadow: var(--shadow-lg);
}

/* Attachments shown inside sent message bubble */
.msg-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}
.msg-attachments .att {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 10px 6px 6px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  max-width: 220px;
}
.msg-attachments .att .ic {
  width: 22px; height: 22px;
  border-radius: 5px;
  background: rgba(124, 140, 255, 0.15);
  color: var(--brand);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.msg-attachments .att .nm {
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  max-width: 160px;
}
.msg-attachments .img-att {
  width: 120px; height: 120px;
  border-radius: 10px;
  object-fit: cover;
  cursor: zoom-in;
  border: 1px solid var(--border);
}


/* =========================================================
   MEMORY PANEL
   ========================================================= */
.mem-add-row {
  display: flex; gap: 8px;
}
.mem-add-row input { flex: 1; }

.mem-list {
  display: flex; flex-direction: column; gap: 4px;
  max-height: 320px;
  overflow-y: auto;
  padding: 2px;
}
.mem-list-empty {
  text-align: center;
  color: var(--text-dim);
  padding: 24px;
  font-size: 13px;
}
.mem-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 13.5px;
  line-height: 1.4;
  transition: border-color 0.15s;
}
.mem-item:hover { border-color: var(--border-strong); }
.mem-item .mem-icon {
  flex-shrink: 0;
  width: 24px; height: 24px;
  border-radius: 6px;
  background: rgba(124, 140, 255, 0.12);
  color: var(--brand);
  display: flex; align-items: center; justify-content: center;
}
.mem-item .mem-text { flex: 1; color: var(--text); min-width: 0; }
.mem-item .mem-meta {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 3px;
}
.mem-item .mem-del {
  background: transparent; border: 0;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  flex-shrink: 0;
}
.mem-item .mem-del:hover { color: var(--danger); background: rgba(248, 113, 113, 0.12); }


/* =========================================================
   MERMAID DIAGRAMS
   ========================================================= */
.mermaid-wrapper {
  margin: 10px 0;
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  background: linear-gradient(180deg, color-mix(in srgb, var(--surface-2) 88%, rgba(110, 110, 255, 0.08)), var(--surface));
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.03);
  contain: layout paint;
}
.mermaid-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
}
.mermaid-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.mermaid-label svg { color: var(--success); }
.mermaid-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.mermaid-zoom {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-right: 2px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: color-mix(in srgb, var(--surface-2) 88%, transparent);
}
.mermaid-zoom-value {
  min-width: 48px;
  text-align: center;
  padding: 0 4px;
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}
.mermaid-actions .copy-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.mermaid-diagram {
  padding: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  min-height: 80px;
  max-height: min(54vh, 520px);
  background:
    radial-gradient(circle at top, rgba(110, 110, 255, 0.06), transparent 42%),
    var(--surface);
  overscroll-behavior: contain;
}
.mermaid-diagram.is-zoomed {
  align-items: flex-start;
  justify-content: flex-start;
}
.mermaid-diagram.is-draggable {
  cursor: grab;
  user-select: none;
  touch-action: none;
}
.mermaid-diagram.is-dragging {
  cursor: grabbing;
}
.mermaid-diagram svg,
.mermaid-diagram .mermaid-svg {
  flex: 0 0 auto;
  max-width: 100%;
  height: auto;
  display: block;
  margin: 0 auto;
  filter: drop-shadow(0 8px 24px rgba(0, 0, 0, 0.16));
}
.mermaid-fullscreen-modal {
  position: fixed;
  inset: 0;
  display: none;
  z-index: 320;
}
.mermaid-fullscreen-modal.show {
  display: block;
  animation: fade 0.18s ease both;
}
.mermaid-fullscreen-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(6px);
}
.mermaid-fullscreen-card {
  position: absolute;
  inset: 24px;
  display: flex;
  flex-direction: column;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
}
.mermaid-fullscreen-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.mermaid-fullscreen-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.mermaid-fullscreen-body {
  flex: 1;
  min-height: 0;
  background:
    radial-gradient(circle at top, rgba(110, 110, 255, 0.08), transparent 38%),
    var(--surface);
}
.mermaid-fullscreen-diagram {
  width: 100%;
  height: 100%;
  min-height: 100%;
  padding: 28px;
  max-height: none;
  cursor: grab;
}
.mermaid-fullscreen-diagram.is-dragging { cursor: grabbing; }
.mermaid-pending {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 120px;
  width: 100%;
  padding: 16px 18px;
  color: var(--text-muted);
  font-size: 13px;
}
.mermaid-source {
  margin: 0;
  border-top: 1px solid var(--border);
  border-radius: 0;
  background: #0d1117;
}
.mermaid-source code {
  display: block;
  padding: 12px 14px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: #e6edf3;
  white-space: pre-wrap;
}
.mermaid-error {
  display: grid;
  gap: 4px;
  align-content: center;
  justify-items: center;
  min-height: 160px;
  padding: 18px 16px;
  text-align: center;
  color: var(--text-muted);
}
.mermaid-error-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}
.mermaid-error-sub {
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-dim);
}
.mermaid-error-sub strong {
  color: var(--text-muted);
}
[data-theme="light"] .mermaid-diagram { background: #fff; }


/* =========================================================
   TOUCH & MOBILE ENHANCEMENTS
   ========================================================= */
/* Prevent text selection on buttons */
button, .mode-btn, .suggest, .history-item { -webkit-tap-highlight-color: transparent; }

/* Smooth scrolling on iOS */
.chat, .history, .modal-body, .model-list, .mem-list {
  -webkit-overflow-scrolling: touch;
}

/* Fix iOS input zoom (font-size must be >= 16px) */
@media (max-width: 520px) {
  #input, .field input, .field textarea, .field select,
  .search-box input, .edit-area, #mem-input, #pull-name {
    font-size: 16px;
  }
}

/* Landscape phone */
@media (max-height: 500px) and (orientation: landscape) {
  .topbar { min-height: 40px; padding: 6px 12px; }
  .chat { padding: 10px 16px 6px; gap: 10px; }
  .composer { padding: 8px 12px 10px; }
  .welcome { padding: 10px; }
  .welcome-badge { display: none; }
  .welcome h2 { font-size: 18px; margin-bottom: 4px; }
  .welcome p { margin-bottom: 12px; }
  .suggestions { gap: 6px; }
}

/* Tablet landscape (1024-1200px) */
@media (min-width: 861px) and (max-width: 1200px) {
  :root { --sidebar-w: 240px; --maxw: 680px; }
  .sidebar { padding: 12px; }
  .new-chat-btn { padding: 9px 12px; font-size: 13px; }
  .new-chat-btn .kbd { display: none; }
  .history-item { padding: 8px 10px; font-size: 13px; }
}

/* Large screens (1600px+) */
@media (min-width: 1600px) {
  :root { --maxw: 860px; --sidebar-w: 300px; }
  .chat { padding: 36px 32px 16px; }
  .bubble { padding: 18px 22px; }
}

/* =========================================================
   LaTeX & KaTeX Math Styling
   ========================================================= */
.math-block {
  margin: 1rem 0;
  padding: 0.5rem;
  overflow-x: auto;
  overflow-y: hidden;
  max-width: 100%;
  text-align: center;
}
.math-block::-webkit-scrollbar {
  height: 4px;
}
.math-block::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}
.math-inline {
  padding: 0 2px;
  white-space: nowrap;
}
.math-block-error, .math-inline-error {
  color: var(--danger);
  font-family: var(--font-mono);
  font-size: 0.9em;
}

/* =========================================================
   Reply Preview Styling
   ========================================================= */
.reply-preview {
  grid-area: reply-preview;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  margin-bottom: 6px;
  width: 100%;
}
.reply-preview-content {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}
.reply-preview-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--brand-2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.reply-preview-text {
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  margin-top: 1px;
}
.reply-close-btn {
  background: transparent;
  border: 0;
  color: var(--text-dim);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, background 0.15s;
}
.reply-close-btn:hover {
  color: var(--text);
  background: var(--surface-2);
}

/* =========================================================
   Lovable.dev Design Overrides & Extensions
   ========================================================= */

/* Main layout changes */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
  overflow: hidden;
}

/* Mesh gradient background on main chat area */
.main {
  background-color: #060608 !important;
  background-image: 
    radial-gradient(circle at 15% 15%, rgba(59, 130, 246, 0.22) 0%, transparent 45%),
    radial-gradient(circle at 85% 75%, rgba(236, 72, 153, 0.24) 0%, transparent 50%),
    radial-gradient(circle at 50% 90%, rgba(139, 92, 246, 0.20) 0%, transparent 45%),
    radial-gradient(circle at 80% 10%, rgba(30, 27, 75, 0.4) 0%, transparent 40%) !important;
  background-size: 100% 100% !important;
  background-attachment: fixed !important;
}

/* Glassmorphism for bubbles and headers */
.bubble {
  backdrop-filter: blur(12px) !important;
  -webkit-backdrop-filter: blur(12px) !important;
  background: rgba(22, 22, 26, 0.65) !important;
  border: 1px solid rgba(255, 255, 255, 0.08) !important;
  border-radius: 20px !important;
}
.msg.user .bubble {
  background: rgba(110, 110, 255, 0.12) !important;
  border-color: rgba(110, 110, 255, 0.25) !important;
}

/* Sidebar layout overrides */
.sidebar {
  background: #09090b !important;
  border-right: 1px solid rgba(255, 255, 255, 0.06) !important;
  padding: 16px !important;
  gap: 16px !important;
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), width 0.25s cubic-bezier(0.16, 1, 0.3, 1), padding 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.sidebar-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}
.sidebar-logo-icon {
  display: flex;
  align-items: center;
  justify-content: center;
}
.sidebar-toggle-btn {
  background: transparent;
  border: 0;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, background-color 0.15s;
}
.sidebar-toggle-btn:hover {
  color: #fff;
  background-color: rgba(255, 255, 255, 0.05);
}

.workspace-selector {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
  border: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(255, 255, 255, 0.02);
  transition: background 0.15s, border-color 0.15s;
}
.workspace-selector:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.1);
}
.workspace-avatar {
  width: 20px;
  height: 20px;
  background: #3b82f6;
  color: #fff;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}
.workspace-name-wrap {
  flex: 1;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.workspace-title {
  font-size: 13px;
  font-weight: 600;
  color: #ececef;
}
.workspace-selector .chevron-down {
  color: var(--text-muted);
}

.sidebar-nav, .sidebar-projects-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: transparent;
  border: 0;
  color: #a1a1aa;
  font-size: 13.5px;
  font-weight: 500;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
  transition: color 0.15s, background-color 0.15s;
  width: 100%;
}
.nav-item:hover {
  color: #fff;
  background-color: rgba(255, 255, 255, 0.04);
}
.nav-item.active {
  color: #fff;
  background-color: rgba(255, 255, 255, 0.08);
}
.nav-item svg {
  flex-shrink: 0;
  opacity: 0.85;
}

/* Custom Search Box styled as a nav item */
.sidebar .search-box {
  display: flex;
  align-items: center;
  gap: 12px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 10px;
  color: #a1a1aa;
  transition: border-color 0.2s, background-color 0.2s;
  cursor: text;
}
.sidebar .search-box:hover {
  background-color: rgba(255, 255, 255, 0.03);
}
.sidebar .search-box:focus-within {
  background-color: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.08);
  box-shadow: none;
}
.sidebar .search-box input {
  flex: 1;
  background: transparent;
  border: 0;
  outline: 0;
  font-size: 13.5px;
  color: #fff;
  min-width: 0;
  padding: 0;
}
.sidebar .search-box .kbd {
  font-size: 9px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.08);
  color: #52525b;
  border-radius: 4px;
  padding: 1px 4px;
}

.sidebar-section {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 8px;
  min-height: 0;
}
.sidebar-section.flex-grow {
  flex: 1;
  overflow: hidden;
}
.sidebar-label {
  font-size: 11px;
  font-weight: 600;
  color: #52525b;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
  text-transform: uppercase;
  padding-left: 10px;
}

.history {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
  min-height: 0;
}

/* History items styling */
.history-item {
  border-radius: 8px !important;
  padding: 8px 10px !important;
  font-size: 13px !important;
  border: 1px solid transparent !important;
}
.history-item:hover {
  background: rgba(255,255,255,0.03) !important;
}
.history-item.active {
  background: rgba(255,255,255,0.06) !important;
  border-color: rgba(255,255,255,0.04) !important;
}

/* Utility row */
.sidebar-utility-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 8px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  margin-top: auto;
}
.utility-actions {
  display: flex;
  gap: 4px;
}
.sidebar-utility-row .status-row {
  font-size: 11.5px;
}

/* Token Usage Bar */
.token-usage-container {
  padding: 8px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.token-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
}
.token-progress-bar {
  width: 100%;
  height: 6px;
  background-color: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  overflow: hidden;
}
[data-theme="light"] .token-progress-bar {
  background-color: rgba(0, 0, 0, 0.1);
}
.token-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #8b8bff, #6e6eff);
  border-radius: 4px;
  transition: width 0.3s ease, background 0.3s ease;
}

/* Promo cards styling */
.sidebar-promo-cards {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.promo-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s;
}
.promo-card:hover {
  background-color: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.08);
}
.promo-content {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}
.promo-title {
  font-size: 12px;
  font-weight: 600;
  color: #fff;
}
.promo-desc {
  font-size: 10px;
  color: #52525b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.promo-icon {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.03);
  color: #71717a;
  flex-shrink: 0;
}
#promo-upgrade .promo-icon {
  background: rgba(168, 85, 247, 0.1);
  color: #c084fc;
}

/* User footer dock */
.sidebar-user-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  cursor: pointer;
  background:
    linear-gradient(135deg, rgba(110, 110, 255, 0.15) 0%, transparent 80%),
    linear-gradient(225deg, rgba(236, 72, 153, 0.1) 0%, transparent 80%),
    var(--surface-2);
  border: 1px solid rgba(110, 110, 255, 0.2);
  border-radius: 12px;
  transition: transform 0.1s, box-shadow 0.15s, border-color 0.15s;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  margin-top: 4px;
}
.sidebar-user-footer:hover {
  border-color: rgba(110, 110, 255, 0.4);
  box-shadow: 0 4px 16px rgba(110, 110, 255, 0.15);
  transform: translateY(-1px);
}
.sidebar-user-footer:active {
  transform: translateY(1px);
}
[data-theme="light"] .sidebar-user-footer {
  background:
    linear-gradient(135deg, rgba(110, 110, 255, 0.08) 0%, transparent 80%),
    linear-gradient(225deg, rgba(236, 72, 153, 0.06) 0%, transparent 80%),
    var(--surface-2);
  border-color: rgba(110, 110, 255, 0.15);
  box-shadow: 0 2px 8px rgba(110, 110, 255, 0.05);
}
[data-theme="light"] .sidebar-user-footer:hover {
  border-color: rgba(110, 110, 255, 0.3);
  box-shadow: 0 4px 12px rgba(110, 110, 255, 0.1);
}
.user-avatar-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}
.user-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #ec4899;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11.5px;
  font-weight: 700;
  flex-shrink: 0;
}
.user-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}
.user-info strong {
  font-size: 12.5px;
  color: var(--text);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-info span {
  font-size: 10px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-notifications {
  position: relative;
  color: var(--text-muted);
  padding: 6px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, background-color 0.15s;
}
.sidebar-user-footer:hover .user-notifications {
  color: var(--text);
  background-color: var(--surface-3);
}
.notification-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #ef4444;
}

/* Collapsing desktop sidebar styling */
.sidebar-collapsed {
  grid-template-columns: 0 1fr;
}
.sidebar-collapsed .sidebar {
  transform: translateX(-100%);
  pointer-events: none;
  border-right: 0;
}
.sidebar-collapsed #sidebar-open.mobile-only {
  display: inline-flex !important;
}

.main.chat-empty .chat {
  flex: 1 !important;
}
.main.chat-empty .composer {
  padding-top: 0;
  margin-bottom: 40px;
}

/* Welcome template overrides */
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  max-width: 680px;
  margin: auto;
  padding: 60px 20px 20px;
}
.welcome-top-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(9, 9, 11, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 11.5px;
  font-weight: 500;
  color: #ececef;
  margin-bottom: 24px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}
.welcome-top-badge:hover {
  background: rgba(25, 25, 35, 0.85);
  border-color: rgba(255, 255, 255, 0.15);
}
.welcome-top-badge span.fire-icon {
  font-size: 12px;
}
.welcome-top-badge span.link-icon {
  font-size: 11px;
}
.welcome-top-badge .arrow {
  transition: transform 0.2s;
  color: #71717a;
  margin-left: 2px;
}
.welcome-top-badge:hover .arrow {
  transform: translateX(2px);
  color: #fff;
}
.welcome h2 {
  font-size: 38px;
  font-weight: 700;
  color: #fff;
  margin: 0 0 28px;
  letter-spacing: -0.8px;
}
.welcome-templates-section {
  width: 100%;
  margin-top: 36px;
  animation: fade-up 0.4s ease 0.1s both;
}
.welcome-templates-section .section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  font-size: 12.5px;
  font-weight: 600;
  color: #52525b;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 0 4px;
}
.browse-all-link {
  color: #71717a;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 500;
  text-transform: none;
  cursor: pointer;
  transition: color 0.15s;
}
.browse-all-link:hover {
  color: #fff;
}

/* Floating Glass Composer overrides */
.composer {
  padding: 16px 28px 24px;
}
#form {
  background: rgba(16, 16, 20, 0.65);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 20px;
  padding: 14px 16px 12px 16px;
  box-shadow: 0 20px 40px rgba(0,0,0,0.3);
  display: flex;
  flex-direction: column;
  gap: 8px;
  grid-template-columns: none;
  grid-template-areas: none;
}
#form:focus-within {
  border-color: rgba(255, 255, 255, 0.16);
  box-shadow: 0 20px 40px rgba(0,0,0,0.4), 0 0 0 3px rgba(255,255,255,0.02);
}
#input {
  width: 100%;
  max-height: 220px;
  font-size: 14.5px;
  line-height: 1.5;
  padding: 6px 4px;
  background: transparent;
  color: #fff;
  border: 0;
  outline: 0;
  resize: none;
  flex: none;
}
.composer-controls-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 4px;
  border-top: none;
  padding-top: 6px;
}
.composer-controls-left {
  display: flex;
  align-items: center;
  gap: 6px;
}
.composer-controls-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Tool buttons inside composer */
#form .tool-btn {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
  color: #a1a1aa;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s, border-color 0.15s;
}
#form .tool-btn:hover {
  background-color: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.12);
  color: #fff;
}
#form .tool-btn.active {
  background-color: rgba(110, 110, 255, 0.15);
  border-color: rgba(110, 110, 255, 0.3);
  color: #8b8bff;
}

/* Send button styling */
.send-btn {
  background: #ffffff !important;
  color: #09090b !important;
  border: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.15s, transform 0.08s, opacity 0.15s;
  box-shadow: 0 4px 12px rgba(255, 255, 255, 0.15);
  padding: 0;
}
.send-btn:hover {
  background-color: #e4e4e7 !important;
  transform: scale(1.02);
}
.send-btn:active {
  transform: scale(0.95);
}
.send-btn:disabled {
  opacity: 0.35 !important;
  background-color: rgba(255, 255, 255, 0.08) !important;
  color: #52525b !important;
  cursor: not-allowed;
  box-shadow: none;
}
.stop-btn {
  background: rgba(239, 68, 68, 0.1) !important;
  border: 1px solid rgba(239, 68, 68, 0.2) !important;
  color: #ef4444 !important;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.15s;
}
.stop-btn:hover {
  background-color: rgba(239, 68, 68, 0.2) !important;
}

/* Model Picker inside composer box overrides */
#form .model-picker-custom {
  position: relative;
}
#form .model-picker-trigger {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 500;
  height: 32px;
  min-width: 110px;
  max-width: 180px;
  color: #ececef;
}
#form .model-picker-trigger:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.1);
}
#form .model-picker-menu {
  bottom: calc(100% + 8px);
  top: auto;
  right: 0;
  left: auto;
}

/* Mobile responsive fixes */
@media (max-width: 768px) {
  .app {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 50;
    transform: translateX(-100%);
    width: var(--sidebar-w);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .composer {
    padding: 12px 16px 20px;
  }
  #form {
    padding: 10px 12px;
  }
  .welcome h2 {
    font-size: 28px;
    margin-bottom: 20px;
  }
  .welcome-templates-section {
    margin-top: 24px;
  }
}

/* Extra premium content styling */
.topbar .icon-btn {
  border: 1px solid rgba(255, 255, 255, 0.04) !important;
  background: rgba(255, 255, 255, 0.01) !important;
  color: #a1a1aa !important;
}
.topbar .icon-btn:hover {
  background: rgba(255, 255, 255, 0.06) !important;
  color: #fff !important;
  border-color: rgba(255, 255, 255, 0.1) !important;
}
.foot-row {
  opacity: 0.45;
  transition: opacity 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}
.foot-row:hover {
  opacity: 0.85;
}
