/* Clinidex global brand theme — clinical product palette (light workspace + navy accents) */

:root {
  /* Brand */
  --cx-navy: #0b3c5d;
  --cx-blue: #1d65a6;
  --cx-red: #e63946;
  --cx-bg: #f4f6f8;
  --cx-card: #ffffff;
  --cx-text: #1f2933;
  --cx-muted: #64748b;
  --cx-border: #e5e7eb;
  --cx-success: #2ca58d;
  --cx-warning: #f4a261;
  --cx-danger: #e63946;

  /* Backgrounds (default page — tools with theme.css) */
  --color-bg-main: var(--cx-bg);
  --color-bg-card: var(--cx-card);
  --color-bg-sidebar: var(--cx-navy);

  /* Brand controls */
  --color-primary: var(--cx-blue);
  --color-primary-hover: #155a94;
  --color-accent: var(--cx-red);

  /* Status */
  --color-success: var(--cx-success);
  --color-warning: var(--cx-warning);
  --color-danger: var(--cx-danger);

  /* Text */
  --color-text-main: var(--cx-text);
  --color-text-muted: var(--cx-muted);

  /* Borders */
  --color-border: var(--cx-border);

  /* Chart.js palette */
  --chart-primary: var(--cx-blue);
  --chart-red: var(--cx-red);
  --chart-green: var(--cx-success);
  --chart-amber: var(--cx-warning);
  --chart-grid: #e2e8f0;
  --chart-text: var(--cx-muted);
  --chart-info: var(--cx-blue);

  /* App shell bridge (app_shell.css) — navy sidebar, light main */
  --shell-sidebar-bg: var(--cx-navy);
  --shell-sidebar-text: rgba(255, 255, 255, 0.92);
  --shell-sidebar-muted: rgba(255, 255, 255, 0.58);
  --shell-sidebar-border: rgba(255, 255, 255, 0.14);
  --shell-sidebar-hover: rgba(255, 255, 255, 0.1);
  --shell-sidebar-active-bg: rgba(29, 101, 166, 0.55);
  --shell-sidebar-active-text: #ffffff;

  --shell-main-bg: var(--cx-bg);
  --shell-main-text: var(--cx-text);
  --shell-main-muted: var(--cx-muted);
  --shell-card-bg: var(--cx-card);
  --shell-card-border: var(--cx-border);
  --shell-primary: var(--cx-blue);
  --shell-accent: var(--cx-red);

  /* Legacy shell keys used in a few rules */
  --shell-bg: var(--shell-main-bg);
  --shell-surface: var(--shell-sidebar-bg);
  --shell-border: var(--shell-sidebar-border);
  --shell-text: var(--shell-sidebar-text);
  --shell-muted: var(--shell-sidebar-muted);

  /* Layout / control rhythm (tool pages + shell) */
  --cx-radius-lg: 12px;
  --cx-radius-md: 8px;
  --cx-control-height: 40px;
  --cx-space-page-y: 24px;
  --cx-space-page-x: 28px;
  --cx-space-section: 24px;
  --cx-space-card: 20px;

  /* Legacy aliases: override dark inline :root when theme loads after it (via app_shell.css). */
  --bg: var(--cx-bg);
  --surface: var(--cx-card);
  --border: var(--cx-border);
  --text: var(--cx-text);
  --muted: var(--cx-muted);
  --primary: var(--cx-blue);
  --radius: var(--cx-radius-lg);
  --danger: var(--cx-danger);
  --success: var(--cx-success);
  --warn: var(--cx-warning);
  --warning: var(--cx-warning);
  --ok: var(--cx-success);
  /* Accent tints for gradients / hovers (tool pages) */
  --cx-blue-soft: #60a5fa;
  --cx-bg-muted: #f8fafc;
}

/* Tool pages: prefer these classes over per-page :root when using app_shell.css */

body {
  background-color: var(--color-bg-main);
  color: var(--color-text-main);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
}

.sidebar {
  background-color: var(--color-bg-sidebar);
  border-right: 1px solid var(--shell-sidebar-border);
}

