/* ============================================
   Langfuse Lens — SaaS Design System v2
   Aesthetic: Precision Observability
   Dark, depth-layered, glass-accented
   ============================================ */

/* --- Google Fonts --- */
@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&family=IBM+Plex+Mono:wght@400;500;600&display=swap');

/* --- Custom Properties --- */
:root {
  /* Surface layers (deep → shallow) */
  --bg-0: #06080f;
  --bg-1: #0a0e1a;
  --bg-2: #0f1423;
  --bg-3: #141a2e;
  --bg-4: #1a2139;
  --bg-glass: rgba(14, 19, 35, 0.72);

  /* Borders */
  --border-0: rgba(255,255,255,0.04);
  --border-1: rgba(255,255,255,0.07);
  --border-2: rgba(255,255,255,0.10);
  --border-focus: #6366f1;

  /* Text */
  --text-1: #f1f3f9;
  --text-2: #b0b8cd;
  --text-3: #6b7694;
  --text-4: #3d4663;

  /* Brand — Indigo/Violet core */
  --accent: #818cf8;
  --accent-hover: #6366f1;
  --accent-glow: rgba(129, 140, 248, 0.15);
  --accent-strong: #a5b4fc;

  /* Semantic */
  --green: #34d399;
  --green-soft: rgba(52, 211, 153, 0.12);
  --green-glow: rgba(52, 211, 153, 0.06);
  --amber: #fbbf24;
  --amber-soft: rgba(251, 191, 36, 0.12);
  --red: #f87171;
  --red-soft: rgba(248, 113, 113, 0.12);
  --cyan: #22d3ee;
  --cyan-soft: rgba(34, 211, 238, 0.10);
  --violet: #a78bfa;
  --violet-soft: rgba(167, 139, 250, 0.10);

  /* Layout */
  --sidebar-w: 232px;
  --topbar-h: 52px;
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;

  /* Type */
  --font: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Noto Sans KR', sans-serif;
  --mono: 'IBM Plex Mono', 'JetBrains Mono', monospace;

  /* Effects */
  --shadow-card: 0 1px 3px rgba(0,0,0,0.4), 0 0 0 1px var(--border-0);
  --shadow-elevated: 0 8px 32px rgba(0,0,0,0.55), 0 0 0 1px var(--border-1);
  --shadow-glow-accent: 0 0 20px rgba(129, 140, 248, 0.12);
  --transition: 0.18s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-spring: 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* --- Light Theme Override --- */
[data-theme="light"] {
  --bg-0: #ffffff;
  --bg-1: #f8f9fb;
  --bg-2: #f1f3f8;
  --bg-3: #e8ecf4;
  --bg-4: #dde2ee;
  --bg-glass: rgba(255, 255, 255, 0.80);

  --border-0: rgba(0, 0, 0, 0.06);
  --border-1: rgba(0, 0, 0, 0.10);
  --border-2: rgba(0, 0, 0, 0.14);
  --border-focus: #4f46e5;

  --text-1: #0f172a;
  --text-2: #334155;
  --text-3: #64748b;
  --text-4: #94a3b8;

  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-glow: rgba(99, 102, 241, 0.10);
  --accent-strong: #4338ca;

  --green: #059669;
  --green-soft: rgba(5, 150, 105, 0.10);
  --green-glow: rgba(5, 150, 105, 0.05);
  --amber: #d97706;
  --amber-soft: rgba(217, 119, 6, 0.10);
  --red: #dc2626;
  --red-soft: rgba(220, 38, 38, 0.10);
  --cyan: #0891b2;
  --cyan-soft: rgba(8, 145, 178, 0.08);
  --violet: #7c3aed;
  --violet-soft: rgba(124, 58, 237, 0.08);

  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.10), 0 0 0 1px rgba(0, 0, 0, 0.05);
  --shadow-elevated: 0 8px 32px rgba(0, 0, 0, 0.12), 0 0 0 1px rgba(0, 0, 0, 0.06);
  --shadow-glow-accent: 0 0 20px rgba(99, 102, 241, 0.08);
}

[data-theme="light"] ::selection { background: rgba(99, 102, 241, 0.2); }
[data-theme="light"] ::-webkit-scrollbar-thumb { background: rgba(0, 0, 0, 0.12); }
[data-theme="light"] ::-webkit-scrollbar-thumb:hover { background: rgba(0, 0, 0, 0.20); }

