@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=Space+Grotesk:wght@700;800&display=swap');

:root {
  --bg: #0f1117;
  --bg-card: #1a1d27;
  --bg-sidebar: #13151f;
  --text: #f1f1f1;
  --text-muted: #9ca3af;
  --primary: #ffc451;
  --border: #2a2d3e;
  --radius: 0.75rem;
  --shadow: 0 4px 24px rgba(0,0,0,0.3);
}

*, *::before, *::after { box-sizing: border-box; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', sans-serif;
  margin: 0;
}

.layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-logo {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--primary);
  padding: 0 0.5rem 1.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.5rem;
  line-height: 1.3;
}

.sidebar-logo span {
  display: block;
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-top: 0.2rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.625rem 0.75rem;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  text-decoration: none;
}

.nav-item svg {
  flex-shrink: 0;
  opacity: 0.7;
}

.nav-item:hover,
.nav-item.active {
  background: rgba(255, 196, 81, 0.08);
  color: var(--primary);
}

.nav-item:hover svg,
.nav-item.active svg {
  opacity: 1;
}

.nav-section {
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 0.75rem 0.75rem 0.25rem;
  margin-top: 0.5rem;
}

.main {
  overflow-y: auto;
  padding: 2rem;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
}

.topbar-left h1 {
  font-size: 1.25rem;
  font-weight: 700;
  margin: 0 0 0.25rem;
}

