/* SparkAI admin console — follows the SparkDen design system (sparkden.org):
   warm paper background, Inter + Space Grotesk, Spark orange, hairline cards. */
:root {
  --orange-50: #fff3e9; --orange-100: #ffe4d1; --orange-200: #ffcba8;
  --orange-300: #ffa76f; --orange-400: #ff813d; --orange-500: #ff5b14;
  --orange-600: #e0470a; --orange-700: #c2410c; --orange-800: #9a3412;
  --gray-50: #faf6ef; --gray-100: #f2ece2; --gray-200: #e8e0d3; --gray-300: #d6ccbc;
  --gray-400: #a89c8e; --gray-500: #8a7e72; --gray-600: #5d534a; --gray-700: #443b33;
  --gray-800: #2a231d; --gray-900: #17120e;
  --green-50: #f1f9ed; --green-100: #ddf0d4; --green-500: #4d9e3f; --green-600: #3f8534; --green-700: #336b2b;
  --red-50: #fdf1ee; --red-100: #fadfd8; --red-500: #e04f35; --red-600: #c43d25; --red-700: #a13120;
  --yellow-50: #fff7e6; --yellow-100: #ffeec7; --yellow-500: #fb8b00; --yellow-600: #b45309;
  --blue-50: #eff4fb; --blue-100: #dbe7f6; --blue-500: #3b76c4; --blue-600: #2c5fa3;

  --primary: var(--orange-500);
  --primary-hover: var(--orange-600);
  --paper: #fffdf9;
  --hairline: rgba(23, 18, 14, .08);
  --hairline-strong: rgba(23, 18, 14, .16);

  --font-body: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-display: "Space Grotesk", "Inter", sans-serif;
  --font-serif: "Instrument Serif", Georgia, serif;
  --font-mono: ui-monospace, "SF Mono", "Fira Code", "Fira Mono", monospace;

  --radius-sm: 7px; --radius-md: 10px; --radius-lg: 16px; --radius-full: 9999px;
  --shadow-sm: 0 1px 0 rgba(23,18,14,.03), 0 6px 18px -12px rgba(23,18,14,.18);
  --shadow-md: 0 1px 0 rgba(23,18,14,.03), 0 12px 28px -14px rgba(23,18,14,.22);
  --shadow-lg: 0 1px 0 rgba(23,18,14,.03), 0 24px 50px -24px rgba(23,18,14,.28);
  --shadow-acc: 0 16px 40px -16px rgba(255,91,20,.5);
  --ease-spring: cubic-bezier(.16, 1, .3, 1);
  --sidebar-width: 260px;
}

/* Base ---------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  min-height: 100vh; background: var(--gray-50); color: var(--gray-700);
  font-family: var(--font-body); font-size: 15px; line-height: 1.55;
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
}
a { color: var(--orange-700); text-decoration: none; }
a:hover { color: var(--orange-800); text-decoration: underline; text-underline-offset: 2px; }
h1, h2, h3, h4 { margin: 0 0 .5em; font-family: var(--font-display); font-weight: 600;
  letter-spacing: -.025em; color: var(--gray-900); line-height: 1.15; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 1em; }
code, pre, kbd { font-family: var(--font-mono); }
hr { border: 0; border-top: 1px solid var(--hairline); margin: 24px 0; }
.lucide { width: 18px; height: 18px; stroke-width: 2; flex-shrink: 0; }
[hidden] { display: none !important; }

/* Text helpers */
.muted { color: var(--gray-500); }
.faint { color: var(--gray-400); }
.small { font-size: .82rem; }
.mono { font-family: var(--font-mono); font-size: .86em; }
.num { font-variant-numeric: tabular-nums; }
.strong { font-weight: 600; color: var(--gray-900); }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.right { text-align: right; }
.eyebrow { display: block; font-family: var(--font-mono); font-size: .72rem; font-weight: 500;
  text-transform: uppercase; letter-spacing: .09em; color: var(--primary); margin-bottom: 8px; }
