/* ============================================================
   Saqqar — Unified design system
   Inspired by Saqqar AID (Digital Harbor)
   Glass cards · ambient gradients · cyan/purple/navy accents
   Theme switch: html[data-theme="dark"|"light"] (also .dark/.light)
   ============================================================ */

/* ---------- Design tokens ---------- */
:root,
html[data-theme="dark"],
html.dark {
  color-scheme: dark;

  /* Surfaces */
  --bg: #030712;
  --surface: #111827;
  --surface-1: #111827;
  --surface-2: #1E293B;
  --surface-3: #0F172A;
  --space-black: #020409;

  /* Card / glass */
  --card-bg: rgba(17, 24, 39, 0.70);
  --card-border: rgba(30, 41, 59, 0.80);
  --nav-bg: rgba(17, 24, 39, 0.80);
  --input-bg: #1E293B;
  --hover-bg: rgba(255, 255, 255, 0.05);

  /* Text */
  --text: #F8FAFC;
  --spectral: #F8FAFC;
  --spectral-dim: #94A3B8;
  --spectral-dimmer: rgba(248, 250, 252, 0.55);
  --spectral-faint: rgba(248, 250, 252, 0.30);
  --muted: #94A3B8;

  /* Brand */
  --brand-cyan: #06B6D4;
  --brand-cyan-soft: rgba(6, 182, 212, 0.18);
  --brand-cyan-strong: #22D3EE;
  --brand-purple: #8B5CF6;
  --brand-purple-soft: rgba(139, 92, 246, 0.18);
  --brand-navy: #1F3C88;
  --brand-primary: #1F3C88;
  --brand-primary-strong: #122466;
  --brand-secondary: #06B6D4;
  --brand-accent: #22D3EE;
  --brand-gradient: linear-gradient(135deg, #1F3C88 0%, #06B6D4 100%);
  --brand-gradient-vivid: linear-gradient(135deg, #06B6D4 0%, #8B5CF6 100%);

  /* Status */
  --success: #10B981;
  --success-soft: rgba(16, 185, 129, 0.12);
  --success-border: rgba(16, 185, 129, 0.30);
  --warning: #F59E0B;
  --warning-soft: rgba(245, 158, 11, 0.12);
  --danger: #EF4444;
  --danger-bg: rgba(239, 68, 68, 0.10);
  --danger-border: rgba(239, 68, 68, 0.30);

  /* Lines / dividers */
  --border: #1E293B;
  --hairline: rgba(148, 163, 184, 0.10);
  --hairline-strong: rgba(148, 163, 184, 0.22);
  --ghost-bg: rgba(255, 255, 255, 0.04);
  --ghost-bg-hover: rgba(255, 255, 255, 0.08);
  --ghost-border: rgba(148, 163, 184, 0.18);

  /* Overlays / shadows */
  --overlay: rgba(2, 6, 23, 0.72);
  --shadow-pop: 0 10px 30px rgba(6, 182, 212, 0.18);
  --shadow-card: 0 22px 60px rgba(2, 6, 23, 0.55);
  --scrollbar-thumb: rgba(6, 182, 212, 0.30);

  /* Type */
  --font-display: 'Inter', 'Tajawal', system-ui, -apple-system, sans-serif;
  --font-text: 'Inter', 'Tajawal', system-ui, -apple-system, sans-serif;
  --font-display-ar: 'Tajawal', 'Inter', system-ui, sans-serif;
  --font-text-ar: 'Tajawal', 'Inter', system-ui, sans-serif;
  --track-display: 0.02em;
  --track-nav: 0.06em;
  --track-micro: 0.10em;

  /* Geometry */
  --nav-height: 72px;
  --radius-button: 12px;
  --radius-card: 20px;
}

html[data-theme="light"],
html.light {
  color-scheme: light;

  --bg: #F8FAFC;
  --surface: #FFFFFF;
  --surface-1: #FFFFFF;
  --surface-2: #F1F5F9;
  --surface-3: #E2E8F0;
  --space-black: #E2E8F0;

  --card-bg: rgba(255, 255, 255, 0.85);
  --card-border: rgba(226, 232, 240, 0.95);
  --nav-bg: rgba(255, 255, 255, 0.88);
  --input-bg: #F1F5F9;
  --hover-bg: rgba(15, 23, 42, 0.04);

  --text: #0F172A;
  --spectral: #0F172A;
  --spectral-dim: #64748B;
  --spectral-dimmer: rgba(15, 23, 42, 0.55);
  --spectral-faint: rgba(15, 23, 42, 0.28);
  --muted: #64748B;

  --brand-cyan-soft: rgba(6, 182, 212, 0.14);
  --brand-purple-soft: rgba(139, 92, 246, 0.14);

  --border: #E2E8F0;
  --hairline: rgba(15, 23, 42, 0.08);
  --hairline-strong: rgba(15, 23, 42, 0.16);
  --ghost-bg: rgba(15, 23, 42, 0.04);
  --ghost-bg-hover: rgba(15, 23, 42, 0.08);
  --ghost-border: rgba(15, 23, 42, 0.10);

  --overlay: rgba(15, 23, 42, 0.40);
  --shadow-pop: 0 10px 30px rgba(31, 60, 136, 0.12);
  --shadow-card: 0 22px 60px rgba(15, 23, 42, 0.10);
  --scrollbar-thumb: rgba(6, 182, 212, 0.28);
}

/* ---------- Reset / base ---------- */
*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-text);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background 0.3s ease, color 0.3s ease;
}

html[lang="ar"] body,
[dir="rtl"] body { font-family: var(--font-text-ar); }

a { color: var(--brand-cyan); text-decoration: none; transition: color 0.15s ease; }
a:hover { color: var(--brand-purple); }

button { font-family: inherit; cursor: pointer; }

h1, h2, h3, h4, h5, h6 { margin: 0; font-family: var(--font-display); letter-spacing: var(--track-display); font-weight: 700; }

p { margin: 0; }

/* ---------- Ambient background ---------- */
.ambient-bg,
body {
  background:
    radial-gradient(ellipse at 18% 20%, rgba(6, 182, 212, 0.08) 0%, transparent 70%),
    radial-gradient(ellipse at 82% 12%, rgba(139, 92, 246, 0.06) 0%, transparent 70%),
    radial-gradient(ellipse at 50% 100%, rgba(59, 130, 246, 0.05) 0%, transparent 70%),
    var(--bg);
  background-attachment: fixed;
  background-repeat: no-repeat;
  background-size: cover;
}
html[data-theme="light"] body,
html.light body {
  background:
    radial-gradient(ellipse at 18% 20%, rgba(6, 182, 212, 0.05) 0%, transparent 70%),
    radial-gradient(ellipse at 82% 12%, rgba(139, 92, 246, 0.04) 0%, transparent 70%),
    radial-gradient(ellipse at 50% 100%, rgba(59, 130, 246, 0.03) 0%, transparent 70%),
    var(--bg);
  background-attachment: fixed;
  background-repeat: no-repeat;
  background-size: cover;
}

/* ---------- Scrollbars ---------- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: rgba(6, 182, 212, 0.55); }
* { scrollbar-width: thin; scrollbar-color: var(--scrollbar-thumb) transparent; }

/* ---------- Utility text ---------- */
.muted-line { color: var(--muted); font-size: 13px; line-height: 1.5; margin: 0; }
.eyebrow {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: var(--track-micro);
  color: var(--brand-cyan);
  margin: 0 0 4px;
}
.gradient-text {
  background: var(--brand-gradient-vivid);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
}
.hidden { display: none !important; }
.mobile-only { display: none !important; }
@media (max-width: 1024px) {
  .desktop-only { display: none !important; }
  .mobile-only { display: inline-flex !important; }
}

