/* Jobmath: plain, trustworthy, phone-first. Light UI for daylight use on job sites. */
:root {
  --bg: #f3f5f7;
  --surface: #ffffff;
  --ink: #111827;
  --ink-2: #4b5563;
  --ink-3: #6b7280;
  --line: #dde2e8;
  --line-2: #c9d0d8;
  --field: #ffffff;
  --calc: #eef3fd;
  --accent: #1a56db;
  --accent-hover: #1648b8;
  --accent-soft: #e8effc;
  --profit: #0f7b3f;
  --profit-soft: #e7f5ec;
  --loss: #b91c1c;
  --loss-soft: #fdecec;
  --radius: 12px;
  --radius-s: 8px;
  --shadow: 0 1px 2px rgba(17, 24, 39, 0.06), 0 4px 12px rgba(17, 24, 39, 0.05);
  --shadow-lift: 0 2px 4px rgba(17, 24, 39, 0.08), 0 12px 28px rgba(17, 24, 39, 0.1);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --nav-h: 64px;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--font);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
a:hover { color: var(--accent-hover); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
svg.i { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- top bar ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.top-in { max-width: 1180px; margin: 0 auto; padding: 0 20px; height: 60px; display: flex; align-items: center; gap: 24px; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 750; font-size: 20px; letter-spacing: -0.02em; color: var(--ink); text-decoration: none; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); display: grid; place-items: center; }
.brand-mark svg { width: 18px; height: 18px; stroke: #fff; stroke-width: 2.2; fill: none; stroke-linecap: round; }
.tabs { display: flex; gap: 4px; margin-left: auto; }
.tab {
  display: flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 999px;
  color: var(--ink-2); text-decoration: none; font-weight: 600; font-size: 15px;
}
.tab:hover { background: var(--bg); color: var(--ink); }
.tab[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.tab svg.i { width: 19px; height: 19px; }

/* bottom nav on phones */
.bottom { display: none; }
@media (max-width: 759px) {
  .tabs { display: none; }
  .top-in { height: 54px; }
  .bottom {
    display: grid; grid-template-columns: repeat(3, 1fr);
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    height: calc(var(--nav-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: #fff; border-top: 1px solid var(--line);
  }
  .bottom a {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    color: var(--ink-3); text-decoration: none; font-size: 12px; font-weight: 600;
  }
  .bottom a[aria-current="page"] { color: var(--accent); }
  body { padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); }
}

/* ---------- page ---------- */
.page { max-width: 1180px; margin: 0 auto; padding: 32px 20px 64px; }
.page-narrow { max-width: 760px; }
.head { margin: 0 0 24px; }
h1 { font-size: clamp(28px, 4.2vw, 40px); line-height: 1.12; letter-spacing: -0.03em; margin: 0 0 8px; font-weight: 780; text-wrap: balance; }
.lede { color: var(--ink-2); font-size: 17px; margin: 0; max-width: 60ch; }
h2 { font-size: 22px; letter-spacing: -0.02em; margin: 48px 0 12px; line-height: 1.25; }
h3 { font-size: 17px; margin: 28px 0 8px; }
.prose p, .prose li { color: var(--ink-2); max-width: 68ch; }
.prose strong { color: var(--ink); font-weight: 600; }
@media (max-width: 759px) { .page { padding-top: 20px; } }

/* ---------- panels & fields ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel-pad { padding: 20px; }
.panel + .panel { margin-top: 16px; }
.panel-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 15px; font-weight: 700; margin: 0 0 14px; }
.panel-title small { font-weight: 500; color: var(--ink-3); font-size: 14px; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
@media (max-width: 559px) { .grid2, .grid3 { grid-template-columns: 1fr; } .grid2.keep, .grid3.keep { grid-template-columns: 1fr 1fr; } }

label.f { display: block; }
.f > span { display: block; font-size: 14px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
.box { position: relative; display: flex; align-items: center; }
.box .pre, .box .suf { position: absolute; color: var(--ink-3); font-size: 17px; pointer-events: none; }
.box .pre { left: 14px; }
.box .suf { right: 14px; }
input, select, textarea {
  width: 100%; font: inherit; font-size: 17px; color: var(--ink);
  background: var(--field); border: 1.5px solid var(--line-2); border-radius: var(--radius-s);
  min-height: 50px; padding: 12px 14px; transition: border-color 0.15s, background-color 0.25s, box-shadow 0.15s;
}
textarea { min-height: 88px; resize: vertical; line-height: 1.45; }
select { appearance: none; padding-right: 36px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%234b5563' stroke-width='1.8' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; }
.box .pre + input { padding-left: 30px; }
.box input:has(+ .suf) { padding-right: 34px; }
input::placeholder, textarea::placeholder { color: var(--ink-3); font-weight: 400; }
input:hover, select:hover, textarea:hover { border-color: #aeb7c2; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(26, 86, 219, 0.18); }
input[type="color"] { padding: 4px; width: 56px; min-height: 50px; cursor: pointer; }
input[type="date"] { min-height: 50px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px; border-radius: 10px; border: 1.5px solid transparent;
  font: inherit; font-weight: 650; font-size: 16px; cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background-color 0.15s, border-color 0.15s, transform 0.1s var(--ease);
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); color: #fff; }
.btn-ghost { background: #fff; color: var(--ink); border-color: var(--line-2); }
.btn-ghost:hover { background: var(--bg); color: var(--ink); }
.btn-quiet { background: transparent; color: var(--accent); padding: 0 10px; min-height: 44px; }
.panel-pad > .btn-quiet:first-child, .hint + .btn-quiet { margin-left: -10px; }
.btn-quiet:hover { background: var(--accent-soft); }
.btn-block { width: 100%; }
.btn svg.i { width: 19px; height: 19px; }
.icon-btn {
  width: 44px; height: 44px; display: grid; place-items: center; border-radius: 10px; border: 0;
  background: transparent; color: var(--ink-3); cursor: pointer; flex: none;
}
.icon-btn:hover { background: var(--loss-soft); color: var(--loss); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
@media (max-width: 559px) { .chips { display: grid; grid-template-columns: repeat(3, 1fr); } }
.chip {
  min-height: 44px; padding: 0 14px; border-radius: 999px; border: 1.5px solid var(--line-2);
  background: #fff; font: inherit; font-size: 15px; font-weight: 600; color: var(--ink-2); cursor: pointer;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }

.seg { display: inline-flex; background: #e8ecf0; border-radius: 10px; padding: 3px; gap: 2px; }
.seg button {
  border: 0; background: transparent; font: inherit; font-size: 15px; font-weight: 600; color: var(--ink-2);
  min-height: 44px; padding: 0 18px; border-radius: 8px; cursor: pointer;
}
.seg button[aria-pressed="true"] { background: #fff; color: var(--ink); box-shadow: var(--shadow); }

/* ---------- calculator ---------- */
.calc { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 20px; align-items: start; }
@media (max-width: 859px) { .calc { grid-template-columns: 1fr; } }
.calc-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 14px; }
@media (max-width: 419px) { .calc-fields { gap: 14px 10px; } }
.calc-fields input { font-size: 22px; font-weight: 650; min-height: 60px; }
.calc-fields .box .pre, .calc-fields .box .suf { font-size: 20px; }
.calc-fields input.is-calc { background: var(--calc); border-color: #c7d6f5; }
.f .tag { font-size: 12px; font-weight: 600; font-style: normal; color: var(--accent); margin-left: 6px; visibility: hidden; }
.f.is-calc .tag { visibility: visible; }
.hint { font-size: 14px; color: var(--ink-3); margin: 14px 0 0; min-height: 21px; }
.hint.err { color: var(--loss); }

.result { padding: 22px; }
.result-top { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.result-label { font-size: 14px; font-weight: 600; color: var(--ink-2); }
.big { font-size: clamp(40px, 7vw, 56px); font-weight: 780; letter-spacing: -0.035em; line-height: 1.05; margin: 6px 0 4px; transition: color 0.2s; }
.big.pos { color: var(--profit); }
.big.neg { color: var(--loss); }
.stat-row { display: grid; grid-template-columns: repeat(2, 1fr); border-top: 1px solid var(--line); margin-top: 18px; }
.stat { padding: 14px 0 0; }
.stat + .stat { padding-left: 16px; border-left: 1px solid var(--line); }
.stat b { display: block; font-size: 24px; letter-spacing: -0.02em; }
.stat span { font-size: 14px; color: var(--ink-2); }
.formula { margin-top: 18px; padding: 12px 14px; background: var(--bg); border-radius: var(--radius-s); font-size: 15px; color: var(--ink-2); line-height: 1.6; }
.formula b { color: var(--ink); font-weight: 600; }

table.t { width: 100%; border-collapse: collapse; font-size: 16px; }
table.t th, table.t td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line); }
table.t th { font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-3); font-weight: 650; background: #f8fafb; }
table.t td.n, table.t th.n { text-align: right; }
table.t tr:last-child td { border-bottom: 0; }
table.t tbody tr:hover td { background: #f8fafb; }
.t-wrap { overflow: hidden; border-radius: var(--radius); border: 1px solid var(--line); background: #fff; }

.next { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: 48px; padding: 20px 22px; }
.next p { margin: 0; color: var(--ink-2); }
.next b { display: block; color: var(--ink); font-size: 17px; margin-bottom: 2px; }
@media (max-width: 559px) { .next { flex-direction: column; align-items: stretch; } }

/* ---------- builder (quote + invoice) ---------- */
.builder { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 24px; align-items: start; }
.builder-side { position: sticky; top: 84px; }
@media (max-width: 979px) { .builder { grid-template-columns: 1fr; } .builder-side { position: static; } }

.lines { display: grid; gap: 12px; }
.line { border: 1px solid var(--line); border-radius: 10px; padding: 12px; background: #fbfcfd; }
.line-top { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.line-top input { flex: 1; }
.line-nums { display: grid; grid-template-columns: 0.8fr 0.9fr 1.2fr; gap: 8px; }
.line-nums.inv { grid-template-columns: 0.8fr 1.2fr 1fr; }
.line-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; font-size: 14px; color: var(--ink-2); }
.line-foot b { color: var(--ink); font-size: 15px; }
.kind { font-size: 12px; font-weight: 700; letter-spacing: 0.03em; text-transform: uppercase; padding: 4px 8px; border-radius: 8px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.kind.labor { background: #fdf2e2; color: #9a5b00; }
.kind.sub { background: #f1ecfb; color: #6a3fb5; }
.kind.other { background: #eef0f2; color: var(--ink-2); }
.line .mini > span { font-size: 13px; margin-bottom: 4px; }
.line input, .line select { min-height: 46px; font-size: 16px; padding: 10px 12px; }
.line .box .pre + input { padding-left: 26px; }
.line .box .pre { left: 11px; font-size: 16px; }
.add-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

.sum { padding: 20px 22px; }
.sum-row { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; font-size: 16px; color: var(--ink-2); }
.sum-row b { color: var(--ink); font-weight: 600; }
.sum-row.total { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 14px; font-size: 20px; }
.sum-row.total b { font-weight: 780; letter-spacing: -0.02em; }
.inside { margin-top: 16px; padding: 14px 16px; border-radius: 10px; background: var(--profit-soft); }
.inside.neg { background: var(--loss-soft); }
.inside-h { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--profit); margin-bottom: 6px; display: flex; gap: 6px; align-items: center; }
.inside.neg .inside-h { color: var(--loss); }
.inside .sum-row { padding: 4px 0; font-size: 15px; }
.actions { display: grid; gap: 10px; margin-top: 16px; }

details.more > summary { cursor: pointer; list-style: none; display: flex; align-items: center; justify-content: space-between; font-weight: 700; font-size: 15px; min-height: 28px; }
details.more > summary::-webkit-details-marker { display: none; }
details.more > summary::after { content: ""; width: 10px; height: 10px; border-right: 2px solid var(--ink-3); border-bottom: 2px solid var(--ink-3); transform: rotate(45deg) translateY(-3px); transition: transform 0.2s var(--ease); }
details.more[open] > summary::after { transform: rotate(-135deg) translateY(-2px); }
details.more > summary small { font-weight: 500; color: var(--ink-3); margin: 0 auto 0 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
details.more[open] > summary { margin-bottom: 14px; }
.stack { display: grid; gap: 14px; }

.logo-drop {
  display: flex; align-items: center; gap: 14px; padding: 12px; border: 1.5px dashed var(--line-2); border-radius: 10px; cursor: pointer; background: #fbfcfd;
}
.logo-drop:hover { border-color: var(--accent); }
.logo-drop img { max-width: 120px; max-height: 56px; object-fit: contain; }
.logo-drop .ph { width: 56px; height: 56px; border-radius: 8px; background: var(--bg); display: grid; place-items: center; color: var(--ink-3); }
.swatches { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.sw { width: 44px; height: 44px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1.5px var(--line-2); cursor: pointer; padding: 0; }
.sw[aria-pressed="true"] { box-shadow: 0 0 0 2.5px var(--ink); }

.mob-switch { display: none; }
@media (max-width: 979px) {
  .mob-switch { display: flex; justify-content: center; margin: 0 0 16px; }
  .builder[data-view="edit"] .builder-side .paper-wrap { display: none; }
  .builder[data-view="preview"] .builder-main { display: none; }
}

/* sticky money bar on phones (quote) */
.mbar { display: none; }
@media (max-width: 979px) {
  .mbar {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 10px); z-index: 10;
    margin-top: 16px; padding: 12px 16px; border-radius: 12px; background: var(--ink); color: #fff; box-shadow: var(--shadow-lift);
  }
  .mbar small { display: block; font-size: 13px; color: #c4cad3; }
  .mbar b { font-size: 20px; letter-spacing: -0.02em; }
  .mbar .p { text-align: right; margin-left: auto; }
  .mbar .btn { min-height: 44px; padding: 0 14px; font-size: 15px; background: #fff; color: var(--ink); }
  .mbar .btn:hover { background: #e8ecf0; color: var(--ink); }
  .mbar .p b { color: #6ee7a0; }
  .mbar .p.neg b { color: #fca5a5; }
}
@media (min-width: 760px) and (max-width: 979px) { .mbar { bottom: 16px; } }

/* ---------- paper (invoice / estimate document) ---------- */
.paper-wrap { background: #e9edf1; border-radius: var(--radius); padding: 18px; }
@media (max-width: 559px) { .paper-wrap { padding: 8px; margin: 0 -12px; border-radius: 0; } }
.paper {
  --doc-accent: #1a56db; --doc-font: var(--font);
  background: #fff; color: #1f2328; font-family: var(--doc-font); font-size: 13px; line-height: 1.5;
  padding: 36px 34px 28px; border-radius: 4px; box-shadow: var(--shadow-lift);
  aspect-ratio: 8.5 / 11; min-height: 0; display: flex; flex-direction: column; font-variant-numeric: tabular-nums;
}
@media (max-width: 559px) { .paper { padding: 22px 18px 18px; font-size: 12px; aspect-ratio: auto; min-height: 520px; } }
.d-head { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; }
.d-logo { max-width: 170px; max-height: 70px; object-fit: contain; display: block; margin-bottom: 10px; }
.d-biz b { font-size: 1.25em; display: block; color: #111; }
.d-biz div { color: #555; white-space: pre-line; }
.d-title { text-align: right; }
.d-title h2 { font-family: var(--doc-font); margin: 0 0 6px; font-size: 2.1em; letter-spacing: -0.01em; color: var(--doc-accent); line-height: 1.1; text-transform: uppercase; font-weight: 700; }
.d-meta { display: grid; grid-template-columns: auto auto; gap: 1px 14px; justify-content: end; color: #555; }
.d-meta dt { text-align: right; }
.d-meta dd { margin: 0; color: #111; text-align: right; font-weight: 600; }
.d-bill { margin: 26px 0 18px; display: flex; justify-content: space-between; gap: 20px; }
.d-bill h4, .d-notes h4 { margin: 0 0 4px; font-size: 0.8em; letter-spacing: 0.08em; text-transform: uppercase; color: var(--doc-accent); }
.d-bill div { white-space: pre-line; }
.d-bill .due { text-align: right; }
.d-bill .due b { display: block; font-size: 1.7em; color: #111; letter-spacing: -0.01em; }
table.d-items { width: 100%; border-collapse: collapse; }
.d-items th { text-align: left; font-size: 0.8em; letter-spacing: 0.06em; text-transform: uppercase; color: #fff; background: var(--doc-accent); padding: 7px 9px; font-weight: 700; }
.d-items td { padding: 8px 9px; border-bottom: 1px solid #e6e8eb; vertical-align: top; }
.d-items .n { text-align: right; white-space: nowrap; }
.d-items td.desc { white-space: pre-line; }
.d-totals { margin: 12px 0 0 auto; min-width: 46%; }
.d-totals div { display: flex; justify-content: space-between; gap: 16px; padding: 3px 9px; }
.d-totals .grand { border-top: 2px solid var(--doc-accent); margin-top: 4px; padding-top: 7px; font-weight: 700; font-size: 1.15em; color: #111; }
.d-totals .bal { background: color-mix(in srgb, var(--doc-accent) 10%, #fff); font-weight: 700; color: #111; border-radius: 4px; margin-top: 4px; padding: 6px 9px; }
.d-notes { margin-top: 22px; white-space: pre-line; color: #333; }
.d-foot { margin-top: auto; padding-top: 18px; text-align: center; color: #8a8f96; font-size: 0.82em; }
.d-empty td { color: #9aa0a6; font-style: italic; }

@media print {
  @page { size: letter; margin: 0.45in; }
  body { background: #fff; padding: 0 !important; }
  body > *:not(.print-root) { display: none !important; }
  .print-root { display: block !important; }
  .print-root .paper { box-shadow: none; border-radius: 0; padding: 0; aspect-ratio: auto; min-height: 9.9in; font-size: 13px; }
  .d-items th, .d-totals .bal { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
.print-root { display: none; }

/* ---------- footer ---------- */
.foot { border-top: 1px solid var(--line); margin-top: 40px; }
.foot-in { max-width: 1180px; margin: 0 auto; padding: 24px 20px 32px; display: flex; flex-wrap: wrap; gap: 8px 24px; font-size: 14px; color: var(--ink-3); }
.foot-in a { color: var(--ink-2); text-decoration: none; }
.foot-in a:hover { color: var(--accent); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; z-index: 50;
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 10px; font-weight: 600; font-size: 15px;
  transition: opacity 0.25s var(--ease), transform 0.35s var(--ease); pointer-events: none;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }
@media (max-width: 759px) { .toast { bottom: calc(var(--nav-h) + 20px); } }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

.calc > .panel + .panel { margin-top: 0; }
