:root {
  --bg-base: #07111f;
  --bg-surface: #0d1d32;
  --bg-elevated: #132843;
  --bg-hover: #19385d;
  --bg-input: #0a1828;
  --border: #24496f;
  --border-subtle: #1b3955;
  --text-primary: #e7f1ff;
  --text-secondary: #9bb5d3;
  --text-muted: #617d9b;
  --accent-blue: #38bdf8;
  --accent-blue-dim: #0284c7;
  --accent-green: #22c55e;
  --accent-orange: #f59e0b;
  --accent-red: #ef4444;
  --user-bubble-bg: #0b6aa6;
  --bot-bubble-bg: #10233a;
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 14px;
  --radius-xl: 18px;

  /* Typography */
  --text-heading: #c8e8ff;
  --sidebar-w: 300px;
  --topbar-h: 68px;
  --font-sans: 'Inter', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  --transition: 0.2s ease;

  /* Accent variants */
  --accent-blue-light: #7dd3fc;
  --accent-blue-ghost: rgba(56, 189, 248, 0.08);
  --accent-blue-tint: rgba(56, 189, 248, 0.14);
  --accent-blue-border: rgba(56, 189, 248, 0.22);

  /* Semantic surface tokens */
  --surface-topbar: rgba(13, 29, 50, 0.92);
  --surface-input-area: rgba(13, 29, 50, 0.95);

  /* Shadow scale */
  --shadow-sm: 0 1px 4px rgba(0,0,0,0.18), 0 2px 8px rgba(0,0,0,0.10);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.28), 0 2px 6px rgba(0,0,0,0.14);
  --shadow-glow: 0 0 0 3px rgba(56, 189, 248, 0.15);

  /* Easing */
  --ease-out: cubic-bezier(0.4, 0, 0.2, 1);

  /* Focus ring */
  --ring-focus: 0 0 0 3px rgba(56, 189, 248, 0.18);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
  font-family: var(--font-sans);
  background:
    radial-gradient(circle at top left, rgba(56, 189, 248, 0.18), transparent 32rem),
    linear-gradient(135deg, #07111f 0%, #0c182a 100%);
  color: var(--text-primary);
  overflow: hidden;
}

body {
  display: flex;
  height: 100vh;
}

body.auth-active .sidebar,
body.auth-active .main {
  visibility: hidden;
  pointer-events: none;
}

.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: grid;
  place-items: center;
  padding: 32px;
  background: #04111d;
  overflow: hidden;
  isolation: isolate;
}

.auth-screen::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(ellipse at 18% 22%, rgba(56, 189, 248, 0.28), transparent 26rem),
    radial-gradient(ellipse at 82% 78%, rgba(14, 165, 233, 0.22), transparent 30rem),
    linear-gradient(180deg, #0a3157 0%, #0a2440 34%, #07172a 68%, #030915 100%);
}

.auth-screen::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    linear-gradient(108deg, transparent 0%, rgba(186, 230, 253, 0.08) 46%, transparent 52%),
    repeating-linear-gradient(172deg, transparent 0 32px, rgba(147, 197, 253, 0.05) 33px 34px, transparent 35px 68px);
  mix-blend-mode: screen;
  opacity: 0.7;
  animation: waterSheen 16s ease-in-out infinite alternate;
}

@keyframes waterSheen {
  from { transform: translate3d(-2%, -1%, 0) scale(1.02); }
  to { transform: translate3d(2%, 1.5%, 0) scale(1.06); }
}

.auth-particles {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  opacity: 0.82;
  pointer-events: none;
}

.auth-grid {
  position: relative;
  z-index: 2;
  width: min(1080px, 100%);
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(340px, 420px);
  gap: 34px;
  align-items: center;
}

.auth-hero {
  padding: 30px;
  animation: fadeInUp 0.35s cubic-bezier(0.4, 0, 0.2, 1) both;
}

.auth-brand-lockup {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-bottom: 30px;
}

.brand-mark {
  display: block;
  overflow: visible;
  flex-shrink: 0;
  filter: drop-shadow(0 18px 36px rgba(56, 189, 248, 0.28));
}