/* ---------- Global navigation ---------- */
.global-nav {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 24px;
  background: var(--nav-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.nav-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  flex-shrink: 0;
}
.nav-logo { height: 48.4px; width: auto; object-fit: contain; }
html[data-theme="dark"] .nav-logo-light,
html.dark .nav-logo-light { display: none; }
html[data-theme="light"] .nav-logo-dark,
html.light .nav-logo-dark { display: none; }
html, body { transition: background-color 200ms ease, color 200ms ease; }

.nav-spacer { flex: 1; }

/* Tabs / primary navigation */
.nav-tabs {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin-left: 18px;
  padding: 4px;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.nav-tab {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  padding: 6px 14px;
  border-radius: 8px;
  text-decoration: none;
  transition: color 0.15s, background 0.15s;
  white-space: nowrap;
}
.nav-tab:hover { color: var(--text); background: var(--hover-bg); }
.nav-tab-active {
  color: #FFFFFF;
  background: var(--brand-gradient);
  box-shadow: 0 4px 12px rgba(6,182,212,0.20);
}
.nav-tab-active:hover { color: #FFFFFF; background: var(--brand-gradient); filter: brightness(1.05); }

/* Right-side actions cluster */
.nav-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* Legacy nav-link kept for shared.html "Shared transcript" pill */
.nav-link {
  font-size: 13px;
  color: var(--muted);
  padding: 6px 12px;
  border-radius: 10px;
  transition: color 0.15s ease, background 0.15s ease;
  font-weight: 500;
}
.nav-link:hover { color: var(--brand-cyan); background: var(--hover-bg); }
a.nav-link { text-decoration: none; }

.nav-logout-form { display: inline-flex; align-items: center; gap: 8px; margin: 0; }

.nav-logout {
  font-size: 12px;
  padding: 6px 12px;
}

/* User menu dropdown (uses native <details>) */
.user-menu {
  position: relative;
}
.user-menu summary { list-style: none; cursor: pointer; }
.user-menu summary::-webkit-details-marker { display: none; }

.user-menu-trigger {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  padding: 3px 12px 3px 3px;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(255,255,255,0.06), rgba(255,255,255,0.02)), var(--surface);
  border: 1px solid rgba(6,182,212,0.38);
  box-shadow: 0 10px 26px rgba(15,23,42,0.10);
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s, transform 0.15s;
  user-select: none;
}
.user-menu-trigger:hover,
.user-menu[open] .user-menu-trigger {
  border-color: rgba(6,182,212,0.70);
  background: linear-gradient(180deg, rgba(255,255,255,0.08), rgba(255,255,255,0.03)), var(--surface);
  box-shadow: 0 14px 30px rgba(6,182,212,0.12);
}
.user-menu-trigger:focus-visible {
  outline: none;
  border-color: rgba(6,182,212,0.82);
  box-shadow: 0 0 0 4px rgba(6,182,212,0.14);
}

.user-menu-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--brand-gradient-vivid);
  color: #FFFFFF;
  font-size: 13px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  letter-spacing: 0;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.16);
}
.user-menu-name {
  font-size: 14px;
  font-weight: 650;
  color: var(--text);
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-menu-caret {
  font-size: 11px;
  color: var(--muted);
  transition: transform 0.15s ease;
}
.user-menu[open] .user-menu-caret { transform: rotate(180deg); }

.user-menu-panel {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  min-width: 242px;
  max-width: min(320px, calc(100vw - 16px));
  background: var(--surface-1, var(--card-bg));
  border: 1px solid var(--card-border);
  border-radius: 18px;
  box-shadow: 0 24px 56px rgba(15,23,42,0.18);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  z-index: 60;
  animation: menu-in 0.15s ease-out;
}
@keyframes menu-in {
  from { opacity: 0; transform: translateY(-6px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
[dir="rtl"] .user-menu-panel { right: auto; left: 0; }

.user-menu-head {
  padding: 10px 12px 11px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2px;
}
.user-menu-username {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-menu-role {
  font-size: 12px;
  color: var(--muted);
  margin: 3px 0 0;
}

.user-menu-form { margin: 0; }
.user-menu-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0 2px;
}
.user-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: start;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  padding: 10px 12px;
  font-size: 14px;
  font-weight: 500;
  border-radius: 10px;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  font-family: inherit;
}
.user-menu-item:hover {
  background: var(--hover-bg);
  border-color: rgba(6,182,212,0.14);
  color: var(--text);
}
.user-menu-item-active {
  background: linear-gradient(135deg, rgba(6,182,212,0.13), rgba(139,92,246,0.08));
  border-color: rgba(6,182,212,0.24);
  color: var(--text);
}
.user-menu-item-danger { color: var(--danger); }
.user-menu-item-danger:hover { background: var(--danger-bg); color: var(--danger); }

/* Theme toggle */
.theme-toggle {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.theme-toggle:hover { color: var(--brand-cyan); border-color: var(--brand-cyan); background: var(--hover-bg); }
.theme-icon { display: none; line-height: 1; }
html[data-theme="dark"] .theme-icon-sun,
html.dark .theme-icon-sun { display: inline; color: #F59E0B; }
html[data-theme="light"] .theme-icon-moon,
html.light .theme-icon-moon { display: inline; color: var(--brand-purple); }

/* Language toggle */
.lang-toggle {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  height: 36px;
  min-width: 36px;
  padding: 0 12px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.lang-toggle:hover { color: var(--brand-cyan); border-color: var(--brand-cyan); }
.lang-flag { display: none; }
html:not([data-active-lang="ar"]):not([lang="ar"]) .lang-flag-ar { display: inline; }
html[data-active-lang="ar"] .lang-flag-en,
html[lang="ar"] .lang-flag-en { display: inline; }

/* Auto-approve pill — sits in the composer toolbar */
.auto-approve-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--ghost-bg);
  border: 1px solid var(--ghost-border);
  transition: background 0.2s ease, border-color 0.2s ease;
}
.auto-approve-toggle input { display: none; }
.auto-approve-track {
  width: 28px;
  height: 16px;
  border-radius: 999px;
  background: var(--surface-3);
  position: relative;
  transition: background 0.2s ease;
  flex-shrink: 0;
}
.auto-approve-thumb {
  position: absolute;
  top: 2px;
  inset-inline-start: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--text);
  transition: transform 0.2s ease, background 0.2s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.auto-approve-toggle:has(input:checked) {
  background: var(--success-soft);
  border-color: var(--success-border);
}
.auto-approve-toggle:has(input:checked) .auto-approve-label { color: #6EE7B7; }
.auto-approve-toggle input:checked + .auto-approve-track { background: rgb(27, 80, 148); }
.auto-approve-toggle input:checked + .auto-approve-track .auto-approve-thumb { transform: translateX(12px); background: #fff; }
.auto-approve-label { font-size: 12px; font-weight: 600; color: var(--text); transition: color 0.2s ease; }

/* Active credential dropdown in the chat header */
.active-credential-select {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 4px 10px 4px 12px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  transition: border-color 0.15s, background 0.15s;
}
.active-credential-select:hover {
  border-color: rgba(6, 182, 212, 0.35);
}
.active-credential-select:focus-within {
  border-color: rgba(6, 182, 212, 0.55);
  box-shadow: 0 0 0 3px rgba(6, 182, 212, 0.18);
}
.active-credential-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: var(--track-micro);
  color: var(--muted);
  white-space: nowrap;
}
.active-credential-select select {
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  background: transparent;
  border: 0;
  outline: none;
  padding: 4px 4px 4px 0;
  max-width: 220px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    calc(100% - 14px) center,
    calc(100% - 9px) center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-inline-end: 22px;
}
.active-credential-select select:disabled {
  color: var(--muted);
  cursor: not-allowed;
  opacity: 0.6;
}
.active-credential-select option {
  background: var(--surface);
  color: var(--text);
}
[dir="rtl"] .active-credential-select select {
  background-position:
    14px center,
    9px center;
  padding-inline-end: 22px;
  padding-inline-start: 0;
}
@media (max-width: 720px) {
  .active-credential-select .active-credential-label { display: none; }
  .active-credential-select select { max-width: 160px; }
}

/* ---------- App shell layout ---------- */
.app-shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr) 320px;
  padding: 10px;
  height: 100vh;
  min-height: 0;
  overflow: hidden;
}

@media (min-width: 1025px) {
  /* Chat page locks the viewport; standalone pages scroll naturally. */
  body.chat-page { overflow: hidden; }
}

@media (max-width: 1280px) {
  .app-shell { grid-template-columns: 280px minmax(0, 1fr) 280px; padding: 10px; }
}

@media (max-width: 1024px) {
  body.chat-page { overflow: auto; }
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-areas: "main" "sidebar" "rail";
    height: auto;
    overflow: visible;
  }
  .chat-stage { grid-area: main; min-height: 70vh; }
  .sidebar { grid-area: sidebar; }
  .action-rail { grid-area: rail; }
}

/* ---------- Sidebar ---------- */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
  min-width: 0;
}

.brand-block { display: flex; flex-direction: column; gap: 8px; min-width: 0; }

/* Logo at the top of the left sidebar (replaces the global-nav header on the chat page) */
.sidebar-brand {
  display: inline-flex;
  align-items: center;
  padding: 2px 4px 6px;
  text-decoration: none;
  flex-shrink: 0;
}
.sidebar-brand .nav-logo { height: 36px; }

/* Theme / language / user-menu cluster sits at the top of the right rail */
.rail-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
  min-height: 36px;
}