[data-theme="light"] .topbar {
  background: rgba(248, 249, 252, 0.85);
}

[data-theme="light"] tbody tr:hover { background: rgba(0, 0, 0, 0.02); }

[data-theme="light"] .toast-success { background: rgba(220, 252, 231, 0.95); color: #065f46; border-color: rgba(5, 150, 105, 0.2); }
[data-theme="light"] .toast-error   { background: rgba(254, 226, 226, 0.95); color: #991b1b; border-color: rgba(220, 38, 38, 0.2); }
[data-theme="light"] .toast-info    { background: rgba(224, 242, 254, 0.95); color: #0c4a6e; border-color: rgba(8, 145, 178, 0.2); }
[data-theme="light"] .toast-warning { background: rgba(254, 243, 199, 0.95); color: #92400e; border-color: rgba(217, 119, 6, 0.2); }

[data-theme="light"] .ai-chat-input-wrap {
  background: linear-gradient(0deg, var(--bg-0) 70%, transparent 100%);
}

[data-theme="light"] .ai-chat-input-bar {
  box-shadow: 0 -4px 30px rgba(0, 0, 0, 0.08), 0 0 0 1px var(--border-0);
}

[data-theme="light"] .skeleton {
  background: linear-gradient(90deg, var(--bg-3) 25%, var(--bg-4) 50%, var(--bg-3) 75%);
  background-size: 200% 100%;
}

/* --- Theme & Locale Toggle Buttons --- */
.topbar-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--border-1);
  border-radius: var(--radius-sm);
  background: var(--bg-2);
  color: var(--text-3);
  cursor: pointer;
  transition: all var(--transition);
  font-size: 11px;
  font-weight: 700;
  font-family: var(--mono);
  line-height: 1;
  padding: 0;
}

.topbar-toggle:hover {
  background: var(--bg-3);
  color: var(--text-1);
  border-color: var(--border-2);
}

.topbar-toggle svg { width: 16px; height: 16px; }

/* Theme icon visibility via CSS */
[data-theme="dark"] .icon-sun,
:root:not([data-theme]) .icon-sun { display: block; }
[data-theme="dark"] .icon-moon,
:root:not([data-theme]) .icon-moon { display: none; }
[data-theme="light"] .icon-sun { display: none; }
[data-theme="light"] .icon-moon { display: block; }

/* --- Reset --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 14px; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }

body {
  font-family: var(--font);
  background: var(--bg-0);
  color: var(--text-1);
  line-height: 1.55;
  overflow-x: hidden;
}

a { color: var(--accent); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--accent-strong); }

::selection { background: rgba(129, 140, 248, 0.3); }

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

/* ============================================
   Page entrance animation
   ============================================ */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes slideInLeft {
  from { opacity: 0; transform: translateX(-16px); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.content { animation: fadeUp 0.4s ease both; }
.content > *:nth-child(1) { animation: fadeUp 0.35s ease both; animation-delay: 0.05s; }
.content > *:nth-child(2) { animation: fadeUp 0.35s ease both; animation-delay: 0.1s; }
.content > *:nth-child(3) { animation: fadeUp 0.35s ease both; animation-delay: 0.15s; }

/* ============================================
   Sidebar
   ============================================ */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--bg-1);
  border-right: 1px solid var(--border-1);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: width var(--transition);
}

/* Subtle gradient edge on right side */
.sidebar::after {
  content: '';
  position: absolute;
  top: 0; right: 0;
  width: 1px;
  height: 100%;
  background: linear-gradient(180deg, var(--accent-glow) 0%, transparent 30%, transparent 70%, var(--accent-glow) 100%);
  pointer-events: none;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  height: var(--topbar-h);
  border-bottom: 1px solid var(--border-0);
}

.sidebar-logo {
  width: 26px; height: 26px;
  color: var(--accent);
  flex-shrink: 0;
  filter: drop-shadow(0 0 6px rgba(129, 140, 248, 0.3));
}

.sidebar-title {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-1);
  white-space: nowrap;
  overflow: hidden;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 8px 8px;
}

.nav-section {
  padding: 18px 10px 5px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-4);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-3);
  font-size: 13px;
  font-weight: 500;
  transition: all var(--transition);
  text-decoration: none;
  position: relative;
}

.nav-item svg {
  width: 17px; height: 17px;
  flex-shrink: 0;
  stroke-width: 1.7;
  transition: color var(--transition);
}

