/* ===== Enterprise Design System Tokens ===== */
:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-warm: #eef2f7;
  --fg: #0f172a;
  --fg-2: #334155;
  --muted: #64748b;
  --meta: #1d4ed8;
  --border: #d8dee8;
  --border-soft: #edf1f6;
  --accent: #1d4ed8;
  --accent-on: #ffffff;
  --accent-hover: color-mix(in oklab, var(--accent), black 8%);
  --accent-active: color-mix(in oklab, var(--accent), black 14%);
  --success: #15803d;
  --warn: #b45309;
  --danger: #b91c1c;
  --font-display: Inter, system-ui, sans-serif;
  --font-body: Inter, system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;
  --text-xs: 12px;
  --text-sm: 14px;
  --text-base: 16px;
  --text-lg: 18px;
  --text-xl: 24px;
  --text-2xl: 34px;
  --text-3xl: 48px;
  --leading-body: 1.52;
  --leading-tight: 1.08;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-12: 48px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-pill: 9999px;
  --elev-flat: none;
  --elev-ring: 0 0 0 1px var(--border);
  --elev-raised: 0 20px 52px rgba(15, 23, 42, 0.10);
  --focus-ring: 0 0 0 4px rgba(29, 78, 216, 0.22);
  --motion-fast: 150ms;
  --motion-base: 230ms;
  --ease-standard: cubic-bezier(0.2, 0, 0, 1);
  --sidebar-width: 240px;
  --topbar-height: 64px;
}

/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-font-smoothing: antialiased; }
body {
  font-family: var(--font-body);
  color: var(--fg);
  background: var(--bg);
  line-height: var(--leading-body);
  overflow: hidden;
  height: 100vh;
}

/* ===== Dashboard Layout ===== */
.dashboard {
  display: flex;
  height: 100vh;
  width: 100%;
}

/* ===== Sidebar ===== */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: var(--space-5) 0;
  overflow-y: auto;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0 var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--border-soft);
  margin-bottom: var(--space-3);
  flex-wrap: wrap;
}
.brand-icon {
  flex-shrink: 0;
  display: flex;
  align-items: center;
}
.brand-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--text-lg);
  color: var(--fg);
  letter-spacing: -0.01em;
}
.brand-period {
  font-size: var(--text-xs);
  color: var(--muted);
  background: var(--surface-warm);
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  font-weight: 500;
  margin-left: auto;
}
.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 var(--space-3);
  flex: 1;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--fg-2);
  text-decoration: none;
  font-size: var(--text-sm);
  font-weight: 500;
  transition: background var(--motion-fast) var(--ease-standard), color var(--motion-fast) var(--ease-standard);
}
.nav-item:hover {
  background: var(--surface-warm);
  color: var(--fg);
}
.nav-item.active {
  background: color-mix(in oklab, var(--accent), white 92%);
  color: var(--accent);
  font-weight: 600;
}
.nav-icon {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
}
.sidebar-footer {
  padding: var(--space-4) var(--space-5) 0;
  border-top: 1px solid var(--border-soft);
  margin-top: var(--space-4);
}
.sidebar-footer-text {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--fg);
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.sidebar-footer-sub {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

/* ===== Main Area ===== */
.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ===== Top Bar ===== */
.topbar {
  height: var(--topbar-height);
  min-height: var(--topbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-8);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  gap: var(--space-4);
}
.topbar-left {
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
}
.page-title {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--fg);
  letter-spacing: var(--tracking-display, -0.015em);
  white-space: nowrap;
}
.page-subtitle {
  font-size: var(--text-sm);
  color: var(--muted);
  white-space: nowrap;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}
