:root {
  --brand: oklch(48% .09 183);
  --brand-hover: oklch(42% .085 183);
  --brand-soft: oklch(96% .025 183);
  --accent: oklch(58% .13 68);
  --success: oklch(55% .14 155);
  --success-soft: oklch(96% .035 155);
  --warning: oklch(64% .14 74);
  --warning-soft: oklch(97% .035 74);
  --danger: oklch(54% .18 25);
  --danger-soft: oklch(97% .025 25);
  --ink: oklch(24% .025 240);
  --ink-strong: oklch(17% .03 240);
  --muted: oklch(50% .025 240);
  --muted-light: oklch(65% .02 240);
  --canvas: oklch(98% .008 220);
  --surface: oklch(99.5% .004 220);
  --surface-2: oklch(96.5% .012 220);
  --line: oklch(90% .015 220);
  --line-strong: oklch(82% .02 220);
  --shadow-sm: 0 1px 2px color-mix(in oklch, var(--ink) 7%, transparent);
  --shadow-md: 0 16px 36px -26px color-mix(in oklch, var(--ink) 32%, transparent);
  --ring: 0 0 0 3px color-mix(in oklch, var(--brand) 22%, transparent);
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei UI", "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", sans-serif;
  color: var(--ink);
  background: var(--canvas);
  font-family: var(--font-sans);
  font-synthesis: none;
  font-kerning: normal;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: var(--canvas); color: var(--ink); -webkit-font-smoothing: antialiased; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
a { color: var(--brand); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.skip-link { position: fixed; left: 16px; top: -60px; z-index: 200; background: var(--ink-strong); color: var(--surface); padding: 10px 14px; text-decoration: none; border-radius: var(--radius-sm); }
.skip-link:focus { top: 16px; }
.eyebrow { margin: 0; color: var(--brand); font-size: .75rem; font-weight: 750; letter-spacing: .04em; }
.mark { width: 38px; height: 38px; flex: 0 0 38px; display: grid; place-items: center; border-radius: var(--radius-sm); background: var(--brand); color: var(--surface); font-weight: 800; }

/* Login mirrors the restrained local workbench rather than a marketing page. */
.login-screen { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(360px, .85fr); background: var(--canvas); }
.login-brand { display: flex; flex-direction: column; justify-content: center; gap: var(--space-4); padding: clamp(48px, 8vw, 120px); border-right: 1px solid var(--line); }
.login-brand-lockup { display: flex; align-items: center; gap: 12px; margin-bottom: clamp(36px, 7vw, 84px); color: var(--ink-strong); font-size: 1rem; }
.login-brand h1 { margin: 0; max-width: 760px; color: var(--ink-strong); font-size: clamp(2.5rem, 5.2vw, 5.5rem); line-height: 1.08; letter-spacing: -.045em; }
.login-panel { align-self: center; margin: clamp(20px, 5vw, 72px); padding: clamp(32px, 5vw, 64px); display: grid; gap: var(--space-5); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow-md); }
.login-panel > div { display: flex; align-items: center; gap: 12px; }
.login-panel h2, dialog h2 { margin: 0; color: var(--ink-strong); font-size: 1.5rem; }

label { display: grid; gap: 8px; color: var(--ink); font-size: .875rem; font-weight: 650; }
input, textarea, select { width: 100%; min-height: 44px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink-strong); padding: 10px 12px; border-radius: var(--radius-sm); outline: none; transition: border-color .16s ease, box-shadow .16s ease, background .16s ease; }
textarea { min-height: 96px; resize: vertical; line-height: 1.65; }
input:hover, textarea:hover, select:hover { border-color: color-mix(in oklch, var(--brand) 48%, var(--line)); }
input:focus, textarea:focus, select:focus { border-color: var(--brand); box-shadow: var(--ring); }
.button { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid transparent; border-radius: var(--radius-sm); padding: 10px 16px; color: var(--ink); background: transparent; font-weight: 700; text-decoration: none; transition: background .16s ease, border-color .16s ease, color .16s ease, transform .16s ease; }
.button:focus-visible, .nav-item:focus-visible, .workspace-tabs button:focus-visible, .project-card:focus-visible, .text-button:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.button:active { transform: translateY(1px); }
.button:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.button.primary { background: var(--brand); color: var(--surface); }
.button.primary:hover { background: var(--brand-hover); }
.button.secondary { border-color: var(--line-strong); background: var(--surface); }
.button.secondary:hover { border-color: var(--brand); color: var(--brand); background: var(--brand-soft); }
.button.danger { border-color: color-mix(in oklch, var(--danger) 28%, var(--line)); color: var(--danger); background: var(--danger-soft); }
.form-error { min-height: 1.2em; margin: 0; color: var(--danger); font-size: .8125rem; line-height: 1.5; }

