/* ============================================================
 * shared.css — unified design tokens + app shell
 *
 * Included by index.html, heal.html, and dashboard.html.
 * Provides:
 *   - :root + [data-theme] tokens (dark + light)
 *   - Top navigation bar (.app-nav) rendered by shared.js
 *   - Shared button / chip / badge primitives
 *   - Global micro-interaction and polish utilities
 *
 * Page-specific styles (funnel, stat cards, result panels…) stay
 * inline in each page and reference the tokens below.
 * ============================================================ */

/* ──────────────────────────────────────────────────────────────
 *  Design tokens
 * ────────────────────────────────────────────────────────────── */

:root,
[data-theme="dark"] {
  --bg:            #06080f;
  --bg-elev:       #0c0f1a;
  --surface:       #131724;
  --surface-2:     #1a1f30;
  --surface-3:     #252b3f;
  --border:        #262d44;
  --border-strong: #3a4262;

  /* Text */
  --text:          #f0f2ff;
  --text-dim:      #9ba3c2;
  --text-faint:    #6b7394;

  /* Accent — refined blue-violet, punchier */
  --accent:        #7b93ff;
  --accent-strong: #a5b8ff;
  --accent-dim:    #1e2a5e;
  --accent-soft:   rgba(123, 147, 255, 0.12);
  --accent-glow:   rgba(123, 147, 255, 0.25);

  --green:  #34d399;
  --green-soft:  rgba(52, 211, 153, 0.12);
  --yellow: #fbbf24;
  --yellow-soft: rgba(251, 191, 36, 0.12);
  --orange: #fb923c;
  --orange-soft: rgba(251, 146, 60, 0.12);
  --red:    #f87171;
  --red-soft:    rgba(248, 113, 113, 0.12);
  --purple: #c084fc;
  --purple-soft: rgba(192, 132, 252, 0.12);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.5);
  --shadow-md: 0 8px 24px rgba(0,0,0,0.45);
  --shadow-lg: 0 20px 50px rgba(0,0,0,0.6);

  /* Glass & glow effects */
  --glass-bg: rgba(19, 23, 36, 0.65);
  --glass-border: rgba(255, 255, 255, 0.06);
  --glass-blur: blur(20px);
  --glow-accent: 0 0 30px rgba(123, 147, 255, 0.15);
  --glow-green: 0 0 20px rgba(52, 211, 153, 0.15);
  --glow-red: 0 0 20px rgba(248, 113, 113, 0.15);
}

[data-theme="light"] {
  --bg:            #f0f2f8;
  --bg-elev:       #ffffff;
  --surface:       #ffffff;
  --surface-2:     #edf0f7;
  --surface-3:     #dfe3ee;
  --border:        #d0d5e4;
  --border-strong: #b0b8cf;

  --text:          #0a0f1e;
  --text-dim:      #414868;
  --text-faint:    #6b7394;

  --accent:        #4f46e5;
  --accent-strong: #3730a3;
  --accent-dim:    #e0e0ff;
  --accent-soft:   rgba(79, 70, 229, 0.08);
  --accent-glow:   rgba(79, 70, 229, 0.12);

  --green:  #059669;
  --green-soft:  rgba(5, 150, 105, 0.08);
  --yellow: #d97706;
  --yellow-soft: rgba(217, 119, 6, 0.08);
  --orange: #ea580c;
  --orange-soft: rgba(234, 88, 12, 0.08);
  --red:    #dc2626;
  --red-soft:    rgba(220, 38, 38, 0.08);
  --purple: #7c3aed;
  --purple-soft: rgba(124, 58, 237, 0.08);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 8px 24px rgba(0,0,0,0.07);
  --shadow-lg: 0 20px 50px rgba(0,0,0,0.10);

  --glass-bg: rgba(255, 255, 255, 0.70);
  --glass-border: rgba(0, 0, 0, 0.06);
  --glass-blur: blur(20px);
  --glow-accent: 0 0 30px rgba(79, 70, 229, 0.08);
  --glow-green: 0 0 20px rgba(5, 150, 105, 0.08);
  --glow-red: 0 0 20px rgba(220, 38, 38, 0.08);
}

