/* ============================================================
   VagaRoute AI — Professional Interface
   Aesthetic: Refined Operator
   Palette: Deep navy-black + warm terracotta accent
   Typography: Syne (display) + DM Sans (body) + JetBrains Mono
   ============================================================ */

/* ============================================================
   DESIGN TOKENS
   ============================================================ */
:root {
  /* Surfaces */
  --bg:             #070811;
  --bg-soft:        #0C0D1A;
  --panel:          #10121F;
  --panel-strong:   #151728;
  --panel-muted:    #1B1D2E;
  --panel-hover:    #181A2A;

  /* Borders */
  --line:           rgba(148, 163, 184, 0.07);
  --line-strong:    rgba(148, 163, 184, 0.12);

  /* Text */
  --text:           #DFE3F0;
  --muted:          #5A6075;
  --muted-light:    #8890A8;

  /* Accent — warm terracotta/amber */
  --accent:         #C4875A;
  --accent-soft:    #D9A67A;
  --accent-strong:  #A36840;
  --accent-dim:     rgba(196, 135, 90, 0.10);
  --accent-glow:    0 0 0 3px rgba(196, 135, 90, 0.15);

  /* Semantic */
  --danger:         #F87171;
  --danger-dim:     rgba(248, 113, 113, 0.10);
  --success:        #34D399;
  --success-dim:    rgba(52, 211, 153, 0.10);
  --warning:        #FBBF24;
  --warning-dim:    rgba(251, 191, 36, 0.10);

  /* Shape */
  --radius-sm:      6px;
  --radius:         10px;
  --radius-lg:      14px;
  --radius-xl:      20px;

  /* Typography */
  --font:           "DM Sans", system-ui, -apple-system, sans-serif;
  --font-display:   "Syne", "DM Sans", sans-serif;
  --font-mono:      "JetBrains Mono", "Cascadia Code", "Consolas", monospace;

  /* Effects */
  --shadow:         0 1px 3px rgba(0,0,0,0.5), 0 4px 16px rgba(0,0,0,0.3);
  --shadow-lg:      0 8px 32px rgba(0,0,0,0.6), 0 32px 64px rgba(0,0,0,0.4);
  --transition:     150ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  background-color: var(--bg);
  min-height: 100dvh;
  background-image:
    radial-gradient(ellipse 70% 40% at 50% -5%, rgba(196, 135, 90, 0.05) 0%, transparent 60%),
    radial-gradient(rgba(148, 163, 184, 0.022) 1px, transparent 1px);
  background-size: 100% 100%, 28px 28px;
}

#app {
  min-height: 100dvh;
  min-width: 0;
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
  color: var(--text);
}

strong {
  font-weight: 600;
}

small {
  font-size: 0.78rem;
  color: var(--muted);
}

.muted {
  color: var(--muted);
}

/* ============================================================
   LAYOUT SHELL
   ============================================================ */
.shell {
  display: grid;
  grid-template-columns: 252px 1fr;
  min-height: 100dvh;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 0;
  background: var(--panel);
  border-right: 1px solid var(--line);
  position: sticky;
  top: 0;
  height: 100dvh;
  overflow-y: auto;
  padding: 1.25rem 0.875rem;
  scrollbar-width: none;
}

.sidebar::-webkit-scrollbar {
  display: none;
}

/* Brand */
.brand {
  padding: 0.875rem 0.5rem 1.125rem;
  border-bottom: 1px solid var(--line);
  margin-bottom: 0.875rem;
}

.brand h1 {
  font-family: var(--font-display);
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  color: var(--text);
  margin: 0.5rem 0 0.35rem;
}

.brand p {
  font-size: 0.775rem;
  color: var(--muted);
  line-height: 1.5;
}

/* Nav */
.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.nav button {
  display: flex;
  align-items: center;
  width: 100%;
  text-align: left;
  padding: 0.575rem 0.75rem;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--muted-light);
  font: 500 0.875rem var(--font);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  letter-spacing: 0.005em;
  position: relative;
}

.nav button:hover {
  background: var(--panel-hover);
  color: var(--text);
}

.nav button.active {
  background: var(--accent-dim);
  color: var(--accent-soft);
  font-weight: 600;
}

.nav button.active::after {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 2px;
  height: 60%;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
}

/* Sidebar footer */
.sidebar-foot {
  margin-top: auto;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
}

