:root {
  --ink: #15171c;
  --ink-2: #4b5261;
  --ink-3: #7b8292;
  --line: #e1e4ea;
  --line-2: #eef0f4;
  --bg: #f5f6f8;
  --card: #ffffff;
  --accent: #1f4fd8;
  --accent-ink: #ffffff;
  --accent-soft: #eaf0ff;
  --good: #14734a;
  --good-soft: #e4f5ec;
  --warn: #8a5a00;
  --warn-soft: #fff3d6;
  --bad: #b3261e;
  --bad-soft: #fdeceb;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.5 var(--font); color: var(--ink); background: var(--bg); }
h1 { font-size: 1.6rem; line-height: 1.2; margin: 0 0 .25rem; letter-spacing: -.01em; text-wrap: balance; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
h3 { font-size: .95rem; margin: 1.25rem 0 .5rem; }
p { margin: 0 0 .75rem; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
[hidden] { display: none !important; }
.muted { color: var(--ink-3); }
.small { font-size: .85rem; }
.pre { white-space: pre-line; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.bad-text { color: var(--bad); }
code { font: 600 1.05rem ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--line-2); padding: .2rem .5rem; border-radius: 6px; }

/* ---------- layout ---------- */
.topbar { display: flex; align-items: center; gap: 1.5rem; padding: 0 1.25rem; min-height: 56px; background: var(--ink); color: #fff; flex-wrap: wrap; }
.topbar a { color: #cfd4de; }
.topbar .brand { display: flex; align-items: center; gap: .6rem; color: #fff; font-weight: 650; padding: .5rem 0; }
.topbar .brand img { height: 28px; width: auto; background: #fff; border-radius: 4px; padding: 2px; }
.topbar nav { display: flex; gap: .25rem; flex: 1; flex-wrap: wrap; }
.topbar nav a { padding: .4rem .7rem; border-radius: 6px; }
.topbar nav a:hover { background: #2a2e37; text-decoration: none; }
.topbar nav a[aria-current] { background: #2f3440; color: #fff; }
.topbar .who { display: flex; align-items: center; gap: 1rem; padding: .5rem 0; }
.topbar form { margin: 0; }
button.link { background: none; border: 0; color: #cfd4de; font: inherit; cursor: pointer; padding: 0; }
button.link:hover { text-decoration: underline; }

main { max-width: 1040px; margin: 0 auto; padding: 1.5rem 1.25rem 5rem; }
main.wide { max-width: 1280px; }
body.centered main { display: grid; place-items: center; min-height: 100vh; padding-bottom: 1.5rem; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.page-head p { margin: 0; }
.back { display: inline-block; font-size: .85rem; margin-bottom: .35rem; color: var(--ink-3); }
.actions { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.actions.left { margin-top: 1rem; }
form.inline { display: inline-flex; gap: .5rem; margin: 0; }
.grid { display: grid; gap: 0 1rem; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.grid.four { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.grid.align-end { align-items: end; }
.grid > section.card { margin-bottom: 1rem; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1rem; }
.card.flush { padding: 0; overflow: hidden; }
.card.narrow { width: 100%; max-width: 440px; margin-inline: auto; }
.card.empty { text-align: center; padding: 2.5rem 1.25rem; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; flex-wrap: wrap; margin-bottom: .5rem; }
details.card > summary { cursor: pointer; list-style: none; }
details.card > summary h2 { display: inline; margin: 0; }
details.card > summary::before { content: "▸ "; color: var(--ink-3); }
details.card[open] > summary::before { content: "▾ "; }
details.card[open] > summary { margin-bottom: 1rem; }
.login-logo { max-height: 56px; max-width: 220px; margin-bottom: 1rem; }

/* ---------- buttons, pills, messages ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; font: 600 .92rem var(--font); padding: .55rem .95rem; border-radius: 8px;
  border: 1px solid var(--line); background: #fff; color: var(--ink); cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--line-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #1a43b8; }
.btn.danger { color: var(--bad); border-color: #efc4c1; }
.btn.danger:hover { background: var(--bad-soft); }
.btn.small { padding: .35rem .7rem; font-size: .85rem; }
.btn.big { padding: .8rem 1.4rem; font-size: 1rem; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.icon { border: 1px solid transparent; background: none; color: var(--ink-3); cursor: pointer; border-radius: 6px; width: 28px; height: 28px; font-size: .9rem; }
button.icon:hover:not(:disabled) { background: var(--line-2); color: var(--ink); }
button.icon:disabled { opacity: .3; cursor: default; }

.pill { display: inline-block; font-size: .75rem; font-weight: 650; padding: .15rem .55rem; border-radius: 99px; background: var(--line-2); color: var(--ink-2); vertical-align: middle; white-space: nowrap; }
.pill.pending { background: var(--warn-soft); color: var(--warn); }
.pill.issued { background: var(--accent-soft); color: var(--accent); }
.pill.accepted { background: var(--good-soft); color: var(--good); }
.pill.declined, .pill.cancelled, .pill.expired { background: var(--line-2); color: var(--ink-2); }

.flash { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid; }
.flash.good { background: var(--good-soft); border-color: #bfe5d0; color: var(--good); }
.flash.bad { background: var(--bad-soft); border-color: #f3c7c4; color: var(--bad); }
.flash.warn { background: var(--warn-soft); border-color: #f0dba2; color: var(--warn); }

/* ---------- forms ---------- */
label.field, div.field { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 1rem; }
.stack > label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 1rem; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
  display: block; width: 100%; font: 400 .95rem var(--font); color: var(--ink); background: #fff; border: 1px solid #cdd2db; border-radius: 8px; padding: .55rem .7rem; margin-top: .3rem; }
textarea { resize: vertical; line-height: 1.45; }
input.short { max-width: 200px; }
input.n { width: 5.5rem; display: inline-block; text-align: right; }
.inline-input { display: flex; align-items: center; gap: .4rem; font-weight: 400; }
.check { display: flex; gap: .55rem; align-items: baseline; font-weight: 400; font-size: .95rem; margin: .45rem 0; }
.check input { flex: none; transform: translateY(1px); }
.indent { margin-left: 1.6rem; }
.req { color: var(--bad); }
.err { display: block; color: var(--bad); font-size: .85rem; font-weight: 600; margin-top: .3rem; }
.invalid input, .invalid textarea { border-color: var(--bad); }
.hint { display: block; font-weight: 400; font-size: .85rem; color: var(--good); margin-top: .3rem; min-height: 1.2em; }
.hint.warn { color: var(--warn); }
.hint.muted { color: var(--ink-3); }
fieldset.plain { border: 0; padding: 0; margin: 0; min-width: 0; }
.row-form { display: flex; gap: .5rem; }
.row-form input { margin: 0; }
.filters { display: flex; gap: .75rem; align-items: center; margin-bottom: 1rem; flex-wrap: wrap; }
.filters input[type=search], .filters select { margin: 0; width: auto; min-width: 240px; }
.tabs { display: flex; gap: .25rem; flex-wrap: wrap; flex: 1; }
.tabs a { padding: .35rem .7rem; border-radius: 99px; color: var(--ink-2); font-weight: 600; font-size: .88rem; }
.tabs a[aria-current] { background: var(--ink); color: #fff; }
.tabs .count { opacity: .65; font-weight: 500; }
.sticky-actions { position: sticky; bottom: 0; display: flex; gap: .5rem; align-items: center; padding: .75rem 1rem; background: rgba(255, 255, 255, .95); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 -4px 16px rgba(20, 23, 28, .06); flex-wrap: wrap; margin-bottom: 1rem; }
.spacer { flex: 1; }
.creds { display: grid; grid-template-columns: auto 1fr; gap: .5rem 1rem; align-items: center; margin: 1rem 0; }
.creds dt { color: var(--ink-3); } .creds dd { margin: 0; font-weight: 600; }
.logo-row { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; margin-top: .4rem; font-weight: 400; }
.logo-preview { max-height: 60px; max-width: 220px; border: 1px solid var(--line); border-radius: 6px; padding: 4px; background: #fff; }

/* condition and formula editors */
.cond-row { display: flex; gap: .6rem; align-items: flex-start; flex-wrap: wrap; padding: .6rem 0; border-top: 1px solid var(--line-2); }
.cond-row:first-of-type { border-top: 0; }
.cond-row select, .cond-row input { margin: 0; width: auto; max-width: 100%; }
.cond-row .cond-q { flex: 1 1 260px; }
.cond-options { display: flex; flex-wrap: wrap; gap: .1rem 1.1rem; }
.cond-options .check { margin: .3rem 0; }
fieldset.formula { border: 1px solid var(--line); border-radius: 8px; padding: .75rem 1rem 1rem; margin: 0 0 1rem; min-width: 0; }
fieldset.formula legend { font-weight: 650; padding: 0 .4rem; }
.formula-row { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.formula-row input { margin: 0; }
.formula-qs { margin-top: .5rem; max-height: 180px; overflow: auto; }
.opt-row { margin-bottom: .4rem; }
.opt-row input { margin: 0; }

/* ---------- tables ---------- */
.table-scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
table.list th { text-align: left; font-size: .76rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); font-weight: 650; padding: .7rem 1rem; border-bottom: 1px solid var(--line); background: #fafbfc; white-space: nowrap; }
table.list th.num { text-align: right; }
table.list td { padding: .75rem 1rem; border-bottom: 1px solid var(--line-2); vertical-align: top; }
table.list tr:last-child td { border-bottom: 0; }
table.list.compact td, table.list.compact th { padding: .5rem .75rem; }
table.list tr.off td { opacity: .5; }
.row-actions { white-space: nowrap; text-align: right; }
.row-actions form { margin: 0; display: inline-flex; }

/* ---------- questionnaire ---------- */
.builder.with-estimate { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 1.25rem; align-items: start; }
fieldset.q { border: 0; padding: 0; margin: 0 0 1.4rem; min-width: 0; }
fieldset.q:last-child { margin-bottom: 0; }
fieldset.q legend { font-weight: 650; padding: 0; margin-bottom: .35rem; font-size: 1rem; }
fieldset.q .help { color: var(--ink-3); font-size: .88rem; margin: 0 0 .5rem; }
.choices { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: .25rem; }
.choice { position: relative; cursor: pointer; }
.choice input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.choice span { display: block; padding: .6rem 1rem; border: 1.5px solid #cdd2db; border-radius: 10px; background: #fff; font-weight: 550; }
.choice span small { display: block; font-weight: 400; color: var(--ink-3); font-size: .82rem; }
.choice:hover span { border-color: var(--ink-3); }
.choice input:checked + span { border-color: var(--accent); background: var(--accent-soft); color: #173aa3; box-shadow: inset 0 0 0 1px var(--accent); }
.choice input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.submit-row { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; margin-top: .5rem; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.tile { display: flex; flex-direction: column; gap: .4rem; align-items: flex-start; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; color: var(--ink); }
.tile:hover { border-color: var(--accent); text-decoration: none; }
.tile strong { font-size: 1.05rem; } .tile span { color: var(--ink-3); font-size: .9rem; }

.estimate { position: sticky; top: 1rem; max-height: calc(100vh - 2rem); overflow: auto; }
.est-group { display: flex; justify-content: space-between; gap: 1rem; font-weight: 650; margin-top: .8rem; font-variant-numeric: tabular-nums; }
.est-lines { list-style: none; margin: .15rem 0 0; padding: 0; color: var(--ink-3); font-size: .85rem; }
.est-row, .est-total { display: flex; justify-content: space-between; gap: 1rem; font-variant-numeric: tabular-nums; }
.est-row { margin-top: .6rem; color: var(--ink-2); }
.est-total { margin: 1rem 0 .75rem; padding-top: .8rem; border-top: 2px solid var(--ink); align-items: baseline; }
.est-total strong { font-size: 1.5rem; letter-spacing: -.01em; }

/* ---------- staff quote editor ---------- */
dl.brief { display: grid; grid-template-columns: minmax(120px, 40%) 1fr; gap: .35rem 1rem; margin: 0; font-size: .92rem; }
dl.brief dt { color: var(--ink-3); } dl.brief dd { margin: 0; }
table.lines-edit th { text-align: left; font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); padding: .3rem .25rem; white-space: nowrap; }
table.lines-edit th.num { text-align: right; }
table.lines-edit td { padding: .15rem .2rem; }
table.lines-edit input { margin: 0; padding: .38rem .5rem; font-size: .88rem; border-radius: 6px; min-width: 7rem; }
table.lines-edit input.desc { min-width: 15rem; }
table.lines-edit input.bundle { min-width: 11rem; }
table.lines-edit input.n { width: 4.2rem; min-width: 0; }
table.lines-edit input.n.wide { width: 6rem; }
table.lines-edit input.u { width: 4.5rem; min-width: 0; }
table.lines-edit td.total { padding-left: .75rem; min-width: 6.5rem; font-size: .9rem; }

/* ---------- the quote document ---------- */
.doc { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 2.5rem; max-width: 900px; margin: 0 auto; }
.doc h2 { font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); margin: 0 0 .4rem; }
.doc section { margin-bottom: 1.5rem; }
.doc-head { display: flex; justify-content: space-between; gap: 2rem; align-items: flex-start; margin-bottom: 2rem; flex-wrap: wrap; }
.doc-head h1 { font-size: 1.9rem; text-transform: uppercase; letter-spacing: .06em; margin-top: .75rem; }
.doc-logo { max-height: 64px; max-width: 260px; display: block; }
.doc-company { font-weight: 700; font-size: 1.15rem; }
.doc-meta { display: grid; grid-template-columns: auto auto; gap: .2rem 1rem; margin: 0; font-size: .92rem; }
.doc-meta dt { color: var(--ink-3); text-transform: uppercase; font-size: .72rem; letter-spacing: .06em; align-self: center; }
.doc-meta dd { margin: 0; font-weight: 600; }
.doc-brief dl { display: grid; grid-template-columns: minmax(140px, 34%) 1fr; gap: .3rem 1rem; margin: 0; font-size: .92rem; }
.doc-brief dt { color: var(--ink-2); } .doc-brief dd { margin: 0; }
.doc-wait { background: var(--warn-soft); border-radius: 8px; padding: 1.25rem; }
.doc-wait h2 { color: var(--warn); }
table.doc-lines { margin-bottom: 1.5rem; font-size: .92rem; }
table.doc-lines tr.grp th { text-align: left; padding: 1.1rem .5rem .4rem; border-bottom: 2px solid var(--ink); font-size: 1rem; }
table.doc-lines tr.grp th.num { text-align: right; }
table.doc-lines tr.grp th.num:nth-child(2) { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); font-weight: 600; }
table.doc-lines td { padding: .4rem .5rem; border-bottom: 1px solid var(--line-2); vertical-align: top; }
table.doc-lines td:first-child { width: 58%; }
table.doc-lines .note { color: var(--ink-3); font-size: .85rem; }
table.doc-totals { width: auto; margin: 1rem 0 1.5rem auto; min-width: 320px; }
table.doc-totals td { padding: .35rem .5rem; }
table.doc-totals input { margin: 0 .2rem; }
table.doc-totals tr.grand td { border-top: 2px solid var(--ink); font-weight: 700; font-size: 1.2rem; padding-top: .6rem; }
.doc-terms p { font-size: .82rem; color: var(--ink-2); }
.doc-foot { border-top: 1px solid var(--line); padding-top: 1rem; margin-top: 2rem; text-align: center; font-size: .78rem; color: var(--ink-3); }

@media (max-width: 860px) {
  .builder.with-estimate { grid-template-columns: 1fr; }
  .estimate { position: static; max-height: none; order: 2; }
  .doc { padding: 1.25rem; }
  .topbar { gap: .5rem 1rem; }
  table.doc-totals { min-width: 0; width: 100%; }
}

@media print {
  @page { margin: 14mm; }
  body { background: #fff; font-size: 11pt; }
  .no-print, .topbar, .flash { display: none !important; }
  main, main.wide { max-width: none; padding: 0; }
  .doc { border: 0; padding: 0; max-width: none; }
  table.doc-lines tbody { break-inside: auto; }
  table.doc-lines tr { break-inside: avoid; }
  table.doc-lines tr.grp { break-after: avoid; }
  .doc-terms { break-inside: avoid; }
}
