/* ============================================
   CVD Risk Recalibration Tool — Styles
   ============================================ */

:root {
  --color-bg: #f0f4f8;
  --color-surface: #ffffff;
  --color-primary: #2563eb;
  --color-primary-hover: #1d4ed8;
  --color-primary-light: #dbeafe;
  --color-text: #1e293b;
  --color-text-secondary: #64748b;
  --color-border: #e2e8f0;
  --color-success: #059669;
  --color-success-light: #d1fae5;
  --color-warning: #d97706;
  --color-warning-light: #fef3c7;
  --color-danger: #dc2626;
  --color-danger-light: #fee2e2;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -4px rgba(0,0,0,0.04);
  --transition: 0.2s ease;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem 1rem 3rem;
}

/* ---- Welcome Modal ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  animation: modalFadeIn 0.3s ease;
}

.modal-overlay.hidden {
  display: none;
}

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

.modal {
  background: var(--color-surface);
  border-radius: 16px;
  max-width: 560px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
  overflow: hidden;
  animation: modalSlideIn 0.35s ease;
}

@keyframes modalSlideIn {
  from { opacity: 0; transform: translateY(20px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
  background: linear-gradient(135deg, #1e293b, #334155);
  color: #fff;
  padding: 2rem 2rem 1.5rem;
  text-align: center;
}

.modal-icon {
  width: 52px;
  height: 52px;
  margin: 0 auto 0.75rem;
  background: rgba(239, 68, 68, 0.2);
  border: 2px solid rgba(239, 68, 68, 0.4);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #f87171;
}

.modal-header h2 {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.modal-tagline {
  font-size: 0.85rem;
  color: #94a3b8;
  margin-top: 0.35rem;
  line-height: 1.5;
}

.modal-body {
  padding: 1.5rem 2rem;
}

.modal-body h3 {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  color: var(--color-text);
}

.modal-body > p {
  font-size: 0.85rem;
  color: var(--color-text-secondary);
  margin-bottom: 1rem;
  line-height: 1.6;
}

.modal-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.modal-list li {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  font-size: 0.84rem;
  color: var(--color-text);
  line-height: 1.55;
}

.modal-list-icon {
  font-size: 1.2rem;
  flex-shrink: 0;
  margin-top: 0.1rem;
}

.modal-list li strong {
  color: var(--color-text);
}

.modal-disclaimer {
  margin-top: 1.25rem;
  padding: 0.65rem 0.85rem;
  background: var(--color-warning-light);
  border: 1px solid #fde68a;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  line-height: 1.55;
  color: var(--color-text-secondary);
}

.modal-disclaimer strong {
  color: var(--color-warning);
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 2rem 1.5rem;
  border-top: 1px solid var(--color-border);
}

.modal-checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  color: var(--color-text-secondary);
  cursor: pointer;
}

.modal-checkbox-label input[type="checkbox"] {
  accent-color: var(--color-primary);
  width: 15px;
  height: 15px;
  cursor: pointer;
}

.btn-modal {
  padding: 0.65rem 1.5rem;
  font-size: 0.875rem;
  font-weight: 600;
  font-family: inherit;
  color: #fff;
  background: var(--color-primary);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition), box-shadow var(--transition);
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
}

.btn-modal:hover {
  background: var(--color-primary-hover);
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.35);
}

/* ---- Header ---- */
.header {
  text-align: center;
  margin-bottom: 2rem;
}

.header-icons {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.header-icon {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}

.header-icon-heart {
  background: linear-gradient(135deg, #dc2626, #ef4444);
  box-shadow: 0 4px 14px rgba(220, 38, 38, 0.3);
}

.header-icon-lung {
  background: linear-gradient(135deg, #0284c7, #38bdf8);
  box-shadow: 0 4px 14px rgba(2, 132, 199, 0.3);
}

.header-icon-lung svg {
  width: 24px;
  height: 24px;
}

.header-icon svg {
  width: 26px;
  height: 26px;
}

.header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--color-text);
}

.subtitle {
  color: var(--color-text-secondary);
  font-size: 0.95rem;
  margin-top: 0.35rem;
}

/* ---- Card ---- */
.card {
  background: var(--color-surface);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--color-border);
}

