/* =========================================================
   NovaMetrics Dashboard — Design System
   Single accent color, dark-mode-first with light override.
   ========================================================= */

:root {
  --accent: #6366f1;
  --accent-soft: rgba(99, 102, 241, 0.15);
  --radius: 14px;
  --sidebar-w: 260px;
}

[data-theme="dark"] {
  --bg: #0b0e14;
  --surface: #12151f;
  --surface-alt: #171b28;
  --border: #232838;
  --text: #e7e9f0;
  --text-muted: #8b93a7;
}

[data-theme="light"] {
  --bg: #f4f5f9;
  --surface: #ffffff;
  --surface-alt: #f0f1f6;
  --border: #e2e4ec;
  --text: #171a21;
  --text-muted: #666d80;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background .25s ease, color .25s ease;
}

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

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  z-index: 100;
  transition: transform .25s ease;
}
.sidebar__brand {
  display: flex; align-items: center; gap: 10px;
  padding: 24px 20px; font-weight: 700; font-size: 1.1rem;
}
.brand__mark, .brand__accent { color: var(--accent); }
.sidebar__nav { flex: 1; padding: 8px 12px; overflow-y: auto; }
.sidebar__nav ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.nav-link {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px; border-radius: 10px;
  color: var(--text-muted); text-decoration: none;
  font-size: .92rem; font-weight: 500;
}
.nav-link:hover { background: var(--surface-alt); color: var(--text); }
.nav-link.active { background: var(--accent-soft); color: var(--accent); }
.sidebar__footer { padding: 16px; border-top: 1px solid var(--border); }
.theme-toggle {
  width: 100%; background: var(--surface-alt); border: 1px solid var(--border);
  color: var(--text); padding: 10px; border-radius: 10px; cursor: pointer; font-size: .85rem;
}
.theme-toggle:hover { border-color: var(--accent); }

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

