/* Replacement Cycle List — field-first viewer
   One visual language across every tab. Readable on a phone in sunlight,
   printable for the truck, zero learning curve.
   All user-facing copy lives in content.js, not here.
*/

:root {
  --bg: #ffffff;
  --ink: #1a1a1a;
  --ink-soft: #555;
  --line: #d5d5d5;
  --accent: #0b5cad;
  --row-alt: #f5f8fc;
  --ok: #1F6F1F;

  --eol: #990000;
  --mid: #B8860B;
  --norec: #C25E00;
  --newhome: #1F6F1F;

  --touch: 44px;
  --map-h: 0px;              /* drives the sticky offset of table headers */
}

* { box-sizing: border-box; }

/* The HTML `hidden` attribute must always win over author display rules. */
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  margin: 0; display: flex; flex-direction: column; overflow: hidden;
  background: var(--bg); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 17px; line-height: 1.35; -webkit-text-size-adjust: 100%;
}

#demo-banner {
  background: #7a0000; color: #fff; text-align: center;
  font-weight: 700; padding: 7px 12px; font-size: 14px; flex: 0 0 auto;
}

/* ---- Top bar ---- */
.topbar {
  flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 10px 16px; border-bottom: 2px solid var(--ink); background: var(--bg);
}
.brand h1 { margin: 0; font-size: 19px; letter-spacing: -0.01em; }
.brand .sub { color: var(--ink-soft); font-size: 13px; margin-top: 2px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.week-picker { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.week-picker .wp-label { color: var(--ink-soft); }
.week-picker select {
  min-height: 40px; font-size: 15px; padding: 0 8px;
  border: 2px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink);
}

.btn {
  min-height: var(--touch); padding: 0 16px; font-size: 16px; font-weight: 600;
  border: 2px solid var(--ink); background: #fff; color: var(--ink);
  border-radius: 8px; cursor: pointer;
}
.btn:active { background: #eee; }
.btn-sm { min-height: 38px; font-size: 14px; padding: 0 12px; }
.btn-icon { min-width: 44px; padding: 0 10px; font-size: 17px; }
.btn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---- Tabs ---- */
.tabs {
  flex: 0 0 auto; display: flex; gap: 2px; padding: 6px 8px 0;
  overflow-x: auto; border-bottom: 1px solid var(--line); background: var(--bg);
  -webkit-overflow-scrolling: touch;
}
.tab {
  flex: 0 0 auto; min-height: 42px; padding: 0 14px; font-size: 15px; font-weight: 600;
  color: var(--ink-soft); background: transparent; border: none;
  border-bottom: 3px solid transparent; cursor: pointer; white-space: nowrap;
}
.tab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }
.tab .count { font-weight: 500; opacity: .65; margin-left: 5px; font-size: 13px; }

.tab-sub {
  flex: 0 0 auto; padding: 7px 16px; font-size: 13px; color: var(--ink-soft);
  background: #fafbfc; border-bottom: 1px solid var(--line);
}
.tab-sub:empty { display: none; }
.tab-sub .nurture { color: var(--accent); font-weight: 600; }

/* ---- Controls ---- */
.controls {
  flex: 0 0 auto; display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 8px 16px; border-bottom: 1px solid var(--line);
}
.search {
  flex: 1 1 200px; max-width: 300px; min-height: 40px; padding: 0 12px;
  font-size: 16px; border: 2px solid var(--line); border-radius: 8px;
}
.status-filter {
  min-height: 40px; font-size: 14px; padding: 0 8px;
  border: 2px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink);
}
.tier-filters { display: flex; flex-wrap: wrap; gap: 5px; }
.tier-toggle {
  display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 0 11px;
  font-size: 13px; font-weight: 600; border: 2px solid var(--line);
  border-radius: 18px; background: #fff; cursor: pointer; user-select: none; color: var(--ink);
}
.tier-toggle .dot { width: 11px; height: 11px; border-radius: 50%; display: inline-block; }
.tier-toggle .rate { font-weight: 500; color: var(--ink-soft); font-size: 12px; }
.tier-toggle[aria-pressed="false"] { opacity: .35; }
.ctl-spacer { flex: 1 1 auto; }
.result-count { color: var(--ink-soft); font-size: 13px; }

/* ---- Panel + sticky map overlay ---- */
.panel { flex: 1 1 auto; overflow-y: auto; padding: 0 0 90px; min-width: 0; position: relative; }
#content { padding: 10px 14px 0; }

