/* ============================================================
   Peit — design system
   ============================================================ */
:root {
  --bg: #0a0a0c;
  --bg-2: #0e0f12;
  --panel: #141519;
  --panel-2: #1a1c22;
  --border: rgba(255, 255, 255, 0.09);
  --border-soft: rgba(255, 255, 255, 0.05);
  --text: #f3f4f6;
  --muted: #9aa1ad;
  --faint: #656b78;
  /* Single confident accent, used solid (not as a wash) */
  --accent: #6366f1;
  --accent-2: #818cf8;
  --brand: #6366f1;
  --brand-2: #818cf8;
  --grad: linear-gradient(140deg, #6366f1, #8b5cf6); /* reserved for the brand mark */
  --grad-soft: rgba(99, 102, 241, 0.13);
  --accent-soft: rgba(99, 102, 241, 0.13);
  --user-bubble: #1b1d23;
  --assistant-bubble: #141519;
  --good: #34d399;
  --danger: #f87171;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --radius: 14px;
  --radius-sm: 10px;
  --radius-lg: 20px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #fbfbfc;
  --bg-2: #f5f6f8;
  --panel: #ffffff;
  --panel-2: #f6f7f9;
  --border: rgba(17, 20, 28, 0.11);
  --border-soft: rgba(17, 20, 28, 0.06);
  --text: #16181d;
  --muted: #5a616e;
  --faint: #969ba6;
  --grad-soft: rgba(99, 102, 241, 0.10);
  --accent-soft: rgba(99, 102, 241, 0.10);
  --user-bubble: #eef0fb;
  --assistant-bubble: #ffffff;
  --shadow: 0 24px 60px rgba(30, 35, 60, 0.15);
  --shadow-sm: 0 1px 2px rgba(30, 35, 60, 0.06);
}
:root[data-theme="dark"] {
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}
/* The [hidden] attribute must always win, even over display rules on the same
   element (e.g. .auth-form { display: flex } on the verification step). */
[hidden] {
  display: none !important;
}
html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}
body {
  font-family: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  line-height: 1.6;
}
a {
  color: inherit;
  text-decoration: none;
}

.view {
  display: none;
  min-height: 100vh;
}
.view.active {
  display: block;
}
#view-app.active {
  display: grid;
}

.grad-text {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font: inherit;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 11px 18px;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.15s, background 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.btn:active {
  transform: translateY(1px) scale(0.99);
}
.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover {
  background: var(--accent-2);
  transform: translateY(-1px);
}
.btn-ghost {
  background: color-mix(in srgb, var(--panel) 55%, transparent);
  color: var(--text);
  border-color: var(--border);
  backdrop-filter: blur(6px);
}
.btn-ghost:hover {
  border-color: var(--brand);
  background: var(--grad-soft);
}
.btn-sm {
  padding: 8px 14px;
  font-size: 14px;
}
.btn-lg {
  padding: 14px 26px;
  font-size: 16px;
}
.btn-block {
  width: 100%;
}

/* ---------- Logo ---------- */
.logo {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 20px;
  letter-spacing: -0.02em;
  cursor: pointer;
}
.logo-mark {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  filter: drop-shadow(0 4px 12px rgba(99, 102, 241, 0.3));
}
.logo-mark.sm {
  width: 26px;
  height: 26px;
}
.mark-ic {
  width: 100%;
  height: 100%;
  display: block;
}
.nav-link {
  color: var(--muted);
  font-size: 15px;
  font-weight: 500;
  transition: color 0.15s;
  cursor: pointer;
}
.nav-link:hover {
  color: var(--text);
}
.pill-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--good);
  box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.25);
}

/* ============================================================
   LANDING — single animated screen
   ============================================================ */
#view-landing {
  position: relative;
  height: 100vh;
  overflow: hidden;
}
/* Only render the landing when it's the active view (an #id rule must beat
   `.view { display:none }`, so the display toggle lives here, not on the base). */
#view-landing.active {
  display: flex;
  flex-direction: column;
}

