/*
 * Vulcan UI Component Library (vui)
 * 
 * Themeable component styles using CSS custom properties.
 * All classes prefixed with `vui-` to avoid collisions.
 * 
 * Override any component by loading a stylesheet after this one,
 * or override theme tokens by redefining the custom properties.
 *
 * Architecture:
 *   0. Theme & Reset — color tokens, CSS reset
 *   1. Tokens (custom properties) — spacing, radii, typography
 *   2. Base components — buttons, inputs, badges, cards
 *   3. Layout components — page headers, tab layouts, grids
 *   4. Composite components — provider cards, empty states, save bars
 */

/* ═══════════════════════════════════════════════════════════════════════
   0. THEME & RESET
   ═══════════════════════════════════════════════════════════════════════ */

/* ─── Theme: Dark (default) ─────────────────────────────────────── */
:root, [data-theme="dark"] {
  --background: #141110;
  --background-secondary: #1c1917;
  --background-tertiary: #292524;
  --foreground: #fafaf9;
  --foreground-secondary: #a8a29e;
  --foreground-tertiary: #57534e;
  --border: #3a3633;
  --hover: #1c1917;
  --accent: #fafaf9;
  --accent-foreground: #0c0a09;
  --danger: #dc2626;
  --success: #22c55e;
  --info: #3b82f6;
  color-scheme: dark;
}

/* ─── Theme: Light ──────────────────────────────────────────────── */
[data-theme="light"] {
  --background: #fafaf9;
  --background-secondary: #f5f5f4;
  --background-tertiary: #e7e5e4;
  --foreground: #1c1917;
  --foreground-secondary: #78716c;
  --foreground-tertiary: #a8a29e;
  --border: #d6d3d1;
  --hover: #f5f5f4;
  --accent: #1c1917;
  --accent-foreground: #fafaf9;
  --danger: #dc2626;
  --success: #16a34a;
  --info: #2563eb;
  color-scheme: light;
}

/* ─── Reset ───────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  background: var(--background); color: var(--foreground);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}
img, svg { display: block; }
img { max-width: 100%; }
a { color: inherit; text-decoration: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, h4, h5, h6 { font-size: inherit; font-weight: inherit; }
ol, ul { list-style: none; }
table { border-collapse: collapse; border-spacing: 0; }

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

/* ─── Messages (chat-specific but global) ──────────────────────── */
.msg-user {
  background: var(--accent); color: var(--accent-foreground);
  max-width: 85%; padding: 12px 16px; border-radius: 16px;
  font-size: 14px; white-space: pre-wrap; word-break: break-word;
}
.msg-assistant {
  background: var(--background-secondary); color: var(--foreground);
  max-width: 85%; padding: 12px 16px; border-radius: 16px;
  font-size: 14px; line-height: 1.6; overflow-x: auto;
}
.msg-assistant code { background: var(--background-tertiary); padding: 2px 6px; border-radius: 4px; font-size: 13px; }
.msg-assistant pre { background: var(--background-tertiary); padding: 12px; border-radius: 8px; overflow-x: auto; margin: 8px 0; }
.msg-assistant p { margin: 0 0 8px 0; }
.msg-assistant p:last-child { margin-bottom: 0; }

/* ─── Tool badge (chat-specific but global) ────────────────────── */
.tool-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 8px; font-size: 13px; font-family: var(--vui-font-mono);
  background: var(--background-tertiary); border: 1px solid var(--border); color: var(--foreground-secondary);
  margin: 4px 0;
}

/* ─── Sidebar ──────────────────────────────────────────────────── */
.sidebar-link {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 12px; border-radius: 8px; font-size: 14px; font-weight: 400;
  color: var(--foreground); background: transparent;
  transition: background 0.15s; cursor: pointer; text-decoration: none;
}
.sidebar-link:hover { background: var(--hover); }
.sidebar-link.active { background: var(--hover); }
.sidebar-link svg { color: var(--foreground-secondary); width: 18px; height: 18px; flex-shrink: 0; }
.sidebar-link.active svg { color: var(--foreground); }

