/* ============================================
   PULSE DASHBOARD — CSS (Mobile First)
   Base styles = mobile. Scale up with min-width.
   ============================================ */

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

html {
  scroll-behavior: smooth;
  overflow-x: hidden;
}

/* ── DESIGN TOKENS ──────────────────────────── */
:root {
  --font-display: 'Syne', sans-serif;
  --font-body:    'DM Sans', sans-serif;

  --bg-base:       #0d0d14;
  --bg-surface:    #13131f;
  --bg-card:       #1a1a2e;
  --bg-card-hover: #1f1f38;
  --bg-input:      #1f1f38;
  --border:        rgba(255,255,255,0.07);
  --border-strong: rgba(255,255,255,0.12);

  --text-primary:  #f0f0f8;
  --text-secondary:#8b8ba8;
  --text-muted:    #55556a;

  --accent:        #6c63ff;
  --accent-glow:   rgba(108,99,255,0.25);
  --accent-soft:   rgba(108,99,255,0.12);

  --green:         #22d3a5;
  --green-soft:    rgba(34,211,165,0.12);
  --red:           #ff5f7e;
  --red-soft:      rgba(255,95,126,0.12);
  --orange:        #ff9f43;
  --orange-soft:   rgba(255,159,67,0.12);
  --blue:          #4fa3e0;
  --blue-soft:     rgba(79,163,224,0.12);

  --sidebar-width: 260px;
  --topbar-height: 60px;
  --radius:        12px;
  --radius-sm:     8px;
  --shadow:        0 4px 24px rgba(0,0,0,0.4);
  --shadow-card:   0 2px 16px rgba(0,0,0,0.25);
  --transition:    0.2s ease;
}

/* ── LIGHT THEME ────────────────────────────── */
[data-theme="light"] {
  --bg-base:       #f2f2f8;
  --bg-surface:    #e8e8f2;
  --bg-card:       #ffffff;
  --bg-card-hover: #f8f8ff;
  --bg-input:      #ededf7;
  --border:        rgba(0,0,0,0.07);
  --border-strong: rgba(0,0,0,0.12);
  --text-primary:  #12121e;
  --text-secondary:#5a5a7a;
  --text-muted:    #9999b8;
  --accent-glow:   rgba(108,99,255,0.15);
  --accent-soft:   rgba(108,99,255,0.08);
  --shadow:        0 4px 24px rgba(0,0,0,0.1);
  --shadow-card:   0 2px 12px rgba(0,0,0,0.07);
}

/* ── BODY ───────────────────────────────────── */
body {
  font-family: var(--font-body);
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  display: block; /* mobile: no flex row */
  overflow-x: hidden;
  transition: background var(--transition), color var(--transition);
}

/* ── OVERLAY ────────────────────────────────── */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 90;
  backdrop-filter: blur(2px);
}
.overlay.active { display: block; }

/* ── SIDEBAR ────────────────────────────────── */
/* Mobile: off-screen, slides in as drawer */
.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-width);
  max-width: 82vw;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1.25rem 0.875rem;
  z-index: 100;
  transform: translateX(-100%);
  transition: transform var(--transition), background var(--transition);
  overflow-y: auto;
}

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

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

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

.logo-dot {
  width: 9px; height: 9px;
  background: var(--accent);
  border-radius: 50%;
  box-shadow: 0 0 10px var(--accent-glow);
  animation: pulse-dot 2s infinite;
  flex-shrink: 0;
}

@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 8px var(--accent-glow); }
  50%       { box-shadow: 0 0 18px var(--accent); }
}

