/* ============================================================
   LeafFilter Paperwork — shared UI styles
   Style: Trust & Authority · slate ink + LeafFilter green accent
   Font: Atkinson Hyperlegible (high legibility outdoors)
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Atkinson+Hyperlegible:ital,wght@0,400;0,700;1,400&display=swap');

:root {
  --ink: #0f172a;
  --ink-2: #334155;
  --ink-3: #64748b;
  --bg: #eef1f5;
  --surface: #ffffff;
  --muted: #e8ecf1;
  --border: #d7dee7;
  --accent: #15803d;        /* LeafFilter green, AA on white */
  --accent-ink: #0e5e2b;
  --accent-soft: #e7f4ec;
  --destructive: #dc2626;
  --ring: #15803d;
  --radius: 10px;
  --shadow-1: 0 1px 2px rgba(15, 23, 42, 0.06), 0 1px 3px rgba(15, 23, 42, 0.08);
  --shadow-2: 0 4px 12px rgba(15, 23, 42, 0.10);
  --space-1: 4px; --space-2: 8px; --space-3: 12px;
  --space-4: 16px; --space-5: 24px; --space-6: 32px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: 'Atkinson Hyperlegible', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  min-height: 100dvh;
  touch-action: manipulation;
}

/* ---------- App bar ---------- */
.appbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--ink);
  color: #fff;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) var(--space-4) 12px;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  box-shadow: var(--shadow-2);
}
.appbar .brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 17px; letter-spacing: .01em;
  min-width: 0;
}
.appbar .brand .leaf {
  width: 28px; height: 28px; flex: none;
  display: grid; place-items: center;
  background: var(--accent); border-radius: 8px;
}
.appbar .brand .leaf svg { width: 18px; height: 18px; stroke: #fff; }
.appbar .brand span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appbar .spacer { flex: 1; }
.appbar .bar-btn {
  appearance: none; border: 1px solid rgba(255,255,255,.25);
  background: rgba(255,255,255,.08); color: #fff;
  min-height: 44px; padding: 0 14px; border-radius: 8px;
  font: inherit; font-weight: 700; font-size: 14px;
  display: inline-flex; align-items: center; gap: 6px;
  cursor: pointer; transition: background .15s ease;
}
.appbar .bar-btn:hover { background: rgba(255,255,255,.16); }
.appbar .bar-btn svg { width: 17px; height: 17px; }

/* ---------- Layout ---------- */
.wrap {
  max-width: 760px;
  margin: 0 auto;
  padding: var(--space-4) var(--space-4) calc(96px + env(safe-area-inset-bottom, 0px));
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
  margin-bottom: var(--space-4);
  overflow: hidden;
}
.card-head {
  display: flex; align-items: center; gap: 10px;
  padding: var(--space-3) var(--space-4);
  background: linear-gradient(to bottom, #fbfcfe, #f4f7fa);
  border-bottom: 1px solid var(--border);
}
.card-head svg { width: 18px; height: 18px; stroke: var(--accent); flex: none; }
.card-head h2 {
  margin: 0; font-size: 15px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .04em; color: var(--ink-2);
}
.card-head .hint { margin-left: auto; font-size: 12.5px; color: var(--ink-3); font-weight: 400; text-transform: none; letter-spacing: 0; }
.card-body { padding: var(--space-4); }

/* ---------- Fields ---------- */
.field { margin-bottom: var(--space-4); }
.field:last-child { margin-bottom: 0; }
.field > label {
  display: block; font-size: 13.5px; font-weight: 700;
  color: var(--ink-2); margin-bottom: 6px;
}
.field .help { font-size: 12.5px; color: var(--ink-3); margin-top: 4px; }

input[type="text"], input[type="number"], input[type="email"],
input[type="password"], input[type="search"], textarea, select {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  font: inherit;
  color: var(--ink);
  background: #fff;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
textarea { min-height: 96px; resize: vertical; }
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--ring);
  box-shadow: 0 0 0 3px rgba(21, 128, 61, .18);
}
input::placeholder, textarea::placeholder { color: #9aa6b5; }

.row { display: flex; gap: var(--space-3); }
.row > .field { flex: 1; min-width: 0; }

/* numeric inputs: no spin buttons, tabular figures */
input[type="number"] { font-variant-numeric: tabular-nums; }
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number] { -moz-appearance: textfield; appearance: textfield; }

/* ---------- Stepper ---------- */
.stepper {
  display: flex; align-items: stretch;
  border: 1.5px solid var(--border); border-radius: 8px;
  overflow: hidden; background: #fff;
}
.stepper button {
  appearance: none; border: none; cursor: pointer;
  width: 48px; min-height: 48px; flex: none;
  background: var(--muted); color: var(--ink-2);
  font-size: 22px; font-weight: 700; line-height: 1;
  display: grid; place-items: center;
  transition: background .12s ease;
  -webkit-user-select: none; user-select: none;
}
.stepper button:active { background: #d4dbe4; }
.stepper input {
  border: none !important; border-radius: 0 !important;
  text-align: center; min-width: 0; flex: 1;
  box-shadow: none !important; min-height: 48px;
  font-weight: 700; font-size: 17px;
}

/* ---------- Segmented control ---------- */
.seg {
  display: flex; gap: 0;
  border: 1.5px solid var(--border);
  border-radius: 8px; overflow: hidden; background: #fff;
}
.seg button {
  appearance: none; border: none; cursor: pointer;
  flex: 1; min-height: 48px; padding: 8px 10px;
  background: #fff; color: var(--ink-2);
  font: inherit; font-size: 14.5px; font-weight: 700;
  transition: background .15s ease, color .15s ease;
  border-right: 1px solid var(--border);
}
.seg button:last-child { border-right: none; }
.seg button[aria-pressed="true"] {
  background: var(--accent); color: #fff;
}
.seg button:focus-visible { outline: 3px solid rgba(21,128,61,.4); outline-offset: -3px; }
.seg.seg-wrap { flex-wrap: wrap; }
.seg.seg-wrap button { flex: 1 1 30%; border-bottom: 1px solid var(--border); }

/* ---------- Buttons ---------- */
.btn {
  appearance: none; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 50px; padding: 0 20px;
  border-radius: 10px; border: 1.5px solid transparent;
  font: inherit; font-size: 16px; font-weight: 700;
  transition: background .15s ease, transform .08s ease, box-shadow .15s ease;
  text-decoration: none;
}
.btn:active { transform: scale(.98); }
.btn svg { width: 19px; height: 19px; flex: none; }
.btn-primary { background: var(--accent); color: #fff; box-shadow: var(--shadow-1); }
.btn-primary:hover { background: var(--accent-ink); }
.btn-secondary { background: #fff; color: var(--ink-2); border-color: var(--border); }
.btn-secondary:hover { background: var(--muted); }
.btn-ghost { background: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--muted); }
.btn-danger { background: #fff; color: var(--destructive); border-color: #f3c1c1; }
.btn-danger:hover { background: #fdf2f2; }
.btn[disabled] { opacity: .45; cursor: not-allowed; pointer-events: none; }
.btn-block { width: 100%; }

/* ---------- Sticky action bar ---------- */
.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 90;
  background: rgba(255,255,255,.96);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
  padding: 10px var(--space-4) calc(10px + env(safe-area-inset-bottom, 0px));
  display: flex; gap: var(--space-3); align-items: center;
}
.actionbar .inner { max-width: 760px; margin: 0 auto; display: flex; gap: var(--space-3); align-items: center; width: 100%; }
.savestate { font-size: 13px; color: var(--ink-3); flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; }
.savestate .dot { width: 8px; height: 8px; border-radius: 50%; background: #cbd5e1; flex: none; }
.savestate.is-saved .dot { background: var(--accent); }
.savestate.is-dirty .dot { background: #f59e0b; }
.savestate.is-error .dot { background: var(--destructive); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%) translateY(8px);
  background: var(--ink); color: #fff;
  padding: 11px 18px; border-radius: 10px;
  font-size: 14.5px; font-weight: 700;
  box-shadow: var(--shadow-2);
  opacity: 0; pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 200; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--destructive); }

/* ---------- Login ---------- */
.login-shell {
  min-height: 100dvh; display: grid; place-items: center;
  padding: var(--space-4);
}
.login-card {
  width: 100%; max-width: 400px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: var(--shadow-2);
  padding: var(--space-6) var(--space-5);
}
.login-card .logo {
  width: 56px; height: 56px; border-radius: 14px;
  background: var(--accent); display: grid; place-items: center;
  margin: 0 auto var(--space-4);
}
.login-card .logo svg { width: 32px; height: 32px; stroke: #fff; }
.login-card h1 { font-size: 22px; text-align: center; margin: 0 0 4px; }
.login-card .sub { text-align: center; color: var(--ink-3); font-size: 14px; margin: 0 0 var(--space-5); }
.login-error {
  background: #fdf2f2; border: 1px solid #f3c1c1; color: #b91c1c;
  border-radius: 8px; padding: 10px 12px; font-size: 14px;
  margin-bottom: var(--space-4); display: none;
}
.login-error.show { display: block; }

/* ---------- Dashboard job list ---------- */
.toolbar { display: flex; gap: var(--space-3); margin-bottom: var(--space-4); }
.toolbar .search { flex: 1; position: relative; }
.toolbar .search svg {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  width: 18px; height: 18px; stroke: var(--ink-3); pointer-events: none;
}
.toolbar .search input { padding-left: 40px; }

.job-list { display: flex; flex-direction: column; gap: var(--space-3); }
.job-item {
  display: flex; align-items: center; gap: var(--space-3);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-1);
  padding: var(--space-3) var(--space-4);
  text-decoration: none; color: inherit;
  transition: border-color .15s ease, box-shadow .15s ease;
  cursor: pointer;
}
.job-item:hover { border-color: var(--accent); box-shadow: var(--shadow-2); }
.job-item .ico {
  width: 42px; height: 42px; flex: none; border-radius: 9px;
  background: var(--accent-soft); display: grid; place-items: center;
}
.job-item .ico svg { width: 22px; height: 22px; stroke: var(--accent); }
.job-item .meta { flex: 1; min-width: 0; }
.job-item .meta .name { font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.job-item .meta .sub { font-size: 13px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.job-item .chev { flex: none; }
.job-item .chev svg { width: 20px; height: 20px; stroke: var(--ink-3); }

.empty {
  text-align: center; padding: var(--space-6) var(--space-4);
  color: var(--ink-3);
}
.empty .ico {
  width: 64px; height: 64px; margin: 0 auto var(--space-4);
  border-radius: 16px; background: var(--muted);
  display: grid; place-items: center;
}
.empty .ico svg { width: 32px; height: 32px; stroke: var(--ink-3); }
.empty h3 { color: var(--ink); margin: 0 0 4px; font-size: 17px; }
.empty p { margin: 0 0 var(--space-4); font-size: 14.5px; }

/* ---------- Measurement grid ---------- */
.mgrid { width: 100%; border-collapse: collapse; }
.mgrid th, .mgrid td { padding: 4px 3px; text-align: center; }
.mgrid thead th {
  font-size: 12px; color: var(--ink-3); font-weight: 700;
  padding-bottom: 6px; line-height: 1.25;
}
.mgrid thead .story-h { border-bottom: 2px solid var(--border); font-size: 12.5px; color: var(--ink-2); }
.mgrid tbody th {
  text-align: left; font-size: 13px; font-weight: 700; color: var(--ink-2);
  padding-right: 6px; white-space: nowrap;
}
.mgrid input {
  min-height: 44px; padding: 4px 2px; text-align: center;
  font-size: 16px; font-weight: 700; border-radius: 6px;
  font-variant-numeric: tabular-nums;
}
.mgrid .tot td {
  font-weight: 700; font-size: 16px; color: var(--accent-ink);
  background: var(--accent-soft); border-radius: 6px;
  min-height: 40px; padding: 9px 2px;
  font-variant-numeric: tabular-nums;
}
.mgrid .tot th { color: var(--ink); }
.mgrid .gsize { display: block; font-size: 11px; color: var(--ink-3); }

/* ---------- Porch ceiling table ---------- */
.porch-row { display: grid; grid-template-columns: 1.6fr 1fr 1fr .9fr; gap: 6px; margin-bottom: 6px; align-items: center; }
.porch-row .sqft {
  text-align: center; font-weight: 700; color: var(--accent-ink);
  background: var(--accent-soft); border-radius: 8px; min-height: 48px;
  display: grid; place-items: center; font-variant-numeric: tabular-nums;
}
.porch-head { display: grid; grid-template-columns: 1.6fr 1fr 1fr .9fr; gap: 6px; font-size: 12px; color: var(--ink-3); font-weight: 700; margin-bottom: 4px; text-align: center; }
.porch-head span:first-child { text-align: left; }

/* ---------- Drawing canvas ---------- */
.canvas-shell {
  border: 1.5px solid var(--border); border-radius: 10px;
  background: #fff; overflow: hidden; position: relative;
}
.canvas-shell canvas { display: block; width: 100%; touch-action: none; cursor: crosshair; }
.canvas-shell .canvas-label {
  position: absolute; bottom: 6px; left: 0; right: 0;
  text-align: center; font-size: 12px; color: #b6c0cc;
  pointer-events: none; font-weight: 700;
}
.canvas-tools { display: flex; gap: var(--space-2); margin-top: var(--space-2); }
.canvas-tools .btn { min-height: 44px; font-size: 14px; padding: 0 14px; }

/* ---------- Utility ---------- */
.hidden { display: none !important; }
.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}

@media (min-width: 768px) {
  .wrap { padding-top: var(--space-5); }
  .card-body { padding: var(--space-5); }
}

/* ============================================================
   Wizard — one question per screen
   ============================================================ */

.wizard-wrap {
  max-width: 560px; margin: 0 auto;
  padding: var(--space-4) var(--space-4) calc(120px + env(safe-area-inset-bottom, 0px));
}

.progress {
  height: 6px; border-radius: 3px; background: var(--muted);
  overflow: hidden; margin-bottom: var(--space-5);
}
.progress .bar {
  height: 100%; background: var(--accent); border-radius: 3px;
  width: 0%; transition: width .25s ease-out;
}

.step { animation: stepIn .22s ease-out; }
@keyframes stepIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.step .q-kicker {
  font-size: 13px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; color: var(--accent-ink); margin: 0 0 6px;
}
.step h1.q-title {
  font-size: 24px; line-height: 1.25; margin: 0 0 6px; color: var(--ink);
}
.step .q-sub { color: var(--ink-3); font-size: 15px; margin: 0 0 var(--space-5); }

/* Big choice buttons */
.choice-list { display: flex; flex-direction: column; gap: var(--space-3); }
.choice-btn {
  appearance: none; cursor: pointer; text-align: left;
  display: flex; align-items: center; gap: var(--space-3);
  background: var(--surface); color: var(--ink);
  border: 2px solid var(--border); border-radius: 14px;
  padding: var(--space-4); min-height: 64px;
  font: inherit; font-size: 17px; font-weight: 700;
  box-shadow: var(--shadow-1);
  transition: border-color .15s ease, background .15s ease, transform .08s ease;
}
.choice-btn:hover { border-color: var(--accent); }
.choice-btn:active { transform: scale(.985); }
.choice-btn .c-ico {
  width: 44px; height: 44px; flex: none; border-radius: 11px;
  background: var(--accent-soft); display: grid; place-items: center;
}
.choice-btn .c-ico svg { width: 24px; height: 24px; stroke: var(--accent); }
.choice-btn .c-label { flex: 1; min-width: 0; }
.choice-btn .c-desc { display: block; font-size: 13.5px; font-weight: 400; color: var(--ink-3); margin-top: 2px; }
.choice-btn[aria-pressed="true"] {
  border-color: var(--accent); background: var(--accent-soft);
}
.choice-btn[aria-pressed="true"] .c-ico { background: var(--accent); }
.choice-btn[aria-pressed="true"] .c-ico svg { stroke: #fff; }

/* Wizard nav bar */
.wiz-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 90;
  background: rgba(255,255,255,.96);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
  padding: 10px var(--space-4) calc(10px + env(safe-area-inset-bottom, 0px));
}
.wiz-nav .inner {
  max-width: 560px; margin: 0 auto;
  display: flex; gap: var(--space-3); align-items: center;
}
.wiz-nav .btn-back { flex: none; min-width: 96px; }
.wiz-nav .btn-next { flex: 1; }
.wiz-nav .step-count {
  position: absolute; top: -28px; right: var(--space-4);
  background: var(--ink); color: #fff; font-size: 12px; font-weight: 700;
  border-radius: 999px; padding: 4px 10px; opacity: .85;
}

@media (min-width: 768px) {
  .step h1.q-title { font-size: 28px; }
}

/* compact variant for multi-select option lists */
.choice-btn.compact { min-height: 54px; padding: 10px 14px; font-size: 15.5px; border-radius: 11px; }
.choice-btn.compact .c-ico { width: 34px; height: 34px; border-radius: 8px; }
.choice-btn.compact .c-ico svg { width: 19px; height: 19px; }

/* fixed-prefix input (e.g. JAX job numbers) */
.prefix-wrap {
  display: flex; align-items: stretch;
  border: 1.5px solid var(--border); border-radius: 8px;
  background: #fff; overflow: hidden;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.prefix-wrap:focus-within {
  border-color: var(--ring);
  box-shadow: 0 0 0 3px rgba(21, 128, 61, .18);
}
.prefix-wrap .prefix {
  display: flex; align-items: center;
  padding: 0 10px 0 12px;
  background: var(--muted); color: var(--ink-2);
  font-weight: 700; border-right: 1.5px solid var(--border);
}
.prefix-wrap input {
  border: none !important; border-radius: 0 !important;
  box-shadow: none !important; flex: 1; min-width: 0;
}