.card {
  background-color: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--cx-radius-lg);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}

.btn-primary {
  background-color: var(--color-primary);
  border: none;
  color: #fff;
}
.btn-primary:hover {
  background-color: var(--color-primary-hover);
}

.btn-danger {
  background-color: var(--color-accent);
  border: none;
  color: #fff;
}

.btn-success {
  background-color: var(--color-success);
  border: none;
  color: #fff;
}

.btn-warning {
  background-color: var(--color-warning);
  border: none;
  color: #1f2933;
}

.badge-success,
.badge-warning,
.badge-danger,
.badge-primary,
.badge-neutral {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.3;
}
.badge-success {
  background-color: rgba(44, 165, 141, 0.15);
  color: #1d6b5c;
}
.badge-warning {
  background-color: rgba(244, 162, 97, 0.22);
  color: #9a4b12;
}
.badge-danger {
  background-color: rgba(230, 57, 70, 0.12);
  color: #b91c1c;
}
.badge-primary {
  background-color: rgba(29, 101, 166, 0.14);
  color: var(--cx-blue);
}
.badge-neutral {
  background-color: #f1f5f9;
  color: var(--cx-muted);
}

table {
  border-color: var(--color-border);
}
th,
td {
  border-bottom: 1px solid var(--color-border);
}

a {
  color: var(--cx-blue);
}

/* App shell — logo block (sidebar) */
.sidebar-logo {
  padding: 12px 14px 14px;
  text-align: center;
  border-bottom: 1px solid var(--shell-sidebar-border);
  margin-bottom: 0;
}
.sidebar-logo-link {
  display: inline-block;
  line-height: 0;
  vertical-align: middle;
}
.logo-img {
  max-width: 168px;
  width: 100%;
  height: auto;
  max-height: 36px;
  display: block;
  margin: 0 auto;
  object-fit: contain;
}

.sidebar-section-title {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--shell-sidebar-muted);
  margin: 16px 12px 6px 12px;
  font-weight: 600;
}

.clinidex-nav-group-toggle .sidebar-section-title {
  margin: 0;
  flex: 1;
  min-width: 0;
  text-align: left;
}

.metric-card,
.clinidex-main .metric {
  background: var(--shell-card-bg);
  border: 1px solid var(--shell-card-border);
  border-left: 4px solid var(--cx-blue);
  border-radius: var(--cx-radius-lg);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}

.page-title {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--cx-text);
}

.page-subtitle,
.clinidex-main .topbar .clinidex-module-line,
.clinidex-main .topbar .meta-line {
  font-size: 13px;
  color: var(--cx-muted);
  letter-spacing: 0.02em;
}

.clinidex-main .topbar h1:first-of-type {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--cx-text);
}

.btn {
  border-radius: 8px;
  padding: 8px 14px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s ease, box-shadow 0.15s ease;
}
.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(29, 101, 166, 0.35);
}

tbody tr:hover {
  background-color: rgba(29, 101, 166, 0.06);
}

.clinidex-main input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="file"]):not([type="submit"]):not([type="button"]):not([type="image"]),
.clinidex-main select,
.clinidex-main textarea {
  background-color: #ffffff;
  border: 1px solid var(--cx-border);
  color: var(--cx-text);
  border-radius: 8px;
  padding: 8px 12px;
}

.clinidex-main input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="file"]):not([type="submit"]):not([type="button"]):not([type="image"]):focus,
.clinidex-main select:focus,
.clinidex-main textarea:focus {
  outline: none;
  border-color: var(--cx-blue);
  box-shadow: 0 0 0 3px rgba(29, 101, 166, 0.2);
}

.status-pass,
.label-ok {
  color: var(--color-success);
}
.status-warn,
.label-warn,
.risk-needs-improvement {
  color: #b45309;
}
.status-fail,
.label-danger,
.risk-high,
.risk-sentinel {
  color: var(--cx-danger);
}