/* ═══════════════════════════════════════════════════════════════════════
   1. TOKENS
   These extend the theme variables defined in root.html.heex.
   Components reference these tokens, not raw values.
   ═══════════════════════════════════════════════════════════════════════ */

:root {
  /* Spacing scale */
  --vui-space-xs: 4px;
  --vui-space-sm: 8px;
  --vui-space-md: 12px;
  --vui-space-lg: 16px;
  --vui-space-xl: 24px;
  --vui-space-2xl: 32px;

  /* Border radius */
  --vui-radius-sm: 4px;
  --vui-radius-md: 6px;
  --vui-radius-lg: 8px;
  --vui-radius-xl: 12px;
  --vui-radius-full: 9999px;

  /* Typography */
  --vui-font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --vui-font-mono: 'SF Mono', 'Fira Code', ui-monospace, monospace;
  --vui-text-xs: 10px;
  --vui-text-sm: 11px;
  --vui-text-base: 13px;
  --vui-text-md: 14px;
  --vui-text-lg: 16px;
  --vui-text-xl: 18px;

  /* Transitions */
  --vui-transition: 0.15s ease;

  /* Shadows (subtle, for cards) */
  --vui-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --vui-shadow-md: 0 2px 8px rgba(0, 0, 0, 0.1);
}


/* ═══════════════════════════════════════════════════════════════════════
   2. BASE COMPONENTS
   ═══════════════════════════════════════════════════════════════════════ */

/* ─── Buttons ──────────────────────────────────────────────────────── */

.vui-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--vui-space-sm);
  border: none;
  border-radius: var(--vui-radius-md);
  font-size: var(--vui-text-base);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--vui-transition);
  white-space: nowrap;
  text-decoration: none;
  line-height: 1;
}

.vui-btn--sm { padding: 4px 10px; font-size: var(--vui-text-sm); }
.vui-btn--md { padding: 8px 16px; }
.vui-btn--lg { padding: 10px 20px; font-size: var(--vui-text-md); }

.vui-btn--primary {
  background: var(--accent);
  color: var(--accent-foreground);
}
.vui-btn--primary:hover { opacity: 0.9; }
.vui-btn--primary:disabled { opacity: 0.5; cursor: default; }

.vui-btn--ghost {
  padding: 6px 8px;
  background: transparent;
  color: var(--foreground-secondary);
}
.vui-btn--ghost:hover { background: var(--hover); color: var(--foreground); }

.vui-btn--outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--foreground-secondary);
}
.vui-btn--outline:hover {
  background: var(--hover);
  color: var(--foreground);
  border-color: var(--foreground-secondary);
}

.vui-btn--danger {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--danger);
}
.vui-btn--danger:hover {
  background: rgba(220, 38, 38, 0.1);
  border-color: var(--danger);
}

.vui-btn--icon {
  padding: 6px;
  background: transparent;
  border: none;
  color: var(--foreground-secondary);
  border-radius: var(--vui-radius-md);
}
.vui-btn--icon:hover { background: var(--hover); color: var(--foreground); }


/* ─── Inputs ───────────────────────────────────────────────────────── */

.vui-input,
.vui-select {
  width: 100%;
  padding: 8px 12px;
  background: var(--background);
  border: 1px solid var(--border);
  border-radius: var(--vui-radius-md);
  color: var(--foreground);
  font-size: var(--vui-text-base);
  font-family: var(--vui-font-sans);
  outline: none;
  box-sizing: border-box;
  transition: border-color var(--vui-transition);
}
.vui-input:focus,
.vui-select:focus { border-color: var(--accent); }
.vui-input::placeholder { color: var(--foreground-tertiary); }

.vui-select { appearance: none; }

.vui-input--sm { padding: 6px 10px; font-size: var(--vui-text-sm); }
.vui-input--mono { font-family: var(--vui-font-mono); }

.vui-input--filter {
  padding: 6px 10px;
  font-size: 12px;
  margin-bottom: var(--vui-space-sm);
}


/* ─── Labels & Hints ───────────────────────────────────────────────── */

