:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --ink: #172033;
    --muted: #667085;
    --line: #e4e7ec;
    --accent: #2859d8;
    --accent-dark: #1946bd;
    --accent-soft: #eef3ff;
    --success: #087443;
    --danger: #b42318;
    --warning: #b54708;
    --radius: 18px;
    --shadow: 0 8px 30px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--ink); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; line-height: 1.5; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-dark); }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: .45rem; font-size: clamp(2rem, 4vw, 3.15rem); line-height: 1.04; letter-spacing: -.045em; }
h2 { margin-bottom: .7rem; font-size: 1.3rem; letter-spacing: -.02em; }
button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }
input, select, textarea { width: 100%; border: 1px solid #d0d5dd; border-radius: 10px; background: #fff; color: var(--ink); padding: .72rem .8rem; outline: none; transition: border-color .15s, box-shadow .15s; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(40, 89, 216, .12); }
textarea { resize: vertical; }
label { display: grid; gap: .42rem; color: #344054; font-size: .86rem; font-weight: 650; }

.topbar { position: sticky; top: 0; z-index: 30; min-height: 68px; display: flex; align-items: center; gap: 2rem; padding: .65rem max(1rem, calc((100vw - 1240px) / 2)); border-bottom: 1px solid var(--line); background: rgba(255,255,255,.94); backdrop-filter: blur(16px); }
.brand { display: inline-flex; align-items: center; gap: .65rem; color: var(--ink); font-size: 1.1rem; font-weight: 800; }
.brand span, .auth-mark, .document-logo { display: inline-grid; place-items: center; width: 35px; height: 35px; border-radius: 10px; background: var(--ink); color: white; font-weight: 800; }
.topbar nav { display: flex; gap: .35rem; }
.topbar nav a { padding: .55rem .78rem; border-radius: 9px; color: #475467; font-weight: 650; font-size: .9rem; }
.topbar nav a:hover { background: var(--surface-soft); color: var(--ink); }
.user-menu { margin-left: auto; display: flex; align-items: center; gap: .9rem; color: var(--muted); font-size: .86rem; }
.user-menu form { display: inline; }

.shell { width: min(1240px, calc(100% - 2rem)); margin: 0 auto; padding: 3.25rem 0 5rem; }
.shell-auth { width: min(480px, calc(100% - 2rem)); min-height: 100vh; display: grid; place-items: center; padding: 2rem 0; }
.page-heading { margin-bottom: 2rem; }
.heading-actions { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; }
.heading-inline { display: flex; align-items: center; gap: .8rem; }
.eyebrow { margin-bottom: .5rem; color: var(--accent); font-size: .74rem; font-weight: 800; letter-spacing: .13em; text-transform: uppercase; }
.lede { max-width: 680px; margin-bottom: 0; color: var(--muted); font-size: 1.02rem; }

.panel { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); padding: 1.4rem; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.15rem; }
.panel-heading h2, .panel-heading p { margin-bottom: 0; }
.button { display: inline-flex; align-items: center; justify-content: center; gap: .45rem; min-height: 43px; border: 1px solid var(--accent); border-radius: 10px; background: var(--accent); color: white; padding: .65rem 1rem; font-weight: 750; box-shadow: 0 5px 14px rgba(40, 89, 216, .16); }
.button:hover { border-color: var(--accent-dark); background: var(--accent-dark); color: white; }
.button-secondary { border-color: #cbd5e1; background: white; color: var(--ink); box-shadow: none; }
.button-secondary:hover { border-color: #98a2b3; background: var(--surface-soft); color: var(--ink); }
.button-ghost { border-color: transparent; background: transparent; color: #475467; box-shadow: none; }
.button-ghost:hover { border-color: var(--line); background: white; color: var(--ink); }
.button-small { min-height: 35px; padding: .45rem .7rem; font-size: .82rem; }
.button-block { width: 100%; }
.button-row { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.link-button { border: 0; background: transparent; color: var(--accent); padding: 0; font-weight: 700; }
.link-button:hover { text-decoration: underline; }
.danger-text { color: var(--danger); }
.strong-link { color: var(--ink); font-weight: 750; }
.strong { font-weight: 750; }

.flash { margin-bottom: 1.2rem; border-radius: 12px; padding: .85rem 1rem; font-weight: 650; }
.flash-success { border: 1px solid #abefc6; background: #ecfdf3; color: #067647; }
.flash-error { border: 1px solid #fecdca; background: #fef3f2; color: var(--danger); }
.auth-card { width: 100%; border: 1px solid var(--line); border-radius: 24px; background: white; padding: clamp(1.5rem, 5vw, 2.5rem); box-shadow: 0 20px 60px rgba(16,24,40,.1); }
.auth-mark { width: 46px; height: 46px; margin-bottom: 1.7rem; border-radius: 13px; font-size: 1.3rem; }
.auth-card h1 { font-size: 2rem; }
.stack { display: grid; gap: 1rem; }
.stack-large { display: grid; gap: 1.2rem; }
.field-help { margin: 0; color: var(--muted); font-size: .79rem; font-weight: 450; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }

.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin-bottom: 1.2rem; }
.import-banner { display: flex; align-items: center; justify-content: space-between; gap: 1.5rem; margin-bottom: 1.2rem; border: 1px solid #b6c5ef; border-radius: var(--radius); background: linear-gradient(120deg, #f7f9ff, #eef3ff); padding: 1.2rem 1.4rem; }
.import-banner h2, .import-banner p:last-child { margin-bottom: 0; }
.import-banner p:last-child { color: var(--muted); font-size: .84rem; }
.stat { position: relative; overflow: hidden; border: 1px solid var(--line); border-radius: 16px; background: white; padding: 1.25rem; box-shadow: var(--shadow); }
.stat::after { content: ""; position: absolute; right: -12px; bottom: -35px; width: 95px; height: 95px; border-radius: 50%; background: var(--accent-soft); }
.stat span { display: block; color: var(--muted); font-size: .82rem; font-weight: 650; }
.stat strong { position: relative; z-index: 1; display: block; margin-top: .45rem; font-size: 2rem; }
.stat-attention { border-color: #f7c98b; background: #fffaf3; }
.stat-attention::after { background: #ffead0; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th { color: var(--muted); font-size: .72rem; letter-spacing: .06em; text-align: left; text-transform: uppercase; }
th, td { padding: .85rem .7rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafbfc; }
.numeric { text-align: right; }
.status { display: inline-flex; align-items: center; border-radius: 99px; background: #f2f4f7; color: #475467; padding: .24rem .55rem; font-size: .72rem; font-weight: 750; }
.status-ready { background: #eef4ff; color: #3538cd; }
.status-sent { background: #fff6ed; color: #b54708; }
.status-accepted { background: #ecfdf3; color: #067647; }
.status-rejected, .status-expired { background: #fef3f2; color: #b42318; }
.workflow-draft { background: #f2f4f7; color: #475467; }
.workflow-submitted { background: #fff6ed; color: #b54708; }
.workflow-changes_requested { background: #fef3f2; color: #b42318; }
.workflow-approved { background: #ecfdf3; color: #067647; }
.review-queue { margin-bottom: 1.2rem; border-color: #f7c98b; }
.searchbar { display: flex; gap: .6rem; margin-bottom: 1rem; }
.searchbar input { min-width: 220px; }
.empty { padding: 3rem 1rem; color: var(--muted); text-align: center; }
.empty h3, .empty h1 { color: var(--ink); }
.large-empty { margin-top: 5rem; }
.count-badge { display: inline-grid; place-items: center; min-width: 28px; height: 28px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); font-weight: 800; }

.split-layout { display: grid; grid-template-columns: minmax(300px, .75fr) minmax(400px, 1.25fr); gap: 1.2rem; align-items: start; }
.form-panel { position: sticky; top: 88px; }
.portal-account-box { border-top: 1px solid var(--line); margin-top: 1.5rem; padding-top: 1.5rem; }
.client-list { display: grid; gap: .55rem; }
.client-card { position: relative; display: grid; gap: .16rem; border: 1px solid var(--line); border-radius: 12px; padding: .85rem 2.6rem .85rem 1rem; color: var(--ink); }
.client-card:hover { border-color: #b6c5ef; background: var(--accent-soft); color: var(--ink); }
.client-card span { color: var(--muted); font-size: .8rem; }
.client-card .arrow { position: absolute; right: 1rem; top: 50%; color: var(--accent); font-size: 1.2rem; transform: translateY(-50%); }

.catalog-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.catalog-card { display: flex; flex-direction: column; min-height: 285px; }
.catalog-card.is-inactive { opacity: .62; }
.catalog-card-top, .catalog-meta, .price-line { display: flex; align-items: center; justify-content: space-between; gap: .6rem; }
.kind-badge { color: var(--accent); font-size: .72rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.catalog-card h2 { margin-top: 1rem; }
.catalog-card > p { flex: 1; color: var(--muted); font-size: .86rem; }
.price-line { justify-content: flex-start; margin-bottom: .65rem; }
.price-line strong { font-size: 1.25rem; }
.price-line span, .catalog-meta { color: var(--muted); font-size: .76rem; }
.catalog-meta { border-top: 1px solid var(--line); margin-bottom: 1rem; padding-top: .7rem; }

.form-section { padding: clamp(1.2rem, 3vw, 2rem); }
.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1.4rem; }
.section-heading > div { display: flex; align-items: center; gap: .7rem; }
.section-heading > div > span { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; background: var(--accent-soft); color: var(--accent); font-size: .75rem; font-weight: 800; }
.section-heading h2, .section-heading p { margin: 0; }
.section-heading > p { color: var(--muted); font-size: .8rem; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-grid-3 { grid-template-columns: repeat(3, 1fr); }
.span-2 { grid-column: span 2; }
.checkbox-label { display: flex; align-items: center; gap: .55rem; }
.checkbox-label input { width: auto; }
.option-editor { display: grid; gap: .65rem; }
.option-editor-row { display: grid; grid-template-columns: 1.5fr repeat(4, 1fr) 38px; gap: .6rem; align-items: end; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-soft); padding: .8rem; }
.icon-button { display: inline-grid; place-items: center; width: 36px; height: 36px; flex: 0 0 36px; border: 1px solid var(--line); border-radius: 9px; background: white; color: #475467; font-size: 1.1rem; }
.icon-button:hover { border-color: #fda29b; background: #fef3f2; color: var(--danger); }
.icon-button:disabled { cursor: not-allowed; opacity: .35; }
.relation-list { display: grid; gap: .6rem; }
.relation-list > label { display: grid; grid-template-columns: 1fr minmax(210px, .5fr); align-items: center; border: 1px solid var(--line); border-radius: 12px; padding: .7rem .8rem; }
.relation-list span { display: grid; }
.relation-list small { color: var(--muted); font-weight: 450; }
.sticky-actions { position: sticky; bottom: 1rem; z-index: 20; display: flex; justify-content: flex-end; gap: .7rem; border: 1px solid var(--line); border-radius: 14px; background: rgba(255,255,255,.95); padding: .7rem; box-shadow: 0 10px 35px rgba(16,24,40,.13); backdrop-filter: blur(12px); }

.quote-form { display: grid; gap: 1rem; }
.quote-meta { display: grid; grid-template-columns: 1.7fr repeat(4, 1fr); gap: .75rem; }
.builder-layout { display: grid; grid-template-columns: minmax(0, 1fr) 290px; gap: 1rem; align-items: start; }
.builder-panel { min-width: 0; }
.totals-card { position: sticky; top: 88px; }
.totals-card dl { margin: 1.3rem 0 1rem; }
.totals-card dl div { display: flex; justify-content: space-between; gap: 1rem; border-bottom: 1px solid var(--line); padding: .65rem 0; }
.totals-card dt { color: var(--muted); }
.totals-card dd { margin: 0; font-weight: 750; }
.totals-card .grand-total { border: 0; padding-top: 1rem; font-size: 1.15rem; }
.totals-card .grand-total dd { color: var(--accent); font-size: 1.25rem; }
.calculation-message { min-height: 1.3rem; color: var(--muted); font-size: .8rem; }
.calculation-message.is-error { color: var(--danger); }
.builder-lines { display: grid; gap: .8rem; }
.builder-line { border: 1px solid var(--line); border-radius: 14px; background: #fff; padding: .9rem; }
.builder-row-fields { display: grid; grid-template-columns: minmax(180px, 1.6fr) minmax(80px, .45fr) minmax(130px, .65fr) minmax(110px, .55fr) 36px; gap: .55rem; align-items: end; }
.control-label { display: block; color: var(--muted); font-size: .7rem; letter-spacing: .02em; }
.line-price { align-self: center; padding-top: 1.2rem; text-align: right; white-space: nowrap; }
.builder-options { display: flex; flex-wrap: wrap; gap: .45rem .8rem; border-top: 1px dashed var(--line); margin-top: .75rem; padding-top: .7rem; }
.builder-options label { display: flex; align-items: center; gap: .38rem; font-size: .77rem; font-weight: 550; }
.builder-options input { width: auto; }
.builder-children { display: grid; gap: .55rem; margin: .75rem 0 0 1.3rem; }
.builder-child { border-left: 3px solid #b6c5ef; border-radius: 0 10px 10px 0; background: #f8faff; padding: .7rem; }
.text-action { justify-self: start; border: 0; background: transparent; color: var(--accent); padding: .25rem; font-size: .8rem; font-weight: 750; }
.notes-panel label { font-size: .92rem; }
.review-note { border: 1px solid #f7c98b; border-radius: 14px; background: #fffaf3; color: #7a2e0e; padding: 1rem 1.2rem; }
.review-note p { margin: .35rem 0 0; }

.workflow-banner { display: flex; align-items: center; justify-content: space-between; gap: 1.5rem; margin-bottom: 1rem; border: 1px solid #b6c5ef; border-radius: var(--radius); background: linear-gradient(120deg, #f7f9ff, #eef3ff); padding: 1.2rem 1.4rem; }
.workflow-banner-warning { border-color: #f7c98b; background: linear-gradient(120deg, #fffdf8, #fff4e5); }
.workflow-banner h2, .workflow-banner p:last-child { margin-bottom: 0; }
.workflow-banner p:last-child { color: var(--muted); }
.review-panel { display: grid; grid-template-columns: minmax(240px, .75fr) minmax(360px, 1.25fr); gap: 1.5rem; margin-bottom: 1rem; border-color: #f7c98b; }
.review-panel > div > p:last-child { color: var(--muted); margin-bottom: 0; }
.review-form { display: grid; gap: .75rem; }

.detail-layout { display: grid; grid-template-columns: minmax(0, 1fr) 310px; gap: 1rem; align-items: start; }
.detail-sidebar { display: grid; gap: 1rem; }
.preview-header, .document-header { display: flex; justify-content: space-between; gap: 2rem; border-bottom: 2px solid var(--ink); padding-bottom: 1.3rem; }
.preview-header > div, .document-header > div { display: grid; justify-items: start; gap: .3rem; }
.preview-header > div:last-child, .document-header > div:last-child { justify-items: end; }
.preview-header p, .preview-header span, .document-header p, .document-header span { margin: 0; color: var(--muted); font-size: .8rem; }
.document-logo { margin-bottom: .5rem; }
.document-lines { margin-top: 1.7rem; }
.document-line { display: grid; grid-template-columns: minmax(0, 1fr) 125px 145px; gap: 1rem; align-items: start; border-bottom: 1px solid var(--line); padding: .9rem .4rem; font-size: .86rem; }
.document-line > :last-child { text-align: right; }
.document-line small { display: block; margin-top: .22rem; color: var(--muted); }
.document-line-head { color: var(--muted); font-size: .69rem; font-weight: 750; letter-spacing: .07em; text-transform: uppercase; }
.document-subline { background: #fafbfc; padding-left: 1.4rem; }
.document-totals { width: min(380px, 100%); margin: 1.5rem 0 1.5rem auto; }
.document-totals > div { display: flex; justify-content: space-between; border-bottom: 1px solid var(--line); padding: .5rem; }
.document-totals > div:last-child { border: 0; background: var(--ink); color: white; padding: .8rem; font-size: 1.1rem; }
.document-notes { border-top: 1px solid var(--line); margin-top: 2rem; padding-top: 1.2rem; }
.document-notes p { color: #475467; white-space: normal; }
.copy-field { display: flex; gap: .45rem; margin-bottom: .8rem; }
.copy-field input { min-width: 0; font-size: .75rem; }
.version-list { display: grid; gap: .6rem; }
.version-list > div { display: grid; grid-template-columns: 42px 1fr auto; gap: .5rem; color: var(--muted); font-size: .78rem; }
.version-list strong { color: var(--ink); }
.version-list-rich > div { align-items: start; border-bottom: 1px solid var(--line); padding: .45rem 0; }
.version-list-rich > div:last-child { border-bottom: 0; }
.version-list-rich span { display: grid; }
.version-list-rich span:last-child { justify-items: end; }
.version-list-rich b { color: var(--ink); }
.version-list-rich small { color: var(--muted); font-weight: 450; }
.event-list { display: grid; gap: .1rem; }
.event-list > div { position: relative; display: grid; grid-template-columns: 16px 1fr; gap: .55rem; }
.event-list > div:not(:last-child)::before { content: ""; position: absolute; left: 5px; top: 15px; bottom: -6px; width: 1px; background: var(--line); }
.event-dot { position: relative; z-index: 1; width: 11px; height: 11px; margin-top: .35rem; border: 3px solid var(--accent-soft); border-radius: 50%; background: var(--accent); }
.event-list p { display: grid; margin: 0 0 .7rem; font-size: .8rem; }
.event-list small, .event-list p > span { color: var(--muted); }

.document-body { background: #e9edf3; }
.document-toolbar { position: sticky; top: 0; z-index: 10; display: flex; justify-content: space-between; align-items: center; width: min(920px, calc(100% - 2rem)); margin: 1rem auto; border-radius: 12px; background: var(--ink); color: white; padding: .6rem .75rem .6rem 1rem; }
.document-page { width: min(920px, calc(100% - 2rem)); min-height: 1120px; margin: 1rem auto 3rem; background: white; padding: clamp(1.5rem, 6vw, 4.5rem); box-shadow: 0 20px 60px rgba(16,24,40,.14); }
.document-parties { display: grid; grid-template-columns: 1.5fr 1fr; gap: 2rem; margin: 3rem 0; }
.document-parties h1 { font-size: 1.8rem; }
.document-parties p { color: #475467; }
.document-footer { display: flex; justify-content: space-between; border-top: 1px solid var(--line); margin-top: 4rem; padding-top: 1rem; color: var(--muted); font-size: .7rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }

@media (max-width: 980px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .catalog-grid { grid-template-columns: repeat(2, 1fr); }
    .split-layout, .detail-layout, .builder-layout { grid-template-columns: 1fr; }
    .review-panel { grid-template-columns: 1fr; }
    .form-panel, .totals-card { position: static; }
    .quote-meta { grid-template-columns: repeat(3, 1fr); }
    .option-editor-row { grid-template-columns: repeat(2, 1fr) 38px; }
    .option-editor-row label:first-child { grid-column: span 2; }
    .builder-row-fields { grid-template-columns: minmax(180px, 1fr) 90px 140px; }
    .builder-row-fields .line-price { text-align: left; }
}

@media (max-width: 720px) {
    .topbar { position: static; flex-wrap: wrap; gap: .7rem; padding: .75rem 1rem; }
    .topbar nav { order: 3; width: 100%; overflow-x: auto; }
    .user-menu > span { display: none; }
    .shell { width: min(100% - 1rem, 1240px); padding-top: 2rem; }
    .heading-actions { align-items: stretch; flex-direction: column; }
    .import-banner { align-items: stretch; flex-direction: column; }
    .workflow-banner { align-items: stretch; flex-direction: column; }
    .heading-actions > .button, .heading-actions > .button-row .button { flex: 1; }
    .stats-grid, .catalog-grid, .form-grid, .form-grid-3, .quote-meta { grid-template-columns: 1fr; }
    .span-2 { grid-column: span 1; }
    .field-row { grid-template-columns: 1fr; }
    .section-heading { flex-direction: column; }
    .option-editor-row { grid-template-columns: 1fr 38px; }
    .option-editor-row label, .option-editor-row label:first-child { grid-column: 1; }
    .option-editor-row .icon-button { grid-column: 2; grid-row: 1; }
    .relation-list > label { grid-template-columns: 1fr; }
    .builder-row-fields { grid-template-columns: 1fr 1fr; }
    .builder-row-fields .wide-control { grid-column: 1 / -1; }
    .builder-row-fields .line-price { align-self: center; padding-top: 0; }
    .builder-children { margin-left: .45rem; }
    .document-line { grid-template-columns: 1fr 90px; }
    .document-line > :nth-child(2) { grid-row: 2; color: var(--muted); font-size: .76rem; }
    .document-line > :last-child { grid-column: 2; grid-row: 1; }
    .document-parties { grid-template-columns: 1fr; }
    .document-page { width: 100%; margin: 0; box-shadow: none; }
    .document-toolbar { width: calc(100% - 1rem); }
    .sticky-actions { position: static; }
}

@media print {
    @page { size: A4; margin: 15mm; }
    body { background: white; color: black; }
    .document-toolbar { display: none; }
    .document-page { width: 100%; min-height: 0; margin: 0; padding: 0; box-shadow: none; }
    .document-line, .document-notes, .document-footer { break-inside: avoid; }
    .document-totals > div:last-child { background: #eee; color: black; }
}