.sidebar-foot strong {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-foot .muted {
  font-size: 0.775rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

/* ============================================================
   MAIN CONTENT AREA
   ============================================================ */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 100dvh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.875rem 1.5rem;
  border-bottom: 1px solid var(--line);
  background: rgba(16, 18, 31, 0.85);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.headline h2 {
  font-family: var(--font-display);
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: -0.015em;
  color: var(--text);
}

.headline p {
  font-size: 0.775rem;
  color: var(--muted);
  margin-top: 0.1rem;
}

.content {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  flex: 1;
}

/* ============================================================
   PANELS & CARDS
   ============================================================ */
.panel,
.chat-card,
.metric-card,
.play-card,
.playground-menu,
.playground-stage,
.playground-editor,
.playground-preview,
.playground-response {
  background: var(--panel);
  border: 1px solid var(--line);
}

.panel,
.metric-card,
.play-card,
.chat-card {
  border-radius: var(--radius-lg);
  padding: 1.25rem;
}

/* Stat cards — large numbers on overview */
.stat-card {
  padding: 1.25rem;
  border-radius: var(--radius-lg);
  background: var(--panel);
  border: 1px solid var(--line-strong);
  position: relative;
  overflow: hidden;
}

.stat-card::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--accent) 0%, var(--accent-soft) 60%, transparent 100%);
  opacity: 0.6;
}

.stat-card > span.muted {
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.stat-card strong {
  display: block;
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.04em;
  color: var(--text);
  margin: 0.5rem 0 0.3rem;
  line-height: 1;
}

.stat-card small {
  font-size: 0.775rem;
  color: var(--muted);
}

/* Chart cards */
.chart-card {
  padding: 1.25rem;
  border-radius: var(--radius-lg);
  background: var(--panel-strong);
  border: 1px solid var(--line);
  min-width: 0;
}

.chart-card h3 {
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-bottom: 0.2rem;
}

/* ============================================================
   GRID LAYOUTS
   ============================================================ */
.grid-3,
.grid-2,
.settings-grid,
.metrics-summary-grid,
.metrics-layout {
  display: grid;
  gap: 1rem;
}

.grid-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.grid-2,
.settings-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.metrics-summary-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.metrics-layout {
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 0.75fr);
  align-items: start;
}

/* ============================================================
   TAGS / BADGES
   ============================================================ */
.tag {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.55rem;
  border-radius: 4px;
  font-size: 0.73rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  background: var(--panel-muted);
  border: 1px solid var(--line-strong);
  color: var(--muted-light);
  white-space: nowrap;
}

.tag.success {
  background: var(--success-dim);
  border-color: rgba(52, 211, 153, 0.2);
  color: var(--success);
}

.tag.warn {
  background: var(--warning-dim);
  border-color: rgba(251, 191, 36, 0.2);
  color: var(--warning);
}

.tag.danger {
  background: var(--danger-dim);
  border-color: rgba(248, 113, 113, 0.2);
  color: var(--danger);
}

/* ============================================================
   FORMS
   ============================================================ */
form {
  display: grid;
  gap: 0.875rem;
}

label {
  display: grid;
  gap: 0.3rem;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted-light);
  letter-spacing: 0.01em;
}

input,
textarea,
select {
  width: 100%;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: var(--bg-soft);
  color: var(--text);
  font: 400 0.875rem var(--font);
  padding: 0.575rem 0.75rem;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  -webkit-appearance: none;
  appearance: none;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: var(--accent-glow);
}

input::placeholder,
textarea::placeholder {
  color: var(--muted);
}

textarea {
  min-height: 100px;
  resize: vertical;
  line-height: 1.6;
  font-family: var(--font);
}

