/* ============================================
   Dami — Design System v4
   Clean light theme
   ============================================ */

:root {
  /* Light palette */
  --bg-base: #f4f4f6;
  --bg-raised: #ffffff;
  --bg-surface: #ffffff;
  --bg-overlay: #f0f0f3;
  --bg-hover: #eaeaee;
  --bg-active: #e2e2e8;

  --border: #e2e2e8;
  --border-strong: #cbcbd4;
  --border-focus: #6366f1;

  --text: #4a4a56;
  --text-strong: #111118;
  --text-muted: #8a8a98;
  --text-dim: #b0b0bc;

  /* Indigo accent */
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-dim: #4338ca;
  --accent-subtle: rgba(99, 102, 241, 0.08);
  --accent-glow: rgba(99, 102, 241, 0.06);
  --accent-fg: #fff;

  /* Status */
  --success: #16a34a;
  --success-subtle: rgba(22, 163, 74, 0.08);
  --warning: #ca8a04;
  --warning-subtle: rgba(202, 138, 4, 0.08);
  --error: #dc2626;
  --error-subtle: rgba(220, 38, 38, 0.06);
  --info: #0284c7;
  --info-subtle: rgba(2, 132, 199, 0.08);

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', ui-monospace, monospace;

  /* Spacing */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-10: 40px;
  --sp-12: 48px;

  /* Radii */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.1);
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.03);

  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --dur: 150ms;

  --sidebar-width: 220px;
}

/* ---- Midnight (dark indigo) ---- */
[data-theme="midnight"] {
  --bg-base: #0f0f1a;
  --bg-raised: #181825;
  --bg-surface: #1e1e2e;
  --bg-overlay: #232336;
  --bg-hover: #2a2a40;
  --bg-active: #33334d;
  --border: #2e2e45;
  --border-strong: #3e3e5c;
  --border-focus: #818cf8;
  --text: #b8b8cc;
  --text-strong: #e4e4f0;
  --text-muted: #6e6e88;
  --text-dim: #4a4a60;
  --accent: #818cf8;
  --accent-hover: #6366f1;
  --accent-dim: #4f46e5;
  --accent-subtle: rgba(129, 140, 248, 0.1);
  --accent-glow: rgba(129, 140, 248, 0.06);
  --accent-fg: #111;
  --success: #34d399;
  --success-subtle: rgba(52, 211, 153, 0.1);
  --warning: #fbbf24;
  --warning-subtle: rgba(251, 191, 36, 0.1);
  --error: #f87171;
  --error-subtle: rgba(248, 113, 113, 0.08);
  --info: #38bdf8;
  --info-subtle: rgba(56, 189, 248, 0.1);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.2), 0 1px 2px rgba(0, 0, 0, 0.15);
}

/* ---- Slate (neutral dark) ---- */
[data-theme="slate"] {
  --bg-base: #111113;
  --bg-raised: #19191d;
  --bg-surface: #202025;
  --bg-overlay: #27272d;
  --bg-hover: #2e2e36;
  --bg-active: #37373f;
  --border: #2e2e36;
  --border-strong: #42424e;
  --border-focus: #a0a0b0;
  --text: #a8a8b8;
  --text-strong: #e0e0e8;
  --text-muted: #68687a;
  --text-dim: #45454f;
  --accent: #a0a0b0;
  --accent-hover: #c0c0cc;
  --accent-dim: #8888998;
  --accent-subtle: rgba(160, 160, 176, 0.1);
  --accent-glow: rgba(160, 160, 176, 0.06);
  --accent-fg: #111;
  --success: #4ade80;
  --success-subtle: rgba(74, 222, 128, 0.1);
  --warning: #facc15;
  --warning-subtle: rgba(250, 204, 21, 0.1);
  --error: #f87171;
  --error-subtle: rgba(248, 113, 113, 0.08);
  --info: #60a5fa;
  --info-subtle: rgba(96, 165, 250, 0.1);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.6);
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.25), 0 1px 2px rgba(0, 0, 0, 0.2);
}

