/* =========================================================================
   views/dashboard.css — Dashboard — KPI cards, chart card, calendar widget
   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.
   ========================================================================= */
/* ============================ DASHBOARD =============================== */
/* (A failed leads load swaps the .dash-status chip below for the shared
   .load-error-chip — styled in components.css, built in routeToolbars.js.) */
/* overflow-x clip: the dashboard must never scroll sideways. The scroll
   container (#viewScroll) only sets overflow-y, so the spec promotes its
   overflow-x to `auto` — meaning any few-px child overflow (chart paint,
   safe-area bleed, sub-pixel rounding) becomes a real horizontal scroll on
   mobile. Clipping here at the source stops that. `hidden` covers older
   webviews; `clip` (modern) avoids making .dash a scroll container. The KPI
   carousel + kanban keep their own nested overflow-x scrollers. */
.dash { padding: var(--space-5) var(--space-6) var(--space-6); display: flex; flex-direction: column; gap: var(--space-4); overflow-x: hidden; overflow-x: clip; }
.dash-status { display: flex; align-items: center; gap: var(--space-2); color: var(--success-600); font-size: var(--text-md); font-weight: var(--fw-medium); }
.dash-status svg { width: 18px; height: 18px; }
/* (The failed-load variant is the shared .load-error-chip — components.css.) */

.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--space-4); }
/* responsive reflow. minmax(0,1fr) keeps columns truly equal. 4-up needs real
   width (≈1366px+) or the value+vs row gets cramped — below that we use clean
   2-up, then single-column on mobile. */
@media (max-width: 1365px) { .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px)  {
  /* mobile: horizontal swipe carousel — cards bleed off-screen, snap on swipe */
  .kpi-grid {
    display: flex;
    grid-template-columns: none;
    gap: var(--space-3);
    overflow-x: auto;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    /* bleed to the screen edges, then re-inset the first/last card.
       scroll-padding makes snapping respect that inset (otherwise the first
       card snaps flush to the edge and the initial left padding is lost).
       vertical padding gives the card shadows room (an x-scroll container also
       clips on the y-axis, so without it the shadows get cut off). */
    margin-inline: calc(-1 * max(var(--space-4), var(--safe-left)));
    padding-inline: max(var(--space-4), var(--safe-left));
    scroll-padding-inline: max(var(--space-4), var(--safe-left));
    padding-block: var(--space-2);
    margin-top: calc(-1 * var(--space-1));
  }
  .kpi-grid::-webkit-scrollbar { display: none; }
  .kpi-grid > .kpi {
    flex: 0 0 80%;
    scroll-snap-align: start;
  }
}
.kpi {
  background: var(--surface); border: 1px solid var(--metric-border);
  border-radius: var(--radius-xl); padding: var(--space-5) var(--space-5) var(--space-6); box-shadow: var(--shadow-sm);
  transition: box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease);
}
@media (hover: hover) and (pointer: fine) {
  .kpi:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
}
/* clickable KPI → its filtered view (data-kpi-goto) */
.kpi--link { cursor: pointer; }
@media (hover: hover) and (pointer: fine) {
  .kpi--link:hover { border-color: var(--border-strong); }
}
.kpi-head { display: flex; align-items: center; gap: var(--space-3); }
.kpi-ico {
  width: 34px; height: 34px; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--btn-shadow);
  display: inline-flex; align-items: center; justify-content: center; color: var(--text-strong);
}
.kpi-ico svg { width: 22px; height: 22px; }
.kpi-head .label { font-size: var(--text-base); font-weight: var(--fw-semibold); color: var(--text-strong); }
.kpi-head .info { margin-left: auto; color: var(--metric-meta); display: inline-flex; }
.kpi-head .info svg { width: 17px; height: 17px; }
.kpi-body { display: flex; align-items: center; gap: var(--space-3); margin-top: var(--space-6); flex-wrap: wrap; row-gap: var(--space-1); }
.kpi-body .value { font-size: 34px; font-weight: var(--fw-bold); color: var(--text-strong); letter-spacing: -0.02em; line-height: 1; }
.kpi-body .badge { flex-shrink: 0; }
.kpi-body .vs { font-size: var(--text-xs); color: var(--metric-meta); white-space: nowrap; margin-left: auto; align-self: flex-end; }
.kpi-desc { margin: var(--space-3) 0 0; font-size: var(--text-xs); color: var(--text-soft); line-height: 1.45; text-wrap: pretty; }
/* small, minimal empty state for a KPI with no connected data source */
.kpi-empty { display: flex; flex-direction: column; align-items: flex-start; gap: 7px; margin-top: var(--space-5); }
.kpi-empty-text { font-size: var(--text-sm); color: var(--text-soft); line-height: 1.4; }
.kpi-empty-cta { display: inline-flex; align-items: center; gap: 5px; font-size: var(--text-sm); font-weight: var(--fw-semibold); color: var(--primary-600); background: none; border: none; padding: 0; cursor: pointer; transition: color var(--dur) var(--ease); }
.kpi-empty-cta svg { width: 14px; height: 14px; }
@media (hover: hover) and (pointer: fine) {
  .kpi-empty-cta:hover { color: var(--primary-700); }
}

