:root {
  --ink: #17212b;
  --muted: #607080;
  --line: #dbe3ea;
  --panel: #ffffff;
  --page: #f3f6f8;
  --nav: #182734;
  --nav-soft: #253849;
  --accent: #0c7b75;
  --accent-strong: #075e5a;
  --warn: #b2432f;
  --warn-soft: #fff0ed;
  --ok-soft: #e8f7ef;
  --focus: #2563eb;
  font-family: Inter, Segoe UI, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--page);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px 1fr;
}

.sidebar {
  background: var(--nav);
  color: #f9fbfc;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: var(--accent);
  border-radius: 8px;
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  color: #bac8d3;
  font-size: 13px;
  margin-top: 2px;
}

.nav-stack {
  display: grid;
  gap: 8px;
}

.nav-item {
  width: 100%;
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 10px;
  align-items: center;
  text-align: left;
  color: #ecf3f8;
  border: 0;
  border-radius: 8px;
  padding: 10px 12px;
  background: transparent;
}

.nav-item.active,
.nav-item:hover {
  background: var(--nav-soft);
}

.connection-panel {
  margin-top: auto;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding-top: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.14);
}

.connection-panel label {
  grid-column: 1 / -1;
  color: #bac8d3;
  font-size: 12px;
  text-transform: uppercase;
}

.connection-panel input {
  min-width: 0;
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #f9fbfc;
  background: #10202d;
  border-radius: 8px;
  padding: 9px 10px;
}

.main {
  padding: 22px;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.2;
}

h2 {
  font-size: 16px;
}

.topbar-actions,
.chart-actions,
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(340px, 1fr);
  grid-template-areas:
    "patients admissions"
    "chart chart"
    "activity activity";
  gap: 16px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  min-width: 0;
}

.patient-panel {
  grid-area: patients;
}

.admission-panel {
  grid-area: admissions;
}

.chart-panel {
  grid-area: chart;
}

.activity-panel {
  grid-area: activity;
}

.panel-header {
  min-height: 72px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-header p {
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}

.toolbar {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.toolbar input {
  min-width: 0;
  width: 100%;
}

input,
select,
textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 11px;
  background: #fff;
  color: var(--ink);
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.primary-button,
.secondary-button,
.danger-button,
.icon-button {
  border-radius: 8px;
  min-height: 38px;
  border: 1px solid transparent;
  padding: 8px 12px;
  white-space: nowrap;
}

.primary-button {
  color: white;
  background: var(--accent);
}

.primary-button:hover {
  background: var(--accent-strong);
}

.secondary-button {
  background: #f7fafc;
  border-color: var(--line);
  color: var(--ink);
}

.danger-button {
  background: var(--warn);
  color: white;
}

.icon-button {
  min-width: 38px;
  background: #eef4f7;
  border-color: var(--line);
}

.status-pill {
  min-height: 34px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  padding: 6px 10px;
  background: #fff7df;
  color: #665000;
  font-size: 13px;
}

.status-pill.online {
  background: var(--ok-soft);
  color: #17623d;
}

.status-pill.offline {
  background: var(--warn-soft);
  color: var(--warn);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, auto);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.segmented button {
  border: 0;
  background: #fff;
  padding: 8px 10px;
}

.segmented button.active {
  color: white;
  background: var(--accent);
}

.list {
  max-height: 390px;
  overflow: auto;
}

.list-item {
  width: 100%;
  display: grid;
  gap: 6px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: white;
  text-align: left;
  padding: 13px 16px;
}

.list-item:hover,
.list-item.active {
  background: #eef8f7;
}

.item-title {
  font-weight: 700;
}

.item-meta,
.empty-state {
  color: var(--muted);
  font-size: 13px;
}

.item-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 8px;
  padding: 3px 8px;
  background: #eef3f7;
  color: #334553;
  font-size: 12px;
}

.tag.active {
  background: var(--ok-soft);
  color: #17623d;
}

.tag.stopped,
.tag.deleted {
  background: var(--warn-soft);
  color: var(--warn);
}

.medication-table-wrap {
  overflow: auto;
}

.medication-table {
  width: 100%;
  border-collapse: collapse;
}

.medication-table th,
.medication-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

.medication-table th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  background: #f8fafb;
}

.row-actions {
  display: flex;
  gap: 8px;
}

.activity-feed {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 0;
}

.activity-card {
  padding: 14px 16px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.activity-card strong {
  display: block;
  margin-bottom: 4px;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(9, 20, 31, 0.55);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 20;
}

.modal[hidden] {
  display: none;
}

.modal-panel {
  width: min(760px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 20px 70px rgba(0, 0, 0, 0.25);
}

.modal-header,
.modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.modal-actions {
  border-top: 1px solid var(--line);
  border-bottom: 0;
  justify-content: flex-end;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  padding: 16px;
}

label {
  display: grid;
  gap: 6px;
  color: #405262;
  font-size: 13px;
  font-weight: 700;
}

.wide {
  grid-column: 1 / -1;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
}

.check-row input {
  width: 18px;
  height: 18px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: min(420px, calc(100vw - 40px));
  background: #10202d;
  color: white;
  padding: 13px 15px;
  border-radius: 8px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.25);
  z-index: 30;
}

.empty-state {
  padding: 18px 16px;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    padding: 14px;
  }

  .nav-stack {
    grid-template-columns: repeat(4, 1fr);
  }

  .connection-panel {
    margin-top: 0;
  }

  .workspace-grid {
    grid-template-columns: 1fr;
    grid-template-areas:
      "patients"
      "admissions"
      "chart"
      "activity";
  }
}

@media (max-width: 640px) {
  .main {
    padding: 14px;
  }

  .topbar,
  .panel-header,
  .toolbar,
  .chart-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .nav-stack {
    grid-template-columns: repeat(2, 1fr);
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .segmented {
    width: 100%;
    grid-template-columns: repeat(3, 1fr);
  }
}
