/* ─── Reset & Variables ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:           #f7f8fa;
  --card-bg:      #ffffff;
  --sidebar-bg:   #ffffff;
  --border:       #e5e7eb;
  --text-main:    #1f2937;
  --text-muted:   #6b7280;
  --text-subtle:  #9ca3af;
  --accent:       #111827;
  --accent-fg:    #ffffff;
  --accent-soft:  #f3f4f6;
  --green:        #10b981;
  --green-hover:  #059669;
  --input-bg:     #ffffff;
  --hover-bg:     #f3f4f6;
  --active-bg:    #f0fdf4;
  --active-text:  #065f46;
  --code-bg:      #f3f4f6;
  --shadow-xs:    0 1px 2px rgba(0,0,0,.05);
  --shadow-sm:    0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md:    0 4px 12px rgba(0,0,0,.08), 0 2px 4px rgba(0,0,0,.04);
  --shadow-lg:    0 10px 25px rgba(0,0,0,.1), 0 4px 10px rgba(0,0,0,.06);
  --shadow-xl:    0 20px 40px rgba(0,0,0,.12);
  --radius-sm:    6px;
  --radius-md:    10px;
  --radius-lg:    16px;
  --radius-xl:    20px;
  --sidebar-w:    252px;
  --right-w:      268px;
  --topbar-h:     56px;
  --font:         -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono:         ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  --ease:         cubic-bezier(.4,0,.2,1);
  --t:            160ms;
}

[data-theme="dark"] {
  --bg:           #0d0f14;
  --card-bg:      #161a24;
  --sidebar-bg:   #111420;
  --border:       #1e2438;
  --text-main:    #f1f5f9;
  --text-muted:   #94a3b8;
  --text-subtle:  #64748b;
  --accent:       #f1f5f9;
  --accent-fg:    #0d0f14;
  --accent-soft:  #1e2438;
  --input-bg:     #161a24;
  --hover-bg:     #1a1f2e;
  --active-bg:    #0a2318;
  --active-text:  #34d399;
  --code-bg:      #1a1f2e;
  --shadow-xs:    0 1px 2px rgba(0,0,0,.4);
  --shadow-sm:    0 1px 3px rgba(0,0,0,.5);
  --shadow-md:    0 4px 12px rgba(0,0,0,.5);
  --shadow-lg:    0 10px 25px rgba(0,0,0,.6);
  --shadow-xl:    0 20px 40px rgba(0,0,0,.7);
}

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-main);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}
button { cursor: pointer; border: none; background: none; font-family: inherit; color: inherit; }
input, textarea, select { font-family: inherit; color: inherit; }

/* ─── SPLASH ─────────────────────────────────────────────────────────────────── */
.splash {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.splash-bg {
  position: absolute;
  inset: 0;
  background: #0a0c12;
}
.splash-bg::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 60% 50% at 30% 40%, rgba(16,185,129,.18) 0%, transparent 60%),
    radial-gradient(ellipse 50% 60% at 70% 60%, rgba(99,102,241,.12) 0%, transparent 60%);
}

.splash-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 32px;
}

.splash-logo-wrap {
  position: relative;
  width: 120px;
  height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: splashLogoIn .8s var(--ease) .1s both;
}

@keyframes splashLogoIn {
  from { opacity: 0; transform: scale(.6) rotateY(-20deg); }
  to   { opacity: 1; transform: scale(1) rotateY(0deg); }
}

.splash-logo-ring {
  position: absolute;
  inset: -16px;
  border-radius: 50%;
  border: 1.5px solid rgba(16,185,129,.35);
  animation: ringPulse 2.5s ease-in-out infinite;
}
.ring2 {
  inset: -32px;
  border-color: rgba(16,185,129,.15);
  animation-delay: .5s;
}
@keyframes ringPulse {
  0%, 100% { opacity: .6; transform: scale(1); }
  50%       { opacity: 1; transform: scale(1.04); }
}