.vui-label {
  display: block;
  font-size: var(--vui-text-sm);
  font-weight: 500;
  color: var(--foreground-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.vui-hint {
  font-size: var(--vui-text-sm);
  color: var(--foreground-secondary);
  margin-top: var(--vui-space-xs);
}


/* ─── Badges ───────────────────────────────────────────────────────── */

.vui-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: var(--vui-text-xs);
  font-weight: 500;
  padding: 2px 8px;
  border-radius: var(--vui-radius-sm);
  white-space: nowrap;
}

.vui-badge--default {
  background: var(--background-tertiary);
  color: var(--foreground-secondary);
}
.vui-badge--success {
  background: rgba(34, 197, 94, 0.15);
  color: var(--success);
}
.vui-badge--danger {
  background: rgba(220, 38, 38, 0.1);
  color: var(--danger);
}
.vui-badge--info {
  background: rgba(59, 130, 246, 0.15);
  color: var(--info);
}
.vui-badge--warning {
  background: rgba(234, 179, 8, 0.15);
  color: #eab308;
}
.vui-badge--accent {
  background: rgba(124, 58, 237, 0.15);
  color: #a78bfa;
}


/* ─── Status Dot ───────────────────────────────────────────────────── */

.vui-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.vui-dot--success { background: var(--success); }
.vui-dot--danger { background: var(--danger); }
.vui-dot--info { background: var(--info); }
.vui-dot--warning { background: #eab308; }
.vui-dot--muted { background: var(--foreground-tertiary); }
.vui-dot--pulse { animation: vui-pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite; }


/* ═══════════════════════════════════════════════════════════════════════
   3. LAYOUT COMPONENTS
   ═══════════════════════════════════════════════════════════════════════ */

/* ─── Page Header ──────────────────────────────────────────────────── */

.vui-page-header {
  display: flex;
  align-items: center;
  gap: var(--vui-space-md);
  height: 48px;
  padding: 0 var(--vui-space-xl);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.vui-page-title {
  font-size: var(--vui-text-lg);
  font-weight: 600;
  color: var(--foreground);
  margin: 0;
  display: flex;
  align-items: center;
  gap: var(--vui-space-sm);
}

.vui-page-icon {
  font-size: var(--vui-text-lg);
}

.vui-page-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--vui-space-sm);
}


/* ─── Section Header ───────────────────────────────────────────────── */

.vui-section-header {
  font-size: var(--vui-text-md);
  font-weight: 600;
  color: var(--foreground-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: var(--vui-space-md);
}


/* ─── Tab Layout (vertical sidebar tabs) ───────────────────────────── */

.vui-tab-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.vui-tab-nav {
  width: 180px;
  flex-shrink: 0;
  padding: var(--vui-space-lg) var(--vui-space-sm);
  border-right: 1px solid var(--border);
  background: var(--background);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.vui-tab-btn {
  display: flex;
  align-items: center;
  gap: var(--vui-space-sm);
  padding: 8px 12px;
  border: none;
  border-radius: var(--vui-radius-lg);
  background: transparent;
  color: var(--foreground-secondary);
  font-size: var(--vui-text-base);
  font-weight: 400;
  cursor: pointer;
  transition: all var(--vui-transition);
  text-align: left;
  width: 100%;
  border-left: 3px solid transparent;
}
.vui-tab-btn:hover {
  background: var(--hover);
  color: var(--foreground);
}
.vui-tab-btn.active {
  background: var(--background-secondary);
  color: var(--foreground);
  font-weight: 500;
  border-left-color: var(--accent);
}

.vui-tab-icon {
  display: flex;
  align-items: center;
  color: inherit;
  opacity: 0.7;
}
.vui-tab-btn.active .vui-tab-icon { opacity: 1; }

.vui-tab-content {
  flex: 1;
  overflow-y: auto;
  padding: var(--vui-space-xl);
}

.vui-tab-panel {
  display: none;
}
.vui-tab-panel.active {
  display: block;
}


/* ─── Content Area (scrollable page body) ──────────────────────────── */

.vui-content {
  padding: var(--vui-space-xl);
  overflow-y: auto;
  flex: 1;
}

.vui-content--narrow { max-width: 720px; }
.vui-content--wide { max-width: 1200px; }


/* ═══════════════════════════════════════════════════════════════════
   4. COMPOSITE COMPONENTS
   ═══════════════════════════════════════════════════════════════════════ */

/* ─── Card ─────────────────────────────────────────────────────────── */

.vui-card {
  background: var(--background-secondary);
  border: 1px solid var(--border);
  border-radius: var(--vui-radius-xl);
  padding: 20px 24px;
  margin-bottom: var(--vui-space-lg);
}

.vui-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: var(--vui-space-lg);
}

.vui-card-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--foreground);
}

