/* ============================================================
   SD-Server WebUI — Redesign
   Font: Plus Jakarta Sans + JetBrains Mono
   Theme: Clean minimal developer tool
   ============================================================ */

/* --- Design Tokens ----------------------------------------- */
:root {
  /* Palette (hue/sat driven; JS may override --palette-h) */
  --palette-h: 206;
  --palette-s: 80%;
  --palette-l: 44%;

  /* Brand colors */
  --primary:       hsl(var(--palette-h), var(--palette-s), var(--palette-l));
  --primary-light: hsl(var(--palette-h), var(--palette-s), calc(var(--palette-l) + 14%));
  --primary-dark:  hsl(var(--palette-h), var(--palette-s), calc(var(--palette-l) - 12%));
  --accent:        var(--primary);
  --accent-soft:   hsl(var(--palette-h), 50%, 93%);
  --accent-2:      hsl(calc(var(--palette-h) + 28), 60%, 60%);

  /* Default surface system (day mode) */
  --bg:           hsl(var(--palette-h), 20%, 96%);
  --surface:      #ffffff;
  --surface2:     hsl(var(--palette-h), 28%, 93%);
  --border:       hsl(var(--palette-h), 18%, 82%);
  --border-light: hsl(var(--palette-h), 18%, 90%);

  /* Text */
  --text-strong: hsl(var(--palette-h), 24%, 11%);
  --text-main:   hsl(var(--palette-h), 16%, 30%);
  --text-soft:   hsl(var(--palette-h), 12%, 52%);

  /* Semantic */
  --success: #1a9368;
  --warning: #c07814;
  --danger:  #c83550;

  /* Inputs */
  --input-bg:  #ffffff;
  --chip-bg:   var(--surface2);
  --code-bg:   hsl(var(--palette-h), 24%, 95%);

  /* Shadow / border alias */
  --panel-shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 14px rgba(0,0,0,.07);
  --panel-border: var(--border);

  /* Radius scale */
  --radius-sm: 8px;
  --radius:    12px;
  --radius-md: 14px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  /* Typography */
  --sans: "Plus Jakarta Sans", "PingFang SC", "Hiragino Sans GB",
          "Microsoft YaHei UI", "Noto Sans SC", sans-serif;
  --mono: "JetBrains Mono", "Cascadia Code", "SFMono-Regular", Consolas, monospace;

  /* Motion */
  --transition: 150ms ease;
}

/* --- Reset -------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.6;
  background: var(--bg);
  color: var(--text-main);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  transition: background .25s, color .25s;
}

input, select, textarea, button { font: inherit; }

/* --- App Shell --------------------------------------------- */
.app-shell {
  width: min(1440px, calc(100vw - 2rem));
  margin: 1rem auto 3rem;
}

/* --- Header ------------------------------------------------ */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.8rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--panel-shadow);
  position: sticky;
  top: 0.75rem;
  z-index: 30;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  flex: none;
  background: linear-gradient(140deg, var(--primary-light), var(--primary));
  box-shadow: 0 2px 10px color-mix(in srgb, var(--primary) 32%, transparent);
  position: relative;
  overflow: hidden;
}

.brand-mark::after {
  content: "";
  position: absolute;
  inset: 24% 22%;
  border-radius: 5px;
  background: rgba(255, 255, 255, .86);
  transform: rotate(12deg);
}

.brand-topline {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.brand h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--text-strong);
  letter-spacing: -.02em;
}

.brand p { display: none; }
.brand-copy p { display: none; }

.brand-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-soft);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .07em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.help-wrap,
.settings-wrap { position: relative; }

.icon-button {
  width: 34px;
  height: 34px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-soft);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition);
}

.icon-button:hover,
.icon-button.on {
  background: var(--border-light);
  color: var(--primary-dark);
  border-color: var(--primary-light);
}