/* Animated aurora background */
.aurora {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}
.aurora .blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.55;
  will-change: transform;
}
.aurora .b1 {
  width: 46vw;
  height: 46vw;
  top: -12%;
  left: -8%;
  background: radial-gradient(circle at 30% 30%, #6366f1, transparent 62%);
  animation: drift1 16s ease-in-out infinite;
}
.aurora .b2 {
  width: 42vw;
  height: 42vw;
  bottom: -14%;
  right: -6%;
  background: radial-gradient(circle at 60% 40%, #8b5cf6, transparent 62%);
  animation: drift2 19s ease-in-out infinite;
}
.aurora .b3 {
  width: 34vw;
  height: 34vw;
  top: 30%;
  left: 45%;
  background: radial-gradient(circle at 50% 50%, #6366f1, transparent 62%);
  opacity: 0.4;
  animation: drift3 22s ease-in-out infinite;
}
@keyframes drift1 {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(9vw, 7vh) scale(1.12); }
}
@keyframes drift2 {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(-8vw, -6vh) scale(1.16); }
}
@keyframes drift3 {
  0%, 100% { transform: translate(-50%, 0) scale(1); }
  50% { transform: translate(-42%, -8vh) scale(1.1); }
}
:root[data-theme="light"] .aurora .blob {
  opacity: 0.28;
}

/* Animated network background (Vanta.js) — a moving layer above the aurora glow
   but below the hero orb. Transparent WebGL background lets the aurora show through. */
#vanta-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none; /* purely ambient — never intercept clicks */
}
#vanta-bg canvas {
  opacity: 0.9;
}
:root[data-theme="light"] #vanta-bg canvas {
  opacity: 0.7;
}

/* Interactive 3D hero orb (Three.js) sits above the aurora */
#hero-canvas {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
  opacity: 0.5; /* keep the orb a subtle background accent so hero text stays legible */
}

/* vignette to frame the scene */
#view-landing::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 45%, rgba(7, 11, 22, 0.6) 100%);
}
:root[data-theme="light"] #view-landing::after {
  background: radial-gradient(ellipse at center, transparent 50%, rgba(247, 249, 253, 0.6) 100%);
}
:root[data-theme="light"] #view-landing::after {
  background: radial-gradient(ellipse at center, transparent 45%, rgba(247, 249, 253, 0.6) 100%);
}

.nav-min {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 28px;
  max-width: 1120px;
  width: 100%;
  margin: 0 auto;
}
.nav-min-actions {
  display: flex;
  align-items: center;
  gap: 20px;
}

.hero-min {
  position: relative;
  z-index: 3;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 0 24px 8vh;
  animation: fadeUp 0.9s cubic-bezier(0.22, 1, 0.36, 1);
}
.hero-min::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 0;
  background: radial-gradient(ellipse 48% 40% at center, rgba(7, 11, 22, 0.62), transparent 72%);
}
:root[data-theme="light"] .hero-min::before {
  background: radial-gradient(ellipse 48% 40% at center, rgba(247, 249, 253, 0.7), transparent 72%);
}
.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 14px;
  color: var(--muted);
  background: color-mix(in srgb, var(--panel) 55%, transparent);
  backdrop-filter: blur(6px);
  margin-bottom: 26px;
}
.hero-min-title {
  font-size: clamp(46px, 9vw, 92px);
  line-height: 1.02;
  letter-spacing: -0.035em;
  font-weight: 800;
  margin: 0 0 22px;
}
.hero-min-sub {
  font-size: clamp(17px, 2.4vw, 21px);
  color: var(--muted);
  max-width: 540px;
  margin: 0 0 36px;
}
.hero-min-cta {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: center;
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: none; }
}

/* ============================================================
   AUTH
   ============================================================ */