.dash-row { display: grid; gap: var(--space-4); }
/* Calendar column == one card width of the 3-col row below (Retention Rate) */
.dash-row.r1 { grid-template-columns: 1fr calc((100% - var(--space-4) * 2) / 3); }
.dash-row.r2 { grid-template-columns: 1fr 1fr 1fr; }
/* tablet → small desktop: the chart + calendar row stacks — the calendar needs
   real width for its 7-column grid and event cards, not a cramped column. */
@media (max-width: 1300px) {
  .dash-row.r1 { grid-template-columns: minmax(0, 1fr); }
}
/* mobile: stack every dashboard row into a single column. minmax(0, 1fr)
   (not bare 1fr, whose implicit `auto` minimum is the chart SVG's intrinsic
   width) lets each cell shrink to the viewport so nothing overflows. */
@media (max-width: 640px) {
  .dash { padding: var(--space-4) max(var(--space-4), var(--safe-left)) 0 max(var(--space-4), var(--safe-right)); gap: var(--space-3); }
  .dash-row.r1, .dash-row.r2 { grid-template-columns: minmax(0, 1fr); }
}

.widget { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-xl); box-shadow: var(--shadow-sm); padding: var(--space-5); }
.widget-head { display: flex; align-items: center; gap: var(--space-2); margin-bottom: var(--space-4); }
.widget-head .wtitle { font-size: var(--text-base); font-weight: var(--fw-semibold); color: var(--text-strong); display: inline-flex; align-items: center; gap: 6px; }
.widget-head .wtitle .updown { color: var(--text-soft); display: inline-flex; }
.widget-head .wtitle .updown svg { width: 15px; height: 15px; }

/* revenue chart */
.rev-amount { display: flex; align-items: baseline; gap: var(--space-2); margin-bottom: var(--space-5); }
.rev-amount .num { font-size: var(--text-2xl); font-weight: var(--fw-bold); color: var(--text-strong); letter-spacing: -0.02em; }
.rev-amount .num .cur { color: var(--text-soft); font-weight: var(--fw-semibold); }
.rev-amount .sub { font-size: var(--text-md); color: var(--text-soft); white-space: nowrap; font-weight: var(--fw-regular); }

/* calendar widget */
#calWidget .wtitle { font-weight: var(--fw-medium); }
.cal-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); margin-bottom: var(--space-3); }
.cal-head .cal-nav { width: 28px; height: 28px; flex: none; border-radius: var(--radius-sm); display: inline-flex; align-items: center; justify-content: center; color: var(--text-muted); border: none; background: none; box-shadow: none; padding: 0; transition: background var(--dur) var(--ease); }
@media (hover: hover) and (pointer: fine) {
  .cal-head .cal-nav:hover { background: var(--nav-hover-bg); }
}
.cal-head .cal-nav svg { width: 18px; height: 18px; }
.cal-head .month { flex: 1; font-size: var(--text-md); font-weight: var(--fw-semibold); color: var(--text-strong); text-align: center; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; }
.cal-grid .dow { font-size: var(--text-xs); color: var(--text-soft); font-weight: var(--fw-medium); padding: 6px 0; }
.cal-grid .day { height: 38px; display: inline-flex; align-items: center; justify-content: center; font-size: var(--text-md); font-weight: var(--fw-bold); color: var(--text-strong); border-radius: 50%; cursor: pointer; transition: background var(--dur) var(--ease), color var(--dur) var(--ease); margin: 0 auto; width: 38px; }
@media (hover: hover) and (pointer: fine) {
  .cal-grid .day:hover { background: var(--gray-100); }
}
.cal-grid .day.active { background: var(--primary-600); color: var(--on-primary); font-weight: var(--fw-bold); }
/* dotted divider between the date grid and the event list — matches the
   deals lane divider dash pattern */
