/*
 * edcomatic — Compact Typography & Layout
 * ─────────────────────────────────────────────────────────────────────────────
 * Applied AFTER Bootstrap and themes.css.
 * Reduces font sizes and padding globally for information-dense clinical views.
 * ─────────────────────────────────────────────────────────────────────────────
 */

/* Base font — tighter than Bootstrap's 16px default */
:root {
  --edc-font-size-base: 13.5px;
  --edc-line-height:    1.45;
}

/* ── Full-viewport layout: nav + content + footer always visible ─────────── */
html, body { height: 100%; margin: 0; }
body {
  display: flex;
  flex-direction: column;
  overflow: hidden;          /* body never scrolls — only #main-content does */
  font-size: 1rem;           /* relative to html, so 13.5px */
  line-height: var(--edc-line-height);
  color: #1e293b;
}

/* Wrapper that holds sidebar + main between nav and footer */
.page-body {
  flex: 1 1 0;
  min-height: 0;             /* required: flex child must be able to shrink */
  overflow: hidden;
}

/* Sticky top navbar */
.navbar { position: sticky; top: 0; z-index: 1030; }

/* ── Headings — scaled down proportionally ───────────────────────────────── */
h1, .h1 { font-size: 1.6rem;  font-weight: 600; }
h2, .h2 { font-size: 1.35rem; font-weight: 600; }
h3, .h3 { font-size: 1.15rem; font-weight: 600; }
h4, .h4 { font-size: 1rem;    font-weight: 600; }
h5, .h5 { font-size: 0.875rem; font-weight: 600; }
h6, .h6 { font-size: 0.84rem; font-weight: 600; }

/* ── Tables — one consistent look everywhere ─────────────────────────────
   Applied to the base .table class itself (not the table-bordered /
   table-light modifiers) so every table in the app matches without having
   to remember to add modifier classes on each new template. A table can
   still opt out per-cell (e.g. a status/icon column staying text-center)
   or override the header shade with an inline style for a deliberate
   exception — inline styles win over these class-based rules, so nothing
   here needs !important. */
.table {
  font-size: 0.84rem;
  --bs-table-cell-padding-y: 0.35rem;
  --bs-table-cell-padding-x: 0.65rem;
  width: auto;           /* override Bootstrap width:100%; shrink to content */
  text-align: left;      /* default alignment — individual cells/columns (e.g. status icons) may still opt into text-center */
}
/* Use .table-full to explicitly restore 100% width where needed */
.table-full { width: 100% !important; }

/* Opt-in wrapper for a table that can grow long: caps its height and lets
   the body scroll internally (with the header pinned) instead of the whole
   page scrolling past a legend/toolbar above it. Wrap the same element that
   already carries .table-responsive (or nest it just inside), and put any
   legend markup above this wrapper, not below, so it stays visible no
   matter how far the table body is scrolled. */
.table-scroll {
  max-height: 65vh;
  overflow-y: auto;
}
.table-scroll thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background-color: #f8fafc; /* opaque — a scrolled row must not show through */
}

/* All-borders — matches .table-bordered without requiring the class */
.table > :not(caption) > * > * {
  border: 1px solid #dee2e6;
}

/* One row rhythm in every system. Bootstrap 5.3 does not read the --bs-table-cell-padding-*
   variables set on .table above, so plain tables got 0.5rem and .table-sm got 0.25rem. The
   intended padding is applied to the cells themselves here, which also makes .table-sm match.
   Component rules further down (.matrix-table ...) come later and still win. */
.table > :not(caption) > * > * {
  padding: 0.35rem 0.65rem;
}
/* Side padding is the same in every table: hand-set .ps-3 / .pe-3 / .px-3 on a cell made some
   tables 16px and others 10.4px. Matrix grids keep their own cell padding. */
.table:not(.matrix-table) > :not(caption) > * > * {
  padding-left: 0.65rem !important;
  padding-right: 0.65rem !important;
}

/* thead.table-light paints the header cells #f8f9fa over the shaded .table thead above;
   give it the same shade so a header looks the same with or without the class. */
.table-light {
  --bs-table-bg: #f8fafc;
}

