:root {
  color-scheme: dark;

  --bg-primary: #0f1218;
  --bg-surface: #171c26;
  --bg-surface-alt: #1d2330;
  --bg-input: #1b2130;
  --text-primary: #f2f4f8;
  --text-secondary: #9ea6b5;
  --text-tertiary: #70798c;
  --accent: #d7a83d;
  --accent-muted: #4c3d1b;
  --success: #6dc48a;
  --danger: #df6f7a;
  --border: #2a3241;
  --border-strong: #3a4559;
  --surface-shadow: rgba(4, 7, 14, 0.42);

  --radius-panel: 16px;
  --radius-control: 10px;
  --radius-pill: 999px;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
}

:root[data-theme='light'] {
  color-scheme: light;

  --bg-primary: #eef1f6;
  --bg-surface: #ffffff;
  --bg-surface-alt: #f5f7fb;
  --bg-input: #f2f4f8;
  --text-primary: #1a1d26;
  --text-secondary: #5e6778;
  --text-tertiary: #7d8698;
  --accent: #8f5d0d;
  --accent-muted: #d8c39e;
  --success: #2e8f57;
  --danger: #c65460;
  --border: #d7ddea;
  --border-strong: #c4ccdd;
  --surface-shadow: rgba(24, 31, 47, 0.08);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

[hidden] {
  display: none !important;
}

body {
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: 'Avenir Next', 'Avenir', 'Segoe UI', 'Helvetica Neue', sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='56' height='56' viewBox='0 0 56 56'%3E%3Crect width='56' height='56' fill='none'/%3E%3Cpath d='M0 55.5h56M55.5 0v56' stroke='%2326303f' stroke-width='1'/%3E%3C/svg%3E");
}

:root[data-theme='light'] body {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='56' height='56' viewBox='0 0 56 56'%3E%3Crect width='56' height='56' fill='none'/%3E%3Cpath d='M0 55.5h56M55.5 0v56' stroke='%23dde3ef' stroke-width='1'/%3E%3C/svg%3E");
}

.shell {
  max-width: 1520px;
  min-height: 100vh;
  margin: 0 auto;
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

h1,
h2,
h3 {
  font-family: 'Baskerville', 'Times New Roman', serif;
  letter-spacing: 0.01em;
}

h1 {
  font-size: 31px;
  line-height: 1.08;
  text-transform: uppercase;
  font-weight: 700;
}

h2 {
  font-size: 18px;
  text-transform: uppercase;
  font-weight: 700;
}

h3 {
  font-size: 12px;
  text-transform: uppercase;
  color: var(--text-secondary);
  letter-spacing: 0.08em;
}

.kicker {
  font-size: 11px;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin-bottom: 6px;
}

.meta {
  color: var(--text-secondary);
  font-size: 13px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--space-4);
  align-items: center;
  padding: var(--space-4) var(--space-5);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-panel);
  background: var(--bg-surface);
  box-shadow: 0 10px 24px var(--surface-shadow);
  position: sticky;
  top: 12px;
  z-index: 15;
}

.brand-wrap {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.brand-mark {
  width: 14px;
  height: 52px;
  background: var(--accent);
  border-radius: 4px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  justify-content: flex-end;
}

.api-settings {
  grid-column: 1 / -1;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  background: var(--bg-surface-alt);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.api-settings-row {
  display: flex;
  align-items: flex-end;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.layout {
  display: grid;
  gap: var(--space-4);
  align-items: start;
  grid-template-columns: minmax(320px, 1fr) minmax(340px, 1.06fr) minmax(420px, 1.24fr);
}

.column {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.panel {
  border: 1px solid var(--border);
  background: var(--bg-surface);
  border-radius: var(--radius-panel);
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  box-shadow: 0 8px 18px var(--surface-shadow);
  animation: panel-enter 300ms ease both;
}

.column > .panel:nth-child(2) {
  animation-delay: 50ms;
}

.column > .panel:nth-child(3) {
  animation-delay: 100ms;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--space-3);
}

.panel-ai {
  border-color: var(--accent-muted);
  background: var(--bg-surface-alt);
}

.accent-title {
  color: var(--accent);
}

.form-grid {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

label,
.search-label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
}

.input-row {
  display: grid;
  gap: var(--space-2);
  grid-template-columns: 1fr 1fr;
}

input[type='text'],
input[type='number'],
input[type='password'],
input[type='date'],
input[type='time'],
input[type='datetime-local'],
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  background: var(--bg-input);
  color: var(--text-primary);
  padding: 11px 12px;
  font-family: inherit;
  font-size: 14px;
}

textarea {
  resize: vertical;
  min-height: 84px;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
}

button {
  border: 1px solid var(--accent);
  border-radius: var(--radius-control);
  background: var(--accent);
  color: #151515;
  padding: 11px 14px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.2s ease;
}

:root[data-theme='light'] button {
  color: #ffffff;
}

button:hover {
  filter: brightness(1.05);
}

button:active {
  transform: translateY(1px);
}

button.ghost {
  background: transparent;
  color: var(--accent);
}

button.ghost:hover {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

.full-width {
  width: 100%;
}

.prompt-label {
  margin-bottom: var(--space-2);
}

fieldset {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: var(--space-3);
}

legend {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
  padding: 0 4px;
}

.domains-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px;
}

.chip-check {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-direction: row;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 11px;
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 12px;
  letter-spacing: 0.02em;
  text-transform: none;
}

.chip-check input,
.inline-check input {
  accent-color: var(--accent);
}

.inline-check {
  flex-direction: row;
  align-items: center;
  font-size: 13px;
  letter-spacing: 0;
  text-transform: none;
}

.status-pill {
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 6px 10px;
  font-size: 12px;
  color: var(--text-secondary);
}

.status-pill.ok {
  color: var(--success);
  border-color: color-mix(in srgb, var(--success) 30%, var(--border));
}

.status-pill.bad {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 30%, var(--border));
}

.api-control {
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-1);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  min-width: 280px;
}