.splash-logo {
  width: 100px;
  height: 100px;
  border-radius: 24px;
  object-fit: contain;
  filter: invert(1) brightness(1.1);
  box-shadow: 0 0 40px rgba(16,185,129,.3), 0 8px 32px rgba(0,0,0,.6);
  border: 1px solid rgba(255,255,255,.1);
}

.splash-text {
  text-align: center;
  animation: splashTextIn .8s var(--ease) .5s both;
}
@keyframes splashTextIn {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

.splash-title {
  font-size: 15px;
  font-weight: 400;
  color: rgba(255,255,255,.5);
  letter-spacing: .1em;
  text-transform: uppercase;
  margin-bottom: 8px;
}
.splash-brand {
  font-size: 36px;
  font-weight: 700;
  color: #ffffff;
  letter-spacing: -.02em;
  line-height: 1.1;
  background: linear-gradient(135deg, #fff 0%, rgba(16,185,129,.9) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.splash-sub {
  font-size: 14px;
  color: rgba(255,255,255,.35);
  margin-top: 10px;
  letter-spacing: .02em;
}

.splash-loader {
  width: 200px;
  height: 2px;
  background: rgba(255,255,255,.08);
  border-radius: 99px;
  overflow: hidden;
  animation: splashTextIn .5s var(--ease) 1s both;
}
.splash-bar {
  height: 100%;
  background: linear-gradient(90deg, #10b981, #34d399);
  border-radius: 99px;
  animation: splashProgress 3.2s var(--ease) 0.6s forwards;
  width: 0;
}
@keyframes splashProgress {
  0%   { width: 0%; }
  40%  { width: 60%; }
  100% { width: 100%; }
}

.splash.fade-out {
  animation: splashFade .5s var(--ease) forwards;
  pointer-events: none;
}
@keyframes splashFade {
  to { opacity: 0; transform: scale(1.03); }
}

/* ─── AUTH SCREEN ────────────────────────────────────────────────────────────── */
.auth-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: var(--bg);
}

.auth-bg {
  position: absolute;
  inset: 0;
  overflow: hidden;
}
.auth-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: .4;
}
.orb1 {
  width: 500px; height: 500px;
  background: radial-gradient(circle, rgba(16,185,129,.25) 0%, transparent 70%);
  top: -150px; left: -100px;
}
.orb2 {
  width: 400px; height: 400px;
  background: radial-gradient(circle, rgba(99,102,241,.2) 0%, transparent 70%);
  bottom: -100px; right: -80px;
}
.orb3 {
  width: 300px; height: 300px;
  background: radial-gradient(circle, rgba(16,185,129,.15) 0%, transparent 70%);
  top: 50%; right: 10%;
}
[data-theme="dark"] .auth-orb { opacity: .5; }

.auth-card {
  position: relative;
  z-index: 1;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 36px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-xl);
  animation: cardIn .4s var(--ease) both;
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(20px) scale(.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.auth-logo-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}
.auth-logo {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  object-fit: contain;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
[data-theme="dark"] .auth-logo { filter: invert(1); }
.auth-brand-text {
  display: flex;
  flex-direction: column;
}
.auth-brand-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -.01em;
}
.auth-brand-tag {
  font-size: 12px;
  color: var(--text-subtle);
}

.auth-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -.02em;
  margin-bottom: 4px;
}
.auth-sub {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 28px;
}

.auth-form { display: flex; flex-direction: column; gap: 16px; }

.auth-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.auth-field label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
}
.auth-input-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  background: var(--input-bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  transition: border-color var(--t), box-shadow var(--t);
  color: var(--text-subtle);
}
.auth-input-wrap:focus-within {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(16,185,129,.12);
  color: var(--text-muted);
}
.auth-input-wrap input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  font-size: 14.5px;
  color: var(--text-main);
}
.auth-input-wrap input::placeholder { color: var(--text-subtle); }

.auth-error {
  font-size: 13px;
  color: #ef4444;
  min-height: 18px;
  padding: 0 2px;
}