.nav-item:hover {
  color: var(--text-2);
  background: var(--bg-3);
  text-decoration: none;
}

.nav-item.active {
  color: var(--accent);
  background: var(--accent-glow);
}

/* Active indicator bar */
.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 6px; bottom: 6px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
  box-shadow: 0 0 8px rgba(129, 140, 248, 0.4);
}

.sidebar-footer {
  padding: 10px 16px;
  border-top: 1px solid var(--border-0);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-user {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
}

.username-label {
  font-size: 0.75rem;
  color: var(--text-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.logout-btn {
  padding: 0.25rem 0.5rem;
  font-size: 0.6875rem;
  font-family: var(--font);
  color: var(--text-3);
  background: var(--bg-3);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition);
  white-space: nowrap;
}

.logout-btn:hover {
  color: var(--red);
  border-color: var(--red);
}

.version-badge {
  font-size: 10px;
  color: var(--text-4);
  font-family: var(--mono);
  background: var(--bg-3);
  padding: 2px 7px;
  border-radius: 4px;
}

/* Collapsed */
.sidebar.collapsed { width: 56px; }
.sidebar.collapsed .sidebar-title,
.sidebar.collapsed .nav-item span,
.sidebar.collapsed .nav-section,
.sidebar.collapsed .version-badge,
.sidebar.collapsed .sidebar-user { display: none; }
.sidebar.collapsed .sidebar-brand { justify-content: center; padding: 14px 0; }
.sidebar.collapsed .nav-item { justify-content: center; padding: 9px; }
.sidebar.collapsed .nav-item.active::before { display: none; }

/* ============================================
   Main Area
   ============================================ */
.main-area {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  transition: margin-left var(--transition);
}

.sidebar.collapsed ~ .main-area { margin-left: 56px; }

.topbar {
  position: sticky;
  top: 0;
  height: var(--topbar-h);
  background: rgba(10, 14, 26, 0.82);
  backdrop-filter: blur(12px) saturate(1.4);
  -webkit-backdrop-filter: blur(12px) saturate(1.4);
  border-bottom: 1px solid var(--border-0);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 12px;
  z-index: 50;
}

.sidebar-toggle {
  background: none;
  border: 1px solid var(--border-1);
  color: var(--text-3);
  cursor: pointer;
  padding: 5px;
  display: flex;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}

.sidebar-toggle:hover { color: var(--text-1); background: var(--bg-3); border-color: var(--border-2); }
.sidebar-toggle svg { width: 16px; height: 16px; }

.page-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-1);
  letter-spacing: -0.01em;
  flex: 1;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.content {
  padding: 24px;
  max-width: 100%;
}

/* ============================================
   Cards — Glass morphism layered
   ============================================ */
.card {
  background: var(--bg-2);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-card);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.card:hover {
  border-color: var(--border-2);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-1);
  letter-spacing: -0.01em;
}

.card-subtitle {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 2px;
}

/* Grids */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.grid-auto { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }

/* ============================================
   Stat Cards — Elevated with glow
   ============================================ */
.stat-card {
  background: var(--bg-2);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow-card);
  position: relative;
  overflow: hidden;
  transition: all var(--transition);
}

.stat-card:hover {
  border-color: var(--border-2);
  transform: translateY(-1px);
  box-shadow: var(--shadow-elevated);
}

/* Subtle gradient accent on top edge */
.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 20%; right: 20%;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  opacity: 0.3;
}

.stat-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 6px;
}

.stat-value {
  font-size: 30px;
  font-weight: 700;
  color: var(--text-1);
  font-family: var(--mono);
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.stat-detail {
  font-size: 11px;
  color: var(--text-3);
  margin-top: 6px;
  font-family: var(--mono);
}

/* ============================================
   Forms
   ============================================ */
.form-group { margin-bottom: 14px; }

.form-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 5px;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg-1);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-sm);
  color: var(--text-1);
  font-size: 13px;
  font-family: inherit;
  transition: all var(--transition);
  outline: none;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12), var(--shadow-glow-accent);
}

.form-textarea {
  min-height: 100px;
  resize: vertical;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.55;
}

.form-input::placeholder,
.form-textarea::placeholder { color: var(--text-4); }

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}

.form-hint { font-size: 11px; color: var(--text-4); margin-top: 4px; }

