/* CreteGenie — main stylesheet */
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
:root {
  --bg: #0f1115;
  --panel: #16181d;
  --panel2: #1b1e24;
  --border: #24262c;
  --border2: #2e3138;
  --text: #d6d6d9;
  --text-dim: #8a8d95;
  --text-faint: #5a5d65;
  --accent: #1AA7C4;
  --accent-hi: #3FC0DD;
  --amber: #E8923A;
  --amber-hi: #F2B25A;
  --green: #4ade80;
  --red: #f87171;
  --blue: #60a5fa;
  --radius: 10px;
  --sidebar-w: 220px;
}
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px;
  overscroll-behavior: none;
}
.hidden { display: none !important; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #2e3138; border-radius: 3px; }

/* ── Login ── */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-box { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 32px; }
.brand-row { display: flex; align-items: center; gap: 12px; margin-bottom: 28px; }
.brand-mark { width: 42px; height: 42px; border-radius: 10px; background-image: url('logo-mark.svg'); background-size: contain; background-repeat: no-repeat; background-position: center; flex-shrink: 0; font-size: 0; }
.brand-mark.sm { width: 32px; height: 32px; border-radius: 8px; }
.brand-name { font-size: 18px; font-weight: 700; color: #fff; }
.brand-sub { font-size: 9px; letter-spacing: 1.5px; color: var(--text-faint); font-weight: 600; }
.login-error { background: #2a1212; border: 1px solid #7f1d1d; color: #fca5a5; padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 14px; }

/* ── Fields & buttons ── */
.field-label { display: block; font-size: 11.5px; font-weight: 600; color: var(--text-dim); margin: 16px 0 7px; text-transform: uppercase; letter-spacing: .5px; }
.field { width: 100%; padding: 12px 14px; border-radius: 9px; border: 1px solid var(--border2); background: var(--bg); color: #fff; font-size: 14px; font-family: inherit; transition: border-color .15s, box-shadow .15s; }
.field:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(26,167,196,.15); }
.field.linkfield { border-color: var(--accent); background: rgba(26,167,196,.12); color: var(--accent-hi); font-weight: 600; }
/* two short fields side by side; collapses on narrow screens */
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
@media (max-width: 520px) { .field-row { grid-template-columns: 1fr; } }
.modal-hint { font-size: 12.5px; color: var(--text-dim); margin: 6px 0 2px; line-height: 1.5; }
/* full-page builder (Proposals, Invoices) */
.builder { max-width: 860px; }
.builder-head { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.builder-actions { display: flex; gap: 10px; justify-content: flex-end; position: sticky; bottom: 0; background: linear-gradient(to top, var(--bg) 72%, rgba(15,17,21,0)); padding: 16px 0 10px; margin-top: 4px; z-index: 5; }
textarea.field { resize: vertical; min-height: 70px; }
select.field { appearance: none; }
.btn-primary { padding: 11px 20px; border: none; border-radius: 8px; background: var(--accent); color: #fff; font-size: 14px; font-weight: 700; cursor: pointer; font-family: inherit; transition: background .15s; }
.btn-primary:hover { background: var(--accent-hi); }
.btn-primary:disabled { opacity: .5; cursor: default; }
.btn-block { width: 100%; margin-top: 22px; }
.btn { padding: 9px 16px; border: 1px solid var(--border2); border-radius: 8px; background: var(--panel2); color: var(--text); font-size: 13px; font-weight: 600; cursor: pointer; font-family: inherit; transition: all .15s; }
.btn:hover { border-color: #3e4148; color: #fff; }
.btn.danger { color: var(--red); }
.btn.sm { padding: 6px 12px; font-size: 12px; }

/* ── App layout ── */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: fixed; top: 0; bottom: 0; left: 0; z-index: 50;
  transition: transform .25s ease;
  /* Respect the iPhone notch / status bar when installed to the home screen. */
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px);
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 18px 16px; border-bottom: 1px solid var(--border); }
.sidebar-company { font-weight: 700; color: #fff; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-items { flex: 1; padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px;
  color: var(--text-dim); font-size: 13px; font-weight: 500; cursor: pointer; text-decoration: none;
  transition: all .15s;
}
.nav-item:hover { background: var(--panel2); color: var(--text); }
.nav-item.active { background: #221708; color: var(--accent-hi); }
.nav-ico { width: 18px; text-align: center; font-size: 13px; opacity: .8; }
.nav-section { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .8px; color: var(--text-faint); padding: 12px 12px 4px; margin-top: 4px; user-select: none; }
.nav-section:first-of-type { margin-top: 0; }
.sidebar-foot { padding: 10px; border-top: 1px solid var(--border); }
.whoami { padding: 4px 12px 10px; }
.whoami-name { font-size: 13px; font-weight: 700; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.whoami-role { font-size: 11px; color: var(--text-faint); margin-top: 1px; }

.topbar { display: none; }
.bottombar { display: none; }   /* mobile-only bar — re-shown in the max-width:860px block below */
.main { flex: 1; margin-left: var(--sidebar-w); padding: 28px; padding-top: calc(28px + var(--trial-banner-h, 0px) + var(--cg-upgrade-h, 0px)); min-width: 0; }
/* Trial countdown banner — fixed across the top of the content area (right of the fixed
   sidebar) so it never becomes a flex column in the sidebar|main row. JS reports its height
   into --trial-banner-h so .main padding clears it. */
#trial-banner { position: fixed; top: 0; left: var(--sidebar-w); right: 0; z-index: 45; display: flex; align-items: center; justify-content: center; gap: 14px; padding: 9px 16px; color: #fff; font-size: 13.5px; font-weight: 600; flex-wrap: wrap; }
/* Free-first "finish upgrading" bar — SAME fix as #trial-banner (they never show together:
   trialing vs active-on-Free). Fixed across the top of the content area so it spans the full
   width instead of collapsing into a clipped column in the sidebar|main flex row. JS reports
   its height into --cg-upgrade-h so .main padding clears it. (v3.99.223) */
#cg-upgrade-bar { position: fixed; top: 0; left: var(--sidebar-w); right: 0; z-index: 44; display: flex; align-items: center; gap: 12px; padding: 10px 16px; font-size: 13.5px; flex-wrap: wrap; background: linear-gradient(90deg, rgba(26,167,196,.22), rgba(26,167,196,.07)); border-bottom: 1px solid rgba(26,167,196,.34); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }

/* (v3.99.282) Tap-outside-to-close backdrop for the mobile nav drawer. Desktop never shows it —
   there the sidebar is docked, not overlaid — so it is display:none until the phone breakpoint. */
.nav-scrim { display: none; }

@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: 0 0 60px rgba(0,0,0,.6); }
  /* Sits under the drawer (z 50) but over the topbar (40), banners (44/45) and bottom bar (45),
     so while the drawer is open the only thing a tap can hit is "close the drawer" — it can no
     longer land on a button underneath. Modals are z 100 and stay above it. cursor:pointer is
     required, not cosmetic: iOS Safari won't dispatch click on a plain div without it. */
  .nav-scrim {
    display: block; position: fixed; inset: 0; z-index: 49; cursor: pointer;
    background: rgba(0,0,0,.45); opacity: 0; pointer-events: none;
    transition: opacity .25s ease; -webkit-tap-highlight-color: transparent;
  }
  .nav-scrim.show { opacity: 1; pointer-events: auto; }
  /* Content clears the fixed topbar AND the notch; bottom clears the home indicator. */
  .main {
    margin-left: 0; padding: 16px;
    padding-top: calc(70px + env(safe-area-inset-top, 0px) + var(--trial-banner-h, 0px) + var(--cg-upgrade-h, 0px));
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    padding-left: calc(16px + env(safe-area-inset-left, 0px));
    padding-right: calc(16px + env(safe-area-inset-right, 0px));
  }
  /* On phones the banner sits just below the fixed mobile topbar, full width. */
  #trial-banner { left: 0; top: calc(54px + env(safe-area-inset-top, 0px)); }
  #cg-upgrade-bar { left: 0; top: calc(54px + env(safe-area-inset-top, 0px)); }
  .topbar {
    display: flex; align-items: center; gap: 14px; position: fixed; top: 0; left: 0; right: 0;
    height: 54px; background: var(--panel); border-bottom: 1px solid var(--border); z-index: 40;
    padding: 0 14px;
    /* Push the bar's content below the notch and extend its background up into it. */
    padding-top: env(safe-area-inset-top, 0px);
    height: calc(54px + env(safe-area-inset-top, 0px));
    padding-left: calc(14px + env(safe-area-inset-left, 0px));
    /* iOS Safari/PWA: a fixed bar can flicker or vanish at the scroll extremes when the
       dynamic toolbar resizes the viewport. Promoting it to its own compositing layer
       (translateZ + backface-visibility) keeps it pinned and stable. */
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    will-change: transform;
  }
  .menu-btn { background: none; border: none; color: var(--text); font-size: 20px; cursor: pointer; padding: 6px; }
  .topbar-title { font-weight: 700; color: #fff; font-size: 15px; }
  /* Mobile bottom tab bar — one-tap nav, slides away while scrolling down. */
  .bottombar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
    background: var(--panel); border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    transform: translateY(0) translateZ(0);
    transition: transform .26s cubic-bezier(.4,0,.2,1);
    -webkit-backface-visibility: hidden; backface-visibility: hidden; will-change: transform;
  }
  .bottombar.down { transform: translateY(115%) translateZ(0); }
  .bbar-item { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; background: none; border: none; color: var(--text-faint); cursor: pointer; padding: 8px 2px 7px; font-size: 10.5px; font-weight: 600; min-height: 52px; -webkit-tap-highlight-color: transparent; }
  .bbar-item .bbar-ico { font-size: 19px; line-height: 1; }
  .bbar-item.active { color: var(--accent-hi); }
  .bbar-item:active { opacity: .6; }
  /* Content clears the fixed bottom bar so nothing hides behind it. */
  .main { padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px)); }
}

/* ── Page elements ── */
.page-title { font-size: 22px; font-weight: 700; color: #fff; margin-bottom: 4px; }
.page-sub { font-size: 13px; color: var(--text-faint); margin-bottom: 24px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }
.card-title { font-size: 11px; font-weight: 700; color: var(--text-dim); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 14px; }
.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
/* Dashboard KPI tiles. */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(168px, 1fr)); gap: 12px; margin-top: 6px; }
/* ── Mobile responsive polish ── */
@media (max-width: 860px) {
  /* Roomier tap targets on small row/action buttons (incl. the row-menu popup items). */
  .btn.sm { padding-top: 8px; padding-bottom: 8px; }
}
@media (max-width: 520px) {
  /* Inline two/three-column form grids collapse to a single column on phones. */
  [style*="grid-template-columns:1fr 1fr"] { grid-template-columns: 1fr !important; }
  /* Keep KPI tiles two-up instead of one tall column on the narrowest phones. */
  .kpi-grid { grid-template-columns: 1fr 1fr; }
}
.stat { text-align: center; padding: 18px 10px; }
.stat-num { font-size: 30px; font-weight: 800; color: #fff; }
.stat-label { font-size: 11px; color: var(--text-faint); text-transform: uppercase; letter-spacing: .8px; margin-top: 4px; }

.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 11px; font-weight: 700; color: var(--text-faint); text-transform: uppercase; letter-spacing: .6px; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.table td { padding: 12px 10px; border-bottom: 1px solid #1b1d22; font-size: 13px; }
.table tr:hover td { background: #181a1f; }
.rowmenu { position: relative; display: inline-block; }
.rowmenu-pop { position: absolute; right: 0; top: calc(100% + 4px); z-index: 50; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 6px; display: none; flex-direction: column; gap: 4px; min-width: 132px; box-shadow: 0 10px 28px rgba(0,0,0,.45); }
.rowmenu.open .rowmenu-pop { display: flex; }
.rowmenu-pop .btn.sm { width: 100%; text-align: left; }
/* Schedule: List/Month segmented toggle + month calendar grid */
.seg { display: inline-flex; background: var(--bg); border: 1px solid var(--border); border-radius: 9px; padding: 3px; gap: 3px; }
.seg-opt { border: none; background: transparent; color: var(--text-dim); font-family: inherit; font-weight: 700; font-size: 13px; padding: 6px 14px; border-radius: 6px; cursor: pointer; transition: background .12s, color .12s; }
.seg-opt.on { background: var(--accent); color: #fff; }
.cal-nav { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.cal-nav .cal-title { font-weight: 700; font-size: 16px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-dow > div { text-align: center; font-size: 12px; font-weight: 700; color: var(--text-faint); text-transform: uppercase; letter-spacing: .5px; padding: 2px 0 6px; }
.cal-day { min-height: 104px; border: 1px solid var(--border); border-radius: 8px; padding: 7px; background: var(--bg); cursor: pointer; transition: border-color .12s, background .12s; overflow: hidden; display: flex; flex-direction: column; }
.cal-day:hover { border-color: var(--accent); background: var(--panel2); }
.cal-day.blank { background: transparent; border: none; cursor: default; }
.cal-day.today { border-color: var(--accent-hi); box-shadow: inset 0 0 0 1px var(--accent-hi); }
.cal-dayhead { display: flex; justify-content: space-between; align-items: center; gap: 4px; margin-bottom: 4px; }
.cal-daynum { font-size: 14px; font-weight: 700; color: var(--text-dim); }
.cal-day.today .cal-daynum { color: var(--accent-hi); }
.cal-wx { font-size: 11.5px; font-weight: 700; white-space: nowrap; }
.cal-chips { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.cal-chip { background: var(--accent); color: #fff; border-radius: 5px; padding: 3px 6px 4px; line-height: 1.25; min-width: 0; }
.cal-chip-title { font-size: 12.5px; font-weight: 600; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; word-break: break-word; }
.cal-chip-addr { display: block; font-size: 11px; color: rgba(255,255,255,.88); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
.cal-chip-addr:hover { text-decoration: underline; }
.cal-more { font-size: 11.5px; color: var(--text-faint); }
.cal-add { font-size: 11.5px; color: var(--text-faint); opacity: .45; margin-top: auto; transition: opacity .12s, color .12s; }
.cal-day.empty:hover .cal-add { opacity: 1; color: var(--accent-hi); }
@media (max-width: 680px) { .cal-grid { gap: 4px; } .cal-day { min-height: 78px; padding: 5px; } .cal-chip { font-size: 11px; padding: 1px 4px; } .cal-daynum { font-size: 13px; } .cal-dow > div { font-size: 11px; } .cal-wx { font-size: 10px; } .cal-add { font-size: 10.5px; } }
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge.lead { background: #1e2638; color: var(--blue); }
.badge.quoted { background: #2a2210; color: var(--accent-hi); }
.badge.won { background: #122a18; color: var(--green); }
.badge.lost { background: #2a1414; color: var(--red); }
.badge.scheduled { background: #221a2e; color: #c084fc; }
.badge.open { background: #1e2638; color: var(--blue); }
.badge.partial { background: #2a2210; color: var(--accent-hi); }
.badge.paid { background: #122a18; color: var(--green); }

.jpill { border: 1px solid var(--border2); background: var(--panel2); color: var(--text-dim); padding: 6px 13px; border-radius: 20px; font-size: 12.5px; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 7px; transition: all .12s; }
.jpill:hover { color: #fff; border-color: #3e4148; }
.jpill .jpc { font-size: 11px; font-weight: 700; background: rgba(255,255,255,.08); color: inherit; padding: 1px 7px; border-radius: 10px; min-width: 16px; text-align: center; }
.jpill.active { color: #fff; border-color: transparent; }
.jpill.active .jpc { background: rgba(0,0,0,.22); }
.jpill.active[data-status=""] { background: var(--accent); }
.jpill.active[data-status="lead"] { background: var(--blue); }
.jpill.active[data-status="quoted"] { background: var(--amber); }
.jpill.active[data-status="scheduled"] { background: #a855f7; }
.jpill.active[data-status="won"] { background: #22c55e; }
.jpill.active[data-status="lost"] { background: var(--red); }
.jp-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--amber-hi); margin-left: 5px; vertical-align: middle; }
.jpill.active .jp-dot { background: #fff; }
.tag-new { display: inline-block; background: var(--accent); color: #fff; font-size: 9.5px; font-weight: 800; letter-spacing: .06em; padding: 2px 6px; border-radius: 5px; vertical-align: middle; margin-right: 3px; }
/* (v3.99.315) Same shape as .tag-new but outlined amber rather than solid — it has to be noticeable
   beside a NEW badge without competing with it. This is a note, not an alarm. */
.tag-warn { display: inline-block; background: transparent; color: #d99a2b; border: 1px solid #d99a2b; font-size: 9.5px; font-weight: 800; letter-spacing: .06em; padding: 1px 5px; border-radius: 5px; vertical-align: middle; margin-right: 3px; cursor: help; }
.kpi { flex: 1; min-width: 120px; background: var(--panel2); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.kpi-l { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-faint); font-weight: 600; }
.kpi-v { font-size: 22px; font-weight: 800; margin-top: 3px; }
.kpi-s { font-size: 11.5px; color: var(--text-dim); margin-top: 2px; }
.badge.material { background: #1e2638; color: var(--blue); }
.badge.labor { background: #2a2210; color: var(--amber-hi); }
.badge.equipment { background: #221a2e; color: #c084fc; }
.badge.subcontractor { background: #10262a; color: var(--accent-hi); }
.badge.other { background: #23262c; color: var(--text-dim); }

.empty { text-align: center; padding: 40px 20px; color: var(--text-faint); font-size: 13px; }

/* ── Modal ── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.65); z-index: 100; display: flex; align-items: center; justify-content: center; padding: 16px; -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
.modal { width: 100%; max-width: 540px; background: var(--panel); border: 1px solid var(--border2); border-radius: 16px; padding: 26px 28px; max-height: 92vh; overflow-y: auto; box-shadow: 0 24px 64px rgba(0,0,0,.55); animation: modalIn .16s ease-out; }
@keyframes modalIn { from { opacity: 0; transform: translateY(10px) scale(.99); } to { opacity: 1; transform: none; } }
.modal-title { font-size: 18px; font-weight: 700; color: #fff; margin: 0 -28px 18px; padding: 0 28px 16px; border-bottom: 1px solid var(--border); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--border); }

/* ── Toast ── */
.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px;
  background: #20232b; border: 1px solid var(--border2); border-left: 4px solid var(--green);
  color: #fff; padding: 14px 20px 14px 15px;
  border-radius: 13px; font-size: 14.5px; font-weight: 600; z-index: 200;
  box-shadow: 0 14px 44px rgba(0,0,0,.6); animation: toastIn .3s cubic-bezier(.2,.9,.3,1.25);
  max-width: min(440px, 92vw); min-width: 200px;
}
.toast-ico {
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  width: 28px; height: 28px; border-radius: 50%; font-size: 16px; font-weight: 900; line-height: 1;
  background: rgba(34, 197, 94, .18); color: var(--green);
}
.toast-msg { line-height: 1.35; }
.toast.success { border-left-color: var(--green); }
.toast.error { border-left-color: var(--red); color: #ffe3e3; }
.toast.error .toast-ico { background: rgba(248, 113, 113, .18); color: var(--red); }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 16px) scale(.96); } to { opacity: 1; transform: translate(-50%, 0) scale(1); } }

/* ── Visualizer ── */
.viz-layout { display: flex; gap: 16px; align-items: flex-start; }
.viz-canvas-col { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 10px;
  position: sticky; top: 16px; align-self: flex-start; max-height: calc(100vh - 32px); }
.viz-canvas-col .viz-stage { min-height: 0; }
.viz-stage {
  position: relative; background: #0a0b0e; border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; min-height: 320px; display: flex; align-items: center; justify-content: center;
}
.viz-stage canvas { display: block; max-width: 100%; }
.viz-upload {
  border: 2px dashed var(--border2); border-radius: 12px; padding: 50px 20px; text-align: center;
  cursor: pointer; transition: all .2s; width: 90%;
}
.viz-upload:hover { border-color: var(--accent); background: rgba(217,119,6,.04); }
.viz-upload .big { font-size: 40px; opacity: .35; margin-bottom: 10px; }
.viz-toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.viz-hint { font-size: 12px; color: var(--text-faint); }
.viz-side { width: 280px; flex-shrink: 0; display: flex; flex-direction: column; gap: 12px; }
.viz-side .card { margin-bottom: 0; }
.finish-item {
  display: flex; gap: 10px; align-items: center; padding: 8px; border-radius: 8px;
  border: 1.5px solid var(--border); cursor: pointer; margin-bottom: 6px; transition: all .15s;
}
.finish-item:hover { border-color: var(--border2); background: var(--panel2); }
.finish-item.sel { border-color: var(--accent); background: #221708; }
.finish-item canvas { border-radius: 6px; flex-shrink: 0; }
.finish-name { font-size: 12px; font-weight: 600; color: var(--text); }
.finish-desc { font-size: 10px; color: var(--text-faint); }
.color-row { display: flex; flex-wrap: wrap; gap: 7px; }
.color-dot { width: 26px; height: 26px; border-radius: 50%; cursor: pointer; border: 2px solid transparent; transition: transform .15s; }
.color-dot:hover { transform: scale(1.15); }
.color-dot.sel { border-color: #fff; box-shadow: 0 0 0 2px var(--accent); }
.range-row { display: flex; align-items: center; gap: 10px; }
input[type=range] { flex: 1; accent-color: var(--accent); }

/* compare slider */
.cmp-wrap { position: relative; overflow: hidden; border-radius: var(--radius); border: 1px solid var(--border); background: #0a0b0e; user-select: none; }
.cmp-wrap img { display: block; width: 100%; pointer-events: none; }
.cmp-top { position: absolute; top: 0; left: 0; height: 100%; overflow: hidden; }
.cmp-top img { height: 100%; width: auto; max-width: none; }
.cmp-bar { position: absolute; top: 0; bottom: 0; width: 3px; background: #fff; cursor: ew-resize; z-index: 5; }
.cmp-knob { position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); width: 34px; height: 34px; border-radius: 50%; background: #fff; color: #111; display: flex; align-items: center; justify-content: center; font-weight: 800; box-shadow: 0 2px 14px rgba(0,0,0,.5); }
.cmp-label { position: absolute; top: 10px; padding: 3px 10px; border-radius: 4px; font-size: 10px; font-weight: 700; letter-spacing: .5px; z-index: 4; }
.cmp-label.before { left: 10px; background: rgba(0,0,0,.7); color: #bbb; }
.cmp-label.after { right: 10px; background: rgba(217,119,6,.85); color: #fff; }

@media (max-width: 980px) {
  .viz-layout { flex-direction: column; }
  .viz-canvas-col { position: static; }
  .viz-side { width: 100%; }
}

/* ── Estimator ── */
.est-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 700px) { .est-grid { grid-template-columns: 1fr; } }
.est-line { display: flex; justify-content: space-between; padding: 9px 0; border-bottom: 1px solid #1b1d22; font-size: 13px; }
.est-line.total { border-top: 2px solid var(--border2); border-bottom: none; padding-top: 14px; margin-top: 4px; }
.est-line.total .v { font-size: 20px; font-weight: 800; color: var(--accent-hi); }
.est-line .v { font-weight: 600; color: #fff; font-variant-numeric: tabular-nums; }

/* ── Proposal preview ── */
.prop-preview { background: #fff; color: #1a1a1a; border-radius: var(--radius); padding: 36px; font-size: 14px; line-height: 1.6; }
.prop-preview h2 { font-size: 22px; margin-bottom: 4px; }
.prop-preview .muted { color: #777; font-size: 12px; }
.prop-preview hr { border: none; border-top: 1px solid #e2e2e2; margin: 18px 0; }
.prop-preview img { max-width: 100%; border-radius: 8px; }
.prop-preview table { width: 100%; border-collapse: collapse; margin: 10px 0; }
.prop-preview td, .prop-preview th { padding: 8px 6px; border-bottom: 1px solid #eee; text-align: left; font-size: 13px; }

/* ── Render Lab lightbox ── */
.lb-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.92); z-index: 300; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 20px; }
.lb-overlay img { max-width: 96vw; max-height: 82vh; border-radius: 8px; display: block; }
.lb-title { color: #fff; font-size: 15px; font-weight: 700; margin-bottom: 12px; }
.lb-close { position: absolute; top: 16px; right: 20px; color: #fff; font-size: 30px; cursor: pointer; line-height: 1; background: none; border: none; }
.lb-tools { margin-top: 14px; display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.lb-cmp { position: relative; max-width: 96vw; max-height: 82vh; overflow: hidden; border-radius: 8px; user-select: none; touch-action: none; }
.lb-cmp img { position: static; }
.lb-cmp .lb-top { position: absolute; top: 0; left: 0; height: 100%; width: 50%; overflow: hidden; }
.lb-cmp .lb-top img { height: 100%; width: auto; max-width: none; max-height: none; }
.lb-cmp .lb-bar { position: absolute; top: 0; bottom: 0; left: 50%; width: 3px; background: #fff; cursor: ew-resize; }
.lb-cmp .lb-knob { position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); width: 38px; height: 38px; border-radius: 50%; background: #fff; color: #111; display: flex; align-items: center; justify-content: center; font-weight: 800; box-shadow: 0 2px 14px rgba(0,0,0,.5); }
.lb-lbl { position: absolute; top: 12px; padding: 4px 12px; border-radius: 5px; font-size: 11px; font-weight: 700; }
.lb-lbl.b { left: 12px; background: rgba(0,0,0,.7); color: #ddd; }
.lb-lbl.a { right: 12px; background: rgba(217,119,6,.9); color: #fff; }
.result-img { cursor: zoom-in; transition: opacity .15s; }
.result-img:hover { opacity: .85; }

/* contractor co-brand logo in sidebar */
.contractor-logo { padding: 12px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: center; }
.contractor-logo img { max-height: 46px; max-width: 100%; }

/* ── Settings section tabs ── */
.settabs { position: sticky; top: 0; z-index: 20; display: flex; gap: 6px; overflow-x: auto; padding: 9px 0; margin: 2px 0 16px; background: var(--bg); border-bottom: 1px solid var(--border); scrollbar-width: none; }
.settabs::-webkit-scrollbar { display: none; }
.settab { flex: 0 0 auto; background: var(--panel2); border: 1px solid var(--border); color: var(--text-dim); padding: 7px 14px; border-radius: 999px; font-size: 12.5px; font-weight: 600; cursor: pointer; white-space: nowrap; transition: background .15s, color .15s, border-color .15s; }
.settab:hover { color: var(--text); }
.settab.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.set-sec { scroll-margin-top: 74px; }
/* Collapsible section cards (accordion) — works for both simple titles and flex headers
   (title + action button). Forces a consistent header layout; chevron pinned right. */
.acc > .acc-head { display: flex !important; align-items: center; gap: 10px; justify-content: flex-start !important; cursor: pointer; user-select: none; margin: 0 !important; padding: 4px 0; -webkit-tap-highlight-color: transparent; }
.acc > .acc-head:hover { color: var(--text); }
.acc-head .acc-chev { margin-left: auto; flex: 0 0 auto; font-size: 19px; line-height: 1; color: var(--text-faint); transition: transform .25s ease; }
.acc.collapsed .acc-head .acc-chev { transform: rotate(-90deg); }
.acc-body { display: grid; grid-template-rows: 1fr; transition: grid-template-rows .28s cubic-bezier(.4,0,.2,1); }
.acc.collapsed .acc-body { grid-template-rows: 0fr; }
.acc.collapsed .acc-head { padding-bottom: 4px; }
.acc-inner { overflow: hidden; min-height: 0; }
.acc:not(.collapsed) .acc-inner { padding-top: 10px; }
.grid.cols-2 > .set-sec.acc { grid-column: 1 / -1; }
@media (max-width: 860px) {
  .settabs { top: calc(54px + env(safe-area-inset-top, 0px)); }
  .set-sec { scroll-margin-top: calc(118px + env(safe-area-inset-top, 0px)); }
  .acc > .acc-head { padding: 6px 0; }   /* bigger tap target on phones */
}

/* ── Sticky list filters + clickable rows ── */
.liststick { position: sticky; top: 0; z-index: 15; background: var(--bg); padding: 6px 0 2px; }
.table tbody tr.clickrow { cursor: pointer; }
.table tbody tr.clickrow:hover { background: var(--panel2); }
.pour-open:hover { background: var(--panel2); }
@media (max-width: 860px) { .liststick { top: calc(54px + env(safe-area-inset-top, 0px)); } }

/* ── (v3.99.283) Phone list tables → stacked cards ──────────────────────────────
   The list pages (Jobs, Customers, Estimates, Proposals, Invoices) are 6–7 column
   tables. `.table { width:100% }` makes the browser divide that width across every
   column, so on a 390px phone each column gets ~45px and the text shreds into one
   word per line — the "everything shrinks into one tiny window" report.

   Fixed by restructuring rather than shrinking: below 700px each ROW becomes its own
   card and each CELL becomes a labelled line (LABEL on the left, value on the right).
   The header row is hidden because every cell now carries its own label. Labels come
   from data-label, stamped onto each <td> at runtime by cgStackTables() in app.js from
   that table's own <th> text — so no render site had to be touched and any table added
   later is handled automatically.

   Only tables tagged .cg-stack transform: that tag is only applied to tables with 4+
   header columns, so the compact 2–3 column tables (dashboard recent jobs, hours by
   member) keep their normal grid, which already reads fine on a phone.
   Desktop is completely untouched — every rule here is inside the media query. */
@media (max-width: 700px) {
  .table.cg-stack, .table.cg-stack tbody, .table.cg-stack tr, .table.cg-stack td { display: block; width: 100%; }
  .table.cg-stack thead { display: none; }
  .table.cg-stack tr {
    background: var(--panel2); border: 1px solid var(--border);
    border-radius: var(--radius); margin-bottom: 10px; overflow: hidden;
  }
  /* Neutralise the desktop hover fills. On iOS :hover sticks after a tap, so a tapped
     row would otherwise stay lit up as though it were selected. The card keeps its own
     panel2 fill in every state instead of going transparent. */
  .table.cg-stack tr:hover,
  .table.cg-stack tbody tr.clickrow:hover { background: var(--panel2); }
  .table.cg-stack tr:hover td { background: transparent; }
  .table.cg-stack td {
    display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
    padding: 9px 13px; font-size: 14px; text-align: left;
    border-bottom: 1px solid rgba(255, 255, 255, .045);
    overflow-wrap: anywhere;
  }
  .table.cg-stack td:last-child { border-bottom: none; }
  .table.cg-stack td::before {
    content: attr(data-label);
    flex: 0 0 38%; min-width: 0;
    font-size: 10.5px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase;
    color: var(--text-faint);
  }
  /* Cells with no header text (the trailing actions column) and any colspan cell
     (the "no results" row) get no label and the full card width. */
  .table.cg-stack td:not([data-label])::before { content: none; }
  .table.cg-stack td.cg-nolabel { justify-content: flex-end; padding: 10px 13px; }
  .table.cg-stack td[colspan] { display: block; }
  /* Action cells are inline-styled white-space:nowrap for the desktop grid; on a card
     that forces horizontal overflow, so let them wrap. */
  .table.cg-stack td[style*="nowrap"] { white-space: normal !important; }
}

/* ── Measure: live per-edge length labels ── */
.mz-edge-label { background: rgba(26,167,196,.94); color: #fff; font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 6px; white-space: nowrap; pointer-events: none; box-shadow: 0 1px 4px rgba(0,0,0,.55); letter-spacing: .2px; }
/* Precise-placement crosshair (pinned to map center) */
.mz-cross { position: absolute; left: 50%; top: 50%; width: 46px; height: 46px; transform: translate(-50%, -50%); pointer-events: none; z-index: 5; }
.mz-cross::before, .mz-cross::after { content: ''; position: absolute; background: rgba(255,255,255,.92); box-shadow: 0 0 2px rgba(0,0,0,.85); }
.mz-cross::before { left: 50%; top: 0; width: 1.5px; height: 100%; transform: translateX(-50%); }
.mz-cross::after { top: 50%; left: 0; height: 1.5px; width: 100%; transform: translateY(-50%); }
.mz-cross > i { position: absolute; left: 50%; top: 50%; width: 9px; height: 9px; border-radius: 50%; border: 2px solid #1AA7C4; background: rgba(255,255,255,.45); transform: translate(-50%, -50%); box-shadow: 0 0 2px rgba(0,0,0,.7); }
/* Drag magnifier loupe */
.mz-loupe { position: absolute; z-index: 6; pointer-events: none; border-radius: 50%; box-shadow: 0 4px 16px rgba(0,0,0,.55); }

/* ── Measure: live GPS "you are here" dot ── */
.mz-here { width: 16px; height: 16px; border-radius: 50%; background: #3FC0DD; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.5); animation: mzpulse 1.8s ease-out infinite; }
@keyframes mzpulse { 0% { box-shadow: 0 0 0 0 rgba(63,192,221,.55), 0 1px 4px rgba(0,0,0,.5); } 70% { box-shadow: 0 0 0 15px rgba(63,192,221,0), 0 1px 4px rgba(0,0,0,.5); } 100% { box-shadow: 0 0 0 0 rgba(63,192,221,0), 0 1px 4px rgba(0,0,0,.5); } }

/* ── Settings → Lead Capture: public form design picker ──
   One card per entry in cgLeadTemplates(). The whole card is the control, so a
   phone gets a large tap target; the Preview link inside it opens the real
   public page with ?tpl= and must not select the card (handled in app.js). */
.tplgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(216px, 1fr)); gap: 10px; margin-top: 2px; }
.tplcard { position: relative; display: flex; flex-direction: column; gap: 6px; text-align: left; width: 100%;
  background: var(--panel2); border: 1.5px solid var(--border); border-radius: var(--radius); padding: 13px 14px 12px;
  color: var(--text-dim); font-family: inherit; cursor: pointer;
  transition: border-color .15s, background .15s, color .15s; }
.tplcard:hover { border-color: var(--border2); color: var(--text); }
.tplcard:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(26,167,196,.28); }
.tplcard.on { border-color: var(--accent); background: rgba(26,167,196,.09); color: var(--text); }
.tplcard-h { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.tplcard-h b { font-size: 14px; font-weight: 700; color: var(--text); letter-spacing: -.01em; }
.tpltag { font-size: 10.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--text-faint); border: 1px solid var(--border2); border-radius: 999px; padding: 2px 7px; }
.tplcard.on .tpltag { color: var(--accent); border-color: var(--accent); }
.tplcard p { margin: 0; font-size: 12.5px; line-height: 1.45; }
.tplcard .tplprev { align-self: flex-start; margin-top: 2px; font-size: 12px; font-weight: 600; color: var(--accent); text-decoration: none; padding: 4px 0; }
.tplcard .tplprev:hover { text-decoration: underline; }
.tplcard .tplnow { position: absolute; top: 11px; right: 12px; font-size: 10.5px; font-weight: 700;
  letter-spacing: .06em; text-transform: uppercase; color: var(--accent); display: none; }
.tplcard.on .tplnow { display: block; }
.tplcard.on .tpltag { display: none; }