/* ---------- Action rail ---------- */
.action-rail {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 0;
  min-height: 0;
  min-width: 0;
}

/* ---------- Rail cards (Phase 2 — editorial right rail) ---------- */
.rail-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-inline-start: 2px solid transparent;
  border-radius: 16px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: fit-content;
  min-width: 0;
  transition: border-color 0.2s ease;
}
.rail-card[data-empty="0"].rail-card-approvals { border-inline-start-color: var(--warning); }
.rail-card[data-empty="0"].rail-card-actions { border-inline-start-color: var(--brand-cyan); }
.rail-card[data-empty="0"].rail-card-artifacts { border-inline-start-color: var(--brand-purple); }

.rail-head {
  display: flex;
  align-items: center;
  gap: 10px;
}
.rail-head-icon {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--spectral-dim);
  background: var(--ghost-bg);
  flex-shrink: 0;
}
.rail-card-approvals[data-empty="0"] .rail-head-icon { color: var(--warning); background: var(--warning-soft); }
.rail-card-actions[data-empty="0"] .rail-head-icon { color: var(--brand-cyan); background: var(--brand-cyan-soft); }
.rail-card-artifacts[data-empty="0"] .rail-head-icon { color: var(--brand-purple); background: var(--brand-purple-soft); }
.rail-head h2 {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: var(--track-nav);
  color: var(--text);
  margin: 0;
  flex: 1;
  min-width: 0;
}
.rail-count {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 2px 8px;
  border-radius: 999px;
  color: var(--spectral-dim);
  background: var(--ghost-bg);
  border: 1px solid var(--ghost-border);
  min-width: 20px;
  text-align: center;
}
.rail-card-approvals[data-empty="0"] .rail-count { color: var(--warning); background: var(--warning-soft); border-color: var(--warning-border); }
.rail-card-actions[data-empty="0"] .rail-count { color: var(--brand-cyan); background: var(--brand-cyan-soft); border-color: rgba(6,182,212,0.30); }
.rail-card-artifacts[data-empty="0"] .rail-count { color: var(--brand-purple); background: var(--brand-purple-soft); border-color: rgba(139,92,246,0.30); }
.rail-card[data-empty="1"] .rail-count { display: none; }

.rail-body {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

/* Empty state inside a rail card */
.rail-empty {
  font-size: 12px;
  color: var(--spectral-dim);
  line-height: 1.5;
  padding: 4px 0 2px;
}

.rail-show-all {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--hairline);
  text-decoration: none;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: var(--track-micro);
  text-transform: uppercase;
  color: var(--brand-cyan);
  background: transparent;
  border-left: 0;
  border-right: 0;
  border-bottom: 0;
  cursor: pointer;
}
.rail-show-all:hover { color: var(--brand-cyan-strong); }

