:root {
  --bg: #f5f6f8; --card: #fff; --ink: #1d232b; --muted: #6b7480; --line: #dfe3e8;
  --accent: #177a73; --accent-ink: #fff; --ok: #2b8a3e; --warn: #b7791f; --bad: #c92a2a;
  --radius: 10px; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.04);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); line-height: 1.45; }
a { color: var(--accent); }
main { max-width: 980px; margin: 0 auto; padding: 24px 16px 48px; }
main.wide { max-width: 1240px; }
h1 { font-size: 1.7rem; margin: .2em 0 .5em; }
h2 { font-size: 1.15rem; margin: 0 0 .6em; }
h3 { font-size: 1rem; margin: 1em 0 .4em; }
.lead { font-size: 1.08rem; color: #3b4450; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.pre { white-space: pre-wrap; }
.error { color: var(--bad); font-weight: 600; min-height: 1em; }
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 10px 20px; background: #1d232b; color: #fff; flex-wrap: wrap; gap: 8px; }
.topbar a { color: #fff; text-decoration: none; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.brand .logo { height: 34px; width: auto; display: block; }
.doc-logo { height: 76px; width: auto; display: block; margin-bottom: 6px; }
.mark { background: var(--accent); color: #fff; padding: 3px 7px; border-radius: 6px; letter-spacing: .04em; font-size: .9rem; }
.nav { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.nav a { opacity: .9; } .nav a:hover { opacity: 1; text-decoration: underline; }
.foot { text-align: center; color: var(--muted); font-size: .85rem; padding: 24px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); margin-bottom: 18px; }
.card.inset { box-shadow: none; background: #fafbfc; }
.card.narrow { max-width: 380px; margin: 40px auto; }
.cards.two { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 18px; }
.card.big { display: block; text-decoration: none; color: inherit; transition: transform .1s; }
.card.big:hover { transform: translateY(-2px); border-color: var(--accent); }
.hero { margin: 8px 0 18px; }
.btn { display: inline-block; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 9px 16px; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn:hover { border-color: #b7bec8; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:disabled { opacity: .55; cursor: not-allowed; }
.btn.danger { color: var(--bad); }
button.link { background: none; border: 0; color: inherit; font: inherit; cursor: pointer; padding: 0; text-decoration: underline; }
.card button.link { color: var(--accent); }
form.inline { display: inline; }
label { display: block; font-weight: 600; font-size: .92rem; margin: 0 0 12px; }
label.check { font-weight: 400; display: flex; gap: 8px; align-items: center; }
input, select, textarea { display: block; width: 100%; margin-top: 4px; padding: 8px 10px; border: 1px solid #c8ced6; border-radius: 7px; font: inherit; background: #fff; }
label.check input { width: auto; margin: 0; }
textarea { resize: vertical; }
fieldset { border: 1px solid var(--line); border-radius: 8px; margin: 0 0 12px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0 18px; }
.hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; background: #e7f0ff; }
.flash.ok { background: #e6f6ea; } .flash.warn { background: #fff4e0; }
.staging-banner { background: #7a3e00; color: #fff; text-align: center; font-size: 13px; font-weight: 600; padding: 6px 10px; letter-spacing: .02em; }
.samples { list-style: none; padding: 0; margin: 0; } .samples li { padding: 10px 0; border-bottom: 1px solid var(--line); }
.samples a { font-weight: 600; word-break: break-all; }
.editor fieldset.card { padding: 12px 16px 4px; } .editor legend { font-weight: 700; padding: 0 6px; }
.editor h3 { margin: 10px 0 6px; font-size: .95rem; color: var(--muted); }
.editor small { display: block; font-weight: 400; margin-top: 3px; } .editor small.hint { color: var(--muted); }
.editor label.bad input, .editor label.bad select, .editor label.bad textarea { border-color: var(--bad); }
pre.doc { white-space: pre-wrap; overflow-wrap: anywhere; font: 15px/1.55 system-ui, -apple-system, sans-serif; margin: 0; }
.pill { display: inline-block; padding: 1px 9px; border-radius: 99px; font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; background: #e9ecef; color: #495057; vertical-align: middle; }
.s-new, .s-sent, .s-open { background: #e7f0ff; color: #1c4fa0; }
.s-accepted, .s-paid, .s-quoted { background: #e6f6ea; color: var(--ok); }
.s-declined, .s-void, .s-expired, .s-overdue { background: #fdecec; color: var(--bad); }
.s-draft, .s-review { background: #fff4e0; color: var(--warn); }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .82rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.num { text-align: right; white-space: nowrap; }
table.lines tfoot td { border-bottom: 0; }
table.lines tr.total td, table.paysum tr.total td { font-weight: 800; font-size: 1.05rem; border-top: 2px solid var(--ink); }
table.meta th { text-transform: none; font-size: .9rem; width: 40%; }
table.edit input, table.edit select { margin: 0; padding: 5px 7px; }
.w-full { width: 100%; } .w-num { width: 90px; }
.stats { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 18px; min-width: 130px; }
.stat b { display: block; font-size: 1.6rem; }
.stat span { color: var(--muted); font-size: .85rem; }
.events { list-style: none; padding: 0; margin: 0; } .events li { padding: 4px 0; border-bottom: 1px dashed var(--line); }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.actions form { margin: 0; }
.totals-inline { text-align: right; margin: 8px 0 14px; }
/* print quote */
.print-layout { display: grid; grid-template-columns: 1fr 360px; gap: 18px; align-items: start; }
@media (max-width: 900px) { .print-layout { grid-template-columns: 1fr; } }
.summary { position: sticky; top: 12px; }
.dropzone { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 34px 16px; border: 2px dashed #b9c0ca; border-radius: var(--radius); background: #fff; text-align: center; cursor: pointer; font-weight: 400; }
.dropzone.over { border-color: var(--accent); background: #fff7f2; }
.dropzone input { display: none; }
.item { display: grid; grid-template-columns: 220px 1fr; gap: 16px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-top: 14px; box-shadow: var(--shadow); }
@media (max-width: 640px) { .item { grid-template-columns: 1fr; } }
.item canvas { width: 100%; height: 200px; background: linear-gradient(#eef1f5, #dde2e8); border-radius: 8px; display: block; touch-action: none; }
.item .placeholder { height: 200px; display: flex; align-items: center; justify-content: center; border-radius: 8px; background: #eef1f5; color: var(--muted); text-align: center; padding: 10px; }
.item h3 { margin: 0 0 4px; word-break: break-all; }
.item .opts { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 0 10px; margin-top: 8px; }
.item .opts label { font-size: .82rem; margin-bottom: 8px; }
.item .stats-line { font-size: .88rem; color: var(--muted); }
.item .warn { color: var(--warn); font-size: .88rem; }
.item .remove { float: right; }
#estimate table td { padding: 5px 4px; font-size: .9rem; }
.big-total { font-size: 1.6rem; font-weight: 800; text-align: right; margin: 8px 0; }
.range { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; margin: 12px 0; }
.range strong { font-size: 1.5rem; }
.files { list-style: none; padding: 0; } .files li { padding: 3px 0; }
.attach { margin-bottom: 12px; } .attach input { display: none; }
.viewer-box { margin-top: 12px; } .viewer-box canvas { width: 100%; height: 380px; background: linear-gradient(#eef1f5, #dde2e8); border-radius: 8px; display: block; touch-action: none; }
/* documents */
.doc { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 28px 32px; margin-bottom: 18px; }
.doc-head { display: flex; justify-content: space-between; gap: 24px; flex-wrap: wrap; border-bottom: 3px solid var(--accent); padding-bottom: 14px; margin-bottom: 16px; }
.doc-biz { font-size: 1.3rem; font-weight: 800; }
.doc-kind { text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; }
.doc-number { font-size: 1.4rem; font-weight: 800; }
.doc-meta table.meta th { width: auto; padding-right: 14px; }
.doc-to { margin-bottom: 16px; }
.terms li { font-size: .88rem; color: #3b4450; }
.paid-stamp { font-size: 1.3rem; font-weight: 800; color: var(--ok); }
.accept-box, .pay-box { border-color: var(--accent); }
/* Phones: a wide table scrolls inside its own card instead of widening the page (which made
   mobile browsers zoom the whole admin page out — caught by the 390px smoke pass). */
@media (max-width: 640px) { .card, .doc { overflow-x: auto; } fieldset { min-width: 0; } }
/* Long unbroken file paths (the editors show where the saved copy lives) must wrap, not widen the
   page: at 390px a DATA_DIR path pushed /admin/rates and /admin/business to 431px. Fieldsets default
   to min-width:min-content, which defeats the card's overflow rule above, hence min-width:0. */
code { overflow-wrap: anywhere; }
.print-only { display: none; }
@media print {
  @page { size: letter; margin: 0.6in 0.6in 0.75in;
    @bottom-right { content: "Page " counter(page) " of " counter(pages); font: 9pt system-ui, sans-serif; color: #666; } }
  .print-only { display: block !important; }
  .no-print, .topbar, .foot, .staging-banner, .flash { display: none !important; }
  body { background: #fff; font-size: 11pt; } main { padding: 0; max-width: none; }
  .doc { border: 0; padding: 0; margin: 0; }
  .doc-head, .pill, .paid-stamp { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  table.lines thead { display: table-header-group; }
  table.lines tr, .terms li, .how-to-pay, .doc-to, .accepted-line { break-inside: avoid; }
  .how-to-pay { border: 1px solid #999; border-radius: 6px; padding: 8px 12px; margin: 14px 0; }
}

input[type=checkbox], input[type=radio] { accent-color: var(--accent); }
