:root {
  --paper: #f3f1eb;
  --surface: #fffefa;
  --ink: #17211c;
  --muted: #687269;
  --line: #d9d8cf;
  --forest: #173f32;
  --forest-2: #245a47;
  --lime: #bedb73;
  --amber: #e7a82e;
  --red: #b84b3e;
  --shadow: 0 14px 36px rgba(23, 63, 50, .08);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; display: grid; grid-template-columns: 232px minmax(0, 1fr); background: var(--paper); color: var(--ink); font-family: Inter, "Segoe UI", Arial, sans-serif; }
button, input, select { font: inherit; }
.proc-sidebar { position: sticky; top: 0; align-self: start; height: 100vh; height: 100dvh; min-height: 0; overflow-y: auto; padding: 26px 18px; display: flex; flex-direction: column; background: var(--forest); color: #fff; z-index: 20; }
.proc-brand { display: flex; align-items: baseline; gap: 8px; margin: 0 10px 34px; color: #fff; text-decoration: none; font-weight: 800; letter-spacing: .08em; }
.proc-brand span { color: var(--lime); font-weight: 600; letter-spacing: 0; }
.proc-sidebar nav { display: grid; gap: 7px; }
.proc-nav { min-height: 44px; border: 0; border-radius: 8px; padding: 10px 13px; background: transparent; color: #d7e2dc; text-align: left; cursor: pointer; }
.proc-nav:hover, .proc-nav.is-active { background: rgba(255,255,255,.11); color: #fff; }
.proc-nav.is-active { box-shadow: inset 3px 0 var(--lime); }
.proc-sidebar-status { margin-top: auto; display: flex; gap: 10px; padding: 15px 11px; border-top: 1px solid rgba(255,255,255,.14); }
.proc-sidebar-status div { display: grid; gap: 3px; }
.proc-sidebar-status small { color: #afc4ba; }
.status-dot { width: 9px; height: 9px; margin-top: 5px; border-radius: 50%; background: var(--lime); box-shadow: 0 0 0 5px rgba(190,219,115,.12); }
main { min-width: 0; padding: 26px 30px 40px; }
.proc-header { min-height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
.eyebrow { margin: 0 0 5px; color: var(--forest-2); font-size: 12px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(28px, 3vw, 40px); letter-spacing: -.04em; }
h2 { margin-bottom: 4px; font-size: 20px; }
p { color: var(--muted); }
.header-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 10px; min-width: 0; }
.filters { display: grid; grid-template-columns: minmax(150px, 1fr) minmax(180px, 1.2fr) minmax(200px, 1.6fr) minmax(120px, .7fr); gap: 10px; width: 100%; min-width: 0; }
.filters > input, .filters > select { width: 100%; min-width: 0; max-width: 100%; }
.source-age { color: var(--muted); font-size: 13px; }
.button, input, select { min-height: 40px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); }
.button { padding: 0 15px; cursor: pointer; }
.button.primary { border-color: var(--forest); background: var(--forest); color: #fff; }
.button:disabled { opacity: .55; cursor: wait; }
input, select { padding: 0 12px; }
input:not([type="checkbox"]):not([type="radio"]) { min-width: 0; }
input[type="checkbox"], input[type="radio"] { width: 18px; height: 18px; min-width: 18px; min-height: 18px; padding: 0; margin: 0; vertical-align: middle; accent-color: var(--forest); }
.loading, .empty { padding: 60px 24px; text-align: center; color: var(--muted); }
.demo-banner, .notice { margin-bottom: 16px; padding: 12px 15px; border-left: 4px solid var(--amber); background: #fff6dd; color: #4c3a16; }
.notice.success { border-left-color: #3b8764; background: #e2f0e7; color: #225b40; }
.notice.error { border-left-color: var(--red); background: #f7e4df; color: #7d2f26; }
.quality-panel { margin-bottom: 16px; padding: 17px; border: 1px solid var(--line); border-left: 5px solid var(--red); border-radius: 10px; background: var(--surface); box-shadow: var(--shadow); }
.quality-panel.is-ready { border-left-color: #3b8764; }
.quality-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.quality-head h2 { margin-bottom: 0; }
.quality-state { padding: 7px 10px; border-radius: 999px; background: #f1d4cf; color: #7d2f26; font-size: 12px; font-weight: 800; }
.is-ready .quality-state { background: #d8eadf; color: #225b40; }
.quality-checks { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 9px; }
.quality-check { min-width: 0; display: flex; gap: 9px; padding: 10px; border-radius: 8px; background: #f7f6f1; }
.quality-check div { min-width: 0; }
.quality-check b, .quality-check small { display: block; }
.quality-check small { margin-top: 3px; color: var(--muted); line-height: 1.35; }
.quality-indicator { flex: 0 0 auto; width: 9px; height: 9px; margin-top: 5px; border-radius: 50%; background: var(--red); }
.quality-check.ok .quality-indicator { background: #3b8764; }
.quality-check.warning .quality-indicator { background: var(--amber); }
.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { min-height: 126px; padding: 17px; border: 1px solid var(--line); border-top: 4px solid var(--forest-2); border-radius: 10px; background: var(--surface); box-shadow: var(--shadow); }
.kpi.danger { border-top-color: var(--red); }
.kpi.success { border-top-color: #3b8764; }
.kpi.accent { border-top-color: var(--amber); }
.kpi span, .kpi small { display: block; color: var(--muted); }
.kpi strong { display: block; margin: 11px 0 7px; font-size: 29px; letter-spacing: -.04em; }
.work-panel { overflow: hidden; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); box-shadow: var(--shadow); }
.work-toolbar { min-height: 88px; display: flex; flex-direction: column; align-items: stretch; gap: 16px; padding: 18px; border-bottom: 1px solid var(--line); }
.work-toolbar > div { min-width: 0; }
.work-toolbar p { margin-bottom: 0; }
.batch-actions { min-height: 58px; display: flex; flex-wrap: wrap; align-items: center; gap: 9px; padding: 9px 18px; border-bottom: 1px solid var(--line); background: #f8f7f2; }
.batch-actions b { margin-right: auto; }
.table-scroll { max-width: 100%; overflow-x: auto; overscroll-behavior-x: contain; }
.needs-table { min-width: 1220px; table-layout: fixed; }
.needs-scroll { max-height: 72vh; scrollbar-width: thin; }
.needs-table th { position: sticky; top: 0; z-index: 1; white-space: normal; padding: 12px 8px; font-size: 11px; letter-spacing: .01em; }
.needs-table td { vertical-align: top; overflow-wrap: anywhere; padding: 13px 10px; }
.needs-table th:first-child, .needs-table td:first-child { text-align: center; padding-left: 8px; padding-right: 8px; }
.needs-table .decision { white-space: normal; padding: 6px 9px; }
.needs-table .item-link { width: 100%; overflow-wrap: anywhere; }
.table-scroll-hint { margin: 0; padding: 9px 18px; font-size: 12px; border-bottom: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { padding: 12px 14px; background: #eeeee8; color: var(--muted); text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
td { padding: 13px 14px; border-top: 1px solid #ecebe4; vertical-align: middle; }
tbody tr:hover { background: #f8f7f2; }
td small, .item-link small { display: block; margin-top: 4px; color: var(--muted); }
.num { text-align: right; white-space: nowrap; }
.strong { font-weight: 700; }
.item-link { border: 0; padding: 0; background: transparent; color: var(--ink); text-align: left; cursor: pointer; }
.zone, .decision { display: inline-flex; align-items: center; min-height: 26px; border-radius: 999px; padding: 0 9px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.zone.black { background: #272b29; color: #fff; }
.zone.red { background: #f1d4cf; color: #7d2f26; }
.zone.yellow { background: #f7e7bc; color: #6e5117; }
.zone.green { background: #d8eadf; color: #225b40; }
.zone.blue { background: #dce8ed; color: #315f70; }
.decision { background: #ecebe5; color: #5e655e; }
.decision.ready { background: #d8eadf; color: #225b40; }
.table-note { margin: 0; padding: 12px 16px; border-top: 1px solid var(--line); font-size: 13px; }
.empty-row { padding: 38px; text-align: center; color: var(--muted); }
.empty { border: 1px dashed #bfc3ba; border-radius: 10px; background: rgba(255,255,255,.45); }
.empty span { color: var(--forest-2); }
.section-intro { min-height: 82px; display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 16px; }
.section-intro p { margin-bottom: 0; }
.safe-badge { padding: 8px 11px; border-radius: 999px; background: #d8eadf; color: #225b40; font-size: 13px; font-weight: 700; white-space: nowrap; }
.basket-grid, .document-list { display: grid; gap: 13px; }
.basket-grid { grid-template-columns: repeat(auto-fit, minmax(min(100%,330px), 1fr)); }
.basket-card, .document-card, .measurement-card { border: 1px solid var(--line); border-radius: 10px; background: var(--surface); box-shadow: var(--shadow); }
.basket-card { padding: 18px; }
.basket-head { display: flex; justify-content: space-between; gap: 14px; }
.basket-head span, .basket-meta, .document-number { color: var(--muted); font-size: 13px; }
.basket-head h2 { margin: 5px 0 0; }
.basket-head strong { font-size: 21px; }
.basket-meta { display: flex; flex-wrap: wrap; gap: 8px 15px; margin: 15px 0; padding: 11px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.basket-card ul, .measurement-card ul { margin: 0; padding-left: 19px; }
.basket-card li { display: flex; justify-content: space-between; gap: 14px; margin: 8px 0; }
.document-card { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 20px; padding: 17px 18px; }
.document-card h2 { margin: 5px 0 0; }
.document-card p { margin-bottom: 0; }
.document-total { display: grid; gap: 5px; text-align: right; }
.document-total strong { font-size: 21px; }
.document-total span { color: var(--muted); }
.progress-layout { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(260px, .8fr); gap: 15px; align-items: start; }
.measurement-card { padding: 20px; }
.measurement-card li { margin: 9px 0; color: var(--muted); }
.positive { color: #2f7655; font-weight: 700; }
.item-dialog { width: min(920px, calc(100% - 28px)); max-height: 84vh; padding: 0; border: 0; border-radius: 12px; background: var(--surface); color: var(--ink); box-shadow: 0 28px 80px rgba(0,0,0,.28); }
.item-dialog::backdrop { background: rgba(13, 25, 20, .55); }
#dialog-content { padding: 22px; }
.dialog-head { display: flex; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.dialog-head h2 { margin: 10px 0 5px; font-size: 25px; }
.dialog-head p { margin-bottom: 0; }
.dialog-close { width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 50%; background: transparent; color: var(--ink); font-size: 25px; cursor: pointer; }
.best-offer { background: #edf5e9; }
.chosen-supplier { background: #edf5e9; }
.historical-prices { margin: 20px 0; }
.historical-prices td { vertical-align: top; }
.historical-prices details { min-width: 160px; }
.price-event { margin: 10px 0; padding: 8px 0; border-bottom: 1px solid var(--line); }
.supplier-directory { display: grid; grid-template-columns: repeat(auto-fit,minmax(min(100%,320px),1fr)); gap: 16px; padding: 20px; }
.supplier-directory-card { border: 1px solid var(--line); padding: 18px; border-radius: 12px; }
.supplier-directory-card[hidden] { display: none; }
.supplier-directory-card .item-link { display: block; margin: 12px 0; text-align: left; }
.historical-prices summary, .supplier-directory-card summary { cursor: pointer; padding: 8px 0; }
.error-text { color: var(--red); }
.row-supplier { width: 100%; min-width: 0; white-space: normal; }
.row-supplier-select { width: 100%; min-width: 0; padding: 9px; text-overflow: ellipsis; }
.row-supplier-edit { margin-top: 8px; padding: 10px; background: #fff6dd; border: 1px solid var(--amber); border-radius: 8px; }
.row-supplier-edit label { display: block; font-size: 12px; }
.row-supplier-edit input { width: 100%; min-width: 0; box-sizing: border-box; margin: 5px 0; }
.row-supplier-edit .button { margin-top: 7px; padding: 7px 10px; }
.basket-budget { margin: 12px 0; padding: 12px; background: #eef4ec; border-radius: 8px; }
.basket-budget small { display: block; margin-top: 5px; }
.basket-budget summary { cursor: pointer; margin-top: 10px; }
#draft-price-form input:not([type="checkbox"]) { width: 155px; min-width: 0; padding: 8px; box-sizing: border-box; }
#draft-price-form input[name^="note-"] { width: 230px; }
#draft-price-form > label { display: block; margin: 18px 0; }
.similar-section { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--line); }
.similar-head h3 { margin: 0 0 5px; font-size: 18px; }
.similar-head p { margin-bottom: 0; }
.similar-search { display: flex; gap: 9px; margin: 14px 0; }
.similar-search input { flex: 1; min-width: 0; }
.similar-warning { margin: 0 0 10px; padding: 10px 12px; border-left: 3px solid var(--amber); background: #fff6dd; color: #4c3a16; font-size: 13px; }
.similar-loading { padding: 24px; text-align: center; color: var(--muted); }
.match-score { display: inline-flex; min-width: 48px; min-height: 28px; align-items: center; justify-content: center; border-radius: 999px; background: #f7e7bc; color: #6e5117; font-weight: 800; }
.match-score.high { background: #d8eadf; color: #225b40; }
.match-score.low { background: #f1d4cf; color: #7d2f26; }
.risk-text { color: var(--red); }

@media (max-width: 1100px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .header-actions { flex-wrap: wrap; justify-content: flex-end; }
  .quality-checks { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 760px) {
  body { grid-template-columns: 1fr; }
  .proc-sidebar { height: auto; min-height: 0; width: 100%; min-width: 0; padding: 10px 14px; overflow: visible; box-shadow: 0 4px 14px #173f3226; }
  .proc-brand { margin: 0 4px 8px; }
  .proc-sidebar nav { display: flex; overflow-x: auto; gap: 6px; padding-bottom: 3px; }
  .proc-nav { flex: 0 0 auto; max-width: 240px; white-space: nowrap; }
  .proc-sidebar-status { display: none; }
  main { padding: 18px 14px 30px; }
  .proc-header, .header-actions, .filters { align-items: stretch; flex-direction: column; }
  .proc-header { align-items: flex-start; }
  .header-actions { width: 100%; }
  .filters { grid-template-columns: 1fr; }
  input:not([type="checkbox"]):not([type="radio"]) { min-width: 0; width: 100%; }
  .kpi-grid { grid-template-columns: 1fr; }
  .batch-actions { align-items: stretch; flex-direction: column; }
  .batch-actions b { margin: 0; }
  .document-card, .progress-layout { grid-template-columns: 1fr; }
  .document-total { text-align: left; }
  .similar-search { align-items: stretch; flex-direction: column; }
  .quality-head { align-items: flex-start; flex-direction: column; }
  .quality-checks { grid-template-columns: 1fr; }
}
.auth-pending > .proc-sidebar, .auth-pending > main, .auth-locked > .proc-sidebar, .auth-locked > main { display: none; }
body.auth-pending, body.auth-locked { display: block; margin: 0; background: #edf2f0; }
.auth-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px; box-sizing: border-box; }
body:not(.auth-pending):not(.auth-locked) > .auth-screen { display: none; }
.auth-card { width: 100%; max-width: 460px; background: white; padding: 36px; border-radius: 20px; box-shadow: 0 14px 50px #173c2520; box-sizing: border-box; }
.auth-card h1 { margin: 18px 0 12px; font-size: 27px; }
.auth-card p, .auth-card small { color: #53625a; line-height: 1.5; }
.auth-brand { color: #22613d; font-weight: 750; letter-spacing: 2px; font-size: 13px; }
.auth-card .button { width: 100%; margin-top: 10px; }
.auth-card #production-login-error { color: #a42d26; }
#allocation-form { display: grid; grid-template-columns: minmax(0, 2fr) minmax(140px, 1fr); gap: 14px 20px; margin-top: 20px; }
#allocation-form label { display: grid; gap: 7px; min-width: 0; }
#allocation-form input:not([type="checkbox"]), #allocation-form select { width: 100%; min-width: 0; max-width: 100%; box-sizing: border-box; }
#allocation-form > label:has(input[type="checkbox"]) { display: flex; align-items: center; grid-column: 1 / -1; }
#allocation-form > p, #allocation-form > label:has(input[name="reason"]), #second-allocation { grid-column: 1 / -1; }
#second-allocation:not([hidden]) { display: grid; grid-template-columns: minmax(0, 2fr) minmax(140px, 1fr); gap: 14px 20px; background: #f4f6f3; border-radius: 12px; padding: 16px; }
#split-half { justify-self: start; }
#allocation-save { justify-self: start; }
@media (max-width: 600px) { #allocation-form, #second-allocation:not([hidden]) { grid-template-columns: minmax(0, 1fr); } }
:is(.account-form,.similar-section) label { display: block; margin: 14px 0; }
:is(.account-form,.similar-section) input, :is(.account-form,.similar-section) select { display: block; padding: 10px; margin-top: 6px; width: 100%; max-width: 720px; box-sizing: border-box; }
