:root {
  --ink: #17211d;
  --muted: #66736d;
  --line: #dde5df;
  --panel: #ffffff;
  --canvas: #f4f6f3;
  --brand: #155f49;
  --brand-dark: #0e4938;
  --brand-soft: #e5f3ec;
  --accent: #e4a739;
  --danger: #b53632;
  --warning: #9b6718;
  --shadow: 0 18px 50px rgba(27, 48, 39, .08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--canvas);
  font-synthesis: none;
}

* { box-sizing: border-box; }
/* Author display rules must not override the application's visibility state. */
[hidden] { display: none !important; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: radial-gradient(circle at 85% 0, rgba(213, 237, 223, .65), transparent 28rem), var(--canvas); }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }
button { cursor: pointer; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: .55rem; font-size: clamp(2rem, 3vw, 3rem); letter-spacing: -.045em; line-height: 1.05; }
h2 { margin-bottom: .35rem; font-size: 1.35rem; letter-spacing: -.025em; }
h3 { margin-bottom: .25rem; }
.muted, small { color: var(--muted); }

.topbar { height: 72px; padding: 0 clamp(1rem, 4vw, 3.25rem); display: flex; align-items: center; gap: 2rem; border-bottom: 1px solid rgba(199, 211, 203, .8); background: rgba(255,255,255,.85); backdrop-filter: blur(18px); position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: .75rem; margin-right: auto; }
.brand > span:last-child { display: flex; flex-direction: column; line-height: 1.15; }
.brand small { font-size: .72rem; margin-top: .15rem; }
.brand-mark { display: grid; place-items: center; width: 36px; height: 36px; color: white; background: var(--brand); border-radius: 11px 11px 11px 3px; font-weight: 800; box-shadow: 0 8px 18px rgba(21,95,73,.25); }
.brand-mark.large { width: 52px; height: 52px; font-size: 1.4rem; margin-bottom: 1.6rem; }
.topbar nav { display: flex; align-self: stretch; gap: .25rem; }
.topbar nav a { display: grid; place-items: center; padding: 0 1rem; color: var(--muted); font-size: .9rem; font-weight: 650; border-bottom: 2px solid transparent; }
.topbar nav a:hover, .topbar nav a.active { color: var(--brand); border-bottom-color: var(--brand); }

