/* DMM Medical Centre — Clinic Management System */
:root {
  --primary: #003d7a;
  --primary-light: #0a5ca8;
  --primary-dark: #002952;
  --accent: #00a651;
  --accent-light: #2dc46e;
  --danger: #e74c3c;
  --warning: #f39c12;
  --bg: #f0f2f5;
  --surface: #ffffff;
  --text: #1a1a2e;
  --text-light: #6b7280;
  --border: #d1d5db;
  --sidebar-w: 220px;
  --topbar-h: 56px;
  --radius: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,.1);
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

/* ── LOGIN ──────────────────────────────────────────── */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
}

.login-card {
  background: var(--surface);
  border-radius: 12px;
  padding: 40px;
  width: 380px;
  box-shadow: 0 8px 32px rgba(0,0,0,.2);
}

.login-card h1 {
  color: var(--primary);
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 4px;
}

.login-card .subtitle {
  color: var(--text-light);
  font-size: 13px;
  margin-bottom: 28px;
}

.login-card .logo-icon {
  font-size: 36px;
  margin-bottom: 12px;
  display: block;
}

/* ── FORM ELEMENTS ──────────────────────────────────── */
.form-group { margin-bottom: 16px; }

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 4px;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  transition: border-color .15s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(0,61,122,.12);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
}

/* ── BUTTONS ────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s;
  font-family: inherit;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-light); }
.btn-success { background: var(--accent); color: #fff; }
.btn-success:hover { background: var(--accent-light); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { background: var(--bg); }
.btn-sm { padding: 5px 12px; font-size: 13px; }
.btn-block { width: 100%; }

/* ── LAYOUT ─────────────────────────────────────────── */
.app-layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  min-height: 100vh;
}

.topbar {
  grid-column: 1 / -1;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 10;
}

.topbar h1 { font-size: 16px; font-weight: 600; letter-spacing: -.2px; }

.topbar-right { display: flex; align-items: center; gap: 16px; font-size: 13px; }
.topbar-right .user-name { opacity: .9; }
.topbar-right .btn-logout {
  background: rgba(255,255,255,.15);
  color: #fff;
  border: none;
  padding: 5px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
}

.sidebar {
  background: var(--primary-dark);
  padding: 16px 0;
  overflow-y: auto;
}

.sidebar a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: rgba(255,255,255,.7);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: background .1s, color .1s;
}

.sidebar a:hover { background: rgba(255,255,255,.08); color: #fff; }

.sidebar a.active {
  background: rgba(255,255,255,.12);
  color: #fff;
  border-left: 3px solid var(--accent);
}

.sidebar .nav-section {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: rgba(255,255,255,.35);
  padding: 20px 20px 6px;
  animation: navSectionPulse 2.6s ease-in-out infinite;
}

@keyframes navSectionPulse {
  0%, 100% { color: rgba(255,255,255,.35); text-shadow: none; }
  50% { color: var(--accent-light); text-shadow: 0 0 6px rgba(45,196,110,.7); }
}

.main-content { padding: 24px; overflow-y: auto; }

/* ── CARDS ──────────────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.card-header h2 { font-size: 16px; font-weight: 600; }

/* ── STATS ROW ──────────────────────────────────────── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

.stat-card .stat-value { font-size: 28px; font-weight: 700; color: var(--primary); }
.stat-card .stat-label { font-size: 13px; color: var(--text-light); margin-top: 2px; }

/* ── TABLES ─────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  background:
    linear-gradient(to right, var(--surface) 30%, rgba(255,255,255,0)),
    linear-gradient(to right, rgba(255,255,255,0), var(--surface) 70%) 0 100%,
    linear-gradient(to right, rgba(0,0,0,.12), rgba(255,255,255,0)),
    linear-gradient(to right, rgba(255,255,255,0), rgba(0,0,0,.12)) 0 100%;
  background-repeat: no-repeat;
  background-color: var(--surface);
  background-size: 24px 100%, 24px 100%, 8px 100%, 8px 100%;
  background-position: 0 0, 100% 0, 0 0, 100% 0;
  background-attachment: local, local, scroll, scroll;
}
.table-wrap .sticky-col {
  position: sticky;
  left: 0;
  background: var(--surface);
  z-index: 1;
}
table { width: 100%; border-collapse: collapse; }

thead th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: .3px;
  padding: 10px 12px;
  border-bottom: 2px solid var(--border);
}

tbody td { padding: 10px 12px; border-bottom: 1px solid #eee; font-size: 13px; }
tbody tr:hover { background: #f8f9fb; }

/* ── STATUS BADGES ──────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
}

.badge-open { background: #dbeafe; color: #1e40af; }
.badge-triage { background: #fef3c7; color: #92400e; }
.badge-consultation { background: #ede9fe; color: #5b21b6; }
.badge-completed { background: #d1fae5; color: #065f46; }
.badge-pending { background: #fef3c7; color: #92400e; }
.badge-resulted { background: #d1fae5; color: #065f46; }

/* ── SEARCH BAR ─────────────────────────────────────── */
.search-bar { display: flex; gap: 8px; margin-bottom: 16px; }
.search-bar input {
  flex: 1;
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
}
.search-bar input:focus { outline: none; border-color: var(--primary); }

/* ── MODAL ──────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal {
  background: var(--surface);
  border-radius: 10px;
  padding: 28px;
  width: 500px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 12px 40px rgba(0,0,0,.2);
}

.modal h2 { font-size: 18px; font-weight: 600; margin-bottom: 20px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

/* ── ALERTS ─────────────────────────────────────────── */
.alert { padding: 10px 14px; border-radius: var(--radius); font-size: 13px; margin-bottom: 16px; }
.alert-error { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; }
.alert-success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }

/* ── QUEUE LIST ──────────────────────────────────────── */
.queue-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid #eee;
  cursor: pointer;
  transition: background .1s;
}
.queue-item:hover { background: #f8f9fb; }
.queue-item .patient-info h3 { font-size: 14px; font-weight: 600; }
.queue-item .patient-info p { font-size: 12px; color: var(--text-light); }
.queue-actions { display: flex; gap: 6px; }

/* ── VITALS GRID ────────────────────────────────────── */
.vitals-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.vital-item {
  text-align: center;
  padding: 12px;
  background: #f8f9fb;
  border-radius: var(--radius);
  transition: all .3s;
}

.vital-item .vital-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--primary);
}

.vital-item .vital-label {
  font-size: 11px;
  color: var(--text-light);
  margin-top: 2px;
}

/* ── CRITICAL VITALS — RED PULSE ────────────────────── */
@keyframes critical-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.6); }
  25%  { box-shadow: 0 0 8px 2px rgba(231, 76, 60, 0.5); }
  50%  { box-shadow: 0 0 16px 4px rgba(231, 76, 60, 0.4); }
  75%  { box-shadow: 0 0 8px 2px rgba(231, 76, 60, 0.5); }
  100% { box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.6); }
}

.vital-critical {
  background: #fef2f2;
  border: 2px solid var(--danger);
  animation: critical-pulse 2.2s ease-in-out infinite;
}

.vital-critical .vital-value {
  color: var(--danger);
  font-weight: 800;
}

.vital-critical .vital-label {
  color: var(--danger);
  font-weight: 600;
}

/* ── WARNING VITALS — AMBER BORDER ──────────────────── */
@keyframes warning-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(243, 156, 18, 0.5); }
  25%  { box-shadow: 0 0 6px 2px rgba(243, 156, 18, 0.4); }
  50%  { box-shadow: 0 0 12px 3px rgba(243, 156, 18, 0.3); }
  75%  { box-shadow: 0 0 6px 2px rgba(243, 156, 18, 0.4); }
  100% { box-shadow: 0 0 0 0 rgba(243, 156, 18, 0.5); }
}

.vital-warning {
  background: #fffbeb;
  border: 2px solid var(--warning);
  animation: warning-pulse 2.8s ease-in-out infinite;
}

.vital-warning .vital-value {
  color: #b45309;
  font-weight: 800;
}

.vital-warning .vital-label {
  color: #92400e;
  font-weight: 600;
}

/* ── SOAP NOTES ─────────────────────────────────────── */
.soap-section { margin-bottom: 16px; }
.soap-section label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 4px;
}
.soap-section textarea {
  width: 100%;
  min-height: 80px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
}
.soap-section textarea:focus { outline: none; border-color: var(--primary); }

/* ── REPORT CARDS ───────────────────────────────────── */
.report-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}

.report-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  cursor: pointer;
  transition: box-shadow .2s, transform .1s;
}

.report-card:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,.15);
  transform: translateY(-2px);
}