.playground-editor textarea {
  min-height: 200px;
  height: 200px;
  max-height: 200px;
  resize: none;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  line-height: 1.7;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.primary-button,
.secondary-button,
.ghost-button,
.danger-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.575rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font: 500 0.875rem var(--font);
  cursor: pointer;
  white-space: nowrap;
  outline: none;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.primary-button {
  background: var(--accent);
  color: #080810;
  font-weight: 600;
  border-color: var(--accent);
}

.primary-button:hover {
  background: var(--accent-soft);
  border-color: var(--accent-soft);
}

.secondary-button {
  background: var(--panel-muted);
  color: var(--text);
  border-color: var(--line-strong);
}

.secondary-button:hover {
  background: var(--panel-strong);
  border-color: var(--accent);
  color: var(--accent-soft);
}

.ghost-button {
  background: transparent;
  color: var(--muted-light);
  border-color: var(--line-strong);
}

.ghost-button:hover {
  background: var(--panel-hover);
  color: var(--text);
}

.danger-button {
  background: var(--danger-dim);
  color: var(--danger);
  border-color: rgba(248, 113, 113, 0.18);
}

.danger-button:hover {
  background: rgba(248, 113, 113, 0.18);
  border-color: var(--danger);
}

/* ============================================================
   METRICS TABS
   ============================================================ */
.metrics-tabs {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.metrics-tabs button {
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 0.4rem 0.875rem;
  border-radius: var(--radius-sm);
  font: 500 0.8125rem var(--font);
  cursor: pointer;
  outline: none;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.metrics-tabs button.active {
  background: var(--accent-dim);
  border-color: rgba(196, 135, 90, 0.2);
  color: var(--accent-soft);
}

.metrics-tabs button:hover:not(.active) {
  background: var(--panel-hover);
  color: var(--text);
}

/* ============================================================
   BUTTON ROW UTILITIES
   ============================================================ */
.button-row,
.row-between,
.inline-form {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.row-between {
  justify-content: space-between;
}

/* ============================================================
   FLASH MESSAGES
   ============================================================ */
.flash {
  padding: 0.875rem 1rem;
  border-radius: var(--radius);
  background: var(--panel-strong);
  border: 1px solid var(--line-strong);
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.flash strong {
  font-size: 0.875rem;
  color: var(--text);
}

.flash p {
  font-size: 0.8rem;
  color: var(--muted-light);
}

.flash.error {
  background: var(--danger-dim);
  border-color: rgba(248, 113, 113, 0.2);
}

.flash.error strong {
  color: var(--danger);
}

/* ============================================================
   EMPTY STATE
   ============================================================ */
.empty-state {
  padding: 1.5rem;
  border-radius: var(--radius);
  background: var(--bg-soft);
  border: 1px dashed var(--line-strong);
  color: var(--muted);
  font-size: 0.8125rem;
  text-align: center;
}

/* ============================================================
   TABLES
   ============================================================ */
.table-wrap {
  overflow-x: auto;
  max-width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  margin-top: 0.875rem;
}

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

thead {
  background: var(--panel-strong);
}

th,
td {
  padding: 0.65rem 0.875rem;
  text-align: left;
  font-size: 0.8125rem;
  border-bottom: 1px solid var(--line);
}

th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

td {
  color: var(--text);
  font-size: 0.8125rem;
}

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

tbody tr {
  transition: background var(--transition);
}

tbody tr:hover td {
  background: var(--panel-hover);
}

/* ============================================================
   METRICS COMPONENTS
   ============================================================ */
.metrics-shell {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.metrics-side-stack,
.metrics-summary-grid,
.leaderboard,
.stats-list {
  display: grid;
  gap: 0.5rem;
}

.metrics-hero {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
}

.metrics-kpis {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.metrics-kpis > div {
  min-width: 120px;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  background: var(--bg-soft);
  border: 1px solid var(--line);
}

.metrics-kpis span.muted {
  font-size: 0.73rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  display: block;
}

.metrics-kpis strong {
  display: block;
  margin-top: 0.35rem;
  font-family: var(--font-display);
  font-size: 1.0625rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  color: var(--text);
}

/* Chart legend */
.chart-legend {
  display: flex;
  gap: 0.875rem;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 0.8rem;
}

.legend-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  margin-right: 0.3rem;
  vertical-align: middle;
}

.legend-dot.total {
  background: rgba(196, 135, 90, 0.4);
}

.legend-dot.prompt {
  background: var(--accent);
}

.legend-dot.completion {
  background: #38BDF8;
}

.trend-chart {
  width: 100%;
  height: auto;
  margin-top: 1rem;
}

.chart-axis {
  fill: none;
  stroke: var(--line-strong);
}

.trend-bar {
  fill: rgba(196, 135, 90, 0.07);
  stroke: none;
}

.chart-line {
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart-line.prompt,
.chart-dot.prompt {
  stroke: var(--accent);
}

.chart-dot.prompt {
  fill: var(--accent);
}

.chart-line.completion,
.chart-dot.completion {
  stroke: #38BDF8;
}

.chart-dot.completion {
  fill: #38BDF8;
}

.trend-chart text {
  fill: var(--muted);
  font-family: var(--font-mono);
  font-size: 10px;
}

/* Leaderboard rows */
.leaderboard {
  margin-top: 0.75rem;
}

.leaderboard-row {
  padding: 0.75rem 0.875rem;
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  display: grid;
  gap: 0.5rem;
}

.stack-bar {
  display: flex;
  height: 4px;
  border-radius: 2px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.05);
}

.stack-bar .prompt {
  background: var(--accent);
}

.stack-bar .completion {
  background: #38BDF8;
}

.token-split {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 0.775rem;
}

.token-split strong {
  color: var(--text);
}

.stats-list {
  margin-top: 0.75rem;
}

.stats-list div {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.575rem 0.75rem;
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  font-size: 0.8125rem;
}

.stats-list strong {
  font-size: 0.875rem;
}

/* ============================================================
   AUTH LAYOUT
   ============================================================ */
.auth-layout {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.auth-card {
  width: min(880px, 100%);
  border-radius: var(--radius-xl);
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow-lg);
}

.auth-copy {
  padding: 2.5rem;
  background: var(--panel-strong);
  position: relative;
  overflow: hidden;
}

.auth-copy::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 60% 60% at 20% 85%, rgba(196, 135, 90, 0.08) 0%, transparent 60%);
  pointer-events: none;
}

.auth-copy h1 {
  font-family: var(--font-display);
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: -0.04em;
  color: var(--text);
  margin: 0.75rem 0 0.75rem;
  line-height: 1.1;
}

.auth-copy p,
.auth-copy li {
  color: var(--muted-light);
  font-size: 0.875rem;
  margin: 0;
}

.auth-copy ul {
  padding-left: 0;
  list-style: none;
  margin: 1.25rem 0 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.auth-copy li {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}

.auth-copy li::before {
  content: '→';
  color: var(--accent);
  flex-shrink: 0;
}

.auth-form {
  padding: 2.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  background: var(--panel);
}

.auth-form h1 {
  font-size: 1.375rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin: 0.35rem 0 0.25rem;
}

.auth-form .muted {
  font-size: 0.8125rem;
}

/* ============================================================
   CHAT
   ============================================================ */
.chat-log {
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  max-height: 420px;
  overflow-y: auto;
  padding: 0.25rem 0;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.bubble {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  max-width: 84%;
  white-space: pre-wrap;
  line-height: 1.6;
  font-size: 0.875rem;
}

.bubble strong {
  display: block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 0.375rem;
  opacity: 0.7;
}

.bubble.user {
  margin-left: auto;
  background: var(--accent-dim);
  border: 1px solid rgba(196, 135, 90, 0.2);
}

.bubble.user strong {
  color: var(--accent);
}

.bubble.assistant {
  background: var(--panel-strong);
  border: 1px solid var(--line);
}

.bubble.system {
  background: var(--panel-muted);
  border: 1px solid var(--line);
  color: var(--muted-light);
  font-size: 0.8rem;
}

/* ============================================================
   CODE BLOCKS
   ============================================================ */
.play-card pre,
.code-block,
.playground-code {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  max-height: 300px;
  overflow-x: auto;
  overflow-y: auto;
  padding: 0.875rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  font-family: var(--font-mono);
  font-size: 0.79rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.75;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

/* ============================================================
   METER
   ============================================================ */
.meter {
  height: 4px;
  border-radius: 2px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.06);
  margin-top: 0.5rem;
}

.meter span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent) 0%, var(--accent-soft) 100%);
}

/* ============================================================
   PLAYGROUND
   ============================================================ */
.playground-shell {
  display: grid;
  grid-template-columns: 210px 1fr;
  gap: 1rem;
  min-width: 0;
}

.playground-menu {
  border-radius: var(--radius-lg);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-content: start;
  min-width: 0;
}

.playground-menu > div:first-child {
  margin-bottom: 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--line);
}

.playground-menu h3 {
  margin-bottom: 0.25rem;
}

.playground-menu > button,
.playground-menu button {
  width: 100%;
  justify-content: flex-start;
  text-align: left;
  font-family: var(--font-mono);
  font-size: 0.775rem;
}

.playground-stage {
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  display: grid;
  gap: 1rem;
  min-width: 0;
}

.playground-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  align-items: flex-start;
  min-width: 0;
}

.playground-toolbar .tag {
  font-family: var(--font-mono);
  font-size: 0.73rem;
}

.playground-toolbar h3 {
  margin: 0.5rem 0 0.2rem;
}

.playground-toolbar p.muted {
  font-size: 0.775rem;
}

.playground-toolbar-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
  width: 100%;
  min-width: 0;
}