/* ============================================
   Buttons
   ============================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  font-family: inherit;
  letter-spacing: -0.01em;
}

.btn svg { width: 15px; height: 15px; }

.btn-primary {
  background: var(--accent-hover);
  color: #fff;
  border-color: var(--accent-hover);
  box-shadow: 0 1px 4px rgba(99, 102, 241, 0.25);
}
.btn-primary:hover {
  background: var(--accent);
  box-shadow: 0 2px 12px rgba(99, 102, 241, 0.35);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--bg-3);
  color: var(--text-2);
  border-color: var(--border-2);
}
.btn-secondary:hover { background: var(--bg-4); color: var(--text-1); }

.btn-danger {
  background: rgba(248, 113, 113, 0.12);
  color: var(--red);
  border-color: rgba(248, 113, 113, 0.2);
}
.btn-danger:hover { background: rgba(248, 113, 113, 0.2); }

.btn-success {
  background: rgba(52, 211, 153, 0.12);
  color: var(--green);
  border-color: rgba(52, 211, 153, 0.2);
}
.btn-success:hover { background: rgba(52, 211, 153, 0.2); }

.btn-ghost {
  background: transparent;
  color: var(--text-3);
  border: none;
  padding: 6px 8px;
}
.btn-ghost:hover { background: var(--bg-3); color: var(--text-1); }

.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-sm svg { width: 13px; height: 13px; }

.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none !important; }

.btn-group { display: flex; gap: 6px; }

/* ============================================
   Tables
   ============================================ */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border-0);
  border-radius: var(--radius);
  background: var(--bg-1);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead th {
  text-align: left;
  padding: 10px 14px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-4);
  background: var(--bg-2);
  border-bottom: 1px solid var(--border-0);
  white-space: nowrap;
}

tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-0);
  color: var(--text-2);
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }

tbody tr { transition: background var(--transition); }
tbody tr:hover { background: rgba(255,255,255,0.02); }

.td-mono { font-family: var(--mono); font-size: 12px; color: var(--accent-strong); }

.td-actions { display: flex; gap: 4px; }

/* ============================================
   Badges & Tags
   ============================================ */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.01em;
  font-family: var(--mono);
}

.badge-success { background: var(--green-soft); color: var(--green); }
.badge-warning { background: var(--amber-soft); color: var(--amber); }
.badge-danger  { background: var(--red-soft);   color: var(--red); }
.badge-info    { background: var(--cyan-soft);   color: var(--cyan); }
.badge-default { background: rgba(255,255,255,0.05); color: var(--text-3); }
.badge-accent  { background: var(--accent-glow); color: var(--accent); }

/* Live dot for running status */
.badge-info::before {
  content: '';
  width: 5px; height: 5px;
  border-radius: 50%;
  background: currentColor;
  margin-right: 4px;
  animation: pulse-dot 1.5s ease-in-out infinite;
}

.tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  background: var(--bg-3);
  color: var(--text-3);
  border: 1px solid var(--border-0);
  font-family: var(--mono);
}

/* ============================================
   Toast
   ============================================ */
.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 12px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  pointer-events: auto;
  animation: toastIn 0.35s var(--transition-spring) both;
  max-width: 380px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.toast-success { background: rgba(6, 78, 59, 0.85); color: #a7f3d0; border: 1px solid rgba(52, 211, 153, 0.2); }
.toast-error   { background: rgba(127, 29, 29, 0.85); color: #fecaca; border: 1px solid rgba(248, 113, 113, 0.2); }
.toast-info    { background: rgba(22, 78, 99, 0.85); color: #a5f3fc; border: 1px solid rgba(34, 211, 238, 0.2); }
.toast-warning { background: rgba(120, 53, 15, 0.85); color: #fed7aa; border: 1px solid rgba(251, 191, 36, 0.2); }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(30px) scale(0.96); }
  to   { opacity: 1; transform: translateX(0) scale(1); }
}

/* ============================================
   Modal — Glass overlay
   ============================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fadeIn 0.2s ease;
}

.modal-overlay[hidden] { display: none; }

.modal {
  background: var(--bg-2);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 540px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow-elevated), 0 0 60px rgba(0,0,0,0.3);
  animation: fadeUp 0.3s var(--transition-spring) both;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border-0);
}

.modal-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.modal-close {
  background: var(--bg-3);
  border: 1px solid var(--border-1);
  color: var(--text-3);
  font-size: 18px;
  cursor: pointer;
  width: 28px; height: 28px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  transition: all var(--transition);
}

.modal-close:hover { color: var(--text-1); background: var(--bg-4); }

.modal-body { padding: 22px; }

.modal-footer {
  padding: 14px 22px;
  border-top: 1px solid var(--border-0);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ============================================
   AI Chat — ChatGPT / Claude / Gemini style
   ============================================ */
.ai-chat {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--topbar-h));
  max-width: 100%;
  position: relative;
}

/* --- Conversation Thread --- */
.ai-chat-thread {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  padding: 24px 0 120px;
}

/* --- Welcome / Empty State --- */
.ai-chat-welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 24px 80px;
  text-align: center;
  animation: fadeUp 0.5s ease both;
}