/* Approval row */
.approval-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  border-radius: 10px;
  background: rgba(245,158,11,0.05);
  border: 1px solid var(--warning-border);
}
.approval-row + .approval-row { margin-top: 8px; }
.approval-row-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: var(--track-micro);
  color: var(--warning);
}
.approval-row-body {
  font-size: 13px;
  color: var(--text);
  margin: 0;
  line-height: 1.45;
  word-break: break-word;
}
.approval-row-meta {
  font-size: 11px;
  color: var(--spectral-dim);
  margin: 0;
}
.approval-row-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 4px;
}
.approval-approve,
.approval-reject,
.approval-batch {
  flex: 1 1 auto;
  min-width: max-content;
  white-space: nowrap;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  line-height: 1.2;
}
.approval-approve {
  background: var(--brand-gradient);
  color: #fff;
  border: 0;
  box-shadow: 0 4px 14px rgba(6,182,212,0.20);
}
.approval-reject {
  background: var(--danger-bg);
  color: #FCA5A5;
  border: 1px solid var(--danger-border);
}
.approval-batch {
  flex: 1 1 100%;
  background: var(--ghost-bg);
  color: var(--text);
  border: 1px solid var(--ghost-border);
}
.approval-show-individual {
  align-self: flex-start;
  background: transparent;
  border: 0;
  color: var(--brand-cyan);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  padding: 0;
}
.approval-show-individual:hover { color: var(--brand-cyan-strong); }
.approval-individuals { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; padding-top: 10px; border-top: 1px solid var(--hairline); }
.approval-individuals.hidden { display: none; }
.approval-individual-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text);
}
.approval-individual-prompt { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.approval-individual-row .approval-approve,
.approval-individual-row .approval-reject {
  flex: 0 0 auto;
  padding: 4px 10px;
  font-size: 11px;
  box-shadow: none;
}

/* Action row */
.action-row {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px 0;
  border-top: 1px solid var(--hairline);
}
.action-row:first-child { border-top: 0; padding-top: 4px; }
.action-row-icon {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--brand-cyan-soft);
  color: var(--brand-cyan);
  flex-shrink: 0;
}
.action-row-text { min-width: 0; }
.action-row-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.action-row-sub {
  font-size: 11px;
  color: var(--spectral-dim);
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.action-row-btn {
  background: var(--ghost-bg);
  border: 1px solid var(--ghost-border);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.action-row-btn:hover { background: var(--ghost-bg-hover); }

/* Artifact row */
.artifact-row {
  display: grid;
  grid-template-columns: 32px 1fr 18px;
  gap: 10px;
  align-items: center;
  padding: 10px 0;
  border-top: 1px solid var(--hairline);
  text-decoration: none;
  color: inherit;
}
.artifact-row:first-child { border-top: 0; padding-top: 4px; }
.artifact-row-glyph {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--ghost-bg);
  color: var(--spectral-dim);
  flex-shrink: 0;
}
.artifact-row-text { min-width: 0; }
.artifact-row-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.artifact-row-title .artifact-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.artifact-row-meta {
  font-size: 11px;
  color: var(--spectral-dim);
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.artifact-row-chevron {
  color: var(--spectral-dim);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.artifact-row:hover .artifact-row-chevron { color: var(--brand-cyan); }

.kind-badge {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: var(--track-micro);
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 4px;
  flex-shrink: 0;
}
.kind-xlsx { background: rgba(16,185,129,0.14); color: #6EE7B7; border: 1px solid var(--success-border); }
.kind-json { background: var(--brand-cyan-soft); color: var(--brand-cyan-strong); border: 1px solid rgba(6,182,212,0.30); }
.kind-pdf { background: var(--danger-bg); color: #FCA5A5; border: 1px solid var(--danger-border); }
.kind-docx { background: rgba(59,130,246,0.14); color: #93C5FD; border: 1px solid rgba(59,130,246,0.35); }
.kind-html { background: rgba(244,114,182,0.14); color: #F9A8D4; border: 1px solid rgba(244,114,182,0.35); }
.kind-csv { background: var(--brand-purple-soft); color: #C4B5FD; border: 1px solid rgba(139,92,246,0.30); }
.kind-other { background: var(--ghost-bg); color: var(--spectral-dim); border: 1px solid var(--ghost-border); }

/* ---------- Panels (glass cards) ---------- */
.panel {
  background: var(--card-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-card);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  box-shadow: 0 1px 0 rgba(255,255,255,0.02) inset;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
html[data-theme="light"] .panel,
html.light .panel { box-shadow: 0 1px 3px rgba(15,23,42,0.06); }

.panel-fill {
  flex: 1 1 0;
  min-height: 220px;
}
/* Sidebar's secondary panel (Credential Vault) shares the column */
.sidebar > .panel:not(.panel-fill) {
  flex: 1 1 0;
  min-height: 200px;
  max-height: 50vh;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.panel-head h2 {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: var(--track-nav);
  color: var(--muted);
  margin: 0;
}
.panel-head-actions { display: inline-flex; gap: 6px; }

/* ---------- Search bar (sidebar) ---------- */
.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.search-icon {
  position: absolute;
  left: 12px;
  pointer-events: none;
  color: var(--muted);
  font-size: 14px;
}
.search-input {
  width: 100%;
  padding: 10px 36px 10px 34px;
  font-size: 13px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.search-input::placeholder { color: var(--muted); }
.search-input:focus {
  outline: none;
  border-color: var(--brand-cyan);
  box-shadow: 0 0 0 3px rgba(6,182,212,0.18);
}
.search-clear {
  position: absolute;
  right: 8px;
  background: transparent;
  border: 0;
  color: var(--muted);
  width: 22px;
  height: 22px;
  border-radius: 6px;
  cursor: pointer;
}
.search-clear:hover { color: var(--brand-cyan); background: var(--hover-bg); }

/* ---------- Lists shared scroll ---------- */
.conversation-list,
.credential-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 2px;
  min-height: 0;
  min-width: 0;
}
.conversation-list { flex: 1; }

/* ---------- Conversation list ---------- */
.conversation-group { display: flex; flex-direction: column; gap: 4px; margin-top: 4px; }
.conversation-group:first-child { margin-top: 0; }
.conversation-group-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: var(--track-micro);
  color: var(--muted);
  padding: 4px 6px 2px;
}
.archived-group { display: flex; flex-direction: column; gap: 4px; }
.archived-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: 0;
  color: var(--muted);
  padding: 4px 6px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: var(--track-micro);
  cursor: pointer;
}
.archived-toggle:hover { color: var(--brand-cyan); background: var(--hover-bg); }
.archived-chevron { transition: transform 0.15s ease; display: inline-block; }
.archived-toggle[aria-expanded="true"] .archived-chevron { transform: rotate(90deg); }
.archived-count {
  font-size: 10px;
  color: var(--muted);
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.conversation-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 12px;
  padding-right: 36px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  min-width: 100%;
  text-align: inherit;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s;
}
.conversation-card:hover { background: var(--hover-bg); border-color: var(--border); }
.conversation-card.active,
.conversation-card[aria-current="true"] {
  background: linear-gradient(135deg, rgba(6,182,212,0.10), rgba(139,92,246,0.10));
  border-color: rgba(6,182,212,0.35);
}
.conversation-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}
.conversation-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 0;
  flex: 1;
  min-width: 0;
}
.conversation-rename-input {
  flex: 1;
  padding: 4px 6px;
  font-size: 13px;
  border-radius: 6px;
  background: var(--surface-2);
  border: 1px solid var(--brand-cyan);
  color: var(--text);
}
.conversation-rename-input:focus { outline: none; box-shadow: 0 0 0 3px rgba(6,182,212,0.18); }

/* Row dropdown menu */
.row-menu {
  position: absolute;
  z-index: 50;
  min-width: 180px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-card);
  padding: 4px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.row-menu-button {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s, background 0.12s;
}
.conversation-card:hover .row-menu-button,
.row-menu-button[aria-expanded="true"] { opacity: 1; }
.row-menu-button:hover { color: var(--text); background: var(--hover-bg); }
.row-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  color: var(--text);
  padding: 8px 10px;
  font-size: 13px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.row-menu-item:hover { background: var(--hover-bg); color: var(--brand-cyan); }
.row-menu-item.danger { color: var(--danger); }
.row-menu-item.danger:hover { background: var(--danger-bg); color: var(--danger); }

/* ---------- Credentials list ---------- */
.credential-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  transition: border-color 0.15s, background 0.15s;
}
.credential-card:hover { border-color: rgba(6,182,212,0.30); }
.credential-card-disabled { opacity: 0.55; }

.credential-row-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.credential-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 0;
}
.credential-copy {
  font-size: 11px;
  color: var(--muted);
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Credential per-conversation toggle */
.credential-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}
.credential-toggle input { display: none; }
.credential-toggle-track {
  width: 30px;
  height: 16px;
  border-radius: 999px;
  background: var(--surface-3);
  position: relative;
  flex-shrink: 0;
  transition: background 0.2s ease;
}
.credential-toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 0.2s ease, background 0.2s ease;
}
.credential-toggle input:checked + .credential-toggle-track { background: var(--brand-gradient); }
.credential-toggle input:checked + .credential-toggle-track .credential-toggle-thumb { transform: translateX(14px); background: #fff; }
.credential-toggle-state {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: var(--track-micro);
  font-weight: 700;
}

/* Edit / delete icon buttons inside a credential card */
.credential-card-actions {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-inline-start: 8px;
  flex-shrink: 0;
}
.credential-action-button {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  border-radius: 8px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  padding: 0;
}
.credential-action-button:hover {
  color: var(--brand-cyan);
  border-color: rgba(6, 182, 212, 0.30);
  background: var(--brand-cyan-soft);
}
.credential-action-button:focus-visible {
  outline: none;
  border-color: rgba(6, 182, 212, 0.55);
  box-shadow: 0 0 0 3px rgba(6, 182, 212, 0.18);
}
.credential-action-button.danger:hover {
  color: var(--danger);
  border-color: var(--danger-border);
  background: var(--danger-bg);
}
.credential-action-button.danger:focus-visible {
  border-color: rgba(239, 68, 68, 0.55);
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.18);
}
.credential-action-button svg {
  width: 14px;
  height: 14px;
  stroke-width: 1.8;
  display: block;
}

/* Inline credential form (Action Center) */
.inline-credential-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 10px;
  padding: 16px;
  background: linear-gradient(180deg, rgba(6,182,212,0.05), transparent 36%), var(--surface);
  border: 1px solid rgba(6,182,212,0.18);
  border-radius: 16px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04);
}

/* ---------- Empty state ---------- */
.empty-state {
  text-align: center;
  padding: 18px 12px;
  color: var(--muted);
  font-size: 12px;
  background: var(--surface-2);
  border: 1px dashed var(--border);
  border-radius: 12px;
}

/* ---------- Chat stage ---------- */
.chat-stage {
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  margin: 0 15px;
  border: 1px solid #1e293b;
  border-top: 0;
  border-bottom: 0;
}
.chat-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 5px;
  flex: 1;
  min-height: 0;
  height: 100%;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 10px 0;
}
.chat-header-main { flex: 1; min-width: 0; display: flex; align-items: center; }
.chat-header-aside {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-shrink: 0;
  flex-wrap: nowrap;
}
.chat-header h2 {
  font-size: 17px;
  font-weight: 700;
  line-height: 1.2;
  margin: 0;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 0 1 auto;
  min-width: 0;
}
.title-rename-btn {
  flex: 0 0 26px;
  width: 26px;
  height: 26px;
  margin-left: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--spectral-dim);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.title-rename-btn:hover { background: var(--ghost-bg); color: var(--text); }