/* App shell */
.app-shell { min-height: 100vh; display: grid; grid-template-columns: 232px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 20px 14px max(20px, env(safe-area-inset-bottom)); background: var(--surface); border-right: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 11px; padding: 4px 8px 20px; color: var(--ink-strong); text-decoration: none; }
.brand strong { font-size: 1rem; }
nav { display: grid; gap: 3px; overflow-y: auto; padding-right: 2px; }
.nav-label { margin: 18px 10px 6px; color: var(--muted-light); font-size: .6875rem; font-weight: 750; letter-spacing: .08em; }
.nav-item { width: 100%; min-height: 42px; display: flex; align-items: center; gap: 11px; border: 0; border-radius: var(--radius-sm); padding: 8px 10px; color: var(--muted); background: transparent; text-align: left; font-weight: 650; }
.nav-item span { width: 24px; height: 24px; flex: 0 0 24px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 5px; color: var(--muted); background: var(--surface-2); font-size: .72rem; font-variant-numeric: tabular-nums; }
.nav-item:hover { color: var(--ink-strong); background: var(--surface-2); }
.nav-item.active { color: var(--brand-hover); background: var(--brand-soft); }
.nav-item.active span { border-color: color-mix(in oklch, var(--brand) 24%, var(--line)); color: var(--surface); background: var(--brand); }
.workflow-nav { font-weight: 720; }
.sidebar-footer { margin-top: auto; padding: 16px 8px 0; border-top: 1px solid var(--line); }
.user-chip { display: flex; align-items: center; gap: 10px; min-width: 0; }
.user-chip > span:first-child { width: 34px; height: 34px; flex: 0 0 34px; display: grid; place-items: center; border-radius: 50%; background: var(--brand-soft); color: var(--brand-hover); font-weight: 800; }
.user-chip > span:last-child { min-width: 0; }
.user-chip strong, .user-chip small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chip small { margin-top: 2px; color: var(--muted); font-size: .75rem; }
.identity-badge { display: inline-flex; margin-top: 10px; padding: 3px 7px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-size: .65rem; letter-spacing: .04em; }
.text-button { min-height: 40px; border: 0; background: transparent; color: var(--muted); padding: 10px 0 0; font-size: .78rem; }
.text-button:hover { color: var(--brand); }

main { min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 10; min-height: 88px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 18px clamp(24px, 4vw, 56px); background: color-mix(in oklch, var(--canvas) 94%, transparent); border-bottom: 1px solid var(--line); backdrop-filter: blur(14px); }
.topbar h1 { margin: 4px 0 0; color: var(--ink-strong); font-size: clamp(1.35rem, 1.8vw, 1.75rem); line-height: 1.2; }
.top-actions { display: flex; align-items: center; gap: 12px; }
.page { width: 100%; max-width: 1520px; padding: clamp(24px, 3vw, 44px) clamp(24px, 4vw, 56px) 72px; }

