/* ============================================================
   CSS Custom Properties (from theme.css)
   ============================================================ */
:root {
  --background: #0d1117;
  --foreground: #f1f5f9;
  --card: #131a23;
  --card-foreground: #f1f5f9;
  --primary: #b6f36b;
  --primary-foreground: #102006;
  --secondary: #1b2530;
  --muted: #18212b;
  --muted-foreground: #8d9ba9;
  --border: rgba(161, 181, 199, 0.14);
  --destructive: #f27575;
  --radius: 0.75rem;
  --font-body: 'Manrope', sans-serif;
  --font-mono: 'DM Mono', monospace;
}

/* ============================================================
   Reset & Base
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: var(--font-body);
  background: var(--background);
  color: var(--foreground);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button { cursor: pointer; font-family: inherit; border: none; background: none; }
input  { font-family: inherit; }
table  { border-collapse: collapse; width: 100%; }

/* ============================================================
   Layout
   ============================================================ */
.app-wrapper {
  display: flex;
  min-height: 100vh;
  max-width: 1600px;
  margin: 0 auto;
}

/* ============================================================
   Sidebar
   ============================================================ */
.sidebar {
  position: fixed;
  inset-block: 0;
  left: 0;
  z-index: 50;
  width: 260px;
  background: #0a0f14;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1.25rem 1rem;
  transition: transform 0.3s ease;
  transform: translateX(-100%);
}

@media (min-width: 1024px) {
  .sidebar {
    position: static;
    transform: translateX(0);
    flex-shrink: 0;
  }
}

.sidebar.open { transform: translateX(0); }

.sidebar-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
}
.sidebar-overlay.hidden { display: none; }

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 0.5rem;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-icon {
  width: 36px;
  height: 36px;
  border-radius: 0.75rem;
  background: var(--primary);
  color: var(--primary-foreground);
  display: grid;
  place-items: center;
  box-shadow: 0 0 28px rgba(182, 243, 107, 0.16);
}

.icon-brand { width: 20px; height: 20px; stroke-width: 2.8; }

.brand-title {
  font-size: 0.875rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.brand-sub {
  font-size: 0.625rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--muted-foreground);
}

.sidebar-close {
  width: 32px;
  height: 32px;
  border-radius: 0.5rem;
  border: 1px solid var(--border);
  color: var(--muted-foreground);
  display: grid;
  place-items: center;
  transition: background 0.15s, color 0.15s;
}
.sidebar-close:hover { background: var(--card); color: white; }
.sidebar-close svg { width: 16px; height: 16px; }

.sidebar-nav {
  margin-top: 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.625rem 0.875rem;
  border-radius: 0.75rem;
  text-align: left;
  font-size: 0.875rem;
  font-weight: 600;
  color: #92a1af;
  transition: background 0.15s, color 0.15s;
}
.nav-item svg { width: 18px; height: 18px; color: #718290; flex-shrink: 0; }
.nav-item:hover { background: #151e27; color: white; }
.nav-item.active { background: #1b2831; color: white; }
.nav-item.active svg { color: var(--primary); }

.nav-dot {
  margin-left: auto;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
  display: none;
}
.nav-item.active .nav-dot { display: block; }

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

/* ============================================================
   Header
   ============================================================ */
.top-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 78px;
  padding: 0 1.25rem;
  border-bottom: 1px solid var(--border);
}

@media (min-width: 640px) { .top-header { padding: 0 2rem; } }

.header-left { display: flex; align-items: center; gap: 0.75rem; }

.page-title {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.035em;
  color: white;
  margin-top: 2px;
}

.header-right { display: flex; align-items: center; gap: 0.5rem; }

@media (min-width: 640px) { .header-right { gap: 0.75rem; } }

.live-badge {
  display: none;
  align-items: center;
  gap: 0.5rem;
  border-radius: 9999px;
  border: 1px solid var(--border);
  background: var(--card);
  padding: 0.375rem 0.75rem;
  font-size: 0.6875rem;
  color: var(--muted-foreground);
}
@media (min-width: 640px) { .live-badge { display: flex; } }

.live-dot {
  width: 6px; height: 6px; border-radius: 50%;
}
.live-dot.live { background: var(--primary); }
.live-dot.demo { background: #f5c76a; }

.avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: #c3d0e4;
  color: #182230;
  font-size: 0.75rem;
  font-weight: 800;
  display: grid;
  place-items: center;
}

/* ============================================================
   Icon Buttons
   ============================================================ */
.icon-btn {
  width: 36px; height: 36px;
  border-radius: 0.5rem;
  border: 1px solid var(--border);
  color: var(--muted-foreground);
  display: grid;
  place-items: center;
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--card); color: white; }
.icon-btn svg { width: 17px; height: 17px; }

/* ============================================================
   Content
   ============================================================ */
.content {
  padding: 1.75rem 1.25rem;
}
@media (min-width: 640px) { .content { padding: 1.75rem 2rem; } }
@media (min-width: 1024px) { .content { padding: 1.75rem 2.5rem; } }

/* ============================================================
   Controls Bar
   ============================================================ */
.controls-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1.75rem;
  justify-content: flex-end;
}