.topbar-left p {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin: 0;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.period-btns {
  display: flex;
  gap: 0.375rem;
}

.period-btn {
  padding: 0.375rem 0.875rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.15s;
  font-family: 'Inter', sans-serif;
}

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

.period-btn.active {
  background: var(--primary);
  color: #000;
  border-color: var(--primary);
  font-weight: 700;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 2rem;
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  transition: border-color 0.15s;
}

.kpi-card:hover {
  border-color: rgba(255, 196, 81, 0.3);
}

.kpi-icon {
  width: 2rem;
  height: 2rem;
  border-radius: 0.5rem;
  background: rgba(255, 196, 81, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0.25rem;
}

.kpi-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.kpi-value {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--text);
  font-family: 'Space Grotesk', sans-serif;
  line-height: 1;
}

.kpi-change {
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.kpi-change.up { color: #34d399; }
.kpi-change.down { color: #f87171; }

.charts-row {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
}

.chart-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text);
  margin: 0;
}

.chart-subtitle {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.7rem;
  color: var(--text-muted);
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.charts-row2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

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

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

th {
  text-align: left;
  padding: 0.625rem 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
}

td {
  padding: 0.625rem 0.75rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

tr:last-child td {
  border-bottom: none;
}

tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

.badge {
  display: inline-block;
  padding: 0.2rem 0.625rem;
  border-radius: 999px;
  font-size: 0.65rem;
  font-weight: 700;
}

.badge-green {
  background: rgba(52, 211, 153, 0.15);
  color: #34d399;
}

.badge-yellow {
  background: rgba(255, 196, 81, 0.15);
  color: var(--primary);
}

.badge-red {
  background: rgba(248, 113, 113, 0.15);
  color: #f87171;
}

.rank-num {
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 50%;
  background: var(--border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--text-muted);
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .sidebar {
    display: none;
  }
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .charts-row {
    grid-template-columns: 1fr;
  }
  .charts-row2 {
    grid-template-columns: 1fr;
  }
  .main {
    padding: 1.25rem;
  }
  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.875rem;
    margin-bottom: 1.25rem;
  }
  .topbar-right {
    width: 100%;
    flex-wrap: wrap;
    gap: 0.5rem;
  }
  .topbar-left h1 {
    font-size: 1.1rem;
  }
  .period-btns {
    flex-wrap: wrap;
  }
  .table-controls {
    flex-wrap: wrap;
  }
  .search-input-dark {
    width: 100%;
    max-width: 220px;
  }
}

@media (max-width: 600px) {
  .kpi-grid {
    grid-template-columns: 1fr 1fr;
  }
  .kpi-value {
    font-size: 1.35rem;
  }
  .live-clock {
    display: none;
  }
  .notification-dropdown {
    width: 260px;
    right: -60px;
  }
  table {
    font-size: 0.72rem;
  }
  th, td {
    padding: 0.5rem 0.5rem;
  }
}

@media (max-width: 420px) {
  .kpi-grid {
    grid-template-columns: 1fr;
  }
  .topbar-right {
    gap: 0.375rem;
  }
  .back-to-main {
    font-size: 0.72rem;
    padding: 0.3rem 0.625rem;
  }
}

/* ── Chart sizing ────────────────────────────────────────────────────────── */
.chart-card canvas {
  width: 100% !important;
  height: 220px !important;
}
@media (max-width: 600px) {
  .chart-card canvas {
    height: 180px !important;
  }
  .chart-card {
    padding: 1rem;
  }
  .chart-legend {
    gap: 0.375rem;
  }
  .legend-item {
    font-size: 0.65rem;
  }
}

/* ── Back-to-main button ─────────────────────────────────────────────────── */
.back-to-main {
  display: inline-flex;
  align-items: center;
  gap: .375rem;
  padding: .375rem .875rem;
  border: 1.5px solid rgba(255,196,81,0.3);
  border-radius: .5rem;
  font-size: .8125rem;
  font-weight: 600;
  color: #ffc451;
  background: rgba(255,196,81,0.08);
  text-decoration: none;
  transition: all .2s;
  white-space: nowrap;
}
.back-to-main:hover { background: #ffc451; color: #000; }

/* ── Topbar layout adjustments ───────────────────────────────────────────── */
.topbar-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

/* ── Live clock ──────────────────────────────────────────────────────────── */
.live-clock {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* ── Icon button (theme toggle) ──────────────────────────────────────────── */
.icon-btn {
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
  padding: 0;
}
.icon-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

/* ── Notification bell ───────────────────────────────────────────────────── */
.notification-bell {
  position: relative;
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.15s;
}
.notification-bell:hover {
  border-color: var(--primary);
  color: var(--primary);
}
.notification-dot {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #f87171;
  border: 1.5px solid var(--bg-card);
}

/* ── Notification dropdown ───────────────────────────────────────────────── */
.notification-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: 300px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0,0,0,0.35);
  z-index: 200;
  overflow: hidden;
}
.notification-dropdown.open { display: block; }

.notif-header {
  padding: 0.75rem 1rem;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.notif-badge {
  background: #f87171;
  color: #fff;
  font-size: 0.6rem;
  font-weight: 700;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
}
.notif-item {
  display: flex;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: rgba(255,255,255,0.03); }
.notif-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-top: 4px;
  flex-shrink: 0;
}
.notif-content { flex: 1; }
.notif-title {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0.2rem;
}
.notif-msg {
  font-size: 0.7rem;
  color: var(--text-muted);
  line-height: 1.4;
  margin-bottom: 0.25rem;
}
.notif-time {
  font-size: 0.65rem;
  color: var(--text-muted);
  opacity: 0.7;
}

/* ── Table controls (search + export) ───────────────────────────────────── */
.table-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.search-input-dark {
  padding: 0.3rem 0.65rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 0.4rem;
  color: var(--text);
  font-size: 0.72rem;
  font-family: 'Inter', sans-serif;
  outline: none;
  width: 150px;
  transition: border-color 0.15s;
}
.search-input-dark::placeholder { color: var(--text-muted); }
.search-input-dark:focus { border-color: var(--primary); }

.btn-export {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.3rem 0.65rem;
  background: rgba(255,196,81,0.1);
  border: 1px solid rgba(255,196,81,0.35);
  border-radius: 0.4rem;
  color: var(--primary);
  font-size: 0.72rem;
  font-weight: 600;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn-export:hover { background: var(--primary); color: #000; }

/* ── Sortable column headers ─────────────────────────────────────────────── */
th[data-sort] { user-select: none; }
th[data-sort]:hover { color: var(--primary); }
.sort-icon { opacity: 0.4; font-size: 0.65rem; }
th.sort-asc  .sort-icon::before { content: '▲'; opacity: 1; }
th.sort-desc .sort-icon::before { content: '▼'; opacity: 1; }
th.sort-asc  .sort-icon,
th.sort-desc .sort-icon { opacity: 1; color: var(--primary); }

/* ── Light mode overrides ────────────────────────────────────────────────── */
body.light-mode {
  --bg: #f8fafc;
  --bg-card: #ffffff;
  --bg-sidebar: #f1f5f9;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
}
body.light-mode .topbar-left p { color: #64748b; }
body.light-mode th { color: #64748b; }
body.light-mode td { color: #1e293b; }
body.light-mode tr:hover td { background: rgba(0,0,0,0.02); }
body.light-mode .icon-btn { color: #64748b; }
body.light-mode .notification-bell { color: #64748b; }
body.light-mode .live-clock { color: #64748b; }
body.light-mode .notification-dot { border-color: #ffffff; }