.vui-card-subtitle {
  margin: 4px 0 0;
  font-size: var(--vui-text-sm);
  color: var(--foreground-secondary);
}

.vui-card-body {}


/* ─── Item Card (nested within sections) ───────────────────────────── */

.vui-item-card {
  background: var(--background);
  border: 1px solid var(--border);
  border-radius: var(--vui-radius-lg);
  padding: var(--vui-space-lg);
  margin-bottom: var(--vui-space-sm);
  transition: border-color var(--vui-transition);
}
.vui-item-card:hover { border-color: var(--foreground-tertiary); }
.vui-item-card.vui-disabled {
  opacity: 0.5;
  pointer-events: none;
}

.vui-item-card-header {
  display: flex;
  align-items: center;
  gap: var(--vui-space-sm);
  margin-bottom: var(--vui-space-md);
}

.vui-item-card-title {
  margin: 0;
  font-size: var(--vui-text-md);
  font-weight: 500;
  color: var(--foreground);
}


/* ─── List Row ─────────────────────────────────────────────────────── */

.vui-list-row {
  display: flex;
  align-items: center;
  gap: var(--vui-space-md);
  padding: 10px 12px;
  border-radius: var(--vui-radius-lg);
  background: var(--background-secondary);
  border: 1px solid transparent;
  transition: all var(--vui-transition);
  text-decoration: none;
  color: inherit;
}
.vui-list-row:hover {
  border-color: var(--border);
  background: var(--background-tertiary);
}
.vui-list-row + .vui-list-row { margin-top: var(--vui-space-sm); }

.vui-list-row-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--vui-radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--background);
  flex-shrink: 0;
}

.vui-list-row-body {
  flex: 1;
  min-width: 0;
}

.vui-list-row-title {
  font-size: var(--vui-text-md);
  font-weight: 500;
  color: var(--foreground);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.vui-list-row-meta {
  font-size: var(--vui-text-sm);
  color: var(--foreground-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.vui-list-row-actions {
  display: flex;
  align-items: center;
  gap: var(--vui-space-sm);
  flex-shrink: 0;
}


/* ─── Form Group ───────────────────────────────────────────────────── */

.vui-form-group {
  margin-bottom: var(--vui-space-lg);
}
.vui-form-group:last-child { margin-bottom: 0; }

.vui-form-row {
  display: flex;
  gap: var(--vui-space-md);
}
.vui-form-row > * { flex: 1; }


/* ─── Empty State ──────────────────────────────────────────────────── */

.vui-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: var(--foreground-secondary);
}

.vui-empty-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--background-secondary);
  font-size: 24px;
  margin-bottom: var(--vui-space-lg);
}

.vui-empty-title {
  font-size: var(--vui-text-md);
  font-weight: 500;
  color: var(--foreground);
  margin-bottom: var(--vui-space-xs);
}

.vui-empty-text {
  font-size: var(--vui-text-base);
  color: var(--foreground-secondary);
  text-align: center;
  max-width: 300px;
}


/* ─── Save Bar ─────────────────────────────────────────────────────── */

.vui-save-bar {
  display: flex;
  align-items: center;
  gap: var(--vui-space-sm);
  padding: var(--vui-space-lg) 0;
}

.vui-save-feedback {
  font-size: 12px;
  color: var(--success);
  opacity: 0;
  transition: opacity 0.3s;
}


/* ─── Model Grid (settings-specific but reusable) ──────────────────── */

.vui-model-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: var(--vui-space-sm);
  max-height: 200px;
  overflow-y: auto;
}

