:root {
  --paper: #f1eee5;
  --paper-2: #fbfaf5;
  --ink: #18262b;
  --muted: #697379;
  --line: rgba(24, 38, 43, .14);
  --line-strong: rgba(24, 38, 43, .28);
  --teal: #116c72;
  --teal-soft: #dcebea;
  --signal: #ec6438;
  --signal-soft: #f9dfd3;
  --amber: #d69a22;
  --green: #277a55;
  --red: #b44337;
  --shadow: 0 18px 50px rgba(35, 42, 40, .08);
  --display: "Songti SC", "STSong", "Noto Serif CJK SC", serif;
  --body: "Avenir Next", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--paper); }
body { margin: 0; color: var(--ink); font-family: var(--body); background:
  radial-gradient(circle at 14% 2%, rgba(236,100,56,.12), transparent 26rem),
  radial-gradient(circle at 83% 18%, rgba(17,108,114,.12), transparent 30rem),
  linear-gradient(135deg, #f6f2e8, #ecebe3 60%, #f4eee3); min-height: 100vh; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.grain { position: fixed; inset: 0; pointer-events: none; opacity: .18; z-index: 10; background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.82' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.16'/%3E%3C/svg%3E"); mix-blend-mode: multiply; }

.topbar { height: 76px; padding: 0 28px; display: flex; align-items: center; gap: 28px; border-bottom: 1px solid var(--line); background: rgba(249,247,240,.82); backdrop-filter: blur(18px); position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: var(--ink); min-width: 265px; }
.brand-mark { display: grid; place-items: center; width: 42px; height: 42px; background: var(--ink); color: var(--paper-2); border-radius: 50% 50% 48% 15%; font: 700 21px var(--display); transform: rotate(-4deg); }
.brand strong { display: block; letter-spacing: .16em; font: 700 18px var(--display); }
.brand small { color: var(--muted); font-size: 11px; letter-spacing: .18em; }
.top-status { display: flex; align-items: center; gap: 9px; font-size: 12px; color: var(--muted); flex: 1; }
.pulse-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 0 rgba(39,122,85,.4); animation: pulse 2s infinite; }
.divider { width: 1px; height: 18px; background: var(--line); margin: 0 5px; }
.run-badge { display: flex; align-items: center; gap: 9px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 999px; background: rgba(255,255,255,.48); font-size: 11px; }
.run-badge span { color: var(--teal); font-weight: 800; letter-spacing: .13em; }

.app-shell { display: grid; grid-template-columns: 240px minmax(540px, 1fr) 340px; gap: 18px; max-width: 1720px; margin: 0 auto; padding: 18px; align-items: start; }
.pipeline-panel, .copilot-panel { position: sticky; top: 94px; max-height: calc(100vh - 112px); }
.pipeline-panel { padding: 22px 16px 18px 10px; }
.pipeline-panel h1, .stage-header h2, .console-heading h2, .copilot-heading h2, dialog h2 { font: 600 25px/1.15 var(--display); margin: 4px 0 8px; letter-spacing: .02em; }
.eyebrow { display: inline-block; font-size: 10px; font-weight: 800; letter-spacing: .18em; color: var(--teal); text-transform: uppercase; }
.muted { color: var(--muted); line-height: 1.6; font-size: 12px; }
.pipeline { margin-top: 24px; position: relative; }
.pipeline:before { content: ""; position: absolute; left: 17px; top: 24px; bottom: 28px; width: 1px; background: var(--line-strong); }
.flow-step { position: relative; display: grid; grid-template-columns: 36px 1fr; gap: 10px; padding: 8px 6px; margin-bottom: 10px; border-radius: 12px; transition: .2s ease; }
.flow-step button { all: unset; display: contents; cursor: pointer; }
.flow-step:hover, .flow-step.active { background: rgba(255,255,255,.55); }
.step-index { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 50%; border: 1px solid var(--line-strong); background: var(--paper); font-size: 10px; font-weight: 800; z-index: 1; }
.flow-step.complete .step-index { background: var(--teal); color: white; border-color: var(--teal); }
.flow-step.active .step-index { background: var(--signal); color: white; border-color: var(--signal); box-shadow: 0 0 0 5px rgba(236,100,56,.12); }
.flow-step.locked { opacity: .48; }
.step-copy strong { display: block; font-size: 13px; margin-top: 2px; }
.step-copy small { display: block; color: var(--muted); font-size: 10px; margin-top: 3px; }
.policy-note { display: flex; gap: 10px; margin-top: 24px; padding: 14px; border: 1px solid rgba(214,154,34,.32); background: rgba(255,247,219,.58); border-radius: 14px; }
.policy-icon { flex: 0 0 24px; width: 24px; height: 24px; border-radius: 50%; background: var(--amber); color: white; display: grid; place-items: center; font-weight: 800; }
.policy-note strong { font-size: 12px; }
.policy-note p { margin: 4px 0 0; font-size: 10px; color: var(--muted); line-height: 1.55; }

.workbench { min-width: 0; display: grid; gap: 18px; }
.project-console, .stage-board, .copilot-panel { border: 1px solid var(--line); background: rgba(251,250,245,.78); box-shadow: var(--shadow); }
.project-console { padding: 20px; border-radius: 18px 18px 8px 8px; animation: rise .45s ease both; }
.console-heading, .stage-header { display: flex; align-items: start; justify-content: space-between; gap: 16px; }
.console-heading h2 { font-size: 21px; }
.settings-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-top: 14px; }
label > span { display: block; font-size: 10px; font-weight: 800; letter-spacing: .08em; color: var(--muted); margin: 0 0 6px; }
input, select, textarea { width: 100%; border: 1px solid var(--line); border-radius: 9px; background: rgba(255,255,255,.78); padding: 10px 11px; outline: none; transition: border .2s, box-shadow .2s; }
input:focus, select:focus, textarea:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(17,108,114,.1); }
input[readonly], input:disabled { background: rgba(24,38,43,.055); color: var(--muted); cursor: not-allowed; }
textarea { resize: vertical; line-height: 1.55; }
.consent-row { display: flex; align-items: flex-start; gap: 10px; margin-top: 14px; padding: 10px 12px; border-left: 3px solid var(--amber); background: rgba(255,247,219,.45); }
.consent-row input { width: auto; margin-top: 3px; }
.consent-row span { margin: 0; letter-spacing: 0; }
.consent-row strong { display: block; font-size: 11px; }
.consent-row small { display: block; margin-top: 2px; font-size: 10px; font-weight: 400; color: var(--muted); }
.upload-row { display: flex; align-items: center; gap: 12px; margin-top: 14px; padding: 14px; border: 1px dashed var(--line-strong); border-radius: 12px; background: rgba(255,255,255,.4); }
.upload-row.dragging { border-color: var(--signal); background: var(--signal-soft); }
.upload-row input { width: 92px; padding: 0; border: 0; background: none; color: transparent; }
.upload-row input::file-selector-button { color: var(--ink); border: 1px solid var(--line); background: var(--paper-2); border-radius: 8px; padding: 8px 10px; cursor: pointer; }
.upload-copy { flex: 1; min-width: 140px; }
.upload-copy strong, .upload-copy span { display: block; }
.upload-copy strong { font: 600 15px var(--display); }
.upload-copy span { font-size: 10px; color: var(--muted); margin-top: 3px; }
.file-list { display: flex; gap: 7px; flex-wrap: wrap; margin-top: 10px; }
.file-pill { display: inline-flex; gap: 7px; align-items: center; padding: 5px 8px; border-radius: 7px; background: var(--teal-soft); color: var(--teal); font-size: 10px; }