.logo-text {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.2rem;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.close-sidebar {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1rem;
  cursor: pointer;
  padding: 0.25rem;
  line-height: 1;
}

/* ── NAV ────────────────────────────────────── */
.sidebar-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.nav-label {
  font-size: 0.62rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  padding: 0 0.625rem;
  margin-top: 1rem;
  margin-bottom: 0.2rem;
  display: block;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.6rem 0.625rem;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all var(--transition);
  position: relative;
}

.nav-item svg {
  width: 17px; height: 17px;
  flex-shrink: 0;
}

.nav-item:hover {
  color: var(--text-primary);
  background: var(--accent-soft);
}

.nav-item.active {
  color: var(--accent);
  background: var(--accent-soft);
  font-weight: 600;
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 20%; bottom: 20%;
  width: 3px;
  background: var(--accent);
  border-radius: 0 3px 3px 0;
}

/* ── SIDEBAR FOOTER ─────────────────────────── */
.sidebar-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 0.375rem 0;
  border-top: 1px solid var(--border);
  margin-top: 1rem;
}

.user-card {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
}

.user-avatar {
  width: 32px; height: 32px;
  background: var(--accent);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 0.65rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.user-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.user-name {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  font-size: 0.68rem;
  color: var(--text-muted);
}

.theme-toggle {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  width: 30px; height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.8rem;
  flex-shrink: 0;
  transition: all var(--transition);
}

.theme-toggle:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

/* ── MAIN ───────────────────────────────────── */
.main {
  width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  /* no margin-left on mobile */
}

/* ── TOPBAR ─────────────────────────────────── */
.topbar {
  height: var(--topbar-height);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  position: sticky;
  top: 0;
  z-index: 50;
  gap: 0.5rem;
  overflow: hidden; /* nothing bleeds out */
  transition: background var(--transition);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  min-width: 0;
  flex: 1;
}

.menu-btn {
  display: flex; /* visible on mobile */
  flex-direction: column;
  gap: 4px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.25rem;
  flex-shrink: 0;
}

.menu-btn span {
  display: block;
  width: 20px; height: 2px;
  background: var(--text-primary);
  border-radius: 2px;
}

.page-title { min-width: 0; }

.page-title h1 {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.page-date {
  font-size: 0.67rem;
  color: var(--text-muted);
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

/* Search hidden on mobile */
.search-box { display: none; }

.date-filter select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.38rem 0.45rem;
  font-family: var(--font-body);
  font-size: 0.72rem;
  color: var(--text-primary);
  cursor: pointer;
  outline: none;
  max-width: 110px;
  transition: border-color var(--transition);
}

.date-filter select:focus { border-color: var(--accent); }

.notif-btn {
  position: relative;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  width: 34px; height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: all var(--transition);
}

.notif-btn:hover { border-color: var(--accent); }

.notif-btn svg {
  width: 16px; height: 16px;
  color: var(--text-secondary);
}

.notif-badge {
  position: absolute;
  top: -4px; right: -4px;
  background: var(--red);
  color: #fff;
  font-size: 0.55rem;
  font-weight: 700;
  width: 15px; height: 15px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── PAGES ──────────────────────────────────── */
.page {
  display: none;
  padding: 0.875rem;
  animation: fadeIn 0.3s ease;
  flex: 1;
  min-width: 0;
  max-width: 100%;
  overflow-x: hidden;
}

.page.active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── METRIC CARDS ───────────────────────────── */
/* Mobile: 2 columns */
.metrics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.625rem;
  margin-bottom: 0.625rem;
}

.metric-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.875rem;
  min-width: 0;
  transition: all var(--transition);
  animation: cardIn 0.4s ease both;
  animation-delay: var(--delay, 0ms);
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.metric-card:hover {
  border-color: var(--border-strong);
  transform: translateY(-2px);
  box-shadow: var(--shadow-card);
}

.metric-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.metric-label {
  font-size: 0.7rem;
  color: var(--text-secondary);
  font-weight: 500;
  line-height: 1.3;
}

.metric-icon {
  width: 28px; height: 28px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.metric-icon svg { width: 13px; height: 13px; }

.metric-icon.revenue  { background: var(--green-soft);  color: var(--green); }
.metric-icon.clients  { background: var(--blue-soft);   color: var(--blue); }
.metric-icon.orders   { background: var(--orange-soft); color: var(--orange); }
.metric-icon.expenses { background: var(--red-soft);    color: var(--red); }

.metric-value {
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text-primary);
  margin-bottom: 0.3rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.metric-change {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  font-size: 0.65rem;
  color: var(--text-muted);
  flex-wrap: wrap;
}

.metric-change svg { width: 11px; height: 11px; flex-shrink: 0; }
.metric-change span { font-weight: 600; }
.metric-change.positive svg,
.metric-change.positive span { color: var(--green); }
.metric-change.negative svg,
.metric-change.negative span { color: var(--red); }

/* ── CHARTS ─────────────────────────────────── */
.charts-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.625rem;
  margin-bottom: 0.625rem;
}

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

.chart-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 0.875rem;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.chart-title {
  font-family: var(--font-display);
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

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

.chart-legend {
  display: flex;
  align-items: center;
  font-size: 0.7rem;
  color: var(--text-secondary);
  gap: 0.5rem;
  flex-wrap: wrap;
}

.legend-dot {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
}

.legend-dot.revenue  { background: var(--accent); }
.legend-dot.expenses { background: var(--red); }

.chart-wrap {
  position: relative;
  width: 100%;
  height: 190px;
}

.doughnut-wrap {
  height: 155px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.doughnut-legend {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-top: 0.7rem;
}

.doughnut-legend-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.73rem;
  color: var(--text-secondary);
}

.doughnut-legend-left {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

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

.doughnut-legend-val {
  font-weight: 600;
  color: var(--text-primary);
}

/* ── AI PULSE + GOAL ────────────────────────── */
.pulse-goal-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.625rem;
  margin-bottom: 0.625rem;
}

.ai-pulse-card {
  background: var(--bg-card);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 1rem;
  position: relative;
  overflow: hidden;
  min-width: 0;
}

.ai-pulse-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--accent), var(--green), var(--accent));
  background-size: 200% 100%;
  animation: shimmer 3s linear infinite;
}