.brand-mark__frame {
  fill: #0a3f66;
  stroke: rgba(186, 230, 253, 0.36);
  stroke-width: 2;
}

.brand-mark__drop {
  fill: #f4fbff;
}

.brand-mark__current {
  fill: none;
  stroke: var(--accent-blue);
  stroke-width: 2.8;
  stroke-linecap: round;
}

.brand-mark__current--back {
  stroke: rgba(56, 189, 248, 0.45);
  stroke-width: 8;
}


.brand-mark--large {
  width: 72px;
  height: 72px;
}

.brand-mark--small {
  width: 36px;
  height: 36px;
  filter: drop-shadow(0 8px 18px rgba(56, 189, 248, 0.22));
}

.auth-brand-lines {
  display: grid;
  gap: 4px;
}

.auth-brand-lines span:first-child {
  color: #f4f9ff;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.16em;
}

.auth-brand-lines span:last-child {
  color: #9ac4ef;
  font-size: 12px;
  letter-spacing: 0.04em;
}

.auth-kicker {
  color: #bae6fd;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  margin-bottom: 12px;
}

.auth-hero h1 {
  font-size: 72px;
  line-height: 0.96;
  letter-spacing: -0.03em;
  font-weight: 800;
  margin-bottom: 22px;
  background: linear-gradient(160deg, #f0f8ff 0%, #93c5fd 60%, var(--accent-blue-light) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.auth-lead {
  max-width: 640px;
  color: #bfd4ec;
  font-size: 17px;
  line-height: 1.75;
}

.auth-feature-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 28px;
}

.auth-feature-row span {
  padding: 7px 14px;
  border: 1px solid var(--accent-blue-border);
  border-radius: 999px;
  color: #bae6fd;
  background: var(--accent-blue-ghost);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: background var(--transition), border-color var(--transition);
}

.auth-feature-row span:hover {
  background: var(--accent-blue-tint);
  border-color: rgba(56, 189, 248, 0.40);
}

.auth-card {
  padding: 30px;
  border: 1px solid rgba(56, 189, 248, 0.22);
  border-radius: 18px;
  background: rgba(11, 24, 42, 0.55);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.42);
  animation: fadeInUp 0.35s cubic-bezier(0.4, 0, 0.2, 1) 0.1s both;
  position: relative;
}

.auth-card::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(circle at 50% 0%, rgba(56, 189, 248, 0.11), transparent 60%);
  pointer-events: none;
}

.auth-card-header {
  margin-bottom: 22px;
}

.auth-card-eyebrow {
  color: var(--accent-blue-light);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.auth-card h2 {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-heading);
  margin: 8px 0 8px;
}

.auth-card p {
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.6;
}

.auth-label {
  display: block;
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 7px;
}

.auth-submit,
.auth-register {
  flex: 1;
  padding: 11px 14px;
  font-size: 13px;
}

.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: rgba(13, 29, 50, 0.96);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1),
              width    0.28s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 100;
}

.sidebar.collapsed {
  transform: translateX(calc(-1 * var(--sidebar-w)));
  width: 0;
  min-width: 0;
}

.sidebar-header {
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--border-subtle);
  background: linear-gradient(160deg, rgba(56, 189, 248, 0.07) 0%, transparent 65%);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-title {
  display: block;
  font-weight: 700;
  font-size: 15px;
  color: var(--text-heading);
  line-height: 1;
  letter-spacing: -0.01em;
}

.logo-sub {
  display: block;
  font-size: 11px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 2px;
}

.session-panel,
.auth-panel,
.user-panel,
.chat-list-panel,
.upload-panel {
  padding: 16px;
}

.upload-panel {
  flex: 1;
}

.panel-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 8px;
}

.session-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

.auth-input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 9px 10px;
  font-family: var(--font-sans);
  font-size: 13px;
  margin-bottom: 8px;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.auth-input:focus {
  outline: none;
  border-color: var(--accent-blue);
  box-shadow: var(--shadow-glow);
}

