:root {
  color-scheme: light;
  --bg: #f7f8f6;
  --ink: #1e2522;
  --muted: #65706b;
  --line: #d9ded8;
  --source: #f2f7ee;
  --source-line: #c8dac1;
  --subscriber: #eef5f8;
  --subscriber-line: #c5d8df;
  --accent: #256f5d;
  --accent-dark: #184f42;
  --surface: #ffffff;
  --shadow: 0 16px 40px rgba(22, 33, 28, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 0 14px;
  font: inherit;
  font-weight: 650;
  cursor: pointer;
}

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

button:hover {
  border-color: var(--accent);
}

.icon-button {
  display: inline-grid;
  width: 28px;
  height: 28px;
  min-height: 28px;
  place-items: center;
  padding: 0;
  border-radius: 999px;
  font-size: 20px;
  line-height: 1;
}

.icon-button.danger {
  border-color: #e5c4c4;
  color: #8a2d2d;
}

.icon-button.danger:hover {
  background: #fff1f1;
  border-color: #c65c5c;
}

.app-shell {
  width: min(1440px, calc(100vw - 40px));
  margin: 0 auto;
  padding: 28px 0 40px;
}

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

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1.05;
  letter-spacing: 0;
}

.topbar p {
  margin-top: 8px;
  color: var(--muted);
  font-size: 16px;
}

.role-control {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  padding: 12px;
  margin-bottom: 20px;
}

.role-button {
  width: 100%;
  margin-top: 12px;
}

.control-label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

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

.chip {
  --patient-color: var(--accent);
  --patient-bg: color-mix(in srgb, var(--patient-color) 14%, white);
  min-height: 32px;
  border-radius: 999px;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 700;
  border-color: color-mix(in srgb, var(--patient-color) 45%, white);
  background: var(--patient-bg);
  color: color-mix(in srgb, var(--patient-color) 60%, #111);
}

.chip.selected {
  background: var(--patient-color);
  border-color: var(--patient-color);
  color: white;
}

.party-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
}

.party,
.transport {
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.party {
  min-width: 0;
  min-height: 520px;
  padding: 20px;
}

.subscriber {
  background: var(--subscriber);
  border-color: var(--subscriber-line);
}

.source {
  background: var(--source);
  border-color: var(--source-line);
}

.party-heading,
.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.party-heading span,
.metric-label,
.section-heading span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.party-heading strong {
  display: block;
  margin-top: 4px;
  font-size: 22px;
}

.metric-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.metric-row > div {
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 8px;
  padding: 14px;
}

.metric-row strong {
  display: block;
  margin-top: 6px;
  font-size: 28px;
  line-height: 1;
}

h2 {
  margin: 18px 0 10px;
  font-size: 17px;
}

.stack,
.timeline {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.empty {
  color: var(--muted);
  font-size: 14px;
}

.card,
.log-entry {
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(20, 30, 26, 0.08);
  border-radius: 8px;
  padding: 12px;
  min-width: 0;
}

.card summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  font-weight: 700;
}

.card-title {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.card-title strong,
.card-title span {
  overflow-wrap: anywhere;
}

.card-title span,
.card-content {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.card-content {
  margin-top: 10px;
  padding-left: 2px;
}

.summary-trail {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  flex-shrink: 0;
}

.patient-badge {
  --patient-color: var(--accent);
  --patient-bg: color-mix(in srgb, var(--patient-color) 16%, white);
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 10px;
  border: 1px solid color-mix(in srgb, var(--patient-color) 44%, white);
  border-radius: 999px;
  background: var(--patient-bg);
  color: color-mix(in srgb, var(--patient-color) 62%, #111);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.card-actions {
  display: inline-flex;
  gap: 6px;
}

.card pre {
  width: 100%;
  max-width: 100%;
  max-height: 300px;
  overflow: auto;
  margin: 12px 0 0;
  padding: 12px;
  border-radius: 8px;
  background: #17211d;
  color: #edf6f1;
  font-size: 12px;
  line-height: 1.45;
  white-space: pre;
}

.transport {
  margin-top: 18px;
  padding: 20px;
  background: var(--surface);
}

.log-entry {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: 12px;
}

.log-entry time {
  color: var(--muted);
  font-size: 13px;
}

.log-entry strong {
  display: block;
  margin-bottom: 3px;
}

.log-entry span {
  color: var(--muted);
  font-size: 14px;
}

@media (max-width: 900px) {
  .app-shell {
    width: min(100vw - 24px, 720px);
    padding-top: 18px;
  }

  .topbar,
  .party-grid {
    grid-template-columns: 1fr;
    display: grid;
  }

  .topbar-actions {
    justify-content: stretch;
  }

  .topbar-actions button {
    flex: 1;
  }

  .log-entry {
    grid-template-columns: 1fr;
  }
}
