/* ==========================================================================
   DASHBOARD — Shared dashboard layout components.
   Used by stat_card() UIComponent and dashboard page layouts.
   ========================================================================== */

/* ── Stats row — responsive grid of stat cards ── */
.dash-stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-4);
    margin-bottom: var(--space-6);
}

/* ── Stat card — horizontal icon + value/label ──
   Rendered by UIComponents::statCard() / stat_card() helper.
   Can be a <div> or <a> (clickable). */
.dash-stat-card {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    padding: var(--space-5) var(--space-6);
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    transition: transform 0.15s, box-shadow 0.15s;
}
.dash-stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
    color: var(--text);
}
.dash-stat-icon {
    color: var(--primary);
    flex-shrink: 0;
}
.dash-stat-body {
    min-width: 0;
}
.dash-stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1;
    color: var(--text);
}
.dash-stat-label {
    font-size: 0.825rem;
    color: var(--text-secondary);
    margin-top: 3px;
}
.dash-stat-sub {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* ── Variant modifiers — colored left-border + icon/value tinting ──
   Use via stat_card([..., 'variant' => 'success'|'info'|'warning'|'danger'|'neutral']).
   'default' renders no modifier. Falls back to hex if token missing. */
.dash-stat-card--danger  { border-left: 3px solid var(--error, #ef4444); }
.dash-stat-card--danger  .dash-stat-icon  { color: var(--error, #ef4444); }
.dash-stat-card--danger  .dash-stat-value { color: var(--error, #ef4444); }

.dash-stat-card--success { border-left: 3px solid var(--success, #10b981); }
.dash-stat-card--success .dash-stat-icon  { color: var(--success, #10b981); }
.dash-stat-card--success .dash-stat-value { color: var(--success, #10b981); }

.dash-stat-card--info    { border-left: 3px solid var(--info, #3b82f6); }
.dash-stat-card--info    .dash-stat-icon  { color: var(--info, #3b82f6); }
.dash-stat-card--info    .dash-stat-value { color: var(--info, #3b82f6); }

.dash-stat-card--warning { border-left: 3px solid var(--warning, #f59e0b); }
.dash-stat-card--warning .dash-stat-icon  { color: var(--warning, #f59e0b); }
.dash-stat-card--warning .dash-stat-value { color: var(--warning, #f59e0b); }

.dash-stat-card--neutral { border-left: 3px solid var(--gray-400, #9ca3af); }
.dash-stat-card--neutral .dash-stat-icon  { color: var(--text-secondary); }
.dash-stat-card--neutral .dash-stat-value { color: var(--text-secondary); }

/* ── No-icon mode (vertical stack: value over label, larger value) ──
   Use for compact KPI strips that don't need an icon column. */
.dash-stat-card--no-icon {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-1);
    padding: var(--space-5) var(--space-6);
    border-radius: var(--radius-lg, 0.75rem);
}
.dash-stat-card--no-icon .dash-stat-body { width: 100%; }
.dash-stat-card--no-icon .dash-stat-value {
    font-size: 2rem;
    line-height: 1;
}
.dash-stat-card--no-icon .dash-stat-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-top: var(--space-1);
}

/* ── Dashboard grid — 2-column layout for card sections ── */
.dash-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-6);
    margin-bottom: var(--space-6);
}

/* ── Dashboard card — lighter .card variant for dashboard sections ──
   Prevents double-border when embedding tables inside cards. Also carries
   the canonical `margin-bottom` so two stacked panels space themselves —
   inside `.dash-grid` the gap is handled by the grid, so the margin is
   reset there. */
.dash-card {
    padding: var(--space-5);
    margin-bottom: var(--space-6);
}
.dash-card:hover {
    transform: none;
}
.dash-card .card-header {
    margin-bottom: var(--space-2);
}
/* Cards living inside .dash-grid (or any flex/grid stack inside it) don't
   need their own bottom margin — the parent's `gap` already separates them.
   Descendant selector reaches both direct children and the per-column
   patterns like Plan's `.plan-dash-col`. */
.dash-grid .dash-card {
    margin-bottom: 0;
}

/* Card title + link (header row) */
.dash-card-title {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: 1rem;
}
.dash-card-link {
    font-size: 0.8rem;
    color: var(--primary);
    text-decoration: none;
    white-space: nowrap;
}
.dash-card-link:hover {
    text-decoration: underline;
}

/* ── Inline table inside dashboard cards (no .table-container border) ── */
.dash-table-wrap {
    overflow: visible;
    margin-top: var(--space-2);
}
.dash-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}
.dash-table th {
    text-align: left;
    padding: var(--space-2) var(--space-3);
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.dash-table td {
    padding: var(--space-2) var(--space-3);
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.dash-table tr:last-child td {
    border-bottom: none;
}
.dash-row {
    cursor: pointer;
    transition: background 0.1s;
}
.dash-row:hover td {
    background: rgba(0, 0, 0, .025);
}

/* ── Right-aligned dash table cells (numbers, totals) ── */
.dash-table .dash-text-right,
.dash-table th.dash-text-right,
.dash-text-right {
    text-align: right;
}
.dash-num {
    font-variant-numeric: tabular-nums;
}

/* ── Truncating cell — prevent long values (client names, descriptions, …)
   from overflowing the card when the dashboard sits in a narrow column.
   Pair with a `title` attribute on the cell for full-name tooltip.
   Tight by default (140px) — works inside half-width cards in `.dash-grid`
   where horizontal real estate is scarce. ── */
.dash-cell-truncate {
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Grid children must allow shrinking below their content's min-content,
   otherwise a long un-truncated cell pushes the whole card wider than its
   `1fr` slot and overflows the dashboard. Classic CSS gotcha — fixed once
   here for every dashboard. */
.dash-grid > * {
    min-width: 0;
}

/* In a narrow grid card the dash-table also needs to clip overlong cells.
   `table-layout: fixed` distributes column widths from the first row's
   widths instead of content-driven, so cells can't push the table wider
   than its `width: 100%`. The `.dash-cell-truncate` class still adds the
   ellipsis on specific cells. */
.dash-grid .dash-table {
    table-layout: fixed;
}

/* ── Progress row — labelled horizontal bar (capacity, distribution, …)
   Markup (rendered by dash_progress_row()):
     <div class="dash-progress-row">
       <div class="dash-progress-head">
         <span class="dash-progress-label">[dot?] Label</span>
         <span class="dash-progress-meta">8h / 40h</span>
       </div>
       <div class="dash-progress-track">
         <div class="dash-progress-fill dash-progress-fill--{variant}" style="width:N%"></div>
       </div>
     </div>
   Variants colour the fill ; default = primary. ── */
.dash-progress-list      { display: flex; flex-direction: column; gap: var(--space-3); }
.dash-progress-row-head,
.dash-progress-head      { display: flex; justify-content: space-between; align-items: baseline; font-size: 0.82rem; margin-bottom: var(--space-1); }
.dash-progress-label     { font-weight: 500; color: var(--text); }
.dash-progress-meta      { color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.dash-progress-track     { height: 6px; background: var(--gray-100, var(--bg-secondary)); border-radius: 3px; overflow: hidden; }
.dash-progress-fill      { height: 100%; border-radius: 3px; transition: width .3s; background: var(--primary); }
.dash-progress-fill--success  { background: var(--success); }
.dash-progress-fill--warning  { background: var(--warning); }
.dash-progress-fill--danger   { background: var(--danger, var(--error, #ef4444)); }
.dash-progress-fill--info     { background: var(--info, #3b82f6); }
.dash-progress-fill--gradient { background: linear-gradient(90deg, var(--primary), var(--primary-2, #2a4970)); }
.dash-progress-dot       { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }

/* ── Alert card — full rollup card with attention-grabbing variant.
   Wraps `.card.dash-card` with a coloured left border + tinted icon/title.
   Use for "stop and read" cards (overdue invoices, missing setup, …). ── */
.dash-alert-card                                    { border-left: 3px solid var(--warning); }
.dash-alert-card .card-title.dash-card-title        { color: var(--warning); }
.dash-alert-card.dash-alert-card--danger            { border-left-color: var(--error, #ef4444); }
.dash-alert-card.dash-alert-card--danger  .card-title.dash-card-title { color: var(--error, #ef4444); }
.dash-alert-card.dash-alert-card--info              { border-left-color: var(--info, #3b82f6); }
.dash-alert-card.dash-alert-card--info    .card-title.dash-card-title { color: var(--info, #3b82f6); }
.dash-alert-card.dash-alert-card--success           { border-left-color: var(--success); }
.dash-alert-card.dash-alert-card--success .card-title.dash-card-title { color: var(--success); }

/* ── Dashboard empty state (lighter than full empty-state) ──
   Used inside .dash-card rollups (and as the transient loader before JS-fed
   tables). Kept compact on purpose — the canonical .empty-state class is for
   page-level empty hero blocks ; this is the in-card variant. */
.dash-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-4) 0;
    color: var(--text-secondary);
    font-size: 0.875rem;
    text-align: center;
}
.dash-empty svg { width: 24px; height: 24px; opacity: 0.7; }
.dash-empty p   { margin: 0; }

/* ── Vertical bar chart (single or stacked segments) ──
   Markup: .dash-chart-bars > .dash-chart-col[*N] each with
   .dash-chart-amount / .dash-chart-bar-wrap > .dash-chart-bar[*1-N] / .dash-chart-label.
   Stacked segments live inside .dash-chart-bar-wrap (column-flex, justify-end);
   only the topmost segment gets rounded corners so the stack reads as one bar.
   Per-segment colors (--paid/--pending/--overdue or app-specific) are app-side. */
.dash-chart-wrap   { padding: var(--space-4) 0 0; min-height: 200px; }
.dash-chart-bars   { display: flex; align-items: flex-end; gap: var(--space-2); height: 180px; padding: 0 var(--space-3); }
.dash-chart-col    { flex: 1; display: flex; flex-direction: column; align-items: center; gap: var(--space-1); min-width: 0; }
.dash-chart-bar-wrap { width: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 150px; }
.dash-chart-bar    { width: 70%; max-width: 48px; transition: height 0.4s ease; position: relative; }
.dash-chart-bar-wrap > .dash-chart-bar:first-child { border-radius: 4px 4px 0 0; }
.dash-chart-amount { font-size: 0.7rem; font-weight: 600; color: var(--text); white-space: nowrap; margin-bottom: 2px; }
.dash-chart-label  { font-size: 0.75rem; color: var(--text-secondary); white-space: nowrap; }
.dash-chart-legend { display: flex; justify-content: center; gap: var(--space-6); padding: var(--space-3) 0 0; font-size: 0.75rem; color: var(--text-secondary); }
.dash-chart-legend-dot { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: middle; }

/* ── Responsive ── */
@media (max-width: 1024px) {
    .dash-stats-row { grid-template-columns: repeat(2, 1fr); }
    .dash-grid { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
    /* Scroll rather than overflow when a table still has too many columns
       after col-hide-sm, or when raw markup tables are used in a dash-card. */
    .dash-table-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}
@media (max-width: 600px) {
    .dash-stats-row { grid-template-columns: 1fr 1fr; }
    .dash-stat-card { padding: var(--space-3) var(--space-4); }
    .dash-stat-value { font-size: 1.35rem; }
    .dash-stat-card--no-icon .dash-stat-value { font-size: 1.5rem; }
}
@media (max-width: 480px) {
    /* Single-column KPI strip — 175px cards are too narrow for multi-word labels */
    .dash-stats-row { grid-template-columns: 1fr; }
    .dash-stat-card { flex-direction: row; align-items: center; padding: var(--space-3) var(--space-4); }
}