.auth-wrap {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 100vh;
}
.auth-aside {
  background: linear-gradient(160deg, #1d4ed8, #0ea5e9 90%);
  color: #fff;
  padding: 48px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
}
.auth-aside::after {
  content: "";
  position: absolute;
  width: 460px;
  height: 460px;
  right: -160px;
  bottom: -160px;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(255, 255, 255, 0.22), transparent 70%);
}
.logo.light .logo-mark {
  background: rgba(255, 255, 255, 0.16);
  backdrop-filter: blur(4px);
}
.auth-aside-body {
  position: relative;
  max-width: 380px;
}
.auth-aside-body h2 {
  font-size: 34px;
  line-height: 1.15;
  letter-spacing: -0.02em;
  margin: 0 0 12px;
}
.auth-aside-body > p {
  font-size: 17px;
  color: rgba(255, 255, 255, 0.85);
  margin: 0 0 26px;
}
.auth-benefits {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  font-size: 15.5px;
  color: rgba(255, 255, 255, 0.92);
}
.auth-aside-foot {
  position: relative;
  color: rgba(255, 255, 255, 0.7);
  font-size: 14px;
}
.auth-panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 40px 24px;
  position: relative;
}
.auth-back {
  position: absolute;
  top: 24px;
  left: 24px;
  color: var(--muted);
  font-size: 14px;
}
.auth-back:hover {
  color: var(--text);
}
.auth-card {
  width: 100%;
  max-width: 400px;
}
.auth-card h1 {
  font-size: 28px;
  letter-spacing: -0.02em;
  margin: 0 0 6px;
}
.auth-lead {
  color: var(--muted);
  margin: 0 0 26px;
}
.auth-form {
  display: flex;
  flex-direction: column;
  gap: 15px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
  color: var(--muted);
  font-weight: 500;
}
.field input {
  font: inherit;
  font-size: 15px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.18);
}
.auth-error {
  color: var(--danger);
  font-size: 13.5px;
  min-height: 6px;
}
.auth-divider {
  text-align: center;
  color: var(--faint);
  font-size: 13px;
  margin: 20px 0 14px;
  position: relative;
}
.auth-divider::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--border-soft);
}
.auth-divider span {
  position: relative;
  background: var(--bg);
  padding: 0 12px;
}
.auth-switch {
  text-align: center;
  color: var(--muted);
  font-size: 14.5px;
  margin: 22px 0 0;
}
.auth-switch a {
  color: var(--brand-2);
  font-weight: 600;
  cursor: pointer;
}
.auth-switch a:hover {
  text-decoration: underline;
}
.forgot-row {
  display: flex;
  justify-content: flex-end;
  margin-top: -6px;
}

/* ============================================================
   APP / DASHBOARD
   ============================================================ */
#view-app {
  grid-template-columns: 300px 1fr;
  height: 100vh;
  height: 100dvh;
  grid-template-rows: 100vh;
  grid-template-rows: 100dvh;
  overflow: hidden; /* each pane scrolls internally; the page itself never scrolls */
}
.app-sidebar {
  position: relative;
  min-height: 0;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 14px;
  overflow-y: auto;
}
.app-brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 4px 6px;
}
.app-brand .logo {
  cursor: default;
}
.app-brand .sidebar-close {
  display: none;
}
.new-chat {
  padding: 11px;
}
.history-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.history-label {
  font-family: var(--mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--faint);
  padding: 4px 4px 6px;
  font-weight: 600;
}
.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.history-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14px;
  color: var(--muted);
  border: 1px solid transparent;
  transition: background 0.15s, color 0.15s;
}
.history-item:hover {
  background: var(--panel);
  color: var(--text);
}
.history-item.active {
  background: var(--grad-soft);
  color: var(--text);
  border-color: var(--border);
}
.history-item .hi-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.hi-actions {
  display: flex;
  align-items: center;
  gap: 1px;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.12s;
}
.history-item:hover .hi-actions,
.history-item.active .hi-actions {
  opacity: 1;
}
.hi-btn {
  border: none;
  background: none;
  color: var(--faint);
  cursor: pointer;
  font-size: 12.5px;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  transition: color 0.12s, background 0.12s;
}
.hi-btn:hover {
  background: color-mix(in srgb, var(--text) 10%, transparent);
  color: var(--text);
}
.hi-del:hover {
  color: var(--danger) !important;
}
.hi-edit {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--brand);
  border-radius: 7px;
  padding: 3px 7px;
  outline: none;
}
.history-empty {
  color: var(--faint);
  font-size: 13px;
  padding: 4px 10px;
}
.history-item .hi-doc {
  display: inline-flex;
  align-items: center;
  color: var(--faint);
  flex-shrink: 0;
}
.app-docs {
  margin-top: 6px;
  border-top: 1px solid var(--border-soft);
  padding-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 9px;
}
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.link-btn {
  background: none;
  border: none;
  color: var(--brand-2);
  font-size: 12px;
  cursor: pointer;
  padding: 0;
}
.link-btn:hover {
  text-decoration: underline;
}
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
  padding: 16px 12px;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-sm);
  color: var(--faint);
  cursor: pointer;
  font-size: 12.5px;
  line-height: 1.45;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover,