.cal-sep { height: 1px; margin: var(--space-4) 0 var(--space-1); background-image: repeating-linear-gradient(to right, var(--border-strong) 0 7px, transparent 7px 13px); }
.cal-event { display: flex; align-items: flex-start; gap: var(--space-3); padding: var(--space-4); margin-top: var(--space-3); border-radius: var(--radius-lg); background: var(--surface-event); }
/* the inner wrapper defaults to min-width:auto and won't shrink — that blocks
   the title from truncating and pushes the card (and the calendar) too wide */
.cal-event > div { min-width: 0; flex: 1; }
.cal-event .row-between { min-width: 0; gap: var(--space-2); }
.cal-event .etitle { font-size: var(--text-md); font-weight: var(--fw-semibold); color: var(--text-strong); white-space: nowrap; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.cal-event .etime { font-size: var(--text-xs); color: var(--text-soft); margin-left: auto; white-space: nowrap; padding-left: var(--space-3); flex-shrink: 0; }
.cal-event .erow { display: flex; align-items: center; margin-top: var(--space-2); flex-wrap: wrap; gap: var(--space-2); }
.cal-event .avatar-stack { flex-shrink: 0; }
.cal-event .ebtn { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border: 1px solid var(--border); border-radius: var(--radius-md); font-size: var(--text-sm); font-weight: var(--fw-medium); color: var(--btn-card-fg); background: var(--surface); box-shadow: var(--btn-shadow-card); transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease); }
@media (hover: hover) and (pointer: fine) {
  .cal-event .ebtn:hover { background: var(--gray-50); border-color: var(--border-strong); }
}
.cal-event .ebtn svg { width: 14px; height: 14px; color: var(--btn-card-fg); }
/* dashboard widget: rail rows (matches the calendar's rail chips) — a 2px
   calendar-colour rail + a light tint of the same colour as the fill */
.cal-event.cal-ev-card { cursor: pointer; background: color-mix(in srgb, var(--ev, var(--border-strong)) 7%, var(--surface)); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; margin-top: var(--space-2); padding: 9px var(--space-3); border-left: 2.5px solid var(--ev, var(--border-strong)); text-align: left; width: 100%; transition: background var(--dur) var(--ease); }
@media (hover: hover) and (pointer: fine) {
  .cal-event.cal-ev-card:hover { background: color-mix(in srgb, var(--ev, var(--primary-600)) 14%, var(--surface)); }
}
.cal-event.cal-ev-card .ebtn.cal-ev-join { height: 28px; padding: 0 10px; }
/* The calendar shares row r1 with the chart, and a grid row is as tall as its
   tallest item — so a busy day must never let the EVENT LIST set the row
   height. The widget is a flex column whose list scrolls:
   - stacked / solo layouts: the list is capped (max-height) and scrolls;
   - two-col desktop (chart visible): the widget body absolute-fills its card,
     so the CHART alone sizes the row and the list scrolls inside exactly that
     height. Guarded with :has on a visible chart — an absolutely positioned
     calendar alone in the row would collapse it to zero height. */
.cal-widget { display: flex; flex-direction: column; min-height: 0; }
.cal-widget > * { flex: 0 0 auto; }
.cal-events { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; max-height: 430px; overflow-y: auto; overscroll-behavior: contain; }
@media (min-width: 1301px) {
  .dash-row.r1:has(> [data-widget="chart"]:not([hidden])) > #calWidget { position: relative; }
  /* inset replicates the card's --space-5 padding, which absolute ignores */
  .dash-row.r1:has(> [data-widget="chart"]:not([hidden])) > #calWidget > .cal-widget { position: absolute; inset: var(--space-5); }
  .dash-row.r1:has(> [data-widget="chart"]:not([hidden])) > #calWidget .cal-events { max-height: none; }
}
.cal-ev-empty { display: flex; align-items: center; gap: var(--space-2); margin-top: var(--space-3); padding: var(--space-4) var(--space-3); color: var(--text-soft); font-size: var(--text-sm); font-weight: var(--fw-medium); }
.cal-ev-empty svg { width: 16px; height: 16px; flex: none; color: var(--text-soft); }
/* week-strip day markers */
.cal-grid .day.is-today:not(.active) { color: var(--primary-600); }
/* small accent dot on today (hidden when today is the selected day) */
.cal-grid .day.is-today { position: relative; }
.cal-grid .day.is-today:not(.active)::after { content: ""; position: absolute; bottom: 4px; left: 50%; transform: translateX(-50%); width: 4px; height: 4px; border-radius: 50%; background: var(--primary-600); }
.cal-grid .day.has-ev { position: relative; }
.cal-grid .day.has-ev::after { content: ""; position: absolute; bottom: 4px; left: 50%; transform: translateX(-50%); width: 4px; height: 4px; border-radius: 50%; background: var(--primary-500); }
.cal-grid .day.active.has-ev::after { background: var(--on-primary); }

