/* E-MedCareTech Clinical Styling System */
@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@300;400;500;600;700;800&family=Inter:wght@300;400;500;600;700&display=swap');

:root {
  --primary-navy: #0A3981;
  --primary-blue: #0052CC;
  --primary-cyan: #00C2CB;
  --primary-cyan-light: #E0F7FA;
  --primary-cyan-hover: #00A8B0;
  
  --bg-page: #F8FAFC;
  --bg-card: #FFFFFF;
  --bg-subtle: #F1F5F9;
  
  --border-color: #E2E8F0;
  --border-focus: #00C2CB;
  
  --text-main: #0F172A;
  --text-muted: #64748B;
  --text-light: #94A3B8;
  
  --brand-gradient: linear-gradient(135deg, #00C2CB 0%, #0052CC 100%);
  --brand-gradient-subtle: linear-gradient(135deg, rgba(0, 194, 203, 0.08) 0%, rgba(0, 82, 204, 0.08) 100%);
  --sidebar-width: 260px;
  --header-height: 70px;
}

* {
  box-sizing: border-box;
}

body {
  font-family: 'Plus Jakarta Sans', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--bg-page);
  color: var(--text-main);
  margin: 0;
  padding: 0;
  font-size: 0.9375rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: #F1F5F9;
}
::-webkit-scrollbar-thumb {
  background: #CBD5E1;
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: #94A3B8;
}

/* Layout */
.app-container {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.app-sidebar {
  width: var(--sidebar-width);
  background-color: #FFFFFF;
  border-right: 1px solid var(--border-color);
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 1030;
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease;
}

.sidebar-brand {
  height: var(--header-height);
  display: flex;
  align-items: center;
  padding: 0 1.25rem;
  border-bottom: 1px solid var(--border-color);
  text-decoration: none;
  gap: 0.75rem;
}

.sidebar-logo {
  height: 42px;
  width: auto;
  object-fit: contain;
}

.sidebar-title {
  font-weight: 800;
  font-size: 1.15rem;
  color: var(--primary-navy);
  letter-spacing: -0.02em;
}

.sidebar-title span {
  color: var(--primary-cyan);
}

.sidebar-menu {
  padding: 1.25rem 0.85rem;
  overflow-y: auto;
  flex-grow: 1;
}

.menu-category {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-light);
  padding: 0.5rem 0.75rem;
  margin-top: 0.75rem;
}

.nav-item {
  margin-bottom: 0.25rem;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.65rem 0.85rem;
  border-radius: 0.5rem;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.9rem;
  transition: all 0.2s ease;
  text-decoration: none;
}

.nav-link i {
  font-size: 1.1rem;
  width: 1.5rem;
  text-align: center;
  color: #94A3B8;
  transition: color 0.2s;
}

.nav-link:hover {
  background-color: var(--bg-subtle);
  color: var(--primary-blue);
}

.nav-link:hover i {
  color: var(--primary-blue);
}

.nav-link.active {
  background: var(--brand-gradient-subtle);
  color: var(--primary-navy);
  font-weight: 600;
  border-left: 3.5px solid var(--primary-cyan);
}

.nav-link.active i {
  color: var(--primary-cyan);
}

.sidebar-user {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border-color);
  background-color: #FFFFFF;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--brand-gradient);
  color: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
  flex-shrink: 0;
}

.user-info {
  flex-grow: 1;
  min-width: 0;
}

.user-name {
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role-badge {
  font-size: 0.7rem;
  padding: 0.15rem 0.5rem;
  border-radius: 9999px;
  font-weight: 600;
  display: inline-block;
}

/* Main Content Wrapper */
.app-main {
  margin-left: var(--sidebar-width);
  flex-grow: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Header */
.app-header {
  height: var(--header-height);
  background-color: #FFFFFF;
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 1020;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.75rem;
}

.header-search {
  position: relative;
  max-width: 380px;
  width: 100%;
}

.header-search input {
  width: 100%;
  padding: 0.5rem 1rem 0.5rem 2.4rem;
  background-color: var(--bg-subtle);
  border: 1px solid transparent;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  transition: all 0.2s;
}

.header-search input:focus {
  background-color: #FFFFFF;
  border-color: var(--primary-cyan);
  outline: none;
  box-shadow: 0 0 0 3px rgba(0, 194, 203, 0.15);
}

.header-search i {
  position: absolute;
  left: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-light);
}

/* Content Area */
.app-body {
  padding: 1.75rem;
  flex-grow: 1;
}

/* Cards */
.card-med {
  background: #FFFFFF;
  border: 1px solid var(--border-color);
  border-radius: 0.75rem;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04);
  transition: transform 0.2s, box-shadow 0.2s;
  overflow: hidden;
}

