/* ═══════════════════════════════════════════════
   SaaS Analytics Dashboard — Design System
   Premium UI Template by Acrutus
   ═══════════════════════════════════════════════ */

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

/* ── Design Tokens ── */
:root {
  /* Color Palette — Dark Mode (Default) */
  --bg-0: #0a0a12;         /* Deepest background */
  --bg-1: #0f0f1a;         /* App background */
  --bg-2: #161625;         /* Sidebar / Elevated surfaces */
  --bg-3: #1e1e32;         /* Cards */
  --bg-4: #282845;         /* Hover states / inputs */
  --bg-5: #32325a;         /* Active states */

  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-default: rgba(255, 255, 255, 0.1);
  --border-strong: rgba(255, 255, 255, 0.16);

  --text-primary: #f0f0f5;
  --text-secondary: #a0a0b8;
  --text-tertiary: #6b6b85;
  --text-inverse: #0a0a12;

  /* Accent Colors */
  --accent-indigo: #6366f1;
  --accent-indigo-soft: rgba(99, 102, 241, 0.15);
  --accent-purple: #8b5cf6;
  --accent-pink: #ec4899;
  --accent-cyan: #06b6d4;
  --accent-emerald: #10b981;
  --accent-emerald-soft: rgba(16, 185, 129, 0.15);
  --accent-amber: #f59e0b;
  --accent-amber-soft: rgba(245, 158, 11, 0.15);
  --accent-red: #ef4444;
  --accent-red-soft: rgba(239, 68, 68, 0.15);

  /* Gradients */
  --gradient-primary: linear-gradient(135deg, #6366f1, #8b5cf6);
  --gradient-accent: linear-gradient(135deg, #6366f1, #ec4899);
  --gradient-hero: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #ec4899 100%);

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-display: 'Space Grotesk', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --text-xs: 0.6875rem;     /* 11px */
  --text-sm: 0.8125rem;     /* 13px */
  --text-base: 0.875rem;    /* 14px */
  --text-md: 1rem;          /* 16px */
  --text-lg: 1.125rem;      /* 18px */
  --text-xl: 1.25rem;       /* 20px */
  --text-2xl: 1.5rem;       /* 24px */
  --text-3xl: 1.875rem;     /* 30px */

  /* Spacing */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;

  /* Radii */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.5);
  --shadow-glow-indigo: 0 0 20px rgba(99, 102, 241, 0.3);

  /* Layout */
  --sidebar-width: 260px;
  --topbar-height: 64px;
  --transition: 0.2s ease;
}

/* ── Light Mode ── */
[data-theme="light"] {
  --bg-0: #f5f5f7;
  --bg-1: #ffffff;
  --bg-2: #f0f0f3;
  --bg-3: #ffffff;
  --bg-4: #e8e8ed;
  --bg-5: #d8d8e0;

  --border-subtle: rgba(0, 0, 0, 0.05);
  --border-default: rgba(0, 0, 0, 0.1);
  --border-strong: rgba(0, 0, 0, 0.15);

  --text-primary: #1a1a2e;
  --text-secondary: #555570;
  --text-tertiary: #8888a0;
  --text-inverse: #f0f0f5;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.12);
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-0);
  color: var(--text-primary);
  line-height: 1.5;
  overflow-x: hidden;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

ul, ol { list-style: none; }
img { max-width: 100%; display: block; }
input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  background: transparent;
  border: none;
  outline: none;
}

/* ═══════════════════════════════════════════════
   LAYOUT
   ═══════════════════════════════════════════════ */

.app {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-2);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  transition: transform var(--transition);
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--border-subtle);
  height: var(--topbar-height);
}

.sidebar__logo {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: var(--gradient-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: white;
  font-size: var(--text-sm);
}

.sidebar__brand-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--text-md);
  letter-spacing: -0.02em;
}

.sidebar__nav {
  flex: 1;
  padding: var(--space-4) var(--space-3);
  overflow-y: auto;
}

.sidebar__section {
  margin-bottom: var(--space-6);
}

.sidebar__section-label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 0 var(--space-3);
  margin-bottom: var(--space-2);
}

.sidebar__link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  font-size: var(--text-base);
  font-weight: 500;
  color: var(--text-secondary);
  transition: all var(--transition);
  margin-bottom: 2px;
}

.sidebar__link:hover {
  background: var(--bg-4);
  color: var(--text-primary);
}

.sidebar__link--active {
  background: var(--accent-indigo-soft);
  color: var(--accent-indigo);
}

.sidebar__link-icon {
  width: 20px;
  height: 20px;
  opacity: 0.7;
  flex-shrink: 0;
}

.sidebar__link--active .sidebar__link-icon {
  opacity: 1;
}