.auth-btn {
  width: 100%;
  padding: 12px;
  background: var(--text-main);
  color: var(--card-bg);
  border-radius: var(--radius-md);
  font-size: 14.5px;
  font-weight: 600;
  letter-spacing: -.01em;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: opacity var(--t), transform var(--t);
  margin-top: 4px;
}
.auth-btn:hover:not(:disabled) { opacity: .88; transform: translateY(-1px); }
.auth-btn:disabled { opacity: .6; cursor: not-allowed; }

.btn-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.auth-switch {
  margin-top: 22px;
  text-align: center;
  font-size: 13.5px;
  color: var(--text-muted);
}
.auth-switch-btn {
  color: var(--green);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: inherit;
  font-family: inherit;
}
.auth-switch-btn:hover { color: var(--green-hover); }

/* ─── DASHBOARD LAYOUT ───────────────────────────────────────────────────────── */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr var(--right-w);
  height: 100vh;
  overflow: hidden;
}

/* ─── Sidebar ─────────────────────────────────────────────────────────────────── */
.sidebar {
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 14px 12px;
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 10px; }

.brand-logo-wrap {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  flex-shrink: 0;
  box-shadow: var(--shadow-xs);
}
.brand-logo-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
[data-theme="dark"] .brand-logo-img { filter: invert(1); }

.brand-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -.02em;
}

.icon-btn {
  width: 30px; height: 30px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
  transition: background var(--t), color var(--t);
}
.icon-btn:hover { background: var(--hover-bg); color: var(--text-main); }

.sidebar-search {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 12px;
  padding: 7px 11px;
  background: var(--hover-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-muted);
  transition: border-color var(--t), box-shadow var(--t);
}
.sidebar-search:focus-within {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(16,185,129,.1);
}
.sidebar-search input {
  flex: 1; background: none; border: none; outline: none;
  font-size: 13px; color: var(--text-main);
}
.sidebar-search input::placeholder { color: var(--text-subtle); }
.sidebar-search kbd {
  font-size: 10.5px; padding: 1px 5px;
  background: var(--card-bg); border: 1px solid var(--border);
  border-radius: 4px; color: var(--text-subtle); font-family: var(--font);
}

.sidebar-nav { flex: 1; overflow-y: auto; padding: 6px 8px; }
.sidebar-nav::-webkit-scrollbar { width: 0; }

.nav-section-label {
  font-size: 10.5px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-subtle); padding: 14px 8px 5px;
}

.nav-item {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 9px;
  border-radius: var(--radius-md);
  font-size: 13.5px; font-weight: 450;
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--t), color var(--t);
  user-select: none;
  position: relative;
}
.nav-item:hover { background: var(--hover-bg); color: var(--text-main); }
.nav-item.active { background: var(--active-bg); color: var(--active-text); font-weight: 500; }
.nav-item svg { flex-shrink: 0; opacity: .75; }
.nav-item.active svg { opacity: 1; }