.card-med:hover {
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.06);
}

.card-med-header {
  padding: 1.15rem 1.35rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: #FFFFFF;
}

.card-med-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--primary-navy);
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.card-med-body {
  padding: 1.35rem;
}

/* Stat Card */
.stat-card {
  background: #FFFFFF;
  border: 1px solid var(--border-color);
  border-radius: 0.85rem;
  padding: 1.35rem;
  position: relative;
  overflow: hidden;
  transition: all 0.2s;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(10, 57, 129, 0.07);
}

.stat-icon {
  width: 50px;
  height: 50px;
  border-radius: 0.65rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
  margin-bottom: 1rem;
}

.stat-value {
  font-size: 1.85rem;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.1;
  margin-bottom: 0.25rem;
}

.stat-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

/* Patient Header Component (Key Point #1) */
.patient-header-card {
  background: #FFFFFF;
  border: 1px solid var(--border-color);
  border-radius: 0.85rem;
  box-shadow: 0 2px 6px rgba(10, 57, 129, 0.05);
  margin-bottom: 1.5rem;
  overflow: hidden;
  position: relative;
}

.patient-header-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: var(--brand-gradient);
}

.patient-header-body {
  padding: 1.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  align-items: center;
}

.patient-avatar-box {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: 3px solid #E0F7FA;
  box-shadow: 0 2px 8px rgba(0, 194, 203, 0.2);
  object-fit: cover;
}

.patient-avatar-fallback {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--brand-gradient);
  color: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  font-weight: 700;
}

.patient-header-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem 2rem;
  margin-top: 0.75rem;
}

.meta-item {
  display: flex;
  flex-direction: column;
}

.meta-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-light);
  font-weight: 600;
}

.meta-val {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-main);
}

/* Clinical Summary Component (Key Point #2) */
.clinical-summary-box {
  background: #FFFFFF;
  border: 1px solid #BFDBFE;
  border-left: 5px solid #0052CC;
  border-radius: 0.65rem;
  padding: 1.25rem;
  margin-bottom: 1.5rem;
}

.alert-danger-clinical {
  background-color: #FEF2F2;
  border: 1px solid #FECACA;
  border-left: 4px solid #EF4444;
  color: #991B1B;
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  font-weight: 500;
}

/* Vital Signs Box */
.vital-tile {
  background: #FFFFFF;
  border: 1px solid var(--border-color);
  border-radius: 0.65rem;
  padding: 1rem;
  text-align: center;
  transition: all 0.2s;
}

.vital-tile:hover {
  border-color: var(--primary-cyan);
  background-color: #FAFCFF;
}

.vital-value {
  font-size: 1.45rem;
  font-weight: 800;
  color: var(--primary-navy);
}

.vital-unit {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
}

