/* ============================================
   FIRE Path Planner — Design System
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Outfit:wght@400;500;600;700;800&display=swap');

/* ---------- Custom Properties ---------- */
:root {
  /* Colors */
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-card: rgba(30, 41, 59, 0.6);
  --bg-card-hover: rgba(30, 41, 59, 0.8);
  --border-glass: rgba(51, 65, 85, 0.5);
  --border-glass-hover: rgba(99, 102, 241, 0.3);

  --text-primary: #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-muted: #64748b;

  --accent-indigo: #818cf8;
  --accent-violet: #a78bfa;
  --accent-emerald: #34d399;
  --accent-amber: #fbbf24;
  --accent-rose: #fb7185;
  --accent-cyan: #22d3ee;

  --gradient-hero: linear-gradient(135deg, #0f172a 0%, #1e1b4b 40%, #312e81 70%, #1e1b4b 100%);
  --gradient-accent: linear-gradient(135deg, #818cf8, #a78bfa, #c084fc);
  --gradient-success: linear-gradient(135deg, #34d399, #2dd4bf);
  --gradient-danger: linear-gradient(135deg, #fb7185, #f472b6);

  /* Spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;
  --space-3xl: 4rem;

  /* Radii */
  --radius-sm: 0.5rem;
  --radius-md: 0.75rem;
  --radius-lg: 1rem;
  --radius-xl: 1.25rem;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-card: 0 4px 24px rgba(0, 0, 0, 0.3), 0 0 0 1px var(--border-glass);
  --shadow-card-hover: 0 8px 40px rgba(99, 102, 241, 0.15), 0 0 0 1px var(--border-glass-hover);
  --shadow-glow-indigo: 0 0 30px rgba(129, 140, 248, 0.25);
  --shadow-glow-emerald: 0 0 30px rgba(52, 211, 153, 0.25);

  /* Transitions */
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);
}

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

html {
  scroll-behavior: smooth;
  font-size: 16px;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ---------- Animated Background ---------- */
.bg-mesh {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.bg-mesh::before,
.bg-mesh::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  filter: blur(120px);
  opacity: 0.4;
  animation: meshFloat 20s ease-in-out infinite;
}

.bg-mesh::before {
  width: 600px;
  height: 600px;
  background: radial-gradient(circle, rgba(99, 102, 241, 0.35), transparent 70%);
  top: -10%;
  right: -10%;
}

.bg-mesh::after {
  width: 500px;
  height: 500px;
  background: radial-gradient(circle, rgba(139, 92, 246, 0.3), transparent 70%);
  bottom: -10%;
  left: -15%;
  animation-delay: -10s;
}

@keyframes meshFloat {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(30px, -40px) scale(1.05); }
  66% { transform: translate(-20px, 30px) scale(0.95); }
}

/* ---------- Layout ---------- */
.app-container {
  position: relative;
  z-index: 1;
  max-width: 1280px;
  margin: 0 auto;
  padding: var(--space-xl) var(--space-lg);
}

/* ---------- Hero ---------- */
.hero {
  text-align: center;
  padding: var(--space-3xl) 0 var(--space-2xl);
}

.hero__badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-xs) var(--space-md);
  border-radius: var(--radius-full);
  background: rgba(99, 102, 241, 0.12);
  border: 1px solid rgba(99, 102, 241, 0.25);
  color: var(--accent-indigo);
  font-size: 0.8rem;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-bottom: var(--space-lg);
  animation: fadeInDown 0.6s ease-out;
}

.hero__badge .icon {
  font-size: 1rem;
}

.hero__title {
  font-family: 'Outfit', sans-serif;
  font-size: clamp(2.2rem, 5vw, 3.8rem);
  font-weight: 800;
  line-height: 1.1;
  margin-bottom: var(--space-md);
  animation: fadeInUp 0.7s ease-out;
}

.hero__title .highlight {
  background: var(--gradient-accent);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero__subtitle {
  font-size: 1.1rem;
  color: var(--text-secondary);
  max-width: 600px;
  margin: 0 auto;
  animation: fadeInUp 0.8s ease-out;
}

/* ---------- Glass Card ---------- */
.glass-card {
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-card);
  transition: box-shadow var(--transition-base), border-color var(--transition-base);
}

.glass-card:hover {
  border-color: var(--border-glass-hover);
}

.glass-card__header {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-lg) var(--space-xl);
  border-bottom: 1px solid var(--border-glass);
}

.glass-card__header .icon {
  font-size: 1.25rem;
}

.glass-card__header h2 {
  font-family: 'Outfit', sans-serif;
  font-size: 1.15rem;
  font-weight: 600;
}

.glass-card__body {
  padding: var(--space-xl);
}