.badge-new {
  margin-left: auto; font-size: 9.5px; font-weight: 700;
  letter-spacing: .04em; padding: 2px 6px;
  background: #dbeafe; color: #1d4ed8; border-radius: 20px;
}
[data-theme="dark"] .badge-new { background: #1e3a5f; color: #60a5fa; }

.sidebar-footer {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 10px;
}

.theme-toggle {
  display: flex;
  background: var(--hover-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 3px; gap: 2px;
}
.theme-btn {
  flex: 1; display: flex; align-items: center; justify-content: center;
  gap: 5px; padding: 5px 8px; border-radius: 7px;
  font-size: 12px; font-weight: 500; color: var(--text-muted);
  transition: background var(--t), color var(--t), box-shadow var(--t);
}
.theme-btn.active { background: var(--card-bg); color: var(--text-main); box-shadow: var(--shadow-xs); }

.user-row {
  display: flex; align-items: center; gap: 9px; padding: 5px 4px;
}
.user-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: linear-gradient(135deg, #111827, #374151);
  color: #fff; font-size: 12px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; text-transform: uppercase;
}
.user-info { flex: 1; min-width: 0; }
.user-name { font-size: 13px; font-weight: 600; color: var(--text-main); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-sub { font-size: 11px; color: var(--text-muted); }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); flex-shrink: 0; box-shadow: 0 0 0 2px var(--sidebar-bg); }

/* ─── Main ───────────────────────────────────────────────────────────────────── */
.main { display: flex; flex-direction: column; height: 100vh; overflow: hidden; background: var(--bg); }

.topbar {
  height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0; z-index: 10;
}
.topbar-left { display: flex; align-items: center; gap: 10px; }
.topbar-logo {
  width: 28px; height: 28px;
  border-radius: 7px; object-fit: contain;
  border: 1px solid var(--border);
}
[data-theme="dark"] .topbar-logo { filter: invert(1); }
.topbar-title { font-size: 15px; font-weight: 600; color: var(--text-main); }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

.btn-upgrade {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 14px;
  background: var(--text-main); color: var(--card-bg);
  border-radius: var(--radius-md);
  font-size: 13px; font-weight: 600;
  transition: opacity var(--t), transform var(--t);
}
.btn-upgrade:hover { opacity: .88; transform: translateY(-1px); }

/* Welcome */
.welcome-screen {
  flex: 1; display: flex; align-items: center; justify-content: center;
  padding: 40px 24px; overflow-y: auto;
}
.welcome-inner {
  max-width: 620px; width: 100%; text-align: center;
}
.welcome-logo {
  width: 72px; height: 72px;
  border-radius: 18px;
  object-fit: contain;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  margin-bottom: 20px;
  animation: welcomeLogoIn .5s var(--ease) both;
}
[data-theme="dark"] .welcome-logo { filter: invert(1); }
@keyframes welcomeLogoIn {
  from { opacity: 0; transform: scale(.8) translateY(-10px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
.welcome-heading {
  font-size: 30px; font-weight: 700; color: var(--text-main);
  letter-spacing: -.03em; line-height: 1.2; margin-bottom: 10px;
}
.welcome-sub { font-size: 14.5px; color: var(--text-muted); margin-bottom: 32px; line-height: 1.6; }

.quick-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; text-align: left; }

.quick-card {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  font-size: 13.5px; font-weight: 500;
  color: var(--text-main); cursor: pointer;
  transition: box-shadow var(--t), border-color var(--t), transform var(--t);
  box-shadow: var(--shadow-xs);
}
.quick-card:hover { box-shadow: var(--shadow-md); border-color: transparent; transform: translateY(-2px); }
.card-icon { width: 38px; height: 38px; border-radius: var(--radius-md); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.card-plus { margin-left: auto; width: 20px; height: 20px; border-radius: 50%; border: 1.5px solid var(--border); display: flex; align-items: center; justify-content: center; font-size: 14px; color: var(--text-subtle); flex-shrink: 0; }

/* Chat messages */
.chat-messages {
  flex: 1; overflow-y: auto; padding: 24px 20px;
  display: flex; flex-direction: column; gap: 20px;
  scroll-behavior: smooth;
}
.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }

.msg-row {
  display: flex; gap: 12px;
  animation: fadeUp .2s var(--ease) both;
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.msg-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; flex-shrink: 0; margin-top: 2px;
  text-transform: uppercase;
}
.msg-row.user .msg-avatar { background: var(--text-main); color: var(--card-bg); }
.msg-row.assistant .msg-avatar {
  background: none; border: 1px solid var(--border); padding: 2px; overflow: hidden;
}
.msg-row.assistant .msg-avatar img { width: 100%; height: 100%; object-fit: contain; }
[data-theme="dark"] .msg-row.assistant .msg-avatar img { filter: invert(1); }

.msg-content { flex: 1; min-width: 0; }
.msg-bubble {
  display: inline-block;
  background: var(--card-bg); border: 1px solid var(--border);
  border-radius: var(--radius-lg) var(--radius-lg) var(--radius-lg) 4px;
  padding: 10px 14px; font-size: 14px; color: var(--text-main);
  max-width: 78%; box-shadow: var(--shadow-xs);
  white-space: pre-wrap; word-break: break-word;
}

/* Kimi AI bubble */
.kimi-ai-bubble {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 22px;
  color: var(--text-main);
  box-shadow: var(--shadow-sm);
  font-size: 14.5px; line-height: 1.72; font-weight: 400;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
.kimi-ai-bubble h1, .kimi-ai-bubble h2, .kimi-ai-bubble h3, .kimi-ai-bubble h4 {
  color: var(--text-main); font-weight: 600;
  margin-top: 1.2rem; margin-bottom: .55rem; line-height: 1.3; letter-spacing: -.01em;
}
.kimi-ai-bubble h1 { font-size: 1.2rem; }
.kimi-ai-bubble h2 { font-size: 1.1rem; }
.kimi-ai-bubble h3 { font-size: 1rem; }
.kimi-ai-bubble p { margin-bottom: .85rem; }
.kimi-ai-bubble p:last-child { margin-bottom: 0; }
.kimi-ai-bubble ul, .kimi-ai-bubble ol { margin-bottom: .85rem; padding-left: 1.3rem; }
.kimi-ai-bubble li { margin-bottom: .3rem; }
.kimi-ai-bubble strong { font-weight: 600; color: var(--text-main); }
.kimi-ai-bubble em { font-style: italic; color: var(--text-muted); }
.kimi-ai-bubble a { color: var(--green); text-decoration: underline; text-underline-offset: 2px; }
.kimi-ai-bubble code {
  font-family: var(--mono); font-size: .8rem;
  background: var(--code-bg); padding: 2px 5px;
  border-radius: 4px; border: 1px solid rgba(0,0,0,.06);
}
[data-theme="dark"] .kimi-ai-bubble code { border-color: rgba(255,255,255,.06); }
.kimi-ai-bubble pre {
  background: var(--code-bg); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 14px 16px;
  overflow-x: auto; margin-bottom: 1rem; position: relative;
}
.kimi-ai-bubble pre code { background: none; border: none; padding: 0; font-size: .8rem; line-height: 1.6; white-space: pre; }
.kimi-ai-bubble blockquote { border-left: 3px solid var(--green); padding-left: .9rem; margin: .75rem 0; color: var(--text-muted); }
.kimi-ai-bubble hr { border: none; border-top: 1px solid var(--border); margin: 1rem 0; }
.kimi-ai-bubble table { width: 100%; border-collapse: collapse; font-size: .875rem; margin-bottom: 1rem; }
.kimi-ai-bubble th, .kimi-ai-bubble td { padding: 7px 10px; border: 1px solid var(--border); text-align: left; }
.kimi-ai-bubble th { background: var(--hover-bg); font-weight: 600; }

.code-wrapper { position: relative; }
.copy-btn {
  position: absolute; top: 8px; right: 8px;
  padding: 3px 8px; font-size: 11px;
  background: var(--card-bg); border: 1px solid var(--border);
  border-radius: 4px; color: var(--text-muted);
  transition: background var(--t), color var(--t); cursor: pointer;
}
.copy-btn:hover { background: var(--hover-bg); color: var(--text-main); }
.copy-btn.copied { color: var(--green); border-color: var(--green); }

.typing-indicator {
  display: flex; align-items: center; gap: 5px;
  padding: 12px 16px; background: var(--card-bg);
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  width: fit-content; box-shadow: var(--shadow-xs);
}
.typing-dot { width: 6px; height: 6px; background: var(--text-subtle); border-radius: 50%; animation: bounce .8s infinite ease-in-out; }
.typing-dot:nth-child(2) { animation-delay: .15s; }
.typing-dot:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%,80%,100% { transform: scale(.6); opacity: .4; } 40% { transform: scale(1); opacity: 1; } }

/* Input bar */
.input-bar { padding: 14px 20px 18px; background: var(--bg); border-top: 1px solid var(--border); flex-shrink: 0; }

.input-box {
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--input-bg); border: 1.5px solid var(--border);
  border-radius: var(--radius-xl); padding: 10px 10px 10px 16px;
  box-shadow: var(--shadow-sm);
  transition: border-color var(--t), box-shadow var(--t);
}
.input-box:focus-within { border-color: var(--green); box-shadow: 0 0 0 3px rgba(16,185,129,.12), var(--shadow-sm); }

textarea#user-input {
  flex: 1; background: none; border: none; outline: none; resize: none;
  font-size: 14px; line-height: 1.6; color: var(--text-main);
  max-height: 160px; overflow-y: auto;
}
textarea#user-input::placeholder { color: var(--text-subtle); }
textarea#user-input::-webkit-scrollbar { width: 0; }

.send-btn {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--text-main); color: var(--card-bg);
  display: flex; align-items: center; justify-content: center;
  transition: background var(--t), transform var(--t), opacity var(--t);
  flex-shrink: 0; opacity: .4;
}
.send-btn.active { background: var(--green); opacity: 1; }
.send-btn.active:hover { background: var(--green-hover); transform: scale(1.06); }
.send-btn.loading { animation: spin .9s linear infinite; opacity: .7; }

