:root {
  --bs-primary: #00BFFF;
  --bs-primary-rgb: 0, 191, 255;
  --bs-primary-dark: #009ACD;
  --bs-primary-light: rgba(0, 191, 255, 0.08);
  --sidebar-width: 260px;
  --sidebar-bg: #0f1923;
  --sidebar-hover: rgba(0, 191, 255, 0.1);
  --sidebar-active: rgba(0, 191, 255, 0.18);
  --sidebar-text: rgba(255,255,255,0.65);
  --sidebar-text-active: #fff;
  --topbar-height: 60px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: #f0f4f8;
  color: #1a2332;
  overflow-x: hidden;
}

/* ─── LOGIN SCREEN ───
   Full-screen overlay displayed when the user is not authenticated.
   Contains the animated background shapes, hospital brand column,
   and the login card. Uses gradient background with floating
   radial-gradient ellipses for visual depth. */
#login-screen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: linear-gradient(135deg, #f0f4f8 0%, #e8edf5 50%, #f5f7fa 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.login-bg {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 20% 50%, rgba(0, 191, 255, 0.12) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 20%, rgba(0, 191, 255, 0.08) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 80%, rgba(0, 191, 255, 0.06) 0%, transparent 50%);
}

.login-bg-shapes {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}
.shape {
  position: absolute;
  border-radius: 50%;
  background: rgba(0, 191, 255, 0.08);
  animation: float 20s ease-in-out infinite;
}
.shape-1 { width: 500px; height: 500px; top: -150px; right: -100px; animation-delay: 0s; }
.shape-2 { width: 300px; height: 300px; bottom: -50px; left: -80px; animation-delay: -5s; }
.shape-3 { width: 200px; height: 200px; top: 40%; left: 60%; animation-delay: -10s; }

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

.login-card {
  background: rgba(255, 255, 255, 0.97);
  border-radius: 20px;
  padding: 2.5rem;
  box-shadow:
    0 20px 60px rgba(0, 0, 0, 0.3),
    0 8px 24px rgba(0, 0, 0, 0.15);
  position: relative;
  animation: loginFadeIn 0.6s ease-out;
  backdrop-filter: blur(20px);
}

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

.login-logo {
  width: 72px;
  height: 72px;
  border-radius: 20px;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
  overflow: hidden;
  padding: 10px;
}
.login-logo-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.input-icon-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}
.input-icon-wrapper .input-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: #adb5bd;
  font-size: 1.1rem;
  z-index: 2;
  transition: color 0.2s;
}
.input-icon-wrapper .form-control {
  padding-left: 42px;
  padding-right: 44px;
  height: 50px;
  font-size: 0.95rem;
  background: #f8f9fc;
  border: 2px solid #e9edf2;
  border-radius: 12px;
  transition: all 0.25s;
}
.input-icon-wrapper .form-control:focus {
  background: #fff;
  border-color: #00BFFF;
  box-shadow: 0 0 0 4px rgba(0, 191, 255, 0.12);
}
.input-icon-wrapper .form-control:focus ~ .input-icon,
.input-icon-wrapper .form-control:focus + .input-icon {
  color: #00BFFF;
}

.password-toggle {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: #adb5bd;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  z-index: 2;
  font-size: 1.1rem;
}
.password-toggle:hover {
  background: #f0f0f0;
  color: #495057;
}

.btn-login {
  height: 50px;
  font-size: 1rem;
  border-radius: 12px !important;
  transition: all 0.25s;
  position: relative;
  overflow: hidden;
}
.btn-login:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 191, 255, 0.35);
}
.btn-login:active {
  transform: translateY(0);
}

#login-screen .form-label {
  font-weight: 600;
  font-size: 0.85rem;
  color: #495057;
  margin-bottom: 0.5rem;
}

#login-screen .text-muted {
  color: #8a94a6 !important;
}

/* ─── LOGIN BRAND ───
   Left-column hospital branding with logo, institution name,
   tagline ("We value life more than anything else."), and three
   feature badges (Secure & Reliable, Fast Results, Trend Analysis). */
.login-brand {
  color: #1a2332;
  text-align: center;
  padding: 2rem;
  animation: loginFadeIn 0.6s ease-out;
}
.login-brand-logo {
  width: 100px;
  height: 100px;
  border-radius: 28px;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1.5rem;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.12);
  overflow: hidden;
  padding: 12px;
}
.login-brand-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.login-brand-name {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: 0.5px;
  margin-bottom: 0.25rem;
}
.login-brand-sub {
  font-size: 1rem;
  color: #5a6a7e;
  font-weight: 500;
  margin-bottom: 0.5rem;
}
.login-brand-tagline {
  font-size: 0.95rem;
  color: #8a94a6;
  line-height: 1.6;
  margin-bottom: 2.5rem;
}
.login-brand-features {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}
.brand-feature {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.9rem;
  color: #6c7a8e;
  transition: color 0.2s;
}
.brand-feature i { font-size: 1.1rem; }
.brand-feature:hover { opacity: 0.9; }

