/* =========================================================================
   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; }
/* urgent account-level alerts (from /api/alerts) — one line each above the KPIs, the fix behind "What to do" */
.dash-alerts { display: flex; flex-direction: column; gap: var(--space-2); }
.dash-alerts[hidden] { display: none; }
/* the portal's connect-Facebook-&-Instagram bar, above everything else on the
   dashboard: a soft Meta-blue → Instagram-pink tint, the gradient as its edge,
   the Meta mark in a raised tile, a Meta-blue button */
.dash-meta[hidden] { display: none; }
.dash-meta-bar { position: relative; display: flex; align-items: center; gap: var(--space-3-5); padding: var(--space-3) var(--space-3) var(--space-3) var(--space-5); overflow: hidden;
  border: 0; border-radius: var(--radius-lg);
  background: linear-gradient(100deg, color-mix(in srgb, var(--brand-meta) 9%, var(--surface)) 0%, color-mix(in srgb, var(--brand-ig-mid) 6%, var(--surface)) 55%, var(--surface) 100%);
  box-shadow: var(--shadow-xs); }
.dash-meta-bar::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: linear-gradient(180deg, var(--brand-meta) 0%, var(--brand-ig-end) 45%, var(--brand-ig-mid) 75%, var(--brand-ig-start) 100%); }
.dash-meta-tile { display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; width: 40px; height: 40px; border-radius: var(--radius-md); background: #fff; box-shadow: var(--shadow-sm); }   /* white in both themes: the Meta mark sits on white */
.dash-meta-tile img { width: 22px; height: 22px; }
.dash-meta-text { flex: 1; min-width: 0; display: grid; gap: 2px; }
.dash-meta-text b { font-size: var(--text-md); font-weight: var(--fw-semibold); color: var(--text-strong); letter-spacing: -0.01em; }
.dash-meta-text small { font-size: var(--text-sm); color: var(--text-muted); }
.dash-meta-nets { display: inline-flex; gap: var(--space-1-5); flex-shrink: 0; margin-right: var(--space-1); }
.dash-meta-nets img { width: 20px; height: 20px; border-radius: 50%; box-shadow: 0 0 0 2px var(--surface); }
/* (doubled selectors: the shared .btn hover / focus rules must not wash the Meta blue out) */
.dash-meta-bar .dash-meta-btn { flex-shrink: 0; height: 36px; padding: 0 var(--space-4); }   /* colour: .btn-meta (components) */
.dash-meta-bar .dash-meta-btn svg { width: 15px; height: 15px; }
@media (max-width: 640px) {
  .dash-meta-bar { flex-wrap: wrap; padding-left: var(--space-4); }
  .dash-meta-text small, .dash-meta-nets { display: none; }
}
/* the portal's Finish-setting-up card sits with the alerts, above the KPIs */
.dash-setup[hidden] { display: none; }
/* desktop has the sidebar's Getting started panel; the dashboard card is for phones (no sidebar) */
@media (min-width: 641px) { .dash-setup { display: none; } }
.dash-alert { padding: var(--space-2) var(--space-3); border: 1px solid var(--danger-300); border-radius: var(--radius-lg); background: var(--danger-bg); color: var(--text-strong); }
.dash-alert-row { display: flex; align-items: center; gap: var(--space-2-5); min-height: 28px; }
.dash-alert-ico { display: inline-flex; flex: 0 0 auto; color: var(--danger-600); }
.dash-alert-ico svg { width: 16px; height: 16px; }
.dash-alert-tag { flex: 0 0 auto; padding: 1px var(--space-2); border-radius: var(--radius-full); background: var(--danger-600); color: #fff; font-size: 10px; font-weight: var(--fw-semibold); text-transform: uppercase; letter-spacing: .05em; }
.dash-alert-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--text-md); font-weight: var(--fw-medium); }
.dash-alert-more { flex: 0 0 auto; border: 0; background: none; padding: 0; font: inherit; font-size: var(--text-sm); font-weight: var(--fw-medium); color: var(--danger-600); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.dash-alert-more:focus-visible { outline: none; box-shadow: var(--ring-primary); border-radius: var(--radius-sm); }
.dash-alert-x { flex: 0 0 auto; color: var(--danger-600); }
.dash-alert-detail { display: flex; flex-direction: column; gap: var(--space-1); margin: var(--space-1-5) 0 var(--space-1) 34px; font-size: var(--text-sm); color: var(--text); line-height: 1.45; }
.dash-alert-detail[hidden] { display: none; }
.dash-alert-meta { font-size: var(--text-xs); color: var(--text-soft); }
.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); }
/* the customiser can hide metrics — it publishes the visible count as
   [data-kpi-cols] (dashboardCustomize.applyDashConfigToDOM) instead of an
   inline style, so the reflow rules below still win at narrow widths. */
.kpi-grid[data-kpi-cols="1"] { grid-template-columns: minmax(0, 1fr); }
.kpi-grid[data-kpi-cols="2"] { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.kpi-grid[data-kpi-cols="3"] { grid-template-columns: repeat(3, minmax(0, 1fr)); }
/* 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,
  .kpi-grid[data-kpi-cols="3"],
  .kpi-grid[data-kpi-cols="4"] { 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); }
}
/* (4 Sep) reference KPI hierarchy: a title row closed by a hairline, then the
   big number — no icon tile. .kpi-ico stays in the markup for the customiser /
   iOS mirrors but is not drawn. */
.kpi-head { display: flex; align-items: center; gap: var(--space-3); padding-bottom: var(--space-3); border-bottom: 1px solid var(--border-faint); }
.kpi-ico { display: none; }
.kpi-head .label { font-size: var(--text-md); 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-4); flex-wrap: wrap; row-gap: var(--space-1); }
.kpi-body .value { font-size: 30px; font-weight: var(--fw-semibold); 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 a 3-col row */
.dash-row.r1 { grid-template-columns: 1fr calc((100% - var(--space-4) * 2) / 3); }
/* 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 { grid-template-columns: minmax(0, 1fr); }
}

/* (.widget markup now carries `card card-pad` — the shell comes entirely from
   components.css; .widget remains only as a JS/markup hook) */
.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 — the date-picker grid itself (.cal-head/.cal-grid) is the
   shared base in components.css */
#calWidget .wtitle { font-weight: var(--fw-medium); }
/* 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); }
/* .ebtn markup carries .btn-card (components.css) — only placement lives here */
.cal-event .ebtn { margin-left: auto; }
/* 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); }

/* 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); }