@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.pulse-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
  gap: 0.5rem;
}

.pulse-badge {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid rgba(108,99,255,0.2);
  padding: 0.22rem 0.55rem;
  border-radius: 999px;
  white-space: nowrap;
}

.pulse-dot {
  width: 6px; height: 6px;
  background: var(--accent);
  border-radius: 50%;
  animation: blink 1.5s infinite;
  flex-shrink: 0;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.2; }
}

.refresh-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  width: 28px; height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-secondary);
  flex-shrink: 0;
  transition: all var(--transition);
}

.refresh-btn:hover { border-color: var(--accent); color: var(--accent); }
.refresh-btn svg { width: 13px; height: 13px; }

.refresh-btn.spinning svg {
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

.pulse-content {
  font-size: 0.875rem;
  color: var(--text-primary);
  line-height: 1.65;
  min-height: 44px;
  display: flex;
  align-items: center;
}

.pulse-loading {
  display: flex;
  gap: 5px;
  align-items: center;
}

.pulse-loading span {
  width: 7px; height: 7px;
  background: var(--accent);
  border-radius: 50%;
  animation: bounce 1s ease infinite;
}

.pulse-loading span:nth-child(2) { animation-delay: 0.15s; }
.pulse-loading span:nth-child(3) { animation-delay: 0.3s; }

@keyframes bounce {
  0%, 100% { transform: translateY(0); opacity: 0.4; }
  50%       { transform: translateY(-5px); opacity: 1; }
}

/* ── GOAL CARD ──────────────────────────────── */
.goal-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.7rem;
  min-width: 0;
}

.goal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.goal-percent {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: -0.03em;
}

.goal-bar-track {
  width: 100%;
  height: 8px;
  background: var(--bg-input);
  border-radius: 999px;
  overflow: hidden;
}

.goal-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--green));
  border-radius: 999px;
  width: 0%;
  transition: width 1.2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.goal-details {
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
  color: var(--text-secondary);
  flex-wrap: wrap;
  gap: 0.25rem;
}

/* ── TABLE ──────────────────────────────────── */
.table-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  min-width: 0;
}

.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.875rem 1rem;
  border-bottom: 1px solid var(--border);
  gap: 0.75rem;
}

