:root {
  --forest: #1f5132;
  --forest-2: #2b6b43;
  --lime: #a4d233;
  --lime-soft: #e9f5cf;
  --sand: #f5efe3;
  --sand-2: #ebe2d0;
  --card: #fffdf8;
  --ink: #23262a;
  --muted: #5f6368;
  --line: #ddd3bf;
  --red: #b3261e;
  --red-soft: #fbe9e7;
  --amber: #8a5a00;
  --amber-soft: #fff3d6;
  --radius: 14px;
  --tap: 52px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  font-size: 17px;
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--sand); }
body { min-height: 100vh; line-height: 1.4; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--forest); }
h1 { font-size: 1.45rem; margin: 0.2rem 0 0.8rem; }
h2 { font-size: 1.12rem; margin: 1.4rem 0 0.6rem; }
h3 { font-size: 1rem; margin: 0 0 0.3rem; }
p { margin: 0.3rem 0 0.8rem; }
.muted { color: var(--muted); }
.small { font-size: 0.86rem; }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  background: var(--forest); color: #fff;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
}
.topbar .brand { font-weight: 800; letter-spacing: 0.2px; display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.topbar .brand span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .brand .dot { width: 22px; height: 22px; border-radius: 6px; background: var(--lime); flex: none; }
.topbar button { background: transparent; border: 0; color: #fff; min-height: 44px; min-width: 44px; font-size: 1.3rem; cursor: pointer; }
main { overflow-x: hidden; max-width: 760px; margin: 0 auto; padding: 16px 16px calc(110px + env(safe-area-inset-bottom)); }
.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 62px; text-decoration: none; color: var(--muted); font-size: 0.78rem; font-weight: 600;
}
.tabs a .ico { font-size: 1.35rem; line-height: 1; }
.tabs a.on { color: var(--forest); }
.tabs a .badge { position: absolute; margin-left: 28px; margin-top: -30px; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 20px; border-radius: 12px; border: 2px solid transparent;
  background: var(--forest); color: #fff; font-weight: 700; cursor: pointer; text-decoration: none;
  -webkit-tap-highlight-color: transparent; user-select: none;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.lime { background: var(--lime); color: #17351f; }
.btn.ghost { background: transparent; color: var(--forest); border-color: var(--forest); }
.btn.quiet { background: var(--sand-2); color: var(--ink); }
.btn.danger { background: var(--red); }
.btn.block { display: flex; width: 100%; }
.btn.big { min-height: 64px; font-size: 1.12rem; border-radius: 16px; }
.btn.small { min-height: 40px; padding: 0 14px; font-size: 0.9rem; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row > .grow { flex: 1; }
.stack > * + * { margin-top: 10px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 380px) { .grid2 { grid-template-columns: 1fr; } }

label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-weight: 650; font-size: 0.92rem; margin-bottom: 5px; }
label.field > small { display: block; color: var(--muted); font-size: 0.82rem; margin-top: 4px; }
input[type=text], input[type=email], input[type=tel], input[type=password], input[type=number], input[type=date], input[type=time], input[type=search], select, textarea {
  width: 100%; min-height: var(--tap); padding: 10px 14px; border-radius: 12px;
  border: 1.5px solid var(--line); background: #fff; outline: none;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--forest); box-shadow: 0 0 0 3px rgba(31, 81, 50, 0.15); }
.field.err input, .field.err textarea { border-color: var(--red); }
.money { position: relative; }
.money::before { content: '$'; position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.money input { padding-left: 26px; }
.check { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; cursor: pointer; }
.check input { width: 26px; height: 26px; flex: none; accent-color: var(--forest); margin: 0; }

/* ---------- cards ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.card.tap { display: block; text-decoration: none; color: inherit; cursor: pointer; }
.card.tap:active { background: #fbf6ea; }
.card.hl { border: 2px solid var(--lime); background: #fcfff4; }
.card.warn { border-color: #f0d38a; background: var(--amber-soft); }
.card.bad { border-color: #f3b8b2; background: var(--red-soft); }
.item { display: flex; gap: 12px; align-items: center; }
.item .grow { flex: 1; min-width: 0; }
.item .title { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .sub { color: var(--muted); font-size: 0.88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .right { text-align: right; font-weight: 700; white-space: nowrap; }
.thumb { width: 56px; height: 56px; border-radius: 10px; object-fit: cover; background: var(--sand-2); flex: none; }
.chev { color: var(--muted); font-size: 1.4rem; }
.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 0.78rem; font-weight: 700; background: var(--sand-2); color: var(--ink); white-space: nowrap; }
.pill.green { background: var(--lime-soft); color: #2d5a12; }
.pill.dark { background: var(--forest); color: #fff; }
.pill.amber { background: var(--amber-soft); color: var(--amber); }
.pill.red { background: var(--red-soft); color: var(--red); }
.badge { display: inline-flex; min-width: 22px; height: 22px; padding: 0 6px; align-items: center; justify-content: center; border-radius: 999px; background: var(--red); color: #fff; font-size: 0.75rem; font-weight: 800; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; margin: 1.4rem 0 0.6rem; }
.section-head h2 { margin: 0; }
.empty { text-align: center; color: var(--muted); padding: 28px 10px; }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 12px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 10px; text-align: center; }
.stat b { display: block; font-size: clamp(1rem, 5vw, 1.35rem); color: var(--forest); overflow-wrap: anywhere; }
.stat span { font-size: 0.76rem; color: var(--muted); }

/* ---------- steps (new quote) ---------- */
.steps { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 14px; }
.steps div { height: 6px; border-radius: 3px; background: var(--sand-2); }
.steps div.on { background: var(--forest); }
.steps-label { font-size: 0.85rem; color: var(--muted); margin-bottom: 4px; font-weight: 600; }

/* ---------- photos ---------- */
.photos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.photo { position: relative; aspect-ratio: 1; border-radius: 12px; overflow: hidden; background: var(--sand-2); border: 3px solid transparent; cursor: pointer; }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo.sel { border-color: var(--lime); }
.photo .tick { position: absolute; top: 6px; right: 6px; width: 28px; height: 28px; border-radius: 50%; background: rgba(255,255,255,0.9); display: flex; align-items: center; justify-content: center; font-weight: 900; color: var(--forest); }
.photo.sel .tick { background: var(--lime); }
.photo .flag { position: absolute; left: 6px; bottom: 6px; right: 6px; background: rgba(179, 38, 30, 0.92); color: #fff; font-size: 0.7rem; font-weight: 700; padding: 3px 6px; border-radius: 6px; text-align: center; }
.photo .num { position: absolute; left: 6px; top: 6px; background: rgba(0,0,0,0.6); color: #fff; font-size: 0.75rem; font-weight: 800; padding: 2px 7px; border-radius: 6px; }
.photo.busy::after { content: ''; position: absolute; inset: 0; background: rgba(255,255,255,0.6); }
.addphoto { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; aspect-ratio: 1; border-radius: 12px; border: 2px dashed var(--forest); color: var(--forest); font-weight: 700; cursor: pointer; background: #fbfdf6; text-align: center; font-size: 0.85rem; }
.addphoto .ico { font-size: 1.8rem; }

/* ---------- AI findings ---------- */
.finding { display: flex; gap: 12px; }
.finding input { width: 28px; height: 28px; margin-top: 2px; flex: none; accent-color: var(--forest); }
.conf { height: 6px; background: var(--sand-2); border-radius: 3px; overflow: hidden; margin: 6px 0; width: 120px; }
.conf i { display: block; height: 100%; background: var(--forest); }
.kv { font-size: 0.9rem; margin: 3px 0; }
.kv b { font-weight: 650; }

/* ---------- pricing ---------- */
.line { position: relative; }
.line .remove { position: absolute; top: 10px; right: 10px; background: none; border: 0; color: var(--muted); font-size: 1.4rem; min-width: 44px; min-height: 44px; cursor: pointer; }
.more-toggle { background: none; border: 0; color: var(--forest); font-weight: 700; padding: 8px 0; cursor: pointer; min-height: 44px; }
.totalbar {
  position: fixed; left: 0; right: 0; bottom: calc(62px + env(safe-area-inset-bottom)); z-index: 15;
  background: var(--forest); color: #fff; padding: 10px 16px;
}
.totalbar .inner { max-width: 760px; margin: 0 auto; display: flex; align-items: center; gap: 12px; }
.totalbar .t { flex: 1; }
.totalbar .t b { font-size: 1.4rem; display: block; }
.totalbar .t span { font-size: 0.82rem; opacity: 0.85; }
.sumtable { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.sumtable td { padding: 6px 0; border-bottom: 1px solid var(--sand-2); }
.sumtable td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.sumtable tr.total td { font-weight: 800; font-size: 1.08rem; border-bottom: 0; }
.sumtable tr.sub td { color: var(--muted); font-size: 0.86rem; }

/* ---------- modal + toast ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(20, 30, 22, 0.55); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.modal { background: var(--card); width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; border-radius: 20px 20px 0 0; padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); }
@media (min-width: 700px) { .modal-back { align-items: center; } .modal { border-radius: 20px; } }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(150px + env(safe-area-inset-bottom)); z-index: 60; background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 12px; font-weight: 600; max-width: 90vw; box-shadow: 0 6px 24px rgba(0,0,0,0.2); }
.toast.err { background: var(--red); }
.spinner { width: 22px; height: 22px; border: 3px solid rgba(255,255,255,0.4); border-top-color: #fff; border-radius: 50%; animation: spin 0.8s linear infinite; }
.spinner.dark { border-color: rgba(31,81,50,0.25); border-top-color: var(--forest); }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: flex; justify-content: center; padding: 40px; }

/* ---------- auth + public pages ---------- */
.center { max-width: 460px; margin: 0 auto; padding: 32px 16px 60px; }
.logo { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.4rem; color: var(--forest); margin-bottom: 20px; }
.logo .dot { width: 34px; height: 34px; border-radius: 9px; background: var(--forest); position: relative; }
.logo .dot::after { content: ''; position: absolute; inset: 9px; border-radius: 4px; background: var(--lime); }
.hero { background: var(--forest); color: #fff; border-radius: var(--radius); padding: 18px; margin-bottom: 14px; }
.hero h1 { margin: 0 0 4px; }
.hero p { margin: 0; opacity: 0.9; }

/* ---------- customer document / print ---------- */
.doc { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; }
.doc .head { display: flex; justify-content: space-between; gap: 16px; border-bottom: 3px solid var(--forest); padding-bottom: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.doc .meta { text-align: right; }
@media (max-width: 480px) { .doc .meta { text-align: left; } }
.doc .bname { font-size: 1.3rem; font-weight: 800; color: var(--forest); }
.doc table { width: 100%; border-collapse: collapse; }
.doc th { text-align: left; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.4px; color: var(--muted); border-bottom: 1px solid var(--line); padding: 6px 0; }
.doc td { vertical-align: top; padding: 10px 0; border-bottom: 1px solid var(--sand-2); }
.doc td.amt, .doc th.amt { text-align: right; white-space: nowrap; padding-left: 12px; }
.doc .totals { margin-left: auto; width: min(320px, 100%); margin-top: 10px; }
.doc .totals div { display: flex; justify-content: space-between; padding: 4px 0; }
.doc .totals .grand { font-size: 1.25rem; font-weight: 800; border-top: 2px solid var(--ink); margin-top: 6px; padding-top: 8px; }
@media print {
  .topbar, .tabs, .totalbar, .noprint, .toast { display: none !important; }
  body, html { background: #fff; }
  main { padding: 0; max-width: none; }
  .doc { border: 0; padding: 0; }
}
