:root {
  --bg: #f3f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #eef2f7;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;
  --primary: #1d4ed8;
  --primary-2: #1e40af;
  --success: #059669;
  --danger: #be123c;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 6px 20px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 12px 28px rgba(15, 23, 42, 0.08);
  --radius: 12px;
  --radius-lg: 16px;
  --font-ui: "Segoe UI Variable Text", "Segoe UI", "Aptos", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(1200px 500px at 100% -10%, rgba(29, 78, 216, 0.06), transparent 60%),
    radial-gradient(900px 380px at -10% 0%, rgba(20, 184, 166, 0.05), transparent 60%),
    var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
}

.sidebar {
  background: #0f172a;
  color: #e2e8f0;
  border-right: 1px solid rgba(255,255,255,0.06);
  padding: 18px 16px;
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 18px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  display: flex;
  gap: 12px;
  align-items: center;
}

.sidebar-brand h1 {
  margin: 0;
  font-size: 1rem;
  line-height: 1.15;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.sidebar-brand p {
  margin: 2px 0 0;
  font-size: 0.78rem;
  color: #94a3b8;
}

.sidebar-mark {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, #2563eb, #1d4ed8);
  color: #fff;
  font-weight: 700;
  font-size: 0.9rem;
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.35);
}

.sidebar-nav {
  display: grid;
  gap: 6px;
}

.nav-item {
  color: #cbd5e1;
  text-decoration: none;
  font-size: 0.9rem;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid transparent;
}

.nav-item:hover {
  background: rgba(255,255,255,0.04);
  border-color: rgba(255,255,255,0.06);
}

.nav-item.is-active {
  background: rgba(37, 99, 235, 0.16);
  border-color: rgba(96, 165, 250, 0.22);
  color: #dbeafe;
}

.sidebar-meta {
  align-self: end;
  border-top: 1px solid rgba(255,255,255,0.06);
  padding-top: 14px;
}

.meta-label {
  margin: 0;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: #94a3b8;
}

.meta-value {
  margin: 3px 0 10px;
  font-size: 0.88rem;
  color: #e2e8f0;
}

.main-panel {
  min-width: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 18px;
  padding: 20px;
}

.topbar {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-md);
  display: grid;
  gap: 16px;
}

.topbar-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
}

.brand h2 {
  margin: 0;
  font-size: 1.25rem;
  line-height: 1.15;
  letter-spacing: -0.02em;
}

.brand p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  max-width: 78ch;
}

.tagline {
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: #334155;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.78rem;
  font-weight: 600;
}

.controls {
  display: grid;
  grid-template-columns: repeat(6, max-content) minmax(260px, 1fr);
  gap: 12px;
  align-items: end;
}

.field {
  display: grid;
  gap: 6px;
  min-width: 148px;
}

.field label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  font-weight: 700;
}

input[type="date"] {
  height: 40px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--ink);
  font: inherit;
}

select {
  height: 40px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--ink);
  font: inherit;
}

.btn {
  height: 40px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  transition: background-color 120ms ease, border-color 120ms ease, transform 120ms ease;
}

.btn:hover { transform: translateY(-1px); }
.btn:disabled { opacity: 0.6; cursor: default; transform: none; }

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-2);
  border-color: var(--primary-2);
}

.btn-secondary:hover {
  background: var(--surface-2);
}

.btn.small {
  height: 32px;
  padding: 0 10px;
  font-size: 0.85rem;
}

.day-nav {
  display: flex;
  gap: 6px;
  align-items: center;
}

.day-nav .btn {
  flex: 1;
  margin: 0;
}

.actions {
  align-self: center;
  justify-self: start;
}

.status {
  margin: 0;
  min-height: 42px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  padding: 10px 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
}

.status.error {
  border-color: #fecdd3;
  background: #fff1f2;
  color: #9f1239;
}

.layout {
  display: grid;
  gap: 18px;
  min-width: 0;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}

.overview {
  padding: 18px;
  display: grid;
  gap: 14px;
}

.overview-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.overview-head h2 {
  margin: 0;
  font-size: 1rem;
  letter-spacing: -0.02em;
}

.overview-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.mini-badge, .badge {
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--muted);
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 0.76rem;
  white-space: nowrap;
}

