/* QuotePad — mobile-first design system for estimates & invoices.
   Large touch targets, strong contrast, money-professional green accent.
   Shares its DNA with the SnapInspect / MailMate apps in this repo. */

:root {
  --bg: #f3f3f5;
  --surface: #ffffff;
  --surface-2: #fafafa;
  --line: #e0e0e6;
  --line-strong: #c4c4cc;
  --ink: #1a1a1f;
  --ink-2: #54545d;
  --ink-3: #8a8a93;
  --accent: #1f7a3d;
  --accent-ink: #ffffff;
  --good: #1c6b39;
  --good-bg: #e7f6ec;
  --fair: #8a5a00;
  --fair-bg: #fff4e0;
  --poor: #99500f;
  --poor-bg: #fde8d8;
  --hazard: #9b1c1c;
  --hazard-bg: #fdecea;
  --radius: 16px;
  --radius-sm: 11px;
  --tap: 54px;
  --shadow: 0 1px 2px rgba(0,0,0,0.05), 0 6px 16px rgba(0,0,0,0.05);
  --maxw: 560px;
  --nav-h: 60px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

html[data-theme='dark'] {
  --bg: #0d0d0f;
  --surface: #18181b;
  --surface-2: #202024;
  --line: #2b2b31;
  --line-strong: #3a3a42;
  --ink: #fafafa;
  --ink-2: #b6b6be;
  --ink-3: #80808a;
  --accent-ink: #ffffff;
  --good: #4ade80; --good-bg: #0f2b1a;
  --fair: #fbbf24; --fair-bg: #2a2008;
  --poor: #fb923c; --poor-bg: #2a1709;
  --hazard: #f87171; --hazard-bg: #2a0e0e;
  --shadow: 0 1px 2px rgba(0,0,0,0.4), 0 6px 18px rgba(0,0,0,0.35);
}

/* ---- palettes (retint accent) ------------------------------------------- */
html[data-palette='forest']   { --accent: #1f7a3d; }
html[data-theme='dark'][data-palette='forest']   { --accent: #34d399; --accent-ink: #04140b; }
html[data-palette='teal']     { --accent: #0d7a78; }
html[data-theme='dark'][data-palette='teal']     { --accent: #2dd4bf; --accent-ink: #042524; }
html[data-palette='pine']     { --accent: #15604a; }
html[data-theme='dark'][data-palette='pine']     { --accent: #34d399; --accent-ink: #04140b; }
html[data-palette='charcoal'] { --accent: #2b2b30; }
html[data-theme='dark'][data-palette='charcoal'] { --accent: #fafafa; --accent-ink: #0d0d0f; }
html[data-palette='brick']    { --accent: #9b2c2c; }
html[data-theme='dark'][data-palette='brick']    { --accent: #ef4444; --accent-ink: #1a0606; }
html[data-palette='slate']    { --accent: #1d4ed8; }
html[data-theme='dark'][data-palette='slate']    { --accent: #3b82f6; --accent-ink: #08111f; }
html[data-palette='contrast'] { --accent: #000000; --line: #000; --line-strong: #000; --ink-2: #000; }
html[data-theme='dark'][data-palette='contrast'] { --accent: #fff; --accent-ink: #000; --line: #fff; --line-strong: #fff; --ink-2: #fff; }

* { box-sizing: border-box; }

button, a, .btn, .chip, .iconbtn, input, select, textarea,
.cond-chip, .seg, .swatch, .menu-item, .add-photo, .thumb-wrap {
  touch-action: manipulation;
}

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: contain;
  line-height: 1.45;
}

#app {
  max-width: var(--maxw);
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  position: relative;
  background: var(--bg);
}

/* ---- app bar ------------------------------------------------------------- */
.appbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 14px;
  padding-top: max(12px, env(safe-area-inset-top, 0px));
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.bar-title { flex: 1; text-align: center; }
.appbar h1 { font-size: 1.2rem; margin: 0; letter-spacing: -0.01em; }
.brandmark {
  width: 40px; height: 40px; border-radius: 11px;
  background: var(--accent); color: var(--accent-ink);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 1.1rem;
}
.iconbtn {
  width: 44px; height: 44px; flex: none;
  border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink);
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 1.15rem;
}
.iconbtn.sm { width: 34px; height: 34px; border-radius: 9px; font-size: 0.9rem; }
.iconbtn:active { transform: scale(0.95); }

/* ---- layout -------------------------------------------------------------- */
.screen {
  padding: 16px 14px calc(var(--nav-h) + 28px + var(--safe-b));
  display: flex; flex-direction: column; gap: 14px;
  animation: rise 0.18s ease;
}
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.section-label {
  font-size: 0.73rem; text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--ink-3); font-weight: 700; margin: 8px 2px -2px;
}
.pad { padding: 8px 2px; }
.muted { color: var(--ink-3); }
.sm { font-size: 0.8rem; }
.grow { flex: 1; }
.desc { color: var(--ink-3); font-size: 0.82rem; }

/* ---- cards --------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 10px;
}

/* ---- buttons ------------------------------------------------------------- */
.btn {
  min-height: var(--tap);
  border-radius: 13px; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink);
  font-size: 1rem; font-weight: 700; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 0 16px; user-select: none; -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.97); }
.btn.block { width: 100%; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.good { background: var(--good); color: #fff; border-color: var(--good); }
.btn.danger { background: transparent; color: var(--hazard); border-color: var(--hazard); }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--ink-2); }
.btn.lg { min-height: 60px; font-size: 1.08rem; }
.btn.sm { min-height: 42px; font-size: 0.88rem; padding: 0 12px; border-radius: 10px; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-row { display: flex; gap: 10px; }
.btn-row > .btn { flex: 1; }

/* ---- inputs -------------------------------------------------------------- */
input[type='text'], input[type='number'], input[type='date'], input[type='tel'],
input[type='email'], input[type='search'], textarea, select {
  width: 100%; min-height: var(--tap);
  border: 1px solid var(--line-strong); border-radius: 11px;
  background: var(--surface); color: var(--ink);
  padding: 11px 13px; font-size: 1rem; font-family: inherit;
}
textarea { min-height: 80px; resize: vertical; line-height: 1.5; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
label.field { display: flex; flex-direction: column; gap: 5px; font-size: 0.82rem; color: var(--ink-2); font-weight: 600; flex: 1; }
.field-row { display: flex; gap: 10px; }
.search { font-size: 1rem; }

/* ---- chips --------------------------------------------------------------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink-2);
  border-radius: 999px; padding: 8px 14px; font-size: 0.85rem; font-weight: 600;
  cursor: pointer; min-height: 40px; display: inline-flex; align-items: center;
}
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* ---- empty state --------------------------------------------------------- */
.empty { text-align: center; color: var(--ink-3); padding: 44px 16px; }
.empty .ico { font-size: 2.4rem; display: block; margin-bottom: 10px; opacity: 0.8; }
.empty .title { font-weight: 700; color: var(--ink-2); font-size: 1.05rem; }
.empty .sub { font-size: 0.85rem; margin-top: 4px; }

/* ---- inspection cards (home) -------------------------------------------- */
.insp-card { flex-direction: row; align-items: stretch; padding: 0; gap: 0; overflow: hidden; }
.insp-main { flex: 1; padding: 14px; cursor: pointer; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.insp-top { display: flex; align-items: center; gap: 10px; }
.insp-name { font-weight: 800; font-size: 1.05rem; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.insp-sub { color: var(--ink-2); font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.insp-meta { display: flex; align-items: center; gap: 10px; font-size: 0.78rem; color: var(--ink-3); }
.insp-meta .haz { color: var(--hazard); font-weight: 700; }
.insp-menu { align-self: center; margin-right: 8px; border: 0; background: transparent; font-size: 1.4rem; color: var(--ink-3); }
.pill {
  font-size: 0.72rem; font-weight: 800; padding: 3px 10px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--line-strong); color: var(--ink-2);
}
.pill.done { background: var(--good-bg); color: var(--good); border-color: transparent; }
.pill.draft { background: var(--surface-2); color: var(--ink-2); }

/* progress bar */
.progress { height: 7px; border-radius: 999px; background: var(--line); overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width 0.25s ease; }
.prog-row { display: flex; align-items: center; justify-content: space-between; }
.prog-label { font-size: 0.8rem; color: var(--ink-3); font-weight: 600; }

/* ---- editor: components ------------------------------------------------- */
.comp-list { display: flex; flex-direction: column; gap: 12px; }
.comp-card { gap: 12px; }
.comp-head { display: flex; align-items: center; gap: 10px; }
.comp-title { font-weight: 800; font-size: 1rem; flex: 1; cursor: pointer; }
.comp-title::after { content: ' ✎'; color: var(--ink-3); font-size: 0.8rem; }

.cond-chips { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.cond-chip {
  border: 1px solid var(--line-strong); background: var(--surface);
  border-radius: 10px; padding: 8px 2px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  color: var(--ink-2); min-height: 56px; justify-content: center;
}
.cond-chip .cc-ico { font-size: 1.05rem; line-height: 1; }
.cond-chip .cc-lbl { font-size: 0.66rem; font-weight: 700; }
.cond-chip.on { color: #fff; border-color: transparent; }
.cond-chip.cond-good.on { background: var(--good); }
.cond-chip.cond-fair.on { background: var(--fair); }
.cond-chip.cond-poor.on { background: var(--poor); }
.cond-chip.cond-hazard.on { background: var(--hazard); }
.cond-chip.cond-na.on { background: var(--ink-3); }
html[data-theme='dark'] .cond-chip.on { color: #0d0d0f; }
.comp-notes { min-height: 56px; }

/* ---- editor: dimensions ------------------------------------------------- */
.dim-list { display: flex; flex-direction: column; gap: 8px; }
.dim-row { display: flex; gap: 6px; align-items: center; }
.dim-row .dim-label { flex: 2; }
.dim-row .dim-value { flex: 1.2; }
.dim-row .dim-unit { flex: 0.8; min-width: 54px; }
.dim-row input { min-height: 46px; padding: 8px 10px; }

/* ---- photos ------------------------------------------------------------- */
.photo-strip { display: flex; flex-wrap: wrap; gap: 8px; }
.photo-strip.empty { display: none; }
.thumb-wrap { position: relative; width: 76px; cursor: pointer; }
.thumb { width: 76px; height: 76px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line-strong); display: block; }
.thumb-cap {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.6); color: #fff; font-size: 0.6rem; padding: 2px 4px;
  border-radius: 0 0 10px 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.add-photo { width: 100%; }
.viewer-img { width: 100%; border-radius: 12px; max-height: 60vh; object-fit: contain; background: var(--surface-2); }

/* ---- signatures --------------------------------------------------------- */
.sig-grid { display: flex; flex-direction: column; gap: 14px; }
.sig-block { display: flex; flex-direction: column; gap: 8px; }
.sig-top { display: flex; align-items: baseline; gap: 8px; }
.sig-name { font-weight: 700; }
.sig-preview {
  border: 1px dashed var(--line-strong); border-radius: 11px;
  min-height: 64px; background: var(--surface-2);
  display: flex; align-items: center; justify-content: center; padding: 6px;
}
.sig-preview img { max-height: 70px; max-width: 100%; }
.sig-pad { border: 1px solid var(--line-strong); border-radius: 12px; background: #fff; overflow: hidden; }
.sig-canvas { width: 100%; display: block; touch-action: none; background: #fff; }

.logo-preview {
  border: 1px dashed var(--line-strong); border-radius: 11px; min-height: 60px;
  background: var(--surface-2); display: flex; align-items: center; justify-content: center; padding: 8px;
}
.logo-preview img { max-height: 60px; max-width: 100%; }

/* ---- editor actions ----------------------------------------------------- */
.editor-actions { margin-top: 8px; display: flex; flex-direction: column; }

/* ---- badges (condition) ------------------------------------------------- */
.badge { display: inline-flex; align-items: center; gap: 3px; font-size: 0.72rem; font-weight: 700; padding: 3px 9px; border-radius: 999px; }
.badge.cond-good { background: var(--good-bg); color: var(--good); }
.badge.cond-fair { background: var(--fair-bg); color: var(--fair); }
.badge.cond-poor { background: var(--poor-bg); color: var(--poor); }
.badge.cond-hazard { background: var(--hazard-bg); color: var(--hazard); }
.badge.cond-na { background: var(--surface-2); color: var(--ink-3); }

/* ---- segmented + swatches (settings) ------------------------------------ */
.segmented { display: flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 4px; gap: 4px; }
.seg { flex: 1; min-height: 42px; border: 0; border-radius: 9px; background: transparent; color: var(--ink-2); font-weight: 700; font-size: 0.9rem; cursor: pointer; }
.seg.on { background: var(--accent); color: var(--accent-ink); }
.swatch-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.swatch { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 6px; border: 2px solid var(--line); border-radius: 14px; background: var(--surface); cursor: pointer; color: var(--ink-2); font-size: 0.72rem; font-weight: 600; }
.swatch .dot { width: 32px; height: 32px; border-radius: 50%; border: 1px solid rgba(0,0,0,0.15); }
.swatch.on { border-color: var(--accent); color: var(--ink); }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 6px 0; }
.set-row .label { font-weight: 600; }

/* ---- toast --------------------------------------------------------------- */
#toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-b));
  transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--bg);
  padding: 12px 18px; border-radius: 999px; font-weight: 600; font-size: 0.9rem;
  box-shadow: var(--shadow); opacity: 0; pointer-events: none;
  transition: opacity 0.2s, transform 0.2s; z-index: 80; max-width: 90%; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---- modal --------------------------------------------------------------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  display: flex; align-items: flex-end; justify-content: center; z-index: 60;
  animation: fade 0.15s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--surface); width: 100%; max-width: var(--maxw);
  border-radius: 20px 20px 0 0; padding: 18px 16px calc(18px + var(--safe-b));
  box-shadow: var(--shadow); animation: rise 0.2s ease;
  max-height: 92vh; overflow-y: auto;
}
.modal h3 { margin: 4px 0 14px; }
.modal .modal-actions { display: flex; gap: 10px; margin-top: 16px; }
.modal .modal-actions .btn { flex: 1; }
.menu-item {
  display: flex; align-items: center; gap: 14px; width: 100%;
  min-height: 54px; border: 0; border-bottom: 1px solid var(--line);
  background: transparent; color: var(--ink); font-size: 1rem; font-weight: 600;
  cursor: pointer; text-align: left; padding: 6px 4px;
}
.menu-item:last-child { border-bottom: 0; }
.menu-item.danger { color: var(--hazard); }
.menu-item .mi-ico { font-size: 1.2rem; width: 26px; text-align: center; }

.email-status { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); margin-left: 6px; vertical-align: middle; }
.email-status.on { background: var(--good); }

/* ---- footer -------------------------------------------------------------- */
.brand-foot { text-align: center; color: var(--ink-3); font-size: 0.72rem; padding: 12px 0 4px; }

/* =========================================================================
   QuotePad-specific components
   ========================================================================= */

/* ---- bottom navigation --------------------------------------------------- */
.tabbar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: var(--maxw);
  height: calc(var(--nav-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  display: flex; background: var(--surface);
  border-top: 1px solid var(--line); z-index: 30;
}
.tab {
  flex: 1; border: 0; background: transparent; color: var(--ink-3);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; cursor: pointer; font-size: 0.66rem; font-weight: 600;
  -webkit-tap-highlight-color: transparent;
}
.tab .ico { font-size: 1.3rem; line-height: 1; }
.tab.on { color: var(--accent); }
.tab.on .ico { transform: translateY(-1px); }

/* ---- home summary header ------------------------------------------------- */
.summary { flex-direction: row; gap: 0; padding: 0; overflow: hidden; }
.sum-col { flex: 1; padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; }
.sum-col + .sum-col { border-left: 1px solid var(--line); }
.sum-k { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-3); font-weight: 700; }
.sum-v { font-size: 1.35rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.sum-v.good { color: var(--good); }

/* ---- document cards (home) ---------------------------------------------- */
.doc-card { flex-direction: row; align-items: stretch; padding: 0; gap: 0; overflow: hidden; }
.doc-main { flex: 1; padding: 14px; cursor: pointer; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.doc-top { display: flex; align-items: center; gap: 10px; }
.doc-name { font-weight: 800; font-size: 1.05rem; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-sub { color: var(--ink-2); font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-type { font-weight: 700; }
.doc-type.invoice { color: var(--accent); }
.doc-type.estimate { color: var(--ink-2); }
.doc-meta { display: flex; align-items: center; gap: 10px; font-size: 0.8rem; color: var(--ink-3); }
.doc-total { font-weight: 800; color: var(--ink); font-variant-numeric: tabular-nums; }
.doc-menu { align-self: center; margin-right: 8px; border: 0; background: transparent; font-size: 1.4rem; color: var(--ink-3); }

/* ---- editor: line items -------------------------------------------------- */
.item-list { display: flex; flex-direction: column; gap: 10px; }
.item-head { display: none; }
.item-row {
  display: flex; flex-direction: column; gap: 6px;
  padding: 10px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.item-desc { width: 100%; min-height: 46px; padding: 8px 10px; }
.item-nums { display: flex; align-items: center; gap: 6px; }
.item-qty, .item-rate { flex: 1; min-height: 46px; padding: 8px 10px; min-width: 0; }
.item-amt { flex: 1; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; padding-right: 4px; }

/* ---- editor: totals box -------------------------------------------------- */
.totals-box { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 12px; display: flex; flex-direction: column; gap: 6px; }
.tot-row { display: flex; justify-content: space-between; font-size: 0.92rem; color: var(--ink-2); }
.tot-row .tot-v { font-variant-numeric: tabular-nums; }
.tot-row.grand { font-size: 1.2rem; font-weight: 800; color: var(--ink); margin-top: 4px; padding-top: 8px; border-top: 1px solid var(--line); }
