:root {
  --ci-primary: #0f6e6e;
  --ci-primary-dark: #0a4f4f;
  --ci-accent: #2e86ab;
  --ci-bg: #f4f7f8;
  --ci-critical: #c0392b;
  --ci-warning: #d68910;
  --ci-info: #2e86ab;
  --ci-success: #1e8449;
  --ci-text: #1f2d2d;
  --ci-muted: #5f7373;
  --ci-border: #dfe7e7;
}

* { box-sizing: border-box; }

body {
  background-color: var(--ci-bg);
  color: var(--ci-text);
  font-family: "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.navbar-ci {
  background: linear-gradient(135deg, var(--ci-primary-dark), var(--ci-primary));
}

.navbar-ci .navbar-brand {
  font-weight: 700;
  letter-spacing: 0.3px;
  color: #fff !important;
}

.navbar-ci .navbar-text,
.navbar-ci .nav-link {
  color: #eaf6f6 !important;
}

.hero-panel {
  background: linear-gradient(135deg, var(--ci-primary-dark) 0%, var(--ci-primary) 55%, var(--ci-accent) 100%);
  color: #fff;
  border-radius: 16px;
  padding: 3rem 2.5rem;
}

.hero-panel h1 {
  font-weight: 700;
}

.card-ci {
  border: 1px solid var(--ci-border);
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 2px 10px rgba(15, 110, 110, 0.06);
}

.card-ci .card-header {
  background-color: #fff;
  border-bottom: 1px solid var(--ci-border);
  font-weight: 600;
  border-radius: 14px 14px 0 0 !important;
}

.step-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--ci-primary);
  color: #fff;
  font-weight: 700;
  margin-right: 0.6rem;
  flex-shrink: 0;
}

.risk-badge {
  font-size: 0.85rem;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  font-weight: 600;
}

