:root {
  color-scheme: light;
  --bg: #f5f6f1;
  --panel: #ffffff;
  --ink: #1d2528;
  --muted: #657174;
  --line: #d9ded8;
  --accent: #245b5f;
  --accent-2: #8a4b33;
  --warn: #b42318;
}

[hidden] { display: none !important; }
* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
}

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

button {
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  padding: 0.72rem 1rem;
  cursor: pointer;
}

button:hover { filter: brightness(0.96); }
button:disabled, textarea:disabled { opacity: 0.55; cursor: not-allowed; }
button.secondary { background: #e7ebe7; color: var(--ink); }
button.compact { padding: 0.48rem 0.72rem; }

input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.72rem;
  background: white;
  color: var(--ink);
}

select { min-height: 42px; }
textarea { resize: vertical; min-height: 74px; max-height: 180px; }
label span { display: block; margin-bottom: 6px; color: var(--muted); font-size: 0.88rem; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 4px; font-size: clamp(1.35rem, 2vw, 1.85rem); }
h2 { margin-bottom: 4px; font-size: 1.08rem; }
h3 { margin-bottom: 10px; font-size: 0.96rem; }
p { margin-bottom: 0; }
pre { white-space: pre-wrap; word-break: break-word; margin: 0; font-family: inherit; color: var(--muted); }

.shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-panel {
  width: min(440px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  box-shadow: 0 18px 50px rgb(29 37 40 / 0.08);
}

.brand-header p, .eyebrow {
  color: var(--accent-2);
  text-transform: uppercase;
  letter-spacing: 0;
  font-size: 0.78rem;
  font-weight: 700;
  margin-bottom: 6px;
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 22px 0 16px;
}

.tabs button { background: #e7ebe7; color: var(--ink); }
.tabs button.active { background: var(--accent); color: white; }
.stack { display: grid; gap: 14px; }
.error { color: var(--warn); min-height: 1.2rem; margin: 0; }
.notice { color: var(--accent); overflow-wrap: anywhere; }
.muted { color: var(--muted); }

.workspace {
  width: min(1280px, 100%);
  min-height: min(850px, calc(100vh - 48px));
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 16px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px 20px;
}

.screen { min-height: 0; }
.admin-grid {
  display: grid;
  grid-template-columns: minmax(260px, 0.72fr) minmax(360px, 1.28fr);
  gap: 16px;
}
.split-grid {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 16px;
}
.patient-grid {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 16px;
}
.span-2 { grid-column: 1 / -1; }

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

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.section-head p { color: var(--muted); font-size: 0.9rem; }

.list {
  display: grid;
  gap: 10px;
  max-height: 460px;
  overflow: auto;
}

.list-item, .clinical-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcf9;
  min-width: 0;
}

.list-item strong, .clinical-item strong { overflow-wrap: anywhere; }
.list-item p, .clinical-item p, .list-button small {
  color: var(--muted);
  font-size: 0.88rem;
  margin: 4px 0 0;
  overflow-wrap: anywhere;
}

.roster-layout {
  display: grid;
  grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
  gap: 16px;
}

.patient-assignment { grid-template-columns: minmax(0, 1fr) minmax(170px, 240px); }

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 0 0.72rem;
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
}
.active-badge { background: #dcebe4; color: #1f5c3e; }
.muted-badge { background: #ecefeb; color: var(--muted); }

.list-button {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  text-align: left;
  background: #fbfcf9;
  color: var(--ink);
  border: 1px solid var(--line);
  padding: 12px;
}
.list-button.selected { border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }
.list-button em {
  color: var(--muted);
  font-style: normal;
  font-size: 0.8rem;
}

.detail-panel { grid-template-rows: auto auto minmax(0, 1fr); }
.consent-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 1fr));
  gap: 10px;
}
.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px;
  background: #fbfcf9;
}
.check-row input { width: 18px; height: 18px; flex: 0 0 auto; }
.check-row span { margin: 0; color: var(--ink); font-size: 0.92rem; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }

.clinical {
  border-top: 1px solid var(--line);
  padding-top: 16px;
}
.clinical-section {
  display: grid;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 14px;
}
.clinical-section:last-child { border-bottom: 0; padding-bottom: 0; }
.clinical-section .message { max-width: 100%; }

.chat-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 14px;
}
.messages {
  overflow-y: auto;
  padding: 4px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.message {
  max-width: 78%;
  padding: 12px 14px;
  border-radius: 8px;
  line-height: 1.45;
  white-space: pre-wrap;
}
.message.user { align-self: flex-end; background: var(--accent); color: white; }
.message.assistant { align-self: flex-start; background: #edf1ec; color: var(--ink); }
.message.flagged { outline: 2px solid var(--warn); }
.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 18px;
  color: var(--muted);
  background: #fbfcf9;
}
.compact-empty { padding: 12px; }

@media (max-width: 880px) {
  .shell { padding: 12px; place-items: stretch; }
  .workspace { min-height: calc(100vh - 24px); }
  .topbar { align-items: flex-start; }
  .admin-grid, .split-grid, .patient-grid, .roster-layout {
    grid-template-columns: 1fr;
  }
  .span-2 { grid-column: auto; }
  .patient-assignment { grid-template-columns: 1fr; }
  .consent-grid { grid-template-columns: 1fr; }
  .composer { grid-template-columns: 1fr; }
  .message { max-width: 92%; }
}
