/* ==============================================================================
   EMAMC (Emergency Medicine Activity Management Center) Master Stylesheet
   Mobile-First Responsive Design, Fluid Breakpoints & Clinical Color Tokens
   ============================================================================== */

:root {
  --em-primary: #0284c7;
  --em-primary-dark: #0369a1;
  --em-primary-light: #e0f2fe;
  --em-navy: #0f172a;
  --em-slate: #1e293b;
  --em-body-bg: #f8fafc;
  --em-card-bg: #ffffff;
  --em-border: #e2e8f0;
  --em-border-dark: #cbd5e1;
  
  /* Clinical Priority Triage Colors */
  --triage-red: #ef4444;
  --triage-red-bg: #fef2f2;
  --triage-yellow: #f59e0b;
  --triage-yellow-bg: #fffbeb;
  --triage-green: #10b981;
  --triage-green-bg: #ecfdf5;
  --clinical-blue: #3b82f6;
  --clinical-purple: #8b5cf6;
  --clinical-teal: #0d9488;
  
  --min-touch-target: 44px;
}

*, *::before, *::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body.emamc-body {
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--em-body-bg);
  color: #334155;
  margin: 0;
  padding: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* Base Accessibility & Touch Targets */
a, button, input, select, textarea, .btn {
  touch-action: manipulation;
}

.btn, .form-control, .form-select, .page-link {
  min-height: 38px;
}

@media (max-width: 768px) {
  /* Prevent mobile Safari zoom by enforcing >= 16px */
  input, select, textarea, .form-control, .form-select {
    font-size: 16px !important;
  }
  
  .btn, .form-control, .form-select {
    min-height: var(--min-touch-target);
  }
}

/* ==============================================================================
   1. NAVIGATION & TOPBAR
   ============================================================================== */
.emamc-navbar {
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 4px 20px -2px rgba(0, 0, 0, 0.25);
  padding: 0.65rem 1rem;
}

.emamc-brand-badge {
  background: rgba(2, 132, 199, 0.2);
  border: 1px solid rgba(56, 189, 248, 0.4);
  color: #38bdf8;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 6px;
}

.emamc-nav-link {
  color: #94a3b8 !important;
  font-weight: 500;
  font-size: 0.88rem;
  padding: 0.55rem 0.85rem !important;
  border-radius: 8px;
  transition: all 0.15s ease-in-out;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.emamc-nav-link:hover {
  color: #ffffff !important;
  background: rgba(255, 255, 255, 0.08);
}

.emamc-nav-link.active {
  color: #ffffff !important;
  background: #0284c7;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(2, 132, 199, 0.4);
}

/* ==============================================================================
   2. STAT CARDS & CLINICAL KPI WIDGETS
   ============================================================================== */
.emamc-stat-card {
  background: var(--em-card-bg);
  border: 1px solid var(--em-border);
  border-radius: 14px;
  padding: 1.15rem;
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.04);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  position: relative;
  overflow: hidden;
}

.emamc-stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 16px -4px rgba(0, 0, 0, 0.08);
}

.emamc-stat-icon {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  flex-shrink: 0;
}