/* ---- Ocean (deep blue-teal dark) ---- */
[data-theme="ocean"] {
  --bg-base: #0a1520;
  --bg-raised: #0f1d2c;
  --bg-surface: #142536;
  --bg-overlay: #1a2d40;
  --bg-hover: #21364a;
  --bg-active: #2a3f54;
  --border: #1e3348;
  --border-strong: #2d4a64;
  --border-focus: #38bdf8;
  --text: #94b8d4;
  --text-strong: #d4e8f8;
  --text-muted: #5a8099;
  --text-dim: #3a5a72;
  --accent: #38bdf8;
  --accent-hover: #22a8e8;
  --accent-dim: #0c8fd4;
  --accent-subtle: rgba(56, 189, 248, 0.1);
  --accent-glow: rgba(56, 189, 248, 0.06);
  --accent-fg: #0a1520;
  --success: #2dd4bf;
  --success-subtle: rgba(45, 212, 191, 0.1);
  --warning: #fbbf24;
  --warning-subtle: rgba(251, 191, 36, 0.1);
  --error: #fb7185;
  --error-subtle: rgba(251, 113, 133, 0.08);
  --info: #38bdf8;
  --info-subtle: rgba(56, 189, 248, 0.1);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.6);
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.25), 0 1px 2px rgba(0, 0, 0, 0.2);
}

/* ---- Nord (arctic frost) ---- */
[data-theme="nord"] {
  --bg-base: #2e3440;
  --bg-raised: #3b4252;
  --bg-surface: #434c5e;
  --bg-overlay: #4c566a;
  --bg-hover: #545e72;
  --bg-active: #5e687a;
  --border: #4c566a;
  --border-strong: #5e6880;
  --border-focus: #88c0d0;
  --text: #b0bec8;
  --text-strong: #eceff4;
  --text-muted: #7b8da0;
  --text-dim: #5a6878;
  --accent: #88c0d0;
  --accent-hover: #8fbccd;
  --accent-dim: #6aabb8;
  --accent-subtle: rgba(136, 192, 208, 0.12);
  --accent-glow: rgba(136, 192, 208, 0.06);
  --accent-fg: #2e3440;
  --success: #a3be8c;
  --success-subtle: rgba(163, 190, 140, 0.12);
  --warning: #ebcb8b;
  --warning-subtle: rgba(235, 203, 139, 0.12);
  --error: #bf616a;
  --error-subtle: rgba(191, 97, 106, 0.1);
  --info: #81a1c1;
  --info-subtle: rgba(129, 161, 193, 0.12);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.4);
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.2), 0 1px 2px rgba(0, 0, 0, 0.15);
}

/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
body {
  height: 100%;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg-base);
}
a { color: var(--accent); text-decoration: none; transition: color var(--dur) var(--ease); }
a:hover { color: var(--accent-hover); }

/* ---- Layout ---- */
.app-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ---- Sidebar ---- */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-raised);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-header {
  padding: var(--sp-5) var(--sp-5) var(--sp-4);
}

.logo {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.logo-icon {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

.logo-text {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-strong);
  letter-spacing: -0.5px;
}

.nav-section {
  margin-bottom: var(--sp-2);
}

.nav-label {
  padding: var(--sp-3) var(--sp-5) var(--sp-1);
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-dim);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 8px var(--sp-4);
  margin: 1px var(--sp-2);
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-size: 13.5px;
  font-weight: 450;
  transition: all var(--dur) var(--ease);
  text-decoration: none;
}

.nav-item:hover {
  color: var(--text-strong);
  background: var(--bg-hover);
}

.nav-item.active {
  color: var(--accent);
  background: var(--accent-subtle);
  font-weight: 550;
}

.nav-icon {
  width: 17px;
  height: 17px;
  flex-shrink: 0;
  opacity: 0.4;
}

.nav-item:hover .nav-icon { opacity: 0.7; }
.nav-item.active .nav-icon { opacity: 1; color: var(--accent); }

.sidebar-footer {
  margin-top: auto;
  padding: var(--sp-4) var(--sp-5);
  border-top: 1px solid var(--border);
}
.sidebar-user {
  margin-top: var(--sp-2);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sidebar-logout-icon { display: none; color: var(--text-muted); }
.theme-icon-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  background: var(--bg-overlay);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
}
.theme-icon-btn:hover { color: var(--accent); }

/* ---- Main Content ---- */
.main-content {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-base);
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--sp-5) var(--sp-8);
  border-bottom: 1px solid var(--border);
  background: var(--bg-raised);
  flex-shrink: 0;
}

.page-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-strong);
  letter-spacing: -0.3px;
}

.page-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 1px;
}