.date-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  height: 40px;
  border-radius: 0.5rem;
  border: 1px solid var(--border);
  background: var(--card);
  padding: 0 0.75rem;
  font-size: 0.875rem;
  color: #cbd7df;
  cursor: default;
}
.date-label svg { width: 15px; height: 15px; color: var(--muted-foreground); }

#date-input {
  width: 116px;
  background: transparent;
  outline: none;
  border: none;
  font-size: 0.75rem;
  color: #cbd7df;
  color-scheme: dark;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  height: 40px;
  padding: 0 0.875rem;
  border-radius: 0.5rem;
  background: var(--primary);
  color: var(--primary-foreground);
  font-size: 0.75rem;
  font-weight: 800;
  transition: filter 0.15s;
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.05); }
.btn-primary:disabled { opacity: 0.7; cursor: not-allowed; }
.btn-primary svg { width: 15px; height: 15px; }

/* ============================================================
   KPI Grid
   ============================================================ */
.kpi-grid {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: 1fr;
}
@media (min-width: 640px)  { .kpi-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1536px) { .kpi-grid { grid-template-columns: repeat(4, 1fr); } }

.kpi-card {
  border-radius: 0.75rem;
  border: 1px solid var(--border);
  background: var(--card);
  padding: 1rem;
  transition: transform 0.2s, border-color 0.2s;
  cursor: default;
}
.kpi-card:hover { transform: translateY(-2px); border-color: #536471; }

.kpi-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

.kpi-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted-foreground);
}

.kpi-icon {
  width: 32px; height: 32px;
  border-radius: 0.5rem;
  background: #1c2831;
  color: var(--primary);
  display: grid;
  place-items: center;
  transition: transform 0.2s;
}
.kpi-card:hover .kpi-icon { transform: scale(1.1); }
.kpi-icon svg { width: 16px; height: 16px; }

.kpi-value {
  margin-top: 1rem;
  font-size: 1.625rem;
  font-weight: 800;
  letter-spacing: -0.045em;
  color: white;
  line-height: 1;
}

.kpi-change {
  margin-top: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.6875rem;
  color: #95a5b2;
}
.kpi-change svg { width: 13px; height: 13px; }
.kpi-change.positive svg { color: var(--primary); }
.kpi-change.negative svg { color: var(--destructive); }

/* ============================================================
   Charts Row
   ============================================================ */
.charts-row {
  margin-top: 1.25rem;
  display: grid;
  gap: 1.25rem;
  grid-template-columns: 1fr;
}
@media (min-width: 1536px) {
  .charts-row { grid-template-columns: minmax(0, 1.55fr) minmax(360px, 0.85fr); }
}

