/* ══════════════════════════════════════════════════════════════
   dashboard.css
   Dashboard widgets, KPI tiles, charts, period control and the
   money-privacy graph.
   ══════════════════════════════════════════════════════════════ */

/* ══════════════════════════════
   DASHBOARD WIDGETS
   ══════════════════════════════ */
.dash-grid {
  display: grid; gap: 16px; margin-top: 4px;
  grid-template-columns: repeat(12, 1fr);
  grid-auto-rows: minmax(0, auto);
  align-items: stretch;
}
.dash-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow); padding: 16px 18px 18px;
  display: flex; flex-direction: column; min-width: 0;
  transition: box-shadow .16s ease, border-color .16s ease;
}
.dash-card:hover { box-shadow: 0 6px 22px rgba(17,20,45,.09); }
.dash-card-head {
  display: flex; align-items: center; gap: 7px; font-size: 12.5px; font-weight: 700;
  color: var(--text); margin-bottom: 14px; text-transform: uppercase; letter-spacing: .04em;
  flex-shrink: 0;
}
.dash-card-head i { color: var(--cs-accent); font-size: 15px; flex-shrink: 0; }
.dash-card-head > span:first-of-type { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dash-count-pill { margin-left: 4px; background: var(--accent-red-bg); color: var(--accent-red-text); font-size: 10.5px; font-weight: 800; padding: 1px 8px; border-radius: 10px; text-transform: none; letter-spacing: 0; }

/* "View all →" affordance in every card header */
.dash-head-link {
  margin-left: auto; flex-shrink: 0; display: inline-flex; align-items: center; gap: 4px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text-secondary);
  font-family: inherit; font-size: 10px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  padding: 3px 9px; border-radius: 20px; cursor: pointer; white-space: nowrap;
  transition: border-color .14s, color .14s, background .14s;
}
.dash-head-link i { font-size: 12px; color: inherit; }
.dash-head-link:hover, .dash-head-link:focus-visible { border-color: var(--cs-accent); color: var(--cs-accent-2); background: var(--surface); }

/* The body of a card grows to fill the row so cards side by side end level */
.dash-card-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.dash-list-body { flex: 1; min-height: 168px; display: flex; flex-direction: column; }

/* ── Row spans — every row adds up to exactly 12 ── */
.dash-kpi-card   { grid-column: span 12; }
.dash-chart-card { grid-column: span 8; }
.dash-donut-card { grid-column: span 4; }
.dash-overdue-card { grid-column: span 4; }
.dash-team-card    { grid-column: span 4; }
.dash-recent-card  { grid-column: span 4; }
.dash-quick-card   { grid-column: span 12; }

@media (max-width: 1240px) {
  .dash-chart-card { grid-column: span 7; }
  .dash-donut-card { grid-column: span 5; }
  .dash-overdue-card { grid-column: span 6; }
  .dash-team-card    { grid-column: span 6; }
  .dash-recent-card  { grid-column: span 12; }
}
@media (max-width: 900px) {
  .dash-chart-card, .dash-donut-card, .dash-overdue-card, .dash-team-card { grid-column: span 12; }
}