.header-actions {
  display: flex;
  gap: var(--sp-2);
  align-items: center;
}

.page-content {
  flex: 1;
  padding: var(--sp-6) var(--sp-8);
}

/* ---- Cards ---- */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-5);
  box-shadow: var(--shadow-card);
  transition: all var(--dur) var(--ease);
}

.card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: var(--sp-4);
}

.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-strong);
  margin-bottom: var(--sp-1);
}

.card-desc {
  font-size: 13px;
  color: var(--text);
  line-height: 1.5;
}

a.card {
  text-decoration: none;
  color: inherit;
  cursor: pointer;
}
a.card:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent-subtle), var(--shadow-md);
}
a.card .card-title { transition: color var(--dur) var(--ease); }
a.card:hover .card-title { color: var(--accent); }

/* ---- Stat Cards ---- */
.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--sp-4);
  margin-bottom: var(--sp-6);
}

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-5);
  box-shadow: var(--shadow-card);
}

.stat-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: var(--sp-1);
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-strong);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.stat-note {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: var(--sp-1);
}

/* ---- Status / Badges ---- */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-dot.online { background: var(--success); box-shadow: 0 0 6px rgba(22, 163, 74, 0.4); }
.status-dot.offline { background: var(--error); }
.status-dot.warning { background: var(--warning); }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.2px;
  white-space: nowrap;
}

.badge-accent { background: var(--accent-subtle); color: var(--accent); }
.badge-success { background: var(--success-subtle); color: var(--success); }
.badge-warning { background: var(--warning-subtle); color: var(--warning); }
.badge-error { background: var(--error-subtle); color: var(--error); }
.badge-info { background: var(--info-subtle); color: var(--info); }
.badge-muted { background: var(--bg-overlay); color: var(--text-muted); }

/* ---- Shared Component Styles ---- */

/* Form components used across Providers, Cron, Models pages */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-4);
}
.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}
.form-group-full {
  grid-column: 1 / -1;
}
.form-label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
}
.form-input {
  background: var(--bg-overlay);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  color: var(--text-strong);
  font-size: 0.85rem;
  font-family: inherit;
}
.form-input:focus {
  outline: none;
  border-color: var(--accent);
}
select.form-input { cursor: pointer; }
textarea.form-input { resize: vertical; }

/* Shared loading spinner used across Cron, Models pages */
.run-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

/* ---- Forms / Inputs ---- */
.input {
  width: 100%;
  padding: 8px 14px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-strong);
  font-family: var(--font-sans);
  font-size: 13px;
  outline: none;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}

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

.input::placeholder { color: var(--text-dim); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-raised);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--dur) var(--ease);
  white-space: nowrap;
  line-height: 1.4;
}

.btn:hover {
  background: var(--bg-hover);
  color: var(--text-strong);
  border-color: var(--border-strong);
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: transparent;
  box-shadow: 0 1px 3px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
  background: var(--accent-hover);
  color: var(--accent-fg);
  border-color: transparent;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.35);
}

.btn-sm {
  padding: 5px 12px;
  font-size: 12px;
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}
.btn-ghost:hover {
  background: var(--bg-hover);
  color: var(--text);
  border-color: transparent;
}

.btn-danger {
  color: var(--error);
  border-color: color-mix(in srgb, var(--error) 40%, transparent);
}
.btn-danger:hover {
  background: var(--error-subtle);
  color: var(--error);
  border-color: var(--error);
}

.btn-accent {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 40%, transparent);
}
.btn-accent:hover {
  background: var(--accent-subtle);
  color: var(--accent);
  border-color: var(--accent);
}

/* ---- Search & Pills ---- */
.search-bar {
  display: flex;
  gap: var(--sp-2);
  margin-bottom: var(--sp-6);
}

.search-bar .input { flex: 1; }

.pill-group {
  display: flex;
  gap: 2px;
  background: var(--bg-overlay);
  border-radius: var(--radius-md);
  padding: 3px;
  border: 1px solid var(--border);
}

.pill {
  padding: 5px 14px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--dur) var(--ease);
  border: none;
  background: transparent;
  font-family: var(--font-sans);
}

.pill:hover { color: var(--text-strong); }
.pill.active {
  background: var(--bg-raised);
  color: var(--accent);
  box-shadow: var(--shadow-sm);
}

/* ---- Table ---- */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  box-shadow: var(--shadow-card);
}