code.inline, .kbd { background: var(--gray-100); border: 1px solid var(--hairline); padding: 1px 6px;
  border-radius: 6px; font-size: .84em; color: var(--gray-800); }

/* Layout helpers */
.stack { display: flex; flex-direction: column; gap: 20px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.grow { flex: 1; min-width: 0; }
.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); align-items: start; }
.mt-0 { margin-top: 0 !important; } .mb-0 { margin-bottom: 0 !important; }
.mt-2 { margin-top: 8px; } .mt-4 { margin-top: 16px; } .mt-6 { margin-top: 24px; }

/* Brand --------------------------------------------------------------------- */
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--gray-900);
  font-family: var(--font-display); font-weight: 700; font-size: 1.2rem; letter-spacing: -.03em; }
.brand:hover { text-decoration: none; color: var(--gray-900); }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; background: var(--primary);
  color: #fff; display: grid; place-items: center; box-shadow: 0 3px 0 var(--orange-600); }
.brand-mark .lucide { width: 19px; height: 19px; fill: #fff; }
.brand em { font-family: var(--font-serif); font-style: italic; font-weight: 400;
  color: var(--primary); font-size: 1.15em; letter-spacing: -.01em; }
.brand-sub { display: block; font-family: var(--font-mono); font-size: .62rem; font-weight: 500;
  letter-spacing: .1em; text-transform: uppercase; color: var(--gray-400); margin-top: 1px; }

/* Buttons ------------------------------------------------------------------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 18px; border: 1px solid transparent; border-radius: var(--radius-md);
  font-family: var(--font-body); font-size: .875rem; font-weight: 600; line-height: 1.3;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: transform .15s ease, background .15s ease, border-color .15s ease, color .15s ease; }
.btn:hover { text-decoration: none; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.btn .lucide { width: 16px; height: 16px; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 2px 0 var(--orange-600); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); color: #fff; }
.btn-secondary { background: #fff; color: var(--gray-700); border-color: var(--hairline-strong); }
.btn-secondary:hover:not(:disabled) { border-color: var(--gray-900); color: var(--gray-900); }
.btn-ghost { background: transparent; color: var(--gray-600); }
.btn-ghost:hover:not(:disabled) { background: var(--gray-100); color: var(--gray-800); }
.btn-dark { background: var(--gray-900); color: #fff; box-shadow: 0 2px 0 #000; }
.btn-dark:hover:not(:disabled) { background: #000; color: #fff; }
.btn-danger { background: var(--red-600); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--red-700); color: #fff; }
.btn-danger-ghost { background: transparent; color: var(--red-600); }
.btn-danger-ghost:hover:not(:disabled) { background: var(--red-50); color: var(--red-700); }
.btn-sm { padding: 6px 12px; font-size: .8rem; }
.btn-lg { padding: 13px 24px; font-size: .95rem; }
.btn-block { width: 100%; }
.btn-icon { padding: 7px; }
.btn-icon.btn-sm { padding: 5px; }
.inline-form { display: inline; margin: 0; }

/* Cards --------------------------------------------------------------------- */
.card { background: #fff; border: 1px solid var(--hairline); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm); min-width: 0; }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap; padding: 16px 22px; border-bottom: 1px solid var(--hairline); }
.card-header h2, .card-header h3 { margin: 0; font-size: 1rem; }
.card-header p { margin: 2px 0 0; font-size: .82rem; color: var(--gray-500); }
.card-body { padding: 22px; }
.card-body.tight { padding: 0; }
.card-footer { display: flex; align-items: center; justify-content: flex-end; gap: 10px;
  padding: 14px 22px; border-top: 1px solid var(--hairline); background: var(--gray-50);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
.card-footer.between { justify-content: space-between; }
a.card-link { display: block; color: inherit; transition: transform .25s var(--ease-spring),
  box-shadow .25s var(--ease-spring), border-color .2s ease; }
a.card-link:hover { text-decoration: none; transform: translateY(-2px); box-shadow: var(--shadow-md);
  border-color: var(--hairline-strong); color: inherit; }
.card.danger { border-color: rgba(196, 61, 37, .25); }
.card.danger .card-header h3 { color: var(--red-700); }

/* Stat tiles */
.stat { padding: 18px 20px; }
.stat-label { display: flex; align-items: center; gap: 7px; font-size: .78rem; font-weight: 500;
  color: var(--gray-500); }
.stat-label .lucide { width: 15px; height: 15px; color: var(--gray-400); }
.stat-value { font-family: var(--font-display); font-size: 1.75rem; font-weight: 600;
  letter-spacing: -.03em; color: var(--gray-900); margin-top: 6px; line-height: 1.1;
  font-variant-numeric: tabular-nums; }
.stat-value small { font-size: .55em; color: var(--gray-400); font-weight: 500; letter-spacing: 0; }
.stat-foot { font-size: .78rem; color: var(--gray-500); margin-top: 6px; }

/* App shell ----------------------------------------------------------------- */
.sidebar { position: fixed; inset: 0 auto 0 0; width: var(--sidebar-width); background: var(--paper);
  border-right: 1px solid var(--hairline); display: flex; flex-direction: column; z-index: 200; }
.sidebar-header { padding: 18px 20px; border-bottom: 1px solid var(--hairline); }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 12px; }
.nav-section { margin-bottom: 14px; }
.nav-section-label { padding: 8px 12px 6px; font-size: .66rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .09em; color: var(--gray-400); }
.nav-item { position: relative; display: flex; align-items: center; gap: 12px; padding: 9px 12px;
  border-radius: var(--radius-md); color: var(--gray-600); font-size: .875rem; font-weight: 500;
  transition: background .2s ease, color .2s ease; }
.nav-item .lucide { transition: transform .2s ease; }
.nav-item:hover { background: var(--orange-50); color: var(--orange-700); text-decoration: none; }
.nav-item:hover .lucide { transform: translateX(2px) scale(1.08); }
.nav-item.active { background: var(--orange-100); color: var(--orange-800); font-weight: 600; }
.nav-item.active::before { content: ""; position: absolute; left: -12px; top: 50%; height: 18px;
  width: 3px; border-radius: 0 3px 3px 0; background: var(--primary); transform: translateY(-50%); }
.nav-badge { margin-left: auto; min-width: 20px; padding: 0 7px; border-radius: 999px;
  font-size: .7rem; font-weight: 700; text-align: center; line-height: 1.6; }
.nav-badge.warn { background: var(--yellow-100); color: var(--yellow-600); }
.nav-badge.bad { background: var(--red-100); color: var(--red-700); }
.sidebar-footer { padding: 14px 16px; border-top: 1px solid var(--hairline); display: flex;
  align-items: center; gap: 10px; }
.sidebar-user { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.sidebar-user-name { font-size: .82rem; font-weight: 600; color: var(--gray-800); }
.sidebar-user-sub { font-size: .7rem; color: var(--gray-500); }
.icon-btn { display: grid; place-items: center; width: 32px; height: 32px; border-radius: var(--radius-md);
  color: var(--gray-400); background: transparent; border: 0; cursor: pointer; flex-shrink: 0; }
.icon-btn:hover { background: var(--red-50); color: var(--red-600); }

.avatar { width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0; object-fit: cover;
  background: var(--orange-100); color: var(--orange-800); display: grid; place-items: center;
  font-family: var(--font-display); font-weight: 600; font-size: .85rem; overflow: hidden; }
.avatar { position: relative; }
.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.avatar.sm { width: 28px; height: 28px; font-size: .72rem; }
.avatar.lg { width: 56px; height: 56px; font-size: 1.2rem; }
.avatar.api { background: var(--blue-50); color: var(--blue-600); }

.app-main { margin-left: var(--sidebar-width); min-height: 100vh; }
.app-content { max-width: 1240px; margin: 0 auto; padding: 32px 40px 64px; }
.topbar { display: none; }
.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px;
  flex-wrap: wrap; margin-bottom: 28px; }
.page-header h1 { font-size: 1.85rem; margin: 0 0 4px; letter-spacing: -.035em; }
.page-header h1 em { font-family: var(--font-serif); font-style: italic; font-weight: 400;
  font-size: 1.08em; color: var(--primary); }
.page-header p { color: var(--gray-500); margin: 0; font-size: .95rem; max-width: 640px; }
.page-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.crumbs { display: flex; align-items: center; gap: 6px; font-size: .8rem; color: var(--gray-500);
  margin-bottom: 10px; }
.crumbs a { color: var(--gray-500); }
.crumbs a:hover { color: var(--orange-700); }
.crumbs .lucide { width: 14px; height: 14px; color: var(--gray-300); }

.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  margin: 32px 0 12px; }
.section-head h2 { margin: 0; font-size: 1.1rem; }
.section-head a { font-size: .82rem; font-weight: 500; }

/* Flash / alerts ------------------------------------------------------------ */
.flashes { display: flex; flex-direction: column; gap: 10px; margin-bottom: 22px; }
.alert { display: flex; align-items: flex-start; gap: 10px; padding: 12px 16px;
  border-radius: var(--radius-md); border: 1px solid var(--hairline); background: #fff;
  font-size: .875rem; color: var(--gray-700); }
.alert .lucide { margin-top: 1px; }
.alert > div { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.alert-success { background: var(--green-50); border-color: var(--green-100); color: var(--green-700); }
.alert-error { background: var(--red-50); border-color: var(--red-100); color: var(--red-700); }
.alert-warn { background: var(--yellow-50); border-color: var(--yellow-100); color: var(--yellow-600); }
.alert-info { background: var(--orange-50); border-color: var(--orange-100); color: var(--orange-800); }
.alert .dismiss { background: none; border: 0; color: inherit; opacity: .6; cursor: pointer; padding: 0; }
.alert .dismiss:hover { opacity: 1; }
.alert b { color: inherit; }

/* Badges -------------------------------------------------------------------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px;
  border-radius: var(--radius-full); font-size: .72rem; font-weight: 600; line-height: 1.5;
  background: var(--gray-100); color: var(--gray-600); white-space: nowrap; }
.badge .lucide { width: 12px; height: 12px; }
.badge-success { background: var(--green-50); color: var(--green-700); }
.badge-warning { background: var(--yellow-50); color: var(--yellow-600); }
.badge-danger { background: var(--red-50); color: var(--red-700); }
.badge-info { background: var(--blue-50); color: var(--blue-600); }
.badge-orange { background: var(--orange-50); color: var(--orange-700); }
.badge-dark { background: var(--gray-900); color: #fff; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--gray-300); flex-shrink: 0; }
.dot.ok { background: var(--green-500); box-shadow: 0 0 0 3px var(--green-50); }
.dot.warn { background: var(--yellow-500); box-shadow: 0 0 0 3px var(--yellow-50); }
.dot.bad { background: var(--red-500); box-shadow: 0 0 0 3px var(--red-50); }
.model-chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px;
  border-radius: var(--radius-sm); background: var(--gray-900); color: #fff;
  font-family: var(--font-mono); font-size: .8rem; font-weight: 500; }

/* Tables -------------------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .875rem; }
th { padding: 10px 16px; text-align: left; font-family: var(--font-mono); font-size: .68rem;
  font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--gray-500);
  background: var(--gray-50); border-bottom: 1px solid var(--hairline); white-space: nowrap; }
td { padding: 12px 16px; border-bottom: 1px solid var(--hairline); color: var(--gray-700);
  vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #fffcf8; }
tr.is-off td { opacity: .55; }
td.actions { text-align: right; white-space: nowrap; }
td.actions .btn, td.actions form { vertical-align: middle; }
.cell-title { font-weight: 600; color: var(--gray-900); }
.cell-title a { color: var(--gray-900); }
.cell-title a:hover { color: var(--orange-700); }
.cell-sub { font-size: .76rem; color: var(--gray-500); margin-top: 1px; }
.empty { text-align: center; padding: 44px 24px; color: var(--gray-500); }
.empty .lucide { width: 28px; height: 28px; color: var(--gray-300); margin-bottom: 8px; }
.empty h3 { color: var(--gray-700); font-size: 1rem; margin-bottom: 4px; }
.empty p { margin: 0 auto 14px; max-width: 380px; font-size: .875rem; }

/* Meters (usage vs limit) */
.meter { min-width: 110px; }
.meter-bar { height: 6px; border-radius: 99px; background: var(--gray-100); overflow: hidden; }
.meter-fill { height: 100%; border-radius: 99px; background: var(--green-500); }
.meter-fill.warn { background: var(--yellow-500); }
.meter-fill.bad { background: var(--red-500); }
.meter-text { display: flex; justify-content: space-between; gap: 8px; font-size: .74rem;
  color: var(--gray-500); margin-bottom: 4px; font-variant-numeric: tabular-nums; }
.meter-text b { color: var(--gray-800); font-weight: 600; }

/* Bar list (top-N breakdowns) */
.barlist { display: flex; flex-direction: column; gap: 12px; }
.barlist-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; font-size: .85rem; }
.barlist-row .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--gray-800); font-weight: 500; }
.barlist-row .val { color: var(--gray-500); font-variant-numeric: tabular-nums; font-size: .8rem; }
.barlist-row .track { grid-column: 1 / -1; height: 6px; background: var(--gray-100); border-radius: 99px; overflow: hidden; }
.barlist-row .track span { display: block; height: 100%; background: var(--orange-400); border-radius: 99px; }