.primary-button, .secondary-button, .quiet-button, .danger-button { border-radius: 9px; padding: 9px 13px; font-weight: 750; font-size: 11px; border: 1px solid transparent; transition: transform .16s, box-shadow .16s, background .16s; white-space: nowrap; }
.primary-button { background: var(--signal); color: white; box-shadow: 0 5px 16px rgba(236,100,56,.2); }
.secondary-button { background: var(--ink); color: white; }
.quiet-button { background: transparent; border-color: var(--line); }
.danger-button { background: #fff2ef; color: var(--red); border-color: rgba(180,67,55,.25); }
button:hover:not(:disabled) { transform: translateY(-1px); }
button:disabled { cursor: not-allowed; opacity: .45; }

.stage-board { border-radius: 8px 8px 20px 20px; min-height: 550px; overflow: hidden; animation: rise .55s .05s ease both; }
.stage-header { padding: 24px 26px 18px; }
.stage-header h2 { font-size: 31px; }
.stage-header p { color: var(--muted); margin: 0; font-size: 12px; }
.view-tabs { display: flex; padding: 0 24px; border-bottom: 1px solid var(--line); }
.view-tabs button { border: 0; background: transparent; padding: 12px 14px; font-size: 11px; color: var(--muted); position: relative; }
.view-tabs button.active { color: var(--ink); font-weight: 800; }
.view-tabs button.active:after { content: ""; position: absolute; height: 3px; left: 12px; right: 12px; bottom: -1px; background: var(--signal); }
.document-content { padding: 22px 24px 30px; }
.document-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 13px 14px; background: rgba(24,38,43,.035); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 15px; }
.document-meta { display: flex; gap: 15px; align-items: center; flex-wrap: wrap; }
.document-meta span { font-size: 10px; color: var(--muted); }
.document-meta strong { color: var(--ink); }
.toolbar-actions, .card-actions { display: flex; gap: 7px; flex-wrap: wrap; }
.status-badge { display: inline-flex; align-items: center; gap: 6px; border: 1px solid currentColor; border-radius: 999px; padding: 5px 9px; font-size: 9px; font-weight: 900; letter-spacing: .08em; }
.status-badge:before { content: ""; width: 6px; height: 6px; background: currentColor; border-radius: 50%; }
.status-approved { color: var(--green); background: rgba(39,122,85,.08); }
.status-pending { color: var(--amber); background: rgba(214,154,34,.09); }
.status-review_required, .status-rejected { color: var(--signal); background: rgba(236,100,56,.08); }
.status-confirmed, .status-corrected { color: var(--teal); background: rgba(17,108,114,.08); }
.status-locked { color: var(--muted); }
.item-grid { display: grid; gap: 12px; }
.attribution-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.attribution-card { border: 1px solid var(--line); border-radius: 14px; background: rgba(255,255,255,.64); overflow: hidden; animation: rise .36s ease both; }
.attribution-card > header { display: flex; justify-content: space-between; gap: 12px; padding: 16px 17px 12px; border-bottom: 1px solid var(--line); }
.attribution-card h3 { margin: 5px 0 0; font: 600 15px/1.35 var(--display); overflow-wrap: anywhere; }
.attribution-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; padding: 13px 17px; }
.field-pair { min-width: 0; padding: 8px 9px; border-radius: 8px; background: var(--paper); }
.field-pair small { display: block; color: var(--muted); font-size: 8px; letter-spacing: .08em; text-transform: uppercase; }
.field-pair strong { display: block; margin-top: 3px; font-size: 10px; overflow-wrap: anywhere; }
.attribution-card > section { padding: 0 17px 14px; }
.attribution-card > section h4 { margin: 0 0 6px; color: var(--muted); font-size: 8px; letter-spacing: .11em; text-transform: uppercase; }
.attribution-card > section p { margin: 0; font-size: 10px; line-height: 1.6; }
.attribution-card > footer { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 11px 17px; border-top: 1px solid var(--line); background: rgba(241,238,229,.48); }
.next-stage { margin-top: 15px; margin-bottom: 0; }
.next-stage > div span { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; }
.analysis-card { border: 1px solid var(--line); border-radius: 14px; background: rgba(255,255,255,.64); overflow: hidden; animation: rise .36s ease both; scroll-margin-top: 110px; }
.analysis-card:nth-child(2) { animation-delay: .04s; }.analysis-card:nth-child(3) { animation-delay: .08s; }.analysis-card:nth-child(4) { animation-delay: .12s; }
.card-top { display: flex; justify-content: space-between; gap: 16px; padding: 17px 18px 13px; }
.card-id { color: var(--teal); font: 800 9px var(--body); letter-spacing: .14em; }
.card-top h3 { margin: 4px 0 5px; font: 600 19px var(--display); }
.card-top p { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.6; }
.type-tag { display: inline-flex; margin-left: 7px; padding: 2px 6px; border-radius: 4px; color: var(--signal); background: var(--signal-soft); font: 800 8px var(--body); vertical-align: middle; }
.card-body { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; padding: 0 18px 16px; }
.data-block { border-top: 1px solid var(--line); padding-top: 11px; }
.data-block.wide { grid-column: 1 / -1; }
.data-block h4 { margin: 0 0 8px; color: var(--muted); font-size: 9px; letter-spacing: .12em; text-transform: uppercase; }
.data-block p, .data-block li { font-size: 11px; line-height: 1.6; }
.data-block ul { padding-left: 17px; margin: 0; }
.cia-row, .score-row { display: flex; flex-wrap: wrap; gap: 7px; }
.metric { padding: 7px 9px; border-radius: 7px; background: var(--paper); min-width: 72px; }
.metric small { display: block; font-size: 8px; color: var(--muted); }
.metric strong { display: block; margin-top: 2px; font-size: 11px; }
.risk-critical { color: #a82e2e; }.risk-high { color: var(--signal); }.risk-medium { color: var(--amber); }.risk-low { color: var(--green); }
.evidence-links { display: flex; flex-wrap: wrap; gap: 5px; }
.evidence-link { border: 0; border-bottom: 1px solid var(--teal); padding: 2px 0; background: transparent; color: var(--teal); font: 750 9px var(--body); }
.card-footer { display: flex; align-items: center; justify-content: space-between; gap: 10px; border-top: 1px solid var(--line); padding: 11px 18px; background: rgba(241,238,229,.48); }
.confidence { min-width: 140px; }
.confidence header { display: flex; justify-content: space-between; font-size: 9px; color: var(--muted); }
.confidence-bar { height: 4px; border-radius: 5px; background: var(--line); margin-top: 5px; overflow: hidden; }
.confidence-bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--amber), var(--teal)); }
.attack-path { display: grid; gap: 6px; }
.attack-step { display: grid; grid-template-columns: 24px 1fr; gap: 8px; align-items: start; }
.attack-step b { width: 23px; height: 23px; border: 1px solid var(--line); border-radius: 50%; display: grid; place-items: center; color: var(--teal); font-size: 9px; }
.attack-step span { font-size: 10px; line-height: 1.5; }
.empty-state { min-height: 310px; display: grid; place-items: center; text-align: center; border: 1px dashed var(--line-strong); border-radius: 14px; background: rgba(255,255,255,.3); }
.empty-state .symbol { width: 65px; height: 65px; margin: auto; display: grid; place-items: center; border-radius: 50%; border: 1px solid var(--line-strong); font: 600 29px var(--display); color: var(--teal); }
.empty-state h3 { font: 600 21px var(--display); margin: 12px 0 5px; }
.empty-state p { color: var(--muted); font-size: 11px; max-width: 360px; line-height: 1.6; }
.trace-table { width: 100%; border-collapse: collapse; font-size: 10px; }
.trace-table th { text-align: left; color: var(--muted); font-size: 8px; letter-spacing: .11em; padding: 10px; border-bottom: 1px solid var(--line-strong); }
.trace-table td { padding: 12px 10px; border-bottom: 1px solid var(--line); vertical-align: top; line-height: 1.5; }
.trace-link { border: 0; background: transparent; color: var(--teal); padding: 0; font-weight: 800; text-decoration: underline; text-underline-offset: 3px; }