/* ---- Two-panel layout ---- */
.main-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  align-items: start;
}

.card-form {
  min-width: 0;
}

.card-results {
  position: sticky;
  top: 2rem;
}

/* Placeholder (before results are shown) */
.results-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--color-text-secondary);
}

.results-placeholder.hidden {
  display: none;
}

.placeholder-icon {
  color: var(--color-border);
  margin-bottom: 1rem;
}

.results-placeholder p {
  font-size: 0.875rem;
  line-height: 1.6;
  max-width: 260px;
}

/* ---- Form ---- */
.form-group {
  margin-bottom: 1.5rem;
}

.form-group label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 0.5rem;
}

/* External calculator link below model selector */
.calculator-link {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.4rem;
  color: var(--color-primary);
}

.calculator-link a {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--color-primary);
  text-decoration: none;
  transition: color var(--transition);
}

.calculator-link a:hover {
  color: var(--color-primary-hover);
  text-decoration: underline;
}

/* Tooltip */
.tooltip-trigger {
  position: relative;
  cursor: help;
  display: inline-flex;
  color: var(--color-text-secondary);
}

.tooltip {
  display: none;
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-text);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 400;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  width: 240px;
  text-align: center;
  z-index: 10;
  line-height: 1.4;
}

.tooltip-trigger:hover .tooltip,
.tooltip-trigger:focus .tooltip {
  display: block;
}

/* Inputs */
input[type="number"],
select {
  width: 100%;
  padding: 0.7rem 0.9rem;
  font-size: 0.95rem;
  font-family: inherit;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}

input[type="number"]:focus,
select:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-light);
}

input[type="number"]::placeholder {
  color: #94a3b8;
}

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

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

.unit {
  position: absolute;
  right: 0.9rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
  pointer-events: none;
}

.input-range-hint {
  font-size: 0.75rem;
  color: var(--color-text-secondary);
  margin-top: 0.35rem;
}

/* Select wrapper */
.select-wrapper {
  position: relative;
}

.select-wrapper select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 2.5rem;
  cursor: pointer;
}

.select-chevron {
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--color-text-secondary);
  pointer-events: none;
}

/* Radio buttons */
.radio-group {
  display: flex;
  gap: 1.5rem;
}

.radio-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 400 !important;
}

.radio-label input[type="radio"] {
  display: none;
}

.radio-custom {
  width: 20px;
  height: 20px;
  border: 2px solid var(--color-border);
  border-radius: 50%;
  position: relative;
  transition: border-color var(--transition);
  flex-shrink: 0;
}

.radio-label input[type="radio"]:checked + .radio-custom {
  border-color: var(--color-primary);
}

.radio-label input[type="radio"]:checked + .radio-custom::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 10px;
  height: 10px;
  background: var(--color-primary);
  border-radius: 50%;
}

/* Age Group Toggle */
.toggle-group {
  display: flex;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.toggle-btn {
  flex: 1;
  padding: 0.65rem 1.25rem;
  font-size: 0.95rem;
  font-weight: 500;
  font-family: inherit;
  color: var(--color-text-secondary);
  background: var(--color-surface);
  border: none;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}

.toggle-btn:first-child {
  border-right: 1px solid var(--color-border);
}

.toggle-btn:last-child {
  border-left: 1px solid var(--color-border);
}

.toggle-btn:hover:not(.active) {
  background: var(--color-primary-light);
}

.toggle-btn.active {
  background: var(--color-primary);
  color: #fff;
}

/* Button */
.btn-calculate {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.85rem 1.5rem;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  color: #fff;
  background: var(--color-primary);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition), transform 0.1s ease, box-shadow var(--transition);
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
}

.btn-calculate:hover {
  background: var(--color-primary-hover);
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.35);
}

.btn-calculate:active {
  transform: scale(0.985);
}

/* ---- Results ---- */
.results {
  animation: fadeIn 0.4s ease;
}

.results.hidden {
  display: none;
}

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

.results-divider {
  display: none;
}