/* ─── TWO-COLUMN RESPONSIVE: login layout collapses to single column on mobile ─── */
@media (max-width: 991.98px) {
  .login-card {
    max-width: 420px;
    margin: 0 auto;
  }
}

.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ─── SIDEBAR ───
   Fixed left navigation panel with hospital logo header, nav link
   groups (Main, Quick Actions, System), and a user footer with
   avatar, name, role badge, and logout button. Uses dark theme
   (--sidebar-bg: #0f1923) with primary-color hover/active states.
   The .chief-only class hides links from non-chief users via JS. */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  z-index: 1040;
  transition: transform 0.3s ease;
}
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1035;
}

.sidebar-header {
  padding: 1.25rem 1.25rem 0.75rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.sidebar-logo-icon, .sidebar-logo-img {
  font-size: 1.6rem;
  color: #00BFFF;
}
.sidebar-logo-img {
  width: 36px;
  height: 36px;
  object-fit: contain;
}
.sidebar-brand-text {
  font-size: 1.3rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: 0.5px;
}
.sidebar-brand-sub {
  width: 100%;
  font-size: 0.7rem;
  color: rgba(255,255,255,0.4);
  letter-spacing: 0.3px;
  margin-top: -0.25rem;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.75rem 0.75rem;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.08) transparent;
  transition: scrollbar-color 0.3s;
}
.sidebar-nav:hover {
  scrollbar-color: rgba(255,255,255,0.2) transparent;
}
.sidebar-nav::-webkit-scrollbar {
  width: 4px;
}
.sidebar-nav::-webkit-scrollbar-track {
  background: transparent;
}
.sidebar-nav::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.08);
  border-radius: 4px;
  transition: background 0.3s;
}
.sidebar-nav:hover::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.2);
}
.sidebar-nav::-webkit-scrollbar-thumb:hover {
  background: rgba(255,255,255,0.35);
}
.sidebar-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: rgba(255,255,255,0.3);
  padding: 0.75rem 0.75rem 0.4rem;
  font-weight: 600;
}
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.85rem;
  margin: 2px 0;
  color: var(--sidebar-text);
  text-decoration: none;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.15s;
  cursor: pointer;
}
.sidebar-link i { font-size: 1.15rem; width: 22px; text-align: center; }
.sidebar-link:hover {
  background: var(--sidebar-hover);
  color: var(--sidebar-text-active);
}
.sidebar-link.active {
  background: var(--sidebar-active);
  color: #00BFFF;
  font-weight: 600;
}