.ai-chat-welcome-icon {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-glow), rgba(167, 139, 250, 0.12));
  border: 1px solid var(--border-1);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
  box-shadow: 0 0 30px rgba(129, 140, 248, 0.08);
}

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

.ai-chat-welcome-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-1);
  letter-spacing: -0.03em;
  margin-bottom: 8px;
}

.ai-chat-welcome-sub {
  font-size: 14px;
  color: var(--text-3);
  max-width: 420px;
  line-height: 1.6;
  margin-bottom: 32px;
}

/* Suggestion cards grid */
.ai-chat-suggestions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  max-width: 520px;
  width: 100%;
}

.ai-chat-suggest-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 14px 16px;
  background: var(--bg-2);
  border: 1px solid var(--border-1);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition);
  text-align: left;
  font-family: inherit;
  color: var(--text-1);
}

.ai-chat-suggest-card:hover {
  border-color: var(--accent);
  background: var(--bg-3);
  box-shadow: 0 0 20px rgba(129, 140, 248, 0.06);
  transform: translateY(-1px);
}

.suggest-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: var(--accent-glow);
  margin-bottom: 4px;
}

.suggest-icon svg {
  width: 15px;
  height: 15px;
  color: var(--accent);
}

.suggest-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-1);
}

.suggest-desc {
  font-size: 12px;
  color: var(--text-3);
}

/* --- Message Row --- */
.ai-msg {
  display: flex;
  gap: 14px;
  max-width: 780px;
  width: 100%;
  margin: 0 auto;
  padding: 12px 24px;
  animation: fadeUp 0.3s ease both;
}

.ai-msg-user {
  /* User messages get a subtle distinct background band */
}

.ai-msg-assistant {
  /* Default — no extra bg */
}

/* Avatar */
.ai-msg-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 2px;
}

.ai-msg-assistant .ai-msg-avatar {
  background: linear-gradient(135deg, var(--accent-glow), rgba(167, 139, 250, 0.12));
  border: 1px solid var(--border-1);
}

.ai-msg-assistant .ai-msg-avatar svg {
  width: 16px;
  height: 16px;
  color: var(--accent);
}

.ai-msg-user .ai-msg-avatar {
  background: var(--bg-4);
  border: 1px solid var(--border-2);
}

.ai-msg-user .ai-msg-avatar svg {
  width: 15px;
  height: 15px;
  color: var(--text-3);
}

/* Bubble */
.ai-msg-bubble {
  flex: 1;
  min-width: 0;
}

.ai-msg-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-3);
  margin-bottom: 4px;
  letter-spacing: -0.01em;
}

.ai-msg-assistant .ai-msg-label { color: var(--accent); }

.ai-msg-body {
  font-size: 14px;
  line-height: 1.7;
  color: var(--text-1);
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.ai-msg-body p { margin-bottom: 10px; }
.ai-msg-body p:last-child { margin-bottom: 0; }
.ai-msg-body ul, .ai-msg-body ol { margin: 8px 0; padding-left: 20px; }
.ai-msg-body li { margin-bottom: 4px; }
.ai-msg-body strong { color: var(--text-1); font-weight: 600; }
.ai-msg-body a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }

.ai-msg-body pre {
  background: var(--bg-0);
  border: 1px solid var(--border-0);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  overflow-x: auto;
  margin: 10px 0;
  font-size: 12px;
  font-family: var(--mono);
  line-height: 1.6;
  color: var(--text-2);
}

.ai-msg-body code {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--bg-3);
  padding: 1px 5px;
  border-radius: 3px;
  color: var(--accent-strong);
}

.ai-msg-body pre code {
  background: none;
  padding: 0;
  color: inherit;
}

/* Metrics row */
.ai-msg-metrics {
  max-width: 780px;
  width: 100%;
  margin: 0 auto;
  padding: 0 24px 0 68px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* --- Typing indicator --- */
.typing-dots {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 6px 0;
}

.typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.35;
  animation: typingBounce 1.4s ease-in-out infinite;
}