/* ---------- Topbar ---------- */
.topbar {
  height: 72px; display: flex; align-items: center; gap: 16px;
  padding: 0 28px; border-bottom: 1px solid var(--border);
  background: var(--surface); position: sticky; top: 0; z-index: 50;
}
.sidebar-toggle { display: none; background: none; border: none; font-size: 1.2rem; cursor: pointer; color: var(--text); }
.icon-btn { background: none; border: none; color: var(--text-muted); font-size: 1.1rem; cursor: pointer; position: relative; }
.search-box {
  flex: 1; max-width: 420px; display: flex; align-items: center; gap: 8px;
  background: var(--surface-alt); border: 1px solid var(--border); border-radius: 10px; padding: 9px 14px;
}
.search-box input { border: none; background: transparent; outline: none; color: var(--text); width: 100%; font-size: .9rem; }
.topbar__right { display: flex; align-items: center; gap: 18px; margin-left: auto; }
.dot { position: absolute; top: -2px; right: -2px; width: 8px; height: 8px; background: #f43f5e; border-radius: 50%; }
.profile { display: flex; align-items: center; gap: 10px; cursor: pointer; position: relative; }
.profile__avatar {
  width: 36px; height: 36px; border-radius: 50%; background: var(--accent);
  color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: .8rem;
}
.profile__meta { display: flex; flex-direction: column; font-size: .8rem; line-height: 1.2; }
.profile__meta small { color: var(--text-muted); }
.profile__dropdown {
  position: absolute; top: 130%; right: 0; background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; min-width: 180px;
  box-shadow: 0 12px 24px rgba(0,0,0,.25); display: none; flex-direction: column; padding: 8px; z-index: 200;
}
.profile__dropdown.open { display: flex; }
.profile__dropdown a { padding: 9px 10px; border-radius: 8px; color: var(--text); text-decoration: none; font-size: .85rem; }
.profile__dropdown a:hover { background: var(--surface-alt); }
.profile__dropdown hr { border-color: var(--border); margin: 4px 0; }

/* ---------- Content / Views ---------- */
.content { padding: 28px; flex: 1; }
.view { display: none; }
.view.active { display: block; animation: fadeIn .3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.view-heading h1 { margin: 0 0 4px; font-size: 1.5rem; }
.view-heading p { margin: 0 0 24px; color: var(--text-muted); font-size: .9rem; }

/* ---------- KPI cards ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; margin-bottom: 24px; }
.kpi-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; display: flex; gap: 14px; align-items: flex-start;
}
.kpi-card__icon {
  font-size: 1.5rem; background: var(--accent-soft); width: 48px; height: 48px;
  border-radius: 12px; display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.kpi-card__body { display: flex; flex-direction: column; gap: 4px; }
.kpi-card__label { color: var(--text-muted); font-size: .8rem; }
.kpi-card__value { font-size: 1.4rem; font-weight: 700; }
.kpi-card__delta { font-size: .78rem; font-weight: 600; }
.delta-up { color: #22c55e; }
.delta-down { color: #f43f5e; }

/* ---------- Charts ---------- */
.charts-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 18px; margin-bottom: 24px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.card__header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; flex-wrap: wrap; gap: 10px; }
.card__header h3 { margin: 0; font-size: 1rem; }
.badge { background: var(--surface-alt); color: var(--text-muted); padding: 4px 10px; border-radius: 20px; font-size: .72rem; white-space: nowrap; }
.chart-wrap svg { width: 100%; height: auto; display: block; }
.grid-line { stroke: var(--border); stroke-width: 1; }
.axis-label { fill: var(--text-muted); font-size: 9px; }
.line-path { fill: none; stroke: var(--accent); stroke-width: 2.5; }
.area-fill { fill: var(--accent); opacity: .12; }
.data-dot { fill: var(--surface); stroke: var(--accent); stroke-width: 2; cursor: pointer; }
.data-dot:hover { fill: var(--accent); }
.bar-rect { fill: var(--accent); opacity: .85; cursor: pointer; transition: opacity .15s ease; }
.bar-rect--hover, .bar-rect:hover { opacity: 1; }

/* ---------- Data table ---------- */
.table-card { overflow: hidden; }
.table-header { flex-wrap: wrap; gap: 12px; }
.table-controls { display: flex; gap: 10px; }
.table-controls input, .table-controls select {
  background: var(--surface-alt); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 8px 12px; font-size: .85rem;
}
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .86rem; }
thead th {
  text-align: left; padding: 12px; color: var(--text-muted); font-weight: 600;
  border-bottom: 1px solid var(--border); cursor: pointer; user-select: none; white-space: nowrap;
}
thead th:hover { color: var(--accent); }
thead th.sorted-asc::after { content: ' \25B2'; color: var(--accent); }
thead th.sorted-desc::after { content: ' \25BC'; color: var(--accent); }
tbody td { padding: 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:hover { background: var(--surface-alt); }
.cust-cell { display: flex; align-items: center; gap: 10px; }
.cust-avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--surface-alt);
  border: 1px solid var(--border); display: flex; align-items: center; justify-content: center;
  font-size: .72rem; font-weight: 700; color: var(--accent); flex-shrink: 0;
}
.status-pill { padding: 4px 10px; border-radius: 20px; font-size: .72rem; font-weight: 600; white-space: nowrap; }
.status-active { background: rgba(34,197,94,.15); color: #22c55e; }
.status-trial { background: rgba(99,102,241,.15); color: var(--accent); }
.status-pending { background: rgba(234,179,8,.15); color: #eab308; }
.status-cancelled { background: rgba(244,63,94,.15); color: #f43f5e; }
.table-empty { text-align: center; padding: 24px; color: var(--text-muted); }

/* ---------- Tooltip ---------- */
.chart-tooltip {
  position: fixed; background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 12px; font-size: .78rem; color: var(--text);
  box-shadow: 0 8px 20px rgba(0,0,0,.3); pointer-events: none; z-index: 999; line-height: 1.4;
}

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .charts-grid { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.sidebar--open { transform: translateX(0); box-shadow: 0 0 0 2000px rgba(0,0,0,.45); }
  .main { margin-left: 0; }
  .sidebar-toggle { display: inline-block; }
  .topbar { padding: 0 16px; }
  .search-box { max-width: none; }
}
@media (max-width: 560px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .content { padding: 16px; }
  .table-controls { flex-direction: column; width: 100%; align-items: stretch; }
  .profile__meta { display: none; }
}
