/* ============================================================
   RD-Doku — Main Application Stylesheet
   Emergency Medical Service Documentation
   ============================================================ */

/* ----- Reset / Base ----- */
*, *::before, *::after { box-sizing: border-box; }
body { font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; background: #f0f2f5; color: #1f2937; }

/* ============================================================
   LAYOUT — Sidebar + Content Wrapper
   ============================================================ */
#wrapper { display: flex; min-height: 100vh; }

/* ----- Sidebar ----- */
.sidebar {
  width: 260px;
  min-height: 100vh;
  background: #1a3a6b;
  color: white;
  display: flex;
  flex-direction: column;
  transition: width 0.3s ease;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 1000;
  overflow-y: auto;
  overflow-x: hidden;
}
.sidebar.collapsed { width: 0; overflow: hidden; }

/* Sidebar Header */
.sidebar-header {
  padding: 20px 16px;
  font-size: 1.1rem;
  font-weight: 700;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
  flex-shrink: 0;
}
.sidebar-header .fa-ambulance,
.sidebar-header .fas.fa-ambulance { color: #e63946; font-size: 1.4rem; }

/* Sidebar Navigation */
.sidebar-nav {
  list-style: none;
  padding: 10px 0;
  margin: 0;
  flex: 1;
}
.sidebar-nav .nav-section {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: rgba(255,255,255,0.4);
  padding: 16px 16px 4px;
  white-space: nowrap;
}
.sidebar-nav li a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  color: rgba(255,255,255,0.85);
  text-decoration: none;
  font-size: 0.9rem;
  transition: background 0.2s, border-left-color 0.2s;
  border-left: 3px solid transparent;
  white-space: nowrap;
}
.sidebar-nav li a:hover,
.sidebar-nav li a.active {
  background: rgba(255,255,255,0.1);
  color: white;
  border-left-color: #e63946;
}
.sidebar-nav li a .fa,
.sidebar-nav li a .fas { width: 18px; text-align: center; flex-shrink: 0; }

/* Sidebar Footer */
.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid rgba(255,255,255,0.1);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  white-space: nowrap;
}
.sidebar-footer .user-info { flex: 1; min-width: 0; }
.sidebar-footer .user-info .name {
  font-size: 0.85rem;
  font-weight: 600;
  color: white;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-footer .user-info .qual {
  font-size: 0.75rem;
  color: rgba(255,255,255,0.5);
}
.btn-logout {
  color: rgba(255,255,255,0.6);
  text-decoration: none;
  font-size: 1.1rem;
  flex-shrink: 0;
  transition: color 0.2s;
}
.btn-logout:hover { color: #e63946; }

/* ============================================================
   MAIN CONTENT AREA
   ============================================================ */
#page-content-wrapper {
  margin-left: 260px;
  flex: 1;
  min-width: 0;
  transition: margin-left 0.3s ease;
  display: flex;
  flex-direction: column;
}
#page-content-wrapper.expanded { margin-left: 0; }

/* Top Navbar */
.navbar-top {
  background: white;
  border-bottom: 1px solid #e5e7eb;
  padding: 0 20px;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  flex-shrink: 0;
}
.navbar-top .navbar-title {
  font-weight: 600;
  font-size: 1rem;
  color: #1a3a6b;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.navbar-top #sidebarToggle {
  padding: 4px 8px;
  color: #6b7280;
  border: none;
  background: transparent;
  font-size: 1.1rem;
  line-height: 1;
}
.navbar-top #sidebarToggle:hover { color: #1a3a6b; }

/* Page Content */
.page-content {
  padding: 24px;
  background: #f0f2f5;
  min-height: calc(100vh - 56px);
  flex: 1;
}

/* ============================================================
   CARDS
   ============================================================ */
.card {
  border: none;
  border-radius: 8px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}
.card-header {
  background: white;
  border-bottom: 2px solid #f0f2f5;
  font-weight: 600;
  border-radius: 8px 8px 0 0 !important;
  padding: 14px 20px;
  color: #1a3a6b;
}
.card-body { padding: 20px; }
.card-footer {
  background: white;
  border-top: 1px solid #f0f2f5;
  border-radius: 0 0 8px 8px !important;
  padding: 12px 20px;
}

/* ============================================================
   DASHBOARD STAT CARDS
   ============================================================ */
.stat-card {
  border-radius: 10px;
  padding: 20px 24px;
  color: white;
  border: none;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
  position: relative;
  overflow: hidden;
}
.stat-card::after {
  content: '';
  position: absolute;
  right: -20px; top: -20px;
  width: 100px; height: 100px;
  border-radius: 50%;
  background: rgba(255,255,255,0.08);
}
.stat-card-rd    { background: linear-gradient(135deg, #1a3a6b 0%, #2563eb 100%); }
.stat-card-san   { background: linear-gradient(135deg, #c2410c 0%, #f4a261 100%); }
.stat-card-total { background: linear-gradient(135deg, #065f46 0%, #10b981 100%); }
.stat-card-draft { background: linear-gradient(135deg, #92400e 0%, #d97706 100%); }

.stat-card .stat-icon { font-size: 2rem; opacity: 0.6; margin-bottom: 8px; }
.stat-card .stat-number { font-size: 2.5rem; font-weight: 800; line-height: 1; }
.stat-card .stat-label { font-size: 0.85rem; opacity: 0.85; margin-top: 4px; }
.stat-card .stat-sub   { font-size: 0.75rem; opacity: 0.65; margin-top: 2px; }

/* ============================================================
   FORM STYLING
   ============================================================ */
.form-label { font-weight: 500; font-size: 0.875rem; color: #374151; margin-bottom: 4px; }
.form-label.required::after { content: ' *'; color: #e63946; }

.form-control,
.form-select {
  border-radius: 6px;
  border: 1px solid #d1d5db;
  font-size: 0.9rem;
  color: #1f2937;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.form-control:focus,
.form-select:focus {
  border-color: #1a3a6b;
  box-shadow: 0 0 0 3px rgba(26,58,107,0.1);
  outline: none;
}
.form-control:disabled,
.form-select:disabled,
.form-control[readonly] {
  background: #f3f4f6;
  color: #9ca3af;
}
.form-control.is-invalid,
.form-select.is-invalid { border-color: #e63946; }
.form-control.is-valid,
.form-select.is-valid { border-color: #10b981; }

.input-group .form-control:not(:last-child) { border-right: 0; }
.input-group-text {
  background: #f9fafb;
  border: 1px solid #d1d5db;
  color: #6b7280;
  font-size: 0.875rem;
}

/* Section headers within forms */
.section-header {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #6b7280;
  border-bottom: 1px solid #e5e7eb;
  padding-bottom: 8px;
  margin-bottom: 16px;
  margin-top: 8px;
}

/* ============================================================
   PROTOCOL FORM — TABS
   ============================================================ */
.protocol-tabs { border-bottom: 2px solid #e5e7eb; margin-bottom: 0; }
.protocol-tabs .nav-link {
  color: #6b7280;
  font-size: 0.875rem;
  padding: 10px 16px;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  background: transparent;
  border-radius: 0;
  transition: color 0.2s, border-color 0.2s;
}
.protocol-tabs .nav-link:hover { color: #1a3a6b; border-bottom-color: rgba(26,58,107,0.3); }
.protocol-tabs .nav-link.active {
  color: #1a3a6b;
  font-weight: 600;
  border-bottom: 2px solid #1a3a6b;
  background: transparent;
}
.protocol-tabs .nav-link .tab-icon { margin-right: 6px; }

/* ============================================================
   VITAL SIGNS
   ============================================================ */
.vitals-container { }
.vitals-row {
  background: white;
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 8px;
  border: 1px solid #e5e7eb;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.vitals-row .vital-time { flex: 0 0 90px; }
.vitals-row .vital-field { flex: 1; min-width: 80px; }
.vitals-row .vital-actions { flex-shrink: 0; }
.vitals-header {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #9ca3af;
  padding: 0 16px 4px;
  display: flex;
  gap: 12px;
}

/* ============================================================
   INTERVENTIONS / CHECKBOXES GRID
   ============================================================ */
.intervention-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 8px;
}
.intervention-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  user-select: none;
  font-size: 0.875rem;
  color: #374151;
}
.intervention-item:hover { border-color: #1a3a6b; background: #f8faff; }
.intervention-item.selected {
  border-color: #1a3a6b;
  background: #f0f4ff;
  color: #1a3a6b;
  font-weight: 500;
}
.intervention-item input[type="checkbox"] { accent-color: #1a3a6b; }

/* ============================================================
   MEDICATION ROWS
   ============================================================ */
.medication-row {
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 10px 14px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.medication-row .med-field { flex: 1; min-width: 100px; }
.removable-row { position: relative; }

/* ============================================================
   STATUS INDICATORS
   ============================================================ */
.status-draft    { color: #d97706; }
.status-completed { color: #059669; }
.status-transferred { color: #0284c7; }
.status-cancelled { color: #9ca3af; }

/* Bootstrap badge extensions */
.badge-rd  { background-color: #e63946 !important; color: white !important; }
.badge-san { background-color: #f4a261 !important; color: #1a1a1a !important; }

/* ============================================================
   SERVICE TYPE TOGGLE
   ============================================================ */
.service-type-toggle { display: flex; gap: 8px; }
.service-type-toggle .btn-check:checked + .btn-outline-danger {
  background: #e63946;
  color: white;
  border-color: #e63946;
}
.service-type-toggle .btn-check:checked + .btn-outline-warning {
  background: #f4a261;
  color: #1a1a1a;
  border-color: #f4a261;
}

/* ============================================================
   PIN DISPLAY
   ============================================================ */
.pin-display {
  font-size: 3rem;
  font-weight: 800;
  letter-spacing: 0.3em;
  color: #1a3a6b;
  font-family: 'Courier New', Courier, monospace;
  text-align: center;
  padding: 20px 24px;
  background: #f0f4ff;
  border-radius: 8px;
  border: 2px dashed #1a3a6b;
  margin: 16px 0;
}
.pin-countdown {
  text-align: center;
  font-size: 0.875rem;
  color: #6b7280;
  margin-top: 8px;
}
.pin-countdown.expiring-soon { color: #e63946; font-weight: 600; }

/* ============================================================
   TABLES
   ============================================================ */
.table { font-size: 0.875rem; }
.table thead th {
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #6b7280;
  background: #f9fafb;
  border-bottom: 2px solid #e5e7eb;
  padding: 10px 14px;
  white-space: nowrap;
}
.table tbody td { padding: 10px 14px; vertical-align: middle; border-bottom: 1px solid #f0f2f5; }
.table tbody tr:hover { background: #f8faff; }
.table-protocols .protocol-number { font-family: monospace; font-weight: 600; color: #1a3a6b; }

/* ============================================================
   ALERTS
   ============================================================ */
.alert { border-radius: 8px; font-size: 0.9rem; border: none; }
.alert-danger  { background: #fef2f2; color: #991b1b; border-left: 4px solid #e63946; }
.alert-success { background: #f0fdf4; color: #065f46; border-left: 4px solid #10b981; }
.alert-warning { background: #fffbeb; color: #92400e; border-left: 4px solid #d97706; }
.alert-info    { background: #f0f9ff; color: #075985; border-left: 4px solid #0284c7; }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn { border-radius: 6px; font-size: 0.875rem; font-weight: 500; transition: all 0.2s; }
.btn-primary { background: #1a3a6b; border-color: #1a3a6b; }
.btn-primary:hover { background: #15306a; border-color: #15306a; filter: brightness(1.1); }
.btn-danger  { background: #e63946; border-color: #e63946; }
.btn-danger:hover  { background: #cc2f3c; border-color: #cc2f3c; }
.btn-sm { font-size: 0.8rem; padding: 4px 10px; }
.btn-lg { font-size: 1rem; padding: 10px 22px; }

/* Unsaved indicator */
.unsaved-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: #d97706;
  font-weight: 500;
}
.unsaved-indicator.saved { color: #059669; }

/* ============================================================
   LOGIN PAGE
   ============================================================ */
.login-page {
  min-height: 100vh;
  background: linear-gradient(160deg, #1a3a6b 0%, #0f2347 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  background: white;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.25);
  padding: 40px 36px;
  width: 100%;
  max-width: 400px;
}
.login-card .login-logo {
  text-align: center;
  margin-bottom: 24px;
}
.login-card .login-logo .fa-ambulance {
  font-size: 2.5rem;
  color: #e63946;
  margin-bottom: 8px;
  display: block;
}
.login-card .login-logo h1 {
  font-size: 1.4rem;
  font-weight: 800;
  color: #1a3a6b;
  margin: 0 0 4px;
}
.login-card .login-logo p { font-size: 0.85rem; color: #6b7280; margin: 0; }
.login-btn {
  width: 100%;
  background: #1a3a6b;
  border: none;
  color: white;
  padding: 11px;
  border-radius: 6px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}
.login-btn:hover  { background: #15306a; }
.login-btn:active { transform: scale(0.99); }

/* ============================================================
   PROTOCOL PRINT VIEW
   ============================================================ */
.protocol-section { margin-bottom: 20px; }
.protocol-section-title {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #1a3a6b;
  border-bottom: 2px solid #1a3a6b;
  padding-bottom: 4px;
  margin-bottom: 12px;
}

/* ============================================================
   MISC UTILITIES
   ============================================================ */
.text-muted-sm { font-size: 0.8rem; color: #9ca3af; }
.divider { border-top: 1px solid #e5e7eb; margin: 16px 0; }
.no-data {
  text-align: center;
  padding: 40px;
  color: #9ca3af;
  font-size: 0.9rem;
}
.no-data .fa { font-size: 2.5rem; display: block; margin-bottom: 12px; opacity: 0.4; }

/* Breadcrumb */
.breadcrumb { font-size: 0.85rem; background: transparent; padding: 0; margin-bottom: 16px; }
.breadcrumb-item a { color: #1a3a6b; text-decoration: none; }
.breadcrumb-item a:hover { text-decoration: underline; }
.breadcrumb-item.active { color: #6b7280; }

/* GCS display */
.gcs-total {
  font-size: 1.5rem;
  font-weight: 800;
  color: #1a3a6b;
  text-align: center;
  padding: 8px;
  background: #f0f4ff;
  border-radius: 6px;
  border: 2px solid #1a3a6b;
  min-width: 60px;
  display: inline-block;
}
.gcs-total.gcs-severe   { color: #e63946; border-color: #e63946; background: #fef2f2; }
.gcs-total.gcs-moderate { color: #d97706; border-color: #d97706; background: #fffbeb; }
.gcs-total.gcs-mild     { color: #059669; border-color: #059669; background: #f0fdf4; }

/* ============================================================
   RESPONSIVE — MOBILE
   ============================================================ */
@media (max-width: 768px) {
  .sidebar { width: 0; overflow: hidden; }
  .sidebar.mobile-open { width: 260px; box-shadow: 4px 0 20px rgba(0,0,0,0.3); }
  #page-content-wrapper { margin-left: 0; }
  #page-content-wrapper.expanded { margin-left: 0; }
  .page-content { padding: 16px; }
  .stat-card .stat-number { font-size: 2rem; }
  .intervention-grid { grid-template-columns: 1fr 1fr; }
  .vitals-row { flex-direction: column; align-items: stretch; }
  .vitals-row .vital-time,
  .vitals-row .vital-field { flex: none; width: 100%; }
  .pin-display { font-size: 2rem; letter-spacing: 0.2em; }
  .login-card { padding: 28px 20px; }
}

@media (max-width: 480px) {
  .intervention-grid { grid-template-columns: 1fr; }
  .navbar-top { padding: 0 12px; gap: 10px; }
  .protocol-tabs .nav-link { padding: 8px 10px; font-size: 0.8rem; }
}

/* Mobile overlay backdrop */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 999;
}
.sidebar-backdrop.active { display: block; }

/* ============================================================
   PRINT STYLES
   ============================================================ */
@media print {
  .sidebar,
  .navbar-top,
  .no-print,
  .btn,
  .sidebar-backdrop,
  .breadcrumb { display: none !important; }

  #page-content-wrapper { margin-left: 0 !important; }
  .page-content { padding: 0 !important; background: white !important; min-height: auto !important; }
  .card { box-shadow: none !important; border: 1px solid #ccc !important; border-radius: 4px !important; }
  .protocol-section { page-break-inside: avoid; }
  body { background: white !important; font-size: 11pt; }
  .pin-display { border: 2px dashed #333 !important; background: #f5f5f5 !important; color: #000 !important; }
  table { font-size: 10pt; }
  .badge { border: 1px solid #ccc !important; color: #000 !important; background: #eee !important; }
}
