/* ── Sideline Health Dashboard — Design System ──────────────────────────────
   Font: Inter (loaded via CDN in layout.ejs)
   Color tokens, spacing grid, sidebar, KPI cards, table, badges, charts
   No frameworks — pure custom CSS on a 4px base-unit grid
   ───────────────────────────────────────────────────────────────────────── */

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

:root {
  /* Colors */
  --bg:           #0A0A0F;
  --surface:      #111118;
  --surface-alt:  #0D0D14;
  --border:       rgba(255,255,255,0.06);
  --border-hover: rgba(255,255,255,0.12);

  --text-primary:   #F1F5F9;
  --text-secondary: #64748B;
  --text-muted:     #3D4A5C;

  --accent:         #6366F1;
  --accent-hover:   #4F52CC;
  --accent-subtle:  rgba(99,102,241,0.08);
  --accent-glow:    rgba(99,102,241,0.20);

  --status-active:  #10B981;
  --status-risk:    #F59E0B;
  --status-churned: #EF4444;

  --status-active-bg:  rgba(16,185,129,0.12);
  --status-risk-bg:    rgba(245,158,11,0.12);
  --status-churned-bg: rgba(239,68,68,0.12);

  /* Spacing (4px grid) */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-10: 40px;
  --sp-12: 48px;

  /* Typography */
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --text-xs:  11px;
  --text-sm:  13px;
  --text-base: 15px;
  --text-lg:  20px;
  --text-xl:  28px;

  /* Layout */
  --sidebar-w: 220px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-pill: 9999px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: var(--text-base);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* ── App Layout ──────────────────────────────────────────────────────────── */
.app-layout {
  display: flex;
  min-height: 100vh;
}

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

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-6) var(--sp-5);
  border-bottom: 1px solid var(--border);
}

.sidebar-logo-mark {
  width: 28px; height: 28px;
  background: var(--accent);
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.sidebar-logo-mark svg { width: 16px; height: 16px; fill: #fff; }

.sidebar-logo-text {
  display: flex; flex-direction: column; line-height: 1.2;
}

.sidebar-logo-name {
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.sidebar-logo-sub {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  font-weight: 400;
}

.sidebar-nav {
  flex: 1;
  padding: var(--sp-3) 0;
  overflow-y: auto;
}

.sidebar-section-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: var(--sp-3) var(--sp-5) var(--sp-2);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-5);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  transition: color 0.15s, background 0.15s;
  position: relative;
  cursor: pointer;
  border: none; background: none; width: 100%; text-align: left;
  text-decoration: none;
}

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

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

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

.nav-item svg {
  width: 16px; height: 16px;
  flex-shrink: 0;
  opacity: 0.7;
}

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

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding: var(--sp-4) var(--sp-5);
}

.sync-info {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  margin-bottom: var(--sp-3);
}

.sync-time {
  color: var(--text-primary);
  font-weight: 500;
}