.auth-input::placeholder {
  color: var(--text-muted);
}

.auth-actions {
  display: flex;
  gap: 8px;
}

.auth-error {
  color: #fca5a5;
  font-size: 12px;
  font-weight: 500;
  margin-top: 8px;
  min-height: 16px;
}

.user-name {
  font-size: 13px;
  color: var(--text-primary);
  margin-bottom: 6px;
  word-break: break-all;
}

.user-role {
  display: inline-flex;
  width: fit-content;
  color: #05243b;
  background: var(--accent-blue-light);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 10px;
}

.admin-launch-btn {
  width: 100%;
  margin-bottom: 8px;
}

/* ── Modal base ─────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
}

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 10, 24, 0.68);
  backdrop-filter: blur(8px);
}

.modal__dialog {
  position: relative;
  z-index: 1;
  width: min(460px, calc(100vw - 32px));
  margin: 12vh auto 0;
  border: 1px solid rgba(186, 230, 253, 0.18);
  border-radius: 22px;
  background: linear-gradient(180deg, rgba(11, 24, 42, 0.99), rgba(9, 18, 32, 0.99));
  box-shadow: 0 24px 72px rgba(0, 0, 0, 0.44);
  overflow: hidden;
}

.modal__header,
.modal__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px;
}

.modal__header {
  border-bottom: 1px solid var(--border-subtle);
}

.modal__header h3 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-heading);
  margin-top: 6px;
}

.modal__body {
  padding: 18px 20px 6px;
}

.modal__footer {
  justify-content: flex-end;
  border-top: 1px solid var(--border-subtle);
}

/* ── Modal z-index variants ──────────────────────────────── */
.rename-modal { z-index: 2400; }
.delete-modal  { z-index: 2450; }
.admin-modal   { z-index: 2500; }

/* ── delete-modal: unique body layout and danger target ─── */
.delete-modal__body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: 18px;
}

.delete-modal__body p {
  margin: 0;
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.6;
}

.delete-modal__target {
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid rgba(239, 68, 68, 0.22);
  background: rgba(127, 29, 29, 0.16);
  color: #fee2e2;
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-danger-solid {
  background: var(--accent-red);
  color: #fff;
}

.btn-danger-solid:hover:not(:disabled) {
  background: #f87171;
}

/* ── admin-modal: wide dialog variant ───────────────────── */
.admin-modal .modal__backdrop {
  background: rgba(4, 10, 24, 0.72);
}

.modal__dialog--lg {
  width: min(1120px, calc(100vw - 40px));
  max-height: calc(100vh - 48px);
  margin: 24px auto;
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(11, 24, 42, 0.98), rgba(9, 18, 32, 0.98));
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.48);
  display: flex;
  flex-direction: column;
}

.modal__header--lg {
  gap: 16px;
  padding: 22px 24px 18px;
}

.modal__header--lg h3 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-heading);
}

.admin-close-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.admin-close-btn:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.admin-grid {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 18px;
  padding: 20px 24px 24px;
  overflow: auto;
}

.admin-create-card,
.admin-users-card {
  border: 1px solid var(--border-subtle);
  background: rgba(16, 35, 58, 0.72);
  border-radius: 18px;
  padding: 18px;
}

.admin-section-title {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-heading);
  margin-bottom: 14px;
}