.typing-dots span:nth-child(2) { animation-delay: 0.16s; }
.typing-dots span:nth-child(3) { animation-delay: 0.32s; }

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

/* --- Input Area --- */
.ai-chat-input-wrap {
  position: sticky;
  bottom: 0;
  padding: 0 24px 16px;
  background: linear-gradient(0deg, var(--bg-0) 70%, transparent 100%);
  z-index: 10;
}

.ai-chat-input-bar {
  max-width: 780px;
  margin: 0 auto;
  background: var(--bg-2);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-xl);
  padding: 10px 14px 8px;
  box-shadow: 0 -4px 30px rgba(0, 0, 0, 0.25), 0 0 0 1px var(--border-0);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.ai-chat-input-bar:focus-within {
  border-color: var(--accent);
  box-shadow: 0 -4px 30px rgba(0, 0, 0, 0.25), 0 0 0 1px var(--accent), 0 0 20px rgba(129, 140, 248, 0.06);
}

.ai-chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.ai-chat-textarea {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text-1);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
  resize: none;
  padding: 4px 4px;
  max-height: 200px;
  overflow-y: auto;
}

.ai-chat-textarea::placeholder {
  color: var(--text-4);
}

.ai-chat-send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--accent-hover);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all var(--transition);
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.25);
}

.ai-chat-send-btn:hover {
  background: var(--accent);
  box-shadow: 0 2px 16px rgba(99, 102, 241, 0.4);
  transform: scale(1.05);
}

.ai-chat-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none !important;
}

.ai-chat-send-btn.loading {
  animation: spin 0.8s linear infinite;
}

.ai-chat-send-btn svg {
  width: 16px;
  height: 16px;
}

.ai-chat-input-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 4px 0;
}

.ai-chat-model-select {
  appearance: none;
  -webkit-appearance: none;
  background: var(--bg-3);
  border: 1px solid var(--border-0);
  color: var(--text-3);
  font-size: 11px;
  font-family: inherit;
  padding: 3px 22px 3px 8px;
  border-radius: 4px;
  cursor: pointer;
  outline: none;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%236b7694' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 6px center;
  transition: all var(--transition);
}

.ai-chat-model-select:hover {
  border-color: var(--border-2);
  color: var(--text-2);
}

.ai-chat-model-select:focus {
  border-color: var(--accent);
}

.ai-chat-model-select option {
  background: var(--bg-2);
  color: var(--text-1);
}

.ai-chat-hint {
  font-size: 11px;
  color: var(--text-4);
}

/* Override .content padding for chat page */
.ai-chat { margin: 0 -24px -24px; }

/* ============================================
   Pagination
   ============================================ */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  font-size: 12px;
  color: var(--text-3);
}

.pagination-buttons { display: flex; gap: 4px; }

.pagination-buttons .btn-ghost {
  min-width: 32px; height: 32px;
  border-radius: var(--radius-sm);
}

.pagination-buttons .btn-ghost.active {
  background: var(--accent-glow);
  color: var(--accent);
}

/* ============================================
   Empty / Loading
   ============================================ */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-4);
}

.empty-state svg {
  width: 48px; height: 48px;
  margin-bottom: 12px;
  opacity: 0.25;
  color: var(--accent);
}

.empty-state p { font-size: 13px; margin-bottom: 14px; color: var(--text-3); }

.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border-1);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
  display: inline-block;
}

.spinner-lg { width: 28px; height: 28px; border-width: 2.5px; }

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

.loading-center {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px;
}

.skeleton {
  background: linear-gradient(90deg, var(--bg-3) 25%, var(--border-1) 50%, var(--bg-3) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.8s infinite;
  border-radius: var(--radius-sm);
}

@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ============================================
   Tabs
   ============================================ */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border-0);
  gap: 0;
  margin-bottom: 20px;
}

.tab {
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-4);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: all var(--transition);
  font-family: inherit;
  letter-spacing: -0.01em;
}

.tab:hover { color: var(--text-2); }

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fadeUp 0.25s ease both; }

/* ============================================
   Detail rows
   ============================================ */
.section-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-4);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 10px;
}

.detail-row {
  display: flex;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-0);
  font-size: 13px;
}

.detail-label {
  width: 130px;
  color: var(--text-3);
  flex-shrink: 0;
  font-weight: 500;
}