.results h2 {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 1.25rem;
  color: var(--color-text);
}

.results-grid {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.result-card {
  flex: 1;
  padding: 1rem;
  border-radius: var(--radius-sm);
  text-align: center;
}

.result-card.original {
  background: #f8fafc;
  border: 1px solid var(--color-border);
}

.result-card.recalibrated {
  background: var(--color-primary-light);
  border: 1px solid #93c5fd;
}

.result-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-secondary);
  margin-bottom: 0.35rem;
}

.result-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color-text);
}

.result-card.recalibrated .result-value {
  color: var(--color-primary);
}

.result-arrow {
  flex-shrink: 0;
  color: var(--color-text-secondary);
}

.result-arrow svg {
  width: 24px;
  height: 24px;
}

/* Risk bar */
.risk-bar-container {
  margin-top: 1.75rem;
  padding-top: 1.75rem;
  padding-bottom: 1.75rem;
}

.risk-bar {
  position: relative;
  height: 16px;
  background: linear-gradient(to right, #d1fae5, #fef3c7, #fee2e2, #fecaca);
  border-radius: 99px;
  overflow: visible;
}

.risk-bar-fill {
  height: 100%;
  border-radius: 99px;
}

.risk-bar-marker {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2.5px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.25);
  z-index: 2;
  transition: left 0.5s ease;
}

.original-marker {
  background: #64748b;
}

.recalibrated-marker {
  background: var(--color-primary);
}

.marker-label {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.65rem;
  font-weight: 600;
  white-space: nowrap;
  color: var(--color-text-secondary);
}

/* Original label sits ABOVE the bar */
.original-marker .marker-label {
  bottom: calc(100% + 6px);
  color: #64748b;
}

/* Recalibrated label sits BELOW the bar */
.recalibrated-marker .marker-label {
  top: calc(100% + 6px);
  color: var(--color-primary);
}

.risk-bar-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 1.5rem;
  font-size: 0.7rem;
  color: var(--color-text-secondary);
}

/* Details */
.result-details {
  margin-top: 1.5rem;
  background: #f8fafc;
  border-radius: var(--radius-sm);
  padding: 1rem 1.25rem;
  border: 1px solid var(--color-border);
}

.detail-row {
  display: flex;
  justify-content: space-between;
  padding: 0.4rem 0;
  font-size: 0.85rem;
}

.detail-row + .detail-row {
  border-top: 1px solid var(--color-border);
}

.detail-label {
  color: var(--color-text-secondary);
}

.detail-value {
  font-weight: 600;
  color: var(--color-text);
}

/* ---- Info Section ---- */
.info-section {
  margin-top: 2rem;
  padding: 1.5rem 2rem;
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border);
}

.info-section h3 {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
}

.info-section p {
  font-size: 0.875rem;
  color: var(--color-text-secondary);
  line-height: 1.65;
}

.info-models {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-top: 1.25rem;
}

.info-model {
  padding: 1rem;
  background: #f8fafc;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
}

.info-model h4 {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--color-primary);
  margin-bottom: 0.3rem;
}

.info-model p {
  font-size: 0.78rem;
  line-height: 1.5;
}

.info-link {
  display: inline-block;
  margin-top: 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-primary);
  text-decoration: none;
  transition: color var(--transition);
}

.info-link:hover {
  color: var(--color-primary-hover);
  text-decoration: underline;
}

/* ---- Footer ---- */
.footer {
  text-align: center;
  margin-top: 2rem;
  font-size: 0.78rem;
  color: var(--color-text-secondary);
}

.footer-credit {
  margin-top: 0.4rem;
  font-size: 0.72rem;
}

.footer-credit a {
  color: var(--color-primary);
  text-decoration: none;
  font-weight: 500;
}

.footer-credit a:hover {
  text-decoration: underline;
}

/* ---- Error state ---- */
.input-error {
  border-color: var(--color-danger) !important;
  box-shadow: 0 0 0 3px var(--color-danger-light) !important;
}

.error-message {
  color: var(--color-danger);
  font-size: 0.78rem;
  margin-top: 0.3rem;
  font-weight: 500;
}

