:root {
  --navy: #0b2e4f;
  --navy-dark: #071f38;
  --teal: #0f7a8c;
  --teal-light: #e5f4f6;
  --banner: #fdf6e3;
  --banner-border: #e8d9a0;
  --border: #d5dbe0;
  --text: #202b33;
  --muted: #64748b;
  --green: #1e8e3e;
  --red: #c0392b;
  --amber: #b7791f;
  --bg: #f4f6f8;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

#topbar {
  background: var(--navy);
  color: #fff;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
}
.app-logo { font-weight: 700; font-size: 18px; margin-right: 12px; }
.app-sub { color: #b7c9db; font-size: 13px; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
#weekLabel { font-weight: 600; background: var(--navy-dark); padding: 6px 12px; border-radius: 4px; }

.btn {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 7px 14px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
}
.btn:hover { background: #f0f2f4; }
.btn-advance { background: var(--teal); color: #fff; border: none; font-weight: 600; }
.btn-advance:hover { background: #0c6474; }
.btn-primary { background: var(--teal); color: #fff; border: none; }
.btn-primary:hover { background: #0c6474; }
.btn-danger { background: #fff; color: var(--red); border: 1px solid var(--red); }
.btn-danger:hover { background: #fdecea; }
.btn-sm { padding: 4px 10px; font-size: 12px; }

#shell { display: flex; height: calc(100vh - 52px); }
#sidenav {
  width: 200px;
  background: var(--navy-dark);
  padding: 10px 0;
  flex-shrink: 0;
}
.nav-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: #c7d4e0;
  padding: 12px 18px;
  font-size: 14px;
  cursor: pointer;
  position: relative;
}
.nav-item:hover { background: rgba(255,255,255,0.06); }
.nav-item.active { background: var(--teal); color: #fff; font-weight: 600; }
.badge {
  background: var(--red); color: #fff; border-radius: 10px; padding: 1px 7px; font-size: 11px; margin-left: 6px;
}

#main { flex: 1; overflow-y: auto; padding: 20px 28px; }
.view { display: none; }
.view.active { display: block; }

h2 { margin-top: 0; color: var(--navy); }

.list-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.list-table th {
  background: var(--navy);
  color: #fff;
  text-align: left;
  padding: 9px 12px;
  font-size: 12.5px;
  font-weight: 600;
}
.list-table td { padding: 9px 12px; border-bottom: 1px solid var(--border); }
.list-table tr:hover td { background: var(--teal-light); cursor: pointer; }
.list-table tr.row-disabled { opacity: 0.45; }
.list-table tr.row-disabled td { cursor: not-allowed; }
.list-table tr.row-disabled:hover td { background: none; }

.status-pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 10px;
  font-size: 11.5px;
  font-weight: 600;
}
.status-active { background: #e6f4ea; color: var(--green); }
.status-new { background: #fdecea; color: var(--red); }
.status-handled { background: #eef1f4; color: var(--muted); }

.back-link {
  background: none; border: none; color: var(--teal); cursor: pointer; font-size: 13px; padding: 0 0 12px 0; font-weight: 600;
}

.patient-banner {
  background: var(--banner);
  border: 1px solid var(--banner-border);
  border-radius: 4px;
  padding: 10px 16px;
  margin-bottom: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 24px;
  font-size: 13.5px;
}
.patient-banner .pname { font-size: 17px; font-weight: 700; color: var(--navy); flex-basis: 100%; }
.patient-banner b { color: var(--navy); }

.chart-tabs { display: flex; border-bottom: 2px solid var(--border); margin-bottom: 16px; }
.chart-tab, .debrief-toplevel-tab, .edit-toplevel-tab {
  background: none; border: none; padding: 10px 18px; cursor: pointer; font-size: 13.5px; font-weight: 600; color: var(--muted);
  border-bottom: 3px solid transparent; margin-bottom: -2px;
}
.chart-tab.active, .debrief-toplevel-tab.active, .edit-toplevel-tab.active { color: var(--teal); border-bottom-color: var(--teal); }
.chart-panel { display: none; }
.chart-panel.active { display: block; }

.card {
  background: #fff; border: 1px solid var(--border); border-radius: 6px; padding: 14px 16px; margin-bottom: 14px;
}
.card h3 { margin: 0 0 10px 0; font-size: 14px; color: var(--navy); border-bottom: 1px solid var(--border); padding-bottom: 6px;}
.card-row { margin-bottom: 6px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.note-block { border-left: 3px solid var(--teal); padding: 8px 12px; margin-bottom: 12px; background: #fafbfc; }
.note-block.old { border-left-color: var(--muted); }
.note-meta { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.note-block textarea, .note-field {
  width: 100%; border: 1px solid var(--border); border-radius: 4px; padding: 6px 8px; font-family: inherit; font-size: 13px; margin-top: 4px;
}
.note-block label { font-weight: 600; font-size: 12.5px; color: var(--navy); display: block; margin-top: 8px; }

.med-row, .lab-row, .order-row {
  display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border);
}
.med-row:last-child, .lab-row:last-child, .order-row:last-child { border-bottom: none; }
.med-name { font-weight: 600; }
.med-status-stopped { text-decoration: line-through; color: var(--muted); }
.tag { font-size: 11px; padding: 1px 7px; border-radius: 8px; background: var(--teal-light); color: var(--teal); margin-left: 6px; }
.tag-warn { background: #fdecea; color: var(--red); }

.form-row { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.form-row input, .form-row select {
  border: 1px solid var(--border); border-radius: 4px; padding: 7px 9px; font-size: 13px;
}

.quick-orders { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.quick-orders button { font-size: 12.5px; }

table.results-table { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 12.5px; }
table.results-table th, table.results-table td { text-align: left; padding: 4px 8px; border-bottom: 1px solid var(--border); }
.flag-H, .flag-L { color: var(--red); font-weight: 700; }

.req-item { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.req-item:last-child { border-bottom: none; }
.req-status { font-size: 11px; padding: 2px 8px; border-radius: 8px; font-weight: 600; }
.req-satisfied { background: #e6f4ea; color: var(--green); }
.req-missed { background: #fdecea; color: var(--red); }
.req-pending { background: #f1f3f5; color: var(--muted); }

.inbox-header { display: flex; justify-content: space-between; align-items: center; }
.inbox-filters button { margin-left: 6px; }
.filter-btn.active { background: var(--teal); color: #fff; border-color: var(--teal); }

.action-btns { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0; }

.toast {
  position: fixed; bottom: 24px; right: 24px; background: var(--navy); color: #fff; padding: 12px 18px; border-radius: 6px;
  box-shadow: 0 3px 10px rgba(0,0,0,0.25); display: none; max-width: 360px; font-size: 13.5px; z-index: 999;
}
.toast.show { display: block; }
.toast.severe { background: var(--red); }
.toast.mild { background: var(--amber); }

.modal-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.4); align-items: center; justify-content: center; z-index: 1000;
}
.modal-overlay.show { display: flex; }
.modal-box { background: #fff; border-radius: 8px; padding: 20px; max-width: 420px; width: 90%; }
.modal-box h3 { margin-top: 0; }
.modal-box .form-row { flex-direction: column; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

.empty-state { color: var(--muted); font-style: italic; padding: 20px 0; }

.verdict-badge { display: inline-block; padding: 2px 10px; border-radius: 10px; font-size: 11.5px; font-weight: 700; }
.verdict-good { background: #e6f4ea; color: var(--green); }
.verdict-reconsider { background: #fdecea; color: var(--red); }
.verdict-documented { background: #eef1f4; color: var(--muted); }

.modal-options { display: flex; flex-direction: column; gap: 8px; margin: 10px 0; }
.modal-options label { font-size: 13.5px; display: flex; align-items: center; gap: 8px; cursor: pointer; }
.modal-box textarea { width: 100%; border: 1px solid var(--border); border-radius: 4px; padding: 8px; font-family: inherit; font-size: 13px; margin-top: 6px; min-height: 70px; }

.debrief-case-block { background: #fff; border: 1px solid var(--border); border-radius: 6px; margin-bottom: 12px; }
.debrief-case-header { padding: 10px 14px; cursor: pointer; display: flex; justify-content: space-between; align-items: center; font-weight: 600; color: var(--navy); }
.debrief-case-header:hover { background: var(--teal-light); }
.debrief-case-body { padding: 0 14px 14px 14px; display: none; }
.debrief-case-block.open .debrief-case-body { display: block; }
.debrief-inbox-item { border: 1px solid var(--border); border-radius: 6px; padding: 10px 14px; margin-bottom: 10px; background: #fff; }
.note-savebox { margin-top: 8px; }

.edit-field-row { display: grid; grid-template-columns: 140px 1fr; gap: 8px; align-items: start; margin-bottom: 8px; }
.edit-field-row label { font-weight: 600; font-size: 12.5px; color: var(--navy); padding-top: 6px; }
.edit-field-row input, .edit-field-row textarea { width: 100%; border: 1px solid var(--border); border-radius: 4px; padding: 6px 8px; font-family: inherit; font-size: 13px; }
.edit-field-row textarea { min-height: 50px; }
.list-mini-item { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--border); }
.list-mini-item input { border: 1px solid var(--border); border-radius: 4px; padding: 5px 7px; font-size: 12.5px; }
.lock-icon-row { display: flex; align-items: center; gap: 8px; }
