@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@300;400;500;600;700&family=DM+Mono:wght@400;500;600&display=swap');

:root {
  --navy:     #0a2240;
  --navy-lt:  #143a68;
  --blue:     #0c5fa5;
  --blue-lt:  #e8f2fc;
  --teal:     #007b6e;
  --teal-lt:  #e0f4f2;
  --amber:    #d97706;
  --amber-lt: #fef3c7;
  --red:      #dc2626;
  --red-lt:   #fee2e2;
  --green:    #16a34a;
  --green-lt: #dcfce7;
  --bg:       #f1f5f9;
  --card:     #ffffff;
  --border:   #cbd5e1;
  --text:     #0f172a;
  --muted:    #64748b;
  --rad:      12px;
  --rad-sm:   8px;
  --shadow:   0 4px 16px rgba(10,34,64,.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body {
  height: 100%;
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  overscroll-behavior: none;
}

/* ── Top Bar ── */
#topbar {
  background: #0B0F19;
  color: #F8FAFC;
  padding: 0 16px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  box-shadow: 0 2px 12px rgba(0,0,0,.28);
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
#topbar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  user-select: none;
}
.brand-logo-container {
  display: flex;
  align-items: center;
  height: 32px;
}
.brand-logo-full {
  height: 28px;
  width: auto;
  display: block;
}
.brand-logo-icon {
  height: 32px;
  width: auto;
  display: none;
}
.brand-meta {
  display: flex;
  flex-direction: column;
  justify-content: center;
  border-left: 1px solid rgba(255,255,255,0.18);
  padding-left: 10px;
  margin-left: 2px;
}
#topbar .practice {
  font-size: 12px;
  color: #94a3b8;
  font-weight: 500;
  letter-spacing: 0.1px;
  white-space: nowrap;
}
#topbar .practice:hover {
  color: #e2e8f0;
}
.topbar-center {
  display: flex;
  align-items: center;
  gap: 8px;
}
.btn-telemetry-pill {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
}
.pulse-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #22c55e;
  margin-right: 5px;
  box-shadow: 0 0 6px #22c55e;
  animation: pulse-live 1.8s infinite;
}
@keyframes pulse-live {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.35; transform: scale(0.85); }
}
.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
#topbar .btn-menu-toggle {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #f8fafc;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 8px;
  transition: all 0.15s ease;
  cursor: pointer;
}
#topbar .btn-menu-toggle:hover {
  background: rgba(255, 255, 255, 0.16);
  border-color: rgba(255, 255, 255, 0.32);
  color: #ffffff;
}
#topbar .btn-menu-toggle:active {
  transform: scale(0.97);
}

/* ── Topbar Dropdown Menu ── */
.topbar-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 10px);
  width: 290px;
  background: #ffffff;
  border-radius: 12px;
  box-shadow: 0 16px 36px rgba(0,0,0,0.22), 0 4px 12px rgba(0,0,0,0.12);
  border: 1px solid #e2e8f0;
  display: none;
  z-index: 250;
  overflow: hidden;
}
.topbar-dropdown.show {
  display: block;
  animation: dropdownFade 0.15s ease-out;
}
@keyframes dropdownFade {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}
.dropdown-header {
  padding: 12px 14px 10px;
  background: #f8fafc;
  border-bottom: 1px solid #f1f5f9;
}
.dropdown-divider {
  height: 1px;
  background: #f1f5f9;
  margin: 4px 0;
}
.dropdown-item {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 10px 14px;
  font-size: 13.5px;
  font-weight: 500;
  color: #1e293b;
  background: none;
  border: none;
  text-align: left;
  cursor: pointer;
  transition: all 0.15s;
}
.dropdown-item:hover {
  background: #f1f5f9;
  color: #0284c7;
}
.dropdown-item .item-icon {
  margin-right: 10px;
  font-size: 16px;
  line-height: 1;
}
.dropdown-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 14px;
  background: #f8fafc;
  border-top: 1px solid #f1f5f9;
}

