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

:root {
  --bg:          #0a0f1e;
  --surface:     #111827;
  --surface-2:   #1a2235;
  --surface-3:   #212d44;
  --border:      #1e2d4a;
  --blue:        #2563eb;
  --blue-light:  #3b82f6;
  --blue-glow:   rgba(37,99,235,0.15);
  --text:        #e2e8f0;
  --text-muted:  #64748b;
  --text-dim:    #94a3b8;
  --success:     #22c55e;
  --error:       #ef4444;
  --radius:      12px;
  --radius-sm:   8px;
  --font:        'Inter', system-ui, -apple-system, sans-serif;
}

html, body { height: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

body.modal-open {
  overflow: hidden;
}

body.mobile-sidebar-open {
  overflow: hidden;
}

body.auth-loading #login-form,
body.auth-loading #clerk-auth {
  display: none !important;
}

.app-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(4, 10, 24, 0.68);
  backdrop-filter: blur(18px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
}

.app-modal-backdrop.visible {
  opacity: 1;
  pointer-events: auto;
}

.app-modal-card {
  width: min(100%, 480px);
  border: 1px solid rgba(83, 112, 172, 0.34);
  border-radius: 24px;
  background:
    linear-gradient(180deg, rgba(19, 29, 54, 0.98) 0%, rgba(10, 17, 33, 0.99) 100%);
  box-shadow:
    0 30px 90px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.04);
  transform: translateY(18px) scale(0.98);
  transition: transform 0.18s ease;
}

.app-modal-backdrop.visible .app-modal-card {
  transform: translateY(0) scale(1);
}

.app-modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 22px 0;
}

.app-modal-title {
  color: #f8fbff;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.04em;
}

.app-modal-description {
  margin-top: 8px;
  color: #91a4c5;
  font-size: 14px;
  line-height: 1.6;
}

.app-modal-close {
  margin-top: -2px;
}

.app-modal-form {
  padding: 18px 22px 22px;
}

.app-modal-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.app-modal-label {
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

#folder-modal-input {
  width: 100%;
  padding: 13px 14px;
  background: rgba(12, 21, 39, 0.92);
  border: 1px solid rgba(58, 79, 120, 0.78);
  border-radius: 14px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

#folder-modal-input:focus {
  border-color: rgba(79, 140, 255, 0.82);
  box-shadow: 0 0 0 4px rgba(79, 140, 255, 0.14);
}

#folder-modal-input::placeholder {
  color: var(--text-muted);
}

.app-modal-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.app-modal-chip {
  padding: 8px 12px;
  border: 1px solid rgba(83, 112, 172, 0.28);
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.72);
  color: #c4d5ff;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease, color 0.12s ease;
}

.app-modal-chip:hover {
  border-color: rgba(79, 140, 255, 0.42);
  background: rgba(20, 31, 58, 0.9);
  color: #f3f7ff;
}

.app-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 22px;
}

.app-modal-btn {
  min-width: 128px;
  padding: 12px 16px;
  border-radius: 14px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.12s ease, border-color 0.12s ease, color 0.12s ease, opacity 0.12s ease;
}

.app-modal-btn:active {
  transform: scale(0.98);
}

.app-modal-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.app-modal-btn-secondary {
  border: 1px solid rgba(83, 112, 172, 0.26);
  background: rgba(11, 20, 39, 0.6);
  color: #d5e3ff;
}

.app-modal-btn-secondary:hover {
  border-color: rgba(105, 143, 221, 0.42);
  background: rgba(16, 28, 54, 0.82);
}

.app-modal-btn-primary {
  border: 0;
  background: linear-gradient(135deg, #4f8cff 0%, #2563eb 100%);
  color: #f8fbff;
  box-shadow: 0 14px 32px rgba(37, 99, 235, 0.35);
}

.app-modal-btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, #66a1ff 0%, #3170f2 100%);
}