.btn-refresh {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  width: 100%;
  padding: var(--sp-2) var(--sp-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: var(--text-xs);
  font-family: var(--font);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

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

.btn-refresh svg { width: 12px; height: 12px; }

/* ── Main Content ─────────────────────────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: var(--sp-6);
  min-height: 100vh;
}

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

.page-title {
  font-size: var(--text-xl);
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text-primary);
}

.page-subtitle {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin-top: 2px;
}

/* ── KPI Cards ───────────────────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: var(--sp-4);
  margin-bottom: var(--sp-6);
}

@media (max-width: 1200px) {
  .kpi-grid { grid-template-columns: repeat(3, 1fr); }
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--sp-5);
  position: relative;
  overflow: hidden;
}

.kpi-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.1), transparent);
}

.kpi-label {
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: var(--sp-3);
}

.kpi-value {
  font-size: 36px;
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1;
  color: var(--text-primary);
  margin-bottom: var(--sp-2);
}

.kpi-card.kpi-active .kpi-value   { color: var(--status-active); }
.kpi-card.kpi-risk .kpi-value     { color: var(--status-risk); }
.kpi-card.kpi-churned .kpi-value  { color: var(--status-churned); }
.kpi-card.kpi-expiring .kpi-value { color: var(--status-risk); }

.kpi-indicator {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

/* ── Toolbar (Search + Filters) ──────────────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
  flex-wrap: wrap;
}

.search-wrap {
  position: relative;
  flex: 1;
  min-width: 200px;
  max-width: 320px;
}

.search-icon {
  position: absolute;
  left: var(--sp-3);
  top: 50%; transform: translateY(-50%);
  width: 14px; height: 14px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: var(--sp-2) var(--sp-3) var(--sp-2) 36px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: var(--text-sm);
  outline: none;
  transition: border-color 0.15s;
}

.search-input::placeholder { color: var(--text-muted); }
.search-input:focus { border-color: var(--accent); }

.filter-pills {
  display: flex;
  gap: var(--sp-1);
}

.filter-pill {
  padding: var(--sp-1) var(--sp-3);
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  font-size: var(--text-xs);
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.filter-pill:hover {
  border-color: var(--border-hover);
  color: var(--text-primary);
}

.filter-pill.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.plan-select {
  padding: var(--sp-2) var(--sp-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: var(--text-sm);
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s;
}

.plan-select:focus { border-color: var(--accent); color: var(--text-primary); }

/* ── Data Table ──────────────────────────────────────────────────────────── */
.table-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.data-table thead {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
}

.data-table th {
  padding: var(--sp-3) var(--sp-4);
  text-align: left;
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-secondary);
  white-space: nowrap;
  user-select: none;
}

.data-table th.sortable {
  cursor: pointer;
  transition: color 0.15s;
}

.data-table th.sortable:hover { color: var(--text-primary); }

.sort-indicator {
  display: inline-block;
  margin-left: 4px;
  opacity: 0.4;
  font-size: 10px;
}

.data-table th.sort-asc .sort-indicator,
.data-table th.sort-desc .sort-indicator {
  opacity: 1;
  color: var(--accent);
}

.data-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.12s;
  cursor: pointer;
}

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

.data-table tbody tr:hover {
  background: var(--accent-subtle);
}

.data-table tbody tr:nth-child(even) {
  background: rgba(255,255,255,0.015);
}

.data-table tbody tr:nth-child(even):hover {
  background: var(--accent-subtle);
}

.data-table td {
  padding: var(--sp-3) var(--sp-4);
  vertical-align: middle;
  color: var(--text-primary);
}

/* ── Member Cell ─────────────────────────────────────────────────────────── */
.member-cell {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: var(--text-xs);
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  letter-spacing: 0.02em;
}

.member-info { min-width: 0; }

.member-name {
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 160px;
}

.member-email {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 160px;
}

/* ── Status Badges ───────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  white-space: nowrap;
}

.badge-active {
  background: var(--status-active-bg);
  color: var(--status-active);
  border: 1px solid rgba(16,185,129,0.2);
}

.badge-at_risk {
  background: var(--status-risk-bg);
  color: var(--status-risk);
  border: 1px solid rgba(245,158,11,0.2);
}

.badge-churned {
  background: var(--status-churned-bg);
  color: var(--status-churned);
  border: 1px solid rgba(239,68,68,0.2);
}

/* ── Storage Cell ────────────────────────────────────────────────────────── */
.storage-cell { min-width: 90px; }

.storage-value {
  font-variant-numeric: tabular-nums;
  font-size: var(--text-sm);
  color: var(--text-primary);
  margin-bottom: 4px;
}

.storage-bar-track {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.storage-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.4s ease;
}

/* ── Renewal Cell ────────────────────────────────────────────────────────── */
.renewal-normal { color: var(--text-secondary); }
.renewal-amber  { color: var(--status-risk); font-weight: 500; }
.renewal-red    { color: var(--status-churned); font-weight: 700; }

/* ── Empty State ─────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: var(--sp-12) var(--sp-6);
  color: var(--text-muted);
}

.empty-state-icon {
  font-size: 36px;
  margin-bottom: var(--sp-3);
  opacity: 0.4;
}

.empty-state-text {
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.scroll-sentinel-cell {
  text-align: center;
  padding: var(--sp-6) var(--sp-4);
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

/* ── Login Page ──────────────────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-6);
}

.login-card {
  width: 100%;
  max-width: 380px;
}

.login-logo {
  text-align: center;
  margin-bottom: var(--sp-8);
}

.login-logo-mark {
  width: 48px; height: 48px;
  background: var(--accent);
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto var(--sp-4);
}

.login-logo-mark svg { width: 26px; height: 26px; fill: #fff; }

.login-app-name {
  font-size: var(--text-lg);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.login-app-sub {
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.login-form-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--sp-8);
}

.form-group {
  margin-bottom: var(--sp-4);
}

.form-label {
  display: block;
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: var(--sp-2);
}

.form-input {
  width: 100%;
  padding: var(--sp-3) var(--sp-3);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: var(--text-base);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

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

.btn-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: var(--sp-3) var(--sp-4);
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  color: #fff;
  font-family: var(--font);
  font-size: var(--text-base);
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  margin-top: var(--sp-2);
}

.btn-primary:hover { background: var(--accent-hover); }

.login-error {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-3);
  background: var(--status-churned-bg);
  border: 1px solid rgba(239,68,68,0.2);
  border-radius: var(--radius-sm);
  color: var(--status-churned);
  font-size: var(--text-sm);
  margin-bottom: var(--sp-4);
}

.error-card { max-width: 520px; }

.error-details {
  margin-bottom: var(--sp-4);
  padding: var(--sp-3);
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: var(--text-xs);
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 240px;
  overflow: auto;
}

.error-actions {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  align-items: stretch;
}

.error-btn {
  display: block;
  text-align: center;
  text-decoration: none;
}

.error-link {
  text-align: center;
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.error-link:hover { color: var(--text-primary); }

/* ── Client Detail Page ──────────────────────────────────────────────────── */
.client-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: var(--sp-6);
  align-items: start;
}

@media (max-width: 900px) {
  .client-layout { grid-template-columns: 1fr; }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--sp-6);
  margin-bottom: var(--sp-4);
}

.card-title {
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: var(--sp-4);
}

.client-avatar-lg {
  width: 64px; height: 64px;
  border-radius: 50%;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 24px;
  font-weight: 700;
  color: #fff;
  margin-bottom: var(--sp-4);
}

.client-name-lg {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.client-email-lg {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin-bottom: var(--sp-4);
}

.detail-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--sp-2) 0;
  border-bottom: 1px solid var(--border);
  font-size: var(--text-sm);
}

.detail-row:last-child { border-bottom: none; }

.detail-key { color: var(--text-secondary); }
.detail-val { color: var(--text-primary); font-weight: 500; }

/* ── Inactivity Ring ─────────────────────────────────────────────────────── */
.inactivity-ring-wrap {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  margin-bottom: var(--sp-4);
}

.ring-svg { transform: rotate(-90deg); }

.ring-track { fill: none; stroke: var(--border); stroke-width: 6; }
.ring-fill  { fill: none; stroke-width: 6; stroke-linecap: round; transition: stroke-dashoffset 0.6s ease; }

.ring-label {
  text-align: center;
}

.ring-days {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1;
}

.ring-caption {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  margin-top: 2px;
}

/* ── Activity Timeline ───────────────────────────────────────────────────── */
.timeline { list-style: none; }

.timeline-item {
  display: flex;
  gap: var(--sp-3);
  padding: var(--sp-3) 0;
  border-bottom: 1px solid var(--border);
  font-size: var(--text-sm);
}

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

.timeline-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 5px;
}

.timeline-dot-web { background: var(--accent); }
.timeline-dot-app { background: var(--status-active); }

.timeline-content { flex: 1; }
.timeline-event { font-weight: 500; color: var(--text-primary); }
.timeline-time  { font-size: var(--text-xs); color: var(--text-secondary); }

/* ── Chart Section ───────────────────────────────────────────────────────── */
.chart-wrap {
  position: relative;
  height: 200px;
}

/* ── Misc Utilities ──────────────────────────────────────────────────────── */
.text-muted { color: var(--text-secondary); }
.text-accent { color: var(--accent); }
.font-mono { font-variant-numeric: tabular-nums; }

.loading-dot {
  display: inline-block;
  width: 6px; height: 6px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
  0%, 80%, 100% { opacity: 0.2; }
  40% { opacity: 1; }
}

/* ── Breadcrumb ──────────────────────────────────────────────────────────── */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin-bottom: var(--sp-4);
}

.breadcrumb-sep { opacity: 0.4; }
.breadcrumb-current { color: var(--text-primary); font-weight: 500; }

/* ── Back link ───────────────────────────────────────────────────────────── */
.btn-back {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  transition: color 0.15s;
}

.btn-back:hover { color: var(--text-primary); }
.btn-back svg { width: 14px; height: 14px; }
