/* app.css — mobile-first base styles (Part 3).
   Primary device: Pixel, Chrome, one-handed, outdoors, Florida sun. */

:root {
  --navy: #1F3B57;
  --teal: #2E7D8A;
  --band: #F5F8F9;
  --border: #C7D0D6;
  --gray: #6B7280;
  --ink: #10222f;      /* body text — >7:1 on white for contrast (§3.1) */
  --bg: #ffffff;
  --danger: #b00020;
  --tap: 48px;         /* minimum tap target (§3.1) */
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Helvetica, Arial, sans-serif;
  font-size: 16px;              /* base ≥16px (§3.1) */
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

/* Full-height uses dvh, not vh, to survive Chrome's collapsing address bar (§3.1). */
.app-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}

main {
  flex: 1 1 auto;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 20px 16px calc(24px + env(safe-area-inset-bottom));
}

header.app-header {
  background: var(--navy);
  color: #fff;
  padding: 14px 16px;
  padding-top: calc(14px + env(safe-area-inset-top));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
header.app-header .brand { font-weight: bold; font-size: 17px; letter-spacing: 0.3px; }
header.app-header a { color: #fff; text-decoration: none; }

h1 { font-size: 22px; color: var(--navy); margin: 0 0 16px; }

/* Single column below 640px — never a horizontally scrolling layout (§3.1). */
.stack { display: flex; flex-direction: column; gap: 16px; }

label { display: block; font-size: 16px; font-weight: 600; margin-bottom: 6px; }

input[type="password"],
input[type="text"],
input[type="tel"],
input[type="email"],
input[type="number"],
input[type="date"],
select,
textarea {
  width: 100%;
  min-height: var(--tap);
  font-size: 16px;             /* ≥16px prevents iOS/Chrome zoom-on-focus (§3.1) */
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font-family: inherit;
}
textarea { min-height: 96px; resize: vertical; }
input[type="file"] {
  width: 100%; min-height: var(--tap); font-size: 16px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 10px; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 3px solid var(--teal); outline-offset: 1px; }

.check-row {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 600;
  min-height: var(--tap);
}
.check-row input[type="checkbox"] { width: 24px; height: 24px; min-height: 24px; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* Buttons and link-buttons meet the 48px minimum with 8px spacing (§3.1). */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  min-width: var(--tap);
  padding: 12px 20px;
  font-size: 16px;
  font-weight: 700;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  text-decoration: none;
}
.btn + .btn { margin-top: 8px; }
.btn-primary { background: var(--teal); color: #fff; width: 100%; }
.btn-secondary { background: var(--band); color: var(--navy); border: 1px solid var(--border); }

.error {
  background: #fdecef;
  color: var(--danger);
  border: 1px solid #f4c7d0;
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 16px;
}

.card {
  background: var(--band);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}
.muted { color: var(--gray); font-size: 14px; }

/* Top navigation */
.topnav { display: flex; align-items: center; gap: 16px; }
.topnav a { color: #fff; text-decoration: none; font-weight: 600; min-height: var(--tap); display: inline-flex; align-items: center; }
.inline-form { margin: 0; display: inline; }
.btn-compact { min-height: var(--tap); padding: 10px 14px; width: auto; }

/* Page headings with a trailing action */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.page-head h1 { margin: 0; }
.section-title { font-size: 18px; color: var(--navy); margin: 8px 0; }
.actions-row { display: flex; flex-direction: column; gap: 8px; }

/* Card lists — single column, never a horizontally scrolling table (§3.1) */
.card-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.card-list .card { padding: 14px 16px; }
.card-link {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  text-decoration: none; color: var(--navy); font-weight: 700; min-height: 32px;
}
.card-title { font-size: 17px; }

/* Badges / status pills */
.badge {
  display: inline-block; font-size: 13px; font-weight: 700; padding: 3px 10px;
  border-radius: 999px; background: #e6edf0; color: var(--navy); white-space: nowrap;
  text-transform: capitalize;
}
.badge-pm { background: var(--teal); color: #fff; }
.status-lead { background: #e6edf0; color: #33475b; }
.status-assessed { background: #e3ecff; color: #274690; }
.status-quoted { background: #dcf1f4; color: #1c5b66; }
.status-accepted { background: #dff3e4; color: #1e6b34; }
.status-in_progress { background: #fff0d6; color: #8a5a00; }
.status-complete { background: #dff3e4; color: #14532d; }
.status-invoiced { background: #ede4ff; color: #5b3aa0; }
.status-paid { background: #cdefd6; color: #14532d; }
.status-declined { background: #fdecef; color: #b00020; }

/* Definition-list detail rows */
dl.detail { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; }
dl.detail dt { color: var(--gray); font-weight: 600; }
dl.detail dd { margin: 0; }
dl.detail a { color: var(--teal); }

/* ---- Quote builder ---- */
.menu-block { margin-bottom: 8px; }
.menu-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.tab {
  min-height: var(--tap); padding: 8px 16px; border-radius: 999px; font-size: 15px; font-weight: 700;
  border: 1px solid var(--border); background: #fff; color: var(--navy);
}
.tab-active { background: var(--navy); color: #fff; border-color: var(--navy); }
.menu-items { display: flex; flex-direction: column; gap: 8px; }
.add-item {
  min-height: var(--tap); text-align: left; padding: 12px 16px; font-size: 16px; font-weight: 600;
  border: 1px dashed var(--border); border-radius: 10px; background: var(--band); color: var(--navy);
}

.line { padding: 14px 16px; }
.line-amber { border-color: #d98a2b; border-width: 2px; background: #fff7ec; } /* low-confidence parse (§8.1) */
.line-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.line .remove { background: #fff; color: var(--danger); border-color: #f0c8cf; }
.field-inline { display: flex; align-items: center; gap: 8px; font-weight: 600; margin-top: 8px; }
.field-inline select, .field-inline input { max-width: 60%; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: var(--tap); padding: 6px 14px; border-radius: 999px; font-size: 14px; font-weight: 600;
  border: 1px solid var(--border); background: #fff; color: var(--navy);
}
.chip-on { background: var(--teal); color: #fff; border-color: var(--teal); }

.footer-spacer { height: 168px; }

/* Sticky price footer — fixed to the bottom, always visible (§3.2).
   dvh-safe and respects the safe-area inset so it survives address-bar
   collapse, keyboard open and rotation. */
.price-footer {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: var(--navy);
  color: #fff;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  box-shadow: 0 -4px 16px rgba(0,0,0,0.18);
  z-index: 50;
}
.price-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.price-main { display: flex; flex-direction: column; }
.price-label { font-size: 13px; opacity: 0.85; }
.price-value { font-size: 30px; font-weight: 800; line-height: 1.1; }
.price-footer .btn-primary { width: auto; }
.price-meta { font-size: 13px; opacity: 0.9; margin-top: 6px; }
.slider-row { display: flex; align-items: center; gap: 12px; margin-top: 10px; }
.slider-row input[type="range"] { flex: 1; min-height: var(--tap); accent-color: var(--teal); }
.override-input {
  width: 96px; min-height: var(--tap); font-size: 16px; text-align: right;
  border-radius: 8px; border: 1px solid #4a637a; background: #16304a; color: #fff; padding: 6px 10px;
}
.warn { margin-top: 8px; font-size: 14px; font-weight: 700; color: #ffd9a8; }
.price-value-dark { font-size: 28px; font-weight: 800; color: var(--navy); margin: 0 0 8px; }

/* Margin panel (§7.4) — internal only, visually distinct from customer content */
.margin-panel {
  background: #10222f;               /* dark, unmistakably not customer-facing */
  color: #eaf1f5;
  border-radius: 12px;
  padding: 16px;
  margin-top: 16px;
}
.margin-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.margin-head > span:first-child { font-size: 17px; font-weight: 800; }
.internal-tag {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
  color: #0f2233; background: #ffd9a8; padding: 3px 8px; border-radius: 6px;
}
.margin-rows { margin: 0; }
.mrow { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 4px 0; }
.mrow dt { color: #a9c0cf; margin: 0; font-weight: 600; }
.mrow dd { margin: 0; font-variant-numeric: tabular-nums; }
.mrow.total { border-top: 1px solid #2c4257; margin-top: 6px; padding-top: 10px; font-weight: 800; }
.mrow.total dt { color: #eaf1f5; }
.mrow.rate dd.rate { font-size: 18px; font-weight: 800; }
.rate-red { color: #ff9a9a; }
.rate-amber { color: #ffcf7a; }
.rate-green { color: #86e6a8; }
.margin-warn {
  margin: 10px 0 0; font-size: 14px; font-weight: 600; color: #10222f;
  background: #ffd9a8; border-radius: 8px; padding: 10px 12px;
}

/* Work log (§11.5) — big thumb targets for dirty hands */
.summary-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; text-align: center; }
.summary-grid .price-value-dark { font-size: 24px; margin: 0; }
.log-actions { display: flex; gap: 12px; margin: 8px 0; }
.log-actions form { flex: 1; margin: 0; }
.btn-log { width: 100%; min-height: 64px; font-size: 20px; }

/* Shopping list (§7.6) */
.shop-total { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.shop-total .price-value-dark { margin: 0; }
.aisle-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.shop-list { list-style: none; margin: 0 0 8px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.shop-row {
  display: flex; align-items: center; gap: 10px; min-height: var(--tap);
  padding: 8px 12px; border: 1px solid var(--border); border-radius: 10px; background: #fff;
}
.shop-row input[type="checkbox"] { width: 24px; height: 24px; min-height: 24px; flex: 0 0 auto; }
.shop-qty { font-weight: 700; color: var(--navy); flex: 0 0 auto; }
.shop-label { flex: 1 1 auto; }
.shop-cost { font-variant-numeric: tabular-nums; color: var(--gray); flex: 0 0 auto; }
.shop-row.done { background: var(--band); }
.shop-row.done .shop-label, .shop-row.done .shop-qty { text-decoration: line-through; color: var(--gray); }

/* Stats tables (§14) — wide tables scroll inside their own container so the
   page body never scrolls horizontally (§3.1) */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.stats-table { border-collapse: collapse; width: 100%; font-size: 14px; }
.stats-table th, .stats-table td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
.stats-table th { color: var(--gray); font-weight: 700; }
.stats-table td { font-variant-numeric: tabular-nums; }
.stats-table code { font-size: 13px; }

/* Photo gallery */
.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 16px; }
.photo-thumb { display: block; aspect-ratio: 1 / 1; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* No hover-dependent interaction (§3.1): all affordances are visible without hover. */

/* --- Assistant chat panel (§13) --- */
.assistant-panel { display: flex; flex-direction: column; gap: 12px; }
.assistant-log { display: flex; flex-direction: column; gap: 10px; max-height: 420px; overflow-y: auto; }
.assistant-empty { margin: 0; }
.assistant-msg { max-width: 92%; padding: 10px 12px; border-radius: 12px; }
.assistant-user { align-self: flex-end; background: var(--navy); color: #fff; }
.assistant-assistant { align-self: flex-start; background: var(--band); color: var(--ink); border: 1px solid var(--border); }
.assistant-text { margin: 0; white-space: pre-wrap; }
.assistant-proposal { margin-top: 8px; padding: 10px; border-radius: 10px; background: #fff; border: 1px dashed var(--teal); display: flex; flex-direction: column; gap: 6px; }
.proposal-label { margin: 0; font-weight: 700; color: var(--teal); font-size: 14px; }
.proposal-body { margin: 0; }
.proposal-copy { padding: 8px; background: var(--band); border-radius: 8px; user-select: all; }
.assistant-form textarea { width: 100%; min-height: var(--tap); font-size: 16px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; color: var(--ink); }

/* --- Search (§13.6) --- */
.search-form input[type="search"] { width: 100%; min-height: var(--tap); font-size: 16px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; }
.search-snippet { margin: 6px 0 0; }

/* --- Field mode (§15) — full-bleed, thumb-reachable, fixed bottom bar --- */
.field { padding: 12px 12px 96px; }
.field-top { margin-bottom: 12px; }
.field-job {
  width: 100%; min-height: var(--tap); display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 12px 16px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--band); color: var(--navy); font-size: 18px; font-weight: 700;
}
.field-job-change { font-size: 13px; font-weight: 600; color: var(--teal); }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  min-height: 40vw; padding: 16px; border-radius: 16px; border: 1px solid var(--border);
  background: #fff; color: var(--navy); text-align: center;
}
.tile-label { font-size: 20px; font-weight: 800; letter-spacing: 0.01em; }
.tile-sub { font-size: 13px; color: var(--gray); }
.tile-time { background: var(--band); }
.tile-actions { display: flex; gap: 10px; width: 100%; }
.tile-btn {
  flex: 1; min-height: var(--tap); border-radius: 12px; border: none;
  background: var(--teal); color: #fff; font-size: 20px; font-weight: 800;
}
.tile-action { background: var(--navy); color: #fff; }
.tile-action .tile-sub { color: #cfe0e6; }

.field-sync { display: flex; align-items: center; gap: 12px; margin-top: 16px; }
.pending-badge {
  min-height: 32px; display: inline-flex; align-items: center; padding: 4px 12px;
  border-radius: 999px; background: var(--danger); color: #fff; font-weight: 700; font-size: 14px;
}

.field-bar {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; align-items: center; gap: 8px;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); background: var(--navy); color: #fff;
}
.field-bar-stat { display: flex; flex-direction: column; line-height: 1.1; }
.field-bar-stat strong { font-size: 20px; }
.field-bar-stat span { font-size: 12px; color: #cfe0e6; }
.field-bar-link { margin-left: auto; color: #fff; font-weight: 700; min-height: var(--tap); display: inline-flex; align-items: center; }

.field-overlay {
  position: fixed; inset: 0; z-index: 20; background: var(--bg); display: flex; flex-direction: column;
  gap: 12px; padding: 12px calc(12px + env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom));
}
.overlay-head { display: flex; align-items: center; gap: 12px; }
.overlay-head span { font-weight: 800; font-size: 18px; }
.overlay-head .btn { margin-left: auto; }
.overlay-close {
  min-width: var(--tap); min-height: var(--tap); border-radius: 10px; border: 1px solid var(--border);
  background: var(--band); color: var(--navy); font-size: 18px;
}
.overlay-textarea { flex: 1; width: 100%; font-size: 18px; padding: 12px; border: 1px solid var(--border); border-radius: 10px; }
.overlay-field { display: flex; flex-direction: column; gap: 6px; font-weight: 600; }
.overlay-field input { min-height: var(--tap); font-size: 18px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; }
.overlay-check { display: flex; align-items: center; gap: 10px; min-height: var(--tap); font-weight: 600; }

.picker-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.picker-item {
  display: flex; flex-direction: column; gap: 2px; min-height: var(--tap); padding: 12px 16px;
  border: 1px solid var(--border); border-radius: 12px; background: #fff;
}
.picker-title { font-weight: 700; color: var(--navy); }
.picker-sub { font-size: 13px; color: var(--gray); }

/* The hidden attribute must always win over display overrides (field overlays,
   the pending badge). Without this, `.field-overlay{display:flex}` etc. keep a
   [hidden] element visible. */
[hidden] { display: none !important; }
