/* ═══════════════════════════════════════════════════════════════
   base.css — design tokens, reset, typography, shared components
   ═══════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&family=DM+Mono:wght@400;500&display=swap');

/* ── Design Tokens ── */
:root {
  /* Backgrounds */
  --bg-base:        #0e0d12;
  --bg-surface:     #13121a;
  --bg-card:        #1a1a20;
  --bg-elevated:    #1f1e27;
  --bg-input:       #252530;
  --bg-hover:       #2b2d31;
  --bg-tertiary:    #24242a;

  /* Borders */
  --border-color:   #27272a;
  --border-subtle:  #2b2d31;
  --border-focus:   #6366f1;

  /* Accent — Indigo */
  --accent-primary: #6366f1;
  --accent-hover:   #5254cc;
  --accent-active:  #4547b8;
  --accent-glow:    rgba(99, 102, 241, 0.25);
  --accent-subtle:  rgba(99, 102, 241, 0.08);

  /* Semantic Colors */
  --color-success:  #22c55e;
  --color-warning:  #f59e0b;
  --color-danger:   #ef4444;
  --color-info:     #06b6d4;

  --color-success-glow: rgba(34, 197, 94, 0.2);
  --color-warning-glow: rgba(245, 158, 11, 0.2);
  --color-danger-glow:  rgba(239, 68, 68, 0.2);
  --color-info-glow:    rgba(6, 182, 212, 0.2);

  /* Aliases (keep for old refs) */
  --accent-green:   var(--color-success);
  --accent-amber:   var(--color-warning);
  --accent-danger:  var(--color-danger);
  --accent-cyan:    var(--color-info);

  /* Text */
  --text-primary:   #f1f1f3;
  --text-secondary: #9494a0;
  --text-tertiary:  #5a5a68;
  --text-disabled:  #3a3a45;

  /* Shadows */
  --shadow-sm:  0 2px 8px  rgb(0 0 0 / 0.35);
  --shadow-md:  0 4px 16px rgb(0 0 0 / 0.40);
  --shadow-lg:  0 8px 32px rgb(0 0 0 / 0.50);
  --shadow-xl:  0 16px 48px rgb(0 0 0 / 0.60);
  --glow-accent: 0 0 0 3px var(--accent-glow);

  /* Radius */
  --radius-xs:  4px;
  --radius-sm:  6px;
  --radius-md:  8px;
  --radius-lg:  12px;
  --radius-xl:  16px;
  --radius-2xl: 24px;

  /* Transitions */
  --t-fast:   0.12s ease;
  --t-base:   0.18s ease;
  --t-slow:   0.28s ease;
  --t-spring: 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);

  /* Typography */
  --font-sans: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'DM Mono', 'SF Mono', 'Fira Code', monospace;

  /* Heatmap */
  --heat-0: #1a1a20;
  --heat-1: #2d2b4e;
  --heat-2: #4338a0;
  --heat-3: #6366f1;
  --heat-4: #818cf8;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  background-color: var(--bg-base);
  background-image:
    radial-gradient(rgba(255,255,255,0.05) 1px, transparent 1px),
    linear-gradient(135deg, var(--bg-base) 0%, #1a1625 100%);
  background-size: 28px 28px, 100% 100%;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  min-height: 100vh;
  padding: 32px 24px 48px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Scrollbar ── */
::-webkit-scrollbar        { width: 4px; height: 4px; }
::-webkit-scrollbar-track  { background: transparent; }
::-webkit-scrollbar-thumb  {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 4px;
  transition: background var(--t-base);
}
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.25); }

/* ── Accessibility ── */
*:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}


/* ═══════════════════════════════════════════════════════════════
   LAYOUT
   ═══════════════════════════════════════════════════════════════ */
.page {
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border-color);
}

.page-title {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.page-subtitle {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 4px;
  font-family: var(--font-mono);
}


/* ═══════════════════════════════════════════════════════════════
   CARD
   ═══════════════════════════════════════════════════════════════ */
.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  position: relative;
  overflow: hidden;
}

.card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 60% -10%, rgba(99, 102, 241, 0.06) 0%, transparent 65%);
  pointer-events: none;
}


