/* 5 Star design system: red is for action, blue is for structure.
   Barlow Condensed 700 uppercase for headings, Public Sans for body. */
:root {
  --red: #F2252C;
  --red-dark: #D4161C;
  --blue: #006CB7;
  --blue-dark: #005692;
  --deep: #004270;
  --ink: #20252A;
  --ink-strong: #12161A;
  --surface-alt: #F5F5F5;
  --success: #1E7B41;
  --warning: #B4690E;
  --focus: #0B84E0;

  --bg: var(--surface-alt);
  --surface: #ffffff;
  --text: var(--ink);
  --muted: #4A535C;
  --line: #E3E7EA;
  --brand: var(--blue);
  --brand-2: var(--blue);
  --danger: var(--red);
  --cold: var(--blue);
  --warm: var(--warning);
  --hot: var(--red);
  --radius: 10px;
  --shadow: 0 4px 18px rgba(18, 22, 26, .12);
  --topbar-h: 56px;
  --tabs-h: 62px;
  --font-display: "Barlow Condensed", "Arial Narrow", Helvetica, Arial, sans-serif;
  --font-body: "Public Sans", "Segoe UI", Helvetica, Arial, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 400 17px/1.62 var(--font-body);
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
a { color: var(--blue); }
h1, h2, h3, .display {
  font-family: var(--font-display); font-weight: 700; text-transform: uppercase;
  letter-spacing: .01em; line-height: 1.1; color: var(--deep);
}
h1 { font-size: clamp(30px, 6vw, 40px); margin: 0 0 .25rem; }
h2 { font-size: 22px; margin: 0 0 .75rem; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.muted { color: var(--muted); }

/* ---------- shell ---------- */
.topbar {
  position: fixed; inset: 0 0 auto 0; height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 12px 0; display: flex; align-items: center; gap: 12px;
  background: var(--surface); color: var(--ink); z-index: 1000;
  border-bottom: 3px solid var(--red);
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--deep); text-decoration: none; }
.brand img { height: 36px; width: auto; }
.brand span { font-family: var(--font-display); font-weight: 700; text-transform: uppercase; font-size: 20px; letter-spacing: .02em; }
.today { font-size: 13px; color: var(--muted); font-weight: 600; letter-spacing: .1em; text-transform: uppercase; }
.user { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.avatar { width: 28px; height: 28px; border-radius: 50%; }
main { padding-top: calc(var(--topbar-h) + env(safe-area-inset-top)); padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom)); min-height: 100%; }
.tabs {
  position: fixed; inset: auto 0 0 0; height: calc(var(--tabs-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom); display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--line); z-index: 1000;
}
.tab {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--deep); text-decoration: none; font-size: 11px; font-weight: 700; letter-spacing: .02em; text-transform: uppercase; white-space: nowrap;
  border-top: 3px solid transparent;
}
.tab.on { color: var(--red); border-top-color: var(--red); }
.tab-icon { font-size: 1.25rem; line-height: 1; }
.tab-badge {
  position: absolute; top: 6px; left: calc(50% + 8px); min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--danger); color: #fff; font-size: .7rem; line-height: 18px; text-align: center;
}