.page-shell { width: min(1500px, calc(100% - 2rem)); margin: 0 auto; padding: clamp(2rem, 5vw, 4.5rem) 0 5rem; }
.page-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 2rem; margin-bottom: 2rem; }
.page-heading p:not(.eyebrow) { color: var(--muted); max-width: 730px; margin-bottom: 0; }
.eyebrow, .step-label { color: var(--brand); margin: 0 0 .45rem; text-transform: uppercase; letter-spacing: .13em; font-size: .68rem; font-weight: 800; }
.status-pill { display: inline-flex; align-items: center; justify-content: center; white-space: nowrap; padding: .36rem .65rem; border-radius: 999px; background: #eef1ef; color: #56615c; font-size: .7rem; font-weight: 750; text-transform: capitalize; }
.status-pill.success { color: var(--brand-dark); background: var(--brand-soft); }
.status-pill.running { color: #765013; background: #fff2d5; }
.status-pill.danger { color: #8d2926; background: #fbe8e6; }

.workflow-steps { list-style: none; display: grid; grid-template-columns: repeat(3, 1fr); padding: 0; margin: 0 0 1.5rem; border: 1px solid var(--line); border-radius: 14px; background: rgba(255,255,255,.6); overflow: hidden; }
.workflow-steps li { position: relative; display: flex; gap: .8rem; align-items: center; padding: .85rem 1rem; color: #89938f; }
.workflow-steps li:not(:last-child)::after { content: ""; position: absolute; right: 0; width: 1px; height: 55%; background: var(--line); }
.workflow-steps li > span { display: grid; place-items: center; width: 27px; height: 27px; border: 1px solid #bec8c2; border-radius: 50%; font-size: .75rem; font-weight: 800; }
.workflow-steps li div { display: flex; flex-direction: column; }
.workflow-steps li small { font-size: .68rem; }
.workflow-steps li.active { color: var(--brand); background: var(--brand-soft); }
.workflow-steps li.active > span, .workflow-steps li.done > span { color: white; background: var(--brand); border-color: var(--brand); }
.workflow-steps li.done > span { font-size: 0; }
.workflow-steps li.done > span::after { content: "✓"; font-size: .8rem; }

.context-disclosure { margin-bottom: 1.5rem; border-bottom: 1px solid var(--line); }
.context-disclosure summary { width: max-content; padding: .5rem 0 1rem; color: var(--muted); font-size: .8rem; font-weight: 700; cursor: pointer; }
.context-row { display: flex; align-items: end; flex-wrap: wrap; gap: .75rem; padding: 0 0 1.1rem; }
.context-row label { min-width: 220px; }
.context-row > span { align-self: center; font-size: .78rem; }
.standalone-context { margin: -1rem 0 1.5rem; padding: 1rem; border: 1px solid var(--line); background: rgba(255,255,255,.7); border-radius: 13px; }

.workspace-grid { display: grid; grid-template-columns: minmax(340px, .82fr) minmax(460px, 1.3fr); gap: 1.5rem; align-items: start; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); overflow: hidden; }
.panel-heading { display: flex; justify-content: space-between; align-items: center; min-height: 88px; padding: 1.35rem 1.5rem; border-bottom: 1px solid var(--line); }
.panel-heading h2 { margin: 0; }
.stack-form { display: grid; gap: 1.15rem; padding: 1.5rem; }
label { display: grid; gap: .42rem; color: #34433c; font-size: .78rem; font-weight: 700; }
label small { font-weight: 450; font-size: .7rem; }
input, select, textarea { width: 100%; padding: .72rem .8rem; color: var(--ink); border: 1px solid #ccd6d0; border-radius: 9px; background: white; outline: none; transition: border .15s, box-shadow .15s; }
textarea { resize: vertical; line-height: 1.55; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(21,95,73,.1); }

.segmented { display: grid; grid-template-columns: 1fr 1fr; padding: 3px; border-radius: 10px; background: #edf1ee; }
.segmented button { padding: .58rem; border: 0; border-radius: 8px; color: var(--muted); background: transparent; font-size: .78rem; font-weight: 750; }
.segmented button.active { color: var(--ink); background: white; box-shadow: 0 2px 8px rgba(24,46,37,.09); }
.file-drop { min-height: 240px; display: flex; flex-direction: column; justify-content: center; align-items: center; padding: 1.5rem; text-align: center; border: 1.5px dashed #aebdb5; border-radius: 13px; background: #fafcf9; transition: .18s; cursor: pointer; }
.file-drop:hover, .file-drop.dragging { border-color: var(--brand); background: var(--brand-soft); transform: translateY(-1px); }
.file-drop input { display: none; }
.file-drop small { max-width: 350px; margin: .35rem 0 1rem; }
.upload-icon { display: grid; place-items: center; width: 48px; height: 48px; margin-bottom: .9rem; border-radius: 15px; color: var(--brand); background: var(--brand-soft); font-size: 1.55rem; }
.browse-button { padding: .58rem .85rem; color: var(--brand); background: white; border: 1px solid #bad3c5; border-radius: 8px; }
.selected-file { display: flex; align-items: center; gap: .8rem; min-height: 72px; padding: .8rem; border: 1px solid var(--line); border-radius: 12px; }
.selected-file > span:nth-child(2) { display: flex; flex: 1; min-width: 0; flex-direction: column; }
.selected-file strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip { display: grid; place-items: center; width: 43px; height: 43px; border-radius: 10px; color: var(--brand); background: var(--brand-soft); font-size: .65rem; font-weight: 850; }

.primary-button, .secondary-button, .text-button, .icon-button { display: inline-flex; justify-content: center; align-items: center; gap: .45rem; border: 0; border-radius: 9px; font-weight: 750; transition: .15s; }
.primary-button { padding: .72rem 1rem; color: white; background: var(--brand); box-shadow: 0 8px 20px rgba(21,95,73,.18); }
.primary-button:hover { background: var(--brand-dark); transform: translateY(-1px); }
.primary-button:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.primary-button.loading::before { content: ""; width: 12px; height: 12px; border: 2px solid rgba(255,255,255,.45); border-top-color: white; border-radius: 50%; animation: spin .8s linear infinite; }
.large-action { min-height: 48px; justify-content: space-between; padding-left: 1.1rem; }
.schema-editor { margin-top: 1rem; padding: 1rem; border: 1px solid var(--line); border-radius: 12px; background: #fafcfb; min-width: 0; }
.schema-editor > summary { cursor: pointer; font-size: .88rem; font-weight: 750; }
.schema-editor > summary .muted { font-size: .7rem; font-weight: 450; }
.schema-intro { margin: .75rem 0; color: var(--muted); font-size: .76rem; line-height: 1.5; }
.schema-preset-row { display: flex; align-items: end; flex-wrap: wrap; gap: .5rem; }
.schema-preset-row label { flex: 1; min-width: 170px; }
.schema-preset-row select { min-width: 0; }
.schema-tools { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin: .5rem 0; }
.schema-import-label { color: var(--brand); font-size: .72rem; cursor: pointer; }
.schema-import-label input { width: 160px; padding: .3rem; font-size: .65rem; }
.schema-editor #schemaStatus { font-size: .72rem; overflow-wrap: anywhere; }
.schema-error { padding: .65rem; border: 1px solid #e8b8ae; border-radius: 8px; background: #fff0ed; color: #922c22; font-size: .76rem; overflow-wrap: anywhere; }
.schema-fields { border: 0; padding: 0; margin: .75rem 0; min-width: 0; max-height: 540px; overflow: auto; scrollbar-gutter: stable; }
.schema-fields:disabled { opacity: .6; }
.schema-field { border: 1px solid var(--line); border-radius: 9px; background: white; margin-bottom: .5rem; }
.schema-field > summary { cursor: pointer; padding: .7rem; font-size: .78rem; overflow-wrap: anywhere; }
.schema-field-kind { display: block; padding-left: 1rem; color: var(--muted); font-size: .67rem; }
.schema-field-body { display: grid; gap: .7rem; padding: .8rem; border-top: 1px solid var(--line); }
.schema-field-body input, .schema-field-body select, .schema-field-body textarea { min-width: 0; }
.schema-field-actions { display: flex; flex-wrap: wrap; gap: .35rem; font-size: .7rem; }
.schema-advanced > summary { font-size: .74rem; color: var(--muted); cursor: pointer; }
.schema-advanced label { margin-top: .5rem; }
.schema-json-label { margin-top: 1rem; }
.schema-json-label textarea, .schema-advanced textarea { font: .72rem/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; tab-size: 2; }
.schema-editor button:disabled { opacity: .5; cursor: not-allowed; }
.schema-json-label textarea[readonly] { background: #edf1ee; }
.secondary-button { padding: .67rem .9rem; color: var(--brand); background: white; border: 1px solid #bfd0c7; }
.secondary-button:hover { background: var(--brand-soft); }
.text-button { padding: .35rem; color: var(--brand); background: transparent; }
.icon-button { width: 36px; height: 36px; padding: 0; color: var(--muted); background: transparent; font-size: 1.15rem; }
.icon-button:hover { color: var(--ink); background: #edf1ee; }
.icon-button.compact { width: 28px; height: 28px; }
.link-button { width: max-content; }

.result-panel { min-height: 620px; }
.empty-state { min-height: 500px; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 2rem; color: var(--muted); text-align: center; }
.empty-state p { max-width: 390px; margin: .45rem 0 0; font-size: .82rem; }
.empty-state.compact { min-height: 180px; }
.empty-illustration { display: grid; place-items: center; width: 68px; height: 68px; margin-bottom: 1.1rem; border: 1px solid var(--line); border-radius: 22px; background: linear-gradient(145deg, white, var(--brand-soft)); color: var(--brand); font-size: 2rem; }
.progress-panel { min-height: 500px; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 2rem; text-align: center; }
.progress-panel p { color: var(--muted); }
.progress-panel.failed .spinner { border-color: #f1beb9; border-top-color: var(--danger); animation: none; }
.spinner { width: 46px; height: 46px; margin-bottom: 1.2rem; border: 4px solid #d9e9e0; border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; }
.progress-track { width: min(280px, 80%); height: 5px; margin-top: .5rem; overflow: hidden; background: #e6ebe8; border-radius: 99px; }
.progress-track i { display: block; width: 35%; height: 100%; border-radius: inherit; background: var(--brand); animation: progress 1.8s ease-in-out infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes progress { 0% { transform: translateX(-120%); } 100% { transform: translateX(400%); } }
.result-summary, .model-summary { display: grid; grid-template-columns: repeat(3, 1fr); border-bottom: 1px solid var(--line); background: #fbfcfb; }
.result-summary > div, .model-summary > div { display: flex; flex-direction: column; padding: 1rem 1.5rem; border-right: 1px solid var(--line); }
.result-summary strong, .model-summary strong { font-size: 1.25rem; }
.result-summary span, .model-summary span { color: var(--muted); font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; }
.review-heading { display: flex; justify-content: space-between; gap: 1rem; padding: 1.4rem 1.5rem .9rem; }
.review-heading p { margin: 0; color: var(--muted); font-size: .75rem; }
.review-list { display: grid; gap: .55rem; padding: 0 1.5rem 1.2rem; }
.review-row { display: grid; grid-template-columns: 22px minmax(110px,.7fr) minmax(160px,1.4fr) auto 70px 28px; align-items: center; gap: .55rem; padding: .55rem; border: 1px solid var(--line); border-radius: 10px; }
.review-row.missing { background: #fafbfa; border-style: dashed; }
.review-row input, .review-row select { min-width: 0; padding: .56rem .6rem; border: 0; background: transparent; }
.review-row .review-value { font-weight: 650; }
.review-row .review-occurrence { grid-column: 2 / -2; font-size: .72rem; }
.review-row .review-source { width: 100%; border: 1px solid var(--line); font-size: .7rem; }
.review-row .confidence { color: var(--brand); font-size: .68rem; font-weight: 750; text-align: right; }
.absent-label { display: flex; align-items: center; gap: .25rem; white-space: nowrap; color: var(--muted); font-size: .68rem; }
.absent-label input { width: auto; }
.review-include { accent-color: var(--brand); }
.review-actions { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: 1rem 1.5rem; border-top: 1px solid var(--line); }
.check-label { display: flex; align-items: center; grid-auto-flow: column; }
.check-label input { width: auto; accent-color: var(--brand); }
.json-details { margin: 0 1.5rem 1.5rem; border: 1px solid var(--line); border-radius: 10px; }
.json-details summary { padding: .75rem; color: var(--muted); font-size: .75rem; cursor: pointer; }
.json-details pre { max-height: 350px; margin: 0; padding: 1rem; overflow: auto; border-top: 1px solid var(--line); background: #f7f9f7; font: .72rem/1.55 ui-monospace, SFMono-Regular, Menlo, monospace; }

.admin-shell { width: min(1440px, calc(100% - 2rem)); }
.admin-layout { display: grid; grid-template-columns: 230px minmax(0,1fr); gap: 1.5rem; align-items: start; }
.side-tabs { display: grid; gap: .35rem; position: sticky; top: 95px; }
.side-tabs button { display: grid; grid-template-columns: 34px 1fr; align-items: center; gap: .7rem; padding: .75rem; text-align: left; color: var(--muted); border: 0; border-radius: 10px; background: transparent; }
.side-tabs button > span { font: .65rem ui-monospace, monospace; }
.side-tabs button div { display: flex; flex-direction: column; }
.side-tabs button small { font-size: .67rem; }
.side-tabs button:hover, .side-tabs button.active { color: var(--brand); background: white; box-shadow: 0 7px 22px rgba(27,48,39,.06); }
.admin-content { min-width: 0; }
.admin-section { display: none; min-height: 600px; padding: 1.6rem; background: white; border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); }
.admin-section.active { display: block; }
.section-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 1.5rem; padding-bottom: 1.25rem; border-bottom: 1px solid var(--line); }
.section-heading p:last-child { margin-bottom: 0; color: var(--muted); font-size: .8rem; max-width: 700px; }
.section-subheading { display: flex; justify-content: space-between; align-items: center; margin-top: 1.8rem; }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; padding-top: 1.25rem; }
.setting-card { padding: 1.2rem; border: 1px solid var(--line); border-radius: 13px; background: #fbfcfb; }
.setting-card.wide { grid-column: 1 / -1; }
.setting-card > p, .setting-title p { color: var(--muted); font-size: .76rem; }
.setting-title { display: flex; justify-content: space-between; gap: 1rem; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 1rem; }
.compact-form-row { grid-template-columns: 1fr 1fr 1fr; margin-top: 0; }
.form-row.disabled { opacity: .42; pointer-events: none; }
.button-row, .filter-row { display: flex; align-items: end; flex-wrap: wrap; gap: .65rem; margin-top: 1rem; }
.filter-row label { min-width: 210px; }
.switch { display: block; }
.switch input { display: none; }
.switch i { display: block; width: 43px; height: 24px; padding: 3px; border-radius: 20px; background: #cbd4cf; transition: .2s; }
.switch i::before { content: ""; display: block; width: 18px; height: 18px; border-radius: 50%; background: white; box-shadow: 0 1px 4px rgba(0,0,0,.18); transition: .2s; }
.switch input:checked + i { background: var(--brand); }
.switch input:checked + i::before { transform: translateX(19px); }
.mini-stats { margin: .8rem 0 0; }
.mini-stats div { display: flex; justify-content: space-between; padding: .5rem 0; border-top: 1px solid var(--line); }
.mini-stats dt { color: var(--muted); font-size: .72rem; }
.mini-stats dd { margin: 0; font-size: .75rem; font-weight: 750; }
.inline-success { color: var(--brand); font-size: .75rem; }
.inline-warning { color: var(--warning); font-size: .75rem; }
.inline-error { color: var(--danger); font-size: .75rem; }

.schema-grid { display: grid; grid-template-columns: minmax(220px,.7fr) minmax(360px,1.3fr); gap: 1rem; margin-top: 1.25rem; }
.item-list { display: grid; align-content: start; gap: .45rem; max-height: 680px; overflow: auto; }
.list-item { display: grid; grid-template-columns: 38px 1fr 15px; align-items: center; gap: .65rem; padding: .72rem; text-align: left; border: 1px solid var(--line); border-radius: 10px; background: white; }
.list-item:hover, .list-item.active { border-color: #aac8b8; background: var(--brand-soft); }
.list-item > span:nth-child(2) { display: flex; flex-direction: column; min-width: 0; }
.list-item small { overflow: hidden; text-overflow: ellipsis; }
.type-icon { display: grid; place-items: center; width: 36px; height: 36px; color: var(--brand); background: #edf6f1; border-radius: 10px; font-weight: 800; }
.schema-detail { min-height: 400px; padding: 1rem; border: 1px solid var(--line); border-radius: 12px; background: #fafbfa; }
.detail-heading { display: flex; justify-content: space-between; align-items: center; padding-bottom: .8rem; }
.detail-heading code, .field-card code { color: var(--muted); font-size: .68rem; }
.field-list { display: grid; gap: .55rem; }
.field-card { display: grid; grid-template-columns: 1fr auto; align-items: start; padding: .85rem; border: 1px solid var(--line); border-radius: 10px; background: white; }
.field-card > div { display: flex; flex-direction: column; }
.field-card p { grid-column: 1 / -1; margin: .45rem 0 0; color: var(--muted); font-size: .7rem; }
.field-card .field-edit { justify-self: end; }
.danger-text { color: var(--danger); }
.value-badge { padding: .25rem .45rem; color: var(--brand); background: var(--brand-soft); border-radius: 6px; font-size: .65rem; font-weight: 750; }

.table-wrap { margin-top: 1rem; overflow: auto; border: 1px solid var(--line); border-radius: 11px; }
table { width: 100%; border-collapse: collapse; font-size: .75rem; }
th { padding: .7rem .85rem; text-align: left; color: var(--muted); background: #f7f9f7; font-size: .65rem; text-transform: uppercase; letter-spacing: .07em; }
td { padding: .75rem .85rem; border-top: 1px solid var(--line); vertical-align: middle; }
td:first-child strong, td:first-child small { display: block; }
.training-launcher { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; padding: 1.25rem; margin-top: 1.25rem; border: 1px solid var(--line); border-radius: 13px; background: #fbfcfb; }
.training-callout { grid-column: 1 / -1; padding: .9rem; color: #6f521e; background: #fff5df; border-radius: 9px; }
.training-callout p { margin: .25rem 0 0; font-size: .72rem; }
.training-launcher button { width: max-content; }
.job-list { display: grid; gap: .55rem; }
.job-card { display: grid; grid-template-columns: 10px 1fr auto auto; align-items: center; gap: .75rem; padding: .75rem; border: 1px solid var(--line); border-radius: 10px; }
.job-card p { margin: .15rem 0 0; color: var(--muted); font-size: .68rem; }
.job-card time { color: var(--muted); font-size: .68rem; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--brand); }
.model-summary { margin-top: 1.25rem; border: 1px solid var(--line); border-radius: 11px; overflow: hidden; }

dialog { width: min(520px, calc(100% - 2rem)); padding: 0; border: 0; border-radius: 16px; box-shadow: 0 30px 100px rgba(12,33,24,.3); }
dialog::backdrop { background: rgba(15,28,22,.5); backdrop-filter: blur(3px); }
.dialog-form { display: grid; gap: 1rem; padding: 1.4rem; }
.dialog-heading { display: flex; justify-content: space-between; }
.dialog-actions { display: flex; justify-content: flex-end; gap: .6rem; margin-top: .4rem; }
.form-error { padding: .65rem; margin: 0; color: var(--danger); background: #fcecea; border-radius: 8px; font-size: .75rem; }
.login-page { display: grid; place-items: center; padding: 1rem; }
.login-card { width: min(430px, 100%); padding: 2.2rem; background: white; border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow); }
.login-card > p.muted { margin-bottom: 1.5rem; line-height: 1.55; }
.login-card .stack-form { padding: 0; }
.toast { position: fixed; right: 1.2rem; bottom: 1.2rem; z-index: 100; max-width: min(420px, calc(100% - 2.4rem)); padding: .85rem 1rem; color: white; background: var(--brand-dark); border-radius: 10px; box-shadow: 0 12px 35px rgba(0,0,0,.2); font-size: .78rem; }
.toast.error { background: #8c2b28; }

@media (max-width: 900px) {
  .workspace-grid, .admin-layout, .schema-grid { grid-template-columns: 1fr; }
  .side-tabs { position: static; grid-template-columns: repeat(5, minmax(100px,1fr)); overflow: auto; }
  .side-tabs button { grid-template-columns: 1fr; }
  .side-tabs button > span, .side-tabs small { display: none; }
  .settings-grid { grid-template-columns: 1fr; }
  .setting-card.wide { grid-column: auto; }
  .result-panel { min-height: auto; }
  .empty-state, .progress-panel { min-height: 380px; }
}

@media (max-width: 650px) {
  .topbar { height: 64px; padding: 0 .8rem; gap: .5rem; }
  .topbar .brand small { display: none; }
  .topbar nav a { padding: 0 .55rem; font-size: .76rem; }
  .page-shell { width: min(100% - 1rem, 1500px); padding-top: 1.5rem; }
  .page-heading { flex-direction: column; gap: 1rem; }
  .workflow-steps li { padding: .7rem .45rem; }
  .workflow-steps li div small { display: none; }
  .review-row { grid-template-columns: 20px 1fr 28px; }
  .review-row .review-value { grid-column: 2 / 3; }
  .review-row .absent-label { grid-column: 2 / 3; }
  .review-row .confidence { grid-column: 2; text-align: left; }
  .review-row .icon-button { grid-column: 3; grid-row: 1; }
  .form-row, .training-launcher { grid-template-columns: 1fr; }
  .training-callout { grid-column: auto; }
  .result-summary > div, .model-summary > div { padding: .8rem; }
}
[hidden] { display: none !important; }
.native-profile { font-weight: 700; }
.native-table-scroll { overflow-x: auto; margin: 12px 0 20px; }
.native-table { width: 100%; border-collapse: collapse; text-align: left; font-size: .9rem; }
.native-table th, .native-table td { padding: 10px; border-bottom: 1px solid #dce2e9; vertical-align: top; overflow-wrap: anywhere; }
.native-table th { font-size: .8rem; color: #526173; }
.native-source summary { cursor: pointer; white-space: pre-wrap; }
.native-source p { color: #526173; font-size: .8rem; }
.native-record { border: 1px solid #dce2e9; border-radius: 10px; padding: 12px; margin: 12px 0; }
.native-record h4 { margin: 0; }
.native-warning { border: 1px solid #d7a63a; background: #fff8e4; border-radius: 10px; padding: 14px; margin: 16px 0; }
.native-observations, .native-warning details { margin: 12px 0; }
#glinerResult pre { overflow: auto; max-height: 420px; white-space: pre-wrap; font-size: .8rem; }
#glinerResult h3 { margin-top: 24px; }
#glinerOptions small { display: block; margin-top: 6px; }
/* Reviewed native datasets retain source IDs and structured task scopes. */
.native-training-form { display: grid; gap: 16px; margin: 20px 0; }
.native-training-form textarea { font-family: ui-monospace, monospace; font-size: 12px; }
.native-training-preview, .native-job-card { padding: 18px; border: 1px solid var(--border, #dfe3e8); border-radius: 12px; background: #fff; }
.native-training-preview pre, .native-job-card pre { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 420px; overflow: auto; font-size: 12px; }
.native-training-preview details { margin: 10px 0; }
.review-confirmation { display: flex; align-items: flex-start; gap: 12px; }
.review-confirmation input { width: auto; margin-top: 4px; }

.queue-panel { margin-top: 24px; padding: 24px; }
.queue-tools { display: flex; gap: 16px; align-items: end; flex-wrap: wrap; }
.queue-tools label { display: grid; gap: 6px; }
.queue-scroll { overflow: auto; max-height: 480px; }
#queueHeading { scroll-margin-top: 96px; }
.queue-table { width: 100%; border-collapse: collapse; text-align: left; }
.queue-table th, .queue-table td { padding: 12px 8px; border-bottom: 1px solid #dce3ed; vertical-align: top; }
.queue-table small { display: block; margin-top: 5px; overflow-wrap: anywhere; }
.queue-table strong { overflow-wrap: anywhere; }
.queue-actions { min-width: 250px; }
.queue-actions > * { display: inline-block; margin: 3px; font-size: 12px; }

.adjustment-strength { min-width: 0; border: 1px solid var(--border, #d5dce3); border-radius: 8px; padding: 16px; margin: 12px 0; }
.adjustment-strength input[type="range"] { width: 100%; cursor: pointer; }
.adjustment-labels { display: flex; justify-content: space-between; gap: 8px; font-size: .85rem; }
.adjustment-labels span { cursor: help; }
.adjustment-labels span:focus { outline: 2px solid currentColor; outline-offset: 3px; }
.adjustment-strength p { margin: 10px 0; }

.field-labeling { margin-top:24px; border-top:1px solid #cad5e2; padding-top:16px; }
.label-toolbar { display:flex;flex-wrap:wrap;gap:8px;align-items:center; }
.label-toolbar select { width:auto;flex:1 1 180px;max-width:320px; }
.label-viewport { max-height:520px;overflow:auto;background:#edf2f7;border:1px solid #c9d5e3;border-radius:8px;margin:12px 0; }
.label-page { position:relative;background:white;touch-action:none;user-select:none; }
/* State highlights must not take space from small OCR word boxes. */
.label-word { position:absolute;display:flex;align-items:center;justify-content:flex-start;padding:0;border:0;background:transparent;color:#15263e;line-height:normal;white-space:nowrap;overflow:hidden;text-align:left;border-radius:2px; }
.label-word:hover,.label-word:focus-visible { outline:2px solid #225ace;z-index:2; }
.label-word.labeled { background:#dceee4;box-shadow:inset 0 -2px #258158; }
.label-word.selected { background:#b4d5ff;box-shadow:inset 0 0 0 1px #225ace; }
.label-occurrences { max-height:260px;overflow:auto; }
.label-occurrence { display:flex;gap:8px;margin:6px 0; }
.label-occurrence > :first-child { flex:1;text-align:left;white-space:normal; }
.field-labeling > button,.field-labeling > select { margin:8px 8px 8px 0; }

/* Compact workspace: bounded regions, no page-wide annotation overflow. */
[hidden] { display:none !important; }
.page-shell { max-width:1560px; padding:1rem 1.5rem 2rem; }
.page-heading { margin-bottom:1rem; }
.page-heading h1 { font-size:1.55rem; }
.workflow-steps { display:none; }
.workspace-grid { grid-template-columns:minmax(300px,.7fr) minmax(0,1.3fr); gap:1rem; }
.workspace-grid > *, .admin-layout > *, .workspace-region, .stack-form, #resultContent { min-width:0; }
.panel { padding:1rem; }
.panel-heading { margin-bottom:.8rem; }
.workspace-tabs { display:flex;gap:.25rem;border-bottom:1px solid var(--line);margin:0 0 1rem; }
.workspace-tabs button { flex:1;min-width:0;padding:.6rem .5rem;border:0;border-bottom:2px solid transparent;background:transparent;color:var(--muted);font:inherit;cursor:pointer; }
.workspace-tabs button[aria-selected="true"] { color:var(--primary,#225ace);border-color:currentColor;font-weight:650; }
.workspace-tabs button:focus-visible, summary:focus-visible { outline:2px solid #225ace;outline-offset:2px; }
.workspace-region > * { max-width:100%; }
.stack-form { gap:.8rem; }
.stack-form label, .form-row > label { min-width:0; }
.schema-fields { max-height:45vh; }
.schema-json-disclosure { margin-top:.75rem; }
.schema-json-disclosure textarea { min-height:160px; }
.schema-preset-row { flex-wrap:wrap; }
.result-summary { padding:.65rem;gap:1rem;margin-bottom:.6rem; }
.queue-disclosure { margin-top:1rem;border:1px solid var(--line);border-radius:10px;background:#fff; }
.queue-disclosure > summary { padding:.85rem 1rem;cursor:pointer;font-weight:600; }
.queue-panel { margin:0;border:0; }
.label-toolbar { display:flex;flex-wrap:wrap;gap:.4rem; }
.label-toolbar select { min-width:0;max-width:100%;flex:1 1 140px; }
.label-toolbar button { flex:0 1 auto; }
.label-viewport { max-width:100%;max-height:55vh;overflow:auto;contain:inline-size; }
.label-page { position:relative;flex-shrink:0; }
.label-word { min-height:0 !important;min-width:0 !important;padding:0 !important;letter-spacing:normal; }
.label-occurrences { max-height:180px;overflow:auto; }
.label-occurrence { min-width:0; }
.label-occurrence button:first-child { min-width:0;white-space:normal;overflow-wrap:anywhere;text-align:left; }
.label-save-actions { display:flex;align-items:center;flex-wrap:wrap;gap:.8rem;margin:.8rem 0; }
.label-save-actions .check-label { flex:1; }
.help-tip { cursor:help;display:inline-block;font-size:.8rem;margin:.25rem; }
.sample-source { display:flex;align-items:center;flex-wrap:wrap;gap:.75rem;margin:.6rem 0; }
.sample-source span { color:var(--muted);font-size:.8rem; }
.training-advanced, .training-import { margin:.6rem 0; }
.training-advanced .form-row { grid-template-columns:repeat(auto-fit,minmax(170px,1fr)); }
.admin-layout { grid-template-columns:180px minmax(0,1fr);gap:1rem; }
.admin-section .section-heading p, .adjustment-strength > p { font-size:.8rem; }
.form-row { flex-wrap:wrap; }
.native-job-card { overflow-wrap:anywhere; }
pre { max-width:100%;overflow:auto; }
@media(max-width:900px){
  .workspace-grid,.admin-layout { grid-template-columns:minmax(0,1fr); }
  .page-shell { padding:.75rem; }
  .topbar { gap:.5rem;flex-wrap:wrap; }
  .topbar nav { flex-wrap:wrap;gap:.5rem; }
  .label-viewport { max-height:50vh; }
}

/* Keep navigation in normal flow: wrapped links must not cover page content. */
.topbar { position:relative; height:auto; min-height:64px; }
.topbar nav a { min-height:48px; }
.panel-heading { min-height:60px; padding:.65rem .5rem; margin-bottom:.5rem; }
.panel-heading .eyebrow { display:none; }
.file-drop { min-height:175px; padding:1rem; }
.file-drop small { margin:.25rem 0 .6rem; }
@media(max-width:900px){
  .side-tabs { display:flex; position:static; overflow-x:auto; gap:.25rem; }
  .side-tabs button { display:block; flex:0 0 auto; padding:.6rem; }
  .side-tabs button > span, .side-tabs small { display:none; }
  .topbar { padding:.4rem .8rem; }
}

.panel-heading .step-label { display:none; }

/* Word-region selection is visible at every zoom and cannot intercept clicks. */
.label-page { touch-action: none; user-select: none; }
.label-selection-rectangle { position: absolute; z-index: 10; pointer-events: none; border: 1px solid #2563eb; background: rgb(37 99 235 / 14%); }
.label-word.selecting { background: #dbeafe; outline: 1px solid #2563eb; }
.topbar nav { display: flex; flex-wrap: wrap; gap: .25rem; }
@media (max-width: 760px) { .topbar { flex-wrap: wrap; } .topbar nav { order: 3; flex-basis: 100%; } .topbar nav a { padding: .45rem .65rem; } }

.label-toolbar select.label-grouping { flex: 2 1 260px; }

/* Searchable native select enhancement, including dynamically added fields. */
.search-select { position: relative; width: 100%; min-width: 0; }
.search-select-native { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; clip-path: inset(50%); overflow: hidden; opacity: 0; }
.search-select-trigger { display: block; position: relative; width: 100%; min-width: 0; padding: .65rem 2rem .65rem .75rem; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; background: #fff; border: 1px solid var(--line); border-radius: 8px; color: inherit; font: inherit; }
.search-select-trigger::after { content: '⌄'; position: absolute; right: .7rem; top: .55rem; }
.search-select-trigger:focus-visible, .search-select-trigger[aria-expanded=true] { outline: 2px solid var(--accent, #2a8062); outline-offset: 2px; }
.search-select-trigger[aria-invalid=true] { border-color: #bb3838; }
.search-select-popup { position: fixed; inset: auto; margin: 0; padding: .5rem; display: flex; flex-direction: column; gap: .35rem; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 30px #152c2433; background: #fff; color: var(--text, #25352f); z-index: 1000; }
.search-select-popup input { flex-shrink: 0; width: 100%; margin: 0; }
.search-select-options { overflow-y: auto; overscroll-behavior: contain; min-height: 0; }
.search-select-options [role=option] { padding: .55rem .65rem; border-radius: 5px; cursor: pointer; overflow-wrap: anywhere; }
.search-select-options [aria-selected=true] { font-weight: 650; background: #eaf5ee; }
.search-select-options .highlighted, .search-select-options [role=option]:hover { background: #e2efe9; }
.search-select-options [aria-disabled=true] { opacity: .45; cursor: default; }
.search-select-popup small:empty { display: none; }
.value-list { display: grid; gap: .35rem; min-width: 0; }
.value-list > strong { font-size: .82rem; font-weight: 600; }
.value-list-rows { display: grid; gap: .3rem; max-height: 180px; overflow-y: auto; }
.value-list-row { display: flex; gap: .3rem; align-items: center; }
.value-list-row input, .value-list-row textarea { flex: 1; min-width: 0; }
.value-list > .text-button { justify-self: start; padding: .25rem 0; }
.rule-editor { display: grid; gap: .6rem; min-width: 0; }
.rule-list { display: grid; gap: .6rem; }
.rule-card { min-width: 0; padding: .65rem; border: 1px solid var(--line); border-radius: 9px; background: #fafcfb; }
.rule-heading { display: flex; align-items: center; justify-content: space-between; gap: .3rem; margin-bottom: .35rem; }
.rule-heading strong { font-size: .85rem; }
.rule-controls { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: .5rem; }
.rule-controls label { min-width: 0; }
.rule-controls label > span { font-size: .76rem; }
.rule-values { grid-column: 1 / -1; }
.rule-add { display: flex; align-items: end; gap: .5rem; }
.rule-add > label { flex: 1; min-width: 0; }
.rule-add > button { flex-shrink: 0; }
#entityDialog { max-height: calc(100dvh - 2rem); }
#entityDialog.field-dialog { width: min(1100px, calc(100% - 2rem)); }
#entityDialog .dialog-form { padding: 0; gap: 0; max-height: calc(100dvh - 2rem); }
#entityDialog .dialog-heading { padding: 1rem 1.25rem; border-bottom: 1px solid var(--line); }
#entityDialog .dialog-heading h2 { margin: 0; font-size: 1.3rem; }
#entityDialog .entity-columns { padding: 1rem 1.25rem; overflow-y: auto; min-height: 0; }
#entityDialog.field-dialog .entity-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
.entity-basics { display: grid; align-content: start; gap: .75rem; min-width: 0; }
.entity-rule-region { display: grid; align-content: start; gap: .6rem; min-width: 0; }
.entity-rule-region h3 { margin: 0; font-size: 1rem; }
#entityDialog .dialog-actions { margin: 0; padding: .8rem 1.25rem; border-top: 1px solid var(--line); background: #fff; }
#entityDialog .form-error { margin: .5rem 1.25rem; }
#entityDialog .form-row { margin: 0; }
.help-tip { cursor: help; font-weight: normal; color: var(--muted); font-size: .85rem; }
.merge-settings { margin-top: .5rem; }
.merge-settings summary { cursor: pointer; font-size: .85rem; margin-bottom: .5rem; }
.library-json { margin: 1rem 0; }
#ruleSettings { max-width: 950px; margin: 1rem 0; }
@media (max-width: 700px) {
  #entityDialog.field-dialog .entity-columns { grid-template-columns: 1fr; gap: 1rem; }
  #entityDialog .entity-columns { padding: .85rem; }
  .rule-controls { grid-template-columns: 1fr; }
  .rule-add { flex-wrap: wrap; }
  .rule-add > label { flex-basis: 100%; }
}

/* Debug evidence is loaded explicitly and stays within the result pane. */
#traceContent { min-width: 0; }
#traceContent pre { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 26rem; overflow: auto; font-size: .78rem; }
#traceContent summary { padding-block: .5rem; }
.debug-table { overflow-x: auto; margin-block: .75rem; }
.debug-table table { width: 100%; border-collapse: collapse; font-size: .82rem; }
.debug-table th,.debug-table td { padding: .5rem; border-bottom: 1px solid var(--border, #dce2e9); text-align: left; vertical-align: top; overflow-wrap: anywhere; }
.debug-table td:first-child { min-width: 9rem; }
.debug-removal { border-left: 3px solid #b7791f; padding: .5rem .75rem; margin-block: .5rem; }
.debug-table table { min-width: 34rem; }
.debug-table th:nth-child(2),.debug-table td:nth-child(2) { white-space: nowrap; overflow-wrap: normal; }
