:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #475569;
  --accent: #0f766e;
  --accent-2: #134e4a;
  --border: #dbe3ec;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  background: radial-gradient(circle at top left, #ecfeff 0%, var(--bg) 35%, #e2e8f0 100%);
  color: var(--text);
}
.container {
  width: min(1080px, 94vw);
  margin: 0 auto;
}
.topbar {
  background: #0f172a;
  color: #fff;
  border-bottom: 1px solid #1e293b;
}
.topbar-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.9rem 0;
}
.brand {
  color: #ecfeff;
  text-decoration: none;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.nav {
  display: flex;
  gap: 1rem;
  align-items: center;
}
.nav a, .nav .link-button {
  color: #cbd5e1;
  text-decoration: none;
  background: none;
  border: none;
  font-size: 0.95rem;
  cursor: pointer;
}
.main-content { padding: 1.5rem 0 3rem; }
.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.2rem;
  box-shadow: 0 8px 25px rgba(15, 23, 42, 0.06);
}
.hero { padding: 1.8rem; }
h1 { margin-top: 0; font-size: 1.5rem; }
h2 { margin: 0; font-size: 1.2rem; }
.muted { color: var(--muted); }
.actions { display: flex; gap: 0.75rem; margin-top: 1rem; flex-wrap: wrap; }
.btn {
  background: var(--accent);
  color: white;
  border: none;
  padding: 0.62rem 1rem;
  border-radius: 8px;
  text-decoration: none;
  display: inline-block;
  cursor: pointer;
}
.btn:hover { background: var(--accent-2); }
.btn-secondary {
  background: #e2e8f0;
  color: #1e293b;
}
.form-grid p {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin: 0 0 0.85rem;
}
.form-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  margin: 0 0 1rem;
  padding: 1rem;
}
.form-card legend { font-weight: 700; padding: 0 0.35rem; }
.form-card label {
  align-items: center;
  display: flex;
  gap: 0.5rem;
  margin: 0.45rem 0;
}
.form-card input[type="radio"] { padding: 0; }
.diagnostic-card {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-top: 1rem;
  padding: 1rem;
}
.diagnostic-card h3 { margin: 1rem 0 0.4rem; }
.diagnostic-card pre {
  background: #0f172a;
  border-radius: 10px;
  color: #e2e8f0;
  max-height: 26rem;
  overflow: auto;
  padding: 0.85rem;
  white-space: pre-wrap;
}
input, select, textarea {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.65rem;
  font: inherit;
}
.search-row {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 0.8rem;
}
.search-row input { flex: 1; }
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}
.table th, .table td {
  text-align: left;
  border-bottom: 1px solid var(--border);
  padding: 0.6rem 0.4rem;
  vertical-align: top;
}
.alert {
  border-radius: 8px;
  padding: 0.65rem 0.8rem;
  margin-bottom: 0.8rem;
  border: 1px solid #a7f3d0;
  background: #ecfdf5;
  color: #065f46;
}
.alert-error {
  border-color: #fecaca;
  background: #fef2f2;
  color: #991b1b;
}
.auth-form-panel {
  padding: 1.7rem;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.98) 0%, #ffffff 100%);
}

.auth-form-inner {
  max-width: 340px;
  margin: 0 auto;
}

.auth-card {
  max-width: 480px;
  margin: 1.25rem auto;
  width: 100%;
}

.auth-login-icon {
  display: block;
  width: 88px;
  max-width: 88px;
  height: auto;
  margin: 0 auto 1rem;
  object-fit: contain;
  border-radius: 12px;
}

.auth-form-panel h1 {
  margin-bottom: 0.45rem;
  text-align: center;
}

.auth-form-panel > .muted {
  margin-bottom: 1.1rem;
  text-align: center;
}

.auth-form-inner > .muted {
  margin-bottom: 1.1rem;
  text-align: center;
}

.auth-form {
  margin-top: 0.5rem;
}