/* ---------- map ---------- */
.map-host, .map-wrap { position: fixed; inset: calc(var(--topbar-h) + env(safe-area-inset-top)) 0 calc(var(--tabs-h) + env(safe-area-inset-bottom)) 0; }
.map { position: absolute; inset: 0; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.pin { background: none; border: 0; filter: drop-shadow(0 1px 2px rgba(0,0,0,.4)); }
.map-btn {
  width: 40px; height: 40px; border: 0; border-radius: 6px; background: #fff; color: #111;
  font-size: 1.4rem; box-shadow: 0 1px 5px rgba(0,0,0,.35); cursor: pointer;
}
.leaflet-control-layers { border-radius: 8px !important; }
.leaflet-control-layers-base label { display: inline-block; margin-right: 6px; }
.map-search { position: absolute; top: 10px; left: 10px; right: 170px; z-index: 800; max-width: 420px; }
.map-search input {
  width: 100%; padding: 10px 12px; border-radius: 8px; border: 0; box-shadow: 0 1px 5px rgba(0,0,0,.3);
  font-size: 16px; background: var(--surface); color: var(--text);
}
.search-results { margin-top: 4px; background: var(--surface); border-radius: 8px; box-shadow: var(--shadow); overflow: hidden; }
.search-results:empty { display: none; }
.search-row { display: block; width: 100%; text-align: left; padding: 10px 12px; border: 0; border-bottom: 1px solid var(--line); background: none; color: var(--text); font: inherit; }
.legend-wrap { position: absolute; left: 10px; bottom: 24px; z-index: 800; }
.legend-toggle { border: 0; border-radius: 8px; padding: 8px 12px; background: var(--surface); color: var(--text); box-shadow: 0 1px 5px rgba(0,0,0,.3); font-weight: 600; }
.legend { display: none; margin-bottom: 6px; padding: 8px 10px; background: var(--surface); border-radius: 8px; box-shadow: var(--shadow); grid-template-columns: 1fr 1fr; gap: 4px 12px; font-size: .8rem; }
.legend.open { display: grid; }
.legend-wrap { display: flex; flex-direction: column-reverse; align-items: flex-start; }
.legend-item { display: flex; align-items: center; gap: 4px; }

/* long-press menu */
.knock-popup .leaflet-popup-content-wrapper { border-radius: 14px; background: var(--surface); color: var(--text); }
.knock-popup .leaflet-popup-tip { background: var(--surface); }
.knock-popup .leaflet-popup-content { margin: 14px 14px 12px; }
.knock-popup a.leaflet-popup-close-button { font-size: 22px; width: 32px; height: 32px; top: 4px; right: 4px; }
.knock { font-size: 15px; }
.knock-head { padding-right: 22px; margin-bottom: 8px; }
.knock-title { font-family: var(--font-display); font-weight: 700; text-transform: uppercase; font-size: 20px; color: var(--deep); line-height: 1.15; }
.knock-sub { color: var(--muted); font-size: .85rem; margin-top: 2px; }
.knock-address { width: 100%; font-size: 16px; font-weight: 600; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); }
.knock-list { display: flex; flex-direction: column; }
.knock-option {
  display: flex; align-items: center; gap: 14px; padding: 7px 4px; border: 0; background: none;
  font: inherit; font-size: 1.15rem; color: var(--text); text-align: left; border-radius: 8px; cursor: pointer;
}
.knock-option:active, .knock-option:hover { background: var(--bg); }
.knock-icon { display: inline-flex; }
.knock-actions { display: flex; gap: 8px; margin-top: 10px; }
.knock-actions .btn { flex: 1; text-align: center; }
.knock .field { margin-top: 8px; }
.knock-loading { padding: 12px 0; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip { border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 999px; padding: 4px 10px; font: inherit; font-size: .8rem; }
.chip.on { background: var(--blue); border-color: var(--blue); color: #fff; }

/* ---------- pages ---------- */
.view { padding: 14px 12px 24px; }
.page { max-width: 960px; margin: 0 auto; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin-bottom: 12px; }
.page-head h1 { margin: 0; }
.page-head p { flex-basis: 100%; margin: 0; }
.page-loading, .empty { padding: 40px 12px; text-align: center; color: var(--muted); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px 12px; }
.wide { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: 13px; font-weight: 700; color: var(--deep); text-transform: uppercase; letter-spacing: .1em; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.row > input { flex: 1; min-width: 0; }
input, select, textarea {
  font: inherit; font-size: 16px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--text); width: 100%;
}
input[type=checkbox] { width: auto; }
textarea { resize: vertical; }
.btn {
  display: inline-block; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
/* One red (primary) button per view; blue (secondary) for everything else. */
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.primary:hover { background: var(--red-dark); border-color: var(--red-dark); }
.btn.secondary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.secondary:hover { background: var(--blue-dark); border-color: var(--blue-dark); }
.btn { color: var(--blue); border-color: #C6CCD2; }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: .85rem; }
.btn.big { padding: 12px 22px; font-size: 1.05rem; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; color: #fff; font-size: .75rem; font-weight: 700; }
.tag { margin-left: 6px; padding: 1px 6px; border-radius: 6px; background: var(--bg); font-size: .72rem; color: var(--muted); }
details summary { cursor: pointer; font-weight: 700; color: var(--blue); margin-top: 10px; }
.add-form { margin-top: 10px; }
.check { display: flex; align-items: center; gap: 6px; }

.prop-head { margin-bottom: 12px; }
.prop-head .back { text-decoration: none; font-weight: 700; font-size: 13px; letter-spacing: .1em; text-transform: uppercase; }
.prop-meta { display: flex; align-items: center; gap: 8px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg-btn { border: 0; padding: 7px 14px; background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; }
.seg-btn + .seg-btn { border-left: 1px solid var(--line); }
.seg-btn.on { color: #fff; background: var(--blue); }
.seg-btn.temp-cold.on { background: var(--cold); }
.seg-btn.temp-warm.on { background: var(--warm); }
.seg-btn.temp-hot.on { background: var(--hot); }
.temp-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.temp-dot.temp-cold { background: var(--cold); }
.temp-dot.temp-warm { background: var(--warm); }
.temp-dot.temp-hot { background: var(--hot); }

.list { display: flex; flex-direction: column; gap: 8px; }
.contact, .deal-row, .list-row {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--text); text-decoration: none;
}
.deal-row { justify-content: flex-start; }
.list-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; color: var(--text); text-decoration: none; }
.list-actions { display: flex; gap: 6px; }
.clamp { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.group-title { margin: 16px 0 8px; }
.group-overdue { color: var(--danger); }
.custom-row { margin-bottom: 6px; flex-wrap: nowrap; }

.activity-form { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.activity-form .row > * { flex: 1; }
.timeline { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--line); }
.tl { position: relative; padding: 0 0 12px 14px; }
.tl::before { content: ''; position: absolute; left: -6px; top: 6px; width: 10px; height: 10px; border-radius: 50%; background: var(--line); }
.tl-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.tl-icon { display: inline-flex; }
.tl-body { white-space: pre-wrap; margin-top: 2px; }
.tl-system { opacity: .7; font-size: .9em; }
.danger-zone { text-align: center; padding: 10px 0 20px; }

/* ---------- pipeline ---------- */
.pipeline-page { max-width: none; }
.board { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 10px; scroll-snap-type: x proximity; }
.col { flex: 0 0 270px; scroll-snap-align: start; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; max-height: calc(100vh - 220px); }
.col-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-top: 4px solid; border-radius: var(--radius) var(--radius) 0 0; font-family: var(--font-display); font-weight: 700; text-transform: uppercase; font-size: 18px; color: var(--deep); }
.col-count { background: var(--bg); border-radius: 999px; padding: 0 8px; font-size: .8rem; }
.col-head .muted { margin-left: auto; font-size: .85rem; }
.col-list { flex: 1; min-height: 80px; overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 8px; }
.deal-card { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px; cursor: grab; display: flex; flex-direction: column; gap: 4px; touch-action: manipulation; }
.deal-title { font-weight: 700; color: var(--blue); text-decoration: none; }
.deal-card { background: var(--surface); }
.deal-meta { display: flex; align-items: center; gap: 6px; font-size: .82rem; color: var(--muted); }
.deal-meta strong { margin-left: auto; color: var(--text); }
.deal-services { font-size: .82rem; }
.deal-follow { font-size: .78rem; color: var(--muted); }
.deal-follow.overdue { color: var(--danger); font-weight: 700; }
.card-ghost { opacity: .4; }

/* ---------- misc ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabs-h) + 16px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: #0f172a; color: #fff; padding: 10px 16px; border-radius: 10px; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; z-index: 2000; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.err { background: var(--danger); }

.login-body { display: grid; place-items: center; min-height: 100vh; padding: 16px; background: linear-gradient(160deg, var(--ink-strong) 0%, var(--ink) 55%, var(--deep) 100%); }
.login-card { background: var(--surface); border-top: 5px solid var(--red); border-radius: var(--radius); padding: 32px 28px; text-align: center; max-width: 380px; width: 100%; box-shadow: 0 18px 50px rgba(0,0,0,.35); }
.login-card img { width: 190px; height: auto; }
.login-card h1 { margin-top: 14px; }
.eyebrow { font-size: 13px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--blue); margin: 0 0 4px; }

@media (min-width: 900px) {
  .map-search { right: auto; width: 380px; }
}

/* ---------- agreements ---------- */
.env-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink); text-decoration: none; }
.env-row .muted { font-size: 14px; }
.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: #fff; }
.pill-draft { background: #6B7580; }
.pill-sent { background: var(--blue); }
.pill-viewed { background: var(--warning); }
.pill-signed { background: var(--success); }
.pill-completed { background: var(--success); }
.pill-declined, .pill-voided { background: var(--red); }

/* ---------- sign-in forms ---------- */
.login-form { display: flex; flex-direction: column; gap: 12px; text-align: left; margin-top: 16px; }
.login-form .btn { width: 100%; text-align: center; }
.login-card > .btn { display: block; width: 100%; text-align: center; }
.login-or { display: flex; align-items: center; gap: 10px; margin: 16px 0; color: var(--muted); font-size: 13px; letter-spacing: .1em; text-transform: uppercase; }
.login-or::before, .login-or::after { content: ''; flex: 1; border-top: 1px solid var(--line); }
.login-error { background: #FEF2F2; color: #A81015; border-radius: 6px; padding: 8px 12px; margin: 12px 0 0; font-weight: 600; }