.export-btn {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--accent-soft);
  border: 1px solid rgba(108,99,255,0.2);
  border-radius: var(--radius-sm);
  padding: 0.32rem 0.6rem;
  font-family: var(--font-body);
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--accent);
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition);
}

.export-btn:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.export-btn svg { width: 12px; height: 12px; flex-shrink: 0; }

/* KEY: scrollable container, not the table itself */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  min-width: 460px; /* scroll if screen < 460px */
  border-collapse: collapse;
  font-size: 0.78rem;
}

.data-table th {
  text-align: left;
  padding: 0.6rem 0.875rem;
  font-size: 0.63rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: 0.72rem 0.875rem;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
}

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

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

.client-cell {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-primary);
  font-weight: 500;
  white-space: nowrap;
}

.client-dot {
  width: 26px; height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.58rem;
  font-weight: 700;
  flex-shrink: 0;
  color: #fff;
}

.amount-cell {
  font-family: var(--font-display);
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.18rem 0.5rem;
  border-radius: 999px;
  font-size: 0.63rem;
  font-weight: 600;
  white-space: nowrap;
}

.status-badge.paid    { background: var(--green-soft);  color: var(--green); }
.status-badge.pending { background: var(--orange-soft); color: var(--orange); }
.status-badge.overdue { background: var(--red-soft);    color: var(--red); }

/* ── PLACEHOLDER PAGES ──────────────────────── */
.placeholder-page {
  display: none;
  align-items: center;
  justify-content: center;
  flex: 1;
  min-height: calc(100vh - var(--topbar-height));
  padding: 2rem 1rem;
}

.placeholder-page.active { display: flex; }
.placeholder-content { text-align: center; }
.placeholder-icon { font-size: 2.5rem; margin-bottom: 0.875rem; }

.placeholder-content h2 {
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 0.4rem;
}

.placeholder-content p {
  color: var(--text-secondary);
  font-size: 0.875rem;
}

/* ============================================
   TABLET — 600px+
   ============================================ */
@media (min-width: 600px) {
  .page { padding: 1.125rem; }
  .topbar { padding: 0 1.25rem; }
  .page-title h1 { font-size: 1.05rem; }
  .metric-value { font-size: 1.3rem; }
  .chart-wrap { height: 210px; }
  .doughnut-wrap { height: 170px; }
  .metrics-grid { gap: 0.75rem; margin-bottom: 0.75rem; }
  .charts-grid { gap: 0.75rem; margin-bottom: 0.75rem; }
  .pulse-goal-grid { gap: 0.75rem; margin-bottom: 0.75rem; }
}

/* ============================================
   LARGE TABLET — 768px+
   Search appears, charts go side by side
   ============================================ */
@media (min-width: 768px) {
  .search-box {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.38rem 0.65rem;
    transition: border-color var(--transition);
  }

  .search-box:focus-within { border-color: var(--accent); }

  .search-box svg {
    width: 14px; height: 14px;
    color: var(--text-muted);
    flex-shrink: 0;
  }

  .search-box input {
    background: none;
    border: none;
    outline: none;
    font-family: var(--font-body);
    font-size: 0.8rem;
    color: var(--text-primary);
    width: 130px;
  }

  .search-box input::placeholder { color: var(--text-muted); }

  .topbar-right { gap: 0.65rem; }

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

/* ============================================
   DESKTOP — 1024px+
   Sidebar always visible, main shifts right
   ============================================ */
@media (min-width: 1024px) {
  body { display: flex; }

  .sidebar {
    transform: translateX(0); /* always shown */
  }

  .close-sidebar { display: none; }
  .menu-btn { display: none; }

  .main { margin-left: var(--sidebar-width); }

  .topbar { padding: 0 1.5rem; gap: 0.75rem; }

  .page { padding: 1.5rem; }

  .page-title h1 { font-size: 1.15rem; }

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

  .metric-card { padding: 1.25rem; }
  .metric-value { font-size: 1.55rem; }
  .metric-icon { width: 34px; height: 34px; }
  .metric-icon svg { width: 15px; height: 15px; }

  .charts-grid {
    grid-template-columns: 1fr 300px;
    gap: 1rem;
    margin-bottom: 1rem;
  }

  .pulse-goal-grid {
    grid-template-columns: 1fr 300px;
    gap: 1rem;
    margin-bottom: 1rem;
  }

  .chart-card { padding: 1.25rem; }
  .chart-wrap { height: 225px; }
  .doughnut-wrap { height: 180px; }
  .chart-title { font-size: 0.95rem; }

  .search-box input { width: 150px; }

  .data-table { min-width: unset; }
  .data-table th { padding: 0.72rem 1.25rem; font-size: 0.67rem; }
  .data-table td { padding: 0.82rem 1.25rem; font-size: 0.82rem; }
  .table-header { padding: 1rem 1.25rem; }
}

/* ============================================
   WIDE DESKTOP — 1280px+
   ============================================ */
@media (min-width: 1280px) {
  .charts-grid { grid-template-columns: 1fr 340px; }
  .pulse-goal-grid { grid-template-columns: 1fr 340px; }
  .search-box input { width: 170px; }
  .metric-value { font-size: 1.65rem; }
}

/* ============================================
   MODAL
   ============================================ */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  backdrop-filter: blur(3px);
}

