/* =============================================================
   AllMed360SAAS EMR — shared design system
   =============================================================
   Single source of truth for every EMR_* page's "teal medical"
   look (variables, hero banner, stat cards, tables, badges, empty
   states, primary buttons). Loaded once site-wide via header.php —
   individual EMR_* pages should NOT redeclare these; only add
   page-specific classes in their own <style> block.
   ============================================================= */

:root {
  --emr-bg: #f5f8fb;
  --emr-border: #e2e8f0;
  --emr-muted: #64748b;
  --emr-text: #0f172a;
  --emr-primary: #1e6be6;
  --emr-primary-dark: #082352;
  --emr-primary-light: #14b8a6;
  --emr-primary-soft: #ccfbf1;
  --emr-accent: #f59e0b;
  --emr-accent-dark: #d97706;
  --emr-accent-soft: #fef3c7;

  /* Elevation scale (mirrors assets/css/main.css's --shadow-sm/md/lg/xl convention) */
  --emr-shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
  --emr-shadow-sm:
    0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --emr-shadow-md:
    0 6px 16px rgba(15, 23, 42, 0.08), 0 2px 6px rgba(15, 23, 42, 0.05);
  --emr-shadow-lg:
    0 14px 32px rgba(15, 23, 42, 0.12), 0 4px 10px rgba(15, 23, 42, 0.06);
  --emr-shadow-xl: 0 24px 48px rgba(15, 23, 42, 0.16);
  /* Kept for backward compat with pages that still reference these names directly */
  --emr-shadow: var(--emr-shadow-sm);
  --emr-shadow-hover: var(--emr-shadow-md);

  --emr-radius: 14px;
  --emr-radius-sm: 10px;
  --emr-transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1);
}

.emr-page {
  background: var(--emr-bg);
  min-height: calc(100vh - 130px);
  padding: 24px;
}
.emr-page * {
  box-sizing: border-box;
}

/* ---- Hero banner ---- */
.emr-hero {
  background: linear-gradient(
    135deg,
    var(--emr-primary-dark),
    var(--emr-primary) 55%,
    var(--emr-primary-light)
  );
  color: #fff;
  border-radius: 18px;
  padding: 26px 32px;
  box-shadow: 0 10px 32px rgba(13, 148, 136, 0.25);
  position: relative;
  overflow: hidden;
  margin-bottom: 20px;
}
/* .emr-hero::before {
    content: ''; position: absolute; inset-inline-start: -40px; bottom: -70px;
    width: 200px; height: 200px; border-radius: 50%;
    background: radial-gradient(circle, rgba(245, 158, 11, .18), transparent 70%);
    z-index: -999999
}
.emr-hero::after {
    content: ''; position: absolute; inset-inline-end: -60px; top: -60px;
    width: 260px; height: 260px; border-radius: 50%; background: rgba(255, 255, 255, .08);
} */
.emr-hero-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
  position: relative;
  z-index: 1;
}
.emr-hero h1 {
  font-size: 1.45rem;
  font-weight: 700;
  margin: 0 0 4px;
}
.emr-hero p {
  margin: 0;
  opacity: 0.9;
  font-size: 0.9rem;
}
.emr-hero-icon {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.18);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  flex-shrink: 0;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.25),
    0 6px 16px rgba(0, 0, 0, 0.12);
  backdrop-filter: blur(6px);
}

/* ---- KPI stat cards ---- */
.emr-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.emr-stat {
  background: #fff;
  border: 1px solid var(--emr-border);
  border-radius: 12px;
  padding: 14px 16px;
  box-shadow: var(--emr-shadow-sm);
  transition: var(--emr-transition);
  display: flex;
  align-items: center;
  gap: 12px;
  position: relative;
  overflow: hidden;
}