.detail-value {
  color: var(--text-1);
  flex: 1;
  word-break: break-all;
}

/* ============================================
   Pre-formatted output
   ============================================ */
.pre-wrap {
  white-space: pre-wrap;
  word-wrap: break-word;
  font-family: var(--mono);
  font-size: 12px;
  background: var(--bg-1);
  border: 1px solid var(--border-0);
  border-radius: var(--radius);
  padding: 14px;
  overflow-x: auto;
  max-height: 500px;
  overflow-y: auto;
  line-height: 1.6;
  color: var(--text-2);
}

/* ============================================
   Utility
   ============================================ */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.gap-20 { gap: 20px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-20 { margin-top: 20px; }
.mb-16 { margin-bottom: 16px; }
.mb-20 { margin-bottom: 20px; }
.text-mono { font-family: var(--mono); }
.text-muted { color: var(--text-3); }
.text-sm { font-size: 12px; }
.text-right { text-align: right; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 200px; }
.hidden { display: none !important; }
.w-full { width: 100%; }

/* ============================================
   Sidebar Overlay (mobile)
   ============================================ */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 90;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.sidebar-overlay.visible {
  display: block;
  opacity: 1;
}

/* ============================================
   Responsive
   ============================================ */

/* --- Tablet (≤1024px) --- */
@media (max-width: 1024px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .topbar { padding: 0 16px; }
}

/* --- Mobile (≤768px) --- */
@media (max-width: 768px) {
  /* Sidebar: off-screen by default, slide in on .open */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-w);
    transform: translateX(-100%);
    z-index: 100;
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.3);
  }

  /* Collapsed state doesn't apply on mobile */
  .sidebar.collapsed {
    width: var(--sidebar-w);
    transform: translateX(-100%);
  }
  .sidebar.collapsed.open {
    transform: translateX(0);
  }
  .sidebar.collapsed .sidebar-title,
  .sidebar.collapsed .nav-item span,
  .sidebar.collapsed .nav-section,
  .sidebar.collapsed .version-badge { display: revert; }
  .sidebar.collapsed .sidebar-brand { justify-content: revert; padding: revert; }
  .sidebar.collapsed .nav-item { justify-content: revert; padding: revert; }

  /* Main area: full width */
  .main-area {
    margin-left: 0 !important;
  }

  /* Prevent body scroll when sidebar is open */
  body.sidebar-open {
    overflow: hidden;
  }

  /* Topbar */
  .topbar {
    padding: 0 12px;
    gap: 8px;
  }

  .page-title {
    font-size: 14px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* Content */
  .content {
    padding: 14px;
  }

  /* Grids */
  .grid-2,
  .grid-3 { grid-template-columns: 1fr; }
  .grid-4 { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .form-row { grid-template-columns: 1fr; }

  /* Stat cards */
  .stat-card { padding: 14px; }
  .stat-value { font-size: 26px; }
  .stat-label { font-size: 9px; }

  /* Cards */
  .card { padding: 14px; }
  .card-header { flex-direction: column; align-items: flex-start; gap: 10px; }

  /* Tables */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { min-width: 480px; }

  /* Tabs */
  .tabs { gap: 0; overflow-x: auto; -webkit-overflow-scrolling: touch; flex-wrap: nowrap; }
  .tab { white-space: nowrap; flex-shrink: 0; font-size: 12px; padding: 8px 12px; }

  /* Chat page */
  .ai-chat-welcome h2 { font-size: 18px; }
  .ai-chat-welcome p { font-size: 13px; }
  .ai-chat-welcome-cards { grid-template-columns: 1fr; }
  .ai-chat-input-bar { margin: 0 8px 8px; }

  /* Modal */
  .modal { width: calc(100vw - 24px); max-height: 85vh; margin: auto 12px; }

  /* Buttons */
  .btn-group { flex-wrap: wrap; }

  /* Detail rows */
  .detail-row { flex-direction: column; gap: 2px; }
  .detail-label { min-width: unset; }
}

/* --- Small phones (≤480px) --- */
@media (max-width: 480px) {
  .grid-4 { grid-template-columns: 1fr; }
  .stat-value { font-size: 22px; }
  .topbar-right .btn { display: none; }
  .topbar-toggle { width: 28px; height: 28px; font-size: 10px; }
  .topbar-toggle svg { width: 14px; height: 14px; }
  .content { padding: 10px; }
}