.map-wrap {
  position: sticky; top: 0; z-index: 20;
  /* 40% of the viewport, but never so short that the map can't render. */
  height: 40vh; min-height: 240px;
  border-bottom: 2px solid var(--ink); background: #eee;
}
.map { width: 100%; height: 100%; }
body.mapstate-hidden .map-wrap { display: none; }
body.mapstate-open { --map-h: 40vh; }
body.mapstate-full .map-wrap { position: fixed; inset: 0; height: 100%; z-index: 1000; }
body.mapstate-full #content { display: none; }
body.no-map .map-wrap { display: none; }

.map-controls { position: absolute; top: 8px; right: 8px; z-index: 1100; display: flex; gap: 6px; }
.map-ctl {
  min-width: 34px; min-height: 34px; font-size: 15px; font-weight: 700;
  border: 2px solid var(--ink); background: rgba(255,255,255,.95); color: var(--ink);
  border-radius: 7px; cursor: pointer;
}
.tile-notice {
  position: absolute; left: 8px; bottom: 8px; right: 60px; z-index: 1100;
  background: #fff8e1; border: 2px solid #e0a800; border-radius: 8px;
  padding: 7px 10px; font-size: 12.5px; display: flex; gap: 8px; align-items: center;
}
.tile-notice-x { margin-left: auto; border: none; background: none; cursor: pointer; font-size: 14px; }

.empty { padding: 34px 16px; text-align: center; color: var(--ink-soft); }

/* ---- Cards ---- */
.card {
  border: 1px solid var(--line); border-left: 6px solid var(--line);
  border-radius: 10px; padding: 11px 13px; margin: 8px 0; background: #fff; cursor: pointer;
}
.card.tier-eol { border-left-color: var(--eol); }
.card.tier-mid { border-left-color: var(--mid); }
.card.tier-norec { border-left-color: var(--norec); }
.card.tier-newhome { border-left-color: var(--newhome); }
.card.selected { outline: 3px solid var(--accent); outline-offset: 1px; }