/* Forms --------------------------------------------------------------------- */
.form-group { margin-bottom: 18px; }
.form-group:last-child { margin-bottom: 0; }
.form-label { display: block; margin-bottom: 6px; font-size: .84rem; font-weight: 600; color: var(--gray-700); }
.form-label .opt { font-weight: 400; color: var(--gray-400); }
.form-hint { margin-top: 6px; font-size: .78rem; color: var(--gray-500); }
.form-hint code { font-size: .9em; }
.form-input, select.form-input, textarea.form-input {
  width: 100%; padding: 9px 13px; border: 1.5px solid var(--gray-200); border-radius: var(--radius-md);
  font-size: .9rem; font-family: var(--font-body); color: var(--gray-900); background: #fff;
  transition: border-color .15s ease, box-shadow .15s ease; }
.form-input:hover:not(:focus):not(:disabled) { border-color: var(--gray-300); }
.form-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(255,91,20,.12); }
.form-input::placeholder { color: var(--gray-400); }
.form-input:disabled { background: var(--gray-50); color: var(--gray-500); }
textarea.form-input { resize: vertical; min-height: 90px; line-height: 1.5; }
textarea.form-input.code { font-family: var(--font-mono); font-size: .82rem; }
select.form-input { appearance: none; padding-right: 36px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238a7e72' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; }
.input-group { display: flex; }
.input-group .form-input { border-radius: var(--radius-md) 0 0 var(--radius-md); }
.input-group .addon { display: flex; align-items: center; padding: 0 12px; border: 1.5px solid var(--gray-200);
  border-left: 0; border-radius: 0 var(--radius-md) var(--radius-md) 0; background: var(--gray-50);
  color: var(--gray-500); font-size: .8rem; white-space: nowrap; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 18px; }
.form-grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 18px; }
.form-grid .full, .form-grid-3 .full { grid-column: 1 / -1; }
.fieldset-title { font-family: var(--font-display); font-size: .95rem; font-weight: 600; color: var(--gray-900);
  margin: 6px 0 2px; }