.table th {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
  color: #475569;
}
/* Shaded header row — matches thead.table-light without requiring the class */
.table thead {
  background-color: #f8fafc;
}

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card { border-radius: 6px; }

/* A card wrapping a compact (non-.table-full) table should hug the table's
   own auto width instead of stretching to fill its container — otherwise
   the card border/shadow encloses dead space past the table's real edge. */
.card:has(.table:not(.table-full)) {
  display: flex;            /* its own row: whatever follows (a button, a note) goes below, never beside it */
  flex-direction: column;   /* a card header sits above the table, not beside it */
  width: fit-content;       /* still hugs the table */
  max-width: 100%;
}
.card-header {
  padding: 0.5rem 0.85rem;
  font-size: 0.84rem;
  font-weight: 600;
  background-color: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
}
.card-body  { padding: 0.85rem; }
.card-footer { padding: 0.45rem 0.85rem; font-size: 0.8rem; }

/* ── Forms ───────────────────────────────────────────────────────────────── */
.form-control,
.form-select {
  font-size: 0.84rem;
  padding: 0.3rem 0.6rem;
  border-radius: 4px;
}
/* .form-select needs extra right padding reserved for its dropdown-arrow
   background icon — the shared rule above would otherwise let a
   width:auto select's text run under the arrow. */