/* ---- Risk Category Badges ---- */
.risk-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.2rem 0.6rem;
  border-radius: 99px;
  margin-top: 0.5rem;
  letter-spacing: 0.02em;
}

.badge-low {
  background: #d1fae5;
  color: #065f46;
}

.badge-borderline {
  background: #fef3c7;
  color: #92400e;
}

.badge-intermediate {
  background: #ffedd5;
  color: #9a3412;
}

.badge-high {
  background: #fee2e2;
  color: #991b1b;
}

/* ---- Change Summary ---- */
.change-summary {
  margin-top: 1.25rem;
  padding: 0.75rem 1rem;
  background: #f8fafc;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  font-size: 0.875rem;
  text-align: center;
  color: var(--color-text);
}

.change-arrow {
  font-size: 1.1rem;
  font-weight: 700;
}

.change-up {
  color: var(--color-danger);
}

.change-down {
  color: var(--color-success);
}

.change-neutral {
  color: var(--color-text-secondary);
}

.change-relative {
  color: var(--color-text-secondary);
  font-size: 0.8rem;
}

/* ---- Comparison Table Section ---- */
.comparison-section {
  margin-top: 2rem;
  padding: 1.5rem 2rem;
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--color-border);
}

.comparison-section.hidden {
  display: none;
}

.comparison-section h3 {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.comparison-subtitle {
  font-size: 0.8rem;
  color: var(--color-text-secondary);
  margin-bottom: 0.5rem;
}

.comparison-note {
  font-size: 0.75rem;
  color: var(--color-text-secondary);
  background: var(--color-warning-light);
  border: 1px solid #fde68a;
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  margin-bottom: 1rem;
  line-height: 1.5;
}

.comparison-note strong {
  color: var(--color-warning);
}

.comparison-table-wrapper {
  overflow-x: auto;
}

.comparison-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.comparison-table thead th {
  text-align: left;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-secondary);
  padding: 0.5rem 0.75rem;
  border-bottom: 2px solid var(--color-border);
}

.comparison-table tbody td {
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}

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

.comp-model {
  font-weight: 600;
  white-space: nowrap;
}

.comparison-table .risk-badge {
  margin-top: 0;
  font-size: 0.65rem;
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
  .container {
    max-width: 640px;
    padding: 1rem 0.75rem 2rem;
  }

  .main-layout {
    grid-template-columns: 1fr;
  }

  .card-results {
    position: static;
  }

  .card {
    padding: 1.5rem;
  }

  .header h1 {
    font-size: 1.35rem;
  }

  .info-models {
    grid-template-columns: 1fr;
  }

  .results-grid {
    flex-direction: column;
    gap: 0.5rem;
  }

  .result-arrow {
    transform: rotate(90deg);
  }

  /* Modal mobile fixes */
  .modal-overlay {
    padding: 0.5rem;
    align-items: flex-start;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .modal {
    max-width: 100%;
    margin-top: 1rem;
    margin-bottom: 1rem;
    max-height: none;
  }

  .modal-header {
    padding: 1.25rem 1rem 1rem;
  }

  .modal-header h2 {
    font-size: 1.15rem;
  }

  .modal-tagline {
    font-size: 0.8rem;
  }

  .modal-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
  }

  .modal-icon svg {
    width: 22px;
    height: 22px;
  }

  .modal-body {
    padding: 1rem;
  }

  .modal-body h3 {
    font-size: 0.9rem;
  }

  .modal-body > p {
    font-size: 0.8rem;
  }

  .modal-list li {
    font-size: 0.8rem;
  }

  .modal-list-icon {
    font-size: 1rem;
  }

  .modal-disclaimer {
    font-size: 0.74rem;
  }

  .modal-footer {
    flex-direction: column;
    gap: 0.75rem;
    padding: 0.85rem 1rem 1rem;
  }

  .modal-checkbox-label {
    font-size: 0.75rem;
  }

  .btn-modal {
    width: 100%;
    text-align: center;
    padding: 0.6rem 1rem;
    font-size: 0.85rem;
  }
}
