:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-strong: #eef3f8;
  --text: #111827;
  --muted: #65758b;
  --line: #d7e0ea;
  --brand: #0b1f3a;
  --brand-strong: #07172c;
  --brand-soft: #e8eef7;
  --accent: #2f6fed;
  --danger: #b42318;
  --danger-soft: #fff0ed;
  --shadow: 0 18px 40px rgba(11, 31, 58, 0.08);
}

* {
  box-sizing: border-box;
}

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

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

.topbar {
  min-height: 86px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 32px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(14px);
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  color: var(--brand);
  font-size: 30px;
  line-height: 1.1;
}

h2 {
  font-size: 22px;
  line-height: 1.2;
}

h3 {
  font-size: 16px;
}

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
  margin-bottom: 5px;
}

.muted {
  color: var(--muted);
  margin-top: 8px;
}

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

.mode-switch {
  display: inline-flex;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
}

.mode-button {
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  padding: 0 12px;
  background: transparent;
  color: var(--brand);
  cursor: pointer;
  font-weight: 800;
}

.mode-button.active {
  background: var(--brand);
  color: #fff;
}

.connection {
  min-width: 132px;
  padding: 9px 12px;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand);
  text-align: center;
  font-weight: 800;
  font-size: 13px;
}

.user-badge {
  max-width: 230px;
  padding: 9px 12px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--brand);
  font-size: 13px;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.logout-button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--brand);
  cursor: pointer;
  font-weight: 900;
  padding: 0 12px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 420px;
  gap: 24px;
  padding: 24px 32px 40px;
}

.login-layout {
  min-height: calc(100vh - 86px);
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(520px, 100%);
  display: grid;
  gap: 22px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-presets {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.login-presets button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--brand);
  cursor: pointer;
  font-weight: 900;
}

.layout.single {
  grid-template-columns: 1fr;
}

.patient-layout {
  grid-template-columns: minmax(0, 1fr) 420px;
}

.workbench,
.panel,
.patient-hero,
.detail-page {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.workbench,
.panel,
.patient-hero,
.detail-page {
  padding: 22px;
}

.patient-hero {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  background: var(--brand);
  color: #fff;
}

.patient-hero .eyebrow,
.patient-hero .muted {
  color: #d9e6f8;
}

.full-row {
  grid-column: 1 / -1;
}

.section-title,
.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.section-title.compact {
  margin-bottom: 14px;
}

.icon-button {
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--brand);
  cursor: pointer;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 22px;
}

.metric {
  min-height: 82px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
}

.metric span {
  display: block;
  color: var(--brand);
  font-size: 30px;
  font-weight: 900;
}

.metric small {
  color: var(--muted);
  font-weight: 800;
}

.metric.urgent {
  background: var(--danger-soft);
  border-color: #ffd3cb;
}

.split-content {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(320px, 0.95fr);
  gap: 22px;
}

.subhead {
  margin-bottom: 10px;
  color: var(--brand);
}

.queue,
.history-list,
.history {
  display: grid;
  gap: 10px;
}

.history-day {
  display: grid;
  gap: 10px;
  padding-top: 2px;
}

.history-day + .history-day {
  margin-top: 18px;
}

.history-day h3 {
  color: var(--muted);
  text-transform: capitalize;
}

.event-card {
  min-height: 74px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.event-main {
  display: grid;
  gap: 4px;
  min-width: 0;
  flex: 1;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.event-type {
  font-weight: 900;
}

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

.badge {
  flex: 0 0 auto;
  padding: 6px 9px;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 12px;
  font-weight: 900;
}

.badge.new,
.badge[data-status="new"] {
  background: var(--danger-soft);
  color: var(--danger);
}

.badge[data-status="in_progress"] {
  background: #fff7df;
  color: #8a5a00;
}

.badge[data-status="closed"] {
  background: #edf7ee;
  color: #17633a;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 220px;
  gap: 14px;
  margin-bottom: 22px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
}

.empty-state {
  min-height: 120px;
  display: grid;
  place-items: center;
  padding: 20px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

.compact-empty {
  min-height: 74px;
}

.detail-layout {
  padding: 24px 32px 40px;
}

.detail-page {
  max-width: 1080px;
  margin: 0 auto;
}

.back-button {
  min-height: 40px;
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--brand);
  cursor: pointer;
  font-weight: 900;
  padding: 0 14px;
}

.detail-grid {
  display: grid;
  gap: 10px;
}

.detail-grid.wide {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 20px;
}

.detail-row {
  display: grid;
  grid-template-columns: 140px minmax(0, 1fr);
  gap: 10px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.detail-row strong {
  color: var(--muted);
  font-size: 13px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 20px;
}

.primary,
.secondary {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  padding: 0 14px;
  cursor: pointer;
  font-weight: 900;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.primary {
  background: var(--brand);
  color: #fff;
}

.patient-hero .primary {
  background: #fff;
  color: var(--brand);
}

.secondary {
  background: var(--surface-strong);
  color: var(--brand);
}

.small {
  min-height: 34px;
  padding: 0 10px;
  font-size: 13px;
}

.inline-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.form {
  display: grid;
  gap: 13px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

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

textarea {
  resize: vertical;
}

.patient-status {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.status-item {
  min-height: 82px;
  display: grid;
  align-content: center;
  gap: 4px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
}

.status-item strong {
  color: var(--brand);
}

.status-item span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

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

.panel.flat {
  box-shadow: none;
}

.table-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.table-row {
  display: grid;
  grid-template-columns: 1.1fr 1.3fr 1fr;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
}

.table-row span {
  color: var(--muted);
  font-size: 14px;
  overflow-wrap: anywhere;
}

.compact-table .table-row {
  grid-template-columns: 1fr 180px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.chips span {
  padding: 9px 11px;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand);
  font-weight: 900;
  font-size: 13px;
}

@media (max-width: 980px) {
  .layout,
  .patient-layout,
  .split-content,
  .admin-grid {
    grid-template-columns: 1fr;
  }

  .layout,
  .detail-layout {
    padding: 18px;
  }

  .topbar {
    padding: 16px 18px;
  }

  .detail-grid.wide {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  .topbar,
  .top-actions,
  .patient-hero {
    align-items: stretch;
    flex-direction: column;
  }

  .mode-switch {
    width: 100%;
  }

  .mode-button {
    flex: 1;
  }

  .login-presets {
    grid-template-columns: 1fr;
  }

  .metrics,
  .patient-status,
  .toolbar {
    grid-template-columns: 1fr;
  }

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

  .table-row,
  .compact-table .table-row {
    grid-template-columns: 1fr;
  }
}
