/* src/styles/pages.css: the Overview funnel panel, and the Calls, Pipeline and
 * Leads pages. Owned by the ui stage. Built only from tokens.css variables and
 * the existing panel, toggle and KPI classes, so nothing here changes another
 * page.
 *
 * PHONE WIDTH IS THE DESIGN TARGET (390px). The rules that keep it true:
 *   - every page is a column of panels and every panel is min-width: 0, so no
 *     child can push the page wider than the screen
 *   - every table lives inside .cl-scroll (or the By Firm table's own
 *     .wow-scroll), which scrolls sideways by itself; the first column is
 *     sticky so a row keeps its name while it scrolls
 *   - chips scroll sideways inside their own row
 *   - the date presets wrap instead of overflowing
 */

.cl-page {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
  padding-bottom: 24px;
}

.cl-page > * {
  min-width: 0;
}

.range-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

/* The preset toggle is an inline-flex row of six buttons; on a narrow screen
   it wraps rather than running off the edge (this also fixes the Ads page). */
.toggle {
  flex-wrap: wrap;
  max-width: 100%;
}

/* The KPI strip's row break: a full-width, zero-height flex item between two rows of cards. */
.cc-kpi-break {
  flex: 0 0 100%;
  height: 0;
  margin-top: -12px; /* the row gap above and below it would otherwise add up to 24px */
}

/* ------------------------------------------------------------- panels */

.cl-panel {
  padding: 18px 18px 10px;
  min-width: 0;
}

.cl-panel .panel-head {
  margin-bottom: 14px;
  flex-wrap: wrap;
  gap: 8px 16px;
}

.cl-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -6px;
}

.cl-foot {
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--text-faint);
  padding: 10px 2px 6px;
}

.cl-faint {
  color: var(--text-faint);
  font-weight: 400;
}

.cl-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 550;
}

.cl-link:hover {
  text-decoration: underline;
}

.cl-badge {
  align-self: flex-start;
  font-size: 12px;
  color: var(--text-dim);
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--hairline);
  border-radius: 999px;
  padding: 4px 11px;
  white-space: nowrap;
}

/* ------------------------------------------------------------- tables */

.cl-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

.cl-table th {
  text-align: right;
  font-size: 10.5px;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
  padding: 9px 10px;
  border-bottom: 1px solid var(--hairline-strong);
  white-space: nowrap;
}

.cl-table td {
  text-align: right;
  padding: 10px;
  color: var(--text);
  border-bottom: 1px solid var(--hairline);
  white-space: nowrap;
}

.cl-table tbody tr:last-child td {
  border-bottom: 0;
}

.cl-table tbody tr:hover td {
  background: rgba(255, 255, 255, 0.025);
}

.cl-table th.sticky-col,
.cl-table td.sticky-col {
  position: sticky;
  left: 0;
  text-align: left;
  background: var(--table-frozen-bg);
  z-index: 1;
}

.cl-table th.sticky-col {
  z-index: 2;
}

.cl-table tbody tr:hover td.sticky-col {
  background: var(--table-frozen-bg-hover);
}

.cl-table.cl-left th,
.cl-table.cl-left td {
  text-align: left;
}

.cl-table td.pos,
.cl-table th.pos {
  color: var(--pos);
}

.cl-table td.neg,
.cl-table th.neg {
  color: var(--neg);
}

.cl-table td.strong {
  font-weight: 700;
}

.cl-table tr.grand td {
  border-top: 1px solid var(--hairline-strong);
  font-weight: 700;
}

/* The rep board: a label column, then the team, then a column per rep. */
.cl-board td.sticky-col {
  white-space: normal;
  min-width: 128px;
  max-width: 168px;
  line-height: 1.25;
}

.cl-board th:not(.sticky-col),
.cl-board td:not(.sticky-col) {
  min-width: 88px;
}

.cl-board th.team,
.cl-board td.team {
  background: rgba(37, 99, 235, 0.07);
}

.cl-board td.best {
  color: var(--pos);
  font-weight: 700;
}