/* --- Menus ------------------------------------------------- */
.menu-panel {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 4px 28px rgba(0, 0, 0, .13);
  padding: 14px;
  display: none;
  flex-direction: column;
  gap: 10px;
  z-index: 60;
}

.menu-panel.on { display: flex; }
.help-menu    { width: min(320px, calc(100vw - 24px)); }
.settings-menu { width: min(340px, calc(100vw - 24px)); }

.menu-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-soft);
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-light);
}

.help-list { display: grid; gap: 6px; }

.help-item {
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  background: var(--surface2);
  border: 1px solid var(--border-light);
  color: var(--text-soft);
  font-size: 12px;
  line-height: 1.6;
}

.settings-stack { display: grid; gap: 10px; }

/* --- Top strip --------------------------------------------- */
.top-strip {
  margin-top: 10px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--panel-shadow);
}

.compact-shell { border-radius: var(--radius-md); }

.status-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text-main);
  font-size: 12px;
  font-weight: 600;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--warning);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--warning) 16%, transparent);
}

.status-dot.ok {
  background: var(--success);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--success) 16%, transparent);
}

.status-dot.bad {
  background: var(--danger);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 16%, transparent);
}

.top-actions { margin-left: auto; }

/* --- Tabbar ------------------------------------------------ */
.tabbar {
  display: flex;
  gap: 3px;
  flex-wrap: wrap;
  margin-top: 10px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--panel-shadow);
  width: fit-content;
  max-width: 100%;
  overflow-x: auto;
}

.tab-button {
  white-space: nowrap;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-soft);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: all var(--transition);
}

.tab-button:hover {
  background: var(--surface2);
  color: var(--text-main);
  transform: none;
}

.tab-button[aria-selected="true"] {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  box-shadow: 0 2px 10px color-mix(in srgb, var(--primary) 28%, transparent);
}

.tab-panel {
  display: none;
  margin-top: 12px;
  animation: fadeIn 140ms ease;
}

.tab-panel.active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* --- Cards ------------------------------------------------- */
.hero-card,
.section-shell,
.info-card,
.api-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--panel-shadow);
  padding: 1.125rem;
}

/* hero-gradient alias used on backgrounds */
.hero-card,
.section-shell,
.info-card,
.api-card {
  background: var(--surface);
}

.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1rem;
}

.section-heading h3,
.section-heading h4,
.section-heading h5 {
  margin: 0;
  color: var(--text-strong);
  font-weight: 700;
  letter-spacing: -.01em;
}

.section-heading h3 { font-size: 14.5px; }
.section-heading h4 { font-size: 13.5px; }
.section-heading h5 { font-size: 13px; }

.section-heading p,
.info-card p {
  margin: 4px 0 0;
  color: var(--text-soft);
  font-size: 12.5px;
  line-height: 1.6;
}

/* --- Layout Grids ------------------------------------------ */
.workspace-grid,
.settings-grid,
.form-grid,
.mini-grid,
.family-cards,
.discovery-grid,
.gallery-grid,
.result-grid,
.api-stack,
.gallery-layout {
  display: grid;
  gap: 12px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.workspace-grid {
  margin-top: 12px;
  grid-template-columns: minmax(0, 1.08fr) minmax(300px, 0.92fr);
  align-items: start;
}

.form-grid   { grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 10px; }
.mini-grid   { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.family-cards { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.discovery-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.gallery-layout { grid-template-columns: minmax(0, 1.05fr) minmax(300px, 0.95fr); align-items: start; }
.gallery-grid { grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); }
.result-grid  { grid-template-columns: repeat(auto-fill, minmax(198px, 1fr)); }
.api-stack    { gap: 14px; }

.span-12 { grid-column: span 12; }
.span-6  { grid-column: span 6; }
.span-4  { grid-column: span 4; }
.span-3  { grid-column: span 3; }

/* --- Form Labels ------------------------------------------- */
.compact-field,
.field {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.compact-field span,
.field span,
.muted {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-soft);
  letter-spacing: .01em;
}

.muted { font-weight: 400; font-size: 12px; }

/* --- Inputs ------------------------------------------------ */
input,
select,
textarea {
  width: 100%;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--text-strong);
  font-size: 13px;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

textarea {
  min-height: 78px;
  resize: vertical;
  line-height: 1.55;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 14%, transparent);
}

/* --- Toggle Line ------------------------------------------- */
.toggle-line {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface2);
  font-size: 13px;
}