.emr-stat .num {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--emr-text);
  line-height: 1.1;
}
.emr-stat .lbl {
  font-size: 0.74rem;
  color: var(--emr-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}
.emr-stat-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.emr-stat-icon {
  width: 42px;
  height: 42px;
  border-radius: 11px;
  background: var(--emr-primary-soft);
  color: var(--emr-primary-dark);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
  flex-shrink: 0;
}
.emr-stat-trend {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 20px;
  margin-top: 2px;
  width: fit-content;
}
.emr-stat-trend.up {
  color: #15803d;
  background: #dcfce7;
}
.emr-stat-trend.down {
  color: #b91c1c;
  background: #fee2e2;
}

/* ---- Cards ---- */
.emr-card {
  background: #fff;
  border: 1px solid var(--emr-border);
  border-radius: var(--emr-radius);
  box-shadow: var(--emr-shadow-sm);
  overflow: hidden;
  transition: var(--emr-transition);
}
.emr-card-header {
  padding: 12px 18px;
  border-bottom: 1px solid var(--emr-border);
  font-weight: 700;
  font-size: 0.88rem;
  background: #f8fafc;
}
.emr-card-body {
  padding: 18px 20px;
}


/* ---- Filter bars ---- */
.emr-filterbar {
  background: #fff;
  border: 1px solid var(--emr-border);
  border-radius: var(--emr-radius);
  box-shadow: var(--emr-shadow-sm);
  padding: 14px 18px;
  margin-bottom: 18px;
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

/* ---- Tables ---- */
.emr-table thead th {
  background: #f8fafc;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--emr-muted);
  font-weight: 700;
  border-bottom: 2px solid var(--emr-border);
  padding-top: 12px;
  padding-bottom: 12px;
}
.emr-table tbody tr {
  transition: var(--emr-transition);
}
.emr-table tbody tr:hover {
  background: #f0fdfa;
  box-shadow: inset 3px 0 0 var(--emr-primary);
}

/* ---- Row-card tables: each record reads as its own separated, rounded
   row-card instead of a dense flat table where rows blend into each other.
   Opt-in — add class="emr-rowcard-table" (and wrap the .table-responsive in
   .emr-rowcard-tablewrap) instead of .emr-table, everything else (actions
   dropdowns, badges, etc.) stays the same. ---- */
.emr-rowcard-tablewrap {
  padding: 6px 14px 14px;
}
.emr-rowcard-table {
  border-collapse: separate;
  border-spacing: 0 10px;
}
.emr-rowcard-table thead th {
  background: transparent;
  border: none;
  color: var(--emr-muted);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 0 16px 6px;
}
.emr-rowcard-table tbody tr {
  transition: var(--emr-transition);
}
.emr-rowcard-table tbody td {
  background: #fff;
  border-top: 1px solid var(--emr-border);
  border-bottom: 1px solid var(--emr-border);
  padding: 14px 16px;
  vertical-align: middle;
  transition: var(--emr-transition);
}
.emr-rowcard-table tbody td:first-child {
  border-inline-start: 4px solid var(--emr-border);
  border-start-start-radius: 12px;
  border-end-start-radius: 12px;
}
.emr-rowcard-table tbody td:last-child {
  border-inline-end: 1px solid var(--emr-border);
  border-start-end-radius: 12px;
  border-end-end-radius: 12px;
}
.emr-rowcard-table tbody tr:hover td {
  background: #f8fafc;
  box-shadow: var(--emr-shadow-sm);
}

/* ---- Empty / loading states ---- */
.emr-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--emr-muted);
}
.emr-empty i {
  font-size: 2.2rem;
  opacity: 0.35;
  margin-bottom: 10px;
  display: block;
}
.emr-skeleton-row td {
  padding: 14px 16px;
}
.emr-skeleton-bar {
  height: 14px;
  border-radius: 6px;
  background: linear-gradient(90deg, #eef1f6 25%, #f7f9fc 37%, #eef1f6 63%);
  background-size: 400% 100%;
  animation: emr-shimmer 1.4s ease infinite;
}
@keyframes emr-shimmer {
  0% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0 50%;
  }
}