/* Status / workflow pills (shared) */
.pill,
.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.35;
}
.pill-success,
.status-pill.ok {
  background: rgba(44, 165, 141, 0.15);
  color: #166534;
}
.pill-warning,
.status-pill.warn {
  background: rgba(244, 162, 97, 0.25);
  color: #9a3412;
}
.pill-danger,
.status-pill.danger,
.status-pill.critical {
  background: rgba(230, 57, 70, 0.12);
  color: #b91c1c;
}
.pill-info,
.status-pill.info {
  background: rgba(29, 101, 166, 0.12);
  color: var(--cx-blue);
}
.pill-neutral {
  background: #f1f5f9;
  color: var(--cx-muted);
}

/* Semantic workflow pills — layout when used without `.pill` */
.pill-risk-high,
.badge-risk-high,
.pill-risk-warn,
.badge-risk-warn,
.pill-risk-medium,
.pill-risk-low,
.badge-risk-low,
.pill-training,
.badge-training,
.pill-followup,
.badge-followup,
.pill-protocol,
.badge-protocol,
.pill-sentinel,
.badge-sentinel,
.pill-complete,
.badge-complete,
.pill-done,
.pill-pending,
.badge-pending {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.35;
}

.pill-risk-high,
.badge-risk-high {
  background: rgba(230, 57, 70, 0.12);
  color: #9f1239;
}
.pill-risk-warn,
.badge-risk-warn,
.pill-risk-medium {
  background: rgba(244, 162, 97, 0.22);
  color: #9a3412;
}
.pill-risk-low,
.badge-risk-low {
  background: rgba(44, 165, 141, 0.14);
  color: #0f5132;
}
.pill-training,
.badge-training {
  background: rgba(29, 101, 166, 0.12);
  color: #155a94;
}
.pill-followup,
.badge-followup {
  background: rgba(99, 102, 241, 0.12);
  color: #4338ca;
}
.pill-protocol,
.badge-protocol {
  background: rgba(11, 60, 93, 0.08);
  color: var(--cx-navy);
}
.pill-sentinel,
.badge-sentinel {
  background: rgba(230, 57, 70, 0.14);
  color: #991b1b;
  font-weight: 700;
}
.pill-complete,
.badge-complete,
.pill-done {
  background: rgba(44, 165, 141, 0.15);
  color: #166534;
}
.pill-pending,
.badge-pending {
  background: #f1f5f9;
  color: var(--cx-muted);
}

/* Muted helper copy (tool pages) */
.muted,
p.muted,
span.muted,
.hint,
.help-text {
  color: var(--cx-muted);
  font-size: 13px;
  line-height: 1.45;
}

/* Data tables (global tool pages) */
thead th,
table > thead > tr > th {
  background: var(--cx-bg-muted);
  color: var(--cx-text);
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--cx-border);
}

/* Topbar link clusters (replaces inline flex on many tool pages) */
.clinidex-topbar-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  text-align: right;
}
.clinidex-topbar-actions--row {
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  text-align: left;
  gap: 12px;
}

/* Alerts / callouts inside main workspace */
.clinidex-callout {
  padding: 14px 16px;
  border-radius: var(--cx-radius-md);
  border: 1px solid var(--cx-border);
  background: var(--cx-card);
  color: var(--cx-text);
  font-size: 14px;
  line-height: 1.45;
}
.clinidex-callout--warn {
  border-color: rgba(244, 162, 97, 0.45);
  background: rgba(244, 162, 97, 0.1);
  color: #92400e;
}
.clinidex-callout--danger {
  border-color: rgba(230, 57, 70, 0.35);
  background: rgba(230, 57, 70, 0.08);
  color: #991b1b;
}
.clinidex-callout--info {
  border-color: rgba(29, 101, 166, 0.28);
  background: rgba(29, 101, 166, 0.06);
  color: var(--cx-text);
}

/* Secondary button on light surfaces (forms / settings) */
.btn-secondary-outline {
  background: var(--cx-card);
  color: var(--cx-text);
  border: 1px solid var(--cx-border);
  border-radius: var(--cx-radius-md);
  padding: 8px 14px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}
.btn-secondary-outline:hover {
  background: var(--cx-bg-muted);
  border-color: var(--cx-muted);
}
