:root {
  --canvas: #f4f6f8;
  --navy: #17324d;
  --navy-2: #254b6d;
  --orange: #f28c28;
  --orange-soft: #f6a84a;
  --terracotta: #c9654b;
  --positive: #3e7c59;
  --text: #24313d;
  --muted: #6b7785;
  --grid: #dce2e8;
  --panel: #ffffff;
  --shadow: 0 1px 5px rgba(23, 50, 77, .10);
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; background: var(--canvas); color: var(--text); font-family: "Segoe UI", Inter, Arial, sans-serif; }
body { min-width: 320px; }
button, select { font: inherit; }

.loading-card { width: min(92vw, 420px); margin: 18vh auto; padding: 26px; background: #fff; border-radius: 8px; box-shadow: var(--shadow); color: var(--navy); text-align: center; }
.dashboard-shell { width: min(100%, 1500px); min-height: 100vh; margin: 0 auto; padding: 24px 28px 14px; display: flex; flex-direction: column; }
.page-head { min-height: 58px; display: flex; gap: 24px; align-items: flex-start; justify-content: space-between; }
.page-title { margin: 0; color: var(--navy); font-size: 22px; line-height: 1.08; font-weight: 700; }
.page-subtitle { margin: 5px 0 0; color: var(--muted); font-size: 11px; }
.reset-button { border: 1px solid var(--grid); color: var(--navy); background: #fff; border-radius: 6px; padding: 8px 12px; cursor: pointer; white-space: nowrap; }
.reset-button:hover, .reset-button:focus-visible { border-color: var(--navy-2); outline: 2px solid rgba(37,75,109,.15); }

.filter-row { display: grid; grid-template-columns: repeat(var(--filter-count, 4), minmax(0, 1fr)); gap: 14px; margin: 8px 0; }
.filter-card { background: var(--panel); border-radius: 7px; box-shadow: var(--shadow); padding: 9px 11px 10px; min-width: 0; }
.filter-card label { display: block; color: var(--muted); font-size: 11px; margin-bottom: 6px; }
.filter-card select { width: 100%; height: 31px; border: 1px solid #cfd6dc; border-radius: 3px; background: white; color: var(--text); padding: 0 9px; cursor: pointer; }

.kpi-row { display: grid; grid-template-columns: repeat(var(--kpi-count, 4), minmax(0, 1fr)); gap: 14px; margin: 8px 0 14px; }
.kpi-card { min-height: 92px; background: var(--panel); border-radius: 7px; box-shadow: var(--shadow); padding: 18px 18px 15px; }
.kpi-label { color: var(--muted); font-size: 11px; line-height: 1.2; }
.kpi-value { margin-top: 9px; color: var(--navy); font-size: clamp(1.35rem, 2vw, 2rem); line-height: 1; letter-spacing: -.02em; white-space: nowrap; }

.visual-grid { display: grid; gap: 14px; flex: 1; min-height: 0; }
.visual-grid.overview { grid-template-columns: 1.55fr 1fr; grid-template-areas: "sales reconciliation" "settlement aging"; grid-auto-rows: 250px; }
.visual-grid.sales-page { grid-template-columns: repeat(12, minmax(0, 1fr)); grid-template-rows: 180px 320px; }
.sales-page > .trend-card { grid-column: span 4; }
.sales-page > .station-card, .sales-page > .payment-card, .sales-page > .ticket-card { grid-column: span 3; }
.sales-page > .side-stack { grid-column: span 3; display: grid; grid-template-rows: 1fr 1fr; gap: 14px; min-width: 0; }
.side-stack .visual-card { min-height: 0; }
.visual-grid.three-by-two { grid-template-columns: repeat(3, minmax(0, 1fr)); grid-template-rows: 250px 250px; }
.visual-grid.pending-page { grid-template-columns: repeat(3, minmax(0, 1fr)); grid-template-rows: 230px 270px; }
.pending-page > .wide-left { grid-column: span 1; }
.pending-page > .wide-right { grid-column: span 2; }
.area-sales { grid-area: sales; }
.area-reconciliation { grid-area: reconciliation; }
.area-settlement { grid-area: settlement; }
.area-aging { grid-area: aging; }
.visual-card { min-width: 0; min-height: 0; background: var(--panel); border-radius: 7px; box-shadow: var(--shadow); padding: 10px 12px 8px; overflow: hidden; }
.visual-title { margin: 0 0 4px; color: var(--navy); font-size: 12px; font-weight: 500; }
.visual-body { height: calc(100% - 22px); min-height: 0; }
.visual-body svg { display: block; width: 100%; height: 100%; overflow: visible; }
.axis-label { fill: var(--muted); font-size: 9.5px; }
.chart-label { fill: var(--text); font-size: 9.5px; }
.grid-line { stroke: var(--grid); stroke-width: 1; }
.data-line { fill: none; stroke-width: 2.4; }
.data-point { stroke: #fff; stroke-width: 1.5; }
.clickable { cursor: pointer; transition: opacity .12s ease; }
.clickable:hover, .clickable:focus { opacity: .78; outline: none; }
.dimmed { opacity: .22; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: -4px; color: var(--muted); font-size: 9.5px; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.no-data { display: grid; place-items: center; height: 100%; color: var(--muted); font-size: .82rem; }
.matrix-wrap { width: 100%; height: 100%; overflow: auto; scrollbar-width: thin; }
.matrix { width: max-content; min-width: 100%; border-collapse: collapse; color: var(--text); font-size: 9.5px; }
.matrix th, .matrix td { border-bottom: 1px solid #e5e9ed; padding: 6px 8px; white-space: nowrap; text-align: right; }
.matrix th:first-child, .matrix td:first-child { position: sticky; left: 0; z-index: 1; background: #fff; text-align: left; }
.matrix thead th { color: var(--navy); background: #fff; font-weight: 600; }
.matrix tbody tr[data-station] { cursor: pointer; }
.matrix tbody tr[data-station]:hover td { background-color: #f4f7fa; }
.matrix tbody tr.selected td { background-color: #e5edf4; }
.matrix .bar-cell { background-repeat: no-repeat; background-size: 100% 62%; background-position: left center; }

.page-nav { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; margin-top: 14px; }
.nav-button { min-height: 38px; border: 0; border-radius: 4px; background: #e8edf1; color: #536171; font-size: 11px; padding: 7px 6px; cursor: pointer; }
.nav-button.active { color: #fff; background: var(--navy); }
.nav-button:hover, .nav-button:focus-visible { outline: 2px solid rgba(37,75,109,.18); }
.disclosure { margin: 10px 0 0; text-align: center; color: var(--muted); font-size: 10px; }

.tooltip { position: fixed; z-index: 50; max-width: 290px; pointer-events: none; background: rgba(25,39,52,.96); color: #fff; border-radius: 5px; padding: 9px 11px; box-shadow: 0 8px 20px rgba(0,0,0,.2); font-size: .75rem; line-height: 1.45; }
.tooltip strong { display: block; margin-bottom: 3px; }

@media (max-width: 1199px) {
  .dashboard-shell { padding: 18px 18px 12px; }
  .filter-row, .kpi-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .visual-grid.overview { grid-template-columns: 1fr 1fr; }
  .visual-grid.sales-page, .visual-grid.three-by-two, .visual-grid.pending-page { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: none; }
  .sales-page > .trend-card, .sales-page > .station-card, .sales-page > .payment-card, .sales-page > .ticket-card, .sales-page > .side-stack { grid-column: span 1; }
  .sales-page > .side-stack { min-height: 540px; }
  .pending-page > .wide-right { grid-column: span 1; }
  .page-nav { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 767px) {
  .dashboard-shell { padding: 15px 12px 10px; }
  .page-head { min-height: 70px; }
  .page-title { font-size: 1.45rem; }
  .page-subtitle { font-size: .78rem; }
  .filter-row, .kpi-row { grid-template-columns: 1fr; }
  .kpi-card { min-height: 80px; }
  .visual-grid.overview { grid-template-columns: 1fr; grid-template-areas: "sales" "reconciliation" "settlement" "aging"; grid-auto-rows: 260px; }
  .visual-grid.sales-page, .visual-grid.three-by-two, .visual-grid.pending-page { display: flex; flex-direction: column; }
  .sales-page > .side-stack { min-height: 560px; }
  .visual-card { min-height: 260px; }
  .visual-body { min-height: 220px; }
  .page-nav { grid-template-columns: 1fr; gap: 6px; }
  .nav-button { text-align: left; padding-left: 12px; }
}