.sidebar__link-badge {
  margin-left: auto;
  background: var(--accent-indigo);
  color: white;
  font-size: var(--text-xs);
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  min-width: 20px;
  text-align: center;
}

/* Sidebar Footer */
.sidebar__footer {
  padding: var(--space-4) var(--space-4);
  border-top: 1px solid var(--border-subtle);
}

.sidebar__user {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  transition: background var(--transition);
}

.sidebar__user:hover {
  background: var(--bg-4);
}

.sidebar__avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: var(--gradient-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: var(--text-sm);
  color: white;
  flex-shrink: 0;
}

.sidebar__user-info {
  flex: 1;
  min-width: 0;
}

.sidebar__user-name {
  font-size: var(--text-sm);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar__user-role {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
}

/* ── Main Content ── */
.main {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Top Bar ── */
.topbar {
  height: var(--topbar-height);
  background: var(--bg-1);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-8);
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(12px);
}

.topbar__left {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.topbar__title {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.topbar__breadcrumb {
  font-size: var(--text-sm);
  color: var(--text-tertiary);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.topbar__breadcrumb span {
  color: var(--text-secondary);
}

.topbar__right {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.topbar__search {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--bg-3);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-4);
  width: 260px;
  transition: all var(--transition);
}

.topbar__search:focus-within {
  border-color: var(--accent-indigo);
  box-shadow: var(--shadow-glow-indigo);
}

.topbar__search-icon {
  width: 16px;
  height: 16px;
  color: var(--text-tertiary);
}

.topbar__search input {
  width: 100%;
  font-size: var(--text-sm);
}

.topbar__search input::placeholder {
  color: var(--text-tertiary);
}

.topbar__icon-btn {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  position: relative;
  color: var(--text-secondary);
}

.topbar__icon-btn:hover {
  background: var(--bg-3);
  color: var(--text-primary);
}

.topbar__icon-btn svg {
  width: 20px;
  height: 20px;
}

.topbar__badge {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 8px;
  height: 8px;
  background: var(--accent-red);
  border-radius: 50%;
  border: 2px solid var(--bg-1);
}

.topbar__theme-btn {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  color: var(--text-secondary);
}

.topbar__theme-btn:hover {
  background: var(--bg-3);
  color: var(--accent-amber);
}

/* ── Page Content ── */
.page {
  flex: 1;
  padding: var(--space-8);
  background: var(--bg-0);
}

/* ═══════════════════════════════════════════════
   COMPONENTS
   ═══════════════════════════════════════════════ */

/* ── Page Header ── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-8);
}

.page-header__left h1 {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: var(--space-1);
}

.page-header__left p {
  color: var(--text-secondary);
  font-size: var(--text-base);
}

.page-header__actions {
  display: flex;
  gap: var(--space-3);
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-5);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 600;
  transition: all var(--transition);
  white-space: nowrap;
  height: 38px;
}

.btn--primary {
  background: var(--gradient-primary);
  color: white;
  box-shadow: var(--shadow-sm);
}

.btn--primary:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-glow-indigo);
}

.btn--secondary {
  background: var(--bg-3);
  border: 1px solid var(--border-default);
  color: var(--text-primary);
}

.btn--secondary:hover {
  background: var(--bg-4);
  border-color: var(--border-strong);
}

.btn--ghost {
  color: var(--text-secondary);
}

.btn--ghost:hover {
  background: var(--bg-3);
  color: var(--text-primary);
}

.btn svg {
  width: 16px;
  height: 16px;
}

/* ── Cards ── */
.card {
  background: var(--bg-3);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: all var(--transition);
}

.card:hover {
  border-color: var(--border-default);
}

.card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--border-subtle);
}

.card__title {
  font-size: var(--text-base);
  font-weight: 600;
}

.card__subtitle {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  margin-top: 2px;
}

.card__body {
  padding: var(--space-6);
}

.card__footer {
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ── KPI / Stat Cards ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-6);
  margin-bottom: var(--space-8);
}

.stat-card {
  background: var(--bg-3);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  transition: all var(--transition);
}

.stat-card:hover {
  border-color: var(--border-default);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.stat-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
}

.stat-card__icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
}

.stat-card__icon--indigo { background: var(--accent-indigo-soft); color: var(--accent-indigo); }
.stat-card__icon--emerald { background: var(--accent-emerald-soft); color: var(--accent-emerald); }
.stat-card__icon--amber { background: var(--accent-amber-soft); color: var(--accent-amber); }
.stat-card__icon--red { background: var(--accent-red-soft); color: var(--accent-red); }

.stat-card__icon svg {
  width: 20px;
  height: 20px;
}

.stat-card__menu {
  color: var(--text-tertiary);
  cursor: pointer;
}