.badge {
  font-size: 12px;
  font-family: 'DM Mono', monospace;
  padding: 5px 11px;
  border-radius: 20px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.badge-blue { background: #2563EB; color: white; }
.badge-sim { background: var(--amber); color: white; }
.badge-live { background: #065f46; color: #a7f3d0; border: 1px solid rgba(16,185,129,0.3); }

/* ── Navigation Tabs ── */
#tabnav {
  position: fixed; top: 58px; left: 0; right: 0; z-index: 99;
  background: var(--card);
  display: flex;
  border-bottom: 2px solid var(--border);
  box-shadow: 0 2px 6px rgba(0,0,0,.05);
}
.tab-btn {
  flex: 1; padding: 12px 6px 10px;
  font-size: 13px; font-weight: 600;
  color: var(--muted);
  background: none; border: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  transition: all .2s;
  position: relative;
}
.tab-btn .tab-icon { font-size: 20px; line-height: 1; }
.tab-btn.active { color: var(--blue); }
.tab-btn.active::after {
  content: ''; position: absolute; bottom: -2px; left: 8%; right: 8%;
  height: 3px; background: var(--blue); border-radius: 2px 2px 0 0;
}
.tab-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ── Page Containers ── */
#pages { padding-top: 120px; padding-bottom: 30px; min-height: 100%; }
.page { display: none; padding: 16px; max-width: 960px; margin: 0 auto; }
.page.active { display: block; }

/* ── Cards & Structure ── */
.card {
  background: var(--card);
  border-radius: var(--rad);
  box-shadow: var(--shadow);
  margin-bottom: 18px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.card-header {
  background: var(--navy);
  color: white;
  padding: 13px 18px;
  font-size: 14.5px; font-weight: 600;
  display: flex; align-items: center; justify-content: space-between;
}
.card-header .header-title { display: flex; align-items: center; gap: 8px; }
.card-body { padding: 18px; }

/* ── Forms & Controls ── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}
.form-grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.form-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
@media(max-width: 600px) {
  .form-grid.cols-2, .form-grid.cols-3 { grid-template-columns: 1fr; }
}

.field { display: flex; flex-direction: column; gap: 5px; }
.field.span-2 { grid-column: span 2; }
.field.span-3 { grid-column: span 3; }
@media(max-width: 600px) {
  .field.span-2, .field.span-3 { grid-column: span 1; }
}

label {
  font-size: 11.5px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .5px;
}
input[type=text], input[type=date], input[type=time], input[type=number], select, textarea {
  font-family: inherit; font-size: 15px; color: var(--text);
  background: #f8fafc; border: 1.5px solid var(--border);
  border-radius: var(--rad-sm); padding: 10px 12px;
  outline: none; transition: border-color .15s, background .15s;
  min-height: 44px;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--blue); background: white; box-shadow: 0 0 0 3px var(--blue-lt);
}
textarea { resize: vertical; min-height: 70px; }

/* ── Buttons ── */
.btn {
  font-family: inherit; font-size: 14px; font-weight: 600;
  border-radius: var(--rad-sm); padding: 10px 16px;
  cursor: pointer; border: none; display: inline-flex;
  align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; transition: all .15s;
}
.btn-primary { background: var(--blue); color: white; }
.btn-primary:hover { background: #0a4f8c; }
.btn-success { background: var(--green); color: white; }
.btn-success:hover { background: #15803d; }
.btn-danger  { background: var(--red); color: white; }
.btn-outline { background: white; border: 1.5px solid var(--border); color: var(--text); }
.btn-outline:hover { background: #f8fafc; border-color: var(--muted); }
.btn-sm { font-size: 12.5px; padding: 6px 12px; min-height: 34px; }
.btn-lg { font-size: 16px; padding: 14px 22px; min-height: 52px; width: 100%; }

/* ── Pill Buttons & Toggles ── */
.pill-group { display: flex; flex-wrap: wrap; gap: 8px; }
.pill-opt { flex: 1; min-width: 90px; }
.pill-opt input[type=radio] { display: none; }
.pill-opt label {
  display: block; text-align: center; padding: 10px 8px;
  background: #f8fafc; border: 1.5px solid var(--border);
  border-radius: var(--rad-sm); font-size: 13.5px; font-weight: 600;
  color: var(--text); cursor: pointer; text-transform: none;
  min-height: 44px; display: flex; align-items: center; justify-content: center;
  transition: all .15s;
}
.pill-opt input[type=radio]:checked + label {
  background: var(--blue-lt); border-color: var(--blue); color: var(--blue);
  box-shadow: 0 0 0 1px var(--blue);
}

.toggle-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 11px 0; border-bottom: 1px solid #f1f5f9;
}
.toggle-label { font-size: 14.5px; font-weight: 500; display: flex; flex-direction: column; }
.toggle-label small { font-size: 12px; color: var(--muted); font-weight: 400; margin-top: 2px; }
.toggle { position: relative; width: 50px; height: 28px; flex-shrink: 0; }
.toggle input { display: none; }
.toggle-track {
  position: absolute; inset: 0; background: #cbd5e1;
  border-radius: 14px; cursor: pointer; transition: .2s;
}
.toggle-track::before {
  content: ''; position: absolute; width: 22px; height: 22px;
  left: 3px; top: 3px; background: white; border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: .2s;
}
.toggle input:checked + .toggle-track { background: var(--green); }
.toggle input:checked + .toggle-track::before { transform: translateX(22px); }

/* ── Live Vitals Grid ── */
.vitals-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 12px;
}
.vital-tile {
  background: #ffffff; border: 1.5px solid #cbd5e1;
  border-radius: var(--rad-sm); padding: 12px 10px; text-align: center;
  position: relative; transition: all .2s;
  box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}
.vital-tile .v-param { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.vital-tile .v-value { font-size: 26px; font-weight: 700; font-family: 'DM Mono', monospace; line-height: 1.2; margin: 4px 0; color: #0f172a; }
.vital-tile .v-unit  { font-size: 11px; color: var(--muted); font-family: 'DM Mono', monospace; }
.vital-tile.stale    { opacity: 0.55; filter: grayscale(80%); border-color: #e2e8f0; background: #f8fafc; }
.vital-tile.stale .v-value { color: #94a3b8; }

/* ── Drug Fast-Tap Buttons ── */
.dose-grid { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.dose-btn {
  flex: 1; min-width: 65px; padding: 12px 6px;
  background: var(--blue-lt); border: 1.5px solid #bfdbfe;
  color: var(--blue); font-size: 16px; font-weight: 700;
  font-family: 'DM Mono', monospace; border-radius: var(--rad-sm);
  cursor: pointer; transition: all .15s;
}
.dose-btn:hover { background: #dbeafe; border-color: var(--blue); }

/* ── Tables & Logs ── */
.table-wrap { overflow-x: auto; margin-top: 10px; }
table.data-table {
  width: 100%; border-collapse: collapse; font-size: 13.5px;
}
table.data-table th, table.data-table td {
  padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left;
}
table.data-table th {
  background: #f8fafc; font-weight: 700; color: var(--navy); font-size: 12px; text-transform: uppercase;
}
table.data-table tr.voided { opacity: .55; text-decoration: line-through; background: #fff1f2; }

/* ── Modal Dialogs ── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(10,34,64,.55);
  backdrop-filter: blur(2px); z-index: 200;
  display: none; align-items: center; justify-content: center; padding: 16px;
}
.modal-overlay.show { display: flex; }
.modal-card {
  background: white; border-radius: var(--rad);
  width: 100%; max-width: 620px; max-height: 90vh;
  display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 10px 25px rgba(0,0,0,.3);
}
.modal-header {
  background: var(--navy); color: white;
  padding: 14px 18px; display: flex; align-items: center; justify-content: space-between;
}
.modal-header h3 { font-size: 16px; font-weight: 700; }
.modal-body { padding: 18px; overflow-y: auto; }
.modal-footer {
  padding: 12px 18px; background: #f8fafc; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 10px;
}

/* ── Signature Canvas ── */
#sig-canvas-wrap {
  border: 2px dashed var(--border); border-radius: var(--rad-sm);
  background: #ffffff; touch-action: none; position: relative;
}
#sig-canvas { width: 100%; height: 160px; display: block; }

/* ── Toast Notifications ── */
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(100px);
  background: var(--navy); color: white; padding: 12px 24px;
  border-radius: 30px; font-size: 14px; font-weight: 600;
  box-shadow: 0 4px 14px rgba(0,0,0,.25); z-index: 300;
  transition: transform .25s ease-out; pointer-events: none;
}
#toast.show { transform: translateX(-50%) translateY(0); }

/* ── Responsive Refinements (Tablets & Mobile) ── */
@media (max-width: 900px) {
  .desktop-only {
    display: none !important;
  }
  #topbar {
    padding: 0 12px;
  }
  #topbar .practice {
    font-size: 11px;
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

@media (max-width: 600px) {
  #topbar {
    padding: 0 10px;
    height: 56px;
  }
  .brand-logo-full {
    display: none !important;
  }
  .brand-logo-icon {
    display: block !important;
    height: 28px;
  }
  .brand-meta {
    padding-left: 8px;
    margin-left: 2px;
  }
  #topbar .practice {
    max-width: 110px;
  }
  .topbar-center .badge {
    padding: 3px 8px;
    font-size: 10px;
  }
  #topbar .btn-menu-toggle {
    padding: 6px 10px;
  }
  .menu-label {
    display: none;
  }
  #tabnav {
    top: 56px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  #tabnav::-webkit-scrollbar {
    display: none;
  }
  .tab-btn {
    min-width: 68px;
    padding: 8px 4px 6px;
    font-size: 11px;
  }
  .tab-btn .tab-icon {
    font-size: 18px;
  }
  #pages {
    padding-top: 108px;
  }
  .topbar-dropdown {
    width: calc(100vw - 20px);
    right: -10px;
  }
}

/* ── Intraoperative Vitals Chart & Timeline ───────────────────────────── */
.chart-container-card {
  position: relative;
  background: white;
  border-radius: 8px;
  border: 1px solid var(--border);
  overflow: hidden;
}

.chart-legend-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: 8px 16px;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  font-size: 11.5px;
}

.chart-legend-items {
  display: flex;
  gap: 14px;
  align-items: center;
  flex-wrap: wrap;
}

.legend-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-weight: 600;
  color: #334155;
}

.legend-indicator {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
}

.chart-svg-wrap {
  width: 100%;
  position: relative;
  background: #ffffff;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.chart-svg-root {
  display: block;
  user-select: none;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.chart-col-hover {
  fill: transparent;
  cursor: pointer;
  transition: fill 0.15s ease;
}
.chart-col-hover:hover {
  fill: rgba(2, 132, 199, 0.06);
}

.chart-annotation-marker {
  cursor: pointer;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.15));
  transition: transform 0.15s ease;
}
.chart-annotation-marker:hover {
  transform: scale(1.18);
}

/* Timeline Medication & Milestone Grid */
.timeline-meds-container {
  width: 100%;
  background: #f8fafc;
  border-top: 1px solid #cbd5e1;
  font-size: 11.5px;
}

.timeline-meds-row {
  display: flex;
  align-items: center;
  border-bottom: 1px solid #e2e8f0;
  min-height: 36px;
}

.timeline-meds-label {
  width: 140px;
  min-width: 140px;
  padding: 6px 12px;
  font-weight: 700;
  color: var(--navy);
  background: #f1f5f9;
  border-right: 1px solid #cbd5e1;
  display: flex;
  align-items: center;
  gap: 6px;
}

.timeline-meds-lane {
  flex: 1;
  position: relative;
  height: 100%;
  min-height: 34px;
}

.timeline-rate-block {
  position: absolute;
  top: 4px;
  bottom: 4px;
  background: #e0f2fe;
  border: 1.5px solid #0284c7;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: #0369a1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0 6px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

.timeline-bolus-chip {
  position: absolute;
  top: 5px;
  transform: translateX(-50%);
  background: #2563eb;
  color: white;
  font-size: 10px;
  font-weight: 700;
  padding: 1.5px 6px;
  border-radius: 10px;
  box-shadow: 0 1px 2px rgba(37,99,235,0.25);
  white-space: nowrap;
  z-index: 2;
}

.timeline-milestone-tag {
  position: absolute;
  top: 5px;
  transform: translateX(-50%);
  background: white;
  border: 1.5px solid #059669;
  color: #065f46;
  font-size: 10px;
  font-weight: 700;
  padding: 1.5px 6px;
  border-radius: 10px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
  white-space: nowrap;
  z-index: 2;
}

.timeline-annot-tag {
  position: absolute;
  top: 5px;
  transform: translateX(-50%);
  background: #fef3c7;
  border: 1px solid #f59e0b;
  color: #92400e;
  font-size: 9.5px;
  font-weight: 600;
  padding: 1.5px 7px;
  border-radius: 10px;
  cursor: pointer;
  white-space: nowrap;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 0 1px 2px rgba(245,158,11,0.15);
  z-index: 2;
}