/* ---------- Main Grid ---------- */
.main-grid {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: var(--space-xl);
  align-items: start;
  animation: fadeInUp 0.9s ease-out;
}

/* ---------- Form Controls ---------- */
.form-group {
  margin-bottom: var(--space-lg);
}

.form-group:last-child {
  margin-bottom: 0;
}

.form-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: var(--space-sm);
  letter-spacing: 0.02em;
}

.form-input {
  width: 100%;
  padding: 0.7rem 1rem;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  font-size: 0.95rem;
  transition: all var(--transition-fast);
  outline: none;
}

.form-input:focus {
  border-color: var(--accent-indigo);
  box-shadow: 0 0 0 3px rgba(129, 140, 248, 0.15), 0 0 20px rgba(129, 140, 248, 0.08);
}

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

.input-with-unit {
  position: relative;
}

.input-with-unit .unit {
  position: absolute;
  right: 1rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 0.85rem;
  pointer-events: none;
}

.input-with-unit .form-input {
  padding-right: 2.8rem;
}

/* ---------- Range Slider ---------- */
.range-group {
  margin-bottom: var(--space-lg);
}

.range-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-sm);
}

.range-value {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent-indigo);
  background: rgba(99, 102, 241, 0.1);
  padding: 2px 10px;
  border-radius: var(--radius-full);
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.08);
  outline: none;
  transition: background var(--transition-fast);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent-indigo);
  cursor: pointer;
  box-shadow: 0 0 10px rgba(129, 140, 248, 0.4);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.15);
  box-shadow: 0 0 18px rgba(129, 140, 248, 0.6);
}

input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent-indigo);
  cursor: pointer;
  border: none;
  box-shadow: 0 0 10px rgba(129, 140, 248, 0.4);
}

/* ---------- Portfolio Buttons ---------- */
.portfolio-group {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-sm);
  margin-bottom: var(--space-lg);
}

.portfolio-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: var(--space-sm) var(--space-xs);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-family: 'Inter', sans-serif;
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.portfolio-btn .emoji {
  font-size: 1.3rem;
}

.portfolio-btn:hover {
  background: rgba(99, 102, 241, 0.08);
  border-color: rgba(99, 102, 241, 0.3);
  color: var(--text-primary);
}

.portfolio-btn.active {
  background: rgba(99, 102, 241, 0.15);
  border-color: var(--accent-indigo);
  color: var(--text-primary);
  box-shadow: 0 0 15px rgba(99, 102, 241, 0.15);
}

.portfolio-btn .detail {
  font-size: 0.65rem;
  color: var(--text-muted);
  transition: color var(--transition-fast);
}

.portfolio-btn.active .detail {
  color: var(--accent-indigo);
}

/* ---------- Tooltips ---------- */
.portfolio-btn .info-icon {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-muted);
  font-size: 9px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-glass);
  transition: all var(--transition-fast);
}

.portfolio-btn:hover .info-icon {
  background: rgba(99, 102, 241, 0.2);
  color: var(--text-primary);
  border-color: rgba(99, 102, 241, 0.3);
}

[data-tooltip] {
  position: relative;
}

[data-tooltip]::before,
[data-tooltip]::after {
  position: absolute;
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
  pointer-events: none;
  z-index: 100;
}

[data-tooltip]::before {
  content: '';
  border: 5px solid transparent;
  border-top-color: rgba(15, 23, 42, 0.98);
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%) translateY(4px);
}

[data-tooltip]::after {
  content: attr(data-tooltip);
  bottom: calc(100% + 5px);
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  background: rgba(15, 23, 42, 0.98);
  color: #f1f5f9;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.75rem;
  font-weight: 400;
  white-space: pre-wrap;
  width: max-content;
  max-width: 200px;
  text-align: left;
  line-height: 1.5;
  border: 1px solid var(--border-glass-hover);
  box-shadow: var(--shadow-card);
  font-family: 'Inter', sans-serif;
}

@media (hover: hover) and (pointer: fine) {
  [data-tooltip]:hover::before,
  [data-tooltip]:hover::after {
    visibility: visible;
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

/* ---------- CTA Button ---------- */
.btn-primary {
  width: 100%;
  padding: 0.85rem var(--space-lg);
  background: var(--gradient-accent);
  border: none;
  border-radius: var(--radius-md);
  color: #fff;
  font-family: 'Outfit', sans-serif;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  position: relative;
  overflow: hidden;
}

.btn-primary::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.15), transparent);
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-glow-indigo);
}

.btn-primary:hover::before {
  opacity: 1;
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-primary .spinner {
  display: none;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin: 0 auto;
}

.btn-primary.loading .btn-text {
  display: none;
}

.btn-primary.loading .spinner {
  display: block;
}

/* ---------- Results Metrics ---------- */
.metrics-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-md);
  margin-top: var(--space-xl);
  animation: fadeInUp 0.5s ease-out;
}