.copilot-panel { border-radius: 18px; overflow: hidden; display: flex; flex-direction: column; height: calc(100vh - 112px); animation: rise .6s .1s ease both; }
.copilot-heading { display: flex; align-items: center; gap: 11px; padding: 18px; border-bottom: 1px solid var(--line); }
.copilot-heading h2 { font-size: 20px; margin-bottom: 0; }
.agent-avatar { width: 39px; height: 39px; display: grid; place-items: center; border-radius: 50% 50% 18% 50%; background: var(--teal); color: white; font-size: 11px; font-weight: 900; }
.scope-strip { padding: 8px 17px; background: var(--teal-soft); color: var(--teal); font-size: 9px; }
.scope-strip span { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--green); margin-right: 5px; }
.chat-messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.message { max-width: 91%; padding: 11px 12px; border-radius: 12px; font-size: 11px; line-height: 1.65; animation: rise .25s ease both; }
.message p { margin: 3px 0 0; white-space: pre-wrap; }
.message small { font-size: 8px; font-weight: 900; letter-spacing: .12em; color: var(--teal); }
.message.assistant { align-self: flex-start; background: var(--paper); border: 1px solid var(--line); border-bottom-left-radius: 3px; }
.message.user { align-self: flex-end; background: var(--ink); color: white; border-bottom-right-radius: 3px; }
.message.user small { color: #b9ddda; }
.message.error { border-color: rgba(180,67,55,.35); background: #fff0ed; }
.message-evidence { margin-top: 8px; display: flex; gap: 5px; flex-wrap: wrap; }
.quick-prompts { display: flex; gap: 5px; flex-wrap: wrap; padding: 0 14px 10px; }
.quick-prompts button { border: 1px solid var(--line); border-radius: 999px; background: transparent; padding: 5px 8px; font-size: 8px; color: var(--muted); }
.chat-form { padding: 13px; border-top: 1px solid var(--line); background: rgba(255,255,255,.48); }
.chat-form textarea { font-size: 11px; }
.chat-form > div { display: flex; justify-content: space-between; align-items: center; margin-top: 7px; }
.chat-form span { color: var(--muted); font-size: 8px; }
.chat-form button { border: 0; border-radius: 8px; background: var(--signal); color: white; padding: 7px 13px; font-size: 10px; font-weight: 800; }

dialog { color: var(--ink); border: 0; padding: 0; box-shadow: 0 30px 100px rgba(24,38,43,.28); background: var(--paper-2); }
dialog::backdrop { background: rgba(17,26,29,.48); backdrop-filter: blur(5px); }
.editor-dialog { width: min(760px, calc(100vw - 30px)); max-height: 88vh; border-radius: 18px; }
.review-dialog { width: min(520px, calc(100vw - 30px)); border-radius: 18px; }
.editor-dialog form { display: flex; flex-direction: column; max-height: 88vh; }
.editor-dialog header, .evidence-dialog header, .review-dialog header { display: flex; justify-content: space-between; align-items: center; padding: 19px 22px 14px; border-bottom: 1px solid var(--line); }
.icon-button { border: 0; background: transparent; font: 300 27px/1 var(--body); color: var(--muted); }
.editor-fields { overflow-y: auto; padding: 20px 22px; display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.editor-fields .wide { grid-column: 1 / -1; }
.editor-fields label { font-size: 10px; font-weight: 800; color: var(--muted); }
.editor-fields label input, .editor-fields label textarea, .editor-fields label select { margin-top: 6px; color: var(--ink); font-weight: 400; }
.editor-dialog footer { padding: 14px 22px; border-top: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 14px; }
.editor-dialog footer p { color: var(--muted); font-size: 9px; max-width: 420px; }
.editor-dialog footer > div { display: flex; gap: 8px; }
.review-fields { padding: 20px 22px; }
.review-fields label { font-size: 10px; font-weight: 800; color: var(--muted); }
.review-fields textarea { margin-top: 7px; }
.review-dialog footer { padding: 14px 22px; border-top: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.review-dialog footer p { color: var(--muted); font-size: 9px; }
.review-dialog footer > div { display: flex; gap: 8px; }
.evidence-dialog { width: min(620px, calc(100vw - 30px)); border-radius: 18px; }
.evidence-dialog #evidenceBody { padding: 22px; }
.evidence-text { font: 14px/1.8 var(--display); padding: 16px; background: var(--paper); border-left: 3px solid var(--teal); white-space: pre-wrap; }
.evidence-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; font-size: 9px; color: var(--muted); }

.busy-layer { position: fixed; inset: 0; z-index: 100; display: grid; place-content: center; justify-items: center; background: rgba(241,238,229,.82); backdrop-filter: blur(12px); }
.busy-layer[hidden] { display: none; }
.busy-layer strong { font: 600 22px var(--display); margin-top: 17px; }
.busy-layer span { color: var(--muted); margin-top: 5px; font-size: 11px; letter-spacing: .14em; }
.radar { position: relative; width: 76px; height: 76px; border-radius: 50%; border: 1px solid var(--teal); }
.radar:after { content: ""; position: absolute; width: 50%; height: 1px; left: 50%; top: 50%; transform-origin: left; background: var(--signal); animation: sweep 1.5s linear infinite; }
.radar i { position: absolute; inset: 15px; border: 1px solid rgba(17,108,114,.28); border-radius: 50%; }.radar i:nth-child(2) { inset: 29px; }.radar i:nth-child(3) { inset: 36px; background: var(--teal); }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 110; max-width: 420px; padding: 12px 15px; border-radius: 10px; background: var(--ink); color: white; font-size: 11px; box-shadow: var(--shadow); transform: translateY(20px); opacity: 0; pointer-events: none; transition: .25s ease; }
.toast.show { transform: translateY(0); opacity: 1; }
.toast.bad { background: var(--red); }

@keyframes pulse { 70% { box-shadow: 0 0 0 8px rgba(39,122,85,0); } 100% { box-shadow: 0 0 0 0 rgba(39,122,85,0); } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes sweep { to { transform: rotate(360deg); } }

@media (max-width: 1260px) {
  .app-shell { grid-template-columns: 210px minmax(500px, 1fr); }
  .copilot-panel { grid-column: 2; position: static; height: 620px; max-height: none; }
  .settings-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 820px) {
  .topbar { padding: 0 15px; height: 66px; }.brand { min-width: 0; }.brand small, .top-status, .run-badge strong { display: none; }
  .app-shell { display: block; padding: 10px; }.pipeline-panel { position: static; padding: 14px 5px; max-height: none; }
  .pipeline { display: flex; overflow-x: auto; gap: 5px; margin-top: 12px; padding-bottom: 4px; }.pipeline:before { display: none; }.flow-step { min-width: 145px; margin: 0; }
  .workbench { margin-top: 8px; }.project-console { padding: 15px; }.upload-row { flex-wrap: wrap; }.upload-copy { order: -1; width: 100%; flex-basis: 100%; }
  .stage-header { padding: 20px 17px 14px; }.stage-header h2 { font-size: 25px; }.document-content { padding: 16px 13px 23px; }.view-tabs { padding: 0 8px; }
  .card-body { grid-template-columns: 1fr; }.data-block.wide { grid-column: auto; }.document-toolbar, .card-top, .card-footer { align-items: flex-start; flex-direction: column; }
  .attribution-grid { grid-template-columns: 1fr; }.attribution-card > footer { align-items: flex-start; flex-direction: column; }
  .copilot-panel { margin-top: 14px; height: 620px; }.editor-fields { grid-template-columns: 1fr; }.editor-fields .wide { grid-column: auto; }.editor-dialog footer { align-items: flex-start; flex-direction: column; }
}
@media (max-width: 480px) {
  .settings-grid { grid-template-columns: 1fr; }.upload-row button { flex: 1; }.stage-header { flex-direction: column; }.trace-table { display: block; overflow-x: auto; }.brand strong { font-size: 16px; }
}

.evidence-search { padding: 12px 14px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.38); }
.evidence-search > label { display: block; margin-bottom: 6px; color: var(--muted); font-size: 8px; font-weight: 900; letter-spacing: .12em; text-transform: uppercase; }
.evidence-search > div { display: grid; grid-template-columns: 1fr auto; gap: 6px; }
.evidence-search input { min-width: 0; padding: 8px 9px; font-size: 10px; }
.evidence-search > div button { border: 0; border-radius: 7px; padding: 0 11px; color: white; background: var(--teal); font-size: 9px; font-weight: 800; }
.evidence-search > section { display: grid; gap: 6px; max-height: 250px; overflow-y: auto; margin-top: 9px; }
.evidence-search > section > button { display: block; width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 8px; text-align: left; color: var(--ink); background: var(--paper); }
.evidence-search > section strong, .evidence-search > section span { display: block; }
.evidence-search > section strong { color: var(--teal); font-size: 9px; }
.evidence-search > section span { margin-top: 2px; color: var(--muted); font-size: 8px; }
.evidence-search > section p { margin: 5px 0 0; font-size: 9px; line-height: 1.45; }
.field-evidence-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
.field-evidence { border: 1px solid var(--line); border-left: 3px solid var(--green); border-radius: 8px; padding: 9px; background: var(--paper); }
.field-evidence.blocked { border-left-color: var(--signal); background: var(--signal-soft); }
.field-evidence header { display: flex; justify-content: space-between; gap: 8px; }
.field-evidence header strong { font-size: 10px; }
.field-evidence header span { color: var(--muted); font-size: 8px; font-weight: 900; }
.field-evidence p, .field-evidence small { display: block; margin: 5px 0; color: var(--muted); font-size: 8px; line-height: 1.45; }
.evidence-gate { margin: 0; padding: 9px; border-radius: 7px; font-size: 9px; }
.evidence-gate.blocked { color: var(--red); background: #fff0ed; }
.evidence-bindings { margin-top: 16px; }
.evidence-bindings h3 { font-size: 11px; }
.evidence-bindings li { margin: 7px 0; font-size: 9px; line-height: 1.5; }
@media (max-width: 820px) { .field-evidence-grid { grid-template-columns: 1fr; } }

/* Touch-first layout: keep the full workflow usable on narrow phone screens. */
@media (max-width: 820px) {
  body { padding-bottom: env(safe-area-inset-bottom); }
  .topbar {
    height: calc(64px + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) calc(12px + env(safe-area-inset-right)) 0 calc(12px + env(safe-area-inset-left));
    gap: 12px;
  }
  .brand { gap: 9px; }
  .brand-mark { width: 38px; height: 38px; font-size: 18px; }
  .run-badge { margin-left: auto; padding: 7px 10px; }

  .app-shell { padding: 8px max(8px, env(safe-area-inset-right)) 12px max(8px, env(safe-area-inset-left)); }
  .pipeline-panel { padding: 8px 2px 6px; }
  .pipeline-panel > .eyebrow, .pipeline-panel > h1, .pipeline-panel > .muted { display: none; }
  .pipeline {
    margin-top: 0;
    padding: 2px 0 8px;
    scroll-snap-type: x proximity;
    scrollbar-width: thin;
    -webkit-overflow-scrolling: touch;
  }
  .flow-step { min-width: 132px; padding: 6px; scroll-snap-align: start; }
  .step-index { width: 34px; height: 34px; }
  .policy-note { align-items: center; margin-top: 4px; padding: 8px 10px; }
  .policy-note p { display: none; }

  .project-console { padding: 14px; border-radius: 16px 16px 8px 8px; }
  .console-heading { align-items: center; }
  .settings-grid { grid-template-columns: 1fr; gap: 12px; }
  input, select, textarea { min-height: 44px; font-size: 16px; }
  textarea { min-height: 88px; }
  .consent-row input { min-height: 22px; min-width: 22px; }
  .upload-row { display: grid; grid-template-columns: 1fr; gap: 10px; padding: 12px; }
  .upload-copy, .upload-row input { grid-column: 1 / -1; width: 100%; }
  .upload-row input { color: inherit; }
  .upload-row button { width: 100%; min-width: 0; }

  .primary-button, .secondary-button, .quiet-button, .danger-button {
    min-height: 44px;
    padding: 11px 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    text-decoration: none;
    touch-action: manipulation;
  }
  .view-tabs {
    position: sticky;
    top: calc(64px + env(safe-area-inset-top));
    z-index: 12;
    overflow-x: auto;
    padding: 0 8px;
    background: rgba(251,250,245,.96);
    scroll-snap-type: x proximity;
    scrollbar-width: thin;
    -webkit-overflow-scrolling: touch;
  }
  .view-tabs button { flex: 0 0 auto; min-height: 44px; padding: 12px 14px; white-space: nowrap; scroll-snap-align: start; touch-action: manipulation; }
  .stage-header { padding-top: 18px; }
  .document-content { overflow-x: hidden; }
  .toolbar-actions, .card-actions { width: 100%; }
  .toolbar-actions > *, .card-actions > * { flex: 1 1 120px; }
  .trace-table { display: block; width: 100%; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .trace-link, .evidence-link { min-height: 44px; padding: 8px 2px; touch-action: manipulation; }

  .copilot-panel { height: min(72svh, 560px); min-height: 480px; }
  .evidence-search > div button, .chat-form button { min-width: 56px; min-height: 44px; font-size: 11px; touch-action: manipulation; }
  .quick-prompts { display: grid; grid-template-columns: 1fr; }
  .quick-prompts button { min-height: 44px; padding: 9px 11px; text-align: left; font-size: 10px; touch-action: manipulation; }
  .chat-form textarea { min-height: 88px; font-size: 16px; }

  .editor-dialog, .evidence-dialog, .review-dialog {
    width: 100%;
    max-width: none;
    max-height: calc(100dvh - 12px);
    margin: auto 0 0;
    border-radius: 20px 20px 0 0;
  }
  .editor-dialog form { max-height: calc(100dvh - 12px); }
  .editor-dialog header, .evidence-dialog header, .review-dialog header { padding: 14px 16px 12px; }
  .editor-fields, .review-fields, #evidenceBody { padding: 15px 16px; }
  .editor-dialog footer, .review-dialog footer { padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); }
  .icon-button { min-width: 44px; min-height: 44px; touch-action: manipulation; }
}

@media (max-width: 480px) {
  .brand strong { font-size: 15px; }
  .app-shell { padding-left: 7px; padding-right: 7px; }
  .project-console { padding: 13px; }
  .upload-row { grid-template-columns: 1fr; }
  .upload-row button { width: 100%; }
  .attribution-fields { grid-template-columns: 1fr; }
  .metric { flex: 1 1 calc(50% - 7px); }
  .confidence { width: 100%; min-width: 0; }
  .stage-header h2 { font-size: 23px; }
  .document-content { padding-left: 11px; padding-right: 11px; }
  .toast { left: 10px; right: 10px; bottom: calc(10px + env(safe-area-inset-bottom)); text-align: center; }
}