.toggle-line input[type="checkbox"] {
  width: 14px;
  height: 14px;
  flex: none;
  margin: 0;
  padding: 0;
  accent-color: var(--primary);
}

/* --- Buttons ----------------------------------------------- */
button {
  border: 0;
  cursor: pointer;
  transition: all var(--transition);
}

button:hover  { transform: translateY(-1px); }
button:active { transform: translateY(0); }

.primary-button,
.secondary-button,
.ghost-button,
.toolbar-button,
.tag-button {
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.primary-button {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 10px color-mix(in srgb, var(--primary) 28%, transparent);
}

.primary-button:hover { background: var(--primary-dark); }

.secondary-button {
  background: color-mix(in srgb, var(--primary) 10%, var(--surface));
  color: var(--primary-dark);
  border: 1px solid color-mix(in srgb, var(--primary) 24%, var(--border));
}

.ghost-button,
.toolbar-button,
.tag-button {
  background: var(--surface2);
  color: var(--text-main);
  border: 1px solid var(--border);
}

.ghost-button:hover,
.toolbar-button:hover,
.tag-button:hover {
  background: var(--border-light);
}

/* --- Compact Toolbar --------------------------------------- */
.compact-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.compact-toolbar .primary-button,
.compact-toolbar .ghost-button,
.compact-toolbar .toolbar-button {
  padding: 6px 10px;
  font-size: 12px;
}

/* --- Inner cards ------------------------------------------- */
.family-card,
.discovery-card,
.result-card,
.gallery-card,
.response-box,
.gallery-detail,
.history-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.family-card,
.discovery-card,
.gallery-detail,
.response-box {
  padding: 1rem;
}

.history-list { padding: 0; }

/* --- Pills ------------------------------------------------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text-main);
  font-size: 11px;
  font-weight: 600;
}

.pill.ok {
  color: var(--success);
  border-color: color-mix(in srgb, var(--success) 24%, var(--border));
  background: color-mix(in srgb, var(--success) 8%, var(--surface));
}

/* --- Eyebrow ----------------------------------------------- */
.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface2);
  border: 1px solid var(--border-light);
  color: var(--primary-dark);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
}

/* --- Hero layout ------------------------------------------- */
.hero {
  margin-top: 12px;
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(300px, 0.9fr);
  gap: 12px;
}

.hero-main {
  padding: 1.25rem;
  display: grid;
  gap: 1rem;
  min-height: 13rem;
}

.hero-main h2 {
  margin: 0;
  color: var(--text-strong);
  font-size: clamp(1.35rem, 2.4vw, 2.1rem);
  line-height: 1.15;
  font-weight: 800;
  letter-spacing: -.025em;
}

.hero-main p {
  margin: 0;
  max-width: 58ch;
  line-height: 1.7;
  color: var(--text-main);
  font-size: 13.5px;
}

.hero-side { padding: 1.125rem; }

/* --- Metrics ----------------------------------------------- */
.metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.metric-card,
.info-card {
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface2);
}

.metric-card strong {
  display: block;
  font-size: 1.1rem;
  color: var(--text-strong);
  font-weight: 700;
  margin-top: 2px;
  letter-spacing: -.01em;
}

.metric-card span {
  color: var(--text-soft);
  font-size: 12px;
}

/* --- Gallery / Results ------------------------------------- */
.result-card img,
.gallery-card img,
.gallery-preview img {
  display: block;
  width: 100%;
}

.result-card img,
.gallery-card img {
  aspect-ratio: 1;
  object-fit: cover;
}

.gallery-card {
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition);
}

.gallery-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .12);
}

.gallery-card.active {
  border-color: color-mix(in srgb, var(--primary) 40%, var(--border));
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 20%, transparent);
}

.result-card .content,
.gallery-card .content {
  padding: 10px 12px;
  display: grid;
  gap: 6px;
}

.result-card .meta,
.gallery-card .meta {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.result-card h5,
.gallery-card h5 {
  margin: 0;
  color: var(--text-strong);
  font-size: 13px;
  font-weight: 600;
}

.result-card p,
.gallery-card p,
.history-row span,
.history-row code {
  margin: 0;
  color: var(--text-soft);
  font-size: 12px;
  line-height: 1.5;
}

.gallery-preview {
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface2);
}

.gallery-preview img {
  aspect-ratio: 1;
  object-fit: contain;
  background:
    repeating-conic-gradient(
      var(--surface2) 0% 25%,
      var(--border-light) 0% 50%
    ) 0 0 / 14px 14px;
}

.result-card .toolbar,
.gallery-detail .toolbar { gap: 6px; }

/* --- Code / Response boxes --------------------------------- */
.response-box pre,
.gallery-detail pre,
.json-box,
.history-row code,
pre {
  font-family: var(--mono);
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-main);
}

.response-box pre,
.gallery-detail pre {
  margin: 0;
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--code-bg);
  max-height: 28rem;
  overflow: auto;
}

/* --- Tables ------------------------------------------------ */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table-wrap, table { background: transparent; }

th, td {
  padding: 9px 11px;
  border-bottom: 1px solid var(--border-light);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--text-strong);
  background: var(--surface2);
  font-weight: 600;
  font-size: 12px;
}

/* --- History List ------------------------------------------ */
.history-row {
  display: grid;
  gap: 2px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-light);
}

.history-row:last-child { border-bottom: 0; }

.history-row strong {
  color: var(--text-strong);
  font-size: 13px;
  font-weight: 600;
}

/* --- Empty State ------------------------------------------- */
.empty-state {
  display: grid;
  place-items: center;
  min-height: 10rem;
  text-align: center;
  padding: 1.5rem;
  border-radius: var(--radius-md);
  border: 1px dashed var(--border);
  background: var(--surface2);
  color: var(--text-soft);
  font-size: 13px;
  line-height: 1.8;
}

/* --- Footer Note ------------------------------------------- */
.footer-note {
  margin-top: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  background: var(--surface2);
  color: var(--text-soft);
  font-size: 12.5px;
  line-height: 1.7;
}

/* --- Form Actions ------------------------------------------ */
.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

/* --- Slider ------------------------------------------------ */
.slider-control { display: grid; gap: 6px; }

.slider-range {
  width: 100%;
  min-height: 24px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  box-shadow: none;
  appearance: none;
  accent-color: var(--primary);
}

.slider-range:hover { transform: none; }
.slider-range:focus { outline: none; box-shadow: none; }

.slider-range::-webkit-slider-runnable-track {
  height: 5px;
  border-radius: 999px;
  background: linear-gradient(90deg,
    color-mix(in srgb, var(--primary) 18%, var(--border)),
    var(--primary));
}

.slider-range::-webkit-slider-thumb {
  appearance: none;
  width: 15px;
  height: 15px;
  margin-top: -5px;
  border-radius: 50%;
  border: 2px solid var(--surface);
  background: var(--primary);
  box-shadow: 0 2px 8px color-mix(in srgb, var(--primary) 26%, transparent);
}

.slider-range::-moz-range-track {
  height: 5px;
  border-radius: 999px;
  background: linear-gradient(90deg,
    color-mix(in srgb, var(--primary) 18%, var(--border)),
    var(--primary));
}

.slider-range::-moz-range-thumb {
  width: 15px;
  height: 15px;
  border: 2px solid var(--surface);
  border-radius: 50%;
  background: var(--primary);
}

.slider-number { width: 100%; }

input.is-readonly {
  background: var(--surface2);
  color: var(--text-soft);
  cursor: default;
}

.slider-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 11px;
  color: var(--text-soft);
  font-weight: 600;
}

.slider-meta span { color: inherit; font-weight: inherit; }

/* --- Toast ------------------------------------------------- */
.toast-host {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  display: grid;
  gap: 8px;
  z-index: 100;
  width: min(340px, calc(100vw - 2rem));
}

.toast {
  padding: 11px 14px;
  border-radius: var(--radius-md);
  background: var(--text-strong);
  color: var(--surface);
  box-shadow: 0 8px 32px rgba(0, 0, 0, .22);
  border: 1px solid rgba(255, 255, 255, .06);
}

.toast strong {
  display: block;
  margin-bottom: 2px;
  font-size: 13px;
}

.toast p {
  margin: 0;
  font-size: 12px;
  line-height: 1.5;
  opacity: .76;
}

/* --- Wizard ------------------------------------------------ */
body.wizard-open { overflow: hidden; }

.wizard-overlay {
  position: fixed;
  inset: 0;
  z-index: 140;
  display: none;
  place-items: center;
  padding: 20px;
}

.wizard-overlay.on { display: grid; }

.wizard-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, .52);
  backdrop-filter: blur(8px);
  border: 0;
  padding: 0;
}

.wizard-dialog {
  position: relative;
  z-index: 1;
  width: min(1080px, calc(100vw - 24px));
  max-height: min(840px, calc(100vh - 24px));
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 14px;
  padding: 20px;
  border-radius: var(--radius-xl);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .2);
  overflow: hidden;
}

.wizard-header,
.wizard-progress-meta,
.wizard-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.wizard-header-copy { display: grid; gap: 3px; }

.wizard-eyebrow,
.wizard-panel-kicker {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--primary);
}

.wizard-title {
  margin: 0;
  font-size: clamp(1.2rem, 2vw, 1.6rem);
  color: var(--text-strong);
  font-weight: 800;
  letter-spacing: -.02em;
}

.wizard-close { flex: none; }

.wizard-progress-shell { display: grid; gap: 8px; }

.wizard-progress-bar {
  height: 4px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--surface2);
}

.wizard-progress-bar span {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--primary-light), var(--primary));
  transition: width .2s ease;
}

.wizard-step-count,
.wizard-step-badge { font-size: 11.5px; font-weight: 700; }

.wizard-step-count { color: var(--text-soft); }

.wizard-step-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-soft);
}

.wizard-step-badge.ok {
  color: var(--primary-dark);
  border-color: color-mix(in srgb, var(--primary) 35%, var(--border));
  background: color-mix(in srgb, var(--primary) 10%, var(--surface));
}

.wizard-layout {
  min-height: 0;
  display: grid;
  grid-template-columns: 256px minmax(0, 1fr);
  gap: 14px;
}

.wizard-sidebar,
.wizard-content { min-height: 0; }

.wizard-sidebar {
  display: grid;
  align-content: start;
  gap: 5px;
  padding-right: 4px;
  overflow: auto;
}

.wizard-nav-item {
  width: 100%;
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  align-items: start;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text-main);
  text-align: left;
  transition: all var(--transition);
}

.wizard-nav-item.active {
  border-color: color-mix(in srgb, var(--primary) 34%, var(--border));
  background: color-mix(in srgb, var(--primary) 7%, var(--surface));
}

.wizard-nav-index {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: color-mix(in srgb, var(--primary) 12%, var(--surface));
  color: var(--primary-dark);
  font-size: 12px;
  font-weight: 700;
}

.wizard-nav-copy { min-width: 0; display: grid; gap: 2px; }

.wizard-nav-copy strong { color: var(--text-strong); font-size: 12.5px; font-weight: 600; }