.app-modal-btn-primary.app-modal-btn-danger {
  background: linear-gradient(135deg, #f87171 0%, #ef4444 100%);
  box-shadow: 0 14px 32px rgba(239, 68, 68, 0.28);
}

.app-modal-btn-primary.app-modal-btn-danger:hover:not(:disabled) {
  background: linear-gradient(135deg, #fb8b8b 0%, #f25f5f 100%);
}

/* ── Screens ────────────────────────────────────────────────────────────── */
.screen { height: 100vh; width: 100%; }

.btn-secondary,
.btn-ghost {
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.btn-secondary {
  padding: 13px 18px;
  border: 1px solid rgba(105, 143, 221, 0.26);
  background: rgba(12, 23, 47, 0.66);
  color: #d9e5ff;
}

.btn-secondary:hover {
  transform: translateY(-1px);
  border-color: rgba(105, 143, 221, 0.48);
  background: rgba(18, 31, 63, 0.84);
}

.btn-ghost {
  padding: 10px 16px;
  border: 1px solid rgba(105, 143, 221, 0.16);
  background: rgba(10, 18, 35, 0.42);
  color: #c4d5ff;
}

.btn-ghost:hover {
  border-color: rgba(105, 143, 221, 0.36);
  background: rgba(16, 28, 54, 0.7);
}

.language-switcher {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border-radius: 999px;
  border: 1px solid rgba(105, 143, 221, 0.2);
  background: rgba(7, 16, 33, 0.82);
  box-shadow:
    0 16px 34px rgba(0, 0, 0, 0.24),
    inset 0 1px 0 rgba(255, 255, 255, 0.04);
  backdrop-filter: blur(14px);
}

.language-btn {
  min-width: 48px;
  padding: 8px 12px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: #9ab3df;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.language-btn:hover {
  color: #f3f7ff;
}

.language-btn.active {
  background: linear-gradient(135deg, #4f8cff 0%, #2563eb 100%);
  color: #f8fbff;
  box-shadow: 0 10px 22px rgba(37, 99, 235, 0.3);
}

/* ── Landing ────────────────────────────────────────────────────────────── */
#landing-screen {
  height: auto;
  min-height: 100vh;
  padding: 24px 28px 40px;
  background:
    radial-gradient(circle at 16% 18%, rgba(77, 132, 255, 0.18) 0%, transparent 26%),
    radial-gradient(circle at 80% 16%, rgba(40, 88, 198, 0.15) 0%, transparent 24%),
    linear-gradient(165deg, #071126 0%, #0b1730 42%, #08111f 100%);
}

.landing-nav,
.landing-main {
  max-width: 1180px;
  margin: 0 auto;
}

.landing-footer {
  max-width: 1180px;
  margin: 28px auto 0;
  display: flex;
  justify-content: flex-end;
}

.social-link {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid rgba(105, 143, 221, 0.18);
  background: rgba(11, 20, 39, 0.52);
  color: #c8d7f7;
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.social-link:hover {
  transform: translateY(-1px);
  border-color: rgba(105, 143, 221, 0.38);
  background: rgba(16, 28, 54, 0.76);
  color: #f3f7ff;
}

.social-link svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
}

.social-link .social-dot {
  fill: currentColor;
  stroke: none;
}

.landing-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 44px;
}

.landing-nav-tools {
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.landing-brand,
.hero-actions,
.hero-pills {
  display: flex;
  align-items: center;
}

.landing-brand {
  gap: 12px;
  color: #f8fbff;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.landing-brand-logo {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 12px;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.08);
}

.landing-main {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(360px, 0.9fr);
  gap: 36px;
  align-items: center;
  min-height: calc(100vh - 108px);
}

.hero-copy {
  padding: 26px 0;
}

.hero-kicker {
  display: inline-flex;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid rgba(123, 154, 219, 0.22);
  background: rgba(11, 21, 42, 0.7);
  color: #9abaff;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.hero-copy h1 {
  margin-top: 18px;
  color: #f8fbff;
  font-size: clamp(42px, 6vw, 68px);
  line-height: 0.98;
  letter-spacing: -0.06em;
}

.hero-text {
  max-width: 620px;
  margin-top: 22px;
  color: #9baecc;
  font-size: 18px;
  line-height: 1.7;
}

.hero-actions {
  gap: 14px;
  margin-top: 28px;
}

.hero-actions .btn-primary {
  margin-top: 0;
}

.hero-primary {
  padding-inline: 22px;
}

.hero-pills {
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 26px;
}

.hero-pills span {
  padding: 9px 12px;
  border-radius: 999px;
  background: rgba(12, 23, 47, 0.72);
  border: 1px solid rgba(105, 143, 221, 0.16);
  color: #c4d5ff;
  font-size: 13px;
}

.hero-panel-shell {
  padding: 24px;
  border-radius: 28px;
  border: 1px solid rgba(83, 112, 172, 0.34);
  background:
    linear-gradient(180deg, rgba(18, 29, 57, 0.96) 0%, rgba(12, 20, 39, 0.98) 100%);
  box-shadow:
    0 26px 80px rgba(0,0,0,0.4),
    inset 0 1px 0 rgba(255,255,255,0.04);
}

.hero-panel-head {
  display: flex;
  align-items: center;
  gap: 14px;
}

.hero-panel-logo {
  width: 54px;
  height: 54px;
  border-radius: 16px;
  object-fit: cover;
}

.hero-panel-head strong {
  display: block;
  color: #f8fbff;
  font-size: 18px;
}

.hero-panel-head p {
  color: #91a4c5;
  font-size: 14px;
}

.hero-chat-preview {
  margin-top: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.hero-preview-row {
  max-width: 92%;
  padding: 14px 16px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.7;
  transition: opacity 0.28s ease, transform 0.28s ease;
}

.hero-preview-user {
  margin-left: auto;
  background: linear-gradient(135deg, #4f8cff 0%, #2563eb 100%);
  color: #f8fbff;
  opacity: 0;
  transform: translateX(28px) scale(0.98);
}

.hero-preview-user.visible {
  opacity: 1;
  transform: translateX(0) scale(1);
}

.hero-preview-thinking {
  max-width: 84px;
  padding: 12px 18px;
  background: rgba(15, 24, 43, 0.74);
  border: 1px solid rgba(83, 112, 172, 0.2);
  color: #a7bbdf;
  opacity: 0;
  transform: translateY(8px);
}

.hero-preview-thinking.visible {
  opacity: 1;
  transform: translateY(0);
}

.hero-preview-thinking span {
  display: inline-block;
  min-width: 22px;
  letter-spacing: 0.16em;
  font-weight: 700;
}

.hero-preview-assistant {
  background: rgba(15, 24, 43, 0.92);
  border: 1px solid rgba(83, 112, 172, 0.26);
  color: #dbe7ff;
  opacity: 0;
  transform: translateY(10px);
}

.hero-preview-assistant.visible {
  opacity: 1;
  transform: translateY(0);
}

/* ── Login ──────────────────────────────────────────────────────────────── */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 20% 20%, rgba(79,140,255,0.18) 0%, transparent 28%),
    radial-gradient(circle at 78% 68%, rgba(37,99,235,0.16) 0%, transparent 34%),
    linear-gradient(145deg, #071126 0%, #0c1630 45%, #08101f 100%);
}

.login-card {
  width: 100%;
  max-width: 380px;
  padding: 40px 36px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.5);
}

.login-card.clerk-mode {
  max-width: 560px;
  padding: 0;
  background: transparent;
  border: 0;
  box-shadow: none;
}

.brand {
  text-align: center;
  margin-bottom: 32px;
}

.login-card.clerk-mode .brand {
  max-width: 520px;
  margin: 0 auto 22px;
}

.brand-kicker {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 18px;
  padding: 6px 12px;
  border: 1px solid rgba(79,140,255,0.26);
  border-radius: 999px;
  background: rgba(9,19,42,0.72);
  color: #9dbdff;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.brand-logo {
  width: 90px;
  height: 90px;
  margin: 0 auto 18px;
  display: block;
  object-fit: cover;
  border-radius: 26px;
  box-shadow:
    0 24px 48px rgba(7, 17, 38, 0.45),
    0 0 0 1px rgba(255, 255, 255, 0.08);
}

.brand h1 {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.04em;
  color: #fff;
}

.brand p {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}

.brand-copy {
  display: block;
  max-width: 420px;
  margin: 14px auto 0;
  color: #8ca0c1;
  font-size: 14px;
  line-height: 1.6;
}

.field { margin-bottom: 16px; }

.field label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.field input {
  width: 100%;
  padding: 11px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}

.field input:focus { border-color: var(--blue); }
.field input::placeholder { color: var(--text-muted); }

.btn-primary {
  width: 100%;
  padding: 12px;
  margin-top: 8px;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.btn-primary:hover { background: var(--blue-light); }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.error-msg {
  font-size: 13px;
  color: var(--error);
  margin-bottom: 10px;
  padding: 10px 12px;
  background: rgba(239,68,68,0.1);
  border-radius: var(--radius-sm);
}

#clerk-auth {
  display: none;
}

.login-card.clerk-mode #clerk-auth {
  display: block;
}

.clerk-native-root {
  width: 100%;
}

.clerk-native-card-box {
  width: 100%;
}

.clerk-native-card {
  width: min(100%, 520px);
  margin: 0 auto;
  border: 1px solid rgba(55, 79, 123, 0.72);
  border-radius: 26px;
  background:
    linear-gradient(180deg, rgba(18, 28, 52, 0.97) 0%, rgba(11, 19, 37, 0.98) 100%);
  box-shadow:
    0 30px 90px rgba(0, 0, 0, 0.48),
    inset 0 1px 0 rgba(255, 255, 255, 0.04);
  backdrop-filter: blur(14px);
}

.clerk-native-title {
  color: #f8fafc;
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.04em;
}

.clerk-native-subtitle {
  color: #94a3b8;
}

.clerk-native-input {
  border: 1px solid rgba(58, 79, 120, 0.72);
  background: rgba(10, 18, 35, 0.92);
  color: #e2e8f0;
  box-shadow: none;
}

.clerk-native-input:focus {
  border-color: rgba(79, 140, 255, 0.82);
  box-shadow: 0 0 0 4px rgba(79, 140, 255, 0.14);
}

.clerk-native-social-button-text,
.clerk-native-label,
.clerk-native-identity-text,
.clerk-native-user-text {
  color: #e2e8f0;
}

.clerk-native-divider-line {
  background: rgba(58, 79, 120, 0.48);
}

.clerk-native-divider-text,
.clerk-native-footer-text,
.clerk-native-user-subtext {
  color: #94a3b8;
}

.clerk-native-primary-button {
  background: linear-gradient(135deg, #4f8cff 0%, #2563eb 100%);
  color: #f8fbff;
  border: 0;
  border-radius: 14px;
  box-shadow: 0 14px 32px rgba(37, 99, 235, 0.35);
}

.clerk-native-primary-button:hover,
.clerk-native-primary-button:focus {
  background: linear-gradient(135deg, #66a1ff 0%, #3170f2 100%);
}

.clerk-native-footer-link,
.clerk-native-link-button {
  color: #8ab4ff;
}

.clerk-native-footer-link:hover,
.clerk-native-link-button:hover {
  color: #bfd4ff;
}

.clerk-native-user-avatar {
  box-shadow: 0 0 0 1px rgba(79, 140, 255, 0.36);
  border-radius: 999px;
}

.clerk-native-user-popover {
  background: #111827;
  border: 1px solid #1e2d4a;
  box-shadow: 0 18px 50px rgba(0,0,0,0.42);
}

.clerk-native-badge {
  background: rgba(79, 140, 255, 0.16);
  color: #9fc1ff;
}

.clerk-native-footer {
  border-top-color: rgba(58, 79, 120, 0.42);
}

/* ── Chat layout ────────────────────────────────────────────────────────── */
#chat-screen {
  display: flex;
  overflow: hidden;
  position: relative;
}

/* ── Sidebar ────────────────────────────────────────────────────────────── */
.mobile-sidebar-backdrop,
.mobile-chat-header,
.sidebar-close-btn {
  display: none;
}

.sidebar {
  width: 240px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px 12px;
}

.sidebar-header { padding: 4px 4px 16px; }

.sidebar-brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand-sm {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
  font-weight: 700;
  color: #fff;
}

.brand-sm-logo {
  width: 28px;
  height: 28px;
  object-fit: cover;
  border-radius: 9px;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.new-chat-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-dim);
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  margin-bottom: 12px;
}

.new-chat-btn:hover { background: var(--surface-2); color: var(--text); }
.new-chat-btn svg { width: 16px; height: 16px; }

.sidebar-section {
  margin-bottom: 14px;
}

.sidebar-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 4px 8px;
}

.sidebar-section-title {
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.section-action-btn {
  padding: 4px;
}

.folder-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.folder-item-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.folder-item {
  flex: 1;
  min-width: 0;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.42);
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease, color 0.12s ease;
}

.folder-item:hover {
  border-color: rgba(79, 140, 255, 0.34);
  color: var(--text);
}

.folder-item.active {
  background: rgba(37, 99, 235, 0.16);
  border-color: rgba(79, 140, 255, 0.46);
  color: #dce8ff;
}

.folder-item-delete {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s ease, background 0.12s ease, color 0.12s ease;
}

.folder-item-row:hover .folder-item-delete,
.folder-item-row:focus-within .folder-item-delete {
  opacity: 1;
}

.folder-item-delete:hover {
  background: rgba(239, 68, 68, 0.12);
  color: #fca5a5;
}

.folder-item-delete svg {
  width: 14px;
  height: 14px;
}

.chat-history {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 6px 6px 10px;
  border-radius: var(--radius-sm);
  transition: background 0.12s, color 0.12s;
}

.history-item:hover { background: var(--surface-2); color: var(--text); }
.history-item.active { background: var(--blue-glow); color: var(--blue-light); }

.history-item-title {
  flex: 1;
  min-width: 0;
  padding: 2px 0;
  border: 0;
  background: transparent;
  color: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item-folder {
  max-width: 78px;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(79, 140, 255, 0.12);
  color: #a9c6ff;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item-delete {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s ease, background 0.12s ease, color 0.12s ease;
}

.history-item-move {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s ease, background 0.12s ease, color 0.12s ease;
}

.history-item:hover .history-item-move,
.history-item:hover .history-item-delete,
.history-item.active .history-item-move,
.history-item.active .history-item-delete {
  opacity: 1;
}

.history-item-move:hover {
  background: rgba(79, 140, 255, 0.12);
  color: #a9c6ff;
}

.history-item-delete:hover {
  background: rgba(239, 68, 68, 0.12);
  color: #fca5a5;
}

.history-item-move svg,
.history-item-delete svg {
  width: 14px;
  height: 14px;
}

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

.sidebar-footer-bottom {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 5px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  transition: color 0.15s, background 0.15s;
  flex-shrink: 0;
}

.icon-btn:hover { color: var(--text); background: var(--surface-2); }
.icon-btn svg { width: 18px; height: 18px; }

#clerk-user-button {
  display: flex;
  align-items: center;
}

.app-settings-card {
  width: min(100%, 420px);
}

.app-settings-form {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.app-settings-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.settings-language-switcher {
  align-self: flex-start;
}

/* ── Chat main ──────────────────────────────────────────────────────────── */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
}

.mobile-chat-header {
  position: sticky;
  top: 0;
  z-index: 8;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid rgba(30, 45, 74, 0.92);
  background: rgba(10, 15, 30, 0.88);
  backdrop-filter: blur(16px);
}

.mobile-chat-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: #f8fbff;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.mobile-chat-logo {
  width: 28px;
  height: 28px;
  object-fit: cover;
  border-radius: 9px;
  flex-shrink: 0;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 0;
  scroll-behavior: smooth;
}

/* ── Welcome ────────────────────────────────────────────────────────────── */
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 60px 24px 32px;
  max-width: 640px;
  margin: 0 auto;
}