.modal-backdrop.open { display: flex; }

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow);
  animation: modalIn 0.2s ease;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.96) translateY(10px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

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

.modal-title {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1rem;
  cursor: pointer;
  padding: 0.25rem;
  line-height: 1;
  transition: color var(--transition);
}

.modal-close:hover { color: var(--text-primary); }

.modal-body {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.form-group label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.form-group input,
.form-group select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.75rem;
  font-family: var(--font-body);
  font-size: 0.85rem;
  color: var(--text-primary);
  outline: none;
  width: 100%;
  transition: border-color var(--transition);
}

.form-group input:focus,
.form-group select:focus { border-color: var(--accent); }

.form-group input::placeholder { color: var(--text-muted); }

.form-error {
  font-size: 0.75rem;
  color: var(--red);
  min-height: 1rem;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 0 1.25rem 1.25rem;
}

.btn-primary {
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.55rem 1.1rem;
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 600;
  color: #fff;
  cursor: pointer;
  transition: opacity var(--transition);
}

.btn-primary:hover { opacity: 0.88; }
.btn-primary.small { padding: 0.4rem 0.8rem; font-size: 0.78rem; }

.btn-secondary {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.55rem 1rem;
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
}

.btn-secondary:hover {
  border-color: var(--border-strong);
  color: var(--text-primary);
}

.btn-danger {
  background: var(--red-soft);
  border: 1px solid rgba(255,95,126,0.25);
  border-radius: var(--radius-sm);
  padding: 0.5rem 1rem;
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--red);
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn-danger:hover {
  background: var(--red);
  color: #fff;
}

/* ── TABLE ACTIONS ──────────────────────────── */
.table-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.filter-tabs {
  display: flex;
  gap: 0.25rem;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  padding: 0.2rem;
}

.filter-tab {
  background: none;
  border: none;
  border-radius: 6px;
  padding: 0.3rem 0.6rem;
  font-family: var(--font-body);
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.filter-tab.active {
  background: var(--bg-card);
  color: var(--text-primary);
  font-weight: 600;
}

.add-btn {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.38rem 0.7rem;
  font-family: var(--font-body);
  font-size: 0.75rem;
  font-weight: 600;
  color: #fff;
  cursor: pointer;
  white-space: nowrap;
  transition: opacity var(--transition);
}

.add-btn:hover { opacity: 0.88; }
.add-btn svg { width: 13px; height: 13px; }

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

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.85rem;
  cursor: pointer;
  font-family: var(--font-body);
  text-decoration: underline;
}

/* Delete button in table */
.delete-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.25rem;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  transition: color var(--transition);
}

.delete-btn:hover { color: var(--red); }
.delete-btn svg { width: 14px; height: 14px; }

