:root {
  --bg: #f4f7fb;
  --panel: #fff;
  --ink: #172033;
  --muted: #68738a;
  --line: #dfe5ef;
  --primary: #155eef;
  --primary-dark: #0f4ac4;
  --success: #16825d;
  --danger: #c9364f;
  --shadow: 0 12px 35px rgba(29, 48, 84, .08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: linear-gradient(145deg, #f8faff 0, #f3f6fb 55%, #eef3fa 100%); line-height: 1.5; }
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }
h1, h2, p { margin-top: 0; }
h1 { font-size: clamp(1.85rem, 4vw, 2.6rem); letter-spacing: -.04em; margin-bottom: 6px; line-height: 1.1; }
h2 { font-size: 1.1rem; letter-spacing: -.015em; margin-bottom: 0; }

.topbar { min-height: 68px; padding: 10px max(24px, calc((100vw - 1180px) / 2)); display: flex; align-items: center; justify-content: space-between; background: rgba(255,255,255,.92); border-bottom: 1px solid var(--line); backdrop-filter: blur(12px); position: sticky; top: 0; z-index: 10; }
.brand { display: flex; gap: 10px; align-items: center; color: var(--ink); font-weight: 750; flex-shrink: 0; }
.brand-mark { width: 32px; height: 32px; border-radius: 10px; background: linear-gradient(145deg, #2875ff, #0f49bd); color: #fff; display: inline-grid; place-items: center; box-shadow: 0 6px 15px rgba(21,94,239,.28); }
.brand-mark.large { width: 48px; height: 48px; border-radius: 14px; font-size: 1.25rem; margin-bottom: 18px; }
.topbar nav { display: flex; gap: 24px; align-items: center; flex-shrink: 0; }
.topbar nav > a, .link-button { color: #48536a; font: inherit; border: 0; background: none; padding: 0; cursor: pointer; }
.topbar nav > a:hover, .link-button:hover { color: var(--primary); }
.topbar .nav-primary { color: var(--primary); font-weight: 700; }
.logout-form { display: inline-flex; }
.global-search { width: min(34vw, 390px); margin: 0 20px; }
.global-search input { background: #f6f8fc; border-color: #e3e8f0; padding: 8px 12px; }

.container { max-width: 1180px; margin: 0 auto; padding: 46px 24px 72px; min-height: calc(100vh - 118px); }
footer { text-align: center; color: #8a94a7; font-size: .82rem; padding: 0 20px 24px; }
.eyebrow { text-transform: uppercase; letter-spacing: .13em; font-size: .72rem; font-weight: 800; color: var(--primary); margin-bottom: 9px; }
.muted { color: var(--muted); }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 30px; }
.page-heading p:last-child { margin-bottom: 0; }
.back { display: inline-block; margin-bottom: 11px; color: var(--muted); font-size: .9rem; }
.meta-line, .heading-actions, .inline-fields { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.meta-line { color: var(--muted); font-size: .9rem; }
.last-contact { margin: 12px 0 0; color: var(--muted); font-size: .88rem; }

.button { appearance: none; display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: #39445a; padding: 10px 16px; min-height: 42px; font: inherit; font-weight: 650; cursor: pointer; white-space: nowrap; }
.button:hover { border-color: #b9c5d7; color: var(--ink); }
.button-primary { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: 0 7px 16px rgba(21,94,239,.2); }
.button-primary:hover { background: var(--primary-dark); color: #fff; }
.button-ghost { background: transparent; }
.full { width: 100%; }

.panel, .stat-card, .detail-strip { background: var(--panel); border: 1px solid rgba(217,225,237,.9); border-radius: 16px; box-shadow: var(--shadow); }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px,1fr)); gap: 18px; margin-bottom: 22px; }
.stat-card { padding: 24px; color: var(--ink); display: grid; grid-template-columns: 1fr auto; gap: 2px 15px; }
.stat-card span { font-weight: 650; }
.stat-card strong { font-size: 2.3rem; line-height: 1; grid-row: 1/3; grid-column: 2; }
.stat-card small { color: var(--muted); }
.stat-card.accent { background: linear-gradient(130deg,#fff,#eef4ff); border-color: #cfddf7; }
.stat-card.attention-stat { border-color: #f1c6cc; background: linear-gradient(130deg,#fff,#fff1f3); }
.dashboard-grid, .company-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 22px; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding-bottom: 17px; border-bottom: 1px solid var(--line); }
.panel > .panel-heading { padding: 20px 22px 16px; }
.panel-heading.bare { padding: 0 0 12px; border-bottom: 0; }

.list-row { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 16px 22px; color: var(--ink); border-bottom: 1px solid #edf0f5; }
.list-row:last-child { border-bottom: 0; }
.list-row:hover { background: #f9fbfe; }
.list-row > div { display: flex; flex-direction: column; min-width: 0; }
.list-row span, .list-row small { color: var(--muted); font-size: .84rem; }
.align-right { align-items: flex-end; gap: 5px; }
.badge { display: inline-flex; width: max-content; border-radius: 99px; padding: 4px 9px; background: #eef1f6; color: #526078!important; font-size: .75rem!important; font-weight: 720; line-height: 1.25; }
.badge-active, .badge-created, .badge-client_interested, .badge-paid, .badge-delivered { background: #e6f6f0; color: #137554!important; }
.badge-draft, .badge-waiting_request, .badge-waiting_feedback, .badge-waiting_payment { background: #fff4db; color: #8b5d00!important; }
.badge-sent, .badge-invoice_sent, .badge-in_transit, .badge-onboarding { background: #e8f0ff; color: #235abe!important; }
.badge-cancelled, .badge-rejected, .badge-do_not_call { background: #ffeaed; color: #af2941!important; }
.badge-paused, .badge-closed, .badge-inactive { background: #eef1f6; color: #59657b!important; }
.empty { text-align: center; color: var(--muted); padding: 48px 24px; }
.empty.compact { padding: 28px 22px; }
.due { color: var(--primary); font-size: .82rem; font-weight: 700; white-space: nowrap; }
.due.overdue { color: var(--danger); }

.search-bar { display: flex; gap: 10px; margin-bottom: 18px; }
.search-bar input { flex: 1; }
.search-page { margin-bottom: 24px; }
.search-results { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 22px; }
.search-results .search-items { grid-column: 1/-1; overflow: hidden; }
.table-panel { overflow: hidden; }
.responsive-table { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; text-align: left; }
th { background: #f8fafe; color: #68738a; font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; }
th, td { padding: 14px 18px; border-bottom: 1px solid #edf0f5; vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
td small { display: block; margin-top: 3px; color: var(--muted); }

label { display: flex; flex-direction: column; gap: 7px; color: #424d62; font-size: .85rem; font-weight: 650; }
input, select, textarea { width: 100%; border: 1px solid #cad3e0; border-radius: 9px; background: #fff; color: var(--ink); font: inherit; font-weight: 400; padding: 10px 12px; outline: none; transition: border-color .15s, box-shadow .15s; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(21,94,239,.11); }
textarea { resize: vertical; }
.stack-form { display: flex; flex-direction: column; gap: 22px; }
.form-panel { padding: 24px; }
.form-panel > h2 { margin-bottom: 20px; }
.form-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 18px; }
.span-2 { grid-column: span 2; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; }
.compact-form { display: flex; flex-direction: column; align-items: flex-start; gap: 13px; }
.compact-form .inline-fields { align-items: flex-end; width: 100%; }
.inline-fields label { flex: 1; }
label small { color: var(--muted); font-weight: 400; }
.intake-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 22px; }
.intake-block { display: flex; flex-direction: column; gap: 16px; }
.intake-block h2 { margin-bottom: 5px; }
.intake-block p { margin-bottom: 0; }
.paste-zone { border: 1.5px dashed #a9b9d2; border-radius: 12px; background: #f8faff; min-height: 90px; padding: 18px; display: grid; place-items: center; align-content: center; text-align: center; color: var(--primary); cursor: text; outline: none; }
.paste-zone:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(21,94,239,.11); }
.paste-zone span { color: var(--muted); font-size: .8rem; }
.file-button { width: max-content; }
.upload-previews, .attachment-grid { display: grid; grid-template-columns: repeat(auto-fill,minmax(110px,1fr)); gap: 10px; width: 100%; }
.upload-previews > div { min-width: 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #fff; position: relative; }
.upload-previews img, .attachment-grid img { width: 100%; height: 88px; object-fit: cover; display: block; background: #edf1f7; }
.upload-previews span, .attachment-grid span { display: block; padding: 6px 8px; color: var(--muted); font-size: .72rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-previews button { position: absolute; top: 4px; right: 4px; border: 0; border-radius: 99px; width: 25px; height: 25px; background: rgba(20,29,45,.78); color: #fff; cursor: pointer; }
.items-workspace { overflow: hidden; }
.items-workspace > .panel-heading { padding: 0 0 18px; }
.item-editor-scroll { margin: 18px -24px -24px; }
.items-editor { min-width: 1740px; }
.items-editor th, .items-editor td { padding: 10px; }
.items-editor th:first-child, .items-editor td:first-child { padding-left: 20px; }
.items-editor td { background: #fff; }
.items-editor input, .items-editor textarea { min-width: 105px; padding: 8px; margin-bottom: 6px; }
.items-editor textarea { min-width: 180px; }
.items-editor output { display: block; min-width: 80px; font-weight: 700; color: var(--primary); }
.rule-note.left { text-align: left; margin: 38px 0 0; }
.quote-materials { margin-bottom: 22px; }
.material-card { overflow: hidden; }
.material-card .panel-heading > div { display: flex; flex-direction: column; }
.material-card .panel-heading span { color: var(--muted); font-size: .8rem; }
.material-text { padding: 18px 22px; margin: 0; }
.attachment-grid { padding: 0 22px 20px; }
.attachment-grid a { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; min-width: 0; }

.alert { padding: 12px 15px; border-radius: 10px; margin-bottom: 20px; background: #e7f6f0; color: #126648; border: 1px solid #bfe8d8; }
.alert-error { background: #ffedf0; color: #a2243b; border-color: #f5c8d0; }
.alert-warning { background: #fff7df; color: #765400; border-color: #ecd899; }
.notes-panel { padding: 22px; margin-bottom: 22px; }
.notes-panel h2 { margin-bottom: 10px; }
.preline { white-space: pre-line; margin-bottom: 0; }
.company-grid .panel { overflow: hidden; }
.company-summary-grid { display: grid; grid-template-columns: minmax(0,.8fr) minmax(0,1.2fr); gap: 22px; margin-bottom: 22px; }
.company-summary-grid .notes-panel { margin: 0; }
.quick-action { padding: 22px; }
.quick-action h2 { margin-bottom: 15px; }
.cards-list { padding: 4px 22px; }
.contact-card { padding: 16px 0; border-bottom: 1px solid #edf0f5; display: flex; flex-direction: column; gap: 3px; }
.contact-card:last-child { border: 0; }
.contact-card span, .contact-card small { color: var(--muted); font-size: .86rem; }
.count { display: inline-grid; place-items: center; min-width: 27px; height: 27px; padding: 0 7px; border-radius: 99px; background: #eef2f8; color: #5a657a; }
.inline-details { border-top: 1px solid var(--line); padding: 15px 22px; }
.inline-details summary { color: var(--primary); font-weight: 650; cursor: pointer; }
.inline-details[open] summary { margin-bottom: 16px; }

.quotes-panel { margin-bottom: 22px; overflow: hidden; }
.template-panel { margin-bottom: 22px; overflow: hidden; }
.template-panel .panel-heading > div { min-width: 0; }
.template-panel .panel-heading p { margin: 4px 0 0; font-size: .82rem; }
.template-list { display: grid; gap: 1px; background: var(--line); }
.template-card { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 16px 22px; background: #fff; }
.template-card-main { display: grid; gap: 3px; min-width: 0; }
.template-card-main > div { display: flex; align-items: center; flex-wrap: wrap; gap: 7px; }
.template-card-main > span { overflow-wrap: anywhere; }
.template-card-main small { color: var(--muted); }
.template-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 7px; }
.template-actions form { margin: 0; }
.template-replace { min-width: 8rem; border: 0; padding: 0; }
.template-replace .compact-form { min-width: min(22rem,75vw); padding-top: 4px; }
.template-upload-form { max-width: 48rem; }
.template-upload-form .form-grid { width: 100%; }
.checkbox-line { display: flex; flex-direction: row; align-items: center; gap: 7px; }
.checkbox-line input { width: auto; }
.button-danger { border-color: #f5c8d0; color: #a2243b; background: #fff7f8; }
.quote-card { border-bottom: 1px solid var(--line); }
.quote-card:last-child { border-bottom: 0; }
.quote-card-head { display: flex; justify-content: space-between; gap: 20px; padding: 18px 22px; color: var(--ink); }
.quote-card-head:hover { background: #f9fbfe; }
.quote-card-head > div { display: flex; flex-direction: column; gap: 4px; }
.quote-card-head span, .quote-card-head small { font-size: .84rem; color: var(--muted); }
.quote-items-preview { display: grid; grid-template-columns: repeat(auto-fit,minmax(190px,1fr)); gap: 1px; background: var(--line); border-top: 1px solid var(--line); }
.quote-items-preview > div { display: flex; flex-direction: column; padding: 12px 22px; background: #fbfcfe; min-width: 0; }
.quote-items-preview span, .quote-items-preview small { font-size: .8rem; color: var(--muted); overflow-wrap: anywhere; }

.timeline { padding: 20px 22px; }
.timeline-panel { margin-top: 22px; overflow: hidden; }
.timeline-item { display: grid; grid-template-columns: 14px 1fr; gap: 9px; padding-bottom: 19px; position: relative; }
.timeline-item:last-child { padding-bottom: 0; }
.timeline-item i { width: 9px; height: 9px; margin-top: 6px; border-radius: 50%; background: var(--primary); box-shadow: 0 0 0 4px #e9f0ff; }
.timeline-contact i { background: var(--success); box-shadow: 0 0 0 4px #e6f6f0; }
.timeline-item:not(:last-child)::before { content: ""; position: absolute; left: 4px; top: 17px; bottom: 3px; border-left: 1px solid #cdd8ea; }
.timeline-item div { display: flex; flex-direction: column; }
.timeline-item small { color: var(--muted); }

.detail-strip { display: grid; grid-template-columns: repeat(5,minmax(0,1fr)); margin-bottom: 22px; overflow: hidden; }
.detail-strip > div { padding: 19px 21px; border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 4px; }
.detail-strip > div:last-child { border-right: 0; }
.detail-strip span { font-size: .77rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.title-row { display: flex; align-items: center; gap: 13px; }
.status-editor { padding: 22px; margin-bottom: 22px; display: grid; grid-template-columns: minmax(220px,.8fr) minmax(420px,1.2fr); gap: 26px; align-items: end; }
.status-editor p { margin: 7px 0 0; font-size: .86rem; }
.status-form { display: grid; grid-template-columns: 1fr 1.4fr auto; align-items: end; gap: 10px; }
.item-card { padding: 20px; margin: 18px 0 0; border: 1px solid var(--line); border-radius: 13px; background: #fbfcfe; }
.item-card-heading { display: flex; justify-content: space-between; margin-bottom: 16px; }
.remove-item { color: var(--danger); }
.remove-item:disabled { opacity: .35; cursor: not-allowed; }
.rule-note { font-size: .86rem; color: var(--muted); text-align: right; margin-top: 14px; }

.login-container { display: grid; place-items: center; min-height: calc(100vh - 55px); padding-top: 30px; }
.login-card { width: min(100%,430px); padding: 34px; background: #fff; border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 24px 70px rgba(28,46,80,.13); }
.login-card h1 { font-size: 1.75rem; margin-bottom: 10px; }
.login-card .muted { margin-bottom: 24px; }

.attention-heading time { color: var(--muted); font-weight: 700; }
.attention-section { margin-bottom: 32px; }
.section-heading { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.attention-overdue .section-heading h2 { color: var(--danger); }
.attention-list { display: flex; flex-direction: column; gap: 14px; }
.attention-card { display: grid; grid-template-columns: minmax(0,1fr) 170px; gap: 18px; padding: 20px 22px; align-items: start; }
.attention-company { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; }
.attention-company h2 { font-size: 1.2rem; }
.attention-company p { display: flex; flex-wrap: wrap; gap: 6px; margin: 5px 0 0; }
.attention-company p span { color: var(--muted); font-size: .83rem; }
.attention-company p span:not(:last-child)::after { content: " ·"; }
.attention-quotes { margin-top: 15px; display: grid; grid-template-columns: minmax(100px,.45fr) repeat(auto-fit,minmax(180px,1fr)); gap: 8px; align-items: stretch; }
.attention-quotes > strong { font-size: .82rem; color: var(--muted); padding: 9px 0; }
.attention-quotes a { display: flex; flex-direction: column; padding: 8px 10px; border: 1px solid var(--line); border-radius: 9px; background: #fafcff; color: var(--ink); }
.attention-quotes a small { color: var(--muted); font-size: .75rem; }
.attention-reminders { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 12px; }
.attention-reminders span { border-radius: 99px; padding: 4px 9px; background: #eef2f8; color: var(--muted); font-size: .78rem; }
.attention-empty { padding: 18px; border: 1px dashed var(--line); border-radius: 12px; }
.called-action { justify-self: end; width: 100%; }
.called-action > summary { list-style: none; width: 100%; }
.called-action > summary::-webkit-details-marker { display: none; }
.called-action[open] { grid-column: 1/-1; justify-self: stretch; border-top: 1px solid var(--line); padding-top: 18px; }
.called-action[open] > summary { display: none; }
.called-action form { display: grid; grid-template-columns: minmax(240px,1.4fr) minmax(210px,.8fr) auto; align-items: end; }
.followup-settings label { width: 100%; }

.ai-index-grid { display: grid; grid-template-columns: minmax(280px,.7fr) minmax(0,1.3fr); gap: 22px; }
.ai-session-list { overflow: hidden; }
.ai-session-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
.ai-session-heading h1 { font-size: clamp(1.5rem,3vw,2.15rem); }
.ai-container { max-width: 1000px; }
.ai-chat { overflow: hidden; }
.ai-messages { min-height: 420px; max-height: 62vh; overflow-y: auto; padding: 24px; display: flex; flex-direction: column; gap: 18px; background: linear-gradient(180deg,#f9fbff,#f5f8fc); }
.ai-message { display: flex; flex-direction: column; align-items: flex-start; max-width: 82%; gap: 5px; }
.ai-message-user { align-self: flex-end; align-items: flex-end; }
.ai-bubble { border: 1px solid var(--line); border-radius: 15px 15px 15px 4px; background: #fff; padding: 13px 15px; box-shadow: 0 5px 16px rgba(30,48,80,.05); max-width: 100%; }
.ai-message-user .ai-bubble { background: #eaf1ff; border-color: #ccdaf5; border-radius: 15px 15px 4px 15px; }
.ai-bubble p:last-child { margin-bottom: 0; }
.ai-message > small { color: var(--muted); font-size: .7rem; }
.ai-message-images { display: grid; grid-template-columns: repeat(auto-fit,minmax(105px,1fr)); gap: 8px; margin-top: 9px; }
.ai-message-images a { display: block; min-width: 0; overflow: hidden; border-radius: 9px; border: 1px solid var(--line); background: #fff; }
.ai-message-images img { display: block; width: 100%; height: 105px; object-fit: cover; }
.document-icon { display: grid!important; place-items: center; min-height: 88px; padding: 12px!important; background: #eef4ff; color: #235abe!important; font-weight: 800; letter-spacing: .06em; }
.ai-message-images .document-icon { height: 105px; }
.ai-message-images span { display: block; padding: 5px 7px; color: var(--muted); font-size: .7rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-options, .match-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 11px; }
.ai-result-list { display: grid; gap: 6px; margin-top: 10px; }
.ai-result-list a { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; color: var(--ink); background: #fafcff; }
.ai-result-list span { color: var(--muted); font-size: .76rem; }
.ai-confirm-action { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.ai-warnings { color: #8b5d00; padding-left: 18px; margin-bottom: 0; font-size: .82rem; }
.ai-composer { padding: 15px 18px; border-top: 1px solid var(--line); background: #fff; }
.ai-composer-options { display: flex; gap: 10px; margin-bottom: 10px; }
.ai-composer-options label { min-width: 180px; }
.ai-composer-row { display: grid; grid-template-columns: 44px 1fr auto; gap: 9px; align-items: end; }
.ai-composer-row textarea { min-height: 48px; max-height: 160px; }
.ai-attach-button { width: 44px; height: 44px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 10px; font-size: 1.35rem; cursor: pointer; color: var(--primary); }
.ai-composer-hint { font-size: .72rem; margin: 8px 0 0 53px; }
.ai-upload-previews { grid-template-columns: repeat(auto-fill,minmax(90px,110px)); margin-bottom: 10px; }
.ai-completed { padding: 22px; text-align: center; color: var(--muted); border-top: 1px solid var(--line); }
.review-decisions { display: grid; gap: 12px; margin-bottom: 22px; }
.review-decisions > h2 { margin-bottom: 2px; }
.match-decision { padding: 16px 18px; display: flex; align-items: center; justify-content: space-between; gap: 18px; border-color: #ead69a; background: #fffdf5; }
.match-decision p { margin: 5px 0 0; }
.match-actions { margin: 0; flex-shrink: 0; }
.confidence { display: inline-flex; width: max-content; padding: 4px 8px; border-radius: 99px; font-size: .71rem; font-weight: 800; }
.confidence-high { color: #126648; background: #e5f6ef; }
.confidence-medium { color: #765400; background: #fff2c9; }
.confidence-low, .confidence-none { color: #a2243b; background: #ffeaed; }
.ai-review-table { min-width: 2050px; }
.calculator-panel > .panel-heading { padding: 0 0 18px; margin-bottom: 18px; }
.calculator-panel > .panel-heading p { margin: 5px 0 0; }
.calculator-inputs { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 14px; }
.calculator-summary { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 1px; margin-top: 18px; overflow: hidden; border: 1px solid var(--line); border-radius: 11px; background: var(--line); }
.calculator-summary span { display: flex; flex-direction: column; padding: 12px; background: #f8faff; color: var(--muted); font-size: .75rem; }
.calculator-summary strong { color: var(--ink); font-size: 1.05rem; }
.calculation-cell { min-width: 175px; }
.calculation-result, .calculation-breakdown { display: grid; gap: 4px; }
.calculation-result span, .calculation-breakdown span { display: flex; justify-content: space-between; gap: 10px; color: var(--muted); font-size: .76rem; }
.calculation-result strong, .calculation-breakdown b { color: var(--ink); }
.calculation-final { margin-top: 4px; padding-top: 5px; border-top: 1px solid var(--line); }
.calculation-final strong { color: var(--primary); font-size: .95rem; }
.calculation-cell details { margin-top: 8px; }
.calculation-cell summary { color: var(--primary); cursor: pointer; font-size: .75rem; }
.calculation-breakdown { margin-top: 6px; }
.calculation-detail-panel { margin-bottom: 22px; overflow: hidden; }
.calculation-detail-panel .panel-heading > div p { margin: 4px 0 0; }
.calculation-detail-grid { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 1px; background: var(--line); }
.calculation-detail-grid > span { display: flex; flex-direction: column; padding: 14px 18px; background: #fff; color: var(--muted); font-size: .78rem; }
.calculation-detail-grid strong { color: var(--ink); font-size: .95rem; }
.ai-review-table .review-needs_confirmation td { background: #fffdf5; }
.ai-review-table .review-unmatched td, .ai-review-table .review-rejected td { background: #fcfcfd; }
.field-missing { border-style: dashed; border-color: #d6a934; background: #fffdf5; }
.review-required { display: inline-flex; margin-top: 6px; padding: 3px 7px; border-radius: 6px; color: #765400; background: #fff2c9; font-size: .7rem; font-weight: 750; }
.field-error { color: var(--danger); }
.provenance-links { display: flex; flex-direction: column; gap: 5px; min-width: 150px; font-size: .75rem; }
.button:disabled { opacity: .5; cursor: not-allowed; }

@media(max-width:760px) {
  .topbar { min-height: 62px; padding: 12px 16px; align-items: flex-start; flex-wrap: wrap; }
  .brand span:last-child { display: none; }
  .topbar nav { gap: 12px; flex-wrap: wrap; justify-content: flex-end; font-size: .86rem; }
  .global-search { order: 3; width: 100%; margin: 10px 0 0; }
  .container { padding: 30px 15px 55px; }
  .page-heading { align-items: flex-start; flex-direction: column; }
  .page-heading > .button { width: 100%; }
  .stats-grid, .dashboard-grid, .company-grid, .company-summary-grid, .search-results, .intake-grid, .form-grid, .detail-strip, .status-editor, .status-form, .ai-index-grid, .calculator-inputs { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .detail-strip > div { border-right: 0; border-bottom: 1px solid var(--line); }
  .detail-strip > div:last-child { border-bottom: 0; }
  .search-bar { flex-wrap: wrap; }
  .search-bar input { flex-basis: 100%; }
  .responsive-table { overflow: visible; }
  table, thead, tbody, tr, th, td { display: block; }
  thead { display: none; }
  tr { padding: 10px 14px; border-bottom: 1px solid var(--line); }
  tr:last-child { border-bottom: 0; }
  td { border: 0; padding: 7px 4px; display: grid; grid-template-columns: minmax(105px,36%) 1fr; gap: 10px; }
  td::before { content: attr(data-label); color: var(--muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; }
  .list-row { padding: 14px 16px; align-items: flex-start; }
  .align-right { flex-shrink: 0; }
  .form-panel, .quick-action, .status-editor { padding: 18px; }
  .item-card { padding: 15px; }
  .login-card { padding: 26px 22px; }
  .form-actions { flex-direction: column-reverse; }
  .form-actions .button, .heading-actions, .heading-actions .button, .status-form .button { width: 100%; }
  .quote-card-head { padding: 15px 16px; align-items: flex-start; }
  .template-card { align-items: stretch; flex-direction: column; padding: 15px 16px; }
  .template-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .template-actions > *, .template-actions .button { width: 100%; }
  .quote-items-preview { grid-template-columns: 1fr; }
  .file-button { width: 100%; }
  .item-editor-scroll { margin: 15px 0 0; }
  .items-editor { min-width: 0; }
  .items-editor tr { padding: 14px 0; }
  .items-editor td:first-child { padding-left: 4px; }
  .items-editor input, .items-editor textarea { min-width: 0; }
  .attention-card { grid-template-columns: 1fr; padding: 17px; }
  .called-action { justify-self: stretch; }
  .called-action[open] { grid-column: auto; }
  .called-action form, .attention-quotes { grid-template-columns: 1fr; }
  .ai-session-heading { align-items: flex-start; flex-direction: column; }
  .ai-session-heading .button { width: 100%; }
  .ai-messages { padding: 15px; min-height: 360px; max-height: none; }
  .ai-message { max-width: 94%; }
  .ai-composer { padding: 12px; }
  .ai-composer-options { display: grid; grid-template-columns: 1fr; }
  .ai-composer-row { grid-template-columns: 42px 1fr; }
  .ai-composer-row .button { grid-column: 1/-1; }
  .ai-composer-hint { margin-left: 0; }
  .match-decision { align-items: flex-start; flex-direction: column; }
  .match-actions, .match-actions form, .match-actions .button { width: 100%; }
  .ai-review-table { min-width: 0; }
  .calculator-summary { grid-template-columns: 1fr 1fr; }
  .calculation-detail-grid { grid-template-columns: 1fr 1fr; }
  .calculation-cell { min-width: 0; }
}