.card-top { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.card .owner { font-size: 17px; font-weight: 700; }
.card .badge {
  flex: 0 0 auto; font-size: 11px; font-weight: 800; padding: 3px 8px;
  border-radius: 6px; color: #fff; white-space: nowrap;
}
.badge.tier-eol { background: var(--eol); }
.badge.tier-mid { background: var(--mid); }
.badge.tier-norec { background: var(--norec); }
.badge.tier-newhome { background: var(--newhome); }
.badge-new { background: #0b7d3b; margin-left: 6px; font-size: 10px; padding: 2px 6px; border-radius: 4px; color: #fff; font-weight: 800; }
.badge-warm { background: #1F6F1F; }
.badge-cold { background: #7b7b7b; }

.card .addr { font-size: 15px; margin: 2px 0 7px; }
.card .addr a { color: var(--accent); text-decoration: none; }
.card .facts { display: flex; flex-wrap: wrap; gap: 3px 16px; font-size: 13.5px; color: var(--ink-soft); }
.card .facts b { color: var(--ink); font-weight: 600; }
.warn { color: var(--eol); font-weight: 700; }
.card .permit { margin-top: 6px; font-size: 13.5px; }
.card .permit a, .lead-table td a { color: var(--accent); }
.contact-line { margin-top: 5px; font-size: 13.5px; }
.contact-line a { color: var(--accent); }
.contact-line .muted { color: #999; }

/* ---- Status chips: compact, must not inflate row height ---- */
.status-row { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.card .status-row { margin-top: 9px; padding-top: 8px; border-top: 1px dashed var(--line); }
.chip {
  min-height: 26px; padding: 0 9px; font-size: 11.5px; font-weight: 700; line-height: 1;
  border: 1.5px solid var(--line); border-radius: 13px; background: #fff;
  color: var(--ink-soft); cursor: pointer; display: inline-flex; align-items: center;
}
.chip[aria-pressed="true"] { background: var(--ok); border-color: var(--ok); color: #fff; }
.chip-note { border-style: dashed; }
.chip-note.has-note { border-color: var(--accent); color: var(--accent); border-style: solid; }
.note-editor { flex: 1 1 100%; margin-top: 6px; display: flex; gap: 6px; }
.note-editor textarea {
  flex: 1 1 auto; font: inherit; font-size: 14px; padding: 6px 8px;
  border: 2px solid var(--line); border-radius: 8px; resize: vertical; min-height: 54px;
}
.status-disabled { font-size: 12px; color: var(--ink-soft); font-style: italic; }

/* ---- Table ---- */
.lead-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; display: none; }
.lead-table th, .lead-table td {
  text-align: left; padding: 6px 9px; border-bottom: 1px solid var(--line);
  vertical-align: top;
}
/* Sticky headers = the freeze-pane equivalent; offset by the map when open. */
.lead-table thead th {
  position: sticky; top: var(--map-h); z-index: 10;
  background: #fff; border-bottom: 2px solid var(--ink);
  cursor: pointer; user-select: none; white-space: nowrap;
}
.lead-table thead th .arrow { color: var(--accent); }
.lead-table tbody tr { cursor: pointer; }
.lead-table tbody tr:nth-child(even) > td { background: var(--row-alt); }
.lead-table tbody tr.selected > td { outline: 2px solid var(--accent); outline-offset: -2px; }
.lead-table .tierdot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }
.lead-table .status-row { flex-wrap: nowrap; }
.lead-table .chip { min-height: 22px; padding: 0 6px; font-size: 10.5px; border-radius: 11px; }
/* Long AI/permit text: one line in the grid, full text in the detail panel. */
.clip1 { display: block; max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.num { text-align: right; white-space: nowrap; }

/* ---- Inline detail panel ---- */
.detail-row > td { background: #f7fbff !important; border-bottom: 2px solid var(--accent); }
.detail, .card .detail { padding: 4px 2px 10px; }
.detail h5 {
  margin: 10px 0 4px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--ink-soft);
}
.detail h5:first-child { margin-top: 2px; }
.detail .ai-text { font-size: 14.5px; margin: 0 0 4px; }
.detail .raw-text {
  font-size: 13.5px; color: #333; background: #fff; border-left: 3px solid var(--line);
  padding: 6px 9px; border-radius: 4px; margin: 0; white-space: pre-wrap;
}
.detail-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 4px 16px; margin-top: 4px; }
.detail-fields div { font-size: 13px; }
.detail-fields .k { color: var(--ink-soft); }
.detail-fields .v { font-weight: 600; }

/* ---- Footnotes ---- */
.footnotes { margin: 18px 2px 8px; border-top: 1px solid var(--line); padding-top: 8px; }
.footnotes summary { cursor: pointer; font-size: 13px; color: var(--accent); font-weight: 600; }
.footnotes ul { margin: 8px 0 0; padding-left: 18px; }
.footnotes li { font-size: 12.5px; color: var(--ink-soft); margin-bottom: 5px; }

/* ---- Overview ---- */
.ov-head { margin: 6px 2px 14px; }
.ov-head h2 { margin: 0 0 3px; font-size: 24px; letter-spacing: -0.02em; }
.ov-head .ov-sub { color: var(--ink-soft); font-size: 14px; }
.ov-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 20px; }
.ov-tile {
  border: 1px solid var(--line); border-top: 4px solid var(--accent); border-radius: 10px;
  padding: 11px 13px; background: #fff; cursor: pointer; text-align: left;
}
.ov-tile:hover { background: var(--row-alt); }
.ov-tile .n { font-size: 27px; font-weight: 800; line-height: 1.1; }
.ov-tile .l { font-size: 12.5px; color: var(--ink-soft); margin-top: 3px; }
.ov-tile .nurture { font-size: 11px; color: var(--accent); font-weight: 600; margin-top: 2px; }
.ov-section-title {
  font-size: 13px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em;
  color: var(--ink); margin: 0 2px 8px;
}
.ov-box { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; margin-bottom: 20px; background: #fff; }
.ov-item { display: flex; align-items: center; gap: 11px; padding: 10px 13px; cursor: pointer; border-bottom: 1px solid var(--line); }
.ov-item:last-child { border-bottom: none; }
.ov-item:hover { background: var(--row-alt); }
.ov-rank { flex: 0 0 auto; width: 25px; height: 25px; border-radius: 50%; background: var(--eol); color: #fff; font-weight: 800; font-size: 13px; display: grid; place-items: center; }
.ov-main { flex: 1 1 auto; min-width: 0; }
.ov-main .o { font-weight: 700; font-size: 15px; }
.ov-main .a { font-size: 13px; color: var(--ink-soft); }
.ov-why { flex: 0 0 auto; font-size: 12.5px; font-weight: 700; color: var(--eol); text-align: right; }
.ov-empty { padding: 14px 13px; color: var(--ink-soft); font-size: 14px; font-style: italic; }
.ov-pulse { border: 1px solid var(--line); border-left: 5px solid var(--accent); border-radius: 8px; padding: 11px 13px; background: #f7fbff; font-size: 14.5px; margin-bottom: 20px; }
.ov-stats { border: 1px solid var(--line); border-radius: 10px; background: #fff; padding: 4px 13px; margin-bottom: 20px; }
.ov-stat { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.ov-stat:last-child { border-bottom: none; }
.ov-stat .k { color: var(--ink-soft); }
.ov-stat .v { font-weight: 700; text-align: right; }

/* ---- Bottom sheet (phone) ---- */
.bottom-sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1200; background: #fff;
  border-top: 2px solid var(--ink); border-radius: 14px 14px 0 0; padding: 13px 15px 18px;
  box-shadow: 0 -6px 24px rgba(0,0,0,.22);
}
.bs-owner { font-size: 17px; font-weight: 700; }
.bs-addr { font-size: 14px; color: var(--ink-soft); margin: 2px 0 10px; }
.bs-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.bs-actions a, .bs-actions button {
  min-height: 42px; padding: 0 14px; font-size: 15px; font-weight: 700;
  border: 2px solid var(--ink); border-radius: 8px; background: #fff; color: var(--ink);
  text-decoration: none; display: inline-flex; align-items: center; cursor: pointer;
}
.bs-actions a.primary { background: var(--ok); border-color: var(--ok); color: #fff; }
.bs-close { position: absolute; top: 9px; right: 11px; border: none; background: none; font-size: 20px; cursor: pointer; }

.mobile-bar {
  display: none; position: fixed; left: 0; right: 0; bottom: 0; z-index: 900;
  padding: 9px 14px; background: rgba(255,255,255,.96); border-top: 1px solid var(--line);
  justify-content: center;
}

/* ---- Help slide-over ---- */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 1400; }
.help-panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(460px, 92vw); z-index: 1500;
  background: #fff; border-left: 2px solid var(--ink); display: flex; flex-direction: column;
  box-shadow: -8px 0 26px rgba(0,0,0,.18);
}
.help-head { flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; padding: 13px 15px; border-bottom: 2px solid var(--ink); font-size: 17px; }
.help-body { flex: 1 1 auto; overflow-y: auto; padding: 14px 16px 40px; font-size: 15px; }
.help-body h4 { margin: 0 0 6px; font-size: 15px; }
.help-body p, .help-body ol, .help-body ul { margin: 0 0 12px; color: var(--ink-soft); }
.help-body details { border-top: 1px solid var(--line); padding: 10px 0; }
.help-body details summary { cursor: pointer; font-weight: 700; font-size: 14.5px; }
.help-body details > *:not(summary) { margin-top: 9px; }
.help-current { background: #f7fbff; border-left: 4px solid var(--accent); padding: 11px 13px; border-radius: 6px; margin-bottom: 16px; }
.help-rates { margin: 10px 0 0; padding-left: 18px; }
.help-rates li { font-size: 13.5px; margin-bottom: 4px; }

.footer { flex: 0 0 auto; padding: 8px 16px; border-top: 1px solid var(--line); color: var(--ink-soft); font-size: 12px; }

/* ---- Wide screens: table instead of cards ---- */
@media (min-width: 820px) {
  .card-list { display: none; }
  .lead-table { display: table; }
  .bottom-sheet { display: none; }
}

/* ---- Phone: list-first; map is full-screen on demand ---- */
@media (max-width: 819px) {
  .map-wrap { position: fixed; inset: 0; height: 100%; z-index: 1000; }
  body:not(.mapstate-full) .map-wrap { display: none; }
  body.mapstate-open .map-wrap { display: block; }
  body.mapstate-open { --map-h: 0px; }
  #map-btn { display: none; }
  .mobile-bar { display: flex; }
  body.no-map .mobile-bar { display: none; }
  .panel { padding-bottom: 110px; }
  .topbar { flex-wrap: wrap; }
  .clip1 { max-width: 180px; }
}

/* ---- Print ---- */
@media print {
  body { overflow: visible; display: block; height: auto; }
  #demo-banner, .topbar-actions, .tabs, .controls, .map-wrap, .footer,
  .mobile-bar, .bottom-sheet, .help-panel, .scrim, .status-row { display: none !important; }
  .topbar { border-bottom: 2px solid #000; }
  .panel { overflow: visible; padding: 0; }
  #content { padding: 0; }
  .card-list { display: none !important; }
  .lead-table { display: table !important; font-size: 11px; }
  .lead-table thead th { position: static; cursor: default; }
  .clip1 { max-width: none; white-space: normal; }
  .tab-sub { background: none; border: none; padding: 4px 0 10px; }
  body { font-size: 12px; }
  a { color: #000 !important; text-decoration: none; }
  .card, .lead-table tbody tr { break-inside: avoid; }
}