.input-meta {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 9px; padding: 0 3px;
}
.input-tools { display: flex; gap: 3px; }
.tool-btn {
  display: flex; align-items: center; gap: 5px;
  padding: 5px 9px; border-radius: var(--radius-sm);
  font-size: 12px; color: var(--text-muted);
  transition: background var(--t), color var(--t);
}
.tool-btn:hover { background: var(--hover-bg); color: var(--text-main); }
.char-counter { font-size: 11.5px; color: var(--text-subtle); }
.input-footer-note { font-size: 11px; color: var(--text-subtle); text-align: center; margin-top: 9px; }

/* Right panel */
.right-panel {
  background: var(--card-bg); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden;
}
.right-panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 14px; border-bottom: 1px solid var(--border);
  font-size: 13px; font-weight: 600; color: var(--text-main); flex-shrink: 0;
}
.history-list { flex: 1; overflow-y: auto; padding: 6px; }
.history-list::-webkit-scrollbar { width: 0; }

.history-item {
  padding: 9px 10px; border-radius: var(--radius-md);
  cursor: pointer; transition: background var(--t);
  display: flex; align-items: flex-start; gap: 8px; margin-bottom: 1px;
}
.history-item:hover { background: var(--hover-bg); }
.history-item.active { background: var(--active-bg); }
.history-check {
  width: 16px; height: 16px; border: 1.5px solid var(--border);
  border-radius: 4px; flex-shrink: 0; margin-top: 1px; transition: border-color var(--t);
}
.history-item:hover .history-check { border-color: var(--green); }
.history-text { min-width: 0; }
.history-title { font-size: 12.5px; font-weight: 500; color: var(--text-main); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-preview { font-size: 11px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }

.right-panel-empty { text-align: center; padding: 40px 16px; color: var(--text-subtle); font-size: 12.5px; }
.right-panel-empty svg { display: block; margin: 0 auto 10px; opacity: .25; }

/* ─── Settings Modal ─────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45); backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; opacity: 0; pointer-events: none;
  transition: opacity .2s var(--ease);
}
.modal-overlay.open { opacity: 1; pointer-events: all; }

.modal {
  background: var(--card-bg); border: 1px solid var(--border);
  border-radius: var(--radius-xl); width: 420px; max-width: calc(100vw - 40px);
  box-shadow: var(--shadow-xl);
  transform: scale(.95) translateY(10px);
  transition: transform .2s var(--ease);
}
.modal-overlay.open .modal { transform: scale(1) translateY(0); }

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px 14px; border-bottom: 1px solid var(--border);
}
.modal-header-brand { display: flex; align-items: center; gap: 10px; }
.modal-logo {
  width: 30px; height: 30px; border-radius: 7px;
  object-fit: contain; border: 1px solid var(--border);
}
[data-theme="dark"] .modal-logo { filter: invert(1); }
.modal-header h2 { font-size: 15px; font-weight: 600; color: var(--text-main); }

.modal-body { padding: 18px 22px 22px; display: flex; flex-direction: column; gap: 14px; }

.field-group { display: flex; flex-direction: column; gap: 5px; }
.field-group label { font-size: 12.5px; font-weight: 500; color: var(--text-muted); }
.label-hint { font-weight: 400; color: var(--text-subtle); }
.field-group input, .field-group select {
  padding: 9px 11px;
  background: var(--input-bg); border: 1.5px solid var(--border);
  border-radius: var(--radius-md); font-size: 13.5px; color: var(--text-main);
  outline: none; transition: border-color var(--t), box-shadow var(--t);
}
.field-group input:focus, .field-group select:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(16,185,129,.1);
}

.btn-primary {
  width: 100%; padding: 10px;
  background: var(--green); color: #fff;
  border-radius: var(--radius-md); font-size: 14px; font-weight: 600;
  transition: background var(--t), transform var(--t);
}
.btn-primary:hover { background: var(--green-hover); transform: translateY(-1px); }

.settings-note { font-size: 12px; color: var(--text-muted); text-align: center; min-height: 16px; }
.settings-note.ok { color: var(--green); }
.settings-note.err { color: #ef4444; }

.gemini-guide {
  display: none;
  margin-top: 10px;
  padding: 12px 14px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 10px;
  font-size: 12px;
  line-height: 1.55;
  color: #1e3a8a;
}
.gemini-guide.open { display: block; }
.gemini-guide a { color: #1d4ed8; font-weight: 600; text-decoration: underline; }
.gemini-guide code { background: rgba(255,255,255,.7); padding: 1px 5px; border-radius: 4px; font-size: 11px; }

/* ─── Toast ──────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: #1f2937; color: #fff;
  padding: 10px 18px; border-radius: var(--radius-md);
  font-size: 13px; box-shadow: var(--shadow-lg); z-index: 300;
  transition: transform .25s var(--ease); white-space: nowrap;
  max-width: 90vw; overflow: hidden; text-overflow: ellipsis;
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* ─── Responsive ─────────────────────────────────────────────────────────────── */
.mobile-top-btn { display: none; }

.mobile-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .45);
  z-index: 180;
  backdrop-filter: blur(2px);
}
.mobile-backdrop.show { display: block; }

