/* ============================================
   Health Inventory — Modal Overlay & Stats
   PRD v11.1: Post-Import Health Story (Phase 1)
   ============================================ */

/* Overlay backdrop */
.health-story-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: hs-fade-in 200ms ease;
}

@keyframes hs-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* Modal card */
.health-story-card {
  position: relative;
  background: var(--color-surface-elevated, #ffffff);
  border-radius: 16px;
  box-shadow: var(--shadow-xl, 0 20px 25px -5px rgba(15, 23, 42, 0.08));
  width: 90%;
  max-width: 560px;
  max-height: 90vh;
  padding: var(--space-8, 2rem) var(--space-8, 2rem) var(--space-6, 1.5rem);
  overflow-y: auto;
  animation: hs-slide-up 300ms ease;
}

@keyframes hs-slide-up {
  from { opacity: 0; transform: translateY(24px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Close (X) button */
.health-story-close {
  position: absolute;
  top: var(--space-3, 0.75rem);
  right: var(--space-3, 0.75rem);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--color-text-muted, #94a3b8);
  font-size: 1.25rem;
  line-height: 1;
  border-radius: var(--radius-sm, 4px);
  cursor: pointer;
  transition: color var(--transition-fast, 150ms ease),
              background var(--transition-fast, 150ms ease);
}

.health-story-close:hover {
  color: var(--color-text, #1e293b);
  background: var(--color-slate-100, #f1f5f9);
}

/* ============================================
   Loading state
   ============================================ */
.health-story-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-12, 3rem) 0;
  gap: var(--space-4, 1rem);
}

.health-story-loading .hs-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--color-slate-200, #e2e8f0);
  border-top-color: var(--color-accent, #16a34a);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.health-story-loading .hs-loading-text {
  font-family: var(--font-body, 'DM Sans', sans-serif);
  font-size: var(--text-sm, 0.875rem);
  color: var(--color-text-secondary, #64748b);
}

/* ============================================
   Title
   ============================================ */
.health-story-title {
  font-family: var(--font-display, 'Source Serif 4', serif);
  font-size: var(--text-2xl, 1.5rem);
  font-weight: 600;
  color: var(--color-text, #1e293b);
  text-align: center;
  margin: 0 0 var(--space-6, 1.5rem);
  line-height: 1.3;
}

/* ============================================
   Stat cards row
   ============================================ */
.health-story-stats {
  display: grid;
  gap: var(--space-3, 0.75rem);
  margin-bottom: var(--space-6, 1.5rem);
}

.health-story-stats--cols-3 {
  grid-template-columns: repeat(3, 1fr);
}

.health-story-stats--cols-4 {
  grid-template-columns: repeat(4, 1fr);
}

.health-story-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--space-4, 1rem) var(--space-2, 0.5rem);
  background: var(--color-slate-50, #f8fafc);
  border-radius: var(--radius-lg, 12px);
  border: 1px solid var(--color-border-light, #f1f5f9);
}

.health-story-stat-number {
  font-family: var(--font-body, 'DM Sans', sans-serif);
  font-size: 2.5rem;
  font-weight: 600;
  line-height: 1.1;
  color: var(--color-accent, #16a34a);
}

.health-story-stat-label {
  font-family: var(--font-body, 'DM Sans', sans-serif);
  font-size: var(--text-sm, 0.875rem);
  color: var(--color-text-secondary, #64748b);
  text-align: center;
  margin-top: var(--space-1, 0.25rem);
}

/* ============================================
   Contextual phrase
   ============================================ */
.health-story-context-phrase {
  text-align: center;
  font-family: var(--font-body, 'DM Sans', sans-serif);
  font-size: var(--text-sm, 0.875rem);
  color: var(--color-text-muted, #94a3b8);
  margin-bottom: var(--space-6, 1.5rem);
  line-height: 1.5;
}

/* ============================================
   Timeline bar chart
   ============================================ */
.health-story-timeline-section {
  margin-bottom: var(--space-6, 1.5rem);
}

.health-story-timeline {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 80px;
  padding: 0;
}

.health-story-timeline-bar {
  flex: 1;
  min-height: 3px;
  background: var(--color-accent, #16a34a);
  border-radius: 2px 2px 0 0;
  transition: height 1s ease-out;
  height: 0;
  position: relative;
}

.health-story-timeline-bar:not([data-count="0"]) {
  cursor: help;
}

.health-story-timeline-bar[data-count]:not([data-count="0"]):hover::after {
  content: attr(data-count);
  position: absolute;
  bottom: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-text, #1e293b);
  color: white;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.7rem;
  white-space: nowrap;
  pointer-events: none;
  z-index: 1;
}

.health-story-timeline-bar[data-count="0"] {
  opacity: 0.15;
}

.health-story-timeline-labels {
  display: flex;
  gap: 4px;
  margin-top: var(--space-1, 0.25rem);
}

.health-story-timeline-label {
  flex: 1;
  font-family: var(--font-body, 'DM Sans', sans-serif);
  font-size: 0.65rem;
  color: var(--color-text-muted, #94a3b8);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
}

/* ============================================
   Multi-patient note
   ============================================ */
.health-story-multi-patient {
  text-align: center;
  font-family: var(--font-body, 'DM Sans', sans-serif);
  font-size: var(--text-sm, 0.875rem);
  color: var(--color-text-secondary, #64748b);
  margin-bottom: var(--space-4, 1rem);
}

/* ============================================
   No-data message
   ============================================ */
.health-story-no-data {
  text-align: center;
  padding: var(--space-10, 2.5rem) 0;
  font-family: var(--font-body, 'DM Sans', sans-serif);
  font-size: var(--text-base, 1rem);
  color: var(--color-text-secondary, #64748b);
}

/* ============================================
   Error state
   ============================================ */
.health-story-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: var(--space-8, 2rem) 0;
  gap: var(--space-4, 1rem);
}

.health-story-error-icon {
  font-size: 2rem;
  line-height: 1;
  color: var(--color-text-muted, #94a3b8);
}

.health-story-error-message {
  font-family: var(--font-body, 'DM Sans', sans-serif);
  font-size: var(--text-base, 1rem);
  color: var(--color-text-secondary, #64748b);
  max-width: 320px;
}

.health-story-error-actions {
  display: flex;
  gap: var(--space-3, 0.75rem);
  margin-top: var(--space-2, 0.5rem);
}

/* ============================================
   Continue / action buttons
   ============================================ */
.health-story-actions {
  display: flex;
  justify-content: center;
  padding-top: var(--space-2, 0.5rem);
}

.health-story-continue {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2, 0.5rem);
  padding: var(--space-3, 0.75rem) var(--space-8, 2rem);
  font-family: var(--font-body, 'DM Sans', sans-serif);
  font-size: var(--text-base, 1rem);
  font-weight: 600;
  border-radius: var(--radius-md, 8px);
  border: none;
  cursor: pointer;
  background: var(--color-accent, #16a34a);
  color: white;
  transition: all var(--transition-fast, 150ms ease);
}

.health-story-continue:hover:not(:disabled) {
  background: var(--color-accent-hover, #15803d);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(22, 163, 74, 0.25);
}

.health-story-continue:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.health-story-back-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2, 0.5rem);
  padding: var(--space-3, 0.75rem) var(--space-5, 1.25rem);
  font-family: var(--font-body, 'DM Sans', sans-serif);
  font-size: var(--text-sm, 0.875rem);
  font-weight: 600;
  border-radius: var(--radius-md, 8px);
  border: 1px solid var(--color-border, #e2e8f0);
  cursor: pointer;
  background: var(--color-surface-elevated, #ffffff);
  color: var(--color-text, #1e293b);
  transition: all var(--transition-fast, 150ms ease);
}

.health-story-back-btn:hover:not(:disabled) {
  background: var(--color-slate-50, #f8fafc);
  border-color: var(--color-slate-300, #cbd5e1);
}

.health-story-back-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.health-story-retry-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2, 0.5rem);
  padding: var(--space-3, 0.75rem) var(--space-5, 1.25rem);
  font-family: var(--font-body, 'DM Sans', sans-serif);
  font-size: var(--text-sm, 0.875rem);
  font-weight: 600;
  border-radius: var(--radius-md, 8px);
  border: none;
  cursor: pointer;
  background: var(--color-accent, #16a34a);
  color: white;
  transition: all var(--transition-fast, 150ms ease);
}

.health-story-retry-btn:hover:not(:disabled) {
  background: var(--color-accent-hover, #15803d);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(22, 163, 74, 0.25);
}

.health-story-retry-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ============================================
   Responsive — mobile 2×2 stat cards
   ============================================ */
@media (max-width: 480px) {
  .health-story-card {
    width: 95%;
    padding: var(--space-6, 1.5rem) var(--space-4, 1rem) var(--space-4, 1rem);
  }

  .health-story-stats--cols-3 {
    grid-template-columns: 1fr;
  }

  .health-story-stats--cols-4 {
    grid-template-columns: repeat(2, 1fr);
  }

  .health-story-stat-number {
    font-size: 2rem;
  }

  .health-story-title {
    font-size: var(--text-xl, 1.25rem);
  }
}

/* Overflow for short viewports */
@media (max-height: 600px) {
  .health-story-card {
    max-height: 85vh;
    overflow-y: auto;
  }
}
