:root {
  --paper: #f6f4ef;
  --card: #ffffff;
  --ink: #1d2a33;
  --ink-2: #4a5964;
  --muted: #7b8790;
  --line: #e2ded4;
  --line-2: #cfc9bc;
  --amber: #f2a33a;
  --amber-deep: #c9771a;
  --good: #2f7d4f;
  --bad: #b3261e;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(29, 42, 51, .06), 0 2px 8px rgba(29, 42, 51, .05);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 16px/1.45 var(--font); -webkit-tap-highlight-color: transparent; }
main { max-width: 1040px; margin: 0 auto; padding: 16px 16px calc(96px + env(safe-area-inset-bottom)); outline: none; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 8px; text-wrap: balance; }
h1 { font-size: 1.5rem; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 10px; }
a { color: inherit; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.pad { padding: 24px 0; }
.num { font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }
.grid2 { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .grid2 { grid-template-columns: 1fr 1fr; } .grid3 { grid-template-columns: 1fr 1fr 1fr; } }
.grid3 { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }
.spacer { flex: 1; }

/* top bar + nav */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--ink); color: #fff; padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); display: flex; align-items: center; gap: 16px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 700; letter-spacing: .01em; min-width: 0; }
.brand span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-mark { width: 26px; height: 26px; border-radius: 7px; background: url(/icons/icon.svg) center/cover; flex: none; }
.sidenav { display: none; gap: 4px; margin-left: auto; }
.sidenav a, .tabbar a { text-decoration: none; }
.sidenav a { padding: 8px 12px; border-radius: 8px; color: #cfd8de; font-weight: 600; font-size: .95rem; }
.sidenav a[aria-current="page"] { background: rgba(255,255,255,.12); color: #fff; }
.tabbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; display: flex; background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px 6px; font-size: .72rem; font-weight: 600; color: var(--muted); }
.tabbar a svg { width: 22px; height: 22px; }
.tabbar a[aria-current="page"] { color: var(--ink); }
.tabbar a[aria-current="page"] svg { color: var(--amber-deep); }
@media (min-width: 860px) {
  .sidenav { display: flex; }
  .tabbar { display: none !important; }
  main { padding-bottom: 48px; }
}

/* cards, lists */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card + .card { margin-top: 12px; }
.card h2 { margin-bottom: 12px; }
.list { list-style: none; margin: 0; padding: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.list li + li { border-top: 1px solid var(--line); }
.list a, .list .item { display: flex; gap: 12px; align-items: center; padding: 14px 16px; text-decoration: none; min-height: 56px; }
.list a:active { background: #faf8f3; }
.list .main { flex: 1; min-width: 0; }
.list .title { font-weight: 600; }
.list .sub { color: var(--muted); font-size: .875rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty { text-align: center; padding: 32px 16px; color: var(--muted); }
.empty strong { display: block; color: var(--ink); font-size: 1.05rem; margin-bottom: 4px; }
.pill { display: inline-block; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: 3px 8px; border-radius: 999px; background: #eeeae0; color: var(--ink-2); white-space: nowrap; }
.pill.sent { background: #e3eef8; color: #22598a; }
.pill.declined { background: #f7e3e1; color: var(--bad); }
.pill.open { background: #fdf0dc; color: #8a520f; }
.pill.closed, .pill.active { background: #e2f1e7; color: var(--good); }
.pill.invited { background: #e3eef8; color: #22598a; }
.pill.disabled { background: #eee; color: #888; }
.tabs { display: flex; gap: 4px; background: #ebe7dd; padding: 4px; border-radius: 10px; margin-bottom: 14px; }
.tabs a { flex: 1; text-align: center; padding: 8px 6px; border-radius: 7px; text-decoration: none; font-weight: 600; font-size: .92rem; color: var(--ink-2); }
.tabs a[aria-current="page"] { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.head { display: flex; align-items: flex-start; gap: 12px; margin: 4px 0 14px; flex-wrap: wrap; }
.head h1 { flex: 1; margin: 0; min-width: 0; }
.back { display: inline-flex; gap: 4px; align-items: center; text-decoration: none; color: var(--ink-2); font-weight: 600; font-size: .92rem; margin-bottom: 6px; min-height: 32px; }

/* forms */
label { display: block; font-weight: 600; font-size: .875rem; color: var(--ink-2); }
label > input, label > select, label > textarea { margin-top: 4px; }
input, select, textarea, button { font: inherit; color: inherit; }
input[type=text], input[type=email], input[type=tel], input[type=password], input[type=number], input[type=search], input:not([type]), select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid var(--line-2); border-radius: 9px; background: #fff; font-size: 16px; font-weight: 400;
}
textarea { min-height: 80px; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--amber); outline-offset: 0; border-color: var(--amber-deep); }
.hint { font-weight: 400; color: var(--muted); font-size: .8rem; margin-top: 4px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; color: var(--ink); min-height: 44px; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--ink); }
.prefix { position: relative; }
.prefix > span { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; font-size: .95rem; }
.prefix > input { padding-left: 24px; }
.suffix { position: relative; }
.suffix > span { position: absolute; right: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; font-size: .9rem; }
.suffix > input { padding-right: 34px; }
.err { color: var(--bad); font-weight: 600; font-size: .9rem; min-height: 1.2em; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 10px 16px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--card); font-weight: 650; text-decoration: none; cursor: pointer; white-space: nowrap; touch-action: manipulation; user-select: none; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn.go { background: var(--amber); border-color: var(--amber-deep); color: #2a1a05; }
.btn.danger { color: var(--bad); border-color: #e7c3bf; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: .9rem; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: default; transform: none; }
.icon-btn { width: 40px; height: 40px; display: inline-grid; place-items: center; border-radius: 9px; border: 0; background: transparent; color: var(--muted); cursor: pointer; flex: none; }
.icon-btn:hover { background: #f0ede5; color: var(--bad); }
.icon-btn svg { width: 18px; height: 18px; }
@media (hover: hover) { .btn:hover { border-color: var(--ink-2); } .btn.primary:hover { background: #2b3c48; } .list a:hover { background: #faf8f3; } }

/* auth */
.auth { max-width: 420px; margin: 7vh auto 0; }
.auth .logo { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.auth .logo .brand-mark { width: 44px; height: 44px; border-radius: 11px; }
.auth .logo b { display: block; font-size: 1.2rem; }

/* wizard */
.steps { display: flex; gap: 6px; margin-bottom: 16px; }
.steps i { flex: 1; height: 5px; border-radius: 3px; background: var(--line); }
.steps i.on { background: var(--amber); }

/* dashboard */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 16px; }
@media (min-width: 640px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; text-decoration: none; box-shadow: var(--shadow); }
.stat b { display: block; font-size: 1.6rem; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: .85rem; font-weight: 600; }

/* estimate editor */
.job { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin-top: 14px; overflow: hidden; }
.job-head { display: flex; gap: 8px; align-items: center; padding: 12px 12px 12px 16px; background: #faf8f3; border-bottom: 1px solid var(--line); }
.job-head .n { font-weight: 800; color: var(--amber-deep); font-size: .85rem; flex: none; }
.job-head input { font-weight: 700; }
.job-body { padding: 14px 16px 16px; }
.section-label { display: flex; align-items: baseline; justify-content: space-between; margin: 16px 0 6px; font-size: .78rem; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-2); }
.section-label:first-child { margin-top: 0; }
.lines { display: grid; gap: 8px; }
.line { display: grid; gap: 6px 8px; align-items: center; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: #fdfcf9; }
.line.mat { grid-template-columns: 1fr 1fr 40px; grid-template-areas: "name name del" "qty cost cost" "mk mk total"; }
.line.lab { grid-template-columns: 1fr 1fr 40px; grid-template-areas: "who who del" "hrs rate rate" "info info total"; }
.line .a-name { grid-area: name; } .line .a-qty { grid-area: qty; } .line .a-cost { grid-area: cost; } .line .a-mk { grid-area: mk; }
.line .a-total { grid-area: total; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; grid-column: 2 / 4; }
.line .a-del { grid-area: del; justify-self: end; }
.line .a-who { grid-area: who; } .line .a-hrs { grid-area: hrs; } .line .a-rate { grid-area: rate; } .line .a-info { grid-area: info; font-size: .82rem; color: var(--muted); }
.line .tiny { font-size: .7rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; display: block; margin-bottom: 2px; }
@media (min-width: 760px) {
  .line.mat { grid-template-columns: 1fr 80px 120px 120px 110px 40px; grid-template-areas: "name qty cost mk total del"; }
  .line.lab { grid-template-columns: 1fr 90px 120px 160px 40px; grid-template-areas: "who hrs rate info del"; }
  .line .a-total { grid-column: auto; }
  .line.lab .a-info { text-align: right; }
  .line .tiny { display: none; }
}
.add-row { margin-top: 8px; display: flex; gap: 8px; flex-wrap: wrap; }
.job-sum { display: flex; flex-wrap: wrap; gap: 4px 16px; justify-content: flex-end; margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--line-2); font-size: .9rem; color: var(--ink-2); }
.job-sum b { color: var(--ink); font-variant-numeric: tabular-nums; }

.totals-bar { position: sticky; bottom: calc(64px + env(safe-area-inset-bottom)); z-index: 10; margin-top: 18px; background: var(--ink); color: #fff; border-radius: var(--radius); padding: 12px 14px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; box-shadow: 0 6px 20px rgba(29, 42, 51, .25); }
@media (min-width: 860px) { .totals-bar { bottom: 12px; grid-template-columns: repeat(3, 1fr) auto; align-items: center; } }
.totals-bar div span { display: block; font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: #aebbc4; font-weight: 700; }
.totals-bar div b { font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.totals-bar .profit b { color: #8fe0ae; }
.totals-bar .profit.neg b { color: #ffaba3; }
.totals-bar .actions { grid-column: 1 / -1; display: flex; gap: 8px; }
.totals-bar .actions .btn { flex: 1; color: var(--ink); }
@media (min-width: 860px) { .totals-bar .actions { grid-column: auto; } }

.breakdown { width: 100%; border-collapse: collapse; font-size: .95rem; }
.breakdown td { padding: 6px 0; border-bottom: 1px solid var(--line); }
.breakdown td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.breakdown tr.total td { font-weight: 800; border-bottom: 0; font-size: 1.05rem; padding-top: 10px; }
.breakdown tr.sub td { color: var(--muted); font-size: .88rem; }

details.more { margin-top: 14px; }
details.more > summary { cursor: pointer; font-weight: 700; padding: 10px 0; list-style: none; display: flex; align-items: center; gap: 8px; }
details.more > summary::-webkit-details-marker { display: none; }
details.more > summary::before { content: "▸"; color: var(--amber-deep); transition: transform .15s; }
details.more[open] > summary::before { transform: rotate(90deg); }

/* work order */
.wo-head { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .wo-head { grid-template-columns: 1fr 1fr; } .wo-head .cust { text-align: right; } }
.wo-head b { display: block; font-size: 1.05rem; margin-bottom: 2px; }
.wo-head div { color: var(--ink-2); font-size: .92rem; }
.money-bar { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin: 14px 0; }
@media (min-width: 640px) { .money-bar { grid-template-columns: repeat(4, 1fr); } }
.money-bar div { background: var(--card); padding: 12px 14px; }
.money-bar span { display: block; font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; }
.money-bar b { font-size: 1.2rem; font-variant-numeric: tabular-nums; }
.money-bar .good b { color: var(--good); }
.wo-job { background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--amber); border-radius: var(--radius); padding: 14px 16px; margin-top: 12px; box-shadow: var(--shadow); }
.wo-job h3 { font-size: 1.05rem; }
.wo-job ul { margin: 6px 0 0; padding-left: 18px; color: var(--ink-2); font-size: .92rem; }
.soon { margin-top: 12px; padding: 10px 12px; border-radius: 9px; background: #faf6ec; border: 1px dashed #e3cfa4; color: #7a5a1e; font-size: .88rem; }

/* modal */
dialog { border: 0; border-radius: 16px; padding: 0; width: min(520px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); box-shadow: 0 20px 60px rgba(0,0,0,.3); color: var(--ink); }
dialog::backdrop { background: rgba(20, 28, 34, .5); }
dialog form, dialog .body { padding: 18px; }
dialog h2 { margin-bottom: 12px; }
dialog .foot { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.linkbox { word-break: break-all; background: #f4f1ea; border-radius: 9px; padding: 10px 12px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .82rem; user-select: all; }

/* search */
.search { margin-bottom: 12px; }
.combo { position: relative; }
.combo-list { position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 4px); background: #fff; border: 1px solid var(--line-2); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.12); max-height: 300px; overflow: auto; list-style: none; margin: 0; padding: 4px; }
.combo-list li { padding: 10px 12px; border-radius: 7px; cursor: pointer; }
.combo-list li[aria-selected="true"], .combo-list li:hover { background: #f4f1ea; }
.combo-list li.new { color: var(--amber-deep); font-weight: 700; }
.combo-list .sub { display: block; font-size: .8rem; color: var(--muted); }

/* addons */
.addon { display: flex; gap: 12px; align-items: flex-start; }
.addon + .addon { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.addon .ic { width: 40px; height: 40px; border-radius: 10px; background: #f4efe2; display: grid; place-items: center; flex: none; color: var(--amber-deep); }
.addon .ic svg { width: 22px; height: 22px; }
.addon .main { flex: 1; }
.addon .price { font-weight: 800; white-space: nowrap; }

#toast { position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; font-weight: 600; opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s; z-index: 50; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.bad { background: var(--bad); }

/* printable estimate */
.doc { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 28px; box-shadow: var(--shadow); }
.doc .doc-top { display: flex; justify-content: space-between; gap: 20px; flex-wrap: wrap; border-bottom: 3px solid var(--ink); padding-bottom: 14px; margin-bottom: 16px; }
.doc .doc-title { font-size: 1.6rem; font-weight: 800; letter-spacing: .02em; }
.doc table { width: 100%; border-collapse: collapse; margin: 10px 0 4px; font-size: .92rem; }
.doc th { text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); border-bottom: 1px solid var(--line-2); padding: 6px 4px; }
.doc td { padding: 6px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
.doc td.n, .doc th.n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.doc .doc-job { margin-top: 18px; break-inside: avoid; }
.doc .doc-totals { margin-left: auto; width: min(320px, 100%); margin-top: 18px; }
@media print {
  body { background: #fff; }
  .topbar, .tabbar, .no-print, #toast { display: none !important; }
  main { padding: 0; max-width: none; }
  .doc { border: 0; box-shadow: none; padding: 0; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
