:root {
  color-scheme: light;
  --ink: #172433;
  --muted: #607184;
  --surface: #ffffff;
  --background: #f3f6f8;
  --brand: #173f5f;
  --accent: #e07a32;
  --border: #d6dee5;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; color: var(--ink); background: var(--background); }
button, input, select, textarea { font: inherit; }
button, a { min-height: 44px; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid #4b91d1; outline-offset: 2px; }
.topbar { min-height: 64px; padding: 0 24px; display: flex; align-items: center; justify-content: space-between; gap: 24px; color: #fff; background: var(--brand); }
.brand { display: inline-flex; align-items: center; color: inherit; font-weight: 800; letter-spacing: .02em; text-decoration: none; }
.topbar nav { display: flex; align-items: center; gap: 8px; }
.topbar nav a, .topbar nav button { display: inline-flex; align-items: center; border: 0; padding: 0 12px; color: #fff; background: transparent; text-decoration: none; cursor: pointer; }
.topbar-logout { display: contents; }
.empty-state { width: min(760px, calc(100% - 32px)); margin: 12vh auto; padding: clamp(32px, 6vw, 72px); border: 1px solid var(--border); border-radius: 20px; background: var(--surface); box-shadow: 0 18px 50px rgb(21 45 65 / 8%); }
.eyebrow { color: var(--accent); font-size: .78rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.empty-state h1 { margin: .4rem 0 1rem; font-size: clamp(2rem, 6vw, 4.5rem); line-height: 1.02; }
.empty-state p:last-child { color: var(--muted); }

:root {
  --brand-deep: #0d2639;
  --accent-soft: #fff0e5;
  --success: #23785b;
  --danger: #b33a3a;
  --warning: #9a650e;
  --shadow: 0 12px 34px rgb(21 45 65 / 12%);
}

body { overflow-x: hidden; }
h1, h2, h3, p { overflow-wrap: anywhere; }
button, .button { border: 1px solid var(--border); border-radius: 8px; padding: 9px 14px; color: var(--ink); background: #fff; cursor: pointer; text-decoration: none; }
button:hover, .button:hover { border-color: #9eb0bf; background: #f8fafb; }
button:disabled { cursor: not-allowed; opacity: .48; }
button.primary, .button.primary { border-color: var(--brand); color: #fff; background: var(--brand); }
button.primary:hover, .button.primary:hover { background: #0e314d; }
button.secondary, .button.secondary { background: #f7f9fa; }
button.quiet { border-color: transparent; background: transparent; }
button.danger { border-color: var(--danger); color: #fff; background: var(--danger); }
.danger-text { color: var(--danger); }
.run-button { border-color: #bc5c19; color: #fff; font-weight: 750; background: var(--accent); }
.icon-button { display: inline-grid; width: 44px; min-width: 44px; padding: 0; place-items: center; font-size: 1.4rem; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.muted, small { color: var(--muted); }
.mobile-only { display: none; }

.topbar { position: relative; z-index: 50; }
.brand { gap: 9px; }
.brand-mark { display: grid; width: 38px; height: 38px; border-radius: 9px; color: var(--brand-deep); background: #fff; place-items: center; font-size: .72rem; }

.library-view { width: min(1280px, calc(100% - 32px)); margin: 0 auto; padding: 48px 0 80px; }
.library-hero { display: flex; align-items: end; justify-content: space-between; gap: 32px; margin-bottom: 36px; }
.library-hero h1 { margin: .25rem 0 .5rem; font-size: clamp(2.25rem, 5vw, 4.6rem); letter-spacing: -.045em; }
.library-hero p:not(.eyebrow) { max-width: 650px; color: var(--muted); font-size: 1.08rem; }
.hero-actions, .card-actions, .model-actions, .run-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.library-controls { display: flex; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.library-controls input[type="search"] { width: min(440px, 70vw); }
.library-controls label { display: flex; align-items: center; gap: 8px; color: var(--muted); }
input, select, textarea { width: 100%; min-height: 44px; border: 1px solid #bdc9d2; border-radius: 7px; padding: 9px 10px; color: var(--ink); background: #fff; }
textarea { min-height: 92px; resize: vertical; }
.simulation-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(350px, 100%), 1fr)); gap: 18px; }
.simulation-card, .empty-card { display: flex; min-height: 280px; padding: 24px; border: 1px solid var(--border); border-radius: 16px; background: var(--surface); box-shadow: 0 3px 12px rgb(20 42 58 / 4%); flex-direction: column; justify-content: space-between; }
.simulation-card:hover { border-color: #aebcc7; box-shadow: var(--shadow); transform: translateY(-1px); }
.simulation-card h2 { margin: .35rem 0 .5rem; font-size: 1.45rem; }
.simulation-card p { color: var(--muted); }
.card-kicker { color: var(--accent); font-size: .75rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.simulation-card dl { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 16px 0; }
.simulation-card dl div { padding: 10px; border-radius: 8px; background: var(--background); }
.simulation-card dt { color: var(--muted); font-size: .72rem; text-transform: uppercase; }
.simulation-card dd { margin: 4px 0 0; font-size: .85rem; }

.editor-app { height: 100dvh; overflow: hidden; }
.model-workspace { display: grid; height: calc(100dvh - 64px); grid-template-rows: auto auto minmax(0, 1fr) auto; }
.modelbar { display: flex; min-height: 58px; padding: 7px 14px; align-items: center; justify-content: space-between; gap: 16px; border-bottom: 1px solid var(--border); background: #fff; }
.model-identity { display: flex; align-items: center; gap: 16px; font-weight: 700; }
.model-identity label { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .82rem; font-weight: 600; }
.model-identity select { width: auto; min-width: 160px; }
.dirty-indicator { padding: 5px 8px; border-radius: 99px; color: var(--warning); background: #fff6dc; font-size: .76rem; }
.editor-toolbar { display: flex; min-height: 48px; padding: 4px 9px; overflow-x: auto; align-items: center; gap: 4px; border-bottom: 1px solid var(--border); background: #f9fbfc; scrollbar-width: thin; }
.editor-toolbar button { min-height: 38px; padding: 6px 9px; white-space: nowrap; background: transparent; }
.toolbar-spacer { flex: 1; }
.editor-layout { position: relative; display: grid; min-height: 0; grid-template-columns: 178px minmax(300px, 1fr) 310px; }
.module-palette, .properties-panel { position: relative; z-index: 8; overflow-y: auto; background: #fff; }
.module-palette { padding: 18px 12px; border-right: 1px solid var(--border); }
.module-palette h2 { margin: 0; font-size: 1rem; }
.module-palette > p { margin: .3rem 0 1rem; color: var(--muted); font-size: .78rem; }
.module-palette > div { display: grid; gap: 7px; }
.module-palette button { display: flex; width: 100%; min-height: 48px; align-items: center; gap: 9px; text-align: left; }
.module-glyph { width: 18px; height: 18px; border: 2px solid currentColor; border-radius: 4px; color: #247d68; background: #e5f6f1; }
.module-glyph.process { color: #256aa3; background: #e8f2fb; }
.module-glyph.decide { border-radius: 2px; color: #b06a18; background: #fff4dd; transform: rotate(45deg) scale(.78); }
.module-glyph.assign, .module-glyph.record { color: #6f57a6; background: #f1edfa; }
.module-glyph.dispose { border-radius: 50%; color: #9f4040; background: #fbeaea; }
.module-glyph.delay, .module-glyph.batch, .module-glyph.separate { color: #536b7d; background: #eef2f5; }
.properties-panel { border-left: 1px solid var(--border); }
.panel-placeholder, .panel-heading, .property-form { padding: 16px; }
.panel-placeholder p { color: var(--muted); }
.panel-heading { padding-bottom: 0; }
.panel-heading h2 { margin: .2rem 0; font-size: 1.18rem; }
.property-form { display: grid; gap: 14px; }
.property-form label, .stack-form label, [data-comparison-form] > label { display: grid; gap: 6px; color: #34495a; font-size: .8rem; font-weight: 700; }
.property-form small, .stack-form small { font-weight: 400; line-height: 1.35; }
.property-form fieldset { display: grid; gap: 11px; margin: 0; padding: 13px; border: 1px solid var(--border); border-radius: 9px; }
.property-form legend { padding: 0 5px; font-size: .78rem; font-weight: 800; }
.row-editor, .branch-editor, .assignment-editor { position: relative; display: grid; gap: 8px; padding: 10px; border-radius: 7px; background: var(--background); }
.row-editor { grid-template-columns: 1fr 76px 44px; align-items: end; }
.branch-editor .icon-button, .assignment-editor .icon-button { position: absolute; top: 4px; right: 4px; }
.checkbox { display: flex !important; min-height: 44px; align-items: center; gap: 8px !important; font-weight: 500 !important; }
.checkbox input { width: 20px; min-height: 20px; }
.else-label { color: var(--warning); font-weight: 800; }

.canvas-panel { position: relative; min-width: 0; min-height: 0; overflow: hidden; background-color: #edf2f5; background-image: radial-gradient(#bdc8d0 1px, transparent 1px); background-size: 18px 18px; }
.drawflow-host { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
.drawflow .drawflow-node { width: 210px; min-height: 92px; padding: 0; border: 0; border-radius: 11px; background: transparent; box-shadow: 0 8px 24px rgb(22 44 60 / 15%); }
.drawflow .drawflow-node.selected { box-shadow: 0 0 0 4px rgb(54 131 190 / 28%), 0 8px 24px rgb(22 44 60 / 15%); }
.drawflow .drawflow-node.multi-selected { box-shadow: 0 0 0 4px rgb(224 122 50 / 35%), 0 8px 24px rgb(22 44 60 / 15%); }
.drawflow .drawflow-node .input, .drawflow .drawflow-node .output { width: 18px; height: 18px; border: 3px solid #fff; background: #426f91; }
.drawflow .drawflow-node .input { left: -9px; }
.drawflow .drawflow-node .output { right: -9px; }
.drawflow .connection .main-path { stroke: #537993; stroke-width: 4px; }
.module-card { display: grid; min-height: 92px; padding: 13px 14px; border: 1px solid #c8d5dd; border-top: 5px solid #247d68; border-radius: 10px; background: #fff; gap: 4px; }
.module-card.module-process { border-top-color: #256aa3; }
.module-card.module-decide { border-top-color: #b06a18; }
.module-card.module-assign, .module-card.module-record { border-top-color: #6f57a6; }
.module-card.module-dispose { border-top-color: #9f4040; }
.module-card.module-delay, .module-card.module-batch, .module-card.module-separate { border-top-color: #536b7d; }
.module-kind { color: var(--muted); font-size: .65rem; font-weight: 850; letter-spacing: .12em; text-transform: uppercase; }
.module-summary { color: var(--muted); font-size: .72rem; line-height: 1.35; }
.module-live { margin-top: 4px; padding: 4px 6px; border-radius: 5px; color: #0b5c48; background: #ddf5ed; font-size: .68rem; font-weight: 750; }
.canvas-overlay { position: absolute; inset: 0; z-index: 7; overflow: hidden; pointer-events: none; }
.entity-token { position: absolute; width: 13px; height: 13px; border: 2px solid #fff; border-radius: 50%; background: var(--accent); box-shadow: 0 2px 7px rgb(0 0 0 / 30%); transition: transform .65s cubic-bezier(.2,.7,.2,1); }

.runbar { display: flex; min-height: 58px; padding: 7px 12px; align-items: center; gap: 12px; border-top: 1px solid var(--border); background: #fff; }
.runbar > label { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: .78rem; }
.runbar select { width: 78px; min-height: 40px; }
.trace-toggle { white-space: nowrap; }
.run-status { display: flex; margin-left: auto; align-items: center; gap: 14px; color: var(--muted); font-size: .78rem; white-space: nowrap; }
.run-status [data-run-state] { padding: 5px 9px; border-radius: 99px; color: var(--brand); background: #e9f2f8; font-weight: 800; }

.app-dialog { width: min(680px, calc(100vw - 28px)); max-height: min(88dvh, 960px); padding: 0; overflow: hidden; border: 0; border-radius: 15px; background: #fff; box-shadow: 0 25px 80px rgb(0 0 0 / 28%); }
.app-dialog.wide { width: min(1180px, calc(100vw - 28px)); }
.app-dialog::backdrop { background: rgb(12 28 40 / 55%); backdrop-filter: blur(2px); }
.dialog-shell { display: grid; max-height: 88dvh; grid-template-rows: auto minmax(0, 1fr) auto; }
.dialog-shell > header, .dialog-shell > footer { display: flex; padding: 14px 18px; align-items: center; gap: 9px; background: #fff; }
.dialog-shell > header { justify-content: space-between; border-bottom: 1px solid var(--border); }
.dialog-shell > header h2 { margin: 0; font-size: 1.25rem; }
.dialog-shell > footer { justify-content: flex-end; border-top: 1px solid var(--border); }
.dialog-content { padding: 20px; overflow: auto; }
.stack-form { display: grid; gap: 14px; }
.table-scroll { overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: .85rem; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: right; vertical-align: top; }
th:first-child, td:first-child { text-align: left; }
thead th { position: sticky; top: 0; z-index: 1; color: var(--muted); background: #f7f9fa; font-size: .72rem; letter-spacing: .03em; text-transform: uppercase; }
td small { display: block; margin-top: 3px; }
.manager { display: grid; gap: 14px; }
.manager table input, .manager table select, .manager table textarea { min-width: 130px; }
.manager table textarea { min-width: 230px; min-height: 70px; font-family: ui-monospace, monospace; font-size: .75rem; }
.scenario-list, .run-history { display: grid; gap: 9px; }
.scenario-list article, .run-history article { display: flex; padding: 14px; align-items: center; justify-content: space-between; gap: 15px; border: 1px solid var(--border); border-radius: 9px; }
.scenario-list h3, .run-history h3 { margin: 0; }
.scenario-list p, .run-history p { margin: .3rem 0 0; color: var(--muted); font-size: .8rem; }
.scenario-list article > div:last-child, .run-history article > div:last-child { display: flex; flex-wrap: wrap; gap: 6px; }
.validation-list { display: grid; gap: 8px; padding-left: 24px; }
.validation-list.errors strong { color: var(--danger); }
.validation-list.warnings strong { color: var(--warning); }
.toast-region { position: fixed; z-index: 1000; right: 18px; bottom: 18px; display: grid; width: min(390px, calc(100vw - 36px)); gap: 8px; pointer-events: none; }
.toast { padding: 13px 16px; border-left: 5px solid var(--brand); border-radius: 8px; color: #fff; background: #20394b; box-shadow: var(--shadow); }
.toast.success { border-color: #66c49e; }
.toast.warning { border-color: #f3bf4c; }
.toast.error { border-color: #f06a6a; }

.tab-list { display: flex; margin: -20px -20px 20px; padding: 0 20px; overflow-x: auto; gap: 3px; border-bottom: 1px solid var(--border); }
.tab-list button { border: 0; border-bottom: 3px solid transparent; border-radius: 0; background: transparent; white-space: nowrap; }
.tab-list button[aria-selected="true"] { border-bottom-color: var(--accent); color: var(--brand); font-weight: 800; }
.metric-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.metric-grid article { padding: 18px; border: 1px solid var(--border); border-radius: 10px; background: #fbfcfd; }
.metric-grid span { display: block; color: var(--muted); font-size: .75rem; }
.metric-grid strong { display: block; margin-top: 7px; font-size: 1.55rem; }
.indicator-list { display: grid; grid-template-columns: repeat(3, 1fr); padding: 0; gap: 10px; list-style: none; }
.indicator-list li { padding: 13px; border-left: 4px solid var(--accent); background: var(--accent-soft); }
.chart-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.chart-grid article { min-width: 0; padding: 12px; border: 1px solid var(--border); border-radius: 10px; }
.chart-grid h3 { margin: 0 0 8px; font-size: .9rem; }
.chart { width: 100%; height: 310px; }
.trace-list { max-height: 56vh; padding: 13px 13px 13px 50px; overflow: auto; border-radius: 8px; color: #dbeaf4; background: #142938; font: .78rem/1.55 ui-monospace, SFMono-Regular, Menlo, monospace; }
.trace-list time { color: #f0a875; }
.saved-indicator { color: var(--success); font-weight: 750; }
.comparison-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 7px; margin: 12px 0; }
.comparison-results .change.up { color: #8b4d10; }
.comparison-results .change.down { color: var(--success); }
.example-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.example-grid article { display: flex; padding: 16px; border: 1px solid var(--border); border-radius: 10px; flex-direction: column; }
.example-grid article button { margin-top: auto; }
.help-content { max-width: 840px; line-height: 1.55; }
.help-content dl { display: grid; grid-template-columns: 150px 1fr; gap: 7px 16px; }
.help-content dt { font-weight: 800; }
.help-content dd { margin: 0; color: var(--muted); }
.fatal-state { width: min(640px, calc(100% - 32px)); margin: 12vh auto; padding: 40px; border-radius: 15px; background: #fff; box-shadow: var(--shadow); }

.login-body { display: grid; min-height: 100dvh; background: linear-gradient(145deg, var(--brand-deep), var(--brand) 48%, #315f7e); place-items: center; }
.login-page { width: min(100%, 520px); padding: 24px; }
.login-card { padding: clamp(28px, 7vw, 48px); border-radius: 20px; background: var(--surface); box-shadow: 0 28px 80px rgb(0 0 0 / 28%); }
.login-brand { display: flex; margin-bottom: 32px; align-items: center; gap: 10px; color: var(--brand); font-size: 1.15rem; font-weight: 850; }
.login-brand .brand-mark { color: #fff; background: var(--brand); }
.login-card h1 { margin: .25rem 0 .6rem; font-size: clamp(2.25rem, 8vw, 3.5rem); letter-spacing: -.04em; }
.login-intro { margin: 0 0 24px; color: var(--muted); line-height: 1.5; }
.login-error { margin: 0 0 18px; padding: 12px 14px; border-left: 4px solid var(--danger); border-radius: 6px; color: #762727; background: #fcecec; line-height: 1.45; }
.login-card form button { width: 100%; margin-top: 4px; }

@media (max-width: 1120px) {
  .editor-layout { grid-template-columns: 160px minmax(280px, 1fr) 280px; }
  .run-status { gap: 8px; }
  .run-status > span:nth-of-type(4), .trace-toggle { display: none !important; }
}

@media (max-width: 860px) {
  .mobile-only { display: inline-flex; }
  .topbar { min-height: 56px; padding: 0 12px; }
  .topbar nav a { display: none; }
  .model-workspace { height: calc(100dvh - 56px); }
  .modelbar { min-height: 54px; }
  .model-identity > span:first-child { display: none; }
  .model-actions button:not([data-editor-action="save"]) { display: none; }
  .editor-layout { grid-template-columns: minmax(0, 1fr); }
  .module-palette, .properties-panel { position: absolute; top: 0; bottom: 0; z-index: 20; width: min(330px, 86vw); box-shadow: var(--shadow); transition: transform .2s ease; }
  .module-palette { left: 0; transform: translateX(-105%); }
  .properties-panel { right: 0; transform: translateX(105%); }
  .module-palette.open, .properties-panel.open { transform: translateX(0); }
  .runbar { flex-wrap: wrap; }
  .run-status { width: 100%; margin-left: 0; overflow-x: auto; }
  .metric-grid { grid-template-columns: 1fr 1fr; }
  .indicator-list { grid-template-columns: 1fr; }
  .chart-grid { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
  .topbar nav button { padding: 0 7px; }
  .library-view { padding-top: 28px; }
  .library-hero { align-items: stretch; flex-direction: column; }
  .library-controls { align-items: stretch; flex-direction: column; }
  .library-controls input[type="search"] { width: 100%; }
  .simulation-card dl { grid-template-columns: 1fr; }
  .model-identity label { font-size: 0; }
  .model-identity select { min-width: 125px; font-size: .82rem; }
  .editor-toolbar .toolbar-spacer { display: none; }
  .runbar > label { display: none; }
  .run-actions { flex-wrap: nowrap; overflow-x: auto; }
  .run-actions button { padding-inline: 10px; }
  .run-status > span:nth-of-type(3) { display: none; }
  .metric-grid { grid-template-columns: 1fr; }
  .dialog-content { padding: 14px; }
  .tab-list { margin: -14px -14px 14px; padding: 0 14px; }
  .scenario-list article, .run-history article { align-items: stretch; flex-direction: column; }
  .help-content dl { grid-template-columns: 1fr; }
}

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