.title-rename-btn[hidden] { display: none; }
.title-rename-input {
  flex: 1 1 auto;
  min-width: 0;
  font-family: inherit;
  font-size: 17px;
  font-weight: 700;
  line-height: 1.2;
  color: var(--text);
  background: var(--ghost-bg);
  border: 1px solid var(--ghost-border);
  border-radius: 8px;
  padding: 2px 8px;
  outline: none;
}
.title-rename-input:focus {
  border-color: var(--brand-cyan);
  box-shadow: 0 0 0 2px rgba(6,182,212,0.20);
}
.header-divider {
  display: inline-block;
  width: 1px;
  height: 20px;
  background: var(--hairline-strong);
}
.env-badges:empty + .header-divider { display: none; }

/* Chat body */
.chat-body {
  padding: 10px;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.chat-log {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 10px;
}
@media (max-width: 1024px) {
  .chat-log { min-height: 50vh; }
}

/* ---------- Messages ---------- */
/* ---------- Editorial messages (Phase 2) ---------- */
.msg-stack {
  display: flex;
  flex-direction: column;
  gap: 28px;
  width: 100%;
}

.msg {
  display: grid;
  grid-template-columns: 30px 1fr;
  gap: 14px;
  align-items: flex-start;
  min-width: 0;
}

.msg-avatar { display: none; }

/* Single-column grid for both roles. Placement is physical (margin-left/right
   auto on the children of .msg-col), so role positioning ignores both the
   session dir and the per-message dir attribute. */
.msg-agent { grid-template-columns: 1fr; }
.msg-agent .msg-col { grid-column: 1; }
.msg-user { grid-template-columns: 1fr; }
.msg-user .msg-col { grid-column: 1; }

/* Side placement handled by chat-v2.css flex alignment + dir mirroring. */

.msg-col {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.msg-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.msg-role {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.msg-agent .msg-role {
  background-image: linear-gradient(135deg, var(--brand-cyan-strong) 0%, var(--brand-navy) 100%);
  background-clip: text;
  -webkit-background-clip: text;
  color: transparent;
}
.msg-time {
  font-size: 11px;
  color: var(--spectral-dim);
  font-weight: 500;
}
.msg-status {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: var(--track-micro);
  text-transform: uppercase;
  color: var(--brand-cyan);
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--brand-cyan-soft);
  border: 1px solid rgba(6,182,212,0.30);
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.msg-status::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  animation: msg-status-pulse 1.6s ease-in-out infinite;
}
@keyframes msg-status-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

.msg-working-elapsed {
  font-size: 11px;
  font-weight: 500;
  color: var(--spectral-dim);
  font-variant-numeric: tabular-nums;
}

/* Progress bar — only rendered when a report-build tool is in flight.
   For SQL exports we don't know the total upfront, so the bar runs in
   indeterminate-shimmer mode. The wrapper hosts the 6 px bar AND the
   sibling label below it; the bar lives in its own overflow-hidden
   container so the indeterminate slider can't bleed sideways. */
.msg-progress-wrap {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.msg-progress {
  position: relative;
  height: 6px;
  border-radius: 999px;
  background: var(--ghost-bg);
  overflow: hidden;
}
.msg-progress-bar {
  height: 100%;
  background: var(--brand-gradient);
  border-radius: inherit;
  transition: width 0.4s ease;
}
.msg-progress-bar-indeterminate {
  position: absolute;
  inset: 0;
  width: 40% !important;
  animation: msg-progress-slide 1.6s linear infinite;
}
@keyframes msg-progress-slide {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(300%); }
}
.msg-progress-label {
  font-size: 11px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--spectral-dim);
  letter-spacing: 0.02em;
}

.msg-body {
  font-size: 14.5px;
  line-height: 1.65;
  color: var(--text);
  word-wrap: break-word;
  overflow-wrap: anywhere;
  margin-top: 2px;
  width: fit-content;
  max-width: 100%;
}
.msg-agent .msg-body {
  background: none;
  border: 0;
  border-radius: 0;
  padding: 0;
}

.msg-date {
  font-size: 11px;
  color: var(--spectral-dim);
  margin-top: 4px;
}
.msg-body p { margin: 0 0 10px; }
.msg-body p:last-child { margin-bottom: 0; }
.msg-body p[dir] { text-align: start; }
.msg-body img {
  display: block;
  max-width: 100%;
  height: auto;
  max-height: 320px;
  border-radius: 10px;
  margin: 8px 0;
  object-fit: contain;
}
.msg-body code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.88em;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--ghost-bg);
  color: var(--brand-cyan-strong);
}
.msg-body pre {
  background: var(--surface-3);
  border: 0;
  border-radius: 10px;
  padding: 12px 14px;
  margin: 10px 0;
  overflow-x: auto;
  font-size: 12.5px;
}
.msg-body pre code {
  background: transparent;
  color: var(--text);
  padding: 0;
}
.msg-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--hairline);
  font-size: 12.5px;
}
.msg-body th {
  background: var(--surface-2);
  font-weight: 700;
  text-align: left;
  padding: 8px 12px;
  border-bottom: 1px solid var(--hairline);
}
.msg-body td {
  padding: 8px 12px;
  border-top: 1px solid var(--hairline);
}

/* Typing state — preserves monospace caret animation on streaming bodies */
.msg-body.is-typing {
  min-height: 1.6em;
  white-space: pre-wrap;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  letter-spacing: 0.01em;
  text-shadow: 0 0 14px rgba(34,211,238,0.12);
}
.msg-body.is-typing::after {
  content: "";
  display: inline-block;
  width: 8px;
  height: 1.05em;
  margin-inline-start: 4px;
  vertical-align: -0.14em;
  border-radius: 2px;
  background: linear-gradient(180deg, rgba(34,211,238,0.95), rgba(165,243,252,0.95));
  box-shadow: 0 0 18px rgba(34,211,238,0.35);
  animation: assistant-cursor 0.9s steps(1) infinite;
}

/* Working state inline body — dots after the status text */
.msg-working-line { display: inline-flex; align-items: center; gap: 8px; }
.msg-working-dots { display: inline-flex; gap: 3px; align-items: center; }
.msg-working-dots span {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--brand-cyan);
  opacity: 0.5;
  animation: msg-working-dot 1.3s ease-in-out infinite;
}
.msg-working-dots span:nth-child(2) { animation-delay: 0.15s; }
.msg-working-dots span:nth-child(3) { animation-delay: 0.30s; }
@keyframes msg-working-dot { 0%, 80%, 100% { opacity: 0.3; transform: scale(0.7); } 40% { opacity: 1; transform: scale(1); } }

/* Attachments — inline chip */
.msg-attachments {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}
.msg-agent .msg-attachments {
  border-left: 2px solid var(--brand-cyan);
  padding-left: 14px;
}
.msg-attachment {
  display: grid;
  grid-template-columns: 28px 1fr auto auto;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--input-bg);
  border: 1px solid var(--hairline);
  font-size: 12px;
  color: var(--text);
  text-decoration: none;
  max-width: 480px;
}
.msg-attachment:hover { border-color: rgba(6,182,212,0.40); }
.msg-attachment-icon {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--brand-cyan-soft);
  color: var(--brand-cyan);
}
.msg-attachment-image .msg-attachment-icon {
  background: var(--brand-purple-soft);
  color: var(--brand-purple);
}
.msg-attachment-name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.msg-attachment-meta {
  font-size: 11px;
  color: var(--spectral-dim);
  white-space: nowrap;
}
.msg-attachment-download { color: var(--spectral-dim); display: inline-flex; }
.msg-attachment:hover .msg-attachment-download { color: var(--brand-cyan); }
.msg-attachment-thumb {
  display: block;
  max-width: 480px;
  line-height: 0;
  border-radius: 10px;
  overflow: hidden;
  background: #0F172A;
  border: 1px solid var(--hairline);
}
.msg-attachment-thumb img {
  display: block;
  width: 100%;
  max-height: 240px;
  object-fit: contain;
}

