:root {
  --bg: #0b0f19;
  --bg-elevated: #111827;
  --bg-card: #151e30;
  --bg-hover: #1c273d;
  --border: rgba(148, 163, 184, 0.14);
  --border-strong: rgba(148, 163, 184, 0.25);
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --accent: #06b6d4;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  --radius: 14px;
  --radius-sm: 9px;
}

body.light-theme {
  --bg: #f1f5f9;
  --bg-elevated: #ffffff;
  --bg-card: #ffffff;
  --bg-hover: #f8fafc;
  --border: rgba(15, 23, 42, 0.1);
  --border-strong: rgba(15, 23, 42, 0.2);
  --text: #0f172a;
  --text-muted: #64748b;
  --shadow: 0 10px 28px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Vazirmatn', 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.6;
}

.mono, code, pre {
  font-family: 'JetBrains Mono', monospace;
  direction: ltr;
  unicode-bidi: isolate;
}

.hidden { display: none !important; }
.muted { color: var(--text-muted); }
.small { font-size: 12.5px; }

/* Buttons & Inputs */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 15px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.16s ease;
  color: var(--text);
  background: transparent;
}
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn-xs { padding: 4px 8px; font-size: 11.5px; }
.btn-block { width: 100%; }
.btn-primary {
  background: linear-gradient(135deg, var(--primary), #4f46e5);
  color: #fff;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.35);
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost {
  background: rgba(148, 163, 184, 0.08);
  border-color: var(--border);
}
.btn-ghost:hover { background: var(--bg-hover); border-color: var(--border-strong); }
.btn-danger-ghost {
  color: #fca5a5;
  background: rgba(239, 68, 68, 0.09);
  border-color: rgba(239, 68, 68, 0.25);
}
.btn-danger-ghost:hover { background: rgba(239, 68, 68, 0.18); }
.btn-icon {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 15px;
  padding: 4px 6px;
  border-radius: 6px;
}
.btn-icon:hover { color: var(--text); background: rgba(148, 163, 184, 0.12); }

input, select, textarea {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-family: inherit;
  font-size: 13.5px;
  outline: none;
  transition: border-color 0.15s ease;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
}
.search-input { width: 220px; }

.form-stack { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; flex: 1; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--text-muted); }
.field-row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.field-header-inline { display: flex; justify-content: space-between; align-items: center; }
.inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline-form input { width: auto; min-width: 180px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.checkbox-label { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.checkbox-label input { width: auto; }

/* Login */
.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at top right, rgba(99, 102, 241, 0.16), transparent 45%),
              radial-gradient(circle at bottom left, rgba(6, 182, 212, 0.12), transparent 45%),
              var(--bg);
}
.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 28px;
  box-shadow: var(--shadow);
}
.login-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 24px;
}
.login-footer {
  margin-top: 18px;
  text-align: center;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.brand-lockup { display: flex; align-items: center; gap: 12px; }
.brand-logo {
  width: 40px;
  height: 40px;
  border-radius: 11px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
  font-weight: 800;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.brand-title { margin: 0; font-size: 18px; font-weight: 800; letter-spacing: -0.01em; }
.brand-subtitle { margin: 0; font-size: 12px; color: var(--text-muted); }

/* App Shell */
.app-shell {
  display: flex;
  min-height: 100vh;
}
.sidebar {
  width: 268px;
  background: var(--bg-elevated);
  border-inline-end: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.sidebar-header {
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--border);
}
.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px;
}
.nav-group { margin-bottom: 20px; }
.nav-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 0 10px 8px;
}
.nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  margin-bottom: 4px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  text-align: start;
  transition: all 0.14s ease;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item.active {
  background: rgba(99, 102, 241, 0.15);
  color: #fff;
  font-weight: 600;
}
body.light-theme .nav-item.active { color: var(--primary); }
.nav-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.5;
}
.nav-item.active .nav-dot { opacity: 1; background: var(--primary); }

.sidebar-footer {
  padding: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.user-pill { display: flex; align-items: center; gap: 10px; }
.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(99, 102, 241, 0.2);
  color: #a5b4fc;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}
.user-name { font-weight: 700; font-size: 13px; }
.user-role { font-size: 11px; color: var(--text-muted); }
.sidebar-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.main-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.topbar {
  height: 62px;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-elevated);
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-left h2 { margin: 0; font-size: 17px; font-weight: 700; }
.mobile-menu-btn { display: none; }
.endpoint-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12.5px;
}

.announcement {
  margin: 16px 24px 0;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  background: rgba(6, 182, 212, 0.12);
  border: 1px solid rgba(6, 182, 212, 0.28);
  font-size: 13px;
}

.page-body { padding: 22px 24px; flex: 1; }
.tab-panel { display: none; flex-direction: column; gap: 18px; }
.tab-panel.active { display: flex; }