.admin-select {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 9px 10px;
  font-family: var(--font-sans);
  font-size: 13px;
  margin-bottom: 12px;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.admin-select:focus {
  outline: none;
  border-color: var(--accent-blue);
  box-shadow: var(--shadow-glow);
}

.admin-create-submit {
  width: 100%;
}

.admin-users-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.admin-users-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.admin-user-card {
  border: 1px solid var(--border);
  background: rgba(7, 17, 31, 0.86);
  border-radius: 16px;
  padding: 14px;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.admin-user-card:hover {
  border-color: rgba(56, 189, 248, 0.30);
  box-shadow: var(--shadow-sm);
}

.admin-user-card__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.admin-user-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
}

.admin-user-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

.admin-user-state {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 4px 8px;
  border-radius: 999px;
}

.admin-user-state--active {
  color: #05251f;
  background: #86efac;
}

.admin-user-state--disabled {
  color: #fee2e2;
  background: rgba(239, 68, 68, 0.16);
}

.admin-user-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.admin-field-label {
  display: block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.admin-user-empty {
  border: 1px dashed var(--border);
  border-radius: 16px;
  padding: 20px;
  color: var(--text-muted);
  text-align: center;
  font-size: 13px;
}

.session-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.session-list-item {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 8px;
  transition: border-color var(--transition), background var(--transition);
  overflow: hidden;
}

.session-list-item:hover {
  border-color: var(--accent-blue);
  background: var(--accent-blue-ghost);
}

.session-list-item.active {
  border-color: var(--accent-blue);
  background: var(--accent-blue-ghost);
  box-shadow: inset 3px 0 0 var(--accent-blue);
}

.session-list-item.active .session-list-title {
  color: var(--text-heading);
}

.session-list-card {
  min-width: 0;
}

.session-list-main {
  width: 100%;
  min-width: 0;
  text-align: left;
  background: transparent;
  border: 0;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0;
  transition: color var(--transition);
}

.session-list-main:hover {
  color: var(--text-primary);
}

.session-list-title {
  display: block;
  font-size: 12px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-list-meta {
  display: block;
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  margin-top: 3px;
}

.session-list-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 8px;
}

.session-list-actions {
  display: inline-flex;
  gap: 6px;
  flex-shrink: 0;
}

.session-action-btn {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
  background: rgba(16, 35, 58, 0.84);
  color: var(--text-muted);
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition), background var(--transition);
}

.session-action-btn:hover {
  color: var(--text-primary);
  border-color: rgba(125, 211, 252, 0.26);
  background: var(--accent-blue-ghost);
}

.session-action-btn--danger:hover {
  color: #fecaca;
  border-color: rgba(239, 68, 68, 0.28);
  background: rgba(127, 29, 29, 0.24);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot-gray { background: var(--text-muted); }
.dot-yellow { background: var(--accent-orange); animation: pulse 1.5s infinite; }
.dot-green { background: var(--accent-green); }
.dot-red { background: var(--accent-red); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

.drop-zone {
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-md);
  padding: 20px 12px;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.drop-zone:hover,
.drop-zone.dragover {
  border-color: var(--accent-blue);
  background: var(--accent-blue-ghost);
  color: var(--text-primary);
}

.drop-zone-hint {
  font-size: 11px;
  color: var(--text-muted);
}

.file-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
  max-height: 160px;
  overflow-y: auto;
}

.file-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--text-secondary);
}

.file-item-body {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.file-item--indexing {
  border: 1px solid rgba(56, 189, 248, 0.35);
}

.file-item--queued {
  border: 1px solid rgba(251, 191, 36, 0.35);
}

.file-item--done {
  border: 1px solid rgba(34, 197, 94, 0.35);
}

.file-item--error {
  border: 1px solid rgba(239, 68, 68, 0.35);
}

.file-spin,
.thinking-spinner,
.progress-spinner {
  border-radius: 50%;
  border-style: solid;
  border-color: rgba(56, 189, 248, 0.25);
  border-top-color: var(--accent-blue);
  animation: spin 0.8s linear infinite;
}

.file-spin {
  width: 14px;
  height: 14px;
  border-width: 2px;
  flex-shrink: 0;
}

.file-item-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-item-name--indexing {
  color: var(--accent-blue-light);
  font-style: italic;
}

.file-item-meta {
  font-size: 10px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0 4px;
  transition: color var(--transition);
}

.file-remove:hover {
  color: var(--accent-red);
}

.docs-counter {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 8px;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border-subtle);
  margin-top: auto;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  cursor: pointer;
  font-family: var(--font-sans);
  font-weight: 500;
  border-radius: var(--radius-sm);
  transition: background var(--transition), opacity var(--transition), transform var(--transition), box-shadow var(--transition);
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent-blue);
  color: #05243b;
  font-size: 13px;
  padding: 9px 14px;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-blue-light);
}