.vui-model-chip {
  padding: 4px 10px;
  border-radius: var(--vui-radius-md);
  font-size: 12px;
  font-family: var(--vui-font-mono);
  background: var(--background);
  border: 1px solid var(--border);
  color: var(--foreground);
  cursor: pointer;
  transition: all var(--vui-transition);
  white-space: nowrap;
}
.vui-model-chip:hover { border-color: var(--foreground-secondary); }
.vui-model-chip.selected {
  background: rgba(124, 58, 237, 0.15);
  border-color: rgba(124, 58, 237, 0.3);
  color: #a78bfa;
}


/* ─── Filter Pills ─────────────────────────────────────────────────── */

.vui-pill {
  padding: 5px 12px;
  border-radius: var(--vui-radius-full);
  font-size: var(--vui-text-sm);
  font-weight: 500;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--foreground-secondary);
  cursor: pointer;
  transition: all var(--vui-transition);
  white-space: nowrap;
}
.vui-pill:hover {
  border-color: var(--foreground-secondary);
  color: var(--foreground);
}
.vui-pill.active {
  background: var(--foreground);
  color: var(--background);
  border-color: var(--foreground);
}


/* ─── Slideover (side panel overlay) ───────────────────────────────── */

.vui-slideover-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.vui-slideover-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.vui-slideover {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 600px;
  max-width: 90vw;
  background: var(--background);
  border-left: 1px solid var(--border);
  z-index: 101;
  transform: translateX(100%);
  transition: transform 0.2s ease;
  display: flex;
  flex-direction: column;
}
.vui-slideover.open { transform: translateX(0); }

.vui-slideover-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--vui-space-lg) var(--vui-space-xl);
  border-bottom: 1px solid var(--border);
}

.vui-slideover-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--vui-space-xl);
}


/* ─── Grid Layouts ─────────────────────────────────────────────────── */

.vui-grid {
  display: grid;
  gap: var(--vui-space-md);
}
.vui-grid--2 { grid-template-columns: repeat(2, 1fr); }
.vui-grid--3 { grid-template-columns: repeat(3, 1fr); }
.vui-grid--4 { grid-template-columns: repeat(4, 1fr); }
.vui-grid--auto { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }


/* ═══════════════════════════════════════════════════════════════════════
   5. UTILITIES
   ═══════════════════════════════════════════════════════════════════════ */

.vui-truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.vui-mono { font-family: var(--vui-font-mono); }

.vui-flex { display: flex; }
.vui-flex-col { display: flex; flex-direction: column; }
.vui-items-center { align-items: center; }
.vui-justify-between { justify-content: space-between; }
.vui-gap-xs { gap: var(--vui-space-xs); }
.vui-gap-sm { gap: var(--vui-space-sm); }
.vui-gap-md { gap: var(--vui-space-md); }
.vui-gap-lg { gap: var(--vui-space-lg); }

.vui-mt-sm { margin-top: var(--vui-space-sm); }
.vui-mt-md { margin-top: var(--vui-space-md); }
.vui-mt-lg { margin-top: var(--vui-space-lg); }
.vui-mb-sm { margin-bottom: var(--vui-space-sm); }
.vui-mb-md { margin-bottom: var(--vui-space-md); }
.vui-mb-lg { margin-bottom: var(--vui-space-lg); }

.vui-text-xs { font-size: var(--vui-text-xs); }
.vui-text-sm { font-size: var(--vui-text-sm); }
.vui-text-base { font-size: var(--vui-text-base); }
.vui-text-md { font-size: var(--vui-text-md); }
.vui-text-lg { font-size: var(--vui-text-lg); }

.vui-text-muted { color: var(--foreground-secondary); }
.vui-text-faint { color: var(--foreground-tertiary); }
.vui-text-success { color: var(--success); }
.vui-text-danger { color: var(--danger); }
.vui-text-info { color: var(--info); }

.vui-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}


/* ═══════════════════════════════════════════════════════════════════════
   6. ANIMATIONS
   ═══════════════════════════════════════════════════════════════════════ */

@keyframes vui-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}
.vui-pulse { animation: vui-pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite; }

@keyframes vui-spin {
  to { transform: rotate(360deg); }
}
.vui-spin { animation: vui-spin 1s linear infinite; }

@keyframes vui-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
.vui-fade-in { animation: vui-fade-in 0.2s ease; }