/* leads management */
.leads-bars { display: flex; flex-direction: column; gap: var(--space-4); margin-top: var(--space-5); }
.leads-bar { display: grid; grid-template-columns: 90px 1fr; align-items: center; gap: var(--space-3); }
.leads-bar .lname { font-size: var(--text-sm); color: var(--text-muted); }
.leads-bar .track { height: 18px; border-radius: var(--radius-xs); background: repeating-linear-gradient(115deg, var(--primary-400) 0 7px, var(--primary-300) 7px 14px); }

/* top country */
.country-row { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-2) 0; font-size: var(--text-md); }
.country-row .rank { color: var(--text-soft); width: 14px; }
.country-row .flag { width: 22px; height: 22px; border-radius: 50%; background: var(--gray-100); display: inline-flex; align-items: center; justify-content: center; font-size: 12px; }
.country-row .cname { color: var(--text); }
.country-row .cpct { margin-left: auto; font-weight: var(--fw-semibold); color: var(--text-strong); }
.map-box { border-radius: var(--radius-lg); background: var(--gray-50); border: 1px solid var(--border); position: relative; min-height: 160px; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.map-box svg { width: 80%; height: auto; opacity: 0.9; }
.map-zoom { position: absolute; left: 12px; bottom: 12px; display: flex; gap: 6px; }
.map-zoom button { width: 28px; height: 28px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); color: var(--text-muted); display: inline-flex; align-items: center; justify-content: center; }
@media (hover: hover) and (pointer: fine) {
  .map-zoom button:hover { background: var(--gray-50); }
}
.map-expand { position: absolute; right: 12px; top: 12px; width: 28px; height: 28px; border-radius: var(--radius-sm); background: var(--surface); border: 1px solid var(--border); color: var(--text-muted); display: inline-flex; align-items: center; justify-content: center; }
.view-more { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 14px; border: 1px solid var(--border); border-radius: var(--radius-md); font-size: var(--text-sm); font-weight: var(--fw-medium); color: var(--btn-card-fg); background: var(--surface); box-shadow: var(--btn-shadow-card); transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease); }
@media (hover: hover) and (pointer: fine) {
  .view-more:hover { background: var(--gray-50); border-color: var(--border-strong); }
}
.view-more svg { width: 15px; height: 15px; color: var(--btn-card-fg); }

/* retention stacked bars */
.legend { display: flex; gap: var(--space-4); margin: var(--space-1) 0 var(--space-5); }
.legend span { display: inline-flex; align-items: center; gap: 6px; font-size: var(--text-xs); color: var(--text-muted); }
.legend i { width: 8px; height: 8px; border-radius: 50%; }
.ret-bars { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--space-2); height: 120px; }
.ret-col { display: flex; flex-direction: column; align-items: center; gap: var(--space-2); flex: 1; }
.ret-stack { width: 60%; max-width: 30px; display: flex; flex-direction: column; border-radius: var(--radius-xs); overflow: hidden; }
.ret-stack i { display: block; }
.ret-col .rl { font-size: var(--text-xs); color: var(--text-soft); }
.ret-col.cur .rl { color: var(--text-strong); font-weight: var(--fw-semibold); }

/* placeholder route */
.placeholder { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--space-4); padding: var(--space-12); text-align: center; min-height: 70%; }
.placeholder .pico { width: 72px; height: 72px; border-radius: var(--radius-xl); background: var(--primary-50); color: var(--primary-600); display: inline-flex; align-items: center; justify-content: center; }
.placeholder .pico svg { width: 34px; height: 34px; }
.placeholder h2 { font-size: var(--text-xl); color: var(--text-strong); font-weight: var(--fw-semibold); }
.placeholder p { color: var(--text-muted); max-width: 360px; }
.placeholder .badge { margin-top: var(--space-1); }