.btn-primary:active:not(:disabled) {
  transform: scale(0.97);
}

.btn-primary:focus-visible {
  outline: none;
  box-shadow: var(--ring-focus);
}

.btn-ghost:focus-visible {
  outline: none;
  box-shadow: var(--ring-focus);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  padding: 6px 10px;
  border: 1px solid var(--border);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn-danger:hover:not(:disabled) {
  border-color: var(--accent-red);
  color: var(--accent-red) !important;
}

.btn-sm {
  font-size: 11px;
  padding: 5px 8px;
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-width: 0;
  overflow: hidden;
}

.topbar {
  height: var(--topbar-h);
  min-height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-topbar);
}

.sidebar-toggle {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  transition: background var(--transition), color var(--transition);
}

.sidebar-toggle:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.topbar-title {
  flex: 1;
  font-weight: 600;
  font-size: 14px;
  color: var(--text-secondary);
  letter-spacing: 0.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-logos {
  display: flex;
  align-items: center;
  padding-left: 16px;
}

.topbar-logos img {
  height: 48px;
  width: auto;
  object-fit: contain;
}

.topbar-badges {
  display: flex;
  gap: 6px;
}

.badge {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  padding: 3px 8px;
  border-radius: 20px;
  text-transform: uppercase;
}

.badge-blue {
  background: rgba(56, 189, 248, 0.16);
  color: #7dd3fc;
  border: 1px solid rgba(56, 189, 248, 0.3);
}

.badge-green {
  background: rgba(34, 197, 94, 0.14);
  color: #86efac;
  border: 1px solid rgba(34, 197, 94, 0.3);
}

#ragView {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px;
  scroll-behavior: smooth;
  position: relative;
}

.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 60px 20px;
  max-width: 660px;
  margin: 0 auto;
}

.welcome-icon {
  margin-bottom: 20px;
  filter: drop-shadow(0 8px 24px rgba(56, 189, 248, 0.22));
}

.welcome h2 {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-heading);
  margin-bottom: 10px;
}

.welcome p {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 28px;
}

.welcome-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.chip {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 12px;
  font-family: var(--font-sans);
  padding: 8px 14px;
  border-radius: 20px;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}

.chip:hover {
  border-color: var(--accent-blue);
  color: var(--text-primary);
  background: var(--accent-blue-ghost);
}

.welcome-chips .chip {
  animation: fadeInUp 0.25s ease both;
}
.welcome-chips .chip:nth-child(1) { animation-delay: 0.06s; }
.welcome-chips .chip:nth-child(2) { animation-delay: 0.14s; }
.welcome-chips .chip:nth-child(3) { animation-delay: 0.22s; }

.messages {
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-width: 860px;
  margin: 0 auto;
  width: 100%;
}