.metric-card {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  text-align: center;
  transition: all var(--transition-base);
}

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

.metric-card .metric-icon {
  font-size: 1.5rem;
  margin-bottom: var(--space-xs);
}

.metric-card .metric-value {
  font-family: 'Outfit', sans-serif;
  font-size: 1.6rem;
  font-weight: 700;
  margin-bottom: 2px;
  transition: color var(--transition-base);
}

.metric-card .metric-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.metric-card.success .metric-value { color: var(--accent-emerald); }
.metric-card.warning .metric-value { color: var(--accent-amber); }
.metric-card.danger .metric-value { color: var(--accent-rose); }
.metric-card.info .metric-value { color: var(--accent-cyan); }

/* ---------- Chart Area ---------- */
.chart-wrapper {
  position: relative;
  width: 100%;
  min-height: 400px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chart-wrapper canvas {
  width: 100% !important;
}

.chart-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-md);
  color: var(--text-muted);
  padding: var(--space-3xl);
  text-align: center;
}

.chart-placeholder .icon {
  font-size: 3rem;
  opacity: 0.4;
}

.chart-placeholder p {
  font-size: 0.95rem;
}

/* ---------- Stress Test Section ---------- */
.stress-section {
  margin-top: var(--space-xl);
  animation: fadeInUp 0.6s ease-out;
}

.stress-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-md);
}

.stress-card {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  transition: all var(--transition-base);
}

.stress-card:hover {
  border-color: var(--border-glass-hover);
  box-shadow: var(--shadow-card-hover);
}

.stress-card__header {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
}

.stress-card__header .icon {
  font-size: 1.3rem;
}

.stress-card__header h3 {
  font-family: 'Outfit', sans-serif;
  font-size: 0.95rem;
  font-weight: 600;
}

.stress-card .stress-chart-wrapper {
  height: 200px;
  position: relative;
}

.stress-card .stress-result {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: var(--space-sm);
  padding-top: var(--space-sm);
  border-top: 1px solid var(--border-glass);
  font-size: 0.82rem;
}

.stress-card .stress-result .label {
  color: var(--text-muted);
}

.stress-card .stress-result .value {
  font-weight: 600;
}

.stress-card .stress-result .value.positive { color: var(--accent-emerald); }
.stress-card .stress-result .value.negative { color: var(--accent-rose); }

/* ---------- Explainer Section ---------- */
.explainer-section {
  margin-top: var(--space-xl);
}

.explainer-body {
  padding: var(--space-xl) var(--space-2xl);
}

.explainer-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-xl);
}

.explainer-block h3 {
  font-family: 'Outfit', sans-serif;
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: var(--space-md);
  color: var(--text-primary);
}

.explainer-block p {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.75;
  margin-bottom: var(--space-sm);
}

.explainer-block p:last-child {
  margin-bottom: 0;
}

.explainer-block strong {
  color: var(--accent-indigo);
  font-weight: 600;
}

.explainer-block ol,
.explainer-block ul {
  padding-left: 1.4rem;
  margin-bottom: var(--space-sm);
}

.explainer-block li {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.7;
  margin-bottom: var(--space-sm);
  padding-left: 0.2rem;
}

.explainer-block li:last-child {
  margin-bottom: 0;
}

.explainer-block li strong {
  color: var(--text-primary);
}

/* ---------- Footer ---------- */
.app-footer {
  text-align: center;
  padding: var(--space-2xl) 0 var(--space-xl);
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* ---------- Animations ---------- */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

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

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

@keyframes valuePopIn {
  0%   { transform: scale(0.8); opacity: 0; }
  60%  { transform: scale(1.08); }
  100% { transform: scale(1); opacity: 1; }
}

.value-pop {
  animation: valuePopIn 0.4s ease-out;
}

/* ---------- Responsive ---------- */
@media (max-width: 1024px) {
  .main-grid {
    grid-template-columns: 1fr;
  }

  .metrics-row {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 640px) {
  .app-container {
    padding: var(--space-md);
  }

  .hero {
    padding: var(--space-2xl) 0 var(--space-lg);
  }

  .hero__title {
    font-size: 1.8rem;
  }

  .metrics-row {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-sm);
  }

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

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

  .portfolio-group {
    grid-template-columns: repeat(3, 1fr);
  }

  .glass-card__header {
    padding: var(--space-md);
  }

  .glass-card__body {
    padding: var(--space-md);
  }

  .metric-card {
    padding: var(--space-md) var(--space-sm);
  }

  .metric-card .metric-value {
    font-size: 1.3rem;
  }
}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* ---------- Utility ---------- */
.hidden { display: none !important; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
}