/* Home workbench */
.workbench-hero { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(280px, .72fr); gap: var(--space-6); align-items: end; padding: 4px 0 28px; border-bottom: 1px solid var(--line); }
.workbench-title { margin: 7px 0 10px; color: var(--ink-strong); font-size: clamp(2rem, 4vw, 3.4rem); line-height: 1.08; letter-spacing: -.035em; }
.workbench-lead { max-width: 62ch; margin: 0; color: var(--muted); font-size: 1rem; line-height: 1.75; }
.workbench-brief { padding: 16px 18px; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface); }
.brief-row { display: flex; justify-content: space-between; gap: 18px; padding: 9px 0; border-top: 1px solid var(--line); font-size: .8125rem; }
.brief-row:first-child { border-top: 0; }
.brief-row span { color: var(--muted); }
.brief-row strong { color: var(--ink-strong); font-variant-numeric: tabular-nums; }
.workflow-lane { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); margin: 24px 0 6px; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface); overflow: hidden; }
.workflow-step { min-height: 142px; display: grid; grid-template-columns: auto 1fr; align-content: start; gap: 4px 14px; padding: 22px; border: 0; border-right: 1px solid var(--line); color: var(--ink); background: transparent; text-align: left; }
.workflow-step:last-child { border-right: 0; }
.workflow-step:hover { background: var(--brand-soft); }
.workflow-step .step-index { grid-row: 1 / span 2; width: 34px; height: 34px; display: grid; place-items: center; border-radius: 50%; color: var(--surface); background: var(--brand); font-weight: 800; font-variant-numeric: tabular-nums; }
.workflow-step strong { color: var(--ink-strong); font-size: 1rem; }
.workflow-step p { grid-column: 2; margin: 2px 0 0; color: var(--muted); font-size: .8125rem; line-height: 1.65; }