.kpis {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.kpi {
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #fff, #fbfdff);
  border-radius: 10px;
  padding: 10px 11px;
  box-shadow: var(--shadow-sm);
}

.kpi-label, .metric-label {
  margin: 0;
  color: var(--muted);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.11em;
  font-weight: 700;
}

.kpi-value {
  margin: 7px 0 0;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.kpi-note {
  margin: 5px 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.chart-shell {
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #ffffff, #fbfdff);
  border-radius: 10px;
  padding: 12px;
}

.chart-shell--section {
  padding: 10px 12px 8px;
}

.chart-caption {
  margin: 0 0 8px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

.chart-caption span:first-child {
  color: var(--ink);
  font-weight: 600;
  letter-spacing: 0.01em;
}

.chart-caption span:last-child {
  font-variant-numeric: tabular-nums;
}

.chart-controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: -2px 0 8px;
}

.chart-select-wrap {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 700;
}

.chart-select-wrap select {
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 8px;
  font: inherit;
  text-transform: none;
  letter-spacing: normal;
  min-width: 140px;
}

.chart-tooltip {
  position: fixed;
  z-index: 9999;
  pointer-events: none;
  max-width: 280px;
  background: rgba(15, 23, 42, 0.96);
  color: #e2e8f0;
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 10px;
  padding: 8px 10px;
  box-shadow: 0 10px 30px rgba(2, 6, 23, 0.35);
  font-size: 0.75rem;
  line-height: 1.35;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 90ms ease, transform 90ms ease;
}

.chart-tooltip.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.chart-tooltip strong {
  color: #fff;
}

.chart {
  width: 100%;
  height: 180px;
  display: block;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.legend {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.overview-insights {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.insight-chip {
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #fff, #f8fbff);
  border-radius: 10px;
  padding: 9px 10px;
  font-size: 0.8rem;
  color: #475569;
}

.insight-chip strong {
  color: #0f172a;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 999px;
  padding: 5px 8px;
  color: var(--muted);
  font-size: 0.75rem;
}

.legend-swatch {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.analytics-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.sections-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  align-items: start;
}

.card {
  background:
    linear-gradient(180deg, rgba(255,255,255,0.98), rgba(248,250,252,0.96)),
    var(--surface);
  border: 1px solid color-mix(in srgb, var(--card-accent, var(--line)) 18%, var(--line));
  border-radius: 14px;
  box-shadow: var(--shadow-md);
  padding: 14px 14px 12px;
  display: grid;
  gap: 12px;
  min-height: 0;
  position: relative;
}

.card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  border-radius: 14px 14px 0 0;
  background: var(--card-accent, var(--primary));
  opacity: 0.85;
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.card-title-wrap h3 {
  margin: 0;
  font-size: 1rem;
  letter-spacing: -0.02em;
}

.card-title-wrap p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
}

.section-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.section-insight {
  border: 1px dashed color-mix(in srgb, var(--card-accent, var(--line)) 30%, var(--line));
  background: rgba(255,255,255,0.7);
  border-radius: 8px;
  padding: 8px 10px;
  color: #475569;
  font-size: 0.8rem;
  line-height: 1.35;
}

.metric {
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.78);
  border-radius: 8px;
  padding: 10px 12px;
  min-height: 64px;
}

.metric-value {
  margin: 6px 0 0;
  font-size: 0.92rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

.section-chart { height: 120px; }

.card-details {
  display: grid;
  gap: 10px;
}

.detail-panel {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  overflow: hidden;
}

.detail-panel > summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #475569;
  background: #f8fafc;
  border-bottom: 1px solid transparent;
}

.detail-panel > summary::-webkit-details-marker {
  display: none;
}

.detail-panel > summary::after {
  content: "+";
  font-size: 1rem;
  line-height: 1;
  color: #64748b;
}

.detail-panel[open] > summary {
  border-bottom-color: var(--line);
}

.detail-panel[open] > summary::after {
  content: "−";
}

.table-wrap {
  border: 0;
  border-radius: 0;
  background: transparent;
  overflow: auto;
  min-height: 0;
  max-height: 220px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

th, td {
  padding: 7px 8px;
  border-bottom: 1px solid #edf2f7;
  text-align: left;
  white-space: nowrap;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 700;
}

td:last-child, th:last-child { text-align: right; }

.rows {
  display: grid;
  gap: 8px;
  max-height: 220px;
  overflow: auto;
  padding: 10px;
  background: #fff;
}

.row-details {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
  overflow: hidden;
}

.row-details summary {
  cursor: pointer;
  padding: 9px 10px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  font-size: 0.78rem;
}

.row-meta {
  color: var(--muted);
  font-size: 0.74rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row-details pre,
.raw-json pre {
  margin: 0;
  padding: 10px;
  border-top: 1px solid var(--line);
  background: var(--surface-2);
  color: #1e293b;
  font: 12px/1.35 Consolas, "Courier New", monospace;
  overflow: auto;
  max-height: 240px;
}

.raw-json {
  margin-top: 2px;
}

.raw-json > summary {
  color: #64748b;
}

.muted {
  color: var(--muted);
  font-size: 0.83rem;
}

.footer {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  align-items: center;
  color: var(--muted);
  font-size: 0.82rem;
  padding: 0 2px 2px;
}

.footer a {
  color: #1d4ed8;
  text-decoration: none;
}

.footer a:hover { text-decoration: underline; }

@media (max-width: 1320px) {
  .controls {
    grid-template-columns: repeat(3, minmax(0, max-content)) minmax(0, 1fr);
  }
  .controls .actions {
    grid-column: 1 / -1;
  }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: static;
    height: auto;
    grid-template-rows: auto auto;
  }
  .sidebar-meta { display: none; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sections-grid { grid-template-columns: 1fr; }
  .analytics-grid { grid-template-columns: 1fr; }
  .section-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .overview-insights { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .main-panel { padding: 12px; gap: 14px; }
  .topbar { padding: 14px; }
  .controls { grid-template-columns: 1fr; }
  .field { min-width: 0; }
  .kpis, .section-metrics { grid-template-columns: 1fr; }
  .sidebar { padding: 12px; }
  .sidebar-nav { grid-template-columns: 1fr 1fr; }
  .card { padding: 12px; }
  .detail-panel > summary { padding: 10px; }
  .rows { padding: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  .btn { transition: none; }
}