.dropzone.dragover {
  border-color: var(--brand);
  background: var(--grad-soft);
  color: var(--text);
}
.dropzone-icon {
  font-size: 18px;
}
.upload-status {
  font-size: 12px;
  min-height: 14px;
  color: var(--muted);
  word-break: break-word;
}
.upload-status.ok { color: var(--good); }
.upload-status.err { color: var(--danger); }
.doc-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.doc-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  padding: 7px 9px;
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: 9px;
}
.doc-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.doc-count {
  color: var(--faint);
  font-variant-numeric: tabular-nums;
}
.doc-del {
  border: none;
  background: none;
  color: var(--faint);
  cursor: pointer;
  opacity: 0;
  font-size: 12px;
}
.doc-list li:hover .doc-del { opacity: 1; }
.doc-del:hover { color: var(--danger); }
.app-user {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.app-user:hover,
.app-user.open {
  border-color: var(--brand);
  background: var(--grad-soft);
}
.avatar-sm {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  flex-shrink: 0;
}
.user-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}
.user-name {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-email {
  font-size: 12px;
  color: var(--faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.profile-caret {
  color: var(--faint);
  font-size: 14px;
  flex-shrink: 0;
}
.profile-menu {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 70px;
  z-index: 70;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  animation: modalIn 0.16s ease;
}
.profile-menu[hidden] {
  display: none;
}
.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border: none;
  background: none;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  text-align: left;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.13s;
}
.menu-item:hover {
  background: var(--grad-soft);
}
.menu-item.danger {
  color: var(--danger);
}
.menu-ic {
  width: 18px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}
.menu-item.danger .menu-ic {
  color: var(--danger);
}
.menu-sep {
  height: 1px;
  background: var(--border-soft);
  margin: 4px 2px;
}
.icon-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  width: 34px;
  height: 34px;
  border-radius: 9px;
  cursor: pointer;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s, background 0.15s;
  flex-shrink: 0;
}
.icon-btn:hover {
  border-color: var(--brand);
  background: var(--grad-soft);
}

.app-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg);
}
.app-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 30px;
  min-height: 58px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg-2) 60%, transparent);
  backdrop-filter: blur(8px);
}
.topbar-title {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* Desktop sidebar collapse: hidden until the sidebar is collapsed. */
.sidebar-expand {
  display: none;
}
.brand-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}
.app-brand .sidebar-collapse {
  display: inline-flex;
}
.topbar-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex-shrink: 0;
  font-size: 12.5px;
  color: var(--muted);
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel);
}
.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 30px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.app-empty {
  margin: auto;
  text-align: center;
  max-width: 460px;
  color: var(--muted);
}
.app-empty .ae-mark {
  width: 60px;
  height: 60px;
  margin: 0 auto 18px;
  display: grid;
  place-items: center;
  filter: drop-shadow(0 12px 30px rgba(37, 99, 235, 0.4));
}
.app-empty .ae-mark .mark-ic {
  width: 60px;
  height: 60px;
}
.app-empty h3 {
  color: var(--text);
  margin: 0 0 8px;
  font-size: 22px;
}
.app-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 20px;
}
.chip {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13.5px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}
.chip:hover {
  border-color: var(--brand);
  background: var(--grad-soft);
  transform: translateY(-1px);
}
.msg {
  display: flex;
  gap: 13px;
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
  animation: rise 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}