table {
  width: 100%;
  border-collapse: collapse;
}

th {
  text-align: left;
  padding: var(--sp-3) var(--sp-4);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  background: var(--bg-overlay);
}

td {
  padding: var(--sp-3) var(--sp-4);
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg-hover); }
tr.clickable { cursor: pointer; }

/* ---- Code / Mono ---- */
.mono {
  font-family: var(--font-mono);
  font-size: 12px;
}

code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--bg-overlay);
  padding: 2px 6px;
  border-radius: 4px;
}

/* ---- Tags / Chips ---- */
.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-1);
}

.tag {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  background: var(--bg-overlay);
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 500;
  color: var(--text);
}

/* ---- Empty States ---- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--sp-12) var(--sp-8);
  text-align: center;
}

.empty-state-icon {
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: var(--sp-5);
  color: var(--text-dim);
  background: var(--bg-overlay);
  border-radius: var(--radius-xl);
}

.empty-state-icon svg {
  width: 28px;
  height: 28px;
  stroke-width: 1.5;
}

.empty-state-icon:not(:has(svg)) {
  font-size: 28px;
  opacity: 0.4;
  background: none;
}

.empty-state-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-strong);
  margin-bottom: var(--sp-2);
}

.empty-state-desc {
  font-size: 13px;
  max-width: 360px;
  line-height: 1.6;
  color: var(--text-muted);
}

/* ---- Score Bar ---- */
.score-bar {
  height: 3px;
  border-radius: 2px;
  background: var(--bg-overlay);
  overflow: hidden;
}

.score-bar-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.3s var(--ease);
}

.score-high .score-bar-fill { background: var(--success); }
.score-medium .score-bar-fill { background: var(--accent); }
.score-low .score-bar-fill { background: var(--text-muted); }

/* ---- Gallery Grid ---- */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: var(--sp-3);
}

.gallery-item {
  aspect-ratio: 1;
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all var(--dur) var(--ease);
  box-shadow: var(--shadow-card);
}

.gallery-item:hover {
  border-color: var(--accent);
  transform: scale(1.03);
  box-shadow: var(--shadow-lg);
}

.gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ---- Loading ---- */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline-flex; }

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================
   Chat
   ============================================ */

.chat-layout {
  display: flex;
  height: 100%;
  overflow: hidden;
}

.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-base);
  position: relative;
}

.scroll-down-btn {
  position: absolute;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-raised);
  color: var(--text-muted);
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  transition: background 0.15s, color 0.15s;
}
.scroll-down-btn:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-3) var(--sp-6);
  border-bottom: 1px solid var(--border);
  background: var(--bg-raised);
  flex-shrink: 0;
}

.chat-header-left {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.chat-header-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-strong);
}

.chat-header-meta {
  font-size: 12px;
  color: var(--text-muted);
}

.chat-thread {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-6) 0;
}

/* Messages */
.chat-msg {
  display: flex;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-8);
  max-width: 860px;
  margin: 0 auto;
  width: 100%;
  border-radius: var(--radius-md);
}

.chat-msg:hover {
  background: rgba(0, 0, 0, 0.015);
}

.chat-msg + .chat-msg {
  margin-top: var(--sp-1);
}

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

.chat-msg-user .chat-msg-avatar {
  background: var(--bg-overlay);
  color: var(--text-muted);
}

.chat-msg-assistant .chat-msg-avatar {
  background: var(--accent);
  color: #fff;
}

.chat-msg-tool .chat-msg-avatar {
  background: var(--info-subtle);
  color: var(--info);
}

.chat-msg-body {
  flex: 1;
  min-width: 0;
}

.chat-msg-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-strong);
  margin-bottom: 3px;
}

.chat-msg-time {
  font-size: 11px;
  color: var(--text-dim);
  margin-left: var(--sp-2);
  font-weight: 400;
}

.chat-msg-content {
  font-size: 14px;
  color: var(--text);
  line-height: 1.65;
  word-break: break-word;
}

