:root {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  color: #1c2823;
  background: #f3f6f4;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { overflow-y: scroll; scrollbar-gutter: stable; }
body { margin: 0; min-width: 1120px; }
button, input, textarea, select { font: inherit; font-size: 12px; font-weight: 450; }
button, .button-link {
  min-height: 32px;
  border: 1px solid #c8d2cd;
  border-radius: 7px;
  background: #fff;
  color: #26332d;
  padding: 5px 10px;
  cursor: pointer;
  text-decoration: none;
}
button:disabled, a.disabled { cursor: default; opacity: .45; }
.primary { background: #176b4d; border-color: #176b4d; color: #fff; font-weight: 650; }
.secondary { background: #f7f9f8; }
.hidden { display: none !important; }

.app-header {
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 18px;
  color: #fff;
  background: #17372c;
}
.brand { display: flex; align-items: center; gap: 9px; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 8px; background: #2c785d; font-weight: 800; }
h1 { margin: 0; font-size: 17px; }
.brand p { margin: 1px 0 0; color: #bed1c9; font-size: 10px; }
.header-meta { display: flex; align-items: center; gap: 8px; }
.runtime { padding: 5px 9px; border: 1px solid #49695e; border-radius: 999px; font-size: 10px; color: #dce8e3; }
.user-button { border-color: #638176; background: #244a3d; color: #fff; }
main { padding: 14px 16px 28px; }

.panel { max-width: 980px; margin: 24px auto 0; padding: 18px; background: #fff; border: 1px solid #d8e0dc; border-radius: 12px; box-shadow: 0 7px 24px rgb(25 55 44 / 7%); }
.section-heading h2, .registry-toolbar h2 { margin: 0; font-size: 18px; }
.section-heading p, .registry-toolbar p { margin: 3px 0 14px; color: #66746e; font-size: 11px; }
.row-heading { display: flex; justify-content: space-between; align-items: start; }
.login-panel { max-width: 550px; }
.login-form { display: grid; grid-template-columns: 1fr 180px auto; align-items: end; gap: 9px; }
.login-form label span, .context-grid label > span, .model-field > span { display: block; margin-bottom: 4px; color: #526159; font-size: 10px; }
.login-form input, .context-grid input, .model-field select, #text-mode textarea, .app-dialog textarea { width: 100%; border: 1px solid #c9d3ce; border-radius: 7px; padding: 7px 9px; font-size: 12px; }
.alert { margin: 8px 0; padding: 8px 10px; border-radius: 7px; font-size: 11px; }
.error { color: #8b2520; background: #fff0ef; border: 1px solid #efc4c1; }
.warning { color: #765b15; background: #fff9e8; border: 1px solid #ead9a1; }

.registry { position: relative; width: min(100%, 1400px); margin: 0 auto; padding: 0; }
.registry-toolbar { min-height: 64px; display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.registry-toolbar p { margin-bottom: 0; }
.registry-actions { display: flex; gap: 6px; align-items: center; }
.registry-actions select, .registry-actions button { height: 32px; min-height: 32px; border: 1px solid #c8d2cd; border-radius: 5px; padding: 0 10px; font-size: 11px; font-weight: 550; }
.registry-actions select { background: #fff; }
.registry-actions .primary { padding-inline: 12px; }
.registry-table-shell { width: 100%; overflow: hidden; border: 1px solid #d3ddd8; border-radius: 4px; background: #fff; box-shadow: 0 3px 12px rgb(25 55 44 / 5%); }
.job-status { display: inline-flex; align-items: center; justify-content: center; padding: 4px 8px; border-radius: 999px; font-size: 10px; font-weight: 700; white-space: nowrap; }
.job-status.queued { color: #695b26; background: #f5efd9; }
.job-status.processing { color: #285a76; background: #e3f0f8; }
.job-status.ready { color: #176b4d; background: #e0f3e8; }
.job-status.failed, .job-status.cancelled { color: #8f2d27; background: #f6dfdd; }
.registry-client + small, .confidence-value + small { display: block; margin-top: 2px; overflow: hidden; color: #728078; font-size: 9px; text-overflow: ellipsis; white-space: nowrap; }
.registry-client { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 10px; }
.confidence-value { display: block; color: #31433b; font-size: 13px; }
.verified-label { display: inline-flex; align-items: center; padding: 3px 6px; border-radius: 999px; color: #176b4d; background: #e0f3e8; font-size: 9px; font-weight: 700; white-space: nowrap; }
.live-timer { font-variant-numeric: tabular-nums; font-weight: 700; color: #405149; }
.research-cell { display: grid; gap: 2px; align-content: center; height: 100%; }
.research-meta { display: flex; align-items: center; justify-content: space-between; gap: 7px; padding-top: 2px; border-top: 1px solid #e0e6e3; color: #68766f; font-size: 8px; }
.research-meta .live-timer { font-size: 9px; }
.row-actions, .line-actions, .document-actions { display: flex; align-items: center; justify-content: center; gap: 4px; }
.row-actions button, .line-reparse, .document-actions button, .document-actions a {
  display: grid;
  place-items: center;
  width: 27px;
  height: 27px;
  min-height: 27px;
  padding: 0;
  border: 1px solid #c2cec8;
  border-radius: 6px;
  color: #486058;
  background: #fff;
}
.row-actions button:hover, .line-reparse:hover, .document-actions button:hover, .document-actions a:hover { border-color: #7eaa97; color: #176b4d; background: #f0f8f4; }
.row-actions .continue-action { border-color: #176b4d; color: #fff; background: #176b4d; }
.row-actions .continue-action:hover { border-color: #0f553d; color: #fff; background: #0f553d; }
.row-actions svg, .line-reparse svg, .document-actions svg, .document-unavailable svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.document-unavailable { display: inline-grid; place-items: center; width: 27px; height: 27px; color: #a5b0ab; }
.document-entry { min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr) 27px; align-items: center; gap: 5px; }
.document-name { min-width: 0; min-height: 27px; padding: 3px 2px; border: 0; background: transparent; color: #176b4d; font-size: 9px; line-height: 1.18; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: normal; }
.document-name:hover { text-decoration: underline; }
.document-download { display: grid; place-items: center; width: 27px; height: 27px; color: #486058; border: 1px solid #c2cec8; border-radius: 6px; background: #fff; }
.document-download svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.document-pending { display: block; color: #7a8781; font-size: 9px; line-height: 1.2; text-align: center; }
.job-state-icon { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; }
.job-state-icon svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.job-state-icon.ready { color: #176b4d; background: #e0f3e8; }
.job-state-icon.normalized { color: #765b15; background: #fff1c9; }
.job-state-icon.failed, .job-state-icon.cancelled { color: #a8322b; background: #f6dfdd; }
.job-state-icon.queued { color: #76641d; background: #f5efd9; }
.job-state-icon.processing { color: #286383; background: #e3f0f8; }
.job-state-icon.processing svg { animation: spin 1.15s linear infinite; }
.action-state .job-state-icon { width: 20px; height: 20px; }
.action-state .job-state-icon svg { width: 12px; height: 12px; }
@keyframes spin { to { transform: rotate(360deg); } }

.activity-panel { position: fixed; z-index: 30; top: 68px; right: 12px; width: 430px; max-height: calc(100vh - 82px); overflow: auto; border: 1px solid #bac9c2; border-radius: 10px; background: #fff; box-shadow: 0 14px 42px rgb(16 42 32 / 20%); }
.activity-panel header { position: sticky; z-index: 2; top: 0; display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; border-bottom: 1px solid #d9e1dd; background: #fff; box-shadow: 0 2px 5px rgb(25 55 44 / 6%); }
.activity-panel header span { display: block; color: #74827b; font-size: 9px; text-transform: uppercase; }
.activity-panel header strong { display: block; margin-top: 2px; font-size: 12px; }
.activity-panel header button { border: 0; font-size: 20px; }
.activity-panel ol { list-style: none; margin: 0; padding: 6px 14px 14px; }
.activity-panel li { position: relative; padding: 9px 0 9px 18px; border-left: 2px solid #d7e1dc; }
.activity-panel li::before { content: ""; position: absolute; left: -5px; top: 15px; width: 8px; height: 8px; border-radius: 50%; background: #80a596; }
.activity-panel li.success::before { background: #1d865e; }
.activity-panel li.error::before { background: #bd493f; }
.activity-panel time { display: block; color: #7b8882; font-size: 9px; }
.activity-panel strong { font-size: 11px; }
.activity-panel p { margin: 2px 0 0; color: #596861; font-size: 10px; line-height: 1.4; }

.context-grid { display: grid; grid-template-columns: 1fr 180px 2fr; gap: 10px; }
.source-switch { display: flex; gap: 2px; width: max-content; margin-top: 15px; padding: 3px; border-radius: 8px; background: #edf2ef; }
.source-tab { min-height: 29px; border: 0; background: transparent; padding: 4px 14px; font-size: 11px; }
.source-tab.active { background: #fff; box-shadow: 0 1px 5px rgb(0 0 0 / 8%); font-weight: 650; }
.source-mode { margin-top: 9px; }
.file-drop { height: 72px; display: flex; flex-direction: column; align-items: center; justify-content: center; border: 1px dashed #94aaa0; border-radius: 8px; background: #f8faf9; cursor: pointer; }
.file-drop.selected { border-color: #176b4d; background: #f0f8f4; }
.file-drop input { display: none; }
.file-title { font-size: 12px; font-weight: 650; color: #176b4d; }
#file-name { margin-top: 4px; color: #76837d; font-size: 10px; }
#text-mode textarea { height: 90px; resize: vertical; }
.settings-row { display: grid; grid-template-columns: 170px 210px 210px minmax(150px, 1fr) auto; align-items: end; gap: 10px; margin-top: 12px; }
.model-field select { height: 34px; }
.prompt-button { justify-self: start; color: #43544c; font-size: 11px; }
.engine-note { margin: 8px 0 0; color: #66756e; font-size: 10px; }

.workspace { width: 100%; }
.request-toolbar { display: flex; align-items: center; gap: 8px; min-height: 46px; padding: 6px 9px; border: 1px solid #d4ddd9; border-radius: 9px 9px 0 0; background: #fff; }
.request-name { display: flex; flex-direction: column; max-width: 290px; }
.request-name span { color: #718078; font-size: 8px; text-transform: uppercase; }
.request-name a { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #176b4d; font-size: 11px; font-weight: 700; text-decoration: none; }
.badge { padding: 3px 7px; border-radius: 999px; background: #edf2ef; color: #58675f; font-size: 9px; }
.toolbar-spacer { flex: 1; }
.client-strip { display: flex; gap: 22px; padding: 6px 11px; border: 1px solid #d4ddd9; border-top: 0; background: #fff; font-size: 10px; }
.client-strip i { font-style: normal; color: #526159; }
.analysis-summary { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(320px, 1fr); border: 1px solid #bfd3ca; border-top: 0; background: #f1f8f4; }
.ai-comment, .commercial-block { min-height: 66px; padding: 9px 12px; }
.commercial-block { border-left: 1px solid #c9ddd4; background: #f8fbf9; }
.summary-label { color: #176b4d; font-size: 9px; font-weight: 750; text-transform: uppercase; letter-spacing: .06em; }
.ai-comment p { margin: 4px 0 0; line-height: 1.42; font-size: 11px; }
.commercial-block ul { margin: 5px 0 0; padding-left: 17px; font-size: 10px; line-height: 1.4; }
.commercial-block li + li { margin-top: 3px; }
.commercial-block li span { color: #65736c; }

.documents-layout { display: flex; align-items: stretch; height: calc(100vh - 250px); min-height: 460px; margin-top: 9px; }
.document-panel { display: flex; min-width: 0; min-height: 0; flex-direction: column; border: 1px solid #d4ddd9; background: #fff; overflow: hidden; }
.source-panel { flex: 0 0 27%; border-radius: 9px 0 0 9px; }
.normalized-panel { flex: 1; border-radius: 0 9px 9px 0; }
.splitter { align-self: stretch; flex: 0 0 7px; min-height: 0; cursor: col-resize; background: #e1e8e4; border-top: 1px solid #d4ddd9; border-bottom: 1px solid #d4ddd9; }
.splitter:hover { background: #9dc2b2; }
.document-panel > header { height: 54px; display: flex; align-items: center; justify-content: space-between; padding: 7px 10px; border-bottom: 1px solid #d9e1dd; }
.document-panel h2 { margin: 1px 0 0; font-size: 13px; }
.panel-kicker { color: #74827b; font-size: 8px; text-transform: uppercase; letter-spacing: .06em; }
.read-only, .result-count { color: #62726a; font-size: 9px; }
.source-sheet-tabs { min-height: 30px; display: flex; gap: 2px; padding: 3px 6px; border-bottom: 1px solid #d9e1dd; background: #f6f8f7; overflow-x: auto; }
.source-sheet-tabs button { min-height: 22px; border: 0; background: transparent; padding: 2px 8px; font-size: 9px; white-space: nowrap; }
.source-sheet-tabs button.active { background: #fff; box-shadow: 0 1px 4px rgb(0 0 0 / 8%); font-weight: 650; }
.table-help { min-height: 30px; margin: 0; padding: 7px 10px; border-bottom: 1px solid #d9e1dd; color: #73817a; background: #f6f8f7; font-size: 9px; }
#source-table, #normalized-table { min-height: 0; flex: 1 1 auto; }

.tabulator { border: 0 !important; background: #fff; font-size: 10px; }
.tabulator .tabulator-header { border-bottom: 1px solid #c5d1cb; background: #e8efeb; }
.tabulator .tabulator-header .tabulator-col { min-height: 38px; background: #e8efeb; }
.tabulator .tabulator-col-title { white-space: normal !important; line-height: 1.08; overflow: visible; }
.tabulator .tabulator-col-sorter { right: 2px !important; }
.tabulator-row { border-bottom: 1px solid #e1e7e4; }
.tabulator-row[data-status="ambiguous"] { background: #fffaf0; }
.tabulator-row[data-status="unidentified"] { background: #fff2f1; }
.tabulator-cell { padding: 5px 6px !important; white-space: normal !important; line-height: 1.24; overflow: hidden !important; }
.normalized-panel .tabulator-row, .normalized-panel .tabulator-row .tabulator-cell { height: 60px !important; max-height: 60px !important; }
.source-panel .tabulator-row, .source-panel .tabulator-row .tabulator-cell { height: 60px !important; max-height: 60px !important; }
#normalized-table .tabulator-tableholder, #source-table .tabulator-tableholder { overflow-x: auto; }
#normalized-table .tabulator-cell[tabulator-field="name"],
#normalized-table .tabulator-cell[tabulator-field="attributes_text"],
#normalized-table .tabulator-cell[tabulator-field="identification_note"],
#normalized-table .tabulator-cell[tabulator-field="related_products_text"],
#normalized-table .tabulator-cell[tabulator-field="clarification_question"] { cursor: zoom-in; }
.product-image { width: 48px; height: 48px; object-fit: contain; border-radius: 5px; }
.image-link { position: relative; display: inline-block; }
.image-mark { position: absolute; right: -3px; bottom: -2px; width: 17px; height: 17px; display: grid; place-items: center; border: 2px solid #fff; border-radius: 50%; font-size: 10px; font-weight: 800; }
.image-mark.identified { background: #176b4d; color: #fff; }
.image-mark.likely { background: #d7e9f4; color: #285a76; }
.image-mark.ambiguous, .image-mark.unidentified { background: #ffe4a6; color: #76540c; }
.image-placeholder { width: 48px; height: 48px; display: grid; place-items: center; margin: auto; border: 1px dashed #c9d2ce; border-radius: 5px; background: #f4f6f5; color: #78847e; font-size: 8px; text-align: center; }
.status { display: inline-block; padding: 3px 6px; border-radius: 999px; font-size: 9px; }
.status.identified { color: #176b4d; background: #e0f3e8; }
.status.likely { color: #315b7e; background: #e5eff8; }
.status.ambiguous { color: #8a6112; background: #fff0c7; }
.status.unidentified { color: #9b3029; background: #f5dddd; }
.review-check { width: 20px; height: 20px; border: 1.5px solid #aab8b2; border-radius: 5px; display: inline-grid; place-items: center; color: transparent; background: #fff; cursor: pointer; font-size: 14px; font-weight: 800; }
.review-check.checked { border-color: #176b4d; background: #176b4d; color: #fff; }
.tabulator-cell ul { margin: 3px 0 0; padding-left: 14px; }
.tabulator-cell strong { color: #814e18; font-weight: 650; }
.tabulator-cell a { color: #176b4d; }
.button-link { display: inline-flex; align-items: center; }
.toolbar-spacer + .primary { padding-left: 14px; padding-right: 14px; }
.research-count { display: block; margin-top: 4px; color: #66756e; font-size: 8px; white-space: nowrap; }
.line-confidence { font-size: 13px; font-variant-numeric: tabular-nums; color: #31433b; }
.line-actions .review-check { flex: 0 0 auto; }

.app-dialog { width: fit-content; max-width: 94vw; margin: auto; padding: 0; border: 0; border-radius: 12px; background: transparent; box-shadow: 0 22px 70px rgb(12 34 25 / 28%); }
.app-dialog::backdrop { background: rgb(17 32 26 / 46%); backdrop-filter: blur(2px); }
.dialog-card { margin: 0; border: 1px solid #bdcbc4; border-radius: 12px; background: #fff; overflow: hidden; }
.dialog-card > header { min-height: 56px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 9px 12px; border-bottom: 1px solid #d9e1dd; }
.dialog-card h2 { margin: 2px 0 0; font-size: 14px; }
.dialog-close { width: 32px; min-height: 32px; padding: 0; border: 0; background: transparent; color: #65736c; font-size: 22px; }
.dialog-card > footer { display: flex; justify-content: flex-end; gap: 8px; padding: 10px 12px; border-top: 1px solid #d9e1dd; background: #f8faf9; }
.dialog-card > footer > :first-child { margin-right: auto; }
.prompt-dialog .dialog-card { width: min(900px, 90vw); }
.prompt-dialog textarea { display: block; height: min(60vh, 620px); margin: 12px; width: calc(100% - 24px); resize: vertical; line-height: 1.45; }
.document-dialog .dialog-card { width: min(1600px, 94vw); min-height: 76vh; }
.dialog-header-actions { display: flex; align-items: center; gap: 7px; }
.icon-download { display: grid; place-items: center; width: 32px; height: 32px; border: 1px solid #c5d0cb; border-radius: 7px; color: #176b4d; text-decoration: none; font-size: 21px; line-height: 1; }
.document-images { display: flex; gap: 10px; padding: 8px 10px; overflow-x: auto; border-bottom: 1px solid #d9e1dd; background: #f8faf9; }
.document-images figure { flex: 0 0 auto; margin: 0; }
.document-images img { display: block; width: 92px; height: 72px; object-fit: contain; border: 1px solid #d6dfda; border-radius: 6px; background: #fff; }
.document-images figcaption { max-width: 92px; margin-top: 3px; overflow: hidden; color: #68766f; font-size: 8px; text-overflow: ellipsis; white-space: nowrap; }
.document-media { min-height: 68vh; max-height: 78vh; display: grid; place-items: center; padding: 12px; background: #edf1ef; overflow: auto; }
.document-media iframe { width: min(1180px, 100%); height: 72vh; border: 0; border-radius: 7px; background: #fff; box-shadow: 0 4px 18px rgb(24 45 36 / 12%); }
.document-media > img { display: block; max-width: min(1180px, 100%); max-height: 72vh; object-fit: contain; border-radius: 7px; background: #fff; box-shadow: 0 4px 18px rgb(24 45 36 / 12%); }
.document-media video { max-width: min(1180px, 100%); max-height: 70vh; border-radius: 8px; background: #17211d; }
.media-player { width: min(680px, 90%); display: grid; gap: 16px; justify-items: center; padding: 34px; border: 1px solid #ccd7d2; border-radius: 12px; background: #fff; box-shadow: 0 5px 20px rgb(24 45 36 / 10%); }
.media-player span { color: #4f6158; font-size: 12px; font-weight: 650; }
.media-player audio { width: 100%; }
.document-markdown { max-height: 26vh; margin: 0; padding: 14px 18px; overflow: auto; border-top: 1px solid #d9e1dd; background: #fbfcfb; color: #34453d; font: 11px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace; white-space: pre-wrap; }
.cell-dialog .dialog-card { width: min(760px, 90vw); }
.cell-dialog textarea { display: block; height: min(42vh, 420px); margin: 12px; width: calc(100% - 24px); resize: vertical; line-height: 1.45; }
.stages-dialog .dialog-card { width: min(820px, 92vw); }
.stages-body { display: grid; gap: 10px; padding: 12px; background: #f5f8f6; }
.stage-card { display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; align-items: start; gap: 12px; padding: 13px; border: 1px solid #d2dcd7; border-radius: 9px; background: #fff; }
.stage-number { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; color: #fff; background: #176b4d; font-size: 13px; font-weight: 750; }
.stage-content h3 { margin: 0; font-size: 13px; }
.stage-content p { margin: 3px 0 10px; color: #68766f; font-size: 10px; }
.stage-content .model-field { display: block; width: min(100%, 360px); }
.stage-actions { display: flex; gap: 7px; margin-top: 9px; }
.stage-status { padding: 4px 7px; border-radius: 999px; background: #edf2ef; color: #526159; font-size: 9px; white-space: nowrap; }
#stage2-help { display: block; margin-top: 7px; color: #718078; font-size: 9px; }

@media (max-width: 1350px) {
  main { padding: 8px 10px 24px; }
  .source-panel { flex-basis: 24%; }
  .context-grid { grid-template-columns: 1fr 160px 1.5fr; }
  .registry-toolbar { min-height: 66px; }
  .client-strip { gap: 12px; }
  .request-name { max-width: 220px; }
}

@media (min-width: 2100px) {
  .registry { width: min(78vw, 1400px); }
  .workspace { width: min(96vw, 2320px); margin: 0 auto; }
}