:root {
  --radius-sm: 8px;
  --radius:    12px;
  --radius-lg: 16px;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'SF Mono', 'JetBrains Mono', 'Fira Code', 'Cascadia Code', ui-monospace, monospace;
  --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-medium: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

html, body {
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Subtle ambient background gradient ─────────────────────── */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 60% at 20% 10%, var(--accent-soft) 0%, transparent 60%),
    radial-gradient(ellipse 60% 50% at 80% 90%, var(--purple-soft) 0%, transparent 50%);
  pointer-events: none;
  z-index: -1;
}

/* ── Top navigation ───────────────────────────────────────── */
.app-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 20px;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-bottom: 1px solid var(--glass-border);
  box-shadow: var(--shadow-sm);
  font-family: var(--font-sans);
  font-size: 13px;
}

.app-nav .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-weight: 700;
  letter-spacing: -0.01em;
  text-decoration: none;
  font-size: 14px;
  margin-right: 8px;
}
.app-nav .brand-mark {
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #a855f6);
  color: #fff;
  box-shadow:
    0 1px 0 rgba(255,255,255,0.15) inset,
    0 4px 14px rgba(123,147,255,0.3);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}
.app-nav .brand:hover .brand-mark {
  transform: scale(1.05) rotate(-2deg);
  box-shadow:
    0 1px 0 rgba(255,255,255,0.15) inset,
    0 6px 20px rgba(123,147,255,0.4);
}
.app-nav .brand-mark svg { width: 16px; height: 16px; }
.app-nav .brand:hover { color: var(--accent); }

.app-nav .nav-links {
  display: flex;
  align-items: center;
  gap: 2px;
}
.app-nav .nav-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  color: var(--text-dim);
  text-decoration: none;
  border-radius: 10px;
  font-weight: 500;
  transition: all var(--transition-fast);
  position: relative;
}
.app-nav .nav-link:hover {
  background: var(--surface-2);
  color: var(--text);
}
.app-nav .nav-link.active {
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 600;
}
.app-nav .nav-link.active::after {
  content: '';
  position: absolute;
  bottom: -8px;
  left: 50%;
  transform: translateX(-50%);
  width: 20px;
  height: 2px;
  border-radius: 2px;
  background: var(--accent);
}
.app-nav .nav-link svg { width: 15px; height: 15px; }

.app-nav .nav-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.app-nav .icon-btn {
  display: inline-grid;
  place-items: center;
  width: 34px; height: 34px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 10px;
  cursor: pointer;
  transition: all var(--transition-fast);
}
.app-nav .icon-btn:hover {
  color: var(--text);
  background: var(--surface-2);
  border-color: var(--border-strong);
  transform: scale(1.05);
}
.app-nav .icon-btn svg { width: 16px; height: 16px; }

.app-nav .user-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px 4px 4px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1;
  transition: border-color var(--transition-fast);
}
.app-nav .user-chip:hover { border-color: var(--border-strong); }
.app-nav .user-chip .avatar {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  color: #fff;
  display: grid; place-items: center;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}
.app-nav .user-chip .email { color: var(--text); font-weight: 500; }

.app-nav .sign-out {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: 10px;
  color: var(--text-dim);
  text-decoration: none;
  font-weight: 500;
  transition: all var(--transition-fast);
}
.app-nav .sign-out:hover {
  background: var(--red-soft);
  color: var(--red);
}
.app-nav .sign-out svg { width: 14px; height: 14px; }

/* Mobile-friendly collapse */
@media (max-width: 780px) {
  .app-nav { padding: 8px 12px; gap: 6px; flex-wrap: wrap; }
  .app-nav .nav-link span { display: none; }
  .app-nav .user-chip .email { display: none; }
  .app-nav .sign-out span { display: none; }
}