.msg.user {
  flex-direction: row-reverse;
}
.avatar {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  font-size: 15px;
  font-weight: 700;
}
.msg.assistant .avatar {
  background: none;
  padding: 0;
}
.avatar .mark-ic {
  width: 100%;
  height: 100%;
}
.msg.user .avatar {
  background: var(--panel-2);
  border: 1px solid var(--border);
}
.bubble {
  position: relative;
  background: var(--assistant-bubble);
  border: 1px solid var(--border);
  padding: 15px 17px;
  border-radius: var(--radius);
  line-height: 1.65;
  overflow-wrap: anywhere;
  box-shadow: var(--shadow-sm);
  flex: 1;
}
.msg.user .bubble {
  background: var(--user-bubble);
  white-space: pre-wrap;
  flex: 0 1 auto;
}
.msg.assistant .bubble {
  padding-right: 40px;
}
.copy-btn {
  position: absolute;
  top: 9px;
  right: 9px;
  width: 26px;
  height: 26px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--faint);
  border-radius: 7px;
  cursor: pointer;
  font-size: 13px;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s, border-color 0.15s;
}
.msg.assistant:hover .copy-btn { opacity: 1; }
.copy-btn:hover { color: var(--brand); border-color: var(--brand); }
.bubble p { margin: 0 0 10px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble h4, .bubble h5, .bubble h6 { margin: 14px 0 8px; line-height: 1.3; }
.bubble h4 { font-size: 15px; }
.bubble ul, .bubble ol { margin: 8px 0; padding-left: 22px; }
.bubble li { margin: 4px 0; }
.bubble code {
  background: var(--panel-2);
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  padding: 1px 6px;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.88em;
}
.bubble pre.code {
  background: var(--panel-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  overflow-x: auto;
  margin: 10px 0;
}
.bubble pre.code code { background: none; border: none; padding: 0; }
.cite {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  margin: 0 1px;
  font-size: 11px;
  font-weight: 700;
  vertical-align: super;
  color: #fff;
  background: var(--accent);
  border-radius: 5px;
  cursor: pointer;
  line-height: 1;
  transition: transform 0.1s, filter 0.15s;
}
.cite:hover { transform: translateY(-1px); filter: brightness(1.1); }
.cursor {
  display: inline-block;
  width: 7px;
  height: 15px;
  background: var(--brand);
  margin-left: 2px;
  border-radius: 1px;
  animation: blink 1s steps(2) infinite;
  vertical-align: text-bottom;
}
@keyframes blink { 50% { opacity: 0; } }
.typing { display: inline-flex; gap: 5px; padding: 3px 0; }
.typing span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--faint); animation: bounce 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: 0.18s; }
.typing span:nth-child(3) { animation-delay: 0.36s; }
@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }
  40% { transform: translateY(-5px); opacity: 1; }
}
.thinking {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: 14px;
}
.spinner {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  border: 2px solid color-mix(in srgb, var(--brand) 28%, transparent);
  border-top-color: var(--brand);
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}
.thinking-label {
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: 0.55; } }
.msg-error {
  color: var(--danger);
  font-size: 14px;
}
.citations {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.citations-title {
  font-family: var(--mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--faint);
  font-weight: 600;
}
.citation {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  font-size: 12.5px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-soft);
  background: var(--panel-2);
}
.citation .cnum {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  color: #fff;
  background: var(--accent);
  border-radius: 5px;
  font-weight: 700;
  font-size: 11px;
}
.cbody { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.csrc { color: var(--text); font-weight: 600; }
.cmeta { color: var(--faint); font-size: 11px; font-family: var(--mono); }
.csnippet { color: var(--muted); line-height: 1.5; }
.cscore { margin-left: auto; flex-shrink: 0; color: var(--faint); font-variant-numeric: tabular-nums; }
.citation.flash { animation: flash 1.1s ease; }
@keyframes flash {
  0%, 100% { background: var(--panel-2); border-color: var(--border-soft); }
  25% { background: var(--grad-soft); border-color: var(--brand); }
}
.composer-wrap {
  width: 100%;
  max-width: 880px;
  margin: 0 auto;
  padding: 4px 30px 0;
}
.attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 0 2px;
}
.attachments[hidden] {
  display: none;
}
.chip-file {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  max-width: 240px;
  padding: 5px 8px 5px 11px;
  font-size: 12.5px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
}
.cf-ic {
  flex-shrink: 0;
}
.cf-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cf-del {
  border: none;
  background: none;
  color: var(--faint);
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  padding: 2px;
}
.cf-del:hover {
  color: var(--danger);
}
.upload-status[hidden] {
  display: none;
}
.attach-btn {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: color 0.15s, background 0.15s;
}
.attach-btn:hover {
  color: var(--brand);
  background: var(--grad-soft);
}
.app-main.dragging {
  outline: 2px dashed var(--brand);
  outline-offset: -8px;
}
/* Unified input bar: attach + textarea + send share one rounded container. */
.composer {
  display: flex;
  gap: 6px;
  padding: 7px 7px 7px 8px;
  align-items: flex-end;
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.composer:focus-within {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.16);
}
.composer textarea {
  flex: 1;
  resize: none;
  background: none;
  border: none;
  color: var(--text);
  padding: 9px 4px;
  font: inherit;
  font-size: 14.5px;
  line-height: 1.5;
  max-height: 170px;
  outline: none;
}
#send-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 11px;
  cursor: pointer;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  transition: background 0.15s, transform 0.1s;
}
#send-btn:hover { background: var(--accent-2); }
#send-btn:active { transform: scale(0.95); }
#send-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.composer-hint {
  text-align: center;
  color: var(--faint);
  font-size: 12px;
  padding: 6px 0 18px;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* Scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--faint); }