.search-box {
  position: relative;
  display: flex;
  align-items: center;
}
.search-icon {
  position: absolute;
  left: 12px;
  color: var(--muted);
  pointer-events: none;
}
.search-input {
  padding: 8px 12px 8px 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--bg);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  color: var(--fg);
  width: 220px;
  transition: border-color var(--motion-fast), box-shadow var(--motion-fast);
  outline: none;
}
.search-input:focus {
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}
.search-input::placeholder { color: var(--muted); }
.user-avatar {
  position: relative;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.avatar-initials {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 700;
  color: var(--accent-on);
}
.avatar-status {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--success);
  border: 2px solid var(--surface);
}

/* ===== Content ===== */
.content {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-6) var(--space-8);
}

/* ===== KPI Grid ===== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-5);
  margin-bottom: var(--space-6);
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  transition: box-shadow var(--motion-fast) var(--ease-standard), border-color var(--motion-fast) var(--ease-standard);
}
.kpi-card:hover {
  box-shadow: var(--elev-raised);
  border-color: transparent;
}
.kpi-card.highlight {
  border-color: var(--accent);
  background: linear-gradient(135deg, color-mix(in oklab, var(--accent), white 96%), var(--surface));
}
.kpi-card.highlight:hover {
  border-color: var(--accent);
}
.kpi-label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.kpi-value {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: 800;
  color: var(--fg);
  line-height: var(--leading-tight);
  letter-spacing: -0.02em;
}
.kpi-delta {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: var(--text-sm);
  font-weight: 600;
}
.kpi-delta.positive { color: var(--success); }
.kpi-delta.negative { color: var(--danger); }
.kpi-delta.neutral { color: var(--muted); }

/* ===== Charts Section ===== */
.charts-row {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: var(--space-5);
  margin-bottom: var(--space-6);
}
.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
}
.chart-card.full {
  grid-column: 1 / -1;
}
.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
}
.chart-title {
  font-family: var(--font-display);
  font-size: var(--text-base);
  font-weight: 700;
  color: var(--fg);
}
.chart-subtitle {
  font-size: var(--text-xs);
  color: var(--muted);
}
.chart-legend {
  display: flex;
  gap: var(--space-4);
  font-size: var(--text-xs);
  font-weight: 500;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--fg-2);
}
.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
.chart-body {
  flex: 1;
  display: flex;
  align-items: flex-end;
  position: relative;
  min-height: 200px;
}
.chart-svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

/* ===== Table Section ===== */
.table-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-5);
  margin-bottom: var(--space-6);
}
.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
}
.table-title {
  font-family: var(--font-display);
  font-size: var(--text-base);
  font-weight: 700;
  color: var(--fg);
}
.data-table {
  width: 100%;
  border-collapse: collapse;
}
.data-table th {
  text-align: left;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border-soft);
}
.data-table td {
  padding: var(--space-3) var(--space-3);
  font-size: var(--text-sm);
  color: var(--fg);
  border-bottom: 1px solid var(--border-soft);
  font-weight: 500;
}
.data-table tr:last-child td {
  border-bottom: none;
}
.data-table .mono {
  font-family: var(--font-mono);
  font-weight: 500;
}
.data-table .positive { color: var(--success); }
.data-table .negative { color: var(--danger); }
.data-table .highlight-row {
  background: color-mix(in oklab, var(--accent), white 96%);
}
.data-table .highlight-row td {
  font-weight: 600;
}

/* ===== Growth trend bar ===== */
.growth-bar-track {
  display: flex;
  align-items: center;
  gap: 6px;
}
.growth-bar {
  height: 6px;
  border-radius: 3px;
  background: var(--border-soft);
  flex: 1;
  overflow: hidden;
}
.growth-bar-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--accent);
}
.growth-bar-fill.positive { background: var(--success); }
.growth-bar-fill.negative { background: var(--danger); }
.growth-bar-fill.warn { background: var(--warn); }

/* ===== Responsive ===== */
@media (max-width: 1024px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .charts-row { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .sidebar { display: none; }
  .topbar { padding: 0 var(--space-4); }
  .content { padding: var(--space-4); }
  .kpi-grid { grid-template-columns: 1fr; }
  .search-input { width: 140px; }
  .page-subtitle { display: none; }
}