.sidebar-footer {
  padding: 0.75rem;
  border-top: 1px solid rgba(255,255,255,0.06);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.sidebar-user {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.65rem;
}
.sidebar-user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(0, 191, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #00BFFF;
  font-size: 1rem;
}
.sidebar-user-info {
  line-height: 1.2;
}
.sidebar-user-name {
  color: #fff;
  font-size: 0.82rem;
  font-weight: 600;
}
.sidebar-user-role {
  color: rgba(255,255,255,0.4);
  font-size: 0.7rem;
}
.sidebar-logout-btn {
  background: none;
  border: none;
  color: rgba(255,255,255,0.4);
  font-size: 1.2rem;
  padding: 0.4rem;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
}
.sidebar-logout-btn:hover { color: #ef4444; background: rgba(239,68,68,0.15); }

/* ─── MAIN AREA ───
   Flex column offset to the right of the sidebar (260px).
   Contains the topbar and scrollable main-content area. */
.main-area {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ─── TOPBAR ───
   Sticky header bar pinned at the top of the main area. Shows
   the hamburger toggle (mobile), the page title (auto-updated),
   and the current user's name. Uses frosted-glass effect with
   backdrop-filter for a modern look. */
.topbar {
  height: var(--topbar-height);
  background: #fff;
  border-bottom: 1px solid #e9edf2;
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  position: sticky;
  top: 0;
  z-index: 1020;
}
.topbar-toggle {
  background: none;
  border: none;
  font-size: 1.4rem;
  color: #6c757d;
  padding: 0.25rem 0.5rem;
  margin-right: 1rem;
  border-radius: 8px;
  cursor: pointer;
  display: none;
}
.topbar-toggle:hover { background: #f0f0f0; }
.topbar-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: #1a2332;
  flex: 1;
}
.topbar-right { display: flex; align-items: center; }
.topbar-user {
  font-size: 0.85rem;
  color: #6c757d;
  font-weight: 500;
}

/* ─── MAIN CONTENT: padded content area below topbar ─── */
.main-content {
  padding: 1.5rem;
  flex: 1;
  display: flex;
  flex-direction: column;
}
.section-content:not(.d-none) {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* ─── BUTTONS: custom primary/outline-primary color overrides ─── */
.btn-primary {
  --bs-btn-bg: #00BFFF;
  --bs-btn-border-color: #00BFFF;
  --bs-btn-hover-bg: #009ACD;
  --bs-btn-hover-border-color: #009ACD;
  --bs-btn-active-bg: #0080A0;
  --bs-btn-active-border-color: #0080A0;
}
.btn-outline-primary {
  --bs-btn-color: #00BFFF;
  --bs-btn-border-color: #00BFFF;
  --bs-btn-hover-bg: #00BFFF;
  --bs-btn-hover-border-color: #00BFFF;
  --bs-btn-active-bg: #009ACD;
}
.text-primary { color: #00BFFF !important; }
.bg-primary { background-color: #00BFFF !important; }
.border-primary { border-color: #00BFFF !important; }
.form-check-input:checked { background-color: #00BFFF; border-color: #00BFFF; }
.form-control:focus, .form-select:focus {
  border-color: #00BFFF;
  box-shadow: 0 0 0 0.2rem rgba(0, 191, 255, 0.25);
}

/* ─── CARDS: general card and stat-card styles with hover effects ─── */
.card {
  border: none;
  border-radius: 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.04), 0 4px 16px rgba(0,0,0,0.04);
  transition: transform 0.2s, box-shadow 0.2s;
}

.stat-card {
  border-radius: 16px;
  padding: 1.5rem;
  transition: transform 0.2s;
}
.stat-card:hover { transform: translateY(-2px); }
.stat-card .stat-icon {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}
.stat-card .stat-number { font-size: 2rem; font-weight: 700; line-height: 1; }
.stat-card .stat-label { font-size: 0.85rem; opacity: 0.8; margin-top: 0.25rem; }

/* ─── TABLES: styled table headers and rows ─── */
.table { margin-bottom: 0; }
.table th {
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #6c757d;
  background: #f8f9fc;
  border-bottom: 2px solid #e9ecef;
  padding: 0.85rem 1rem;
}
.table td { padding: 0.85rem 1rem; vertical-align: middle; border-bottom: 1px solid #f0f0f0; }
.table-hover tbody tr:hover { background: var(--bs-primary-light); }

/* ─── TREND CARDS ───
   Color-coded cards for trend analysis results:
     - green left-border: normal / no intervention needed
     - yellow left-border: slight deviation, monitor
     - orange left-border: moderate deviation, follow-up
     - red left-border: critical, immediate attention
   The .trend-arrow class rotates based on direction enum. */
.trend-card {
  border-left: 4px solid #dee2e6;
  transition: box-shadow 0.2s;
  margin-bottom: 1rem;
}
.trend-card:hover { box-shadow: 0 4px 20px rgba(0,0,0,0.08); }
.trend-yes { border-left-color: #dc3545; }
.trend-monitor { border-left-color: #ffc107; }
.trend-no { border-left-color: #198754; }
.overall-yes { border-left: 5px solid #dc3545; background: linear-gradient(135deg, #fff5f5 0%, #fff 100%); }
.overall-monitor { border-left: 5px solid #ffc107; background: linear-gradient(135deg, #fffef5 0%, #fff 100%); }
.overall-no { border-left: 5px solid #198754; background: linear-gradient(135deg, #f5fff7 0%, #fff 100%); }

.intervention-badge {
  display: inline-block;
  padding: 0.35em 0.8em;
  border-radius: 50px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.3px;
}
.intervention-yes { background: #fce4ec; color: #c62828; }
.intervention-monitor { background: #fff8e1; color: #f57f17; }
.intervention-no { background: #e8f5e9; color: #2e7d32; }

.trend-arrow { font-size: 1.2rem; font-weight: 700; }

/* ─── CHARTS: chart.js container sizing ─── */
.chart-container { position: relative; height: 200px; }

/* ─── FORMS: rounded inputs with custom focus border ─── */
.form-control, .form-select {
  border-radius: 10px;
  padding: 0.6rem 1rem;
  border: 1.5px solid #e2e8f0;
}
.form-control:focus, .form-select:focus { border-color: #00BFFF; }

/* ─── MODALS: rounded modal content with standard padding ─── */
.modal-content { border-radius: 16px; }
.modal-header { padding: 1.25rem 1.5rem 0 1.5rem; }
.modal-body { padding: 1rem 1.5rem; }
.modal-footer { padding: 0 1.5rem 1.25rem 1.5rem; }

/* ─── TOAST: notification toast styling ─── */
.toast { border-radius: 12px; border: none; box-shadow: 0 4px 20px rgba(0,0,0,0.12); }

/* ─── PATIENT HEADER: gradient banner showing patient name and info ─── */
.patient-header-card {
  background: linear-gradient(135deg, #00BFFF 0%, #009ACD 100%);
  color: #fff;
  border-radius: 16px;
  padding: 1.5rem 2rem;
}

/* ─── SEARCH: search box with icon overlay ─── */
.search-box { position: relative; }
.search-box .bi-search { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: #adb5bd; }
.search-box input { padding-left: 38px; }

/* ─── ANIMATIONS: fade-in for section content on navigation ─── */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
.section-content:not(.d-none) { animation: fadeIn 0.25s ease-out; }

/* ─── RESPONSIVE ───
   Mobile breakpoints: sidebar slides off-screen (left: -260px),
   shown by toggling .open class. Main area fills full width.
   Stat cards and tables stack vertically on small screens.
   The login layout collapses to single-column on <992px. */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar-overlay.show {
    display: block;
  }
  .main-area {
    margin-left: 0;
  }
  .topbar-toggle {
    display: inline-flex;
  }
  .stat-card { margin-bottom: 0.75rem; }
  .stat-card .stat-number { font-size: 1.5rem; }
  .main-content { padding: 1rem; }
}

/* ─── HORIZONTAL TABLE SCROLLING ───
   Give tables a minimum width so wide tables scroll horizontally inside
   their scroll containers (.table-scroll / .table-responsive) instead of
   squeezing columns together. Unconditional so it works on every viewport
   and screen size; on desktop the containers are wider than the floor so
   nothing changes. */
.table-scroll table {
  min-width: 720px;
}
.table-responsive table {
  min-width: 600px;
}

/* Inside scrollable modals (.modal-dialog-scrollable), the modal-body is
   already the vertical scroller. Let the paginated table handle only the
   horizontal overflow so users don't see two stacked vertical scrollbars. */
.modal .table-scroll {
  max-height: none !important;
  overflow-y: visible !important;
}

/* Flex ancestors must be allowed to shrink to the viewport width.
   Without this, min-width:auto on flex items lets a wide table expand the
   whole page past the screen, and body{overflow-x:hidden} then silently
   clips it — no scrollbar appears anywhere. Resetting min-width:0 keeps
   the layout pinned to the viewport so the .table-scroll overflow
   container does the scrolling instead. */
.main-area,
.main-content,
.section-content,
.section-content > div,
.section-content .card,
.section-content .card-body,
.section-content .card-body > div,
.portal-layout,
.portal-main {
  min-width: 0;
}

@media (max-width: 991.98px) {
  .table-scroll,
  .table-responsive {
    -webkit-overflow-scrolling: touch;
  }
}

@media (min-width: 769px) {
  .sidebar {
    transform: translateX(0) !important;
  }
  .sidebar-overlay { display: none !important; }
}

/* ─── CATEGORY PILLS ───
   Hover-visible edit button on category pills. When the user hovers
   over a pill, the small pencil/edit icon fades in at the top-left
   corner, allowing quick reassignment of physician or room. */
.category-pill .pill-edit {
  z-index: 2;
  top: -6px;
  left: -6px;
  background: #00BFFF;
  color: #fff;
  border: 2px solid #fff;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  font-size: 10px;
  line-height: 1;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
  transition: transform 0.15s;
}
.category-pill .pill-edit:hover {
  transform: scale(1.15);
  background: #0095cc;
}

/* ─── DEVELOPER-ONLY ───
   Hidden by default, toggled visible by JS for developer role users. */
.developer-only { display: none; }

/* ─── TRIAL BLOCKED OVERLAY ───
   Full-screen overlay shown when the trial expires. Blocks all interaction
   for non-developer users. Same visual style as the login screen. */
#trial-blocked {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: linear-gradient(135deg, #f0f4f8 0%, #e8edf5 50%, #f5f7fa 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.trial-blocked-bg {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 20% 50%, rgba(220, 53, 69, 0.08) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 20%, rgba(220, 53, 69, 0.05) 0%, transparent 50%);
}
.trial-countdown-display {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 1rem;
  background: #1a2332;
  border-radius: 16px;
  margin: 0 auto;
  max-width: 360px;
}
.countdown-digit {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  min-width: 60px;
  font-size: 2.2rem;
  font-weight: 700;
  color: #fff;
  background: rgba(255,255,255,0.08);
  border-radius: 10px;
  padding: 6px 8px;
}
.countdown-digit small {
  font-size: 0.7rem;
  font-weight: 400;
  color: rgba(255,255,255,0.55);
  margin-top: -2px;
}
.countdown-sep {
  font-size: 2rem;
  font-weight: 700;
  color: rgba(255,255,255,0.35);
  line-height: 1;
}
