:root {
  --ink: #14253b;
  --ink-2: #20364f;
  --paper: #f3f5f7;
  --surface: #ffffff;
  --line: #d8dee5;
  --muted: #66717d;
  --blue: #3f6fae;
  --blue-dark: #315b91;
  --green: #247457;
  --amber: #95650e;
  --red: #a43b3b;
  --radius: 14px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--paper); line-height: 1.5; }
a { color: var(--blue-dark); text-underline-offset: 3px; }
button, input, select, textarea { font: inherit; }

.topbar {
  min-height: 72px;
  padding: 0 4vw;
  display: flex;
  align-items: center;
  gap: 32px;
  color: #fff;
  background: var(--ink);
  border-bottom: 3px solid var(--blue);
}
.brand { display: flex; align-items: baseline; gap: 9px; color: #fff; text-decoration: none; font-weight: 700; letter-spacing: .08em; }
.brand-mark { font-size: 1.22rem; letter-spacing: -.02em; }
.topbar nav { display: flex; gap: 8px; }
.topbar nav a { color: #dfe7ef; text-decoration: none; padding: 8px 11px; border-radius: 7px; }
.topbar nav a:hover { background: #ffffff12; color: #fff; }
.account { margin-left: auto; display: flex; align-items: center; gap: 14px; color: #cbd6e1; font-size: .9rem; }
.account form { margin: 0; }
.link-button { border: 0; padding: 0; color: #fff; background: transparent; text-decoration: underline; cursor: pointer; }

.page { width: min(1180px, 92vw); margin: 0 auto; padding: 46px 0 70px; min-height: calc(100vh - 130px); }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 28px; }
.page-head h1 { margin: 2px 0 4px; font-size: clamp(2rem, 4vw, 3.3rem); line-height: 1.03; letter-spacing: -.04em; }
.page-head p { margin: 0; color: var(--muted); }
.eyebrow { color: var(--blue-dark) !important; text-transform: uppercase; letter-spacing: .13em; font-weight: 750; font-size: .75rem; }
.head-actions { display: flex; align-items: center; gap: 12px; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; }
.panel h2 { margin: 0 0 18px; font-size: 1.25rem; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.section-head h2 { margin: 0; }

.button {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 42px; padding: 9px 16px; border: 1px solid var(--blue);
  border-radius: 8px; color: #fff; background: var(--blue); text-decoration: none;
  font-weight: 700; cursor: pointer;
}
.button:hover { background: var(--blue-dark); }
.button.secondary { color: var(--ink); background: #fff; border-color: var(--line); }
.button.secondary:hover { background: #eef2f6; }
.button.danger { background: var(--red); border-color: var(--red); }

.metrics { display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; margin-bottom: 28px; }
.sales-metrics { grid-template-columns: repeat(4, 1fr); }
.section-block { margin-top: 28px; }
.metric { min-height: 116px; padding: 18px; display: flex; flex-direction: column; justify-content: space-between; background: #fff; border: 1px solid var(--line); border-radius: 11px; text-decoration: none; color: var(--ink); }
.metric:hover { border-color: #9db3ce; transform: translateY(-1px); }
.metric span { color: var(--muted); font-size: .82rem; font-weight: 650; }
.metric strong { font-size: 2.1rem; line-height: 1; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { padding: 11px 12px; color: var(--muted); text-align: left; text-transform: uppercase; letter-spacing: .08em; font-size: .68rem; border-bottom: 1px solid var(--line); }
td { padding: 15px 12px; border-bottom: 1px solid #e8ecf0; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
td small { display: block; margin-top: 3px; color: var(--muted); }
.strong-link { color: var(--ink); font-weight: 750; }

.status { display: inline-flex; padding: 5px 9px; border-radius: 999px; background: #e9eef4; color: #3a526c; font-size: .75rem; font-weight: 750; white-space: nowrap; }
.status-new { background: #e4eef9; color: #245b93; }
.status-qualified, .status-won { background: #dff1e9; color: var(--green); }
.status-quoted { background: #fff0cf; color: var(--amber); }
.status-lost, .status-archived { background: #ececef; color: #5f6268; }
.status-company-customer, .status-company-partner, .status-quote-accepted { background: #dff1e9; color: var(--green); }
.status-company-prospect, .status-quote-draft { background: #e4eef9; color: #245b93; }
.status-company-inactive, .status-quote-rejected, .status-quote-expired, .status-quote-cancelled { background: #ececef; color: #5f6268; }
.status-quote-sent { background: #fff0cf; color: var(--amber); }

.filters { margin-bottom: 20px; display: grid; grid-template-columns: minmax(250px, 1fr) 230px auto; align-items: end; gap: 16px; }
label { display: grid; gap: 7px; color: var(--ink-2); font-size: .84rem; font-weight: 700; }
input, select, textarea { width: 100%; padding: 10px 12px; color: var(--ink); background: #fff; border: 1px solid #bdc7d1; border-radius: 8px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px #3f6fae22; }
textarea { min-height: 130px; resize: vertical; }
form .button { margin-top: 12px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 20px; }
.form-grid .full-span { grid-column: 1 / -1; }
.page-alert { margin-bottom: 20px; }
.field-hint { display: block; color: var(--muted); font-size: .78rem; font-weight: 500; }

.detail-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(270px, .85fr); gap: 20px; align-items: start; }
.detail-grid.lower { margin-top: 20px; }
.facts { display: grid; grid-template-columns: 1fr 1fr; margin: 0 0 24px; border-top: 1px solid var(--line); }
.facts div { padding: 14px 0; border-bottom: 1px solid var(--line); }
.facts div:nth-child(odd) { padding-right: 20px; }
.facts dt { color: var(--muted); text-transform: uppercase; letter-spacing: .07em; font-size: .68rem; }
.facts dd { margin: 4px 0 0; overflow-wrap: anywhere; }
.message { white-space: pre-wrap; background: #f7f9fb; border-left: 3px solid var(--blue); padding: 18px; border-radius: 0 8px 8px 0; }
.detail-side form + form { margin-top: 20px; padding-top: 20px; border-top: 1px solid var(--line); }
.conversion-action { margin-bottom: 20px; padding: 16px; background: #f2f7fc; border: 1px solid #d4e1ef; border-radius: 9px; }
.conversion-action form { margin: 0; }
.conversion-action .button { width: 100%; }
.notes article { padding: 18px 0; border-top: 1px solid var(--line); }
.notes article div { display: flex; justify-content: space-between; gap: 12px; }
.notes article time, .timeline span { color: var(--muted); font-size: .78rem; }
.notes article p { margin: 8px 0 0; white-space: pre-wrap; }
.timeline { margin: 0; padding: 0; list-style: none; }
.timeline li { position: relative; padding: 0 0 18px 18px; border-left: 1px solid var(--line); }
.timeline li::before { content: ''; position: absolute; left: -5px; top: 5px; width: 9px; height: 9px; border-radius: 50%; background: var(--blue); }
.timeline strong, .timeline span { display: block; }
.danger-zone { margin-top: 20px; padding-top: 18px; border-top: 1px solid #e2bcbc; }
.danger-zone summary { color: var(--red); font-weight: 750; cursor: pointer; }
.danger-zone p { color: var(--muted); font-size: .85rem; }
.related-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
.record-list { margin: 0; padding: 0; list-style: none; }
.record-list li + li { border-top: 1px solid var(--line); }
.record-list a { display: grid; gap: 3px; padding: 13px 0; color: var(--ink); text-decoration: none; }
.record-list a:hover strong { color: var(--blue-dark); }
.record-list span { color: var(--muted); font-size: .8rem; }

.quote-summary dl { margin: 0; }
.quote-summary dl div { display: flex; justify-content: space-between; gap: 20px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.quote-summary dt { color: var(--muted); }
.quote-summary dd { margin: 0; font-weight: 700; }
.quote-summary .total { margin-top: 5px; padding-top: 16px; border-top: 2px solid var(--ink); border-bottom: 0; font-size: 1.18rem; }
.quote-summary > a { display: block; margin-top: 10px; }
.quote-items { display: grid; gap: 12px; }
.quote-item-card { padding: 18px; background: #f7f9fb; border: 1px solid var(--line); border-radius: 10px; }
.quote-item-form { display: grid; grid-template-columns: 72px minmax(220px, 2fr) 110px 110px 150px 90px 110px auto; gap: 12px; align-items: end; }
.quote-item-form textarea { min-height: 72px; }
.quote-item-form .button { margin: 0; }
.item-total { display: grid; gap: 6px; align-self: center; }
.item-total span { color: var(--muted); font-size: .72rem; }
.delete-item { margin-top: 8px; text-align: right; }
.danger-link { color: var(--red); }
.quote-item-readonly { display: grid; grid-template-columns: 1fr auto auto; gap: 20px; }
.quote-item-readonly span { color: var(--muted); }
.add-item { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--line); }
.add-item summary { color: var(--blue-dark); font-weight: 750; cursor: pointer; }
.add-form { margin-top: 16px; }

.print-body { background: #e9edf1; }
.print-toolbar { width: min(920px, 94vw); margin: 24px auto 12px; display: flex; align-items: center; justify-content: space-between; gap: 20px; color: var(--muted); font-size: .8rem; }
.quote-document { width: min(920px, 94vw); min-height: 1180px; margin: 0 auto 50px; padding: 62px 68px 46px; background: #fff; box-shadow: 0 12px 35px #14253b18; }
.document-head { display: flex; justify-content: space-between; gap: 30px; padding-bottom: 28px; border-bottom: 3px solid var(--ink); }
.document-head > div { display: grid; align-content: start; }
.document-brand { font-size: 2rem; line-height: 1; letter-spacing: -.04em; }
.document-head address { font-style: normal; text-align: right; font-size: .78rem; color: var(--muted); }
.recipient { display: grid; min-height: 150px; align-content: end; margin-top: 28px; font-size: .88rem; }
.document-title { display: flex; justify-content: space-between; align-items: start; gap: 30px; margin: 45px 0 24px; }
.document-title h1 { margin: 2px 0; font-size: 2rem; line-height: 1.1; }
.document-title dl { min-width: 220px; margin: 0; font-size: .8rem; }
.document-title dl div { display: flex; justify-content: space-between; gap: 15px; padding: 4px 0; }
.document-title dd { margin: 0; font-weight: 650; }
.document-copy, .document-terms p { white-space: pre-wrap; }
.document-items { margin-top: 30px; }
.document-items th:first-child, .document-items td:first-child { width: 55px; }
.document-items th:nth-last-child(-n+2), .document-items td:nth-last-child(-n+2) { text-align: right; }
.document-items td small { display: block; }
.document-totals { display: flex; justify-content: flex-end; margin-top: 22px; }
.document-totals dl { width: 330px; margin: 0; }
.document-totals dl div { display: flex; justify-content: space-between; gap: 30px; padding: 7px 0; }
.document-totals dd { margin: 0; }
.document-totals .grand { margin-top: 6px; padding-top: 12px; border-top: 2px solid var(--ink); font-size: 1.08rem; font-weight: 750; }
.document-terms { margin-top: 45px; }
.document-terms h2 { font-size: 1rem; }
.document-footer { display: flex; justify-content: space-between; gap: 20px; margin-top: 80px; padding-top: 14px; border-top: 1px solid var(--line); color: var(--muted); font-size: .68rem; }

.login-shell { display: grid; grid-template-columns: 1.2fr minmax(330px, .7fr); gap: 8vw; align-items: center; min-height: 65vh; }
.login-copy h1 { max-width: 650px; margin: 6px 0 16px; font-size: clamp(3rem, 7vw, 5.5rem); line-height: .95; letter-spacing: -.06em; }
.login-copy p:last-child { max-width: 570px; color: var(--muted); font-size: 1.08rem; }
.login-form { display: grid; gap: 16px; padding: 30px; }
.login-form h2 { margin-bottom: 2px; }
.alert { margin: 0; padding: 11px 13px; color: #842f2f; background: #f9e5e5; border-radius: 7px; font-size: .86rem; }
.error-page { max-width: 620px; padding: 10vh 0; }
.error-page h1 { margin: 4px 0 12px; font-size: 3rem; }
.error-page p { color: var(--muted); }
.empty, .muted { color: var(--muted); }
.footer { padding: 22px 4vw; color: #667483; background: #e9edf1; font-size: .78rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }

@media (max-width: 900px) {
  .topbar { flex-wrap: wrap; padding-top: 13px; padding-bottom: 10px; }
  .topbar nav { order: 3; flex-basis: 100%; overflow-x: auto; padding-bottom: 2px; }
  .account { margin-left: auto; }
  .metrics { grid-template-columns: repeat(3, 1fr); }
  .detail-grid { grid-template-columns: 1fr; }
  .related-grid { grid-template-columns: 1fr; }
  .quote-item-form { grid-template-columns: 70px 1fr 1fr; }
  .quote-item-form .item-description { grid-column: span 2; }
  .login-shell { grid-template-columns: 1fr; }
  .login-copy h1 { font-size: clamp(2.8rem, 12vw, 4.5rem); }
}

@media (max-width: 680px) {
  .topbar {
    min-height: auto;
    padding: 15px 4vw 11px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px 16px;
  }
  .brand { grid-column: 1; grid-row: 1; }
  .account { grid-column: 2; grid-row: 1; margin-left: 0; }
  .account span { display: none; }
  .topbar nav {
    grid-column: 1 / -1;
    grid-row: 2;
    width: 100%;
    display: grid;
    grid-template-columns: repeat(6, max-content);
    justify-content: start;
    gap: 4px;
    overflow-x: auto;
  }
  .topbar nav a { padding: 7px 10px; }
  .page { padding-top: 30px; }
  .page-head { align-items: flex-start; flex-direction: column; }
  .head-actions { flex-wrap: wrap; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .filters { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .full-span { grid-column: auto; }
  .sales-metrics { grid-template-columns: repeat(2, 1fr); }
  .quote-item-form { grid-template-columns: 1fr 1fr; }
  .quote-item-form .item-description { grid-column: 1 / -1; }
  .quote-document { width: 100%; min-height: 0; margin: 0; padding: 32px 22px; box-shadow: none; }
  .print-toolbar { align-items: flex-start; flex-direction: column; }
  .facts { grid-template-columns: 1fr; }
  .facts div:nth-child(odd) { padding-right: 0; }
  .panel { padding: 18px; }
  th, td { padding-left: 9px; padding-right: 9px; }
}

@media print {
  @page { size: A4; margin: 16mm; }
  .print-body { background: #fff; }
  .print-toolbar { display: none; }
  .quote-document { width: auto; min-height: 0; margin: 0; padding: 0; box-shadow: none; }
  .document-head, .document-title, .document-totals, .document-terms, .document-footer { break-inside: avoid; }
  .document-items tr { break-inside: avoid; }
}