/* Data and content primitives */
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.metric { padding: 18px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); }
.metric small { color: var(--muted); }
.metric strong { display: block; margin-top: 8px; color: var(--ink-strong); font-size: 1.65rem; font-weight: 750; font-variant-numeric: tabular-nums; }
.section-head { display: flex; align-items: end; justify-content: space-between; gap: 18px; margin: 36px 0 14px; }
.section-head.compact { margin-top: 0; }
.section-head h2 { margin: 0; color: var(--ink-strong); font-size: 1.1rem; }
.section-head p { margin: 5px 0 0; color: var(--muted); font-size: .8125rem; }
.panel { border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface); box-shadow: var(--shadow-sm); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .875rem; }
th { color: var(--muted); background: var(--surface-2); font-size: .75rem; letter-spacing: .025em; text-align: left; }
th, td { padding: 13px 15px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
.status { display: inline-flex; align-items: center; padding: 4px 8px; border-radius: 999px; color: var(--brand-hover); background: var(--brand-soft); font-size: .72rem; font-weight: 750; white-space: nowrap; }
.status.failed { color: var(--danger); background: var(--danger-soft); }
.status.queued, .status.parsing, .status.running, .status.in_progress { color: color-mix(in oklch, var(--warning) 78%, var(--ink)); background: var(--warning-soft); }
.project-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
.project-card { min-height: 174px; display: flex; flex-direction: column; padding: 19px; border: 1px solid var(--line); border-radius: var(--radius-md); color: var(--ink); background: var(--surface); text-align: left; transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease; }
.project-card:hover { border-color: color-mix(in oklch, var(--brand) 45%, var(--line)); transform: translateY(-2px); box-shadow: var(--shadow-md); }
.project-card h3 { margin: 18px 0 7px; color: var(--ink-strong); font-size: 1.05rem; }
.project-card p { margin: 0; color: var(--muted); font-size: .84rem; line-height: 1.6; }
.project-card footer { display: flex; justify-content: space-between; gap: 14px; margin-top: auto; padding-top: 20px; color: var(--muted); font-size: .74rem; }
.card-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.split { display: grid; grid-template-columns: minmax(280px, .72fr) minmax(0, 1.28fr); gap: 16px; align-items: start; }
.stack { display: grid; gap: 14px; }
.form-panel { display: grid; gap: 16px; padding: 20px; }
.form-panel h3, .operation-card h3, .instance-list h3, .knowledge-list h3, .image-card h3 { margin: 0 0 6px; color: var(--ink-strong); }
.form-panel p { margin: 0; line-height: 1.6; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.toolbar > * { width: auto; }
.empty { padding: 44px 24px; color: var(--muted); text-align: center; }
.empty strong { display: block; margin-bottom: 7px; color: var(--ink-strong); font-size: 1.05rem; }

/* Project workspace: local three-step mental model, server persistence underneath. */
.project-commandbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.project-switcher { width: min(360px, 100%); min-height: 40px; }
.project-summary { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 22px; align-items: center; padding: 15px 17px; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface); }
.project-summary p { margin: 5px 0 0; color: var(--muted); font-size: .84rem; line-height: 1.6; }
.project-summary > div:last-child { display: grid; justify-items: end; gap: 6px; }
.project-summary small { color: var(--muted); }
.workspace-tabs { display: grid; grid-template-columns: repeat(5, minmax(110px, 1fr)); gap: 6px; margin: 18px 0 22px; padding: 6px; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface-2); overflow-x: auto; }
.workspace-tabs button { min-height: 44px; border: 1px solid transparent; border-radius: var(--radius-sm); padding: 9px 12px; color: var(--muted); background: transparent; font-weight: 720; white-space: nowrap; }
.workspace-tabs button:hover { color: var(--ink-strong); background: var(--surface); }
.workspace-tabs button.active { border-color: var(--line); color: var(--brand-hover); background: var(--surface); box-shadow: var(--shadow-sm); }
.workspace-panel { min-height: 360px; animation: panel-in .24s cubic-bezier(.22, 1, .36, 1); }
.operation-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.operation-card { position: relative; display: grid; align-content: start; gap: 16px; padding: 21px; }
.operation-card p { margin: 0; color: var(--muted); font-size: .84rem; line-height: 1.65; }
.step-number { position: absolute; right: 18px; top: 17px; color: var(--brand); font-size: .8rem; font-weight: 800; }
.check { display: flex; grid-template-columns: none; align-items: center; gap: 9px; }
.check input { width: auto; min-height: auto; margin: 0; }
.inline-checks { display: flex; flex-wrap: wrap; gap: 18px; }
.generation-layout { grid-template-columns: minmax(280px, .62fr) minmax(0, 1.38fr); }
.instance-list { padding: 19px; }
.instance-list > button, .artifact-list > button { width: 100%; display: grid; gap: 4px; padding: 13px 2px; border: 0; border-top: 1px solid var(--line); color: var(--ink); background: transparent; text-align: left; }
.instance-list > button:hover, .artifact-list > button:hover { color: var(--brand); }
.instance-list span, .artifact-list span { color: var(--muted); font-size: .75rem; }
.artifact-editor textarea { min-height: 420px; font-size: .95rem; line-height: 1.8; }
.knowledge-list { max-height: 720px; overflow-y: auto; }
.knowledge-list article { padding: 20px; border-bottom: 1px solid var(--line); }
.knowledge-list article:last-child { border-bottom: 0; }
.knowledge-list article p { color: var(--muted); line-height: 1.7; white-space: pre-wrap; }
.knowledge-list article footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.scope, .dev-tag { display: inline-flex; padding: 3px 6px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-size: .65rem; }
.dev-tag { margin-left: 7px; color: var(--accent); }
.notice { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; padding: 13px 15px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); }
.notice strong { font-size: .86rem; }
.notice.warning { border-color: color-mix(in oklch, var(--warning) 24%, var(--line)); background: var(--warning-soft); }
.notice.success { border-color: color-mix(in oklch, var(--success) 24%, var(--line)); background: var(--success-soft); }
.import-grid { display: grid; grid-template-columns: 1.2fr .8fr; gap: 16px; }
.image-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.image-card { padding: 13px; }
.image-placeholder { aspect-ratio: 4 / 3; display: grid; place-items: center; border-radius: var(--radius-sm); color: var(--muted-light); background: var(--surface-2); font-size: 1.25rem; letter-spacing: .12em; }
.image-card h3 { margin-top: 13px; font-size: .93rem; line-height: 1.55; }
.image-card small { color: var(--muted); }
.row-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.row-actions a, .row-actions button, .text-danger { min-height: 30px; border: 0; background: transparent; color: var(--brand); padding: 4px 0; font-size: .78rem; text-decoration: none; }
.row-actions button:disabled { color: var(--muted-light); cursor: not-allowed; }
.row-actions .text-danger, .text-danger { color: var(--danger); }
.export-toolbar { justify-content: flex-end; }
.progress { width: 100%; height: 5px; overflow: hidden; border-radius: 99px; background: var(--line); }
.progress i { display: block; height: 100%; background: var(--brand); }