.auth-field {
  display: flex;
  flex-direction: column;
  gap: 0.38rem;
  margin-bottom: 1rem;
}

.auth-field label {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text);
}

.auth-field input {
  display: block;
  width: 100%;
  min-height: 46px;
  padding: 0.7rem 0.85rem;
  border-color: #cbd5e1;
  background: #f8fafc;
  transition: border-color 160ms ease, box-shadow 160ms ease, background-color 160ms ease;
}

.auth-field input:focus {
  outline: none;
  border-color: rgba(15, 118, 110, 0.65);
  box-shadow: 0 0 0 4px rgba(45, 212, 191, 0.18);
  background: #ffffff;
}

.auth-help {
  color: var(--muted);
  font-size: 0.82rem;
}

.auth-error {
  color: #991b1b;
  font-size: 0.85rem;
  font-weight: 600;
}

.section-kicker {
  margin: 0 0 0.45rem;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.75rem;
  font-weight: 700;
}

.patient-hero {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  margin-bottom: 1rem;
  padding: 1.6rem;
  background:
    radial-gradient(circle at top right, rgba(45, 212, 191, 0.16) 0%, transparent 34%),
    linear-gradient(180deg, #ffffff 0%, #f7fbfb 100%);
}

.hero-stat {
  min-width: 170px;
  padding: 1rem 1.1rem;
  border-radius: 12px;
  background: linear-gradient(135deg, #f0fdfa 0%, #ccfbf1 100%);
  border: 1px solid #bdeae4;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.hero-stat-label {
  color: var(--muted);
  text-transform: uppercase;
  font-size: 0.74rem;
  letter-spacing: 0.06em;
  font-weight: 700;
}

.hero-stat-value {
  font-size: 2rem;
  font-weight: 800;
  line-height: 1;
}

.comparison-panel {
  margin-bottom: 1rem;
  padding: 1.4rem;
  background:
    radial-gradient(circle at top left, rgba(45, 212, 191, 0.18) 0%, transparent 28%),
    linear-gradient(160deg, #ffffff 0%, #f1fbfa 100%);
}

.comparison-panel-copy {
  margin-bottom: 1rem;
}

.comparison-panel-copy h2 {
  margin-bottom: 0.45rem;
}

.comparison-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: 0.9rem;
  align-items: end;
}

.comparison-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.comparison-field label {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
}

.comparison-select {
  min-height: 44px;
}

.comparison-actions {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.comparison-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  max-width: 280px;
}

.table-header {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 1rem;
  margin-bottom: 0.85rem;
}

.table-primary {
  font-weight: 700;
  color: var(--text);
}

.table-secondary {
  margin-top: 0.15rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.table-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem 0.75rem;
}

.table-actions a {
  color: var(--accent-2);
  font-weight: 700;
  text-decoration: none;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.28rem 0.62rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  border: 1px solid transparent;
}

.auth-submit {
  width: 100%;
  margin-top: 0.4rem;
  padding-block: 0.85rem;
  font-weight: 700;
}

@media (max-width: 860px) {
  .auth-form-panel {
    padding: 1.4rem;
  }
}

.status-pill-draft {
  background: #fef3c7;
  color: #92400e;
  border-color: #fcd34d;
}

.status-pill-confirmed {
  background: #e0f2fe;
  color: #0c4a6e;
  border-color: #7dd3fc;
}

.status-pill-report_ready {
  background: #dcfce7;
  color: #166534;
  border-color: #86efac;
}

.config-form-stack {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.config-tabs {
  position: sticky;
  top: 0.75rem;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.55rem;
  border: 1px solid rgba(15, 118, 110, 0.18);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
  backdrop-filter: blur(10px);
}

.config-tab {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0.55rem 0.85rem;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 800;
  cursor: pointer;
  transition: background-color 160ms ease, color 160ms ease, border-color 160ms ease;
}

.config-tab:hover {
  background: #f0fdfa;
  color: var(--accent-2);
}

.config-tab.is-active {
  color: #ffffff;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  border-color: rgba(15, 118, 110, 0.35);
}

.config-section {
  padding: 1.4rem;
}

.config-two-up {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.config-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  background:
    radial-gradient(circle at top left, rgba(45, 212, 191, 0.12) 0%, transparent 28%),
    linear-gradient(180deg, #ffffff 0%, #f8fcfc 100%);
}

.config-card h2 {
  margin-bottom: 1rem;
}

.config-card + .config-card {
  margin-top: 1rem;
}

.config-row {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1.45fr);
  gap: 0.9rem;
  padding: 0.85rem 0;
  border-top: 1px solid var(--border);
}

.config-card .config-row:first-of-type {
  border-top: none;
  padding-top: 0;
}

.config-row-copy {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.config-field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.7rem;
}

.config-field-grid-compact {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.config-mini-field,
.config-block-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.9rem;
}

.config-mini-field span,
.config-block-field span {
  font-weight: 700;
}

.config-input {
  width: 100%;
}

.checkbox-field {
  justify-content: end;
}

.checkbox-field input {
  width: 1rem;
  height: 1rem;
  margin-top: 0.3rem;
}

.config-inline-error {
  color: #b91c1c;
  font-size: 0.8rem;
}

.config-trigger-stack {
  display: grid;
  gap: 0.85rem;
}

.config-trigger-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(160px, 240px);
  gap: 1rem;
  align-items: start;
  padding-top: 0.85rem;
  border-top: 1px solid var(--border);
}

.config-trigger-row:first-child {
  padding-top: 0;
  border-top: none;
}

.config-trigger-copy {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.config-trigger-title {
  font-size: 0.98rem;
  font-weight: 800;
  color: var(--text);
}

.config-trigger-help {
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--muted);
}

.config-trigger-control {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.config-trigger-control input,
.config-trigger-control textarea,
.config-trigger-control select {
  width: 100%;
}

.llm-prompt-preview {
  background:
    radial-gradient(circle at top right, rgba(15, 118, 110, 0.14) 0%, transparent 28%),
    linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
}

.config-prompt-preview {
  max-height: 520px;
  overflow: auto;
  margin: 0;
  padding: 1rem;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  background: #0f172a;
  color: #e2e8f0;
  font-size: 0.82rem;
  line-height: 1.5;
  white-space: pre-wrap;
}

.config-error-list {
  margin-top: 0.8rem;
}

.dashboard-shell {
  display: grid;
  gap: 1.2rem;
}

.patient-list-shell {
  display: grid;
  gap: 1rem;
}

.patient-list-hero {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  padding: 1.45rem;
  background:
    radial-gradient(circle at top left, rgba(45, 212, 191, 0.15) 0%, transparent 28%),
    linear-gradient(180deg, #ffffff 0%, #f8fbfc 100%);
}

.patient-list-hero .muted {
  max-width: 60ch;
}

.patient-list-hero-stat {
  min-width: 150px;
  padding: 0.95rem 1rem;
  border-radius: 16px;
  border: 1px solid #cae6e1;
  background: linear-gradient(160deg, #f0fdfa 0%, #dff7f1 100%);
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.patient-filter-panel {
  padding: 1.2rem;
}

.patient-filter-form {
  display: grid;
  gap: 1rem;
}

.patient-filter-search,
.patient-filter-field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.patient-filter-search label,
.patient-filter-field label {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
}

.patient-filter-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.9rem;
}

.range-inputs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
}

.patient-filter-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.patient-table .table-secondary {
  max-width: 320px;
}

.patient-table td,
.patient-table th {
  vertical-align: middle;
}

.dashboard-hero {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(280px, 0.9fr);
  gap: 1.2rem;
  align-items: stretch;
  padding: 1.6rem;
  background:
    radial-gradient(circle at top left, rgba(20, 184, 166, 0.18) 0%, transparent 32%),
    radial-gradient(circle at bottom right, rgba(15, 23, 42, 0.08) 0%, transparent 28%),
    linear-gradient(135deg, #ffffff 0%, #f4fbfb 55%, #eef6fb 100%);
}

.dashboard-hero-copy h1 {
  font-size: clamp(2rem, 3vw, 3rem);
  line-height: 1;
  margin-bottom: 0.7rem;
}

.dashboard-hero-copy .muted {
  max-width: 56ch;
  font-size: 1rem;
  line-height: 1.65;
}

.dashboard-highlight {
  border-radius: 18px;
  border: 1px solid rgba(15, 118, 110, 0.16);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.92) 0%, rgba(236, 253, 245, 0.95) 100%);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.5rem;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

.dashboard-highlight-label,
.stat-label {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.75rem;
  font-weight: 700;
}

.dashboard-highlight-value {
  font-size: 1.5rem;
  line-height: 1.15;
}

.dashboard-highlight-meta,
.stat-meta,
.quick-action-copy,
.activity-meta {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.dashboard-inline-link {
  color: var(--accent-2);
  font-weight: 700;
  text-decoration: none;
}

.dashboard-stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
}

.stat-card {
  padding: 1.1rem 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.stat-card-accent {
  background:
    radial-gradient(circle at top left, rgba(45, 212, 191, 0.16) 0%, transparent 30%),
    linear-gradient(160deg, #ffffff 0%, #f0fdfa 100%);
}

.stat-value {
  font-size: clamp(2rem, 2.6vw, 2.6rem);
  line-height: 1;
}

.stat-trend {
  margin-top: auto;
  font-size: 0.84rem;
  font-weight: 700;
}

.trend-up {
  color: #166534;
}

.trend-down {
  color: #b91c1c;
}

.dashboard-content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.95fr);
  gap: 1rem;
}

.dashboard-panel {
  padding: 1.35rem;
}

.dashboard-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 1rem;
  margin-bottom: 1rem;
}

.quick-action-grid {
  display: grid;
  gap: 0.85rem;
}

.quick-action-card {
  text-decoration: none;
  color: inherit;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1rem 1.05rem;
  background: linear-gradient(180deg, #ffffff 0%, #f8fbfc 100%);
  transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.quick-action-card:hover {
  transform: translateY(-2px);
  border-color: rgba(15, 118, 110, 0.28);
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
}

.quick-action-title,
.activity-title {
  font-size: 1rem;
  font-weight: 800;
  color: var(--text);
}

.activity-list {
  display: grid;
  gap: 0.8rem;
}

.activity-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.95rem 0;
  border-top: 1px solid var(--border);
}

.activity-list > .activity-row:first-child {
  border-top: none;
  padding-top: 0;
}

.activity-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.45rem;
  text-align: right;
}

@media (max-width: 720px) {
  .topbar-inner { flex-direction: column; gap: 0.7rem; align-items: flex-start; }
  .table { font-size: 0.85rem; }
  .patient-list-hero,
  .dashboard-hero,
  .dashboard-content-grid,
  .dashboard-stats-grid,
  .patient-filter-grid,
  .patient-hero,
  .comparison-form,
  .config-two-up,
  .config-row,
  .config-field-grid,
  .config-field-grid-compact,
  .config-trigger-row {
    grid-template-columns: 1fr;
    display: grid;
  }
  .config-tabs {
    position: static;
  }

  .config-tab {
    flex: 1 1 150px;
  }

  .hero-stat {
    min-width: 0;
  }

  .patient-list-hero-stat {
    min-width: 0;
  }

  .activity-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .activity-side {
    align-items: flex-start;
    text-align: left;
  }
}

@media (max-width: 560px) {
  .dashboard-hero,
  .dashboard-panel {
    padding: 1.15rem;
  }
}