/* ---- Buttons ---- */
.emr-btn-primary {
  background: var(--emr-primary);
  border-color: var(--emr-primary);
  transition: var(--emr-transition);
  box-shadow: 0 2px 8px rgba(13, 148, 136, 0.2);
}
.emr-btn-primary:hover {
  background: var(--emr-primary-dark);
  border-color: var(--emr-primary-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(13, 148, 136, 0.3);
}

/* ---- Soft semantic badges ---- */
.emr-badge-soft {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 20px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.emr-badge-soft.success {
  color: #15803d;
  background: #dcfce7;
}
.emr-badge-soft.warning {
  color: var(--emr-accent-dark);
  background: var(--emr-accent-soft);
}
.emr-badge-soft.danger {
  color: #b91c1c;
  background: #fee2e2;
}
.emr-badge-soft.info {
  color: var(--emr-primary-dark);
  background: var(--emr-primary-soft);
}
.emr-badge-soft.neutral {
  color: var(--emr-muted);
  background: #f1f5f9;
}

/* ---- Page entrance ---- */
.emr-fade-in {
  animation: emr-fade-in 0.25s ease both;
}
@keyframes emr-fade-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ---- Avatars / chips ---- */
.emr-avatar,
.emr-avatar-lg,
.emr-avatar-xl {
  border-radius: 50%;
  background: var(--emr-primary-soft);
  color: var(--emr-primary-dark);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  flex-shrink: 0;
}
.emr-avatar {
  width: 36px;
  height: 36px;
  font-size: 0.85rem;
}
.emr-avatar-lg {
  width: 56px;
  height: 56px;
  font-size: 1.2rem;
}
.emr-avatar-xl {
  width: 72px;
  height: 72px;
  font-size: 1.5rem;
}
.emr-id-chip {
  background: rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  padding: 3px 10px;
  font-size: 0.8rem;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

/* ---- Status badge generic helper (page-specific colors stay per-page) ---- */
.emr-status-pill {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 20px;
}

/* ---- Timeline (shared by PatientProfile + 360 view) ---- */
.emr-timeline {
  position: relative;
}
.emr-tl-item {
  margin-bottom: 14px;
}
.emr-tl-card {
  background: #fff;
  border: 1px solid var(--emr-border);
  border-radius: 12px;
  padding: 14px 16px;
  box-shadow: var(--emr-shadow);
}
.emr-tl-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 6px;
}
.emr-tl-body {
  font-size: 0.88rem;
  color: var(--emr-text);
}
.emr-tl-section {
  margin-top: 8px;
}
.emr-tl-section h6 {
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--emr-muted);
  margin-bottom: 4px;
}
.emr-pill {
  display: inline-block;
  background: #f1f5f9;
  border-radius: 8px;
  padding: 3px 10px;
  margin: 2px;
  font-size: 0.8rem;
}

/* ---- Toast notifications (replaces native alert()) ---- */
#emrToastStack {
  position: fixed;
  top: 20px;
  inset-inline-end: 20px;
  z-index: 10600;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 360px;
}
.emr-toast {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.15);
  padding: 14px 16px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 0.88rem;
  border-inline-start: 4px solid var(--emr-primary);
  animation: emr-toast-in 0.22s ease;
}
.emr-toast.success {
  border-inline-start-color: #16a34a;
}
.emr-toast.error {
  border-inline-start-color: #dc2626;
}
.emr-toast.warning {
  border-inline-start-color: #d97706;
}
.emr-toast i.emr-toast-icon {
  font-size: 1.1rem;
  margin-top: 2px;
}
.emr-toast.success i.emr-toast-icon {
  color: #16a34a;
}
.emr-toast.error i.emr-toast-icon {
  color: #dc2626;
}
.emr-toast.warning i.emr-toast-icon {
  color: #d97706;
}
.emr-toast.info i.emr-toast-icon {
  color: var(--emr-primary);
}
.emr-toast-close {
  cursor: pointer;
  color: var(--emr-muted);
  margin-inline-start: auto;
}
@keyframes emr-toast-in {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
.emr-toast.emr-toast-out {
  animation: emr-toast-out 0.18s ease forwards;
}
@keyframes emr-toast-out {
  to {
    opacity: 0;
    transform: translateX(20px);
  }
}

/* ---- Confirm modal (replaces native confirm()) ---- */
.emr-confirm-icon {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: #fef3c7;
  color: #d97706;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
}

/* ---- Export toolbar (table-export.js) — brand-styled instead of plain Bootstrap grey ---- */
.te-toolbar .btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1.5px solid var(--emr-primary); color: var(--emr-primary);
  background: #fff; font-weight: 600; font-size: .8rem; border-radius: 9px;
  padding: 6px 14px; transition: var(--emr-transition);
}
.te-toolbar .btn:hover, .te-toolbar .btn:focus, .te-toolbar .btn.show {
  background: var(--emr-primary); border-color: var(--emr-primary); color: #fff;
  box-shadow: 0 4px 10px rgba(13, 148, 136, .2);
}
.te-toolbar .dropdown-menu {
  border: 1px solid var(--emr-border); border-radius: 10px; box-shadow: var(--emr-shadow-md); padding: 6px;
}
.te-toolbar .dropdown-item {
  border-radius: 7px; font-size: .85rem; padding: 8px 10px; display: flex; align-items: center;
}
.te-toolbar .dropdown-item:hover { background: var(--emr-primary-soft); }

/* ---- Shared phone-input.js widget — was completely unstyled, so the country-code
   picker and the number field stacked on top of each other instead of sitting
   side by side. ---- */
.pf-group { display: flex; align-items: stretch; gap: 6px; }
.pf-group .ss-wrap { flex: 0 0 150px; min-width: 110px; }
.pf-group .pf-num { flex: 1 1 auto; min-width: 0; }
.pf-wa-same {
  display: flex; align-items: center; gap: 6px; margin: 8px 2px 0;
  font-size: .8rem; font-weight: 500; color: var(--emr-muted); cursor: pointer;
}
.pf-wa-same input[type="checkbox"] { margin: 0; }
@media (max-width: 576px) {
  .pf-group { flex-wrap: wrap; }
  .pf-group .ss-wrap { flex-basis: 100%; }
  .pf-group .pf-num { flex-basis: 100%; }
}

/* ---- Centered small "action" modals (confirm-style: icon circle + title + body) ---- */
.emr-action-modal { border-radius: 16px; border: none; overflow: visible; }
.emr-action-modal-close { position: absolute; inset-inline-end: 12px; top: 12px; z-index: 2; }
.emr-action-modal-icon {
  width: 56px; height: 56px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  font-size: 1.4rem; margin: 0 auto 12px;
}

/* ---- Padded, bordered field-group sections inside a form (real breathing room,
   used instead of dense rows split only by <hr>) ---- */
.emr-form-section {
  background: #f8fafc; border: 1px solid var(--emr-border); border-radius: 12px;
  padding: 18px 20px; margin-bottom: 18px;
}
.emr-form-section:last-child { margin-bottom: 0; }
.emr-form-section-title { font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--emr-muted); margin-bottom: 16px; }