/* ---------------------------------------------------------- KPI extras */

.cl-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(118px, 1fr));
  gap: 10px;
  padding-bottom: 10px;
}

.cl-stat {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--hairline);
  border-radius: 12px;
  padding: 10px 12px;
}

.cl-stat-label {
  font-size: 10.5px;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.cl-stat-val {
  font-size: 22px;
  font-weight: 700;
  margin-top: 4px;
}

/* ------------------------------------------------------ dials by day */

.cl-bars {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 120px;
}

.cl-bar {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  height: 100%;
}

.cl-bar-dials,
.cl-bar-pickups {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: 3px 3px 0 0;
}

.cl-bar-dials {
  background: rgba(37, 99, 235, 0.28);
}

.cl-bar-pickups {
  background: var(--accent-fill);
  z-index: 1;
}

.cl-axis {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-faint);
  margin-top: 6px;
  padding-bottom: 6px;
}

/* ---------------------------------------------------------- pipeline */

.cl-stage-name {
  display: block;
  font-weight: 600;
}

.cl-meter {
  display: block;
  height: 4px;
  min-width: 96px;
  margin-top: 5px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 3px;
}

.cl-meter span {
  display: block;
  height: 100%;
  background: var(--accent-fill);
  border-radius: 3px;
}

.cl-meter.wide {
  height: 6px;
}

.cl-final td {
  color: var(--text-faint);
}

.cl-wk {
  width: 132px;
}

.cl-wk-bar {
  display: flex;
  height: 8px;
  width: 120px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 4px;
}

.cl-wk-bar span {
  display: block;
  height: 100%;
}

.cl-wk-bar .won {
  background: var(--pos);
}

.cl-wk-bar .lost {
  background: var(--neg);
}

.cl-reasons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: 10px;
}

.cl-reason-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  margin-bottom: 5px;
}

/* ------------------------------------------------------------- leads */

.ld-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* On a phone the chips are one row that scrolls sideways, without a scrollbar. */
@media (max-width: 640px) {
  .ld-chips {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 2px;
  }

  .ld-chips::-webkit-scrollbar {
    display: none;
  }
}

/* The day list scrolls inside itself so the lead list under it stays in reach. */
.cl-days-scroll {
  max-height: 420px;
  overflow: auto;
}

.cl-days-scroll thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--table-frozen-bg);
}

.cl-days-scroll thead th.sticky-col {
  z-index: 4;
}

.ld-chip {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 550;
  color: var(--text-dim);
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--hairline);
  border-radius: 999px;
  padding: 7px 13px;
  cursor: pointer;
  transition: color 0.18s, background 0.18s, border-color 0.18s;
}

.ld-chip:hover {
  color: var(--text);
  border-color: var(--hairline-strong);
}

.ld-chip.active {
  color: #fff;
  background: linear-gradient(180deg, rgba(37, 99, 235, 0.28), rgba(37, 99, 235, 0.14));
  border-color: rgba(37, 99, 235, 0.45);
}

.ld-chip-n {
  color: var(--text-faint);
}

.ld-chip.active .ld-chip-n {
  color: var(--text-dim);
}

.cl-cell {
  font: inherit;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  background: none;
  border: 0;
  border-bottom: 1px dotted var(--hairline-strong);
  border-radius: 0;
  padding: 2px 4px;
  cursor: pointer;
}

.cl-cell:hover {
  color: var(--accent);
}

.cl-cell.active {
  color: #fff;
  background: rgba(37, 99, 235, 0.25);
  border-bottom-color: transparent;
  border-radius: 5px;
}

.cl-zero {
  color: var(--text-faint);
}

.cl-pill {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 999px;
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.06);
}

.cl-pill.open {
  color: var(--accent);
  background: rgba(37, 99, 235, 0.14);
}

.cl-pill.won {
  color: var(--pos);
  background: rgba(55, 224, 166, 0.12);
}

.cl-pill.lost {
  color: var(--neg);
  background: rgba(255, 107, 125, 0.12);
}