/* ══ KPI tiles ══ */
.dash-kpi-card { padding: 0; background: none; border: none; box-shadow: none; }
.dash-kpi-card:hover { box-shadow: none; }
.dash-kpi-grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(6, minmax(0, 1fr));
}
@media (max-width: 1240px) { .dash-kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 640px)  { .dash-kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.dash-kpi {
  position: relative; display: flex; flex-direction: column; justify-content: space-between; gap: 6px;
  text-align: left; min-height: 92px; padding: 13px 14px;
  background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--kpi, var(--cs-accent));
  border-radius: var(--radius-lg); box-shadow: var(--shadow);
  font-family: inherit; cursor: pointer; overflow: hidden;
  transition: transform .14s ease, box-shadow .14s ease, border-color .14s ease;
}
.dash-kpi:hover, .dash-kpi:focus-visible { transform: translateY(-2px); box-shadow: 0 8px 22px rgba(17,20,45,.13); }
.dash-kpi-top { display: flex; align-items: center; gap: 6px; }
.dash-kpi-icon { font-size: 15px; color: var(--kpi, var(--cs-accent)); flex-shrink: 0; }
.dash-kpi-label {
  font-size: 10px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0;
}
.dash-kpi-value { font-size: 23px; font-weight: 800; line-height: 1.05; color: var(--text); letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.dash-kpi-value.is-money { font-size: 19px; }
.dash-kpi-sub { font-size: 10.5px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dash-kpi-go { position: absolute; top: 11px; right: 11px; font-size: 13px; color: var(--text-muted); opacity: 0; transition: opacity .14s, transform .14s; }
.dash-kpi:hover .dash-kpi-go { opacity: .75; transform: translateX(2px); }

/* ── bar chart (invoiced value, 7 days) — every column is a button ── */
.dash-bar-chart { display: flex; align-items: stretch; gap: 8px; height: 172px; padding: 0 2px; flex: 1; min-height: 0; }
.dash-bar-col {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
  height: 100%; min-width: 0; padding: 4px 2px 0; border: none; background: none; font-family: inherit;
  border-radius: 8px; cursor: pointer; transition: background .14s;
}
.dash-bar-col:hover, .dash-bar-col:focus-visible { background: var(--bg); }
.dash-bar-col.is-today .dash-bar-label { color: var(--cs-accent-2); font-weight: 800; }
.dash-bar-track { flex: 1; width: 100%; min-height: 0; display: flex; align-items: flex-end; justify-content: center; }
.dash-bar-val { font-size: 9.5px; font-weight: 700; color: var(--text-muted); margin-bottom: 3px; white-space: nowrap; height: 13px; }
.dash-bar { width: 62%; min-width: 14px; background: var(--cs-accent-grad); border-radius: 6px 6px 3px 3px; transition: height .4s cubic-bezier(.4,0,.2,1), opacity .14s; box-shadow: 0 2px 8px rgba(224,51,29,.22); }
.dash-bar.is-empty { background: var(--border); box-shadow: none; }
.dash-bar-col:hover .dash-bar { opacity: .82; }
.dash-bar-label { font-size: 10px; color: var(--text-muted); margin-top: 6px; font-weight: 600; text-transform: uppercase; height: 14px; line-height: 14px; }
.dash-bar-total { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 11.5px; color: var(--text-secondary); margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border); flex-shrink: 0; }
.dash-bar-total b { color: var(--text); }

/* ── donut chart ── */
.dash-donut-wrap { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; flex: 1; }
.dash-donut-ring { width: 118px; height: 118px; border-radius: 50%; flex-shrink: 0; display: flex; align-items: center; justify-content: center; position: relative; border: none; padding: 0; cursor: pointer; transition: transform .16s ease; }
.dash-donut-ring:hover, .dash-donut-ring:focus-visible { transform: scale(1.035); }
.dash-donut-hole { width: 72px; height: 72px; border-radius: 50%; background: var(--surface); display: flex; flex-direction: column; align-items: center; justify-content: center; box-shadow: inset 0 0 0 1px var(--border); }
.dash-donut-total { font-size: 19px; font-weight: 800; color: var(--text); line-height: 1.1; }
.dash-donut-total-label { font-size: 9.5px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }
.dash-donut-legend { display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 130px; }
.dash-legend-row {
  display: flex; align-items: center; gap: 8px; width: 100%; font-family: inherit; font-size: 12px;
  color: var(--text-secondary); cursor: pointer; padding: 4px 6px; border-radius: 7px;
  border: 1px solid transparent; background: none; text-align: left;
  transition: background .12s, border-color .12s;
}
.dash-legend-row:hover, .dash-legend-row:focus-visible { background: var(--bg); border-color: var(--border); }
.dash-legend-row b { margin-left: auto; color: var(--text); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.dash-legend-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }

/* ── generic dashboard row (overdue / recent / team) ── */
.dash-row {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 6px; border-radius: 9px;
  cursor: pointer; transition: background .12s; border: none; border-bottom: 1px solid var(--border);
  background: none; font-family: inherit; text-align: left;
}
.dash-row:last-child { border-bottom: none; }
.dash-row:hover, .dash-row:focus-visible { background: var(--bg); }
.dash-row-mid { flex: 1; min-width: 0; display: block; }
.dash-row-cust { display: block; font-size: 12.5px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dash-row-sub { display: block; font-size: 11px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dash-row-date { display: block; font-size: 10.5px; font-weight: 700; color: var(--accent-red); white-space: nowrap; flex-shrink: 0; text-align: right; }
.dash-row-date.is-muted { color: var(--text-muted); font-weight: 600; }
/* fixed-width reg column keeps the three list cards optically aligned */
.dash-row > .cr-reg { display: inline-block; flex-shrink: 0; min-width: 76px; text-align: center; }

.dash-avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--cs-accent-grad); color: #fff; font-size: 11px; font-weight: 800; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.dash-team-bar { display: block; height: 5px; background: var(--bg); border-radius: 3px; margin-top: 5px; overflow: hidden; }
.dash-team-bar-fill { display: block; height: 100%; background: linear-gradient(90deg, var(--cs-accent), #22c55e); border-radius: 3px; transition: width .4s; }

/* KPI tile internals (spans inside a button) */
.dash-kpi-top { display: flex; align-items: center; gap: 6px; }
.dash-kpi-value { display: block; }
.dash-kpi-sub { display: block; }
.dash-kpi-label { display: block; }
.dash-donut-hole { display: flex; }
.dash-bar-val, .dash-bar-label { display: block; }
.dash-bar-track { display: flex; }
.dash-bar { display: block; }

.dash-empty { text-align: center; padding: 28px 8px; color: var(--text-muted); font-size: 12px; margin: auto 0; }

/* Quick actions — full-width strip that wraps evenly */
.dash-quick-actions { display: grid; gap: 9px; grid-template-columns: repeat(auto-fit, minmax(178px, 1fr)); }
.dash-quick-btn {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; padding: 10px 12px;
  border-radius: 10px; border: 1px solid var(--border); background: var(--bg); color: var(--text);
  font-family: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer;
  transition: border-color .12s, color .12s, transform .12s;
}
.dash-quick-btn i { color: var(--cs-accent); font-size: 15px; flex-shrink: 0; }
.dash-quick-btn span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dash-quick-btn:hover, .dash-quick-btn:focus-visible { border-color: var(--cs-accent); color: var(--cs-accent-2); transform: translateY(-1px); }

/* Consistent keyboard focus ring across every clickable dashboard element */
.dash-kpi:focus-visible, .dash-row:focus-visible, .dash-legend-row:focus-visible,
.dash-bar-col:focus-visible, .dash-donut-ring:focus-visible, .dash-quick-btn:focus-visible,
.dash-head-link:focus-visible {
  outline: 2px solid var(--cs-accent); outline-offset: 2px;
}

.app > #viewDashboard { animation: viewFade .28s ease; }

@media (prefers-reduced-motion: reduce) {
  .dash-bar, .dash-team-bar-fill, .sidebar, .dash-quick-btn, .dash-kpi, .dash-donut-ring { transition: none !important; }
  .dash-kpi:hover, .dash-donut-ring:hover { transform: none; }
}