body.drawer-open { overflow: hidden; }

@media (max-width: 1024px) {
  .layout { grid-template-columns: 1fr; }

  .right-panel {
    display: flex;
    position: fixed;
    top: 0;
    right: 0;
    width: min(320px, 90vw);
    height: 100vh;
    height: 100dvh;
    z-index: 190;
    transform: translateX(100%);
    transition: transform .22s var(--ease);
    box-shadow: var(--shadow-xl);
  }
  .right-panel.open { transform: translateX(0); }

  .mobile-history-btn { display: flex; }

  .topbar { padding: 0 12px; }
  .btn-upgrade span { display: none; }
  .btn-upgrade { padding: 7px 10px; }
}

@media (max-width: 768px) {
  .sidebar {
    display: flex;
    position: fixed;
    top: 0;
    left: 0;
    width: min(288px, 90vw);
    height: 100vh;
    height: 100dvh;
    z-index: 190;
    transform: translateX(-100%);
    transition: transform .22s var(--ease);
    box-shadow: var(--shadow-xl);
  }
  .sidebar.open { transform: translateX(0); }

  .mobile-menu-btn { display: flex; }
  .sidebar-search kbd { display: none; }
  .quick-cards { grid-template-columns: 1fr; }
  .welcome-heading { font-size: 22px; }
  .welcome-screen { padding: 24px 16px; }
  .chat-messages { padding: 16px 12px; }
  .input-bar { padding: 10px 12px 14px; }
  .input-tools { display: none; }
  .msg-bubble { max-width: 92%; }
  .auth-card { padding: 28px 22px; margin: 16px; }
}

@media (min-width: 1025px) {
  .layout.sidebar-collapsed { grid-template-columns: 0 1fr var(--right-w); }
  .layout.sidebar-collapsed .sidebar {
    width: 0;
    min-width: 0;
    padding: 0;
    border: none;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
  }
  .layout.history-collapsed { grid-template-columns: var(--sidebar-w) 1fr 0; }
  .layout.history-collapsed .right-panel {
    width: 0;
    min-width: 0;
    padding: 0;
    border: none;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
  }
}