.cl-pill.abandoned {
  color: var(--text-faint);
}

/* --------------------------------------------------- funnel panel (Overview) */

.fr-panel {
  padding: 18px 18px 12px;
  min-width: 0;
}

.fr-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.fr-side-list {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--hairline);
}

.fr-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.fr-label {
  font-size: 13px;
  font-weight: 600;
}

.fr-val {
  font-size: 16px;
  font-weight: 700;
}

.fr-bar {
  height: 8px;
  margin-top: 6px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 4px;
}

.fr-bar-fill {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--accent-fill), var(--accent-fill-2));
  border-radius: 4px;
}

.fr-bar-fill.side {
  background: linear-gradient(90deg, rgba(255, 107, 125, 0.6), rgba(255, 107, 125, 0.3));
}

.fr-bar-fill.muted {
  background: rgba(144, 161, 185, 0.5);
}

.fr-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 14px;
  margin-top: 4px;
  font-size: 11.5px;
  color: var(--text-faint);
}

.fr-foot {
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--text-faint);
  padding: 14px 2px 4px;
}

/* --------------------------------------------------------- narrow screens */

@media (max-width: 440px) {
  .cl-panel,
  .fr-panel {
    padding: 14px 12px 8px;
    border-radius: 18px;
  }

  .cl-table th {
    padding: 8px 7px;
  }

  .cl-table td {
    padding: 9px 7px;
  }

  .toggle button {
    padding: 6px 10px;
  }

  .cl-stat-val {
    font-size: 19px;
  }

  /* Tighter KPI tiles, so the Ads page's fifteen do not fill two screens. */
  .cc-kpis {
    gap: 8px;
  }

  .cc-kpi {
    padding: 11px 13px;
    border-radius: 14px;
  }

  .cc-kpi-val {
    font-size: 22px;
    margin-top: 4px;
  }

  .cc-kpi-break {
    margin-top: -8px;
  }

  /* The Ads table's frozen name column keeps to a third of the screen, so the numbers beside it stay in view. */
  .ads-table td.ads-sticky {
    max-width: 150px;
  }

  .ads-table td.ads-name > span:last-child {
    display: inline-block;
    max-width: 78px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .cl-board td.sticky-col {
    min-width: 112px;
    max-width: 132px;
  }

  .cl-board th:not(.sticky-col),
  .cl-board td:not(.sticky-col) {
    min-width: 76px;
  }
}

/* ------------------------------------------------- pipeline stage figures */

.cl-inputs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}

.cl-input-block {
  border: 1px solid var(--hairline);
  border-radius: 12px;
  padding: 12px 14px;
  background: var(--card);
  min-width: 0;
}

.cl-input-stage {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
}

.cl-input-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.cl-input-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  font-size: 12.5px;
}

.cl-input-row dt {
  color: var(--text-dim);
  min-width: 0;
}

.cl-input-row dd {
  text-align: right;
  font-weight: 500;
  overflow-wrap: anywhere;
}

/* ------------------------------------------------------------ call rows */

.cl-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.cl-select {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--hairline-strong);
  border-radius: 10px;
  padding: 7px 10px;
  font: inherit;
  font-size: 13px;
  max-width: 100%;
}

.cl-rec {
  white-space: nowrap;
}

.cl-lead-calls td {
  background: var(--card);
}

.cl-link-btn {
  background: none;
  border: 0;
  padding: 0;
  color: var(--accent);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
  text-decoration: underline;
}

.cl-score {
  white-space: nowrap;
}

button.cl-bar {
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

.cl-bar.active {
  outline: 1px solid var(--accent);
  outline-offset: 2px;
}

/* The My Accident Plan badge in the Leads list: about 20 px on a light chip, so the dark badge ring reads on the dark table. */
.cl-src {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  margin-right: 8px;
  border-radius: 999px;
  background: #e8eef5;
  vertical-align: middle;
  flex: none;
}

.cl-src img {
  display: block;
  width: 20px;
  height: 20px;
  border-radius: 999px;
}