/* Markdown */
.chat-msg-content p { margin-bottom: var(--sp-2); }
.chat-msg-content p:last-child { margin-bottom: 0; }
.chat-msg-content strong { color: var(--text-strong); font-weight: 600; }
.chat-msg-content ul, .chat-msg-content ol {
  margin: var(--sp-2) 0;
  padding-left: var(--sp-6);
}
.chat-msg-content li { margin-bottom: var(--sp-1); }
.chat-msg-content pre {
  background: var(--bg-overlay);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--sp-4);
  overflow-x: auto;
  margin: var(--sp-3) 0;
  font-size: 12.5px;
  line-height: 1.5;
}
.chat-msg-content pre code {
  background: none;
  padding: 0;
  font-size: inherit;
}
.chat-msg-content blockquote {
  border-left: 3px solid var(--accent);
  padding-left: var(--sp-4);
  margin: var(--sp-3) 0;
  color: var(--text-muted);
}
.chat-msg-content img, .chat-stream-content img {
  max-width: 200px;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: var(--radius-lg, 12px);
  border: 1px solid var(--border, #333);
  margin: var(--sp-3) 0;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}
.chat-msg-content img:hover, .chat-stream-content img:hover {
  border-color: var(--accent, #6366f1);
  transform: scale(1.03);
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}
.chat-msg-content a { color: var(--accent); }
.chat-msg-content a:hover { text-decoration: underline; }
.chat-msg-content h1, .chat-msg-content h2, .chat-msg-content h3 {
  color: var(--text-strong);
  margin: var(--sp-4) 0 var(--sp-2);
  font-weight: 600;
}
.chat-msg-content h1 { font-size: 18px; }
.chat-msg-content h2 { font-size: 16px; }
.chat-msg-content h3 { font-size: 14px; }

/* Streaming */
.chat-stream-area {
  padding: var(--sp-3) var(--sp-8);
  max-width: 860px;
  margin: 0 auto;
  width: 100%;
}

.chat-stream-wrap {
  display: flex;
  gap: var(--sp-3);
}

.chat-stream-content {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  color: var(--text);
  line-height: 1.65;
  word-break: break-word;
}

.chat-stream-content p { margin-bottom: var(--sp-2); }
.chat-stream-content p:last-child { margin-bottom: 0; }
.chat-stream-content pre {
  background: var(--bg-overlay);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--sp-4);
  overflow-x: auto;
  margin: var(--sp-3) 0;
  font-size: 12.5px;
}
.chat-stream-content pre code { background: none; padding: 0; }

/* Lightbox */
.lightbox {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0,0,0,0.9);
  align-items: center;
  justify-content: center;
  padding: 2rem;
}
.lightbox.active { display: flex; }
.lightbox-content {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.lightbox-content img {
  max-width: 100%;
  max-height: 80vh;
  border-radius: 8px;
  object-fit: contain;
}
.lightbox-info {
  margin-top: 1rem;
  color: #ccc;
  font-size: 0.85rem;
  text-align: center;
  max-width: 600px;
  line-height: 1.4;
}
.lightbox-close {
  position: absolute;
  top: -1rem;
  right: -1rem;
  background: rgba(255,255,255,0.1);
  border: none;
  color: #fff;
  font-size: 2rem;
  cursor: pointer;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.lightbox-close:hover { background: rgba(255,255,255,0.2); }

/* Typing */
.chat-typing {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-8);
  max-width: 860px;
  margin: 0 auto;
  width: 100%;
  color: var(--text-muted);
  font-size: 13px;
}

.chat-typing-dots {
  display: flex;
  gap: 4px;
}

.chat-typing-dots span {
  width: 5px;
  height: 5px;
  background: var(--accent);
  border-radius: 50%;
  animation: typing-bounce 1.2s infinite;
  opacity: 0.5;
}

.chat-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.3; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* Error */
.chat-error {
  margin: var(--sp-2) var(--sp-8);
  max-width: 860px;
  padding: var(--sp-3) var(--sp-4);
  background: var(--error-subtle);
  border: 1px solid rgba(220, 38, 38, 0.15);
  border-radius: var(--radius-md);
  color: var(--error);
  font-size: 13px;
}

/* Compose */
.chat-compose-wrap {
  border-top: 1px solid var(--border);
  background: var(--bg-raised);
  flex-shrink: 0;
}

.chat-compose {
  display: flex;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-8);
  align-items: flex-end;
  max-width: 860px;
  margin: 0 auto;
  width: 100%;
}

.chat-input {
  flex: 1;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 10px 16px;
  color: var(--text-strong);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  resize: none;
  outline: none;
  min-height: 44px;
  max-height: 200px;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}