/* ── Consistent page header — used by all three pages ───── */
.page-header {
  padding: 28px 32px 0;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  animation: fadeInUp 0.35s cubic-bezier(0.4, 0, 0.2, 1) both;
}
.page-header-left { display: flex; flex-direction: column; gap: 4px; }
.page-header h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
}
.page-header .page-desc {
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.4;
}
.page-header-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
@media (max-width: 640px) {
  .page-header { flex-direction: column; align-items: stretch; gap: 12px; padding: 20px 16px 0; }
}

/* ── Consistent page main area ──────────────────────────── */
.page-main {
  padding: 20px 32px 60px;
  animation: fadeInUp 0.4s cubic-bezier(0.4, 0, 0.2, 1) both;
  animation-delay: 0.05s;
}
@media (max-width: 640px) {
  .page-main { padding: 16px 16px 40px; }
}

/* ── Auth-only screen — hide shell when sign-in is active ─ */
body.auth-active .app-nav,
body.auth-active .page-header { display: none; }

/* ── Shared primitives available to all pages ─────────────── */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  background: var(--surface-2);
  color: var(--text-dim);
  white-space: nowrap;
  transition: all var(--transition-fast);
}
.chip.chip-open   { background: var(--green-soft);  color: var(--green); }
.chip.chip-merged { background: var(--accent-soft); color: var(--accent-strong); }
.chip.chip-closed { background: var(--surface-3);   color: var(--text-dim); }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 13px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
  font-family: inherit;
  position: relative;
  overflow: hidden;
}
.btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(255,255,255,0.08) 0%, transparent 100%);
  pointer-events: none;
  border-radius: inherit;
}
.btn-primary {
  background: linear-gradient(135deg, var(--accent), #6366f1);
  color: #fff;
  box-shadow: 0 2px 8px var(--accent-glow);
}
.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px var(--accent-glow);
}
.btn-primary:active { transform: translateY(0); }
.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border-color: var(--border);
}
.btn-ghost:hover {
  color: var(--text);
  background: var(--surface-2);
  border-color: var(--border-strong);
}

/* ── Skeleton / shimmer ─────────────────────────────────────── */
.shared-skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: shared-shimmer 1.6s ease infinite;
  border-radius: 6px;
  display: inline-block;
}
@keyframes shared-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── Smooth page-level transitions ──────────────────────────── */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes shared-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes slideInRight {
  from { opacity: 0; transform: translateX(16px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ── Utility: stagger children entrance ─────────────────────── */
.animate-stagger > * {
  animation: fadeInUp 0.4s cubic-bezier(0.4, 0, 0.2, 1) both;
}
.animate-stagger > *:nth-child(1) { animation-delay: 0.02s; }
.animate-stagger > *:nth-child(2) { animation-delay: 0.06s; }
.animate-stagger > *:nth-child(3) { animation-delay: 0.10s; }
.animate-stagger > *:nth-child(4) { animation-delay: 0.14s; }
.animate-stagger > *:nth-child(5) { animation-delay: 0.18s; }
.animate-stagger > *:nth-child(6) { animation-delay: 0.22s; }
.animate-stagger > *:nth-child(7) { animation-delay: 0.26s; }
.animate-stagger > *:nth-child(8)  { animation-delay: 0.30s; }
.animate-stagger > *:nth-child(9)  { animation-delay: 0.34s; }
.animate-stagger > *:nth-child(10) { animation-delay: 0.38s; }

/* ── Pulsing dot — shared across pages ──────────────────────── */
@keyframes pulse-ring {
  0%   { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.45); }
  70%  { box-shadow: 0 0 0 8px rgba(52, 211, 153, 0); }
  100% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0); }
}

/* ── Custom scrollbar (webkit) ──────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

/* ── Focus ring (accessibility) ─────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ── Selection color ────────────────────────────────────────── */
::selection {
  background: var(--accent-soft);
  color: var(--text);
}

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