/* ═══════════════════════════════════════════════════════════════
   INPUTS
   ═══════════════════════════════════════════════════════════════ */
.field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.55px;
  transition: color var(--t-base);
}

.field-group:focus-within .field-label { color: var(--accent-primary); }

.input {
  width: 100%;
  background: var(--bg-input);
  border: 1.5px solid transparent;
  border-radius: var(--radius-md);
  padding: 10px 14px;
  color: var(--text-primary);
  font-size: 14px;
  font-family: var(--font-sans);
  outline: none;
  transition: border-color var(--t-base), box-shadow var(--t-base), background var(--t-base);
}

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

.input:hover:not(:focus):not(:disabled) {
  border-color: var(--border-subtle);
}

.input:focus {
  border-color: var(--accent-primary);
  box-shadow: var(--glow-accent);
  background: rgba(37, 37, 48, 0.85);
}

.input:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.input.is-error {
  border-color: var(--color-danger);
  box-shadow: 0 0 0 3px var(--color-danger-glow);
  animation: inputShake 0.28s ease;
}

.input.is-success {
  border-color: var(--color-success);
  box-shadow: 0 0 0 3px var(--color-success-glow);
}

/* Input with icon */
.input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.input-wrap .input { padding-right: 42px; }

.input-wrap .input-icon {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-tertiary);
  display: flex;
  align-items: center;
  pointer-events: none;
}

.input-wrap .input-action {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius-xs);
  display: flex;
  align-items: center;
  transition: color var(--t-base), background var(--t-base);
}

.input-wrap .input-action:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.07);
}

.field-hint {
  font-size: 11px;
  color: var(--text-tertiary);
}

.field-error {
  font-size: 11px;
  color: var(--color-danger);
  display: flex;
  align-items: center;
  gap: 4px;
}


/* ═══════════════════════════════════════════════════════════════
   BUTTONS
   ═══════════════════════════════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 18px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font-sans);
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--t-base);
  position: relative;
  overflow: hidden;
  white-space: nowrap;
  user-select: none;
  text-decoration: none;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

/* Primary */
.btn-primary {
  background: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-hover) 100%);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 4px 14px var(--accent-glow);
}

.btn-primary::before {
  content: '';
  position: absolute;
  top: 0; left: -100%;
  width: 100%; height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.15), transparent);
  transition: left 0.45s ease;
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.45);
}

.btn-primary:hover::before { left: 100%; }

.btn-primary:active {
  transform: translateY(0);
  box-shadow: 0 3px 10px var(--accent-glow);
}

/* Secondary */
.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-secondary);
  border-color: var(--border-color);
}

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

/* Ghost */
.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: transparent;
}

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

/* Danger */
.btn-danger {
  background: transparent;
  color: var(--color-danger);
  border-color: rgba(239, 68, 68, 0.25);
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.08);
  border-color: rgba(239, 68, 68, 0.45);
}

/* Sizes */
.btn-sm { padding: 6px 12px; font-size: 12px; border-radius: var(--radius-sm); }
.btn-lg { padding: 12px 24px; font-size: 15px; border-radius: var(--radius-lg); }
.btn-icon {
  padding: 8px;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-tertiary);
  border-color: transparent;
}
.btn-icon:hover { background: var(--bg-hover); color: var(--text-primary); }

/* Loading state */
.btn.is-loading {
  pointer-events: none;
  color: transparent !important;
}

.btn.is-loading::after {
  content: '';
  position: absolute;
  width: 15px; height: 15px;
  top: 50%; left: 50%;
  margin: -7.5px 0 0 -7.5px;
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  color: #fff;
}

.btn-primary.is-loading::after { border-top-color: #fff; }
.btn-secondary.is-loading::after { border-top-color: var(--text-secondary); }


/* ═══════════════════════════════════════════════════════════════
   TABS
   ═══════════════════════════════════════════════════════════════ */
.period-tabs {
  display: flex;
  gap: 3px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 3px;
}

.period-tab {
  padding: 5px 14px;
  border-radius: var(--radius-xs);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-tertiary);
  transition: all var(--t-base);
  border: none;
  background: transparent;
  font-family: var(--font-sans);
}

.period-tab.active  { background: var(--bg-hover); color: var(--text-primary); }
.period-tab:hover:not(.active) { color: var(--text-secondary); }


/* ═══════════════════════════════════════════════════════════════
   SECTION LABEL
   ═══════════════════════════════════════════════════════════════ */
.section-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-family: var(--font-mono);
}


/* ═══════════════════════════════════════════════════════════════
   BADGE
   ═══════════════════════════════════════════════════════════════ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  border: 1px solid transparent;
}

.badge-accent  { background: var(--accent-subtle);            color: #818cf8; border-color: rgba(99,102,241,0.2); }
.badge-success { background: rgba(34,197,94,0.08);            color: #4ade80; border-color: rgba(34,197,94,0.2); }
.badge-warning { background: rgba(245,158,11,0.08);           color: #fbbf24; border-color: rgba(245,158,11,0.2); }
.badge-danger  { background: rgba(239,68,68,0.08);            color: #f87171; border-color: rgba(239,68,68,0.2); }
.badge-neutral { background: rgba(148,148,160,0.1);           color: var(--text-secondary); border-color: var(--border-color); }


/* ═══════════════════════════════════════════════════════════════
   CLOSE BUTTON
   ═══════════════════════════════════════════════════════════════ */
.close-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 16px;
  background: transparent;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-tertiary);
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  transition: all var(--t-base);
}

.close-btn:hover {
  border-color: rgba(239, 68, 68, 0.35);
  color: #f87171;
  background: rgba(239, 68, 68, 0.05);
}

.close-btn svg { transition: transform var(--t-slow); flex-shrink: 0; }
.close-btn:hover svg { transform: rotate(90deg); }


/* ═══════════════════════════════════════════════════════════════
   DIVIDER
   ═══════════════════════════════════════════════════════════════ */
.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-tertiary);
  font-size: 11px;
}

.divider::before,
.divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-color);
}


/* ═══════════════════════════════════════════════════════════════
   LOADING STATES
   ═══════════════════════════════════════════════════════════════ */

/* Spinner overlay (inside a card) */
.spinner-wrap {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(13, 13, 18, 0.6);
  border-radius: inherit;
  z-index: 10;
  backdrop-filter: blur(2px);
  animation: fadeIn var(--t-slow) ease;
}

.spinner {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2.5px solid var(--border-color);
  border-top-color: var(--accent-primary);
  animation: spin 0.75s linear infinite;
}

.spinner-sm { width: 16px; height: 16px; border-width: 2px; }
.spinner-lg { width: 36px; height: 36px; border-width: 3px; }

/* Inline spinner (inside button or text) */
.spinner-inline {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-top-color: currentColor;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
}

/* Skeleton */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-elevated) 25%,
    var(--bg-hover) 50%,
    var(--bg-elevated) 75%
  );
  background-size: 200% 100%;
  animation: skeleton-wave 1.6s ease-in-out infinite;
  border-radius: var(--radius-sm);
}

/* Full-page loader */
.page-loader {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: var(--bg-base);
  z-index: 9999;
  transition: opacity 0.3s ease;
}

.page-loader.fade-out {
  opacity: 0;
  pointer-events: none;
}

.page-loader .spinner { width: 32px; height: 32px; }
.page-loader p {
  font-size: 13px;
  color: var(--text-tertiary);
  font-family: var(--font-mono);
}

/* Stat-specific (kept for statistics page) */
.stat-spinner-wrap {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 15, 19, 0.55);
  border-radius: inherit;
  z-index: 10;
}

.stat-spinner {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2.5px solid var(--border-color);
  border-top-color: var(--accent-primary);
  animation: spin 0.8s linear infinite;
}


/* ═══════════════════════════════════════════════════════════════
   ERROR & EMPTY STATES
   ═══════════════════════════════════════════════════════════════ */
.error-wrap,
.stat-error-wrap {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px;
  background: rgba(13, 13, 18, 0.75);
  border-radius: inherit;
  z-index: 10;
  text-align: center;
  backdrop-filter: blur(2px);
  animation: fadeIn var(--t-slow) ease;
}

.error-wrap svg,
.stat-error-wrap svg {
  width: 24px;
  height: 24px;
  color: var(--text-tertiary);
  flex-shrink: 0;
  opacity: 0.7;
}

.error-wrap p,
.stat-error-wrap p {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin: 0;
  line-height: 1.5;
}

.error-wrap .error-sub {
  font-size: 11px;
  color: var(--text-tertiary);
  font-family: var(--font-mono);
}

/* Empty state (not overlaid — takes own space) */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 40px 24px;
  text-align: center;
  color: var(--text-tertiary);
}

.empty-state svg {
  width: 36px;
  height: 36px;
  opacity: 0.35;
}

.empty-state p {
  font-size: 13px;
  color: var(--text-tertiary);
  line-height: 1.5;
}

/* Retry button */
.retry-btn,
.stat-retry-btn {
  padding: 5px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: background var(--t-base), color var(--t-base), border-color var(--t-base);
  margin-top: 2px;
}

.retry-btn:hover,
.stat-retry-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--accent-primary);
}

/* Network offline banner */
.offline-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  background: rgba(245, 158, 11, 0.12);
  border-bottom: 1px solid rgba(245, 158, 11, 0.25);
  color: #fbbf24;
  font-size: 13px;
  font-weight: 500;
  backdrop-filter: blur(8px);
  animation: slideDown 0.3s ease;
  transform-origin: top;
}

.offline-banner svg { width: 16px; height: 16px; flex-shrink: 0; }


/* ═══════════════════════════════════════════════════════════════
   TOAST / NOTIFICATIONS
   ═══════════════════════════════════════════════════════════════ */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9100;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  min-width: 260px;
  max-width: 360px;
  pointer-events: auto;
  animation: toastIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  backdrop-filter: blur(12px);
}

.toast.removing { animation: toastOut 0.25s ease forwards; }

.toast-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  margin-top: 1px;
}

.toast-body { flex: 1; min-width: 0; }
.toast-title { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.toast-desc  { font-size: 12px; color: var(--text-secondary); margin-top: 2px; line-height: 1.4; }

.toast-success { border-left: 3px solid var(--color-success); }
.toast-success .toast-icon { color: var(--color-success); }
.toast-error   { border-left: 3px solid var(--color-danger); }
.toast-error .toast-icon   { color: var(--color-danger); }
.toast-warning { border-left: 3px solid var(--color-warning); }
.toast-warning .toast-icon { color: var(--color-warning); }
.toast-info    { border-left: 3px solid var(--accent-primary); }
.toast-info .toast-icon    { color: var(--accent-primary); }


/* ═══════════════════════════════════════════════════════════════
   ANIMATIONS / KEYFRAMES
   ═══════════════════════════════════════════════════════════════ */
@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

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

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

@keyframes slideDown {
  from { transform: translateY(-100%); }
  to   { transform: translateY(0); }
}

@keyframes inputShake {
  0%, 100% { transform: translateX(0); }
  25%       { transform: translateX(-5px); }
  75%       { transform: translateX(5px); }
}

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

@keyframes toastIn {
  from { opacity: 0; transform: translateX(16px) scale(0.97); }
  to   { opacity: 1; transform: translateX(0) scale(1); }
}

@keyframes toastOut {
  from { opacity: 1; transform: scale(1); max-height: 120px; }
  to   { opacity: 0; transform: scale(0.95); max-height: 0; padding: 0; margin: 0; }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.5; }
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-6px); }
}

/* Utility animation classes */
.anim-fade-in    { animation: fadeIn    var(--t-slow) ease both; }
.anim-fade-in-up { animation: fadeInUp  0.4s cubic-bezier(0.16, 1, 0.3, 1) both; }
.anim-pulse      { animation: pulse     2s ease-in-out infinite; }

/* Staggered children */
.stagger > * { animation: fadeInUp 0.35s cubic-bezier(0.16, 1, 0.3, 1) both; }
.stagger > *:nth-child(1) { animation-delay: 0.04s; }
.stagger > *:nth-child(2) { animation-delay: 0.08s; }
.stagger > *:nth-child(3) { animation-delay: 0.12s; }
.stagger > *:nth-child(4) { animation-delay: 0.16s; }
.stagger > *:nth-child(5) { animation-delay: 0.20s; }
.stagger > *:nth-child(6) { animation-delay: 0.24s; }