/* Triage Zones */
.zone-card-red {
  border-left: 4px solid var(--triage-red);
  background: linear-gradient(180deg, #fff5f5 0%, #ffffff 100%);
}

.zone-card-yellow {
  border-left: 4px solid var(--triage-yellow);
  background: linear-gradient(180deg, #fffbeb 0%, #ffffff 100%);
}

.zone-card-green {
  border-left: 4px solid var(--triage-green);
  background: linear-gradient(180deg, #f0fdf4 0%, #ffffff 100%);
}

/* ==============================================================================
   3. CLINICAL SECTIONS & FORM CARDS
   ============================================================================== */
.emamc-section-card {
  background: #ffffff;
  border: 1px solid var(--em-border);
  border-radius: 14px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
  margin-bottom: 1.25rem;
  overflow: hidden;
}

.emamc-section-header {
  background: #f8fafc;
  border-bottom: 1px solid var(--em-border);
  padding: 0.9rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.emamc-section-title {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--em-slate);
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

/* Sticky Action Bar for Forms */
.emamc-sticky-actions {
  position: sticky;
  bottom: 0;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--em-border);
  padding: 0.85rem 1rem;
  z-index: 1020;
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.06);
  padding-bottom: calc(0.85rem + env(safe-area-inset-bottom, 0px));
}

/* ==============================================================================
   4. DATA SHEET & SPREADSHEET GRID
   ============================================================================== */
.emamc-grid-wrapper {
  background: #ffffff;
  border: 1px solid var(--em-border);
  border-radius: 12px;
  overflow: auto;
  position: relative;
  -webkit-overflow-scrolling: touch;
}

.emamc-grid-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.82rem;
}

.emamc-grid-table th {
  background: #0f172a;
  color: #ffffff;
  font-weight: 600;
  padding: 0.65rem 0.75rem;
  white-space: nowrap;
  border-right: 1px solid rgba(255, 255, 255, 0.1);
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.emamc-grid-table td {
  padding: 0.5rem 0.65rem;
  border-right: 1px solid #f1f5f9;
  border-bottom: 1px solid #f1f5f9;
  white-space: nowrap;
}

.emamc-grid-table tbody tr:hover {
  background-color: #f8fafc;
}

.emamc-grid-cell-editable {
  cursor: cell;
  background-color: #ffffff;
  transition: background-color 0.15s ease;
}

.emamc-grid-cell-editable:hover {
  background-color: #eff6ff !important;
}

.emamc-grid-cell-editable:focus {
  outline: 2px solid var(--em-primary);
  background-color: #ffffff !important;
  box-shadow: inset 0 0 0 1px var(--em-primary);
}

/* Mobile Data Sheet Card View */
.emamc-mobile-card {
  display: none;
  background: #ffffff;
  border: 1px solid var(--em-border);
  border-radius: 12px;
  padding: 1rem;
  margin-bottom: 1rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

@media (max-width: 767.98px) {
  .emamc-hide-on-mobile-grid {
    display: none !important;
  }
  .emamc-mobile-card {
    display: block;
  }
}

/* ==============================================================================
   5. RECONCILIATION BADGES
   ============================================================================== */
.recon-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.6rem;
  border-radius: 9999px;
  font-size: 0.72rem;
  font-weight: 600;
}

.recon-badge-ok {
  background-color: #ecfdf5;
  color: #065f46;
  border: 1px solid #a7f3d0;
}

.recon-badge-mismatch {
  background-color: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
  animation: pulse-border 2s infinite;
}

@keyframes pulse-border {
  0%, 100% { border-color: #fecaca; }
  50% { border-color: #ef4444; }
}

/* ==============================================================================
   6. RESPONSIVE MEDIA QUERIES & BREAKPOINTS
   ============================================================================== */

/* Small Phones (320px - 380px) */
@media (max-width: 380px) {
  .container-fluid {
    padding-left: 0.75rem !important;
    padding-right: 0.75rem !important;
  }
  
  .emamc-stat-card {
    padding: 0.85rem;
  }
  
  .fs-3 {
    font-size: 1.4rem !important;
  }
}

/* Mobile & Tablets (< 992px) */
@media (max-width: 991.98px) {
  .navbar-collapse {
    background: #0f172a;
    padding: 1rem;
    border-radius: 12px;
    margin-top: 0.75rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
  }
  
  .emamc-nav-link {
    padding: 0.65rem 1rem !important;
  }
  
  .table-responsive {
    border-radius: 10px;
    border: 1px solid var(--em-border);
  }
}

/* Large Screens (>= 1400px) */
@media (min-width: 1400px) {
  .container-fluid {
    max-width: 1800px;
    margin: 0 auto;
  }
}

/* Print Styles */
@media print {
  .no-print, .emamc-navbar, .emamc-sticky-actions, .btn, .card-header button {
    display: none !important;
  }
  
  body.emamc-body {
    background: #ffffff !important;
    font-size: 11pt;
  }
  
  .card, .emamc-section-card {
    border: 1px solid #94a3b8 !important;
    box-shadow: none !important;
    break-inside: avoid;
    margin-bottom: 1rem !important;
  }
}