.chat-input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.chat-input::placeholder { color: var(--text-dim); }

/* Welcome */
.chat-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  text-align: center;
  padding: var(--sp-8);
}

.chat-welcome-icon {
  width: 64px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-subtle);
  border: 1px solid var(--accent-glow);
  border-radius: var(--radius-xl);
  margin-bottom: var(--sp-6);
}

.chat-welcome-icon svg {
  width: 30px;
  height: 30px;
  color: var(--accent);
}

.chat-welcome h2 {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-strong);
  margin-bottom: var(--sp-2);
}

.chat-welcome p {
  font-size: 14px;
  color: var(--text-muted);
  max-width: 400px;
  line-height: 1.6;
}

/* ---- Quick Actions ---- */
.quick-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--sp-3);
}

/* ---- Section Headings ---- */
.section-heading {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-strong);
  margin-bottom: var(--sp-4);
}

/* ---- Utilities ---- */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-xs { gap: var(--sp-1); }
.gap-sm { gap: var(--sp-2); }
.gap-md { gap: var(--sp-4); }
.gap-lg { gap: var(--sp-6); }
.mt-sm { margin-top: var(--sp-2); }
.mt-md { margin-top: var(--sp-4); }
.mt-lg { margin-top: var(--sp-6); }
.mb-sm { margin-bottom: var(--sp-2); }
.mb-md { margin-bottom: var(--sp-4); }
.mb-lg { margin-bottom: var(--sp-6); }
.text-muted { color: var(--text-muted); }
.text-strong { color: var(--text-strong); }
.text-accent { color: var(--accent); }
.text-sm { font-size: 12px; }
.text-xs { font-size: 11px; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.w-full { width: 100%; }

/* ---- Responsive ---- */
@media (max-width: 768px) {
  .sidebar {
    width: 56px;
    min-width: 56px;
  }
  .logo-text, .nav-label, .nav-item span:not(.nav-icon) { display: none; }
  .nav-item {
    justify-content: center;
    padding: var(--sp-2);
    margin: 1px var(--sp-1);
  }
  .sidebar-header { padding: var(--sp-3); justify-content: center; }
  .sidebar-footer { padding: var(--sp-3); display: flex; flex-direction: column; align-items: center; }
  .theme-select { display: none; }
  .theme-icon-btn { display: flex; }
  .status-text { display: none; }
  .status-badge { justify-content: center; }
  .sidebar-user-name, .sidebar-logout-link { display: none; }
  .sidebar-logout-icon { display: flex; align-items: center; justify-content: center; color: var(--text-muted); }
  .sidebar-logout-icon:hover { color: var(--accent); }
  .page-header, .page-content { padding: var(--sp-4); }
  .stat-row { grid-template-columns: 1fr 1fr; }
  .card-grid { grid-template-columns: 1fr; }
  .chat-msg, .chat-compose { padding-left: var(--sp-4); padding-right: var(--sp-4); }
}

/* ---- Toast Notifications ---- */
#toast-container {
  position: fixed;
  top: var(--sp-4);
  right: var(--sp-4);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  pointer-events: none;
}

.toast {
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  max-width: 320px;
  opacity: 0;
  transform: translateX(20px);
  transition: opacity 0.25s var(--ease), transform 0.25s var(--ease);
  pointer-events: auto;
  border: 1px solid var(--border);
  background: var(--bg-raised);
  color: var(--text-strong);
}

.toast-show { opacity: 1; transform: translateX(0); }
.toast-hide { opacity: 0; transform: translateX(20px); }

.toast-success {
  background: var(--success-subtle);
  border-color: color-mix(in srgb, var(--success) 30%, transparent);
  color: var(--success);
}

.toast-error {
  background: var(--error-subtle);
  border-color: color-mix(in srgb, var(--error) 30%, transparent);
  color: var(--error);
}

.toast-info {
  background: var(--accent-subtle);
  border-color: color-mix(in srgb, var(--accent) 30%, transparent);
  color: var(--accent);
}

/* ---- Inline Confirm ---- */
.inline-confirm {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  animation: inline-confirm-in 0.12s var(--ease);
  min-width: 0;
  max-width: 100%;
}
@keyframes inline-confirm-in {
  from { opacity: 0; transform: translateX(-4px); }
  to   { opacity: 1; transform: translateX(0); }
}
.inline-confirm-msg {
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }
