:root {
  color-scheme: light;
  --primary: #0f172a;
  --secondary: #334155;
  --accent: #0369a1;
  --background: #f8fafc;
  --surface: #ffffff;
  --foreground: #020617;
  --muted: #e8ecf1;
  --muted-foreground: #475569;
  --border: #e2e8f0;
  --success: #047857;
  --danger: #b91c1c;
  --focus: #0f172a;
  font-family: "Avenir Next", Avenir, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--background);
  color: var(--foreground);
}

* { box-sizing: border-box; }

body { margin: 0; min-width: 320px; background: var(--background); }
button, input, textarea { font: inherit; }
button, summary, .scenario-button { cursor: pointer; }

:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--focus) 40%, transparent);
  outline-offset: 3px;
}

.topbar {
  min-height: 72px;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; gap: 12px; align-items: center; color: inherit; text-decoration: none; }
.brand strong { display: block; letter-spacing: 0.09em; }
.brand small { display: block; color: var(--muted-foreground); margin-top: 1px; }
.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--primary);
  color: white;
  font-weight: 700;
}

.environment, .status-badge, .count {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 5px 12px;
  background: var(--muted);
  color: var(--secondary);
  font-size: 0.82rem;
  font-weight: 600;
}

.shell { display: grid; grid-template-columns: minmax(260px, 320px) 1fr; min-height: calc(100vh - 72px); }
.sidebar { padding: 32px 20px; border-right: 1px solid var(--border); background: var(--surface); }
.workspace { padding: 40px clamp(24px, 5vw, 72px); max-width: 1120px; width: 100%; }
.section-heading, .workspace-header { display: flex; align-items: start; justify-content: space-between; gap: 16px; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: 1.5rem; }
h2 { font-size: clamp(1.5rem, 3vw, 2.25rem); }
h3 { font-size: 1.1rem; }
.eyebrow { margin-bottom: 6px; color: var(--accent); font-size: 0.75rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; }

.scenario-list { display: grid; gap: 10px; margin-top: 20px; }
.scenario-button {
  width: 100%;
  min-height: 72px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  text-align: left;
  background: var(--surface);
  color: var(--foreground);
  transition: border-color 180ms ease, background 180ms ease;
}
.scenario-button:hover { border-color: var(--accent); }
.scenario-button[aria-current="true"] { background: #e0f2fe; border-color: var(--accent); }
.scenario-button strong, .scenario-button span { display: block; }
.scenario-button span { margin-top: 5px; color: var(--muted-foreground); font-size: 0.84rem; }

.editor { margin-top: 32px; }
.form-grid { display: grid; gap: 24px; }
label > span { display: block; margin-bottom: 8px; font-weight: 650; }
label > small { display: block; margin-top: 7px; color: var(--muted-foreground); }
input, textarea {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  padding: 12px 14px;
  color: var(--foreground);
  background: var(--surface);
  line-height: 1.5;
  transition: border-color 180ms ease, box-shadow 180ms ease;
}
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgb(3 105 161 / 14%); outline: none; }
textarea { resize: vertical; }
.two-column { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

.graph-summary { margin-top: 32px; padding: 24px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; }
.graph-summary dl { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 20px 0; }
.graph-summary dl div { padding: 14px; border-radius: 10px; background: var(--background); }
.graph-summary dt { color: var(--muted-foreground); font-size: 0.82rem; }
.graph-summary dd { margin: 5px 0 0; font-size: 1.35rem; font-weight: 700; }
details { border-top: 1px solid var(--border); padding-top: 18px; }
summary { min-height: 44px; display: flex; align-items: center; color: var(--secondary); font-weight: 600; }
pre { max-height: 340px; overflow: auto; padding: 16px; border-radius: 10px; background: var(--primary); color: #e2e8f0; font-size: 0.78rem; line-height: 1.55; }

.actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 24px; flex-wrap: wrap; }
.button { min-height: 48px; border-radius: 9px; padding: 11px 20px; border: 1px solid transparent; font-weight: 650; transition: background 180ms ease, border-color 180ms ease; }
.button.primary { background: var(--accent); color: white; }
.button.primary:hover { background: #075985; }
.button.secondary { background: var(--surface); border-color: #94a3b8; color: var(--primary); }
.button.secondary:hover { background: var(--muted); }
.button:disabled { cursor: not-allowed; opacity: 0.55; }

.empty-state { max-width: 520px; margin: 96px auto; text-align: center; color: var(--muted-foreground); }
.empty-state h2 { color: var(--foreground); }
.empty-mark { width: 64px; height: 64px; margin: 0 auto 24px; border-radius: 18px; background: linear-gradient(145deg, var(--primary) 0 52%, var(--accent) 52%); }
.message { position: fixed; right: 24px; bottom: 24px; max-width: 420px; padding: 14px 18px; border-radius: 10px; background: var(--primary); color: white; box-shadow: 0 12px 30px rgb(15 23 42 / 22%); }
.message.error { background: var(--danger); }

.auth-dialog {
  width: min(calc(100% - 32px), 440px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  color: var(--foreground);
  box-shadow: 0 24px 80px rgb(15 23 42 / 28%);
}
.auth-dialog::backdrop { background: rgb(2 6 23 / 62%); backdrop-filter: blur(4px); }
.auth-dialog form { padding: 32px; display: grid; gap: 20px; }
.auth-dialog .brand-mark { margin-bottom: 6px; }
.auth-dialog .eyebrow { margin: 0; }
.auth-dialog h2 { margin: -10px 0 0; font-size: 1.7rem; }
.auth-copy { margin: -8px 0 0; color: var(--muted-foreground); line-height: 1.5; }
.auth-dialog .button { width: 100%; }

@media (max-width: 760px) {
  .topbar { padding-inline: 16px; }
  .environment { display: none; }
  .shell { display: block; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--border); padding: 24px 16px; }
  .workspace { padding: 28px 16px 100px; }
  .scenario-list { display: flex; overflow-x: auto; padding-bottom: 8px; }
  .scenario-button { min-width: 240px; }
  .two-column { grid-template-columns: 1fr; }
  .graph-summary dl { grid-template-columns: 1fr; }
  .actions { align-items: stretch; flex-direction: column-reverse; }
  .button { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; }
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --primary: #e2e8f0;
    --secondary: #cbd5e1;
    --accent: #38bdf8;
    --background: #020617;
    --surface: #0f172a;
    --foreground: #f8fafc;
    --muted: #1e293b;
    --muted-foreground: #cbd5e1;
    --border: #334155;
    --focus: #7dd3fc;
  }
  .brand-mark { background: #e2e8f0; color: #0f172a; }
  .scenario-button[aria-current="true"] { background: #0c4a6e; }
  input, textarea { border-color: #475569; }
  .button.primary { color: #082f49; }
  .button.secondary { border-color: #64748b; color: var(--foreground); }
}