.message-form-note { font-size: 12px; color: var(--spectral-dim); margin-top: 4px; font-style: italic; }

.msg-stop-count {
  display: inline-block;
  margin-inline-start: 6px;
  padding: 1px 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface-2);
  border-radius: 999px;
}

/* Collapsible chain-of-thought block — folds run intermediates while the
   final result message renders inline below. */
.msg-thinking {
  margin-block: 0;
  margin-inline: 0 auto;
  max-width: 100%;
  border-inline-start: 2px solid var(--hairline-strong);
  padding-inline-start: 14px;
  transition: border-color 0.15s ease;
}
.msg-thinking > summary {
  list-style: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--spectral-dim);
  padding: 2px 0;
  user-select: none;
}
.msg-thinking > summary::-webkit-details-marker { display: none; }
.msg-thinking > summary::before {
  content: "▸";
  display: inline-block;
  font-size: 10px;
  transition: transform 0.15s ease;
}
.msg-thinking[open] > summary::before { transform: rotate(90deg); }
[dir="rtl"] .msg-thinking > summary::before { content: "◂"; }
[dir="rtl"] .msg-thinking[open] > summary::before { transform: rotate(-90deg); }
.msg-thinking[open] { border-inline-start-color: var(--brand-cyan); }
.msg-thinking > summary:hover { color: var(--text); }
.msg-thinking-live { border-inline-start-color: var(--brand-cyan); }
.msg-thinking-live > summary { color: var(--brand-cyan); }

.msg-thinking-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 10px 0 6px;
}
.msg-thinking-step {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.msg-thinking-step .msg-body {
  font-size: 13px;
  color: var(--spectral-dim);
  background: none;
  border: 0;
  border-radius: 0;
  padding: 0;
  width: 100%;
}
.msg-thinking-step .msg-body p { margin: 0 0 6px; }
.msg-thinking-step .msg-body p:last-child { margin-bottom: 0; }
.msg-thinking-step .msg-date { font-size: 10px; }
.msg-thinking-body .msg-server-activity { margin: 0; }

/* Server-activity card stays full-width and visually distinct from messages */
.msg-server-activity {
  width: 100%;
  padding: 12px 14px;
  background: linear-gradient(135deg, rgba(139,92,246,0.06), rgba(6,182,212,0.04));
  border: 1px dashed rgba(139,92,246,0.35);
  border-radius: 12px;
  font-size: 13px;
  color: var(--muted);
}

/* Role positioning is physical (margin-left / margin-right: auto above), so the
   agent rail always lives on the physical left edge of the body regardless of
   the message's content direction. No RTL flip needed. */

@media (max-width: 1024px) {
  .msg-stack { padding: 0 8px; }
}
html[data-theme="light"] .msg-attachment-thumb img,
html.light .msg-attachment-thumb img { background: var(--surface-3); }

@keyframes assistant-cursor {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

/* Server-activity sub-elements */
.server-activity-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.server-activity-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--brand-cyan);
  box-shadow: 0 0 0 4px rgba(6,182,212,0.15);
  animation: pulse-dot 2s infinite;
  flex-shrink: 0;
}
.server-activity-title { font-weight: 600; color: var(--text); font-size: 13px; }
.server-activity-label {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: var(--track-micro);
  color: var(--brand-purple);
  background: var(--brand-purple-soft);
  padding: 2px 8px; border-radius: 999px;
  border: 1px solid rgba(139,92,246,0.30);
}
.server-activity-meta { color: var(--muted); font-size: 11px; }
.server-activity-time { color: var(--muted); font-size: 11px; margin-left: auto; }
.server-activity-section { margin-top: 6px; }
.server-activity-section-label {
  font-size: 10px;
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: var(--track-micro);
  color: var(--muted);
  margin-bottom: 2px;
}
.server-activity-toggle {
  background: transparent;
  border: 0;
  color: var(--brand-cyan);
  font-size: 11px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
}
.server-activity-toggle:hover { background: var(--brand-cyan-soft); }
.server-activity-body { font-size: 12px; color: var(--text); margin-top: 4px; }
.server-activity-command {
  display: block;
  background: rgba(0,0,0,0.30);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 11px;
  color: var(--brand-cyan);
  margin-top: 4px;
  word-break: break-all;
}
html[data-theme="light"] .server-activity-command,
html.light .server-activity-command { background: rgba(15,23,42,0.05); }

/* ---------- Composer ---------- */
.composer {
  background: var(--surface-2);
  border: 1px solid var(--hairline-strong);
  border-radius: 20px;
  padding: 0;
  margin: 0 15px;
  display: flex;
  flex-direction: column;
  gap: 0;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.composer:focus-within {
  border-color: var(--brand-cyan);
  box-shadow: 0 0 0 3px rgba(6,182,212,0.18);
}

/* Composer stays visually identical while the agent is running so the
   user can keep typing the next task — only the send button morphs
   into the red stop affordance (handled by .composer-send[data-state]). */

.composer-drop-zone { position: relative; padding: 14px 16px 10px; }
.composer-drop-zone textarea {
  width: 100%;
  min-height: 45px;
  resize: none;
  padding: 0;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: transparent;
  border: none;
  outline: none;
}
.composer-drop-zone textarea::placeholder { color: var(--spectral-dimmer); }

.composer-drop-overlay {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100vh;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  font-weight: 700;
  font-size: 20px;
  color: var(--brand-cyan);
  background: rgba(2, 6, 23, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border: 3px dashed var(--brand-cyan);
  pointer-events: none;
  z-index: 9000;
}
.composer-drop-overlay-icon { opacity: 0.85; }
.composer-drop-overlay-label { letter-spacing: 0.02em; }
body.is-drag-target .composer-drop-overlay {
  display: flex;
  pointer-events: auto;
}
body.is-drag-target .stage {
  outline: 2px dashed var(--brand-cyan);
  outline-offset: -8px;
  border-radius: 14px;
}

.composer-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 8px 8px 12px;
  border-top: 1px solid var(--hairline);
}
.composer-actions-spacer { flex: 1; }
.composer-actions-divider {
  display: inline-block;
  width: 1px;
  height: 20px;
  background: var(--hairline);
}
.composer-icon-btn {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--spectral-dim);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.composer-icon-btn:hover { background: var(--ghost-bg); color: var(--text); }
.composer-icon-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.composer-enter-hint {
  font-size: 11px;
  color: var(--spectral-dim);
  letter-spacing: 0.02em;
}
.composer-send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--brand-gradient);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(6,182,212,0.30);
  transition: transform 0.15s, box-shadow 0.15s, background 0.15s;
}
.composer-send:hover:not(:disabled) { transform: translateY(-1px); }
.composer-send:disabled {
  background: var(--ghost-bg);
  color: var(--spectral-faint);
  box-shadow: none;
  cursor: not-allowed;
}
.composer-send[data-state="sending"],
.composer-send[data-state="uploading"] { opacity: 0.7; }

/* Send / Stop icon swap. Both SVGs render in the button; CSS shows one
   based on data-state. While the agent is running, the button tints
   warning-red so users register it as a destructive control. */