.form-select { padding-right: 1.75rem; }
.form-select-sm { padding-right: 1.6rem; }
.form-label {
  display: block; /* labels are inline by default — pin this so a following
                      inline-block control (e.g. a shrink-wrapped checkbox
                      list) can never pull the label onto its own line */
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 0.2rem;
  color: #374151;
}
.form-text { font-size: 0.8rem; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn { font-size: 0.84rem; padding: 0.28rem 0.7rem; border-radius: 4px; }
.btn-sm { font-size: 0.8rem; padding: 0.2rem 0.55rem; }
.btn-lg { font-size: 0.875rem; padding: 0.45rem 1rem; }

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge { font-size: 0.72rem; font-weight: 600; padding: 0.22em 0.55em; }

/* ── Navbar ──────────────────────────────────────────────────────────────── */
.navbar { padding: 0.35rem 0; min-height: 48px; }
.navbar-brand { font-size: 1rem; }
/* A larger icon (edcomatic's bell is fs-5) inherited the 1.5 line height and made the bar taller than the modules'; icons take their own size. */
.navbar .nav-link > .bi { line-height: 1; }

/* ── Pagination ──────────────────────────────────────────────────────────── */
.page-link { font-size: 0.8rem; padding: 0.28rem 0.6rem; }

/* ── Alerts ──────────────────────────────────────────────────────────────── */
.alert { font-size: 0.84rem; padding: 0.5rem 0.85rem; }

/* ── List group ──────────────────────────────────────────────────────────── */
.list-group-item { font-size: 0.84rem; padding: 0.45rem 0.85rem; }

/* ── Breadcrumb ──────────────────────────────────────────────────────────── */
.breadcrumb { font-size: 0.8rem; }
.breadcrumb-item + .breadcrumb-item::before { font-size: 0.8rem; }

/* ── DL definition lists ─────────────────────────────────────────────────── */
dt { font-size: 0.8rem; color: #64748b; text-transform: uppercase; letter-spacing: 0.03em; }
dd { font-size: 0.875rem; }

/* ── KPI cards on dashboard ──────────────────────────────────────────────── */
.display-5 { font-size: 1.8rem; }

/* ── Main content spacing ────────────────────────────────────────────────── */
main.container, main.container-fluid {
  padding-top: 1rem;
  padding-bottom: 3rem;
}

/* ── Left sidebar ────────────────────────────────────────────────────────── */
.edc-sidebar {
  transition: width 0.2s ease;
  flex-shrink: 0;
  position: relative;
}
.sidebar-open      { width: 240px; }
.sidebar-collapsed { width: 36px; }

.sidebar-toggle-btn {
  width: 36px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 1rem;
  border-bottom: 1px solid #e2e8f0;
}

.sidebar-content { font-size: 0.8rem; }

.sidebar-section-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #64748b; /* 4.8:1 on white (was #94a3b8 at 2.6:1, below the WCAG AA minimum) */
  margin: 0.6rem 0 0.3rem 0;
}

.sidebar-visit-chip {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.4rem;
  border-radius: 5px;
  text-decoration: none;
  color: #1e293b;
  margin-bottom: 2px;
  transition: background 0.1s;
  overflow: hidden;
}
.sidebar-visit-chip:hover { background: #f1f5f9; color: var(--bs-primary); }
.sidebar-visit-chip .chip-name { font-size: 0.8rem; }

/* Electronic signature modal (Data Review bulk bar + single-entry Sign) */
.sign-modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 1050;
  display: flex; align-items: center; justify-content: center;
}
.sign-modal-box {
  background: #fff; border-radius: 12px; padding: 2rem; width: min(480px, 90vw);
  box-shadow: 0 8px 32px rgba(0,0,0,.2);
}

/* Subject search result cards (HTMX fragment) */
.subject-card {
  display: block;
  padding: 0.3rem 0.5rem;
  border-radius: 4px;
  text-decoration: none;
  color: #1e293b;
  border: 1px solid #e2e8f0;
  margin-bottom: 3px;
  font-size: 0.8rem;
  transition: background 0.1s;
}
.subject-card:hover { background: #f1f5f9; }
.subject-card .sc-id { font-weight: 700; font-size: 0.8rem; }
.subject-card .sc-meta { font-size: 0.72rem; color: #64748b; }

/* ── Admin panel page ────────────────────────────────────────────────────── */
.admin-section-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #64748b;
  margin-bottom: 0.5rem;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid #e2e8f0;
}

/* ── CRF status icons (visit matrix cells) ──────────────────────────────────
   Global (not page-scoped <style>) because visit_matrix.html is also loaded
   as an HTMX fragment via the sidebar visit chips, which swaps in only the
   page body — a page-local <style> block would never reach the DOM there. */
.mc { display:inline-flex; align-items:center; justify-content:center; width:28px; height:28px; border-radius:6px; font-size:.85rem; }
.mc-frozen    { background:#e0f2fe; color:#0369a1; }
.mc-signed    { background:#fef3c7; color:#92400e; }
.mc-locked    { background:#d1fae5; color:#065f46; }
.mc-sdv       { background:#dcfce7; color:#166534; }
.mc-submitted { background:#e0f2fe; color:#1d4ed8; }
.mc-queried   { background:#fee2e2; color:#991b1b; }
.mc-draft     { background:#f3f4f6; color:#6b7280; }
.mc-none      { background:transparent; color:#d1d5db; }

.matrix-table th {
  white-space: nowrap;       /* column headers stay on one line */
  text-align: center;
  vertical-align: middle;
}
.matrix-table td {
  white-space: normal;       /* data cells wrap — no clipping */
  word-break: break-word;
  text-align: center;
  vertical-align: middle;
}
.matrix-table td:first-child { text-align: left; }

/* ── Horizontal icon legend — sits below a table, wraps on narrow screens ──
   Deliberately smaller than the in-table icons: it's a reference key, not
   an interactive element, so it shouldn't compete with the table visually.
   margin-top (not padding) gives it real separation from the card above. */
.icon-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3rem 0.85rem;
  font-size: 0.72rem;
  color: #64748b;
  margin-top: 0.9rem;
}
.icon-legend + .icon-legend { margin-top: 0; }
.icon-legend .legend-title { font-weight: 600; color: #475569; min-width: 5.2rem; }

/* Visit matrix: every CRF column is the same width. Names wrap to 3 lines,
   then truncate with an ellipsis; a Bootstrap tooltip shows the full name. */
.matrix-table th.crf-col {
  width: 112px;
  min-width: 112px;
  max-width: 112px;
  white-space: normal;
  vertical-align: bottom;
}
.matrix-table td.text-center { width: 112px; min-width: 112px; }
.crf-col-name {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
  line-height: 1.25;
  font-size: 0.8rem;
  cursor: help;
}
.icon-legend .legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}
.icon-legend .mc,
.icon-legend .cell-icon {
  width: 17px;
  height: 17px;
  font-size: 0.62rem;
  border-radius: 4px;
}

/* ── Theme switcher swatches ─────────────────────────────────────────────── */
.theme-swatch {
  width: 28px; height: 28px;
  border-radius: 50%;
  display: inline-block;
  cursor: pointer;
  border: 3px solid transparent;
  transition: border-color 0.15s, transform 0.1s;
}
.theme-swatch:hover   { transform: scale(1.15); }
.theme-swatch.active  { border-color: #fff; box-shadow: 0 0 0 2px #475569; }
.theme-swatch[data-theme="clinical-blue"]    { background: #1a2b4a; }
.theme-swatch[data-theme="slate-teal"]       { background: #1e293b; border-right: 14px solid #0d9488; border-radius: 50%; }
.theme-swatch[data-theme="charcoal-violet"]  { background: #18181b; border-right: 14px solid #7c3aed; border-radius: 50%; }
.theme-swatch[data-theme="forest-amber"]     { background: #1c3a2a; border-right: 14px solid #f59e0b; border-radius: 50%; }

/* ── Application footer ──────────────────────────────────────────────────── */
.app-footer {
  font-size: 0.72rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid #e2e8f0;
}

/* ── CRF pages — standardised to an A4-proportioned page width (210mm @ 96dpi
   ≈ 794px) instead of a viewport-relative Bootstrap column, so a CRF reads
   like a consistent paper form regardless of monitor width. Centered like a
   print preview. ── */
.crf-page {
  max-width: 800px;
  margin-left: auto;
  margin-right: auto;
  padding-left: 1.5rem;
  padding-right: 1.5rem;
}

/* ── Queries list page — relaxed to 70% of the available content width
   (rather than shrinking to the table's own content, or stretching
   edge-to-edge) so the aging pivot, filter/download row, and the queries
   table itself all line up inside one consistent-width column. ── */
.queries-page {
  max-width: 70%;
  min-width: 960px;
}

/* ── Grid / matrix cell icons (shared by the subject grid and visit matrix) ── */
  /* ── Grid cell icons ── */
  .cell-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 6px;
    font-size: 1rem;
    text-decoration: none;
    transition: transform .1s, box-shadow .1s;
  }
  .cell-icon:hover { transform: scale(1.15); box-shadow: 0 2px 8px rgba(0,0,0,.18); }

  /* Status colour tokens */
  .ci-not-scheduled { background: #f1f3f5; color: #adb5bd; border: 1px dashed #ced4da; }
  .ci-no-data       { background: #fff3cd; color: #856404; border: 1px solid #ffc107; }
  .ci-in-progress   { background: #cfe2ff; color: #084298; }
  .ci-queried       { background: #fff3cd; color: #664d03; }
  .ci-submitted     { background: #d1e7dd; color: #0a3622; }
  .ci-sdv-done      { background: #198754; color: #fff; }
  .ci-locked        { background: #dc3545; color: #fff; }
  .ci-signed        { background: #0dcaf0; color: #000; }
  .ci-frozen        { background: #5c6bc0; color: #fff; }

  /* Visit-window compliance dot — corner overlay, independent of CRF data status */
  .cell-icon-wrap { position: relative; display: inline-block; }
  .compliance-dot {
    position: absolute; top: -3px; right: -3px;
    width: 10px; height: 10px; border-radius: 50%;
    border: 1.5px solid #fff;
  }
  .compliance-dot.cd-due-soon { background: #ffc107; }
  .compliance-dot.cd-late     { background: #fd7e14; }
  .compliance-dot.cd-missed   { background: #dc3545; }

/* Small red text (links like Retire) must reach 4.5:1 on the light card headers: Bootstrap's red gives 4.3:1. */
:root { --bs-danger-rgb: 176, 42, 55; }

/* ── Type scale for secondary text (2026-10-17) ──────────────────────────
   Three steps replace the ten ad-hoc sizes (.68rem to .875rem) that were set inline.
   !important like Bootstrap's own utilities, so they beat component rules such as `.table th`. */
.fs-xs { font-size: 0.72rem !important; }
.fs-sm { font-size: 0.8rem !important; }
.fs-md { font-size: 0.875rem !important; }

/* Shaded card/panel header, and the small capitalised label used above grouped fields. */
.panel-head { background: var(--panel-bg, #f8f9fa); }
.panel-head.ruled { border-bottom: 1px solid #e9ecef; }
.text-nav { color: var(--nav-bg); }
.label-caps {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ── CR-072: one font, one type scale, one card rhythm, readable colours (2026-10-29) ─────────
   Steps in rem: .72 (caption) · .8 (secondary) · .84 (table, form, body-small) · .875 (body) · 1 · 1.15 (page title) · 1.35 · 1.6.
   The font stack is explicit so the system looks the same on Windows, Mac and Linux; the first
   installed face wins (Segoe UI on Windows, Inter if the viewer has it, then the platform UI font). */
:root {
  --edc-font-sans: "Segoe UI Variable Text", "Segoe UI", Inter, system-ui, -apple-system, "Helvetica Neue", Roboto, Arial, sans-serif;
  --edc-font-mono: ui-monospace, "Cascadia Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --bs-body-font-family: var(--edc-font-sans);
  --bs-font-sans-serif: var(--edc-font-sans);
  --bs-font-monospace: var(--edc-font-mono);
}
body { font-family: var(--edc-font-sans); -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
code, kbd, pre, samp { font-family: var(--edc-font-mono); }
/* Figures line up in columns. */
.table td, .table th { font-variant-numeric: tabular-nums; }
/* Bootstrap's .small is .875em of the parent, which gave 11.8 to 12.7 px depending on where it sat. */
small, .small { font-size: 0.8rem; }
.navbar-edcomatic .nav-link { font-size: 0.84rem; }
/* A card header is one height and one size on every page (some had py-3, some py-2). */
.card-header { padding: 0.5rem 0.85rem !important; font-size: 0.84rem; line-height: 1.45; }
.card-header h1, .card-header h2, .card-header h3, .card-header h4, .card-header h5, .card-header h6,
.card-header .h5, .card-header .h6 { font-size: inherit; font-weight: inherit; margin: 0; }
.card { box-shadow: var(--bs-box-shadow-sm); }
/* The column header is always the grey thead (a bare table gets it too). */
.table > thead:not(.table-light) > tr > th { background-color: #f8fafc; }
.card > .card-header + .table-responsive > .table > thead > tr:first-child > th,
.card > .card-header + .table > thead > tr:first-child > th { border-top: 0; }
/* Text colours that failed 4.5:1 on white. */
.text-warning { color: #8a5a00 !important; }
.text-info { color: #0b6b82 !important; }
.progress-bar.bg-info { color: #04303a; }
.sp.sp-cancelled { color: #4b5563; }
code, kbd, samp { font-size: 0.8rem; }
.progress { font-size: 0.72rem; }
.form-check-label { font-size: 0.84rem; }
/* One small control size: filters, search boxes and table inputs all use .8rem. */
.form-control-sm, .form-select-sm { font-size: 0.8rem; }
/* Title of a table: its own line OUTSIDE and above the table's card (owner rule, CR-022 and CR-072), one style everywhere.
   The page's main table is titled by the page heading instead. */
.table-title { font-size: 0.875rem; font-weight: 600; color: #1e293b; margin: 1.25rem 0 0.5rem; line-height: 1.3; }
.table-title:first-child { margin-top: 0; }
.table-title-row { margin: 1.25rem 0 0.5rem; }
.table-title-row > .table-title { margin: 0; }
.table-title-row:first-child { margin-top: 0; }
/* More text colours that measured under 4.5:1 (CR-072): outline warning/info buttons, grey chip text, code on a tinted alert. */
.btn-outline-warning { --bs-btn-color: #8a5a00; --bs-btn-border-color: #b88600; --bs-btn-hover-color: #212529; }
.btn-outline-info { --bs-btn-color: #0b6b82; --bs-btn-border-color: #0b6b82; --bs-btn-hover-color: #04303a; }
.text-secondary, .badge.bg-light.text-secondary { color: #565e66 !important; }
.alert code { color: #8a1c52; }
/* A scrolling table box hugs its table, so its scrollbar sits against the table instead of at the page edge (wide grids with .table-full keep the full width). */
.table-scroll:not(:has(.table-full)) { width: fit-content; max-width: 100%; }
