/* =========================================================================
   views/leads.css — Leads — companies table, Gmail-style star column, kanban board
   Split from the old monolithic styles/views.css. LOAD ORDER MATTERS:
   the <link> order in Magnet CRM.html / Client App.html reproduces the
   original file order, so the cascade is unchanged — add new rules to the
   matching feature file, not the end of the list.
   ========================================================================= */
/* ============================ COMPANIES TABLE ========================== */
/* The table fills the available height; #viewScroll handles overflow and the
   leads list reveals rows in batches as you scroll (infinite scroll), so there
   is no pager. */
.table-wrap { padding: var(--space-5) var(--space-6) var(--space-6); display: flex; flex-direction: column; min-height: 100%; }
.table-card {
  border: 1px solid var(--border); border-radius: var(--radius-xl);
  overflow: hidden; background: var(--surface);
  flex: 1 1 auto;   /* fill the wrap's height — never a short floating card */
}
/* empty: header sits at top, the empty state flex-fills the rest of the card
   and centres its illustration */
.table-card.is-empty { display: flex; flex-direction: column; }
.table-card.is-empty .ctable { flex: 0 0 auto; }
.table-card.is-empty .empty-state { flex: 1 1 auto; min-height: 0; }
.ctable { width: 100%; border-collapse: collapse; table-layout: fixed; }
/* infinite scroll: rows past the current batch stay hidden until revealed */
.ctable tbody tr.lead-hidden { display: none; }
.ctable th, .ctable td { text-align: left; padding: 0 var(--space-5); }
.ctable thead th {
  height: 40px; background: var(--surface-sunk);
  font-size: var(--text-sm); font-weight: var(--fw-semibold); color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
/* label + sort caret sit together at the left of the column — the caret
   reads as part of the title, not as a right-edge control */
.ctable .th-inner { display: flex; align-items: center; justify-content: flex-start; gap: var(--space-0-5); width: 100%; }
.ctable .sort-ico {
  display: inline-flex; color: var(--text-soft); cursor: pointer;
  width: 22px; height: 22px; border-radius: var(--radius-xs);
  align-items: center; justify-content: center;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
@media (hover: hover) and (pointer: fine) {
  .ctable .sort-ico:hover { background: var(--gray-150); color: var(--text); }
}
.ctable .sort-ico svg { width: 15px; height: 15px; }
.ctable tbody td { height: 66px; border-bottom: 1px solid var(--border); font-size: var(--text-md); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* default text cells (email, source) clip with an ellipsis instead of
   wrapping into the next row */
.ctable tbody td.email-cell, .ctable tbody td.source-cell { color: var(--text-muted); }
.ctable tbody tr:last-child td { border-bottom: none; }
.ctable tbody tr { transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease); }
.ctable tbody tr.selected { background: var(--surface-hover); }
@media (hover: hover) and (pointer: fine) {
  .ctable tbody tr:hover { background: var(--surface-hover); }
  .ctable tbody tr.selected:hover { background: var(--surface-hover-strong); }
}
/* keyboard: lead rows are role="button" + tabindex (LeadsViews wires
   Enter/Space) — an INSET ring so the collapsed row borders don't clip it */
.ctable tbody tr:focus-visible { outline: none; box-shadow: inset var(--ring-primary); }

.contact-cell { display: flex; align-items: center; gap: var(--space-3); }
.contact-cell .name { color: var(--text); font-weight: var(--fw-medium); }
.date-cell { color: var(--text-muted); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.phone-cell { color: var(--text-muted); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.business-cell { color: var(--text-strong); font-weight: var(--fw-semibold); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-cell { min-width: 0; }
.contact-cell .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.col-actions { text-align: center; }
.col-actions .th-inner { justify-content: center; }
.ctable th.col-actions, .ctable td.col-actions { padding: 0 var(--space-3); }
.ctable td.col-actions { text-align: center; }
.ctable td.col-actions .kebab { margin: 0 auto; }

/* ---------- Calls column (read-only tables) -----------------------------
   Takes the actions slot in read-only sessions (the trainer realm): the
   number of recorded calls on the lead. The explicit svg size is required —
   an unsized icon in a table cell stretches to the column width and blows
   the row height out. ---------------------------------------------------- */
.ctable th.col-calls, .ctable td.calls-cell { padding: 0 var(--space-3); text-align: center; }
.col-calls .th-inner { justify-content: center; }
.lead-calls {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: var(--text-sm); color: var(--text-soft);
  font-variant-numeric: tabular-nums; line-height: 1;
}
.lead-calls svg { width: 15px; height: 15px; flex: none; }
.lead-calls.is-none { opacity: 0.45; }
.lead-calls.has-unreviewed { color: var(--primary-700); font-weight: var(--fw-semibold); }
/* ---------- Gmail-style star column (leadStars.js) -----------------------
   Always-on, narrow, anchored to the left of each lead row. Empty outline by
   default (subtle text-soft); fills yellow on click. Hover ring mimics
   Gmail's 36px focus circle. text-align needs the .ctable td selector to win
   the specificity fight against the global ".ctable th, .ctable td { text-align:
   left }" — without it the star left-aligns and the right padding looks much
   bigger than the left.
------------------------------------------------------------------------- */
.ctable th.col-star, .ctable td.col-star { padding: 0 var(--space-1); text-align: center; }
.ctable th.col-star .th-inner { justify-content: center; }
.lead-star {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px;
  margin: 0 auto;
  border: 0; background: transparent; border-radius: 50%;
  color: var(--text-soft); cursor: pointer;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.lead-star svg { width: 18px; height: 18px; }
@media (hover: hover) and (pointer: fine) {
  .lead-star:hover { background: var(--gray-50); color: var(--text); }
}
.lead-star:active { transform: scale(0.92); }
.lead-star.is-on { color: var(--brand-gold-deep); }   /* Magnet gold, not the accent — a star is identity, not interaction */
.lead-star.is-on svg path { fill: currentColor; }
/* "Starred only" option in the leads Filter menu — gold filled star + label */
.filter-opt .opt-star { display: inline-flex; align-items: center; gap: var(--space-2); }
.filter-opt .opt-star svg { width: 16px; height: 16px; color: var(--brand-gold-deep); }
.filter-opt .opt-star svg path { fill: currentColor; }
/* generic icon+label menu row — muted stroke (the gold above is the star's alone) */
.filter-opt .opt-ic { display: inline-flex; align-items: center; gap: var(--space-2); }
.filter-opt .opt-ic svg { width: 16px; height: 16px; color: var(--text-soft); }
.status-cell { display: inline-flex; align-items: center; gap: var(--space-2); max-width: 100%; min-width: 0; }
.status-td { overflow: hidden; }
.status-td .due-chip { flex-shrink: 0; }
/* (4 Sep wave 2) outlined status pill — dot + label inside a hairline pill,
   the reference's "• Active" table status; still the dropdown trigger */
.stage-trigger {
  display: inline-flex; align-items: center; gap: 5px; height: 26px; padding: 0 var(--space-1-5) 0 var(--space-2);
  border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius-full); cursor: pointer;
  font-size: var(--text-xs); font-weight: var(--fw-medium);
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
@media (hover: hover) and (pointer: fine) {
  .stage-trigger:hover { background: var(--gray-50); border-color: var(--border-strong); }
}
.stage-trigger > svg { width: 14px; height: 14px; color: var(--text-soft); }
.due-chip {
  display: inline-flex; align-items: center; height: 20px; padding: 0 var(--space-2);
  border-radius: var(--radius-full); font-size: var(--text-2xs); font-weight: var(--fw-semibold);
  color: var(--primary-700); background: var(--primary-50); white-space: nowrap;
}
/* the chip is a real button now (click → set/change the follow-up date) */
button.due-chip { border: 0; font-family: inherit; cursor: pointer; }
.due-chip--soon { color: var(--on-primary); background: var(--primary-600); }
/* past due — red, unmissable */
.due-chip--overdue { color: var(--text-invert); background: var(--danger-600); }
/* honest empty state — no stored date, nothing fabricated */
.due-chip--none { color: var(--text-soft); background: transparent; box-shadow: inset 0 0 0 1px var(--border-strong); }
@media (hover: hover) and (pointer: fine) {
  button.due-chip:hover { filter: brightness(0.96); }
  button.due-chip--none:hover { filter: none; background: var(--surface-hover-strong); color: var(--text); }
}

/* pagination */
.pagination {
  display: flex; align-items: center; gap: var(--space-4);
  padding: var(--space-4) var(--space-6);
}
.pager { display: flex; align-items: center; gap: var(--space-1); }
.pager button {
  min-width: 36px; height: 36px; padding: 0 var(--space-2);
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm); color: var(--text-muted);
  font-size: var(--text-md); font-weight: var(--fw-medium);
  border: 1px solid transparent;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.pager button svg { width: 16px; height: 16px; }
@media (hover: hover) and (pointer: fine) {
  .pager button:hover:not(.active):not(:disabled) { background: var(--gray-100); color: var(--text); }
}
.pager button.active { background: var(--primary-600); color: var(--on-primary); }
.pager button:disabled { opacity: 0.4; cursor: default; }
.pagination .right { margin-left: auto; display: flex; align-items: center; gap: var(--space-3); color: var(--text-muted); font-size: var(--text-md); }
.per-page {
  display: inline-flex; align-items: center; gap: var(--space-2);
  height: 36px; padding: 0 var(--space-3); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text); font-weight: var(--fw-medium);
  cursor: pointer; transition: border-color var(--dur) var(--ease);
}
@media (hover: hover) and (pointer: fine) {
  .per-page:hover { border-color: var(--border-strong); }
}
.per-page svg { width: 15px; height: 15px; color: var(--text-soft); }

/* ============================ DEALS KANBAN ============================ */
.kanban { display: flex; gap: var(--space-4); padding: var(--space-5) var(--space-6) 0; align-items: stretch; min-height: 100%; }

/* Column lane — light grey track that groups cards under a status.
   Stretches to the full board height so short lanes still run to the bottom. */
.kcol {
  flex: 1; min-width: 0; max-width: none;
  display: flex; flex-direction: column; gap: var(--space-2-5);
  align-self: stretch;
  background: var(--surface-lane);
  border: none;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 11px;
}

/* Column header — flat, short, integrated into the lane */
.kcol-head {
  display: flex; align-items: center; gap: 7px;
  height: 30px; padding: 0 var(--space-0-5) var(--space-2);
  margin-bottom: 1px;
}
.kcol-head .grip { color: var(--gray-400); display: inline-flex; cursor: grab; }
.kcol-head .grip svg { width: 14px; height: 14px; }
.kcol-head .bar { width: 3px; height: 14px; border-radius: 2px; }
.kcol-head .title { font-size: var(--text-md); font-weight: var(--fw-semibold); color: var(--text-strong); }
.kcol-head .chip-count {
  margin-left: auto; min-width: 0; height: auto; padding: 0;
  background: none; color: var(--text-soft); font-size: var(--text-sm); font-weight: var(--fw-semibold);
}
.kcol[data-stage="Leads"]     .bar { background: var(--stage-leads); }
.kcol[data-stage="Discovery"] .bar { background: var(--stage-discovery); }
.kcol[data-stage="Demo"]      .bar { background: var(--stage-demo); }
.kcol[data-stage="Won"]       .bar { background: var(--stage-won); }
.kcol[data-stage="Lead"]      .bar { background: var(--stage-leads); }
.kcol[data-stage="Follow Up"] .bar { background: var(--stage-discovery); }
.kcol[data-stage="Consult"]   .bar { background: var(--stage-demo); }
.kcol[data-stage="Closed"]    .bar { background: var(--stage-won); }

/* mobile: board scrolls horizontally — one column at a time */
@media (max-width: 640px) {
  #viewScroll > .kanban {
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
    scroll-padding-inline: max(var(--space-4), var(--safe-left));
    padding: var(--space-4) max(var(--space-4), var(--safe-left)) 0;
  }
  #viewScroll > .kanban > .kcol {
    flex: 0 0 82%; min-width: 0; scroll-snap-align: start;
  }
}

/* Card — compact, white, borderless; the lane plane + shadow separate it */
.kcard {
  background: var(--surface); border: 1px solid transparent;
  border-radius: var(--radius-md); padding: var(--space-3);
  box-shadow: var(--shadow-sm); cursor: grab;
  transition: box-shadow var(--dur) var(--ease), border-color var(--dur) var(--ease), transform var(--dur) var(--ease);
}
@media (hover: hover) and (pointer: fine) {
  .kcard:hover { box-shadow: var(--shadow-md); border-color: var(--border); transform: translateY(-1px); }
}
/* keyboard: cards are role="button" + tabindex (LeadsViews wires Enter/Space) */
.kcard:focus-visible { outline: none; box-shadow: var(--ring-primary), var(--shadow-sm); }
.kcard .badges { display: flex; gap: var(--space-1-5); margin-bottom: var(--space-2-5); }
.kcard .deal-title { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-md); font-weight: var(--fw-semibold); color: var(--text-strong); min-width: 0; }
.kcard .deal-title span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* small fallback brand mark inside cards */
.kcard .deal-title .logo { width: 20px; height: 20px; font-size: var(--text-3xs); border-radius: var(--radius-xs); }
.kcard .deal-desc {
  margin-top: 7px; font-size: var(--text-sm); color: var(--text-muted); line-height: var(--leading-snug);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* dashed divider above the Add Task button — slim dashes, sits in normal
   flow directly after the last card (not pinned to the lane bottom). */
.lane-divider {
  height: 1px; margin: 1px 0; border: none;
  background-image: repeating-linear-gradient(to right, var(--border-strong) 0 7px, transparent 7px 13px);
}

/* Add Task — quiet soft placeholder */
.add-task {
  width: 100%; height: 40px; border-radius: var(--radius-md);
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  border: 1px dashed var(--border-strong); background: var(--surface-field);
  color: var(--text-muted); font-size: var(--text-sm); font-weight: var(--fw-medium);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.add-task svg { width: 16px; height: 16px; }
.add-task span { white-space: nowrap; }
@media (hover: hover) and (pointer: fine) {
  .add-task:hover { background: var(--gray-100); color: var(--text); border-color: var(--gray-400); }
}

/* lead card footer (Leads board). min-width:0 + a truncating name keep the
   due-chip INSIDE the card on narrow columns (flex children never shrink
   nowrap content by default, so the chip used to poke past the card edge);
   wrap is the last-resort fallback for ultra-narrow cards. */
.kcard .lead-foot { display: flex; align-items: center; gap: var(--space-2); margin-top: 11px; padding-top: var(--space-2-5); border-top: 1px solid var(--border-faint); font-size: var(--text-sm); min-width: 0; flex-wrap: wrap; row-gap: var(--space-1); }
.kcard .lead-foot .avatar { width: 22px; height: 22px; font-size: var(--text-micro); flex: none; }
.kcard .lead-foot .lname { color: var(--text-muted); font-weight: var(--fw-medium); flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kcard .lead-foot .due-chip { margin-left: auto; flex: none; max-width: 100%; }

/* board drag-and-drop */
.kcard.is-dragging {
  opacity: 0.9; cursor: grabbing;
  box-shadow: var(--shadow-lg);
  transform: rotate(-1.4deg) scale(1.02);
}
@media (prefers-reduced-motion: reduce) {
  .kcard.is-dragging { transform: none; opacity: 0.55; }
}
.kcol.drag-over {
  background: var(--surface-hover-strong);
  border-radius: var(--radius-md);
  box-shadow: inset 0 0 0 2px var(--primary-300);
}

/* ===== Unified Leads filter — tile root + drill-in panels ================
   One "Filter" trigger (routeToolbars.leadsToolsDd) opens a 2×2 tile root
   (Date / Status / Source / Sort); a tile swaps in that panel with a back
   row. Active filters stay visible closed: tinted trigger + count badge,
   and each tile captions its current value. Mobile reuses the FilterSheet
   treatment (panels are .filter-menu inside the relocated .filter-dd). */
.lf-root { min-width: 272px; padding: var(--space-2); }
.lf-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-2); }
.lf-tile {
  display: flex; flex-direction: column; align-items: flex-start;
  padding: var(--space-2-5) var(--space-3); border: 1px solid var(--border);
  border-radius: var(--radius-md); background: var(--surface);
  cursor: pointer; text-align: left; min-width: 0;
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}
@media (hover: hover) and (pointer: fine) {
  .lf-tile:hover { border-color: var(--border-strong); background: var(--surface-hover); }
}
.lf-tile-ico {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: var(--radius-sm);
  background: var(--gray-100); color: var(--text-muted); margin-bottom: var(--space-1-5);
}
.lf-tile-ico svg { width: 15px; height: 15px; }
.lf-tile-label { font-size: var(--text-sm); font-weight: var(--fw-semibold); color: var(--text-strong); }
.lf-tile-cap { max-width: 100%; font-size: var(--text-2xs); color: var(--text-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lf-tile.is-active { border-color: var(--primary-400); background: color-mix(in srgb, var(--primary-500) 5%, var(--surface)); }
.lf-tile.is-active .lf-tile-ico { background: var(--primary-50); color: var(--primary-600); }
.lf-tile.is-active .lf-tile-cap { color: var(--primary-600); font-weight: var(--fw-semibold); }

/* the two toolbar pills sit side by side inside one positioned dd */
.leads-tools-dd { display: inline-flex; gap: var(--space-2); }
#leadsSortTrigger b { font-weight: var(--fw-semibold); }

/* trigger surfaces the applied-filter count */
.lf-count {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: var(--radius-full);
  background: var(--primary-600); color: var(--on-primary);
  font-size: var(--text-2xs); font-weight: var(--fw-semibold); line-height: 1;   /* line-height 1: the digit sits dead centre */
}
#leadsToolsTrigger.lf-active, #leadsSortTrigger.lf-active { border-color: var(--primary-400); color: var(--primary-600); }

/* desktop back row atop each panel (mobile back = the sheet-head arrow) */
.lf-back { color: var(--text-muted); font-weight: var(--fw-semibold); border-radius: var(--radius-sm) var(--radius-sm) 0 0;   /* the hover fill meets the menu's rounded top */ border-bottom: 1px solid var(--border-faint); margin-bottom: var(--space-1); }
.filter-opt.lf-back svg { margin-left: 0; margin-right: var(--space-1); width: 15px; height: 15px; color: var(--text-soft); }   /* the chevron leads (beats .filter-opt svg's right-hand tick placement) */
@media (max-width: 640px) { .lf-back { display: none; } }
/* Sources-breakdown / view-switch rows ride the mobile sheet only — the
   desktop toolbar keeps its dedicated buttons for both */
@media (min-width: 641px) { .lf-mobile-extra { display: none; } }