.chart-card {
  border-radius: 0.75rem;
  border: 1px solid var(--border);
  background: var(--card);
  padding: 1rem;
}
@media (min-width: 640px) { .chart-card { padding: 1.25rem; } }

.chart-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

.chart-title {
  font-size: 0.875rem;
  font-weight: 700;
  color: white;
}
.chart-sub {
  margin-top: 0.25rem;
  font-size: 0.75rem;
  color: var(--muted-foreground);
}

.mtd-badge {
  border-radius: 0.5rem;
  background: #19252d;
  padding: 0.25rem 0.625rem;
  font-family: var(--font-mono);
  font-size: 0.625rem;
  color: var(--primary);
}

.trend-badge {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--primary);
}
.trend-badge svg { width: 15px; height: 15px; }

.chart-area { margin-top: 1.25rem; }

/* ============================================================
   Revenue Chart (SVG-based)
   ============================================================ */
.rev-chart-wrap {
  position: relative;
  height: 260px;
  padding-top: 0.75rem;
}

.rev-tooltip {
  pointer-events: none;
  position: absolute;
  z-index: 20;
  transform: translateX(-50%) translateY(-100%);
  border-radius: 0.5rem;
  border: 1px solid var(--border);
  background: #17222c;
  padding: 0.5rem;
  font-size: 0.75rem;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.rev-tooltip .tt-date { font-family: var(--font-mono); font-size: 0.625rem; color: var(--muted-foreground); }
.rev-tooltip .tt-rev  { font-weight: 800; color: var(--primary); }
.rev-tooltip .tt-sales { font-size: 0.625rem; color: rgba(255,255,255,0.8); }

.rev-y-axis {
  pointer-events: none;
  position: absolute;
  left: 0; right: 0;
  top: 0.75rem;
  bottom: 1.75rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.rev-y-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.rev-y-label {
  width: 40px;
  font-family: var(--font-mono);
  font-size: 0.5625rem;
  color: #718190;
}
.rev-y-line {
  flex: 1;
  height: 1px;
  background: rgba(112, 130, 146, 0.15);
}

.rev-svg-wrap {
  position: relative;
  height: calc(100% - 26px);
  width: 100%;
  overflow: visible;
  padding-left: 2.5rem;
}
.rev-svg-wrap svg { width: 100%; height: 100%; overflow: visible; }

.rev-x-axis {
  position: absolute;
  left: 2.5rem; right: 0;
  bottom: 0;
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 0.5625rem;
  color: #718190;
}

/* ============================================================
   Sales Bars
   ============================================================ */
.bars-wrap {
  display: flex;
  flex-direction: column;
  height: 260px;
  padding-top: 0.75rem;
}

.bars-tooltip-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-radius: 0.5rem;
  background: #18232d;
  padding: 0.25rem 0.75rem;
  font-size: 0.75rem;
  margin-bottom: 0.5rem;
  min-height: 28px;
}
.bars-tooltip-row .bt-label { font-family: var(--font-mono); color: var(--muted-foreground); }
.bars-tooltip-row .bt-val   { font-weight: 800; color: var(--primary); }

.bars-area {
  position: relative;
  flex: 1;
  border-bottom: 1px solid rgba(112, 130, 146, 0.15);
}

.bars-gridlines {
  pointer-events: none;
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.bars-gridline {
  border-top: 1px dashed rgba(112, 130, 146, 0.15);
}

.bars-columns {
  position: absolute;
  inset: 0.75rem 0.75rem 0;
  display: flex;
  align-items: flex-end;
  justify-content: space-around;
  gap: 0.75rem;
}

.bar-col {
  display: flex;
  flex: 1;
  flex-direction: column;
  justify-content: flex-end;
  height: 100%;
  cursor: pointer;
}

.bar-fill {
  width: 100%;
  border-radius: 0.375rem 0.375rem 0 0;
  background: #33424e;
  min-height: 8px;
  transition: background 0.15s;
}
.bar-fill.current {
  background: var(--primary);
  box-shadow: 0 0 12px rgba(182, 243, 107, 0.3);
}
.bar-col:hover .bar-fill { background: var(--primary); }

.bars-x-axis {
  margin-top: 0.5rem;
  display: flex;
  justify-content: space-around;
  padding: 0 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.625rem;
  color: #718190;
}

/* ============================================================
   Leaderboard
   ============================================================ */
.leaderboard-card {
  margin-top: 1.25rem;
  border-radius: 0.75rem;
  border: 1px solid var(--border);
  background: var(--card);
  overflow: hidden;
}

.leaderboard-header {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  border-bottom: 1px solid var(--border);
  padding: 1rem;
}
@media (min-width: 640px) {
  .leaderboard-header {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
  }
}

.leaderboard-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  font-weight: 700;
  color: white;
}
.icon-gold { width: 16px; height: 16px; color: #f5c76a; }

.leaderboard-sub {
  margin-top: 0.25rem;
  font-size: 0.75rem;
  color: var(--muted-foreground);
}

.team-mtd {
  font-family: var(--font-mono);
  font-size: 0.625rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted-foreground);
}
.team-total {
  margin-left: 0.25rem;
  color: var(--primary);
}

.table-wrap { overflow-x: auto; }

.leaderboard-table {
  min-width: 660px;
  text-align: left;
}

.leaderboard-table thead {
  background: #10171e;
  font-family: var(--font-mono);
  font-size: 0.625rem;
  text-transform: uppercase;
  letter-spacing: 0.11em;
  color: var(--muted-foreground);
}
.leaderboard-table th {
  padding: 0.75rem 1.25rem;
  font-weight: 500;
}
.leaderboard-table th:first-child { padding-left: 1.25rem; }
.leaderboard-table .text-right { text-align: right; }
.leaderboard-table .pr { padding-right: 1.25rem; }

.leaderboard-table tbody tr {
  border-top: 1px solid rgba(161, 181, 199, 0.10);
  font-size: 0.875rem;
  transition: background 0.15s;
}
.leaderboard-table tbody tr:hover { background: #17212a; }
.leaderboard-table td { padding: 0.875rem 1.25rem; }
.leaderboard-table td:first-child { padding-left: 1.25rem; }

.rank-cell {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--muted-foreground);
}

.rank-badge {
  display: inline-grid;
  width: 20px; height: 20px;
  place-items: center;
  border-radius: 50%;
  font-size: 14px;
}

.rep-cell { font-weight: 600; color: #e4edf2; }

.rep-avatar {
  display: inline-grid;
  width: 28px; height: 28px;
  border-radius: 50%;
  background: #283746;
  place-items: center;
  font-size: 0.625rem;
  color: var(--primary);
  margin-right: 0.5rem;
  vertical-align: middle;
}

.num-cell { color: #c5d2db; text-align: right; }
.mtd-cell { font-weight: 700; color: var(--primary); text-align: right; padding-right: 1.25rem; }

.empty-row { padding: 2rem; text-align: center; font-size: 0.75rem; color: var(--muted-foreground); }

/* ============================================================
   Toast
   ============================================================ */
.toast {
  position: fixed;
  top: 1rem; right: 1rem;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 0.625rem;
  border-radius: 0.75rem;
  border: 1px solid var(--border);
  background: #141f2a;
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  color: white;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
.toast.hidden { display: none; }
.toast svg { width: 18px; height: 18px; flex-shrink: 0; }
.toast.success svg { color: var(--primary); }
.toast.info    svg { color: #f5c76a; }

/* ============================================================
   Visibility helpers
   ============================================================ */
.lg-hidden { display: grid; }
@media (min-width: 1024px) { .lg-hidden { display: none !important; } }

.hidden { display: none !important; }

.icon-sm { width: 15px; height: 15px; }
.icon-xs { width: 13px; height: 13px; }

/* ============================================================
   Spin animation (loading button)
   ============================================================ */
@keyframes spin { to { transform: rotate(360deg); } }
.spin { animation: spin 0.8s linear infinite; }