.fieldset-sub { font-size: .8rem; color: var(--gray-500); margin: 0 0 14px; }
.divider { height: 1px; background: var(--hairline); margin: 22px 0; }

/* Toggle switch (label wraps input + track + text) */
.switch { display: flex; align-items: flex-start; gap: 12px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track { position: relative; width: 38px; height: 22px; border-radius: 99px; background: var(--gray-300);
  flex-shrink: 0; transition: background .2s ease; margin-top: 1px; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.2); transition: transform .2s var(--ease-spring); }
.switch input:checked + .track { background: var(--primary); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { outline: 2px solid var(--primary); outline-offset: 2px; }
.switch .text { font-size: .875rem; font-weight: 600; color: var(--gray-800); }
.switch .text small { display: block; font-weight: 400; color: var(--gray-500); font-size: .8rem; margin-top: 1px; }

/* Checkbox pills (multi-select) */
.check-pills { display: flex; flex-wrap: wrap; gap: 8px; }
.check-pill { position: relative; }
.check-pill input { position: absolute; opacity: 0; }
.check-pill span { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px;
  border: 1.5px solid var(--gray-200); border-radius: var(--radius-full); font-family: var(--font-mono);
  font-size: .8rem; cursor: pointer; background: #fff; transition: all .15s ease; }
.check-pill input:checked + span { border-color: var(--primary); background: var(--orange-50); color: var(--orange-800); }
.check-pill input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 2px; }
.check-pills.disabled { opacity: .45; pointer-events: none; }

/* Segmented radio */
.segmented { display: inline-flex; padding: 3px; background: var(--gray-100); border-radius: var(--radius-md); gap: 2px; }
.segmented a, .segmented label { padding: 6px 12px; border-radius: 8px; font-size: .8rem; font-weight: 600;
  color: var(--gray-600); cursor: pointer; }
.segmented a:hover, .segmented label:hover { color: var(--gray-900); text-decoration: none; }
.segmented a.active, .segmented input:checked + label { background: #fff; color: var(--gray-900); box-shadow: var(--shadow-sm); }
.segmented input { position: absolute; opacity: 0; width: 0; }

/* Option cards (radio cards) */
.option-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; }
.option-card { position: relative; }
.option-card input { position: absolute; opacity: 0; }
.option-card .body { display: block; height: 100%; padding: 12px 14px; border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-md); cursor: pointer; transition: all .15s ease; background: #fff; }
.option-card .body b { display: block; font-size: .875rem; color: var(--gray-900); }
.option-card .body small { display: block; font-size: .76rem; color: var(--gray-500); margin-top: 2px; line-height: 1.4; }
.option-card input:checked + .body { border-color: var(--primary); background: var(--orange-50);
  box-shadow: 0 0 0 3px rgba(255,91,20,.08); }
.option-card input:focus-visible + .body { outline: 2px solid var(--primary); outline-offset: 2px; }

/* Disclosure */
details.disclosure > summary { cursor: pointer; list-style: none; display: flex; align-items: center;
  gap: 8px; font-weight: 600; font-size: .875rem; color: var(--gray-700); padding: 4px 0; }
details.disclosure > summary::-webkit-details-marker { display: none; }
details.disclosure > summary .lucide { transition: transform .2s ease; color: var(--gray-400); }
details.disclosure[open] > summary .lucide.chev { transform: rotate(90deg); }
details.disclosure > .disclosure-body { padding-top: 14px; }

/* Dialog -------------------------------------------------------------------- */
dialog.modal { border: 0; padding: 0; border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  width: min(620px, calc(100vw - 32px)); max-height: calc(100vh - 48px); background: #fff; color: inherit; }
dialog.modal::backdrop { background: rgba(23, 18, 14, .35); backdrop-filter: blur(2px); }
dialog.modal[open] { animation: pop .25s var(--ease-spring); }
dialog.modal .modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: 20px 24px 0; }
dialog.modal .modal-head h2 { margin: 0; font-size: 1.2rem; }
dialog.modal .modal-head p { margin: 4px 0 0; font-size: .85rem; color: var(--gray-500); }
dialog.modal .modal-body { padding: 20px 24px; overflow-y: auto; max-height: calc(100vh - 220px); }
dialog.modal .modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 24px;
  border-top: 1px solid var(--hairline); background: var(--gray-50); }