/* Mark paid button */
.mark-paid-btn {
  background: var(--green-soft);
  border: 1px solid rgba(34,211,165,0.2);
  border-radius: var(--radius-sm);
  padding: 0.2rem 0.55rem;
  font-family: var(--font-body);
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--green);
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition);
}

.mark-paid-btn:hover {
  background: var(--green);
  color: #fff;
}

/* ── PAGE HEADER ROW ────────────────────────── */
.page-header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  gap: 1rem;
  flex-wrap: wrap;
}

.page-heading {
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.page-subheading {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

/* ── ANALYTICS PAGE ─────────────────────────── */
.analytics-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
}

.chart-card.full-width { grid-column: 1 / -1; }

.top-clients-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

.top-client-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

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

.top-client-name {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-client-bar-track {
  height: 5px;
  background: var(--bg-input);
  border-radius: 999px;
  margin-top: 0.3rem;
  overflow: hidden;
}

.top-client-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.8s ease;
}

.top-client-amount {
  font-family: var(--font-display);
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
}

.health-stats {
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
  margin-top: 0.5rem;
}

.health-stat-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.health-stat-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.82rem;
  color: var(--text-secondary);
}

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

.health-stat-right {
  text-align: right;
}

.health-stat-amount {
  font-family: var(--font-display);
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-primary);
}

.health-stat-count {
  font-size: 0.68rem;
  color: var(--text-muted);
}
/* ── CLIENTS PAGE ───────────────────────────── */
.clients-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
}

.client-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  transition: all var(--transition);
}

.client-card:hover {
  border-color: var(--border-strong);
  transform: translateY(-1px);
}

.client-card-avatar {
  width: 42px; height: 42px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 0.78rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

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

.client-card-name {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.client-card-meta {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

.client-card-stats {
  display: flex;
  gap: 1.25rem;
  flex-shrink: 0;
}

.client-stat {
  text-align: right;
}

.client-stat-value {
  font-family: var(--font-display);
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-primary);
}

.client-stat-label {
  font-size: 0.65rem;
  color: var(--text-muted);
  display: block;
}

/* ── SETTINGS PAGE ──────────────────────────── */
.settings-wrap {
  max-width: 640px;
}

.settings-section {
  margin-top: 1.5rem;
}

.settings-section-title {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.6rem;
}

.settings-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  gap: 1rem;
  flex-wrap: wrap;
}

.settings-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
  display: block;
}

.settings-hint {
  font-size: 0.72rem;
  color: var(--text-muted);
  display: block;
  margin-top: 0.2rem;
}

.settings-input-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.input-prefix {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 600;
}

.settings-input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.7rem;
  font-family: var(--font-body);
  font-size: 0.85rem;
  color: var(--text-primary);
  outline: none;
  width: 120px;
  transition: border-color var(--transition);
}

.settings-input:focus { border-color: var(--accent); }

.theme-options {
  display: flex;
  gap: 0.4rem;
}

.theme-option {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.875rem;
  font-family: var(--font-body);
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
}

.theme-option.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

.settings-toast {
  margin-top: 1rem;
  font-size: 0.8rem;
  color: var(--green);
  min-height: 1.2rem;
  transition: opacity var(--transition);
}

/* ── NOTIFICATION BADGE HIDDEN WHEN 0 ──────── */
.notif-badge.hidden { display: none; }

/* ── PENDING LEGEND DOT ─────────────────────── */
.legend-dot.pending { background: var(--orange); }

/* ── ANALYTICS RESPONSIVE ───────────────────── */
@media (min-width: 768px) {
  .analytics-grid {
    grid-template-columns: 1fr 1fr;
  }
  .chart-card.full-width { grid-column: 1 / -1; }

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

@media (min-width: 1024px) {
  .analytics-grid {
    grid-template-columns: 1fr 1fr;
  }
}

/* ── TABLE HEADER WRAP ON MOBILE ────────────── */
@media (max-width: 600px) {
  .table-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }

  .table-actions {
    width: 100%;
  }

  .filter-tabs {
    flex: 1;
  }

  .filter-tab {
    flex: 1;
    text-align: center;
  }
}