.api-control input {
  width: 100%;
}

#patientSearch {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239ea6b5' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E");
  background-size: 15px;
  background-repeat: no-repeat;
  background-position: 10px center;
  padding-left: 34px;
}

.stats-row {
  display: grid;
  gap: var(--space-2);
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.stat-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  background: var(--bg-surface-alt);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-label {
  font-size: 11px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.stat-value {
  font-family: 'Baskerville', 'Times New Roman', serif;
  font-size: 22px;
  letter-spacing: 0.02em;
}

.patients-list,
.bundle-list {
  display: grid;
  gap: 8px;
  background: transparent;
  border: none;
}

.patients-list > .meta,
.bundle-list > .meta {
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 16px;
  text-align: center;
}

.patient-row {
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: 12px 14px;
  transition: background-color 0.18s ease, border-color 0.18s ease;
  background: var(--bg-surface-alt);
}

.patient-row:hover,
.patient-row.active {
  border-color: var(--accent-muted);
}

.patient-main {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.patient-name {
  font-size: 14px;
  font-weight: 700;
}

.patient-meta {
  font-size: 12px;
  color: var(--text-secondary);
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag {
  border: 1px solid var(--border-strong);
  color: var(--text-secondary);
  border-radius: 999px;
  font-size: 10px;
  padding: 2px 8px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.bundle-card,
.care-plan-item {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--bg-surface-alt);
}

.bundle-head,
.care-plan-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-2);
}

.bundle-id {
  font-weight: 700;
}

.bundle-summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.bundle-summary-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  background: var(--bg-surface);
}

.bundle-summary-item span {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
}

.bundle-summary-item strong {
  font-family: 'Baskerville', 'Times New Roman', serif;
  font-size: 15px;
}

.bundle-section {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.bundle-metric-row,
.bundle-line {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  font-size: 13px;
}

.bundle-metric-row span,
.bundle-line span {
  color: var(--text-secondary);
}

.care-plan-head h3 {
  margin: 0;
  font-size: 13px;
  color: var(--text-primary);
}

.care-plan-head select {
  min-width: 132px;
}

.care-plan-section {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.care-plan-section strong {
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.care-plan-section ul {
  padding-left: 18px;
}

.scroll-box {
  max-height: 260px;
  overflow-y: auto;
}

.event-log {
  list-style: none;
  border: 1px solid var(--border);
  border-radius: 12px;
  max-height: 300px;
  overflow-y: auto;
  background: var(--bg-surface-alt);
  display: grid;
  gap: 8px;
  padding: 8px;
}

.event-log li {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  background: var(--bg-surface);
}

.event-log time {
  color: var(--text-tertiary);
  font-size: 11px;
}

.event-log p {
  font-size: 13px;
}

.event-log li.error p {
  color: var(--danger);
}

@keyframes panel-enter {
  from {
    transform: translateY(8px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@media (max-width: 1180px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .topbar {
    position: static;
    grid-template-columns: 1fr;
  }

  .top-actions {
    justify-content: flex-start;
  }
}

@media (max-width: 760px) {
  .shell {
    padding: 14px;
    gap: 14px;
  }

  h1 {
    font-size: 25px;
  }

  .topbar {
    padding: 12px;
  }

  .brand-mark {
    width: 10px;
    height: 42px;
  }

  .stats-row {
    grid-template-columns: 1fr;
  }

  .bundle-summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .input-row {
    grid-template-columns: 1fr;
  }

  .api-control {
    min-width: 100%;
  }
}