.vital-name {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

/* Buttons */
.btn-med-primary {
  background: var(--brand-gradient);
  color: #FFFFFF;
  border: none;
  font-weight: 600;
  padding: 0.55rem 1.25rem;
  border-radius: 0.5rem;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  box-shadow: 0 2px 6px rgba(0, 194, 203, 0.25);
}

.btn-med-primary:hover {
  background: linear-gradient(135deg, #00A8B0 0%, #0047AB 100%);
  color: #FFFFFF;
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(0, 194, 203, 0.35);
}

.btn-med-secondary {
  background: #FFFFFF;
  border: 1px solid var(--border-color);
  color: var(--text-main);
  font-weight: 600;
  padding: 0.55rem 1.15rem;
  border-radius: 0.5rem;
  transition: all 0.2s;
}

.btn-med-secondary:hover {
  background: var(--bg-subtle);
  border-color: #CBD5E1;
  color: var(--primary-navy);
}

/* Top-Right Toast System */
#toast-container {
  position: fixed;
  top: 1.5rem;
  right: 1.5rem;
  z-index: 1090;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-width: 420px;
  width: calc(100% - 3rem);
  pointer-events: none;
}

.med-toast {
  pointer-events: auto;
  background: #FFFFFF;
  border-radius: 0.65rem;
  box-shadow: 0 10px 25px -5px rgba(15, 23, 42, 0.15), 0 8px 10px -6px rgba(15, 23, 42, 0.1);
  padding: 1rem 1.25rem;
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
  border-left: 4.5px solid #00C2CB;
  animation: slideInRight 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  transition: all 0.3s ease;
}

.med-toast.success {
  border-left-color: #10B981;
}

.med-toast.error {
  border-left-color: #EF4444;
}

.med-toast.warning {
  border-left-color: #F59E0B;
}

.med-toast.info {
  border-left-color: #00C2CB;
}

.toast-icon {
  font-size: 1.25rem;
  flex-shrink: 0;
  margin-top: 0.1rem;
}

.med-toast.success .toast-icon { color: #10B981; }
.med-toast.error .toast-icon { color: #EF4444; }
.med-toast.warning .toast-icon { color: #F59E0B; }
.med-toast.info .toast-icon { color: #00C2CB; }

.toast-content {
  flex-grow: 1;
}

.toast-title {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text-main);
  margin-bottom: 0.15rem;
}

.toast-message {
  font-size: 0.84rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.toast-close {
  background: none;
  border: none;
  color: #94A3B8;
  cursor: pointer;
  padding: 0;
  font-size: 1rem;
}

.toast-close:hover {
  color: var(--text-main);
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(100%);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Modals & Scrolling Architecture */
.modal {
  overflow-x: hidden;
  overflow-y: auto;
}

.modal-dialog {
  margin: 1.75rem auto;
  max-height: calc(100vh - 3.5rem);
}

.modal-content {
  border: none;
  border-radius: 0.85rem;
  box-shadow: 0 20px 40px rgba(15, 23, 42, 0.18);
  max-height: calc(100vh - 3.5rem);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Ensure forms inside modal-content behave as flex containers */
.modal-content form,
form.modal-content {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  max-height: calc(100vh - 3.5rem);
  overflow: hidden;
  margin: 0;
}

.modal-header {
  flex-shrink: 0;
  border-bottom: 1px solid var(--border-color);
  padding: 1.15rem 1.5rem;
  background-color: #FFFFFF;
}

.modal-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--primary-navy);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
}

.modal-body {
  padding: 1.5rem;
  overflow-y: auto !important;
  flex: 1 1 auto;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
}

.modal-footer {
  flex-shrink: 0;
  border-top: 1px solid var(--border-color);
  padding: 1rem 1.5rem;
  background-color: #F8FAFC;
  position: sticky;
  bottom: 0;
  z-index: 1055;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
}

/* Form Controls */
.form-label {
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 0.35rem;
}

.form-control, .form-select {
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  padding: 0.55rem 0.85rem;
  font-size: 0.875rem;
  color: var(--text-main);
  transition: all 0.2s;
}

.form-control:focus, .form-select:focus {
  border-color: var(--primary-cyan);
  box-shadow: 0 0 0 3px rgba(0, 194, 203, 0.15);
}

/* Tables */
.table-med {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

.table-med th {
  background-color: #F8FAFC;
  color: var(--text-muted);
  font-weight: 700;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.85rem 1.15rem;
  border-bottom: 1px solid var(--border-color);
}

.table-med td {
  padding: 0.95rem 1.15rem;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.875rem;
  vertical-align: middle;
}

.table-med tr:hover td {
  background-color: #F8FAFC;
}

/* Badges */
.badge-emct {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.25rem 0.65rem;
  border-radius: 9999px;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

/* Abnormal lab highlight (Key Point #7) */
.badge-flag-abnormal, .badge-flag-critical, .badge-flag-high {
  background-color: #FEE2E2;
  color: #991B1B;
  border: 1px solid #FCA5A5;
  font-weight: 700;
  animation: pulse-border 2s infinite;
}

.badge-flag-low {
  background-color: #FEF3C7;
  color: #92400E;
  border: 1px solid #FCD34D;
  font-weight: 700;
}

.badge-flag-normal {
  background-color: #D1FAE5;
  color: #065F46;
  border: 1px solid #A7F3D0;
}

@keyframes pulse-border {
  0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
  70% { box-shadow: 0 0 0 5px rgba(239, 68, 68, 0); }
  100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

/* Responsive */
@media (max-width: 991.98px) {
  .app-sidebar {
    transform: translateX(-100%);
  }
  .app-sidebar.show {
    transform: translateX(0);
  }
  .app-main {
    margin-left: 0;
  }
  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    z-index: 1025;
    display: none;
  }
  .sidebar-backdrop.show {
    display: block;
  }
}

/* ========================================================
   MODAL SCROLLING & ACCESSIBLE STICKY FOOTER ENGINE
   Fixes Bootstrap 5 flexbox/scrolling bugs across all modals
   ======================================================== */

/* Ensure the modal dialog stays safely within the viewport */
.modal-dialog {
  max-height: calc(100vh - 2.5rem);
  margin: 1.25rem auto;
  display: flex;
  flex-direction: column;
}

@media (min-width: 576px) {
  .modal-dialog {
    max-height: calc(100vh - 3rem);
    margin: 1.5rem auto;
  }
}

/* Override Bootstrap 5 .modal-dialog-centered bug which causes max-height: none */
.modal-dialog-centered,
.modal-dialog-centered.modal-dialog-scrollable {
  display: flex !important;
  align-items: center !important;
  min-height: auto !important;
  max-height: calc(100vh - 3rem) !important;
  height: calc(100% - 3rem) !important;
}

/* Modal Content Container (supports both <div class="modal-content"> and <form class="modal-content">) */
.modal-content,
form.modal-content {
  max-height: calc(100vh - 3.5rem) !important;
  height: auto !important;
  display: flex !important;
  flex-direction: column !important;
  overflow: hidden !important;
  border-radius: 0.85rem !important;
  border: 1px solid var(--border-color) !important;
  box-shadow: 0 25px 50px -12px rgba(10, 57, 129, 0.25) !important;
  background-color: #FFFFFF !important;
  width: 100%;
}

/* When <form> is a child inside <div class="modal-content"> */
.modal-content > form {
  display: flex !important;
  flex-direction: column !important;
  max-height: calc(100vh - 3.5rem) !important;
  flex: 1 1 auto !important;
  min-height: 0 !important;
  overflow: hidden !important;
  width: 100%;
}

/* Modal Header: Permanently pinned at top */
.modal-header {
  flex-shrink: 0 !important;
  background-color: #FFFFFF !important;
  border-bottom: 1px solid var(--border-color) !important;
  padding: 1.1rem 1.5rem !important;
  z-index: 1055 !important;
}

.modal-header .modal-title {
  font-weight: 700;
  color: var(--primary-navy);
  font-size: 1.15rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Modal Body: GUARANTEED SMOOTH SCROLLING */
.modal-body {
  overflow-y: auto !important;
  overflow-x: hidden !important;
  flex: 1 1 auto !important;
  min-height: 100px !important;
  max-height: calc(100vh - 12rem) !important;
  padding: 1.5rem !important;
  -webkit-overflow-scrolling: touch;
}

/* Modern custom scrollbar for modal body */
.modal-body::-webkit-scrollbar {
  width: 8px;
}
.modal-body::-webkit-scrollbar-track {
  background: #F1F5F9;
  border-radius: 4px;
}
.modal-body::-webkit-scrollbar-thumb {
  background: #CBD5E1;
  border-radius: 4px;
}
.modal-body::-webkit-scrollbar-thumb:hover {
  background: var(--primary-cyan);
}

/* Modal Footer: Sticky/pinned at the bottom - ALWAYS 100% VISIBLE AND CLICKABLE! */
.modal-footer {
  flex-shrink: 0 !important;
  background-color: #F8FAFC !important;
  border-top: 1px solid var(--border-color) !important;
  padding: 1rem 1.5rem !important;
  position: sticky !important;
  bottom: 0 !important;
  z-index: 1055 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: flex-end !important;
  gap: 0.75rem !important;
  box-shadow: 0 -4px 6px -1px rgba(0, 0, 0, 0.05);
}

/* ==========================================================================
   Clinical Medical History Timeline Component
   ========================================================================== */
.med-timeline {
  position: relative;
  padding-left: 2.75rem;
  margin-left: 0.5rem;
}

.med-timeline::before {
  content: '';
  position: absolute;
  top: 1rem;
  bottom: 1rem;
  left: 11px; /* Center of 24px marker */
  width: 2px;
  background: linear-gradient(180deg, #00C2CB 0%, #0284C7 50%, #CBD5E1 100%);
  border-radius: 2px;
}

.med-timeline-item {
  position: relative;
  margin-bottom: 1.5rem;
}

.med-timeline-item:last-child {
  margin-bottom: 0.25rem;
}

.med-timeline-marker {
  position: absolute;
  left: -2.75rem;
  top: 0.75rem;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #FFFFFF;
  font-size: 0.7rem;
  border: 2px solid #FFFFFF;
  z-index: 2;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.med-timeline-item:hover .med-timeline-marker {
  transform: scale(1.15);
}

.med-timeline-marker.marker-success {
  background-color: #10B981;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.25), 0 2px 6px rgba(16, 185, 129, 0.3);
}

.med-timeline-marker.marker-primary {
  background-color: #0284C7;
  box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.25), 0 2px 6px rgba(2, 132, 199, 0.3);
}

.med-timeline-marker.marker-danger {
  background-color: #EF4444;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.25), 0 2px 6px rgba(239, 68, 68, 0.3);
}

.med-timeline-marker.marker-cyan {
  background-color: #00C2CB;
  box-shadow: 0 0 0 3px rgba(0, 194, 203, 0.25), 0 2px 6px rgba(0, 194, 203, 0.3);
}

.med-timeline-card {
  background-color: #FFFFFF;
  border: 1px solid #E2E8F0;
  border-radius: 0.5rem;
  padding: 1rem 1.25rem;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04);
  transition: all 0.2s ease;
}

.med-timeline-card:hover {
  border-color: #CBD5E1;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
}

