:root {
  color-scheme: light;
  --bg: #f7f8fc; --surface: #fff; --subtle: #f1f3f9; --text: #172033; --muted: #536078; --border: #dce1ed;
  --accent: #6d43d5; --accent-soft: #f0eaff; --success: #087657; --success-soft: #e6f7ef;
  --danger: #b42338; --danger-soft: #fff0f2; --warn: #9a5b00; --warn-soft: #fff5e0; --info: #087d99; --info-soft: #e3f6fb;
  --idle: #6b7280; --idle-soft: #eef0f4; --shadow: 0 1px 2px rgba(23, 32, 51, .06), 0 8px 24px rgba(23, 32, 51, .05);
  --radius: 16px;
  font: 14px/1.5 Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0c101b; --surface: #141b2b; --subtle: #1b2436; --text: #e7ebf5; --muted: #9aa6bf; --border: #2a3550;
  --accent: #bda4ff; --accent-soft: #2a2148; --success: #4fd1a5; --success-soft: #11322a;
  --danger: #ff8a9a; --danger-soft: #3a1820; --warn: #f5c062; --warn-soft: #3a2c12; --info: #6fd6ef; --info-soft: #102f38;
  --idle: #a0a8b8; --idle-soft: #232b3c; --shadow: none;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 24px; } h2 { font-size: 17px; } h3 { font-size: 14px; margin: 24px 0 8px; }
code { background: var(--subtle); border-radius: 6px; padding: 1px 6px; font-size: 13px; }
button, select, input { font: inherit; color: inherit; }
button { min-height: 44px; border: 0; border-radius: 12px; padding: 0 18px; background: var(--accent); color: #fff; font-weight: 600; cursor: pointer; }
:root[data-theme="dark"] button:not(.secondary) { color: #120d24; }
button.secondary { background: var(--subtle); color: var(--text); border: 1px solid var(--border); }
button:focus-visible, a:focus-visible, select:focus-visible, input:focus-visible, .clickable:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
input, select { min-height: 44px; width: 100%; border: 1px solid var(--border); border-radius: 12px; padding: 0 12px; background: var(--surface); }
.muted { color: var(--muted); }
.error { color: var(--danger); background: var(--danger-soft); padding: 10px 12px; border-radius: 10px; margin: 0; }
[hidden] { display: none !important; }

dialog { border: 0; padding: 0; background: transparent; color: var(--text); max-width: calc(100vw - 32px); }
dialog::backdrop { background: rgba(12, 16, 27, .55); }
.dialog-card { width: min(560px, calc(100vw - 32px)); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px; box-shadow: var(--shadow); display: grid; gap: 14px; }
.dialog-card h2 { margin: 0; }
.dialog-card p { margin: 0; }
.dialog-card label { display: grid; gap: 6px; font-weight: 600; }
.dialog-card .hint { font-size: 13px; }
.dialog-actions { display: flex; justify-content: flex-end; align-items: center; gap: 10px; flex-wrap: wrap; }
.dialog-actions.start { justify-content: flex-start; }
.steps { margin: 0; padding-left: 20px; display: grid; gap: 6px; }
.command { margin: 0; padding: 12px 14px; background: var(--subtle); border: 1px solid var(--border); border-radius: 10px; font-size: 12.5px; white-space: pre-wrap; word-break: break-all; max-height: 180px; overflow: auto; }

.brand { display: flex; align-items: center; gap: 12px; font-weight: 700; font-size: 16px; }
.brand small { display: block; font-weight: 400; font-size: 12px; color: var(--muted); }
.brand-mark { width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center; color: #fff; background: linear-gradient(135deg, #0891b2, #7c3aed); flex: none; }

.signin { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.signin-card { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 32px; box-shadow: var(--shadow); display: grid; gap: 16px; }
.signin-card p { margin: 0; color: var(--muted); }
.signin-card label { display: grid; gap: 6px; font-weight: 600; }
.signin-card .hint { font-size: 13px; }

.shell { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 24px 16px; display: flex; flex-direction: column; gap: 10px; position: sticky; top: 0; height: 100vh; }
.nav-caption { margin-top: 14px; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.pool-picker { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.pool-kind { margin: 0; font-size: 13px; color: var(--muted); }
button.danger { background: var(--danger); color: #fff; }
:root[data-theme="dark"] button.danger { color: #120d24; }
button.secondary.danger { background: var(--danger-soft); color: var(--danger); border-color: var(--danger-soft); }
button.small { min-height: 36px; padding: 0 12px; font-size: 13px; }
.share-form { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.share-form label { flex: 1 1 220px; }
nav { display: grid; gap: 4px; }
nav a { color: var(--text); text-decoration: none; padding: 10px 12px; border-radius: 10px; font-weight: 500; }
nav a:hover { background: var(--subtle); }
nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.sidebar-note { margin-top: auto; display: grid; gap: 8px; }
.sidebar-note p { margin: 0; font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }

.workspace { min-width: 0; padding: 28px 32px 48px; display: grid; gap: 20px; align-content: start; }
.topbar { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; }
.eyebrow { font-size: 11px; font-weight: 700; letter-spacing: .1em; color: var(--accent); text-transform: uppercase; }
.status-bar { margin: 0; padding: 12px 16px; border-radius: 12px; background: var(--warn-soft); color: var(--warn); }
.view { display: grid; gap: 20px; min-width: 0; }
section { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px; box-shadow: var(--shadow); min-width: 0; }
section > h2 { margin-bottom: 14px; }
.section-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.section-heading > * { min-width: 0; }
.prose ol { padding-left: 20px; display: grid; gap: 8px; } .prose p { color: var(--muted); }

.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.stat-grid > div { background: var(--surface); border: 1px solid var(--border); border-top: 4px solid var(--accent); border-radius: var(--radius); padding: 18px 20px; display: grid; gap: 2px; box-shadow: var(--shadow); min-width: 0; }
.stat-grid > div:nth-child(2) { border-top-color: var(--info); }
.stat-grid > div:nth-child(3) { border-top-color: var(--warn); }
.stat-grid > div:nth-child(4) { border-top-color: var(--success); }
.stat-grid span { color: var(--muted); font-size: 13px; }
.stat-grid strong { font-size: 30px; }
.stat-grid em { font-style: normal; color: var(--muted); font-size: 12px; }

.badge { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 3px 10px; font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--idle-soft); color: var(--idle); }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
[data-state="ready"] { --tone: var(--info); --tone-soft: var(--info-soft); }
[data-state="running"], [data-state="online"], [data-state="active"], [data-state="live"] { --tone: var(--accent); --tone-soft: var(--accent-soft); }
[data-state="waiting"], [data-state="busy"], [data-state="blocked"] { --tone: var(--warn); --tone-soft: var(--warn-soft); }
[data-state="succeeded"], [data-state="split"] { --tone: var(--success); --tone-soft: var(--success-soft); }
[data-state="failed"], [data-state="expired"], [data-state="error"] { --tone: var(--danger); --tone-soft: var(--danger-soft); }
[data-state="cancelled"], [data-state="offline"], [data-state="stale"] { --tone: var(--idle); --tone-soft: var(--idle-soft); }
.badge[data-state] { background: var(--tone-soft); color: var(--tone); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover, tbody tr[aria-selected="true"] { background: var(--subtle); }
td .sub { display: block; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.empty { color: var(--muted); padding: 18px; text-align: center; background: var(--subtle); border-radius: 12px; }
.progress { height: 6px; background: var(--subtle); border-radius: 999px; overflow: hidden; min-width: 80px; margin-top: 6px; }
.progress > i { display: block; height: 100%; background: var(--tone, var(--success)); }

.legend { display: flex; flex-wrap: wrap; gap: 8px 14px; font-size: 12px; color: var(--muted); margin: 6px 0 12px; }
.legend span[data-state]::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; background: var(--tone-soft); border: 2px solid var(--tone); vertical-align: -1px; }
.dag { overflow: auto; border: 1px solid var(--border); border-radius: 12px; background: var(--subtle); max-height: 560px; }
.dag svg { display: block; max-width: 100%; height: auto; }
.dag .node rect { fill: var(--tone-soft); stroke: var(--tone); stroke-width: 2; }
.dag .node text { fill: var(--text); font-size: 12px; }
.dag .node text.state { fill: var(--tone); font-weight: 600; font-size: 11px; }
.dag .node { cursor: pointer; }
.dag .node.selected rect { stroke-width: 4; }
.dag .edge { fill: none; stroke: var(--muted); stroke-width: 1.5; }
.dag .edge.child { stroke-dasharray: 5 4; stroke: var(--accent); }
.dag marker path { fill: var(--muted); }
.task-detail { margin-top: 14px; padding: 16px; border-radius: 12px; border: 1px solid var(--border); display: grid; gap: 8px; }
.task-detail h3 { margin: 0 0 4px; }
.task-detail dl { display: grid; grid-template-columns: 140px minmax(0, 1fr); gap: 6px 12px; margin: 0; }
.task-detail dt { color: var(--muted); } .task-detail dd { margin: 0; overflow-wrap: anywhere; white-space: pre-wrap; }

@media (max-width: 1000px) { .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 768px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--border); }
  nav { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
  .workspace { padding: 20px 16px 40px; }
  section { padding: 20px; }
}
@media (max-width: 480px) { .stat-grid { grid-template-columns: 1fr; } .task-detail dl { grid-template-columns: 1fr; } }