/* Cards & Grids */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.card-header h3 { margin: 0; font-size: 15.5px; font-weight: 700; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.stat-label { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.stat-value { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.progress-track {
  height: 6px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.14);
  overflow: hidden;
  margin-top: 10px;
}
.progress-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--primary), var(--accent));
}
.progress-fill.warn { background: var(--warning); }
.progress-fill.danger { background: var(--danger); }

.two-col-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
}

.chips-wrap { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  background: rgba(99, 102, 241, 0.14);
  border: 1px solid rgba(99, 102, 241, 0.25);
  color: var(--text);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
}
.badge-ok { background: rgba(16, 185, 129, 0.15); color: #34d399; }
.badge-warn { background: rgba(245, 158, 11, 0.15); color: #fbbf24; }
.badge-err { background: rgba(239, 68, 68, 0.16); color: #f87171; }
.badge-muted { background: rgba(148, 163, 184, 0.15); color: var(--text-muted); }

.kv-list { display: flex; flex-direction: column; gap: 10px; }
.kv-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.kv-row:last-child { border-bottom: none; padding-bottom: 0; }

/* Tables */
.table-wrap { overflow-x: auto; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table th, .data-table td {
  padding: 10px 12px;
  text-align: start;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 12px;
}
.data-table tbody tr:hover { background: var(--bg-hover); }

/* Playground */
.playground-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 16px;
  min-height: 70vh;
}
.playground-chat {
  display: flex;
  flex-direction: column;
  height: 72vh;
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: 14px;
}
.chat-msg {
  max-width: 85%;
  padding: 11px 14px;
  border-radius: 12px;
  white-space: pre-wrap;
  word-break: break-word;
}
.chat-msg.user {
  align-self: flex-start;
  background: rgba(99, 102, 241, 0.18);
  border: 1px solid rgba(99, 102, 241, 0.3);
}
.chat-msg.assistant {
  align-self: flex-end;
  background: var(--bg);
  border: 1px solid var(--border);
}
.chat-role-tag {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.chat-input-bar {
  display: flex;
  gap: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  align-items: flex-end;
}
.chat-input-bar textarea { resize: none; }

/* Guides */
.guide-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px;
}
.guide-tab {
  padding: 7px 13px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
  font-size: 12.5px;
}
.guide-tab.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.code-block-wrap {
  position: relative;
  margin: 10px 0 16px;
}
.code-block {
  background: #060911;
  color: #e2e8f0;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  overflow-x: auto;
  font-size: 12.5px;
  line-height: 1.55;
  margin: 0;
}
.copy-code-btn {
  position: absolute;
  top: 8px;
  right: 8px;
}

/* Models Grid */
.models-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}
.model-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 10px;
}

.model-picker-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 130px;
  overflow-y: auto;
  margin-top: 6px;
}
.picker-chip {
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  border: 1px solid var(--border);
  cursor: pointer;
  background: var(--bg);
  color: var(--text-muted);
}
.picker-chip.selected {
  background: rgba(99, 102, 241, 0.22);
  border-color: var(--primary);
  color: var(--text);
}

.bars-list { display: flex; flex-direction: column; gap: 10px; }
.bar-item { display: flex; flex-direction: column; gap: 4px; }
.bar-top { display: flex; justify-content: space-between; font-size: 12.5px; }

.mini-chart {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  height: 140px;
  padding-top: 12px;
}
.chart-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  height: 100%;
  justify-content: flex-end;
}
.chart-bar-wrap {
  width: 100%;
  max-width: 36px;
  height: 92px;
  display: flex;
  align-items: flex-end;
  background: rgba(148, 163, 184, 0.08);
  border-radius: 6px;
  overflow: hidden;
}
.chart-bar {
  width: 100%;
  background: linear-gradient(180deg, var(--accent), var(--primary));
  border-radius: 6px 6px 0 0;
  min-height: 3px;
}
.chart-label { font-size: 10.5px; color: var(--text-muted); }

.preset-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 14px 0;
}

.discover-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  background: var(--bg);
}

/* Modals & Alerts & Toasts */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
}
.modal-card {
  position: relative;
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  padding: 22px;
  box-shadow: var(--shadow);
}
.modal-lg { max-width: 780px; }
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.modal-header h3 { margin: 0; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
}

.alert { padding: 10px 12px; border-radius: var(--radius-sm); font-size: 13px; }
.alert-error {
  background: rgba(239, 68, 68, 0.14);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #fca5a5;
}

.toast-container {
  position: fixed;
  bottom: 20px;
  inset-inline-end: 20px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  font-size: 13px;
}
.toast.ok { border-color: var(--success); }
.toast.err { border-color: var(--danger); }

@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    inset-inline-start: -280px;
    z-index: 40;
    transition: inset-inline-start 0.2s ease;
  }
  .sidebar.open { inset-inline-start: 0; }
  .mobile-menu-btn { display: inline-flex; }
  .playground-layout { grid-template-columns: 1fr; }
  .endpoint-chip { display: none; }
}
