@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: var(--navy);
  color: white;
  padding: 0 16px;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  box-shadow: 0 2px 10px rgba(0,0,0,.25);
}
#topbar .brand { display: flex; flex-direction: column; }
#topbar h1 { font-size: 17px; font-weight: 700; letter-spacing: .2px; }
#topbar .practice { font-size: 12px; color: #94a3b8; font-weight: 400; }
.top-actions { display: flex; align-items: center; gap: 10px; }

.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: var(--blue); color: white; }
.badge-sim { background: var(--amber); color: white; }
.badge-live { background: var(--green); color: white; }

/* ── 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: #f8fafc; border: 1.5px solid var(--border);
  border-radius: var(--rad-sm); padding: 12px 10px; text-align: center;
  position: relative; transition: all .2s;
}
.vital-tile .v-param { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; }
.vital-tile .v-value { font-size: 26px; font-weight: 700; font-family: 'DM Mono', monospace; line-height: 1.2; margin: 4px 0; }
.vital-tile .v-unit  { font-size: 11px; color: var(--muted); font-family: 'DM Mono', monospace; }
.vital-tile.ok       { border-color: #86efac; background: #f0fdf4; }
.vital-tile.ok .v-value { color: var(--green); }
.vital-tile.alert    { border-color: #fca5a5; background: #fef2f2; animation: pulse-red 1.2s infinite; }
.vital-tile.alert .v-value { color: var(--red); }
@keyframes pulse-red { 0%,100% { transform: scale(1); } 50% { transform: scale(1.02); } }

/* ── 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); }