.composer-send-icon-stop { display: none; }
.composer-send[data-state="stop"] .composer-send-icon-send,
.composer-send[data-state="stopping"] .composer-send-icon-send { display: none; }
.composer-send[data-state="stop"] .composer-send-icon-stop,
.composer-send[data-state="stopping"] .composer-send-icon-stop { display: inline; }
.composer-send[data-state="stop"],
.composer-send[data-state="stopping"] {
  background: var(--danger);
  box-shadow: 0 6px 18px rgba(239,68,68,0.30);
}
.composer-send[data-state="stopping"] { opacity: 0.7; }

/* Attachment tray — chips sit between textarea and toolbar, no outer frame */
.attachment-tray {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 0;
}
.attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 4px 4px 10px;
  border-radius: 8px;
  background: var(--input-bg);
  border: 1px solid var(--hairline);
  font-size: 11px;
}
.attachment-chip-name {
  font-weight: 600;
  color: var(--text);
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.attachment-chip-kind {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: var(--track-micro);
  color: var(--brand-cyan);
}
.attachment-chip-size { color: var(--muted); }
.attachment-chip-remove {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 0;
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
}
.attachment-chip-remove:hover { background: var(--danger-bg); color: var(--danger); }

/* ---------- Buttons ---------- */
.primary-button {
  border: 0;
  background: var(--brand-gradient);
  color: #FFFFFF;
  font-weight: 600;
  font-size: 13px;
  padding: 10px 18px;
  border-radius: var(--radius-button);
  cursor: pointer;
  letter-spacing: var(--track-display);
  transition: filter 0.15s, transform 0.05s, box-shadow 0.2s;
  box-shadow: 0 6px 18px rgba(6,182,212,0.18);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.primary-button:hover { filter: brightness(1.08); box-shadow: 0 10px 30px rgba(6,182,212,0.30); }
.primary-button:active { transform: translateY(1px); }
.primary-button:disabled { opacity: 0.5; cursor: not-allowed; filter: none; box-shadow: none; }

.ghost-button {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 600;
  font-size: 13px;
  padding: 8px 14px;
  border-radius: var(--radius-button);
  cursor: pointer;
  letter-spacing: var(--track-display);
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.ghost-button:hover { border-color: var(--brand-cyan); color: var(--brand-cyan); background: var(--brand-cyan-soft); }

.danger-button {
  background: var(--danger-bg);
  border: 1px solid var(--danger-border);
  color: var(--danger);
  font-weight: 600;
  font-size: 13px;
  padding: 8px 14px;
  border-radius: var(--radius-button);
  cursor: pointer;
  transition: background 0.15s;
}
.danger-button:hover { background: rgba(239,68,68,0.18); }

.wide-button { width: 100%; }

.icon-button {
  width: 30px;
  height: 30px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.icon-button:hover { color: var(--brand-cyan); border-color: var(--brand-cyan); background: var(--brand-cyan-soft); }

.button-row { display: inline-flex; gap: 8px; flex-wrap: wrap; }

/* Phase 6 — Project popup (Vault entry) + Environment popup (stacked, tabbed). */
.project-popup-card { max-width: 720px; width: 92vw; max-height: 80vh; display: flex; flex-direction: column; }
.project-popup-body { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; padding: 8px 0; }
.project-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.project-card:hover { border-color: var(--brand-cyan); background: var(--hover-bg); }
.project-card .credential-row-head { display: flex; align-items: center; gap: 8px; }
.project-card .credential-title { flex: 1; min-width: 0; }
.project-card .credential-card-actions { display: inline-flex; gap: 4px; }

.environment-popup-card {
  max-width: 760px;
  width: 92vw;
  max-height: 84vh;
  display: flex;
  flex-direction: column;
}
/* Stacked over the project popup. */
#environmentPopup { z-index: 210; }
.env-tabs {
  display: flex;
  gap: 4px;
  padding: 8px 0 0 0;
  border-bottom: 1px solid var(--border);
}
.env-tab-button {
  padding: 8px 14px;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.env-tab-button:hover { color: var(--brand-cyan); }
.env-tab-button.active {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
  position: relative;
  top: 1px;
}
.env-tab-panels {
  flex: 1;
  overflow-y: auto;
  padding: 14px 4px;
}
.env-credential-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.env-credential-form .field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}

/* Phase 4.3 — Projects/Environments management modal. */
.projects-modal-card {
  max-width: 720px;
  width: 90vw;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}
.projects-modal-body {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 4px 0;
}
.project-block {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  background: rgba(15, 23, 42, 0.02);
}
.project-block-head {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}
.project-name-input {
  flex: 1;
  font-size: 14px;
  font-weight: 700;
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
}
.project-name-input:hover, .project-name-input:focus {
  background: var(--surface);
  border-color: var(--border);
}
.env-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.env-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  padding: 6px 8px;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
}
.env-name-input {
  flex: 1;
  min-width: 160px;
  padding: 4px 8px;
  border-radius: 4px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  font-size: 13px;
}
.env-name-input:hover, .env-name-input:focus {
  background: rgba(15, 23, 42, 0.04);
  border-color: var(--border);
}
.env-flag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--text-muted);
}
.new-env-form, .new-project-form {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.new-env-form input, .new-project-form input {
  flex: 1;
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
}

/* Project + Environment selectors render as ghost pills on the slim chat header.
   Empty-state: badges + divider collapse via .env-badges:empty + .header-divider. */
.header-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 10px;
  border-radius: 8px;
  background: var(--ghost-bg);
  border: 1px solid var(--ghost-border);
  cursor: pointer;
}
.header-pill .select-label-text {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: var(--track-micro);
  color: var(--spectral-dim);
  font-weight: 600;
}
.header-pill select {
  appearance: none;
  -webkit-appearance: none;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 0 18px 0 0;
  border: none;
  background: transparent
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' fill='none' stroke='%2394A3B8' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'><polyline points='3 5 6 8 9 5'/></svg>")
    no-repeat right center / 12px 12px;
  color: var(--text);
  cursor: pointer;
  max-width: 160px;
  text-overflow: ellipsis;
}
.header-pill select:focus { outline: none; }
.header-pill select:disabled { opacity: 0.6; cursor: not-allowed; }
.header-pill select option {
  background: var(--surface);
  color: var(--text);
}

.env-badges {
  display: inline-flex;
  gap: 6px;
  flex-wrap: nowrap;
}
.env-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 24px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: var(--track-micro);
  text-transform: uppercase;
  white-space: nowrap;
}
.env-badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.env-badge-live {
  background: var(--danger-bg);
  color: #FCA5A5;
  border: 1px solid var(--danger-border);
}
.env-badge-readonly {
  background: var(--warning-soft);
  color: #FCD34D;
  border: 1px solid var(--warning-border);
}
.env-badge-autoapprove {
  background: var(--success-soft);
  color: #6EE7B7;
  border: 1px solid var(--success-border);
}
.manage-projects-button {
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}
.manage-projects-button:hover {
  color: var(--brand-cyan);
  border-color: var(--brand-cyan);
}

.ghost-button.small {
  padding: 4px 8px;
  font-size: 11px;
}
.primary-button.small {
  padding: 4px 10px;
  font-size: 11px;
}
.secondary-button.small {
  padding: 4px 10px;
  font-size: 11px;
}
.ghost-button.small.danger {
  color: var(--danger);
  border-color: rgba(239,68,68,0.35);
}

/* ---------- Forms / fields ---------- */
.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 12px;
  min-width: 0;
}
.field > span {
  font-weight: 700;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: var(--track-micro);
}
.field.field-wide { grid-column: 1 / -1; }
.field input,
.field select,
.field textarea {
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  background: linear-gradient(180deg, rgba(255,255,255,0.03), rgba(255,255,255,0)), var(--surface-2);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 11px 14px;
  min-height: 48px;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--brand-cyan);
  background: var(--surface);
  box-shadow: 0 0 0 4px rgba(6,182,212,0.14);
}
.field textarea {
  min-height: 110px;
  resize: vertical;
}
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 720px) { .field-grid { grid-template-columns: 1fr; } }
.field-help { color: var(--muted); font-size: 11px; margin: 4px 0 0; }
.field-error { color: var(--danger); font-size: 11px; margin: 4px 0 0; }