dialog { width: min(520px, calc(100vw - 32px)); border: 0; border-radius: var(--radius-lg); padding: 0; background: var(--surface); box-shadow: 0 28px 90px color-mix(in oklch, var(--ink) 30%, transparent); }
dialog::backdrop { background: color-mix(in oklch, var(--ink) 46%, transparent); backdrop-filter: blur(3px); }
.dialog-form { display: grid; gap: 19px; padding: 30px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; }
.toast { position: fixed; right: 24px; bottom: max(24px, env(safe-area-inset-bottom)); z-index: 100; max-width: 420px; padding: 13px 17px; border-radius: var(--radius-sm); color: var(--surface); background: var(--ink-strong); box-shadow: var(--shadow-md); opacity: 0; transform: translateY(12px); pointer-events: none; transition: opacity .2s ease, transform .2s ease; }
.toast.show { opacity: 1; transform: none; }
.toast.error { background: var(--danger); }

@keyframes panel-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

@media (max-width: 1180px) {
  .operation-grid { grid-template-columns: 1fr 1fr; }
  .operation-card:first-child { grid-column: 1 / -1; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 960px) {
  .workbench-hero, .split, .import-grid, .operation-grid, .generation-layout { grid-template-columns: 1fr; }
  .operation-card:first-child { grid-column: auto; }
  .workflow-lane { grid-template-columns: 1fr; }
  .workflow-step { min-height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .workflow-step:last-child { border-bottom: 0; }
  .project-commandbar { align-items: flex-start; flex-direction: column; }
  .export-toolbar { justify-content: flex-start; }
}

@media (max-width: 720px) {
  body { padding-bottom: env(safe-area-inset-bottom); }
  input, textarea, select { font-size: 1rem; }
  .login-screen { grid-template-columns: 1fr; }
  .login-brand { min-height: 36vh; padding: 40px 24px; border-right: 0; border-bottom: 1px solid var(--line); }
  .login-brand-lockup { margin-bottom: 28px; }
  .login-brand h1 { font-size: clamp(2rem, 10vw, 3.25rem); }
  .login-panel { margin: 16px; padding: 28px 22px; }
  .app-shell { display: block; }
  .sidebar { position: static; height: auto; padding: 12px 14px; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand { padding-bottom: 10px; }
  nav { display: flex; gap: 5px; overflow-x: auto; padding-bottom: 3px; }
  .nav-label { display: none; }
  .nav-item { width: auto; flex: 0 0 auto; white-space: nowrap; }
  .nav-item span { display: none; }
  .sidebar-footer { display: none; }
  .topbar { position: static; min-height: 76px; align-items: center; padding: 14px 18px; }
  .topbar .eyebrow { display: none; }
  .page { padding: 22px 18px 60px; }
  .metric-grid, .project-grid { grid-template-columns: 1fr; }
  .project-summary { grid-template-columns: 1fr; }
  .project-summary > div:last-child { justify-items: start; }
  .workspace-tabs { grid-template-columns: repeat(5, minmax(100px, 1fr)); }
  .dialog-actions { flex-direction: column-reverse; }
  .dialog-actions .button { width: 100%; }
}

@media (pointer: coarse) {
  .nav-item, .workspace-tabs button, .row-actions a, .row-actions button { min-height: 44px; }
}

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