.stat-card__value {
  font-family: var(--font-display);
  font-size: var(--text-3xl);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: var(--space-1);
}

.stat-card__label {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin-bottom: var(--space-3);
}

.stat-card__trend {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-xs);
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius-full);
}

.stat-card__trend--up {
  background: var(--accent-emerald-soft);
  color: var(--accent-emerald);
}

.stat-card__trend--down {
  background: var(--accent-red-soft);
  color: var(--accent-red);
}

.stat-card__sparkline {
  margin-top: var(--space-4);
  height: 40px;
}

.stat-card__sparkline svg {
  width: 100%;
  height: 100%;
}

/* ── Charts ── */
.charts-row {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: var(--space-6);
  margin-bottom: var(--space-8);
}

.chart-area {
  padding: var(--space-6);
  height: 300px;
  position: relative;
}

.chart-area svg {
  width: 100%;
  height: 100%;
}

.chart__legend {
  display: flex;
  align-items: center;
  gap: var(--space-5);
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.chart__legend-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.chart__legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

/* Period tabs */
.period-tabs {
  display: flex;
  gap: 2px;
  background: var(--bg-4);
  border-radius: var(--radius-md);
  padding: 2px;
}

.period-tabs__btn {
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-secondary);
  transition: all var(--transition);
}

.period-tabs__btn--active {
  background: var(--bg-3);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

.period-tabs__btn:hover:not(.period-tabs__btn--active) {
  color: var(--text-primary);
}

/* Donut Chart */
.donut-chart {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-6);
}

.donut-chart__graphic {
  width: 180px;
  height: 180px;
  position: relative;
  margin-bottom: var(--space-5);
}

.donut-chart__center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
}

.donut-chart__center-value {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: 700;
}

.donut-chart__center-label {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
}

.donut-chart__items {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.donut-chart__item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: var(--text-sm);
}

.donut-chart__item-left {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.donut-chart__item-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.donut-chart__item-value {
  font-weight: 600;
  color: var(--text-primary);
}

/* ── Data Tables ── */
.table-wrapper {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th {
  text-align: left;
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
}

.data-table td {
  padding: var(--space-4);
  font-size: var(--text-sm);
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
}

.data-table tbody tr {
  transition: background var(--transition);
}

.data-table tbody tr:hover {
  background: var(--bg-4);
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

/* Table user cell */
.table-user {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.table-user__avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: var(--text-xs);
  color: white;
  flex-shrink: 0;
}

.table-user__name {
  font-weight: 600;
}

.table-user__email {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
}

/* ── Status Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
}

.badge--success { background: var(--accent-emerald-soft); color: var(--accent-emerald); }
.badge--warning { background: var(--accent-amber-soft); color: var(--accent-amber); }
.badge--danger  { background: var(--accent-red-soft); color: var(--accent-red); }
.badge--info    { background: var(--accent-indigo-soft); color: var(--accent-indigo); }
.badge--neutral { background: var(--bg-4); color: var(--text-secondary); }

.badge__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* ── Activity Feed ── */
.activity-feed {
  display: flex;
  flex-direction: column;
}

.activity-item {
  display: flex;
  gap: var(--space-4);
  padding: var(--space-4) 0;
  border-bottom: 1px solid var(--border-subtle);
}

.activity-item:last-child {
  border-bottom: none;
}

.activity-item__avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: var(--text-xs);
  color: white;
  flex-shrink: 0;
}

.activity-item__content {
  flex: 1;
  min-width: 0;
}

.activity-item__text {
  font-size: var(--text-sm);
  margin-bottom: 2px;
}

.activity-item__text strong {
  font-weight: 600;
}

.activity-item__time {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
}

/* ── Progress Bar ── */
.progress {
  width: 100%;
  height: 6px;
  background: var(--bg-4);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress__bar {
  height: 100%;
  border-radius: var(--radius-full);
  transition: width 0.6s ease;
}

.progress__bar--indigo { background: var(--accent-indigo); }
.progress__bar--emerald { background: var(--accent-emerald); }
.progress__bar--amber { background: var(--accent-amber); }
.progress__bar--pink { background: var(--accent-pink); }

/* ═══════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════ */

@media (max-width: 1200px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .charts-row { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }

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

  .main {
    margin-left: 0;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .page {
    padding: var(--space-4);
  }

  .topbar {
    padding: 0 var(--space-4);
  }

  .topbar__search {
    display: none;
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-4);
  }
}

/* ── Utility ── */
.text-mono { font-family: var(--font-mono); }
.text-muted { color: var(--text-secondary); }
.text-right { text-align: right; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }
.flex { display: flex; }
.items-center { align-items: center; }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mb-6 { margin-bottom: var(--space-6); }