.report-card .report-icon { font-size: 32px; margin-bottom: 12px; }
.report-card h3 { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.report-card p { font-size: 13px; color: var(--text-light); }

/* ── PRINT ──────────────────────────────────────────── */
@media print {
  .sidebar, .topbar, .btn, .search-bar { display: none; }
  .main-content { padding: 0; }
  .card { box-shadow: none; border: 1px solid #ddd; }
  .vital-critical, .vital-warning { animation: none; }
}

/* ── RESPONSIVE ─────────────────────────────────────── */
.menu-toggle {
  display: none;
  background: transparent;
  border: none;
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  margin-right: 4px;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 90;
}

@media (max-width: 768px) {
  .app-layout { grid-template-columns: 1fr; }
  .menu-toggle { display: inline-block; }
  .topbar h1 { font-size: 14px; }
  .topbar-right .user-name,
  .topbar-right #user-role { display: none; }
  .sidebar {
    display: block;
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    bottom: 0;
    width: 240px;
    transform: translateX(-100%);
    transition: transform .2s ease;
    z-index: 100;
    box-shadow: 2px 0 12px rgba(0,0,0,.2);
  }
  .sidebar.open { transform: translateX(0); }
  body.sidebar-open .sidebar-backdrop { display: block; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .modal { width: 95%; padding: 20px; }
}

/* ── HIDDEN ─────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── TAB NAV ────────────────────────────────────────── */
.tabs { display: flex; gap: 0; border-bottom: 2px solid var(--border); margin-bottom: 20px; }
.tab {
  padding: 10px 20px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-light);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color .15s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ── MC LOGO (text-based) ───────────────────────────── */
.mc-logo-sm {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 36px;
  background: rgba(255,255,255,.15);
  border: 2px solid rgba(255,255,255,.4);
  border-radius: 8px;
  font-size: 11px;
  font-weight: 800;
  color: #fff;
  letter-spacing: 0.5px;
}

.mc-logo-lg {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 72px;
  height: 72px;
  background: linear-gradient(135deg, #003d7a 0%, #0a5ca8 100%);
  border: 3px solid #003d7a;
  border-radius: 14px;
  font-size: 21px;
  font-weight: 800;
  color: #fff;
  letter-spacing: 0px;
  margin-bottom: 12px;
}

/* ── OPTGROUP CATEGORY HEADERS — colored ────────────── */
select optgroup {
  font-weight: 700;
  font-size: 14px;
  color: #003d7a;
  background: #e8f0fe;
  padding: 6px 0;
  font-style: normal;
}

select optgroup option {
  font-weight: 400;
  font-size: 13px;
  color: #1a1a2e;
  background: #fff;
  padding: 4px 12px;
}

select optgroup[label="Haematology"],
select optgroup[label="X-Ray"] { color: #003d7a; background: #dbeafe; }
select optgroup[label="Biochemistry"],
select optgroup[label="Ultrasound"] { color: #065f46; background: #d1fae5; }
select optgroup[label="Urine / Stool"],
select optgroup[label="Advanced Imaging"] { color: #92400e; background: #fef3c7; }
select optgroup[label="Infectious Disease"],
select optgroup[label="Cardiac"] { color: #dc2626; background: #fef2f2; }
select optgroup[label="Serology / Hormones"],
select optgroup[label="Other"] { color: #5b21b6; background: #ede9fe; }

/* ── REASON FOR VISIT — SMOOTH ATTENTION PULSE ──────── */
/* Billing alert panel */
.billing-alert-item { padding:12px 14px; border-bottom:1px solid #f0f1f3; font-size:13px; }
.billing-alert-item:last-child { border-bottom:none; }

.pulse-cta {
  animation: ctaPulse 1.8s ease-in-out infinite;
}
@keyframes ctaPulse {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(0,166,81,0);
    border-color: var(--border);
    background: transparent;
    transform: scale(1);
  }
  50% {
    box-shadow: 0 0 0 6px rgba(0,166,81,0.35);
    border-color: var(--accent);
    background: rgba(0,166,81,0.12);
    transform: scale(1.04);
  }
}

.pulse-danger {
  animation: dangerPulse 1.2s ease-in-out infinite;
}
@keyframes dangerPulse {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(231,76,60,0.6);
    transform: scale(1);
  }
  50% {
    box-shadow: 0 0 0 6px rgba(231,76,60,0.15);
    transform: scale(1.08);
  }
}