.message {
  display: flex;
  gap: 0;
  animation: fadeInUp 0.25s ease;
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.message.assistant {
  align-items: flex-start;
}

.message.user {
  flex-direction: row-reverse;
  align-items: flex-start;
}

.message-avatar {
  display: none;
}

.message-body {
  flex: 1;
  min-width: 0;
}

.message.user .message-body {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.message-bubble {
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  font-size: 14px;
  line-height: 1.65;
  max-width: 100%;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.message.user .message-bubble {
  background: linear-gradient(135deg, #0d79be 0%, var(--user-bubble-bg) 100%);
  color: #fff;
  border-bottom-right-radius: var(--radius-sm);
  max-width: 72%;
}

.message.assistant .message-bubble {
  background: linear-gradient(158deg, rgba(16, 35, 58, 0.95) 0%, var(--bot-bubble-bg) 100%);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  border-bottom-left-radius: var(--radius-sm);
}

.message-bubble--streaming {
  white-space: pre-wrap;
}

.message-bubble h1,
.message-bubble h2,
.message-bubble h3 {
  margin: 16px 0 8px;
  font-weight: 600;
  padding: 0;
  text-indent: 0;
  line-height: 1.35;
}

.message-bubble h1 { font-size: 18px; }
.message-bubble h2 {
  font-size: 16px;
}
.message-bubble h3 {
  font-size: 14px;
  color: #bfd7ef;
}
.message-bubble p {
  margin: 6px 0;
}

.message-bubble p.message-standalone-strong {
  margin: 14px 0 8px;
  font-weight: 700;
  color: var(--text-primary);
}

.message-bubble p:empty {
  display: none;
}

.message-bubble ul,
.message-bubble ol {
  padding-left: 24px;
  margin: 8px 0;
  text-indent: 0;
  list-style-position: outside;
}

.message-bubble ol {
  list-style-type: decimal;
}

.message-bubble ul {
  list-style-type: disc;
}

.message-bubble ul ul,
.message-bubble ol ul {
  list-style-type: circle;
}

.message-bubble ul ul ul,
.message-bubble ol ul ul {
  list-style-type: square;
}

.message-bubble ol ol {
  list-style-type: lower-alpha;
}

.message-bubble ol ol ol {
  list-style-type: lower-roman;
}

.message-bubble ul ul,
.message-bubble ul ol,
.message-bubble ol ul,
.message-bubble ol ol {
  margin-top: 6px;
  margin-bottom: 4px;
  padding-left: 22px;
}

.message-bubble li {
  margin: 5px 0;
  padding-left: 0;
  line-height: 1.6;
}

.message-bubble li > ul,
.message-bubble li > ol {
  margin-left: 2px;
}

/* Tables inside message bubbles */
.message-bubble .table-container {
  overflow-x: auto;
  margin: 10px 0;
}
.message-bubble table {
  display: table;
  width: 100%;
  max-width: 100%;
  border-collapse: collapse;
  table-layout: auto;
}
.message.assistant .message-bubble .table-container table,
.message.user .message-bubble .table-container table {
  border: 1px solid rgba(255,255,255,0.14) !important;
  border-radius: 8px;
  overflow: hidden;
}
.message-bubble thead th {
  background: rgba(255,255,255,0.10) !important;
  color: var(--text-primary) !important;
  font-weight: 700 !important;
  padding: 10px 12px !important;
}
.message-bubble th,
.message-bubble td {
  border: 1px solid rgba(255,255,255,0.14) !important;
  padding: 8px 10px !important;
  text-align: left !important;
  vertical-align: middle !important;
  font-size: 13px !important;
  color: var(--text-primary) !important;
}
.message-bubble tbody tr:nth-child(even) td {
  background: rgba(255,255,255,0.03) !important;
}

/* Images (SVG) inside message bubbles: responsive and limited height */
.message-bubble img {
  display: block;
  max-width: 100% !important;
  height: auto !important;
  max-height: 60vh !important;
  object-fit: contain;
  margin: 8px 0;
  border-radius: 8px;
}

.message-bubble > :first-child {
  margin-top: 0;
}

.message-bubble > :last-child {
  margin-bottom: 0;
}

.message-bubble code {
  font-family: var(--font-mono);
  font-size: 12px;
  background: rgba(255, 255, 255, 0.08);
  padding: 1px 5px;
  border-radius: 4px;
}

.message-bubble pre {
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent-blue-dim);
  border-radius: var(--radius-sm);
  padding: 13px 14px 13px 16px;
  overflow-x: auto;
  margin: 10px 0;
}

.message-bubble pre code {
  background: none;
  padding: 0;
  font-size: 12.5px;
}

.thinking-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--bot-bubble-bg);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  border-bottom-left-radius: var(--radius-sm);
  width: fit-content;
}

.thinking-spinner {
  width: 16px;
  height: 16px;
  border-width: 2px;
  flex-shrink: 0;
}

.thinking-text {
  font-size: 13px;
  color: var(--accent-blue-light);
  font-style: italic;
  opacity: 0.78;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.sources-panel {
  margin-top: 8px;
  padding: 10px 14px;
  background: rgba(56, 189, 248, 0.05);
  border: 1px solid rgba(56, 189, 248, 0.14);
  border-radius: var(--radius-md);
}

.sources-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent-blue-light);
  opacity: 0.7;
  margin-bottom: 8px;
}