.playground-columns {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr);
  gap: 1rem;
  min-width: 0;
}

.playground-editor,
.playground-preview {
  border-radius: var(--radius);
  padding: 1rem;
  display: grid;
  gap: 0.875rem;
  min-width: 0;
  max-width: 100%;
}

.playground-tabs {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.playground-response {
  border-radius: var(--radius-sm);
  padding: 0.875rem;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}

.playground-response .playground-code {
  max-height: 240px;
  margin-top: 0.5rem;
}

.playground-response > strong {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted-light);
  margin-bottom: 0.35rem;
}

/* ============================================================
   LIMITS
   ============================================================ */
.limit-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(256px, 1fr));
  gap: 1rem;
}

.limit-card {
  display: grid;
  gap: 0.75rem;
  padding: 1rem;
  border-radius: var(--radius);
  background: var(--bg-soft);
  border: 1px solid var(--line);
}

.limit-field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.625rem;
}

/* ============================================================
   SETTINGS
   ============================================================ */
.settings-shell {
  display: grid;
  grid-template-columns: 196px minmax(0, 1fr);
  gap: 1rem;
  min-width: 0;
}

.settings-nav,
.settings-page {
  min-width: 0;
}

.settings-nav {
  display: grid;
  gap: 0.5rem;
  align-content: start;
  height: fit-content;
}