dialog.modal .close { background: none; border: 0; cursor: pointer; color: var(--gray-400); padding: 4px;
  border-radius: 8px; }
dialog.modal .close:hover { background: var(--gray-100); color: var(--gray-800); }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }

/* Secret reveal */
.secret { display: flex; align-items: center; gap: 8px; padding: 10px 10px 10px 14px; margin-top: 10px;
  background: var(--gray-900); border-radius: var(--radius-md); }
.secret code { flex: 1; min-width: 0; color: #b5e08f; font-size: .85rem; word-break: break-all; }
.secret .btn { background: rgba(255,255,255,.1); color: #fff; border-color: rgba(255,255,255,.18); }
.secret .btn:hover { background: rgba(255,255,255,.18); color: #fff; }

/* Code blocks */
pre.code { position: relative; background: var(--gray-900); color: #f2ece2; border-radius: var(--radius-md);
  padding: 16px 18px; overflow-x: auto; font-size: .82rem; line-height: 1.65; margin: 0 0 14px; }
pre.code .k { color: #ffa76f; } pre.code .s { color: #b5e08f; } pre.code .c { color: #a89c8e; } pre.code .n { color: #ffcba8; }
pre.code .copy-btn { position: absolute; top: 8px; right: 8px; padding: 4px 9px; font-size: .72rem;
  background: rgba(255,255,255,.1); color: #fff; border: 1px solid rgba(255,255,255,.18); }
pre.code .copy-btn:hover { background: rgba(255,255,255,.2); color: #fff; }

/* Provider chain (fallback order) */
.chain { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.chain .hop { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: var(--radius-sm);
  background: var(--gray-50); border: 1px solid var(--hairline); font-size: .78rem; color: var(--gray-700); }
.chain .hop.off { text-decoration: line-through; color: var(--gray-400); }
.chain .arrow { color: var(--gray-300); width: 14px; height: 14px; }
.order-num { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 7px;
  background: var(--orange-50); color: var(--orange-700); font-family: var(--font-mono); font-size: .75rem; font-weight: 600; }

/* Checklist */
.checklist { list-style: none; margin: 0; padding: 0; }
.checklist li { display: flex; align-items: flex-start; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--hairline); font-size: .875rem; }
.checklist li:last-child { border-bottom: 0; padding-bottom: 0; }
.checklist li:first-child { padding-top: 0; }
.checklist .tick { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; flex-shrink: 0;
  border: 1.5px solid var(--gray-300); color: transparent; }
.checklist .tick .lucide { width: 13px; height: 13px; }
.checklist li.done .tick { background: var(--green-500); border-color: var(--green-500); color: #fff; }
.checklist li.done .what { color: var(--gray-500); text-decoration: line-through; }
.checklist .what { font-weight: 600; color: var(--gray-800); }

/* Key-value list */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 10px 20px; font-size: .875rem; margin: 0; }
.kv dt { color: var(--gray-500); }
.kv dd { margin: 0; color: var(--gray-800); min-width: 0; overflow-wrap: anywhere; }

/* Charts */
.chart-box { position: relative; height: 240px; }

/* Login --------------------------------------------------------------------- */
.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(900px 500px at 50% -10%, rgba(255,91,20,.10), transparent 60%), var(--gray-50); }
.auth-card { width: 100%; max-width: 420px; padding: 36px 32px 28px; text-align: center; box-shadow: var(--shadow-lg); }
.auth-card .brand { justify-content: center; margin-bottom: 26px; }
.auth-card h1 { font-size: 1.6rem; margin-bottom: 6px; }
.auth-card h1 em { font-family: var(--font-serif); font-style: italic; font-weight: 400; color: var(--primary); }
.auth-card > p { color: var(--gray-500); font-size: .92rem; margin-bottom: 24px; }
.auth-card .alert { text-align: left; margin-bottom: 18px; }
.spark-btn { width: 100%; justify-content: center; }
.spark-btn .lucide { fill: currentColor; }
.auth-foot { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--hairline); font-size: .78rem; color: var(--gray-400); }
.auth-foot a { color: var(--gray-500); }

/* Playground ---------------------------------------------------------------- */
.pg { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 20px; height: calc(100vh - 170px); min-height: 480px; }
.pg-chat { display: grid; grid-template-rows: 1fr auto; overflow: hidden; }
.pg-scroll { overflow-y: auto; padding: 24px; display: flex; flex-direction: column; gap: 18px; }
.pg-empty { margin: auto; text-align: center; color: var(--gray-500); max-width: 360px; }
.pg-empty .brand-mark { width: 48px; height: 48px; border-radius: 14px; margin: 0 auto 14px; }
.pg-empty .brand-mark .lucide { width: 24px; height: 24px; }
.msg { display: flex; gap: 12px; max-width: 85%; }
.msg .av { width: 30px; height: 30px; border-radius: 9px; flex-shrink: 0; display: grid; place-items: center; }
.msg .av .lucide { width: 16px; height: 16px; }
.msg .bubble { padding: 10px 14px; border-radius: 14px; font-size: .92rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg.user .av { background: var(--gray-900); color: #fff; }
.msg.user .bubble { background: var(--gray-900); color: #fff; border-bottom-right-radius: 4px; }
.msg.assistant .av { background: var(--orange-100); color: var(--orange-700); }
.msg.assistant .bubble { background: var(--gray-50); border: 1px solid var(--hairline); color: var(--gray-800); border-bottom-left-radius: 4px; }
.msg .meta { font-size: .72rem; color: var(--gray-400); margin-top: 6px; font-family: var(--font-mono); }
.msg .bubble.err { background: var(--red-50); border-color: var(--red-100); color: var(--red-700); }
.cursor { display: inline-block; width: 7px; height: 15px; background: var(--primary); vertical-align: -2px; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.pg-input { border-top: 1px solid var(--hairline); padding: 12px; display: flex; gap: 10px; align-items: flex-end; }
.pg-input textarea { resize: none; max-height: 180px; min-height: 0; }
.pg-side .card-body { display: flex; flex-direction: column; gap: 16px; }

/* Docs */
.docs-grid { grid-template-columns: 200px minmax(0, 1fr); align-items: start; }
.docs-nav { position: sticky; top: 24px; }
.docs-nav a { display: block; padding: 6px 12px; border-radius: 8px; font-size: .85rem; color: var(--gray-600); }
.docs-nav a:hover { background: var(--orange-50); color: var(--orange-700); text-decoration: none; }
.doc-section { scroll-margin-top: 24px; }

/* Mobile -------------------------------------------------------------------- */
.scrim { display: none; }
@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-main, .pg { grid-template-columns: minmax(0, 1fr); }
  .pg { height: auto; }
  .pg-chat { height: calc(100vh - 200px); min-height: 420px; }
}
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); transition: transform .25s var(--ease-spring); box-shadow: var(--shadow-lg); }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(23,18,14,.3); z-index: 150; }
  .app-main { margin-left: 0; }
  .topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; position: sticky; top: 0;
    z-index: 100; padding: 10px 16px; background: rgba(255,253,249,.92); backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--hairline); }
  .app-content { padding: 22px 16px 48px; }
  .grid-2, .grid-3, .form-grid, .form-grid-3, .docs-grid { grid-template-columns: minmax(0, 1fr); }
  .page-header h1 { font-size: 1.5rem; }
  .hide-sm { display: none !important; }
  .msg { max-width: 94%; }
}
@media (max-width: 520px) {
  .grid-4 { grid-template-columns: minmax(0, 1fr); }
}