.wizard-nav-copy small,
.wizard-nav-state { color: var(--text-soft); font-size: 11px; line-height: 1.4; }

.wizard-nav-state { grid-column: 2; font-weight: 700; }

.wizard-content {
  overflow: auto;
  padding-right: 6px;
  display: grid;
  align-content: start;
  gap: 12px;
}

.wizard-panel,
.wizard-card,
.wizard-note {
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
}

.wizard-panel,
.wizard-card { padding: 16px; }

.wizard-panel h3,
.wizard-card h4 { margin: 0 0 6px; color: var(--text-strong); }

.wizard-card-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.wizard-panel h3 { font-size: 15px; font-weight: 700; }

.wizard-panel p,
.wizard-card p,
.wizard-note,
.wizard-list {
  margin: 0;
  color: var(--text-soft);
  line-height: 1.65;
  font-size: 13px;
}

.wizard-panel-hero {
  background:
    radial-gradient(ellipse at 0 0,
      color-mix(in srgb, var(--primary) 8%, transparent), transparent 40%),
    var(--surface);
}

.wizard-pill-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.wizard-grid { display: grid; gap: 12px; }
.wizard-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.wizard-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.wizard-card-wide { grid-column: 1 / -1; }

.wizard-details {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  overflow: hidden;
}

.wizard-details summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  cursor: pointer;
  color: var(--text-strong);
  font-weight: 700;
  font-size: 13px;
}

.wizard-details summary::-webkit-details-marker { display: none; }

.wizard-details-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  padding: 0 6px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text-soft);
  font-size: 11px;
  font-weight: 700;
}

.wizard-param-list {
  display: grid;
  gap: 0;
  border-top: 1px solid var(--border);
  max-height: 480px;
  overflow: auto;
}

.wizard-param-item {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-light);
}

.wizard-param-item:last-child { border-bottom: 0; }

.wizard-param-flag {
  display: inline-block;
  margin-bottom: 6px;
  padding: 4px 8px;
  border-radius: 6px;
  background: var(--code-bg);
  border: 1px solid var(--border-light);
  color: var(--text-strong);
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.wizard-field { min-width: 0; }

.wizard-link { color: var(--primary); text-decoration: none; word-break: break-all; }
.wizard-link:hover { text-decoration: underline; }

.wizard-code-label {
  margin: 12px 0 5px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-soft);
  text-transform: uppercase;
  letter-spacing: .07em;
}