.welcome-logo {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 22px;
  margin-bottom: 20px;
  box-shadow:
    0 20px 42px rgba(0, 0, 0, 0.36),
    0 0 0 1px rgba(255, 255, 255, 0.08);
}

.welcome h2 {
  font-size: 22px;
  font-weight: 600;
  color: #fff;
  margin-bottom: 8px;
}

.welcome p {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 28px;
}

.starter-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 100%;
}

.starter {
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-dim);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  line-height: 1.4;
}

.starter:hover {
  background: var(--surface-2);
  border-color: var(--blue);
  color: var(--text);
}

/* ── Message bubbles ────────────────────────────────────────────────────── */
.message-row {
  display: flex;
  padding: 6px 24px;
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
  gap: 12px;
}

.message-row.user { justify-content: flex-end; }
.message-row.assistant { justify-content: flex-start; }

.msg-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  margin-top: 2px;
}

.assistant .msg-avatar {
  background: transparent;
  color: #fff;
}

.user .msg-avatar {
  background: var(--surface-3);
  color: var(--text-dim);
}

.msg-avatar-logo {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  object-fit: cover;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.msg-content {
  max-width: 75%;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.7;
}

.user .msg-content {
  background: var(--blue);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.assistant .msg-content {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

/* Markdown-like formatting inside assistant messages */
.msg-content p { margin-bottom: 10px; }
.msg-content p:last-child { margin-bottom: 0; }
.msg-content strong { color: #fff; font-weight: 600; }
.msg-content em { color: var(--text-dim); }
.msg-content a {
  color: #8ab4ff;
  text-decoration: underline;
  text-underline-offset: 2px;
  word-break: break-word;
}
.msg-content a:hover {
  color: #bfd4ff;
}
.msg-content code {
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 12px;
  background: var(--surface-3);
  padding: 2px 6px;
  border-radius: 4px;
}
.msg-content ul, .msg-content ol { padding-left: 20px; margin-bottom: 8px; }
.msg-content li { margin-bottom: 4px; }

.msg-content.thinking {
  color: #9fc1ff;
  font-weight: 600;
}

@media (max-width: 960px) {
  .landing-main {
    grid-template-columns: 1fr;
  }

  .hero-copy {
    padding-top: 0;
  }
}

@media (max-width: 640px) {
  .app-modal-backdrop {
    align-items: flex-end;
    padding: 14px;
  }

  .app-modal-card {
    width: 100%;
    border-radius: 22px;
  }

  .app-modal-header {
    padding: 18px 18px 0;
  }

  .app-modal-form {
    padding: 16px 18px 18px;
  }

  .app-modal-actions {
    flex-direction: column-reverse;
  }

  .app-modal-btn {
    width: 100%;
  }

  #landing-screen {
    padding: 18px 16px 28px;
  }

  .landing-nav,
  .hero-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .landing-nav-tools {
    justify-content: flex-start;
  }

  .landing-nav {
    margin-bottom: 26px;
  }

  .landing-footer {
    justify-content: stretch;
  }

  .social-link {
    justify-content: center;
    width: 100%;
  }

  #clerk-user-button {
    display: none !important;
  }

  .hero-copy h1 {
    font-size: 42px;
  }

  .login-card.clerk-mode {
    padding: 0 14px;
  }

  .brand-copy {
    font-size: 13px;
  }

  .clerk-native-card {
    border-radius: 20px;
  }
}

/* ── Input area ─────────────────────────────────────────────────────────── */
.input-area {
  padding: 16px 24px 20px;
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
  padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
}

.input-bar {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 10px 10px 16px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input-bar:focus-within {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-glow);
}

#user-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  resize: none;
  max-height: 200px;
  overflow-y: auto;
  font-family: var(--font);
}

#user-input::placeholder { color: var(--text-muted); }

.send-btn {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  background: var(--blue);
  border: none;
  border-radius: 10px;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.1s;
}

.send-btn:hover:not(:disabled) { background: var(--blue-light); }
.send-btn:active:not(:disabled) { transform: scale(0.93); }
.send-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.send-btn svg { width: 18px; height: 18px; }

.disclaimer {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 10px;
}

/* ── Scrollbar ──────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Mobile ─────────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  #landing-screen {
    padding-top: 74px;
  }

  #login-screen {
    height: auto;
    min-height: 100vh;
    padding: 84px 16px 24px;
  }

  .login-card {
    padding: 30px 22px;
    border-radius: 18px;
  }

  .mobile-sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 18;
    background: rgba(2, 8, 23, 0.56);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
  }

  body.mobile-sidebar-open .mobile-sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .sidebar {
    display: flex;
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 20;
    width: min(84vw, 320px);
    max-width: 320px;
    padding: 16px 12px calc(18px + env(safe-area-inset-bottom, 0px));
    transform: translateX(-108%);
    transition: transform 0.22s ease;
    box-shadow: 24px 0 60px rgba(0, 0, 0, 0.36);
  }

  body.mobile-sidebar-open .sidebar {
    transform: translateX(0);
  }

  .sidebar-close-btn,
  .mobile-chat-header {
    display: flex;
  }

  .chat-main {
    width: 100%;
  }

  .messages {
    padding: 12px 0 0;
  }

  .starter-grid { grid-template-columns: 1fr; }
  .message-row {
    padding: 6px 12px;
    gap: 10px;
  }

  .msg-avatar {
    width: 28px;
    height: 28px;
  }

  .msg-avatar-logo {
    width: 28px;
    height: 28px;
  }

  .msg-content {
    max-width: 90%;
    font-size: 13px;
    line-height: 1.65;
  }

  .welcome {
    padding: 28px 16px 24px;
  }

  .welcome-logo {
    width: 62px;
    height: 62px;
    border-radius: 18px;
    margin-bottom: 18px;
  }

  .welcome h2 {
    font-size: 20px;
  }

  .starter {
    padding: 13px 14px;
  }

  .input-area {
    padding: 10px 12px calc(14px + env(safe-area-inset-bottom, 0px));
  }

  .input-bar {
    padding: 10px;
    border-radius: 16px;
  }

  #user-input {
    font-size: 16px;
  }

  .disclaimer {
    margin-top: 8px;
    font-size: 10px;
  }
}