.credential-primary-grid,
.credential-dynamic-grid {
  gap: 14px;
}

.credential-kind-grid {
  grid-template-columns: minmax(0, 240px);
}

.credential-fields-shell {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.toggle-field {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
}
.credential-remember-row {
  padding: 12px 14px;
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(6,182,212,0.05), rgba(6,182,212,0.02));
  border: 1px solid rgba(6,182,212,0.18);
}
.credential-test-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-block: 8px 4px;
  flex-wrap: wrap;
}
.credential-test-button {
  flex-shrink: 0;
}
.credential-test-status {
  font-size: 12.5px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.credential-test-status.is-pending {
  color: var(--brand-cyan, #06b6d4);
  background: rgba(6, 182, 212, 0.08);
  border: 1px solid rgba(6, 182, 212, 0.28);
}
.credential-test-status.is-ok {
  color: #15803d;
  background: rgba(34, 197, 94, 0.10);
  border: 1px solid rgba(34, 197, 94, 0.32);
}
.credential-test-status.is-error {
  color: #b91c1c;
  background: rgba(239, 68, 68, 0.10);
  border: 1px solid rgba(239, 68, 68, 0.32);
}
.toggle-field input[type="checkbox"] {
  width: 16px; height: 16px;
  accent-color: var(--brand-cyan);
}

/* ---------- Modal / Dialog ---------- */
.modal-shell,
.confirm-shell {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 24px;
  animation: modal-in 0.18s ease-out;
}
@keyframes modal-in { from { opacity: 0; } to { opacity: 1; } }

.modal-card,
.confirm-card {
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow-card);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: card-in 0.22s ease-out;
}
.credential-modal-card {
  max-width: 760px;
  padding: 0;
  gap: 0;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(6,182,212,0.06), rgba(6,182,212,0) 110px),
    var(--surface);
}
.credential-modal-card::before {
  content: "";
  display: block;
  height: 3px;
  background: var(--brand-gradient-vivid);
}
@keyframes card-in {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.credential-modal-head {
  padding: 22px 26px 18px;
  border-bottom: 1px solid var(--border);
}
.modal-head h3 { font-size: 18px; margin: 4px 0 0; }
.credential-modal-reason {
  margin-top: 6px;
  max-width: 52ch;
}
.modal-close-button {
  min-width: 88px;
  min-height: 40px;
  border-radius: 999px;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}
.credential-modal-actions {
  padding-top: 6px;
  border-top: 1px solid var(--border);
}

.confirm-body { color: var(--muted); font-size: 13px; line-height: 1.5; }

.credential-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.credential-modal-form {
  padding: 22px 26px 26px;
  gap: 18px;
}

.inline-form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

@media (max-width: 720px) {
  .credential-modal-head,
  .credential-modal-form {
    padding-left: 18px;
    padding-right: 18px;
  }
  .credential-kind-grid {
    grid-template-columns: 1fr;
  }
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 200;
  background: var(--surface);
  color: var(--text);
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
  font-size: 13px;
  font-weight: 500;
  max-width: 380px;
  animation: toast-in 0.25s ease-out;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.toast.success { border-color: var(--success-border); color: var(--success); }
.toast.error { border-color: var(--danger-border); color: var(--danger); }
.toast.info { border-color: rgba(6,182,212,0.30); color: var(--brand-cyan); }

[dir="rtl"] .toast { right: auto; left: 24px; }

/* ---------- Shared (read-only) view ---------- */
.shared-body {
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}
.shared-header {
  padding: 24px;
  border-bottom: 1px solid var(--border);
  background: var(--card-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.shared-main {
  max-width: 920px;
  margin: 0 auto;
  padding: 24px;
}
/* .shared-log inherits .msg-stack layout when both classes are applied */

/* ---------- RTL support ---------- */
[dir="rtl"] .search-icon { left: auto; right: 12px; }
[dir="rtl"] .search-input { padding: 10px 34px 10px 36px; }
[dir="rtl"] .search-clear { right: auto; left: 8px; }
[dir="rtl"] .row-menu-button { right: auto; left: 8px; }
[dir="rtl"] .auto-approve-toggle input:checked + .auto-approve-track .auto-approve-thumb { transform: translateX(-12px); }
[dir="rtl"] .credential-toggle input:checked + .credential-toggle-track .credential-toggle-thumb { transform: translateX(-14px); }
[dir="rtl"] .archived-toggle[aria-expanded="true"] .archived-chevron { transform: rotate(-90deg); }

/* ---------- Responsive nav (chat page) ---------- */
@media (max-width: 720px) {
  .global-nav { padding: 0 14px; gap: 10px; }
  .nav-link { display: none; }
  .auto-approve-toggle .auto-approve-label { display: none; }
}

/* ---------- Animations utility ---------- */
.animate-fade-in { animation: fade-in 0.4s ease-out; }
@keyframes fade-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

/* ============================================================
   Auth pages utilities (shared with chat via app.css)
   These pair with Tailwind in _aid_base.html for layout helpers
   ============================================================ */

.glass {
  background: var(--card-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--card-border);
}
html[data-theme="light"] .glass,
html.light .glass { box-shadow: 0 1px 3px rgba(15,23,42,0.06); }

.btn-gradient {
  background: var(--brand-gradient);
  color: #FFFFFF;
  transition: filter 0.15s, transform 0.05s, box-shadow 0.2s;
  box-shadow: 0 6px 18px rgba(6,182,212,0.18);
}
.btn-gradient:hover { filter: brightness(1.08); box-shadow: 0 10px 30px rgba(6,182,212,0.30); }
.btn-gradient:active { transform: translateY(1px); }

.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.btn-ghost:hover { border-color: var(--brand-cyan); background: var(--brand-cyan-soft); color: var(--brand-cyan); }

.btn-danger {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid var(--danger-border);
  transition: background 0.15s;
}
.btn-danger:hover { background: rgba(239,68,68,0.18); }

/* Token-bound utilities for Tailwind-styled auth pages */
.t-bg { background: var(--bg); }
.t-surface { background: var(--surface); }
.t-surface2 { background: var(--surface-2); }
.t-border { border-color: var(--border); }
.t-text { color: var(--text); }
.t-muted { color: var(--muted); }
.t-input {
  background: var(--input-bg);
  border: 1px solid var(--border);
  color: var(--text);
}
.t-input::placeholder { color: var(--muted); }
.t-nav { background: var(--nav-bg); }

/* Pulse dot used in auth navbar */
.pulse-dot { animation: pulse-dot 2s infinite; }

/* ---------- Pricing page ---------- */
.pricing-highlight {
  border: 1px solid rgba(6, 182, 212, 0.45);
  box-shadow: 0 12px 40px rgba(6, 182, 212, 0.18);
}
.pricing-badge {
  position: absolute;
  top: -11px;
  inset-inline-start: 50%;
  transform: translateX(-50%);
  padding: 4px 14px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .04em;
  color: #fff;
  background: linear-gradient(135deg, #06B6D4, #8B5CF6);
  white-space: nowrap;
}
html[dir="rtl"] .pricing-badge { transform: translateX(50%); }

/* Public/nav text links (used in the shared navbar) */
.nav-link {
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 8px;
}
.nav-link:hover { color: var(--text); background: var(--surface-2); }
.nav-link-active { color: var(--text); }
.nav-link-cta {
  color: #fff;
  background: linear-gradient(135deg, #06B6D4, #8B5CF6);
}
.nav-link-cta:hover { color: #fff; opacity: .92; background: linear-gradient(135deg, #06B6D4, #8B5CF6); }