/* Mobile menu + sidebar scrim */
.mobile-menu {
  display: none;
}
.sidebar-scrim {
  position: fixed;
  inset: 0;
  z-index: 55;
  background: rgba(6, 10, 20, 0.5);
  backdrop-filter: blur(2px);
}
.sidebar-scrim[hidden] {
  display: none;
}

/* ---------- Responsive ---------- */
@media (min-width: 821px) {
  .sidebar-scrim { display: none !important; }
  /* Collapsed sidebar: hide the pane, reveal the expand button in the top bar. */
  #view-app.collapsed { grid-template-columns: 1fr; }
  #view-app.collapsed .app-sidebar { display: none; }
  #view-app.collapsed .sidebar-expand { display: inline-flex; }
}
@media (max-width: 900px) {
  .auth-wrap { grid-template-columns: 1fr; }
  .auth-aside { display: none; }
}
@media (max-width: 820px) {
  #view-app { grid-template-columns: 1fr; }
  .app-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(86vw, 300px);
    z-index: 60;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }
  .app-sidebar.open { transform: none; box-shadow: var(--shadow); }
  .mobile-menu { display: inline-flex; }
  .app-brand .sidebar-close { display: inline-flex; }
  .app-brand .sidebar-collapse { display: none; }
  .app-topbar { padding: 12px 18px; }
  .messages { padding: 22px 16px; }
  .composer-wrap { padding: 4px 16px 0; }
  .topbar-status { display: none; }
}
@media (max-width: 480px) {
  .modal-card { padding: 24px 20px; border-radius: 18px; }
  .modal-overlay { padding: 12px; }
  .hero-min-title { font-size: clamp(38px, 13vw, 60px); }
  .nav-min { padding: 18px 18px; }
}