.sources-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.source-card {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent-blue);
  border-radius: var(--radius-sm);
  font-size: 12px;
  transition: box-shadow var(--transition), transform var(--transition), border-color var(--transition);
}

.source-card:hover {
  border-color: rgba(56, 189, 248, 0.40);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

.source-card__name {
  color: var(--text-primary);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 240px;
}

.source-badge {
  font-size: 10px;
  font-weight: 600;
  font-family: var(--font-mono);
  color: var(--accent-blue);
  background: rgba(56, 189, 248, 0.12);
  padding: 1px 6px;
  border-radius: 10px;
  white-space: nowrap;
}

.message-time {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  margin-top: 4px;
  padding: 0 4px;
}

.tts-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
  transition: color var(--transition), background var(--transition), transform var(--transition);
}

.tts-btn:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.06);
}

.tts-btn.playing {
  color: var(--accent-blue-light);
  background: var(--accent-blue-tint);
}

.tts-btn:active {
  transform: scale(0.96);
}

.input-area {
  padding: 12px 20px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface-input-area);
}

.input-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-input);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 10px 10px 10px 16px;
  transition: border-color var(--transition), box-shadow var(--transition);
  max-width: 860px;
  margin: 0 auto;
}

.input-wrapper:focus-within {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.15);
}

.query-textarea {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  resize: none;
  max-height: 160px;
  overflow-y: auto;
  padding: 2px 0;
}

.query-textarea::placeholder {
  color: var(--text-muted);
}

.stt-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 8px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  flex-shrink: 0;
  transition: background var(--transition), color var(--transition);
}

.stt-btn:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.stt-btn.recording {
  color: var(--accent-red) !important;
  animation: pulse 1.2s infinite;
}

.send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent-blue);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #05243b;
  flex-shrink: 0;
  transition: background var(--transition), transform var(--transition);
}

.send-btn:hover:not(:disabled) {
  background: var(--accent-blue-light);
  transform: scale(1.05);
}

.send-btn.send-btn--cancel {
  background: #f59e0b;
  color: #1f1300;
}

.send-btn.send-btn--cancel:hover:not(:disabled) {
  background: #fbbf24;
}

.send-btn.send-btn--cancel svg {
  stroke: #1f1300;
}

.send-btn:disabled {
  background: var(--text-muted);
  cursor: not-allowed;
}

.send-btn svg {
  stroke: #05243b;
}

.input-hint {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
}

.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
}

.toast {
  padding: 12px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 13px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
  animation: slideIn 0.3s ease;
  min-width: 240px;
  max-width: 360px;
}

.toast.success { border-left: 3px solid var(--accent-green); }
.toast.error { border-left: 3px solid var(--accent-red); }
.toast.info { border-left: 3px solid var(--accent-blue); }

@keyframes slideIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes slideOut {
  from { opacity: 1; transform: translateX(0); }
  to   { opacity: 0; transform: translateX(20px); }
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95) translateY(-6px); }
  to   { opacity: 1; transform: scale(1)    translateY(0); }
}

.modal[style*="display: block"] .modal__dialog {
  animation: modalIn 0.22s cubic-bezier(0.4, 0, 0.2, 1) both;
}

.toast--leaving {
  animation: slideOut 0.28s ease forwards;
}

.progress-overlay {
  position: fixed;
  inset: 0;
  background: rgba(7, 17, 31, 0.72);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
}

.progress-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 36px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
}

.progress-spinner {
  width: 36px;
  height: 36px;
  border-width: 3px;
}

.progress-text {
  font-size: 14px;
  color: var(--text-secondary);
}

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(56, 189, 248, 0.35);
}

/* ── Identity strip ─────────────────────────────────────── */
.sidebar-identity {
  padding: 10px 14px 12px;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.identity-row {
  display: flex;
  align-items: center;
  gap: 9px;
}

.identity-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent-blue-tint);
  border: 1px solid var(--accent-blue-border);
  color: var(--accent-blue-light);
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  text-transform: uppercase;
  flex-shrink: 0;
  letter-spacing: 0.02em;
  user-select: none;
}