.settings-nav-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.settings-nav-list button {
  width: 100%;
  justify-content: flex-start;
  text-align: left;
}

.settings-page {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.settings-page-hero {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
}

.settings-page-hero h3,
.modal-card h3 {
  font-size: 1rem;
  margin: 0.35rem 0 0.25rem;
}

/* ============================================================
   MODAL
   ============================================================ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(7, 8, 17, 0.82);
  display: grid;
  place-items: center;
  padding: 1.5rem;
  z-index: 50;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.modal-card {
  width: min(660px, 100%);
  max-height: min(85vh, 800px);
  overflow-y: auto;
  background: var(--panel-strong);
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow-lg);
  border-radius: var(--radius-xl);
  padding: 1.5rem;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

/* ============================================================
   TUTORIAL / GUIDE
   ============================================================ */
.tutorial-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 1rem;
}

.tutorial-item {
  padding: 0.875rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-left: 2px solid var(--accent);
}

.tutorial-item strong {
  display: block;
  font-size: 0.875rem;
  margin-bottom: 0.3rem;
  color: var(--text);
}

.tutorial-item p {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--muted-light);
  line-height: 1.55;
}

/* ============================================================
   CUSTOM PROVIDERS
   ============================================================ */
input[type="checkbox"],
input[type="radio"] {
  width: auto;
  padding: 0;
  min-width: 0;
  accent-color: var(--accent);
  -webkit-appearance: checkbox;
  appearance: checkbox;
}

.cp-models-section {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0.875rem;
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  border: 1px solid var(--line);
}

.cp-model-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 0.5rem;
  align-items: center;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--line);
}

.cp-model-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.cp-model-row:first-child {
  padding-top: 0;
}

.cp-check {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--muted-light);
  white-space: nowrap;
  cursor: pointer;
  padding: 0 0.25rem;
}

.cp-check input {
  cursor: pointer;
}

.cp-provider-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.875rem;
}

.cp-provider-row {
  padding: 1rem;
  border-radius: var(--radius);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  transition: border-color var(--transition);
}

.cp-provider-row--editing {
  border-color: var(--accent);
}

.cp-provider-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.4rem;
  flex-wrap: wrap;
  font-size: 0.78rem;
}

.cp-model-tags {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}

/* ============================================================
   SCROLLBARS
   ============================================================ */
::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--panel-muted);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--muted);
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1200px) {
  .shell {
    grid-template-columns: 220px 1fr;
  }

  .playground-shell,
  .playground-columns,
  .playground-toolbar-grid,
  .settings-shell,
  .metrics-layout,
  .metrics-summary-grid,
  .grid-3,
  .grid-2,
  .settings-grid {
    grid-template-columns: 1fr;
  }

  .auth-card {
    grid-template-columns: 1fr;
  }

  .auth-copy {
    display: none;
  }
}

@media (max-width: 768px) {
  .shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--line);
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.75rem;
    padding: 0.875rem;
    order: 2;
  }

  .brand {
    display: none;
  }

  .nav {
    flex-direction: row;
    flex: 0;
    gap: 4px;
  }

  .nav button.active::after {
    display: none;
  }

  .main {
    order: 1;
  }

  .content {
    padding: 1rem;
  }

  .topbar {
    padding: 0.75rem 1rem;
  }

  .metrics-hero {
    flex-direction: column;
  }

  .settings-page-hero {
    flex-direction: column;
    align-items: stretch;
  }

  .bubble {
    max-width: 100%;
  }

  .limit-field-grid {
    grid-template-columns: 1fr;
  }

  .metrics-tabs {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .sidebar-foot {
    display: none;
  }
}