.wizard-code {
  margin: 0;
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  background: var(--code-bg);
  border: 1px solid var(--border);
  color: var(--text-strong);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.65;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.wizard-list { padding-left: 18px; }
.wizard-list li + li { margin-top: 6px; }

.wizard-note {
  padding: 11px 14px;
  background: var(--surface2);
  font-size: 12.5px;
}

.wizard-actions-right {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.wizard-actions .ghost-button:disabled {
  opacity: .38;
  cursor: default;
  transform: none;
}

/* --- Theme Modes ------------------------------------------- */

body[data-actual-mode="day"] {
  --bg:           hsl(var(--palette-h), 22%, 96%);
  --surface:      #ffffff;
  --surface2:     hsl(var(--palette-h), 30%, 93%);
  --text-strong:  hsl(var(--palette-h), 28%, 11%);
  --text-main:    hsl(var(--palette-h), 18%, 30%);
  --text-soft:    hsl(var(--palette-h), 12%, 52%);
  --border:       hsl(var(--palette-h), 18%, 82%);
  --border-light: hsl(var(--palette-h), 18%, 90%);
  --panel-shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 14px rgba(0,0,0,.07);
  --input-bg:     #ffffff;
  --chip-bg:      var(--surface2);
  --code-bg:      hsl(var(--palette-h), 26%, 95%);
}

body[data-actual-mode="twilight"] {
  --bg:           hsl(var(--palette-h), 14%, 14%);
  --surface:      hsl(var(--palette-h), 14%, 19%);
  --surface2:     hsl(var(--palette-h), 14%, 24%);
  --text-strong:  hsl(var(--palette-h), 10%, 88%);
  --text-main:    hsl(var(--palette-h), 8%, 76%);
  --text-soft:    hsl(var(--palette-h), 6%, 54%);
  --border:       hsl(var(--palette-h), 12%, 30%);
  --border-light: hsl(var(--palette-h), 12%, 25%);
  --panel-shadow: 0 4px 20px rgba(0,0,0,.32);
  --input-bg:     hsl(var(--palette-h), 14%, 17%);
  --chip-bg:      hsl(var(--palette-h), 14%, 22%);
  --code-bg:      rgba(0,0,0,.16);
}

body[data-actual-mode="night"] {
  --bg:           hsl(var(--palette-h), 10%, 8%);
  --surface:      hsl(var(--palette-h), 10%, 11%);
  --surface2:     hsl(var(--palette-h), 10%, 15%);
  --text-strong:  hsl(var(--palette-h), 8%, 84%);
  --text-main:    hsl(var(--palette-h), 6%, 70%);
  --text-soft:    hsl(var(--palette-h), 5%, 48%);
  --border:       hsl(var(--palette-h), 8%, 19%);
  --border-light: hsl(var(--palette-h), 8%, 15%);
  --panel-shadow: 0 4px 24px rgba(0,0,0,.5);
  --input-bg:     hsl(var(--palette-h), 10%, 9%);
  --chip-bg:      hsl(var(--palette-h), 10%, 13%);
  --code-bg:      rgba(0,0,0,.22);
}

body[data-actual-mode="black"] {
  --bg:           #020304;
  --surface:      #0a0b0d;
  --surface2:     #101214;
  --text-strong:  #e6eaf0;
  --text-main:    #c2cad5;
  --border:       #1c2027;
  --border-light: #151820;
  --text-soft:    #6b7482;
  --panel-shadow: none;
  --input-bg:     #080a0b;
  --chip-bg:      #0d0f12;
  --code-bg:      rgba(0,0,0,.3);
}

/* --- Responsive ------------------------------------------- */
@media (max-width: 1200px) {
  .workspace-grid,
  .gallery-layout,
  .hero {
    grid-template-columns: minmax(0, 1fr);
  }

  .discovery-grid,
  .family-cards,
  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 860px) {
  .app-shell {
    width: calc(100vw - 1rem);
    margin: 0.5rem auto 2rem;
  }

  .app-header {
    padding: 10px 14px;
    position: static;
  }

  .header-actions { margin-left: auto; }

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

  .span-12, .span-6, .span-4, .span-3 { grid-column: auto; }

  .discovery-grid,
  .family-cards,
  .metrics {
    grid-template-columns: minmax(0, 1fr);
  }

  .top-strip {
    flex-direction: column;
    align-items: stretch;
  }

  .top-actions { margin-left: 0; }

  .settings-menu,
  .help-menu {
    width: min(90vw, 340px);
  }
}

@media (max-width: 720px) {
  .wizard-overlay { padding: 10px; }

  .wizard-dialog {
    width: calc(100vw - 20px);
    max-height: calc(100vh - 20px);
    gap: 12px;
    padding: 14px;
    border-radius: var(--radius-lg);
  }

  .wizard-layout { grid-template-columns: 1fr; }

  .wizard-sidebar {
    grid-auto-flow: column;
    grid-auto-columns: minmax(200px, 1fr);
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 4px;
  }

  .wizard-header,
  .wizard-progress-meta,
  .wizard-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .wizard-actions-right { width: 100%; }

  .wizard-actions-right .ghost-button,
  .wizard-actions-right .primary-button,
  .wizard-actions > .ghost-button { width: 100%; }

  .wizard-grid-2,
  .wizard-grid-3 { grid-template-columns: 1fr; }
}