.risk-badge.High { background-color: #fdecea; color: var(--ci-critical); border: 1px solid #f5c6c0; }
.risk-badge.Normal { background-color: #eafaf1; color: var(--ci-success); border: 1px solid #bfe8cf; }

.alert-card {
  border-left: 5px solid var(--ci-info);
  border-radius: 8px;
  background: #fff;
  padding: 1rem 1.1rem;
  margin-bottom: 0.85rem;
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}

.alert-card.critical { border-left-color: var(--ci-critical); }
.alert-card.warning { border-left-color: var(--ci-warning); }
.alert-card.info { border-left-color: var(--ci-info); }

.severity-tag {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 700;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
}

.severity-tag.critical { background-color: #fdecea; color: var(--ci-critical); }
.severity-tag.warning { background-color: #fdf3e3; color: var(--ci-warning); }
.severity-tag.info { background-color: #e8f2fb; color: var(--ci-info); }

.chart-list-item {
  border-bottom: 1px dashed var(--ci-border);
  padding: 0.5rem 0;
}
.chart-list-item:last-child { border-bottom: none; }

.patient-tile {
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.patient-tile:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(15, 110, 110, 0.15);
}
.patient-tile.active {
  border-color: var(--ci-primary);
  box-shadow: 0 0 0 2px var(--ci-primary) inset;
}

.score-gauge {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  font-weight: 700;
  color: #fff;
  margin: 0 auto;
}

.text-muted-ci { color: var(--ci-muted); }

.btn-ci-primary {
  background-color: var(--ci-primary);
  border-color: var(--ci-primary);
  color: #fff;
}
.btn-ci-primary:hover {
  background-color: var(--ci-primary-dark);
  border-color: var(--ci-primary-dark);
  color: #fff;
}

.badge-fhir {
  background-color: #e8f2fb;
  color: var(--ci-accent);
  font-weight: 600;
  border-radius: 6px;
  padding: 0.25rem 0.5rem;
  font-size: 0.7rem;
}

.footer-ci {
  color: var(--ci-muted);
  font-size: 0.85rem;
}

.validation-note {
  font-size: 0.8rem;
  color: var(--ci-muted);
  padding-left: 1rem;
  border-left: 2px solid var(--ci-border);
  margin-bottom: 0.35rem;
}

.spinner-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

/* ---- Dashboard stat cards ---- */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.9rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  cursor: pointer;
  border: none;
  border-radius: 14px;
  padding: 1.1rem 1.2rem;
  color: #fff;
  position: relative;
  overflow: hidden;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 3px 10px rgba(0,0,0,0.08);
}
.stat-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 22px rgba(0,0,0,0.16);
}
.stat-card:active { transform: translateY(-1px); }

.stat-card .stat-icon {
  font-size: 1.5rem;
  opacity: 0.85;
}
.stat-card .stat-value {
  font-size: 2rem;
  font-weight: 800;
  line-height: 1.1;
  margin-top: 0.35rem;
}
.stat-card .stat-label {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  opacity: 0.9;
  margin-top: 0.15rem;
}
.stat-card .stat-arrow {
  position: absolute;
  right: 0.9rem;
  bottom: 0.8rem;
  font-size: 1.1rem;
  opacity: 0.55;
}

.stat-card.stat-patients   { background: linear-gradient(135deg, #0f6e6e, #2e86ab); }
.stat-card.stat-conditions { background: linear-gradient(135deg, #b9770e, #d68910); }
.stat-card.stat-medications{ background: linear-gradient(135deg, #6c3483, #9b59b6); }
.stat-card.stat-allergies  { background: linear-gradient(135deg, #922b21, #c0392b); }
.stat-card.stat-observations{ background: linear-gradient(135deg, #148f77, #1abc9c); }
.stat-card.stat-encounters { background: linear-gradient(135deg, #1a5276, #2e86ab); }
.stat-card.stat-careplans  { background: linear-gradient(135deg, #196f3d, #27ae60); }
.stat-card.stat-alerts     { background: linear-gradient(135deg, #922b21, #e74c3c); }

/* ---- Stats scope label (shown when cards are scoped to a search/patient) ---- */
.stats-scope-label {
  background: #eaf6f6;
  border: 1px solid #cfe9e8;
  color: var(--ci-primary-dark);
  border-radius: 10px;
  padding: 0.5rem 0.9rem;
  font-size: 0.85rem;
  display: inline-block;
}
.stats-scope-label a {
  color: var(--ci-primary-dark);
  font-weight: 600;
  text-decoration: underline;
}

/* ---- Scrollable patient list ---- */
.patient-list-scroll {
  max-height: 300px;
  overflow-y: auto;
  padding-right: 4px;
}

/* ---- Scrollable chart resource lists (Conditions, Allergies, Medications,
   Observations, Encounters panels on the patient chart) — each box scrolls
   independently once it has more than ~3 items, instead of the card
   growing to fit everything. !important guards against any other rule
   (e.g. a card-ci default) silently overriding the height/overflow. ---- */
.chart-list-scroll {
  max-height: 190px !important;
  overflow-y: auto !important;
  padding-right: 6px;
  display: block;
}
.chart-list-scroll::-webkit-scrollbar,
.patient-list-scroll::-webkit-scrollbar {
  width: 7px;
}
.chart-list-scroll::-webkit-scrollbar-track,
.patient-list-scroll::-webkit-scrollbar-track {
  background: transparent;
}
.chart-list-scroll::-webkit-scrollbar-thumb,
.patient-list-scroll::-webkit-scrollbar-thumb {
  background: var(--ci-border);
  border-radius: 999px;
}
.chart-list-scroll::-webkit-scrollbar-thumb:hover,
.patient-list-scroll::-webkit-scrollbar-thumb:hover {
  background: var(--ci-primary);
}

/* ---- Resource browser (all-patients table view) ---- */
.resource-browser-table th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--ci-muted);
  border-bottom: 2px solid var(--ci-border);
}
.resource-browser-table td {
  vertical-align: middle;
}
.resource-browser-table tr:hover td {
  background-color: #f4faf9;
}
.patient-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: #eaf6f6;
  color: var(--ci-primary-dark);
  border-radius: 999px;
  padding: 0.2rem 0.6rem;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}
.patient-chip:hover { background: #d7ecec; }