/* ============================================================
   AUTH POPUP (centered, blurred backdrop)
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(6, 10, 20, 0.55);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  animation: overlayIn 0.2s ease;
}
:root[data-theme="light"] .modal-overlay {
  background: rgba(20, 32, 58, 0.25);
}
.modal-overlay[hidden] {
  display: none;
}
.modal-card {
  position: relative;
  width: 100%;
  max-width: 400px;
  max-height: calc(100vh - 40px);
  max-height: calc(100dvh - 40px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: var(--shadow);
  animation: modalIn 0.26s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes overlayIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(14px) scale(0.97); }
  to { opacity: 1; transform: none; }
}
.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.modal-close:hover {
  color: var(--text);
  border-color: var(--brand);
}
.modal-brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  margin-bottom: 16px;
}
.modal-title {
  font-size: 23px;
  letter-spacing: -0.02em;
  margin: 0 0 5px;
}
.modal-sub {
  color: var(--muted);
  font-size: 14.5px;
  margin: 0 0 22px;
}
.oauth-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.btn-oauth {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  font-weight: 600;
  padding: 12px 16px;
}
.btn-oauth:hover {
  border-color: var(--brand);
  background: var(--grad-soft);
  transform: translateY(-1px);
}
.modal-card .field input {
  background: var(--panel-2);
}
.modal-card .auth-divider span {
  background: var(--panel);
}

/* ---------- Email verification step ---------- */
.code-lead {
  color: var(--muted);
  font-size: 14px;
  margin: 0 0 6px;
}
.code-lead strong {
  color: var(--text);
}
.demo-code {
  font-size: 13px;
  color: var(--text);
  background: var(--grad-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  line-height: 1.45;
}
.demo-code[hidden] {
  display: none;
}
.code-input {
  letter-spacing: 0.4em;
  text-align: center;
  font-size: 20px !important;
  font-weight: 700;
}
.link-inline {
  border: none;
  background: none;
  color: var(--brand-2);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}
.link-inline:hover {
  text-decoration: underline;
}

/* ---------- Manage account popup ---------- */
.account-head {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 20px;
}
.avatar-lg {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  font-size: 24px;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}
.modal-title.tight {
  margin: 0;
  font-size: 19px;
}
.modal-sub.tight {
  margin: 2px 0 6px;
  font-size: 13.5px;
}
.plan-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--brand-2);
  background: var(--grad-soft);
  border: 1px solid var(--border);
  padding: 3px 9px;
  border-radius: 999px;
}
.field input:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.account-saved {
  color: var(--good);
  font-size: 13px;
}
.account-saved[hidden] {
  display: none;
}

/* ---------- Settings popup ---------- */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 15px 0;
  border-top: 1px solid var(--border-soft);
}
.setting-row:first-of-type {
  border-top: none;
}
.setting-title {
  font-weight: 600;
  font-size: 14.5px;
}
.setting-sub {
  color: var(--muted);
  font-size: 12.5px;
  margin-top: 2px;
}
.seg {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
  background: var(--panel-2);
  flex-shrink: 0;
}
.seg button {
  border: none;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.seg button.active {
  background: var(--accent);
  color: #fff;
}
.pill-tag {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  flex-shrink: 0;
}
.btn-danger {
  background: color-mix(in srgb, var(--danger) 14%, transparent);
  color: var(--danger);
  border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  flex-shrink: 0;
}
.btn-danger:hover {
  background: color-mix(in srgb, var(--danger) 22%, transparent);
}
.danger-row .setting-title {
  color: var(--danger);
}

/* ---------- Dashboard polish ---------- */
.app-brand {
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-soft);
}
.new-chat {
  gap: 7px;
  font-weight: 600;
}
.new-chat .plus {
  font-size: 17px;
  line-height: 1;
}
.history-item {
  position: relative;
}
.history-item.active {
  box-shadow: inset 2px 0 0 var(--brand);
}
.history-label {
  margin-top: 2px;
}
/* Keep the active/hover state readable while renaming. */
.history-item.renaming {
  background: var(--panel);
  border-color: var(--border);
}
.app-topbar .icon-btn {
  flex-shrink: 0;
}
.messages {
  scroll-behavior: smooth;
}
.composer-hint {
  padding-top: 8px;
}