.identity-info {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 7px;
  overflow: hidden;
}

.identity-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex-shrink: 1;
  min-width: 0;
}

.identity-info .user-role {
  margin-bottom: 0;
  flex-shrink: 0;
}

.identity-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.btn-icon {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  padding: 0;
}

.btn-icon:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border-subtle);
}

.btn-icon--danger:hover {
  color: #fca5a5;
  background: rgba(127, 29, 29, 0.18);
  border-color: rgba(239, 68, 68, 0.24);
}

/* ── Sessions section ────────────────────────────────────── */
.sidebar-sessions {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 140px;
  overflow: hidden;
  border-bottom: 1px solid var(--border-subtle);
}

.sessions-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px 8px;
  flex-shrink: 0;
}

.sessions-header .panel-label {
  flex: 1;
  margin-bottom: 0;
}

.sessions-status {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.btn-icon-round {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  padding: 0;
}

.btn-icon-round:hover {
  border-color: var(--accent-blue);
  color: var(--accent-blue);
  background: var(--accent-blue-ghost);
}

.session-list-container {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 2px 10px 10px;
}

/* ── Documents section ────────────────────────────────────── */
.sidebar-docs {
  flex-shrink: 0;
  padding: 12px 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.docs-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.docs-header .panel-label {
  margin-bottom: 0;
}

.docs-status {
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: right;
  flex-shrink: 0;
  max-width: 130px;
}

.sidebar-docs .file-list {
  margin-bottom: 0;
}

/* Drop zone compact state — when documents are present */
.drop-zone--compact {
  flex-direction: row;
  padding: 7px 12px;
  gap: 8px;
  justify-content: flex-start;
  text-align: left;
}

.drop-zone--compact svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.drop-zone--compact .drop-zone-hint {
  display: none;
}

.drop-zone--compact span:not(.drop-zone-hint) {
  font-size: 12px;
}

/* ── Mobile sidebar backdrop ────────────────────────────── */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(4, 10, 24, 0.62);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  z-index: 99;
}

@media (max-width: 768px) {
  .sidebar-backdrop.active {
    display: block;
  }
}

@media (max-width: 768px) {
  .auth-screen {
    padding: 18px;
    overflow-y: auto;
  }

  .auth-grid {
    grid-template-columns: 1fr;
    gap: 18px;
  }

  .auth-hero {
    padding: 12px 4px;
  }

  .auth-brand-lockup {
    margin-bottom: 20px;
  }

  .brand-mark--large {
    width: 58px;
    height: 58px;
  }

  .auth-hero h1 {
    font-size: 42px;
    line-height: 1;
    letter-spacing: -0.02em;
  }

  .auth-lead {
    font-size: 14px;
  }

  .auth-card {
    padding: 22px;
    border-radius: 16px;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    transform: translateX(calc(-1 * var(--sidebar-w)));
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.5);
  }

  .main {
    width: 100%;
  }

  .topbar-badges {
    display: none;
  }

  .message.user .message-bubble {
    max-width: 88%;
  }

  .modal__dialog--lg {
    width: calc(100vw - 20px);
    margin: 10px auto;
    max-height: calc(100vh - 20px);
  }

  .admin-grid {
    grid-template-columns: 1fr;
    padding: 14px;
  }

  .admin-user-controls {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  .auth-hero,
  .auth-card,
  .welcome-chips .chip,
  .message,
  .auth-screen::after {
    animation: none;
  }

  .modal[style*="display: block"] .modal__dialog {
    animation: none;
  }

  .toast {
    animation: none;
  }

  .toast--leaving {
    animation: none;
  }

  .sidebar,
  .input-wrapper,
  .chip,
  .admin-close-btn,
  .sidebar-toggle,
  .auth-input,
  .admin-select,
  .source-card,
  .admin-user-card,
  .session-list-main,
  .file-remove,
  .stt-btn,
  .btn,
  .btn-icon,
  .btn-icon-round,
  .auth-feature-row span {
    transition: none;
  }
}
