/* Laudare design system.
 * --tenant-primary / --tenant-on-primary come from the municipality config (base.html).
 * Every brand shade is derived from it with color-mix(), so each municipality gets a coherent palette. */

@font-face {
  font-family: "Inter";
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url("../vendor/inter/inter-latin-wght-normal.woff2") format("woff2-variations"),
       url("../vendor/inter/inter-latin-wght-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329,
                 U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url("../vendor/inter/inter-latin-ext-wght-normal.woff2") format("woff2-variations"),
       url("../vendor/inter/inter-latin-ext-wght-normal.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329,
                 U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  --brand: var(--tenant-primary, #0d6efd);
  --on-brand: var(--tenant-on-primary, #fff);
  --brand-25: color-mix(in srgb, var(--brand) 4%, #fff);
  --brand-50: color-mix(in srgb, var(--brand) 8%, #fff);
  --brand-100: color-mix(in srgb, var(--brand) 16%, #fff);
  --brand-200: color-mix(in srgb, var(--brand) 30%, #fff);
  --brand-600: color-mix(in srgb, var(--brand) 88%, #000);
  /* brand used as TEXT: computed on the server (app/branding.py) to reach 4.5:1 in each theme */
  --brand-700: var(--brand-text-light, color-mix(in srgb, var(--brand) 74%, #000));
  --brand-800: color-mix(in srgb, var(--brand-700) 82%, #000);
  --brand-900: color-mix(in srgb, var(--brand-700) 65%, #000);

  /* semantic colors (redefined for the dark theme at the end of this file) */
  --st-wait-bg: #fff6e8; --st-wait-fg: #93370d; --st-wait-bd: #fbd9a6;
  --st-prog-bg: #eaf2ff; --st-prog-fg: #1e40af; --st-prog-bd: #bcd3fb;
  --st-done-bg: #e9f8f0; --st-done-fg: #05603a; --st-done-bd: #a9e5c8;
  --st-dlv-bg: #f0f2f5;  --st-dlv-fg: #364152;  --st-dlv-bd: #d3d9e2;
  --tone-amber-bg: #fff4e5; --tone-amber-fg: #b54708;
  --tone-blue-bg: #eaf2ff;  --tone-blue-fg: #1d4ed8;
  --tone-green-bg: #e7f8ef; --tone-green-fg: #047857;
  --co-warn-bg: #fffaeb; --co-warn-bd: #fedf89; --co-warn-fg: #7a2e0e;
  --co-dang-bg: #fef3f2; --co-dang-bd: #fecdca; --co-dang-fg: #7a271a;
  --co-info-bg: #eff6ff; --co-info-bd: #c7dcfe; --co-info-fg: #1e3a8a;
  --danger-fg: #b42318; --danger-bd: #f1b3ad; --danger-soft: #fef3f2;
  --success-fg: #047857; --success-bd: #a6e2cb; --success-soft: #ecfdf3;
  --btn-white-active: #eef2f6; --btn-white-hover-bd: #b8c1cd;
  --placeholder: #8a93a3;
  --check-border: #98a2b3;
  --glass: color-mix(in srgb, var(--surface) 93%, transparent);

  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e3e8ef;
  --border-strong: #cfd6e0;
  --text: #111827;
  --text-2: #374151;
  --muted: #5b6474;      /* 5.9:1 on white, 5.5:1 on --bg */
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow-xs: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-md: 0 4px 12px -2px rgba(16, 24, 40, .08), 0 2px 6px -2px rgba(16, 24, 40, .05);
  --shadow-lg: 0 16px 32px -8px rgba(16, 24, 40, .16);
  --sidebar-w: 256px;
  --focus: 0 0 0 3px color-mix(in srgb, var(--brand) 35%, transparent);

  --bs-body-font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --bs-body-font-size: .9375rem;
  --bs-body-color: var(--text);
  --bs-body-bg: #fff;  /* components (inputs, modals, dropdowns) inherit this; the page uses --bg below */
  --bs-border-color: var(--border);
  --bs-border-radius: var(--radius-sm);
  --bs-border-radius-lg: var(--radius);
  --bs-secondary-color: var(--muted);
  --bs-link-color: var(--brand-700);
  --bs-link-hover-color: var(--brand-800);
  --bs-focus-ring-color: color-mix(in srgb, var(--brand) 35%, transparent);
}

html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
  letter-spacing: -.003em;
}
h1, h2, h3, h4, h5, .h1, .h2, .h3, .h4, .h5 { color: var(--text); letter-spacing: -.015em; font-weight: 650; }
a { color: var(--brand-700); text-underline-offset: 2px; }
a:hover { color: var(--brand-800); }
.text-muted, .text-body-secondary { color: var(--muted) !important; }
code { color: var(--brand-800); background: var(--brand-50); padding: .1rem .35rem; border-radius: 6px; font-size: .85em; }
::selection { background: var(--brand-100); }

/* Visible keyboard focus everywhere */
:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 55%, #fff); outline-offset: 2px; border-radius: 6px; }
.btn:focus-visible, .form-control:focus, .form-select:focus, .form-check-input:focus {
  box-shadow: var(--focus); border-color: var(--brand); outline: none;
}
.skip-link {
  position: absolute; left: 1rem; top: -100px; z-index: 2000; padding: .6rem 1rem;
  background: var(--brand); color: var(--on-brand); border-radius: var(--radius-sm); font-weight: 600;
}
.skip-link:focus { top: 1rem; color: var(--on-brand); }

/* ---------- buttons ---------- */
.btn { font-weight: 550; border-radius: 10px; padding: .5rem .95rem; display: inline-flex; align-items: center; justify-content: center; gap: .45rem; }
.btn-sm { padding: .35rem .7rem; font-size: .84rem; border-radius: 8px; }
.btn-lg { padding: .7rem 1.2rem; font-size: 1rem; }
.btn .bi { font-size: 1.05em; line-height: 1; }
.btn-primary {
  --bs-btn-bg: var(--brand); --bs-btn-border-color: var(--brand); --bs-btn-color: var(--on-brand);
  --bs-btn-hover-bg: var(--brand-600); --bs-btn-hover-border-color: var(--brand-600); --bs-btn-hover-color: var(--on-brand);
  --bs-btn-active-bg: var(--brand-700); --bs-btn-active-border-color: var(--brand-700); --bs-btn-active-color: var(--on-brand);
  --bs-btn-disabled-bg: var(--brand); --bs-btn-disabled-border-color: var(--brand); --bs-btn-disabled-color: var(--on-brand);
  box-shadow: var(--shadow-xs);
}
.btn-soft {
  --bs-btn-bg: var(--brand-50); --bs-btn-color: var(--brand-800); --bs-btn-border-color: var(--brand-100);
  --bs-btn-hover-bg: var(--brand-100); --bs-btn-hover-color: var(--brand-900); --bs-btn-hover-border-color: var(--brand-200);
  --bs-btn-active-bg: var(--brand-200); --bs-btn-active-color: var(--brand-900);
}
.btn-white, .btn-outline-secondary {
  --bs-btn-bg: var(--surface); --bs-btn-color: var(--text-2); --bs-btn-border-color: var(--border-strong);
  --bs-btn-hover-bg: var(--surface-2); --bs-btn-hover-color: var(--text); --bs-btn-hover-border-color: var(--btn-white-hover-bd);
  --bs-btn-active-bg: var(--btn-white-active); --bs-btn-active-color: var(--text); --bs-btn-active-border-color: var(--btn-white-hover-bd);
  box-shadow: var(--shadow-xs);
}
.btn-success { --bs-btn-bg: #047857; --bs-btn-border-color: #047857; --bs-btn-hover-bg: #065f46; --bs-btn-hover-border-color: #065f46; }
.btn-danger { --bs-btn-bg: #b42318; --bs-btn-border-color: #b42318; --bs-btn-hover-bg: #912018; --bs-btn-hover-border-color: #912018; }
.btn-warning { --bs-btn-bg: #b54708; --bs-btn-border-color: #b54708; --bs-btn-color: #fff; --bs-btn-hover-bg: #93370d; --bs-btn-hover-border-color: #93370d; --bs-btn-hover-color: #fff; --bs-btn-active-color: #fff; }
.btn-outline-danger { --bs-btn-color: var(--danger-fg); --bs-btn-border-color: var(--danger-bd); --bs-btn-hover-bg: var(--danger-soft); --bs-btn-hover-color: var(--danger-fg); --bs-btn-hover-border-color: var(--danger-fg); --bs-btn-bg: var(--surface); }
.btn-outline-success { --bs-btn-color: var(--success-fg); --bs-btn-border-color: var(--success-bd); --bs-btn-hover-bg: var(--success-soft); --bs-btn-hover-color: var(--success-fg); --bs-btn-hover-border-color: var(--success-fg); --bs-btn-bg: var(--surface); }
.btn-icon { width: 2.25rem; height: 2.25rem; padding: 0; border-radius: 10px; }
.btn-icon.btn-sm { width: 2rem; height: 2rem; }
.btn-ghost { --bs-btn-color: var(--muted); --bs-btn-hover-bg: var(--brand-50); --bs-btn-hover-color: var(--brand-800); --bs-btn-bg: transparent; --bs-btn-border-color: transparent; --bs-btn-hover-border-color: transparent; }

/* ---------- forms ---------- */
.form-label { font-weight: 550; font-size: .84rem; color: var(--text-2); margin-bottom: .35rem; }
.form-control, .form-select { border-color: var(--border-strong); border-radius: 10px; padding: .55rem .8rem; box-shadow: var(--shadow-xs); }
.form-control-sm, .form-select-sm { padding: .4rem .65rem; font-size: .875rem; border-radius: 8px; }
.form-control::placeholder { color: var(--placeholder); }
.form-check-input { border-color: var(--check-border); width: 1.1em; height: 1.1em; }
.form-check-input:checked { background-color: var(--brand); border-color: var(--brand); }
.form-text { color: var(--muted); }
.input-icon { position: relative; }
.input-icon > .bi { position: absolute; left: .8rem; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.input-icon > .form-control { padding-left: 2.3rem; }

/* ---------- app shell ---------- */
.app-shell { min-height: 100vh; }
.sidebar, .sidebar.offcanvas-lg {
  background: var(--surface) !important;  /* Bootstrap makes offcanvas-lg transparent on desktop */
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
}
@media (min-width: 992px) {
  .sidebar.offcanvas-lg {
    position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 1030;
    visibility: visible !important; transform: none !important;
  }
  .app-main { margin-left: var(--sidebar-w); }
  .topbar { display: none !important; }
}
@media (max-width: 991.98px) {
  .sidebar.offcanvas-lg { width: min(86vw, 300px); }
}
.sidebar .offcanvas-body { display: flex; flex-direction: column; padding: 0; height: 100%; overflow-y: auto; }
.sidebar-brand { display: flex; align-items: center; gap: .75rem; padding: 1.25rem 1.25rem 1rem; text-decoration: none; color: var(--text); }
.sidebar-brand:hover { color: var(--text); }
.sidebar-brand img { width: 44px; height: 44px; object-fit: contain; border-radius: 10px; background: #fff; border: 1px solid var(--border); padding: 3px; flex-shrink: 0; }
.sidebar-brand .t-name { font-weight: 650; font-size: .88rem; line-height: 1.25; }
.sidebar-brand .t-unit { font-size: .76rem; color: var(--muted); line-height: 1.25; margin-top: .1rem; }
.sidebar-section { padding: .25rem .75rem; }
.sidebar-label { font-size: .7rem; font-weight: 650; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: .9rem .6rem .4rem; }
.nav-side .nav-link {
  display: flex; align-items: center; gap: .7rem; color: var(--text-2); font-weight: 550; font-size: .9rem;
  padding: .55rem .7rem; border-radius: 10px; margin-bottom: 2px; position: relative;
}
.nav-side .nav-link .bi { font-size: 1.1rem; color: var(--muted); width: 1.25rem; text-align: center; }
.nav-side .nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-side .nav-link.active { background: var(--brand-50); color: var(--brand-800); }
.nav-side .nav-link.active .bi { color: var(--brand-700); }
.nav-side .nav-link.active::before {
  content: ""; position: absolute; left: -.75rem; top: .45rem; bottom: .45rem; width: 3px; border-radius: 0 3px 3px 0; background: var(--brand);
}
.sidebar-footer { margin-top: auto; border-top: 1px solid var(--border); padding: .9rem 1rem; display: flex; align-items: center; gap: .7rem; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; flex-shrink: 0; display: grid; place-items: center;
  background: var(--brand-100); color: var(--brand-800); font-weight: 650; font-size: .85rem;
}
.sidebar-footer .u-name { font-weight: 600; font-size: .85rem; line-height: 1.2; }
.sidebar-footer .u-role { font-size: .76rem; color: var(--muted); }
.sidebar-product { font-size: .72rem; color: var(--muted); padding: 0 1.25rem .9rem; }

.topbar {
  position: sticky; top: 0; z-index: 1020; background: var(--glass); backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: .6rem; padding: .55rem .9rem;
}
.topbar img { width: 32px; height: 32px; object-fit: contain; }
.topbar .t-name { font-weight: 650; font-size: .88rem; line-height: 1.2; min-width: 0; }

.app-content { padding: 1.75rem 2rem 3rem; max-width: 1480px; }
@media (max-width: 991.98px) { .app-content { padding: 1.25rem 1rem 2.5rem; } }

/* ---------- page header ---------- */
.page-header { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.5rem; }
.page-title { font-size: 1.5rem; font-weight: 700; margin: 0; letter-spacing: -.02em; }
.page-subtitle { color: var(--muted); margin: .25rem 0 0; font-size: .92rem; }
.breadcrumb-back { display: inline-flex; align-items: center; gap: .35rem; font-size: .84rem; font-weight: 550; color: var(--muted); text-decoration: none; margin-bottom: .5rem; }
.breadcrumb-back:hover { color: var(--brand-700); }
@media (max-width: 575.98px) { .page-title { font-size: 1.3rem; } }

/* ---------- cards ---------- */
.card { border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); background: var(--surface); }
.card-header { background: transparent; border-bottom: 1px solid var(--border); padding: .9rem 1.25rem; font-weight: 650; display: flex; align-items: center; gap: .5rem; }
.card-header .bi { color: var(--brand-700); }
.card-body { padding: 1.25rem; }
.card-title-sm { font-size: .78rem; font-weight: 650; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); margin: 0 0 .75rem; }

/* key/value lists */
.kv { display: grid; grid-template-columns: minmax(104px, 38%) minmax(0, 1fr); gap: .55rem 1rem; margin: 0; }
.kv code { word-break: break-all; background: transparent; padding: 0; color: var(--text-2); }
.kv dt { font-weight: 500; color: var(--muted); font-size: .86rem; }
.kv dd { margin: 0; font-weight: 500; color: var(--text); overflow-wrap: anywhere; }
@media (min-width: 992px) {
  .kv-wide { grid-template-columns: 130px minmax(0, 1fr) 130px minmax(0, 1fr); }
}

/* ---------- stats ---------- */
.stat-card { display: flex; flex-direction: row; align-items: center; gap: 1rem; padding: 1.1rem 1.25rem; }
.stat-icon { width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; font-size: 1.35rem; flex-shrink: 0; }
.stat-value { font-size: 1.6rem; font-weight: 700; line-height: 1.1; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat-label { color: var(--muted); font-size: .84rem; font-weight: 500; }
.tone-amber { background: var(--tone-amber-bg); color: var(--tone-amber-fg); }
.tone-blue { background: var(--tone-blue-bg); color: var(--tone-blue-fg); }
.tone-green { background: var(--tone-green-bg); color: var(--tone-green-fg); }
.tone-brand { background: var(--brand-50); color: var(--brand-700); }
@media (max-width: 575.98px) {
  .stat-card { padding: .75rem .8rem; flex-direction: column; align-items: flex-start; gap: .45rem; }
  .stat-icon { width: 30px; height: 30px; font-size: .95rem; border-radius: 8px; }
  .stat-value { font-size: 1.3rem; }
  .stat-label { font-size: .74rem; line-height: 1.25; }
}

/* ---------- status pills & tags ---------- */
.status-pill {
  display: inline-flex; align-items: center; gap: .35rem; white-space: nowrap;
  padding: .2rem .6rem .2rem .48rem; border-radius: 999px; font-size: .76rem; font-weight: 600; border: 1px solid transparent;
}
.status-pill .bi { font-size: .85rem; }
.status-aguardando_laudo { background: var(--st-wait-bg); color: var(--st-wait-fg); border-color: var(--st-wait-bd); }
.status-em_laudo { background: var(--st-prog-bg); color: var(--st-prog-fg); border-color: var(--st-prog-bd); }
.status-laudado { background: var(--st-done-bg); color: var(--st-done-fg); border-color: var(--st-done-bd); }
.status-entregue { background: var(--st-dlv-bg); color: var(--st-dlv-fg); border-color: var(--st-dlv-bd); }
.status-pill.lg { font-size: .85rem; padding: .32rem .8rem .32rem .65rem; }
.tag {
  display: inline-flex; align-items: center; padding: .12rem .45rem; border-radius: 6px; font-size: .74rem; font-weight: 650;
  letter-spacing: .03em; background: var(--brand-50); color: var(--brand-800); border: 1px solid var(--brand-100);
}
.tag + .tag { margin-left: .25rem; }
.tag-neutral { background: var(--st-dlv-bg); color: var(--st-dlv-fg); border-color: var(--st-dlv-bd); }
.badge-soft { display: inline-flex; align-items: center; gap: .3rem; padding: .2rem .55rem; border-radius: 999px; font-size: .76rem; font-weight: 600; }
.badge-soft.ok { background: var(--st-done-bg); color: var(--st-done-fg); }
.badge-soft.off { background: var(--st-dlv-bg); color: var(--st-dlv-fg); }

/* ---------- tables ---------- */
.table-card { overflow: hidden; }
.table-app { margin: 0; --bs-table-bg: transparent; font-size: .875rem; }
.table-app > thead th {
  background: var(--surface-2); color: var(--muted); font-size: .7rem; font-weight: 650; letter-spacing: .05em;
  text-transform: uppercase; border-bottom: 1px solid var(--border); padding: .65rem .8rem; white-space: nowrap;
}
.table-app > thead th:first-child, .table-app > tbody td:first-child { padding-left: 1.25rem; }
.table-app > thead th:last-child, .table-app > tbody td:last-child { padding-right: 1.25rem; }
.table-app > tbody td { padding: .75rem .8rem; border-color: var(--border); vertical-align: middle; color: var(--text-2); }
.table-app > tbody tr:last-child td { border-bottom: 0; }
.table-app > tbody tr { transition: background-color .12s ease; }
.table-app > tbody tr:hover > td { background: var(--brand-25); }
.row-link { cursor: pointer; }
.row-link:hover > td { background: var(--brand-50) !important; }
.patient-link { color: var(--text); font-weight: 600; text-decoration: none; }
.patient-link:hover, .patient-link:focus { color: var(--brand-800); text-decoration: none; }
.cell-sub { display: block; color: var(--muted); font-size: .8rem; margin-top: .1rem; font-weight: 450; }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }
.actions { display: inline-flex; gap: .3rem; justify-content: flex-end; }

/* Worklist turns into cards on phones (same markup, no duplicated rows) */
@media (max-width: 767.98px) {
  .table-cards > thead { display: none; }
  .table-cards, .table-cards > tbody { display: block; }
  .table-cards > tbody > tr {
    display: flex; flex-wrap: wrap; align-items: center; gap: .15rem .6rem;
    padding: .9rem 1rem; border-bottom: 1px solid var(--border);
  }
  .table-cards > tbody > tr:last-child { border-bottom: 0; }
  .table-cards > tbody > tr > td,
  .table-cards > tbody > tr.row-link:hover > td { display: block; padding: 0 !important; border: 0; background: transparent !important; }
  .table-cards > tbody > tr.row-link:hover { background: var(--brand-25); }
  .table-cards .c-name { order: 1; flex: 1 1 100%; min-width: 0; font-size: .98rem; }
  .table-cards .c-date { order: 2; flex: 1 1 auto; color: var(--muted); font-size: .82rem; margin: .35rem 0 .2rem; }
  .table-cards .c-status { order: 3; margin-left: auto; }
  .table-cards .c-date .cell-sub { display: inline; margin-left: .3rem; font-size: inherit; }
  .table-cards > tbody > tr > td.c-mod { display: none !important; }  /* shown inside the description cell on phones */
  .table-cards .c-desc { order: 5; flex: 1 1 100%; min-width: 0; font-size: .86rem; color: var(--text-2); }
  .table-cards .c-count { order: 6; font-size: .8rem; color: var(--muted); }
  .table-cards .c-count::before { content: attr(data-label) ": "; font-weight: 600; }
  .table-cards .c-actions { order: 7; margin-left: auto; }
  .table-cards .c-empty { flex-basis: 100%; }
}

/* generic tables collapse into stacked rows on phones */
@media (max-width: 767.98px) {
  .table-stack > thead { display: none; }
  .table-stack, .table-stack > tbody, .table-stack > tbody > tr, .table-stack > tbody > tr > td { display: block; width: 100%; }
  .table-stack > tbody > tr { padding: .85rem 1rem; border-bottom: 1px solid var(--border); }
  .table-stack > tbody > tr > td { border: 0; padding: .15rem 0; }
  .table-stack > tbody > tr > td[data-label]:not(.c-main)::before {
    content: attr(data-label); display: inline-block; min-width: 8.5rem; color: var(--muted); font-weight: 550; font-size: .8rem;
  }
  .table-stack .c-main { font-weight: 600; font-size: .98rem; margin-bottom: .25rem; }
  .table-stack .c-actions { padding-top: .5rem !important; text-align: left !important; }
}

/* ---------- filters ---------- */
.filter-card .card-body { padding: 1rem 1.25rem; }
.filters-grid { display: grid; gap: .85rem; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: end; }
.filters-grid .f-name, .filters-grid .f-actions { grid-column: 1 / -1; }
.filters-grid .f-actions { display: flex; gap: .5rem; }
.filters-grid .f-actions .btn-primary { flex: 1; }
@media (min-width: 768px) {
  .filters-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .filters-grid .f-name { grid-column: span 2; }
  .filters-grid .f-actions { grid-column: auto; }
}
@media (min-width: 1200px) {
  /* 1366px (hospital PCs): two balanced rows */
  .filters-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .filters-grid .f-name { grid-column: span 2; }
  .filters-grid .f-actions { grid-column: auto; }
}
@media (min-width: 1600px) {
  .filters-grid .f-actions .btn-primary { flex: none; }
}
.filter-toggle { display: none; }
@media (max-width: 767.98px) {
  .filter-toggle { display: flex; }
  .filter-card .card-body { padding: .9rem; }
}

/* ---------- pagination ---------- */
.pager { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .8rem 1rem; border-top: 1px solid var(--border); background: var(--surface-2); }
.pager .info { color: var(--muted); font-size: .85rem; }
.pagination { --bs-pagination-color: var(--text-2); --bs-pagination-active-bg: var(--brand); --bs-pagination-active-border-color: var(--brand);
  --bs-pagination-active-color: var(--on-brand); --bs-pagination-hover-bg: var(--brand-50); --bs-pagination-hover-color: var(--brand-800);
  --bs-pagination-focus-box-shadow: var(--focus); --bs-pagination-border-radius: 8px; margin: 0; gap: .25rem; }
.pagination .page-link { border-radius: 8px !important; min-width: 2.1rem; text-align: center; }

/* ---------- empty states ---------- */
.empty-state { text-align: center; padding: 3rem 1.5rem; }
.empty-state .icon {
  width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; margin: 0 auto 1rem;
  background: var(--brand-50); color: var(--brand-700); font-size: 1.7rem;
}
.empty-state h2 { font-size: 1.05rem; margin-bottom: .35rem; }
.empty-state p { color: var(--muted); margin: 0 auto; max-width: 420px; }

/* ---------- alerts / callouts ---------- */
.callout { display: flex; gap: .75rem; padding: .9rem 1rem; border-radius: var(--radius-sm); border: 1px solid; font-size: .9rem; }
.callout .bi { font-size: 1.15rem; line-height: 1.3; flex-shrink: 0; }
.callout-warning { background: var(--co-warn-bg); border-color: var(--co-warn-bd); color: var(--co-warn-fg); }
.callout-danger { background: var(--co-dang-bg); border-color: var(--co-dang-bd); color: var(--co-dang-fg); }
.callout-info { background: var(--co-info-bg); border-color: var(--co-info-bd); color: var(--co-info-fg); }
.callout-neutral { background: var(--surface-2); border-color: var(--border); color: var(--text-2); }

/* ---------- toasts ---------- */
.toast-stack { position: fixed; top: 1rem; right: 1rem; z-index: 1090; display: flex; flex-direction: column; gap: .6rem; width: min(400px, calc(100vw - 2rem)); }
.app-toast { display: flex; gap: .7rem; align-items: flex-start; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: .85rem .9rem .85rem 1rem; font-size: .9rem; color: var(--text-2); }
.app-toast.hide { display: none; }
.app-toast .t-icon { font-size: 1.2rem; line-height: 1.25; }
.app-toast .t-body { flex: 1; min-width: 0; }
.app-toast.toast-success .t-icon { color: var(--success-fg); }
.app-toast.toast-danger .t-icon { color: var(--danger-fg); }
.app-toast.toast-warning .t-icon { color: var(--tone-amber-fg); }
.app-toast.toast-info .t-icon { color: var(--tone-blue-fg); }
.app-toast.toast-danger { border-left: 4px solid #d92d20; }
.app-toast.toast-success { border-left: 4px solid #12b76a; }
.app-toast.toast-warning { border-left: 4px solid #f79009; }
.app-toast.toast-info { border-left: 4px solid #2e90fa; }

/* ---------- modal ---------- */
.modal-content { border: 0; border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); }
.modal-header { border-bottom: 0; padding: 1.25rem 1.5rem .25rem; }
.modal-body { padding: .5rem 1.5rem 1rem; color: var(--text-2); }
.modal-footer { border-top: 0; padding: .5rem 1.5rem 1.25rem; gap: .5rem; }
.modal-icon { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; font-size: 1.3rem; margin-bottom: .75rem; }

/* ---------- login ---------- */
.auth-page { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); background: var(--surface); }
.auth-brand {
  position: relative; overflow: hidden; color: var(--on-brand); padding: 3rem 3.5rem; display: flex; flex-direction: column;
  background: radial-gradient(1200px 600px at -10% -20%, color-mix(in srgb, var(--brand) 70%, #fff) 0%, transparent 60%),
              linear-gradient(150deg, var(--brand-600) 0%, var(--brand-800) 100%);
}
.auth-brand::after {
  content: ""; position: absolute; right: -120px; bottom: -120px; width: 420px; height: 420px; border-radius: 50%;
  border: 60px solid color-mix(in srgb, var(--on-brand) 8%, transparent);
}
.auth-brand .logo-box { width: 84px; height: 84px; border-radius: 20px; background: #fff; display: grid; place-items: center; box-shadow: var(--shadow-lg); }
.auth-brand .logo-box img { width: 64px; height: 64px; object-fit: contain; }
.auth-brand h2 { color: inherit; font-size: 1.9rem; font-weight: 700; margin: 2rem 0 .5rem; max-width: 480px; line-height: 1.2; }
.auth-brand .unit { opacity: .9; font-size: 1.05rem; }
.auth-brand .features { list-style: none; padding: 0; margin: 2.5rem 0 0; display: grid; gap: .9rem; max-width: 420px; }
.auth-brand .features li { display: flex; gap: .75rem; align-items: flex-start; opacity: .95; }
.auth-brand .features .bi { font-size: 1.15rem; margin-top: .05rem; }
.auth-brand .foot { margin-top: auto; font-size: .82rem; opacity: .8; }
.auth-form { display: flex; align-items: center; justify-content: center; padding: 2.5rem 1.5rem; }
.auth-form .inner { width: 100%; max-width: 380px; }
.auth-form h1 { font-size: 1.6rem; font-weight: 700; margin-bottom: .35rem; }
.auth-mobile-brand { display: none; }
@media (max-width: 991.98px) {
  .auth-page { grid-template-columns: 1fr; background: var(--bg); }
  .auth-brand { display: none; }
  .auth-form { align-items: flex-start; padding-top: 3rem; }
  .auth-form .inner { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-md); padding: 1.75rem 1.5rem; }
  .auth-mobile-brand { display: flex; align-items: center; gap: .8rem; margin-bottom: 1.5rem; }
  .auth-mobile-brand img { width: 48px; height: 48px; object-fit: contain; }
  .auth-mobile-brand .t-name { font-weight: 650; font-size: .95rem; line-height: 1.25; }
  .auth-mobile-brand .t-unit { color: var(--muted); font-size: .8rem; }
}

/* ---------- exam detail ---------- */
.exam-hero { padding: 1.4rem 1.5rem; }
.exam-hero h1 { font-size: 1.45rem; font-weight: 700; margin: 0; letter-spacing: -.02em; overflow-wrap: anywhere; }
.exam-hero .meta { display: flex; flex-wrap: wrap; gap: .35rem 1.1rem; color: var(--muted); font-size: .88rem; margin-top: .45rem; }
.exam-hero .meta span { display: inline-flex; align-items: center; gap: .35rem; }
.exam-hero .actions-bar { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1.1rem; padding-top: 1.1rem; border-top: 1px solid var(--border); }
@media (max-width: 575.98px) {
  .exam-hero { padding: 1.1rem; }
  .exam-hero h1 { font-size: 1.2rem; }
  .exam-hero .actions-bar > .btn, .exam-hero .actions-bar > form { flex: 1 1 auto; }
  .exam-hero .actions-bar > form .btn { width: 100%; }
}
.report-state { display: flex; gap: .85rem; align-items: flex-start; }
.report-state .state-icon { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; font-size: 1.15rem; flex-shrink: 0; }
.version-list { list-style: none; margin: 0; padding: 0; }
.version-list li { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .6rem 0; border-top: 1px solid var(--border); font-size: .88rem; }
.version-list li:first-child { border-top: 0; }

.series-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 1rem; }
@media (max-width: 575.98px) { .series-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem; } }
.series-card { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface); box-shadow: var(--shadow-xs);
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease; }
.series-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--brand-200); }
.series-thumb { display: block; width: 100%; aspect-ratio: 1 / 1; object-fit: contain; background: #0b0f14; }
.series-card .s-body { padding: .65rem .8rem .75rem; font-size: .84rem; }
.series-card .s-title { font-weight: 600; color: var(--text); display: flex; align-items: center; gap: .4rem; }
.series-card .s-sub { color: var(--muted); font-size: .8rem; }

/* ---------- report editor ---------- */
.editor-patientbar {
  position: sticky; top: 0; z-index: 1010; background: var(--glass); backdrop-filter: blur(8px);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm);
  padding: .8rem 1.1rem; display: flex; flex-wrap: wrap; align-items: center; gap: .6rem 1.25rem; margin-bottom: 1.25rem;
}
@media (max-width: 991.98px) { .editor-patientbar { top: 57px; } }
.editor-patientbar .p-name { font-weight: 700; font-size: 1.05rem; letter-spacing: -.01em; }
.editor-patientbar .p-meta { display: flex; flex-wrap: wrap; gap: .25rem .9rem; color: var(--muted); font-size: .84rem; }
/* wide screens: text on the left, comments then templates on the right; narrow: comments, text, templates */
.editor-layout { display: grid; grid-template-columns: minmax(0, 1fr) 330px; grid-template-rows: auto 1fr;
  grid-template-areas: "doc comments" "doc templates"; gap: 1.25rem; align-items: start; }
.editor-layout > .editor-doc { grid-area: doc; }
.editor-layout > .comments-side { grid-area: comments; }
.editor-layout > .templates-panel { grid-area: templates; }
.editor-layout.templates-collapsed .templates-panel { display: none; }
@media (max-width: 1199.98px) {
  .editor-layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: none; grid-template-areas: "comments" "doc" "templates"; }
}
.comments-side .comment-thread { max-height: 42vh; overflow-y: auto; }
.doc-sheet { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-md); overflow: hidden; }
.doc-sheet .ql-toolbar.ql-snow {
  position: sticky; top: 0; z-index: 5; background: var(--surface-2); border: 0; border-bottom: 1px solid var(--border);
  padding: .55rem .75rem; font-family: inherit;
}
.doc-sheet .ql-container.ql-snow { border: 0; font-family: inherit; font-size: 1.02rem; }
.doc-sheet .ql-editor { min-height: 58vh; padding: 2.25rem clamp(1.25rem, 5vw, 3.5rem); line-height: 1.7; color: var(--text); }
/* extra specificity: quill.snow.css is loaded after this file */
.doc-sheet .ql-container .ql-editor h2, .template-form-editor .ql-container .ql-editor h2 { font-size: 1.15rem; font-weight: 700; margin: 1.1rem 0 .4rem; }
.doc-sheet .ql-container .ql-editor h3, .template-form-editor .ql-container .ql-editor h3 { font-size: 1.02rem; font-weight: 650; margin: 1rem 0 .35rem; }
.doc-sheet .ql-container .ql-editor h2:first-child { margin-top: 0; }
/* Quill's paragraph-style picker in Portuguese */
/* "body" raises specificity above quill.snow.css, which is loaded after this file */
body .ql-snow .ql-picker.ql-header { width: 112px; }
body .ql-snow .ql-picker.ql-header .ql-picker-label::before, body .ql-snow .ql-picker.ql-header .ql-picker-item::before { content: "Texto"; }
body .ql-snow .ql-picker.ql-header .ql-picker-label[data-value="2"]::before, body .ql-snow .ql-picker.ql-header .ql-picker-item[data-value="2"]::before { content: "Título"; }
body .ql-snow .ql-picker.ql-header .ql-picker-label[data-value="3"]::before, body .ql-snow .ql-picker.ql-header .ql-picker-item[data-value="3"]::before { content: "Subtítulo"; }
.doc-sheet .ql-editor.ql-blank::before { left: clamp(1.25rem, 5vw, 3.5rem); color: var(--placeholder); font-style: normal; }
body .ql-snow .ql-stroke { stroke: var(--text-2); }
body .ql-snow .ql-fill { fill: var(--text-2); }
body .ql-snow .ql-picker { color: var(--text-2); }
body .ql-snow.ql-toolbar button:hover .ql-stroke, body .ql-snow.ql-toolbar button.ql-active .ql-stroke { stroke: var(--brand-700); }
body .ql-snow.ql-toolbar button:hover .ql-fill, body .ql-snow.ql-toolbar button.ql-active .ql-fill { fill: var(--brand-700); }
body .ql-snow.ql-toolbar button:hover, body .ql-snow.ql-toolbar button.ql-active, body .ql-snow .ql-picker-label:hover, body .ql-snow .ql-picker-label.ql-active { color: var(--brand-700); }
.ql-snow.ql-toolbar button { border-radius: 6px; }
.ql-snow.ql-toolbar button:hover, .ql-snow.ql-toolbar button.ql-active { background: var(--brand-50); }
.editor-actions {
  position: sticky; bottom: 0; z-index: 5; display: flex; flex-wrap: wrap; align-items: center; gap: .6rem;
  padding: .8rem 1rem; background: var(--glass); border-top: 1px solid var(--border);
}
.autosave { font-size: .84rem; color: var(--muted); display: inline-flex; align-items: center; gap: .35rem; }
.template-item { width: 100%; text-align: left; border: 1px solid var(--border); background: var(--surface); border-radius: 10px;
  padding: .6rem .75rem; display: flex; align-items: center; gap: .6rem; font-size: .88rem; color: var(--text-2); }
.template-item:hover { border-color: var(--brand-200); background: var(--brand-25); color: var(--text); }
.template-item .bi { color: var(--brand-700); }
.template-group-label { font-size: .72rem; font-weight: 650; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); margin: .9rem 0 .45rem; }
.template-group-label:first-child { margin-top: 0; }

/* rendered report (version page) */
.report-body { line-height: 1.7; font-size: 1rem; color: var(--text); }
.report-body h1, .report-body h2, .report-body h3 { font-size: 1.1rem; font-weight: 700; margin: 1.1rem 0 .4rem; }
.report-doc { padding: 2.25rem clamp(1.25rem, 5vw, 3.5rem); }
.signature { border-top: 1px solid var(--border); padding: 1.1rem clamp(1.25rem, 5vw, 3.5rem); background: var(--surface-2); font-size: .88rem; color: var(--text-2); }

/* ---------- error pages ---------- */
.error-wrap { min-height: 60vh; display: grid; place-items: center; }
.error-card { text-align: center; max-width: 480px; padding: 2.5rem 2rem; }
.error-card .code { font-size: .8rem; font-weight: 700; letter-spacing: .12em; color: var(--brand-700); text-transform: uppercase; }
.error-card .icon { width: 76px; height: 76px; border-radius: 50%; display: grid; place-items: center; margin: 0 auto 1.25rem; font-size: 2rem; }
.error-card h1 { font-size: 1.4rem; margin: .5rem 0; }
.error-card p { color: var(--muted); }

/* ---------- settings ---------- */
.form-control-color { width: 3.25rem; height: 2.6rem; padding: .3rem; flex-shrink: 0; }
.logo-current { width: 72px; height: 72px; border: 1px solid var(--border); border-radius: 12px; display: grid; place-items: center; background: #fff; flex-shrink: 0; }
.logo-current img { max-width: 60px; max-height: 60px; object-fit: contain; }
/* the strip box stays white in both themes (logos are made for white paper) */
.footer-logos-current { border: 1px dashed var(--border-strong); border-radius: 10px; padding: .6rem; background: #fff; min-height: 3rem;
  display: flex; align-items: center; justify-content: center; }
.footer-logos-current img { max-width: 100%; max-height: 64px; object-fit: contain; }
.footer-logos-empty { color: #4b5563; text-align: center; }
/* order follows the request: Identidade, Aparência, Laudo/PDF (Aparência beside both on wide screens) */
.settings-grid { display: grid; gap: 1.5rem; align-items: start; grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "identity" "look" "pdf" "pacs"; }
.settings-grid .s-identity { grid-area: identity; }
.settings-grid .s-look { grid-area: look; }
.settings-grid .s-pdf { grid-area: pdf; }
.settings-grid .s-pacs { grid-area: pacs; }
@media (min-width: 1200px) {
  .settings-grid { grid-template-columns: minmax(0, 7fr) minmax(0, 5fr);
    grid-template-areas: "identity look" "pdf look" "pacs pacs"; }
}
.settings-actions {
  display: flex; flex-wrap: wrap; align-items: center; gap: .6rem;
  margin-top: 1.5rem; padding: .85rem 1rem; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-md);
}
@media (min-width: 768px) { .settings-actions { position: sticky; bottom: .75rem; z-index: 5; } }
@media (max-width: 767.98px) { .settings-actions .btn { flex: 1 1 100%; } .settings-actions .small { display: none; } }
/* live preview: brand tokens recomputed from the color being edited */
.brand-preview {
  /* always shows the light theme, also when the admin uses the dark one */
  --bg: #f4f6f9; --surface: #ffffff; --border: #e3e8ef; --text: #111827; --text-2: #374151; color: #111827;
  --pv-primary: var(--brand); --pv-on: var(--on-brand);
  --pv-50: color-mix(in srgb, var(--pv-primary) 8%, #fff);
  --pv-700: color-mix(in srgb, var(--pv-primary) 74%, #000);
  --pv-800: color-mix(in srgb, var(--pv-primary) 58%, #000);
  display: grid; grid-template-columns: 170px minmax(0, 1fr); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; background: var(--bg); min-height: 150px;
}
.brand-preview .pv-side { background: #fff; border-right: 1px solid var(--border); padding: .75rem .6rem; display: flex; flex-direction: column; gap: 4px; }
.brand-preview .pv-brand { display: flex; align-items: center; gap: .45rem; margin-bottom: .5rem; min-width: 0; }
.brand-preview .pv-brand img { width: 28px; height: 28px; object-fit: contain; border: 1px solid var(--border); border-radius: 6px; background: #fff; padding: 2px; flex-shrink: 0; }
.brand-preview .pv-name { font-size: .72rem; font-weight: 650; line-height: 1.2; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.brand-preview .pv-item { font-size: .76rem; font-weight: 550; color: var(--text-2); padding: .35rem .45rem; border-radius: 7px; display: flex; gap: .4rem; align-items: center; }
.brand-preview .pv-item.active { background: var(--pv-50); color: var(--pv-800); box-shadow: inset 3px 0 0 var(--pv-primary); }
.brand-preview .pv-main { padding: .9rem; display: flex; flex-direction: column; align-items: flex-start; gap: .6rem; }
.brand-preview .pv-title { font-weight: 650; font-size: .85rem; }
.brand-preview .pv-btn { display: inline-flex; gap: .4rem; align-items: center; background: var(--pv-primary); color: var(--pv-on); font-weight: 600; font-size: .84rem; border-radius: 9px; padding: .45rem .85rem; }
.brand-preview .pv-link { color: var(--pv-700); text-decoration: underline; font-size: .82rem; }
@media (max-width: 420px) { .brand-preview { grid-template-columns: 1fr; } .brand-preview .pv-side { border-right: 0; border-bottom: 1px solid var(--border); } }

/* misc */
.divider { height: 1px; background: var(--border); margin: 1rem 0; }
.min-w-0 { min-width: 0; }
.fw-semibold { font-weight: 600 !important; }
.report-editor { min-height: 320px; }
.template-form-editor .ql-toolbar.ql-snow { border-radius: 10px 10px 0 0; border-color: var(--border-strong); background: var(--surface-2); }
.template-form-editor .ql-container.ql-snow { border-radius: 0 0 10px 10px; border-color: var(--border-strong); font-family: inherit; font-size: 1rem; }
.template-form-editor .ql-editor { min-height: 320px; line-height: 1.65; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---------- theme switch (sidebar footer) ---------- */
.theme-switch { display: inline-flex; gap: 2px; padding: 2px; border-radius: 9px; background: var(--surface-2); border: 1px solid var(--border); }
.theme-switch button { border: 0; background: transparent; color: var(--muted); width: 1.9rem; height: 1.7rem; border-radius: 7px; display: grid; place-items: center; }
.theme-switch button:hover { color: var(--text); }
.theme-switch button[aria-pressed="true"] { background: var(--surface); color: var(--brand-700); box-shadow: var(--shadow-xs); }
.sidebar-theme { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: 0 1rem .75rem; }
.sidebar-theme .label { font-size: .74rem; color: var(--muted); }

/* ---------- report layout editor ---------- */
.layout-editor { display: grid; grid-template-columns: minmax(0, 1fr) minmax(360px, 460px); gap: 1.5rem; align-items: start; }
.layout-preview-col { position: sticky; top: 1rem; }
@media (max-width: 1199.98px) {
  .layout-editor { grid-template-columns: minmax(0, 1fr); }
  .layout-preview-col { position: static; order: -1; }
}
.layout-preview-head { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; margin-bottom: .5rem; font-size: .88rem; }
/* the sheet is always white paper, in both themes */
.layout-preview { position: relative; overflow: hidden; border: 1px solid var(--border-strong); border-radius: 6px; background: #fff;
  box-shadow: var(--shadow-md); }
.layout-preview-inner { width: 210mm; transform-origin: top left; }
.layout-actions { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: 1rem; }
.field-order { list-style: none; margin: 0; padding: 0; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.field-row { display: flex; align-items: center; gap: .25rem; padding: .3rem .5rem .3rem .75rem; border-top: 1px solid var(--border); background: var(--surface); }
.field-row:first-child { border-top: 0; }
.field-row:has(input:not(:checked)) .form-check-label { color: var(--muted); }

/* ---------- public validation page ---------- */
.validate-page { min-height: 100vh; display: grid; place-items: start center; padding: 2.5rem 1rem; background: var(--bg); }
.validate-card { width: 100%; max-width: 620px; padding: 1.75rem 1.5rem; }
.validate-brand { display: flex; align-items: center; gap: .8rem; }
.validate-brand img { width: 52px; height: 52px; object-fit: contain; border-radius: 10px; background: #fff; border: 1px solid var(--border); padding: 3px; }
.validate-brand .t-name { font-weight: 650; line-height: 1.25; }
.validate-brand .t-unit { color: var(--muted); font-size: .86rem; }
.validate-status { display: flex; gap: .85rem; align-items: flex-start; margin: 1.5rem 0 1.25rem; padding: 1rem 1.1rem; border-radius: var(--radius); border: 1px solid; }
.validate-status .bi { font-size: 1.7rem; line-height: 1; }
.validate-status.ok { background: var(--success-soft); border-color: var(--success-bd); color: var(--success-fg); }
.validate-status.warn { background: var(--co-warn-bg); border-color: var(--co-warn-bd); color: var(--co-warn-fg); }
.validate-status h1 { color: inherit; }
.validate-kv { grid-template-columns: minmax(120px, 34%) minmax(0, 1fr); }
code.hash { word-break: break-all; font-size: .78rem; }
.validate-file { margin-top: 1.25rem; padding-top: 1.1rem; border-top: 1px solid var(--border); }

/* ---------- doctor's signature ---------- */
.signature-preview { background: #fff; border: 1px dashed var(--border-strong); border-radius: 12px; padding: 1.25rem; text-align: center; color: #111827; }
.signature-preview img { max-width: 280px; max-height: 90px; object-fit: contain; display: block; margin: 0 auto .25rem; }
.signature-empty { display: block; color: #4b5563; font-size: .88rem; padding: 1.5rem 0 .75rem; }
.signature-line { width: 60%; margin: 0 auto .35rem; border-top: 1px solid #374151; }
.signature-name { font-weight: 650; font-size: .9rem; }
.signature-name span { font-weight: 500; color: #4b5563; font-size: .84rem; }

/* ---------- print images ---------- */
.print-layout { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 1.25rem; align-items: start; }
.print-options { position: sticky; top: 1rem; }
@media (max-width: 991.98px) {
  .print-layout { grid-template-columns: minmax(0, 1fr); }
  .print-options { position: static; }
}
.layout-choices { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .5rem; }
.layout-choice { position: relative; display: flex; flex-direction: column; align-items: center; gap: .3rem; cursor: pointer;
  border: 1px solid var(--border-strong); border-radius: 10px; padding: .5rem .25rem .4rem; background: var(--surface); }
.layout-choice input { position: absolute; opacity: 0; pointer-events: none; }
.layout-choice:has(input:checked) { border-color: var(--brand); background: var(--brand-50); box-shadow: inset 0 0 0 1px var(--brand); }
.layout-choice:has(input:focus-visible) { box-shadow: var(--focus); }
.layout-label { font-weight: 650; font-size: .85rem; color: var(--text-2); }
.layout-sheet { width: 30px; height: 42px; border: 1.5px solid var(--muted); border-radius: 3px; padding: 3px; display: grid; gap: 2px; background: var(--surface); }
.layout-sheet i { background: var(--muted); border-radius: 1px; opacity: .55; }
.layout-1 { grid-template: 1fr / 1fr; }
.layout-2 { grid-template: repeat(2, 1fr) / 1fr; }
.layout-4 { grid-template: repeat(2, 1fr) / repeat(2, 1fr); }
.layout-6 { grid-template: repeat(3, 1fr) / repeat(2, 1fr); }
.layout-choice:has(input:checked) .layout-sheet { border-color: var(--brand-700); }
.layout-choice:has(input:checked) .layout-sheet i { background: var(--brand-700); opacity: .8; }
.print-count { font-size: .88rem; color: var(--text-2); padding: .55rem .7rem; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--border); }
.series-pick { margin-bottom: 1rem; }
.series-pick > summary { cursor: pointer; list-style: none; border-bottom: 0; }
.series-pick > summary::-webkit-details-marker { display: none; }
.series-pick[open] > summary { border-bottom: 1px solid var(--border); }
.series-pick .chevron { transition: transform .15s ease; color: var(--muted); }
.series-pick[open] .chevron { transform: rotate(90deg); }
.thumb-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: .75rem; }
@media (max-width: 575.98px) { .thumb-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.thumb { position: relative; }
.thumb-pick { display: block; cursor: pointer; border: 2px solid var(--border); border-radius: 10px; overflow: hidden; background: #0b0f14; }
.thumb-pick img { display: block; width: 100%; aspect-ratio: 1 / 1; object-fit: contain; }
.thumb-pick .form-check-input { position: absolute; top: .45rem; left: .45rem; margin: 0; width: 1.25em; height: 1.25em; box-shadow: 0 0 0 2px rgba(0, 0, 0, .35); }
.thumb-pick:has(input:checked) { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand); }
.thumb-label { display: block; font-size: .76rem; font-weight: 550; color: #e5e7eb; background: #111827; padding: .25rem .5rem; }
.thumb-download { position: absolute; top: .35rem; right: .35rem; width: 1.9rem; height: 1.9rem; display: grid; place-items: center;
  border-radius: 8px; background: rgba(17, 24, 39, .78); color: #fff; text-decoration: none; }
.thumb-download:hover, .thumb-download:focus { background: #000; color: #fff; }

/* ---------- exam comments (balloons) ---------- */
.comment-thread { list-style: none; margin: 0; padding: 0 .1rem; display: flex; flex-direction: column; gap: .85rem; }
.comment { display: flex; flex-direction: column; align-items: flex-start; max-width: 92%; }
.comment.mine { align-self: flex-end; align-items: flex-end; }
.comment .c-meta { display: flex; flex-wrap: wrap; align-items: baseline; gap: .15rem .5rem; font-size: .76rem; color: var(--muted); margin: 0 .35rem .25rem; }
.comment .c-author { font-weight: 650; color: var(--text-2); }
.comment .c-you { font-weight: 500; color: var(--muted); }
.comment .c-role { padding: 0 .4rem; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); font-weight: 550; }
.comment .c-bubble {
  white-space: pre-wrap; overflow-wrap: anywhere; font-size: .9rem; line-height: 1.5; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border); padding: .6rem .8rem; border-radius: 4px 14px 14px 14px;
}
.comment.mine .c-bubble { background: var(--brand-50); border-color: var(--brand-100); border-radius: 14px 4px 14px 14px; }
.comment .c-bubble.c-hidden { font-style: italic; color: var(--muted); background: transparent; border-style: dashed; }
.comment .c-actions { margin: .1rem .25rem 0; }
.comment .c-hide { --bs-btn-color: var(--muted); --bs-btn-hover-color: var(--danger-fg); padding: 0 .2rem; font-size: .76rem; text-decoration: none; gap: .25rem; }
.comment-empty { color: var(--muted); font-size: .88rem; padding: .25rem 0; }
.comment-form { margin-top: 1rem; }
.comment-form textarea { resize: vertical; min-height: 4.2rem; }
.comment-form-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem; margin-top: .5rem; }
.comment-form-foot .form-text { margin: 0; flex: 1 1 14rem; }
.comment-error:not([hidden]) { margin-top: .4rem; }
#commentsModal .modal-header { align-items: center; padding-bottom: .75rem; border-bottom: 1px solid var(--border); }
#commentsModal .modal-body { padding-top: 1rem; min-height: 6rem; }
#commentsModal .modal-footer { border-top: 1px solid var(--border); padding-top: .9rem; }
#commentsModal .comment-form { margin-top: 0; }

/* comment counter in the worklist */
.comment-btn {
  display: inline-flex; align-items: center; gap: .3rem; border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--muted); border-radius: 999px; padding: .2rem .55rem; font-size: .8rem; font-weight: 600; line-height: 1.3;
}
.comment-btn:hover { color: var(--text); border-color: var(--btn-white-hover-bd); background: var(--surface-2); }
.comment-btn.has-comments { background: var(--brand-50); border-color: var(--brand-200); color: var(--brand-800); }
.comment-btn.has-comments:hover { background: var(--brand-100); }

/* worklist: quick periods and the modalities picker */
.period-bar { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; margin-bottom: .9rem; }
.period-label { display: inline-flex; align-items: center; gap: .35rem; font-size: .84rem; font-weight: 550; color: var(--text-2); margin-right: .25rem; }
.chip {
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-2); border-radius: 999px;
  padding: .25rem .8rem; font-size: .84rem; font-weight: 550; line-height: 1.35;
}
.chip:hover { background: var(--surface-2); color: var(--text); }
.chip[aria-pressed="true"] { background: var(--brand-50); border-color: var(--brand); color: var(--brand-800); }
.modality-toggle { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modality-menu { width: min(340px, calc(100vw - 2rem)); --bs-dropdown-bg: var(--surface); --bs-dropdown-border-color: var(--border); box-shadow: var(--shadow-lg); border-radius: var(--radius); }
.modality-all { padding-bottom: .5rem; margin-bottom: .6rem; border-bottom: 1px solid var(--border); }
.modality-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .35rem .5rem; }
@media (max-width: 400px) { .modality-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.modality-grid .form-check-label { font-weight: 600; font-size: .86rem; letter-spacing: .02em; }
.modality-foot { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin-top: .85rem; padding-top: .7rem; border-top: 1px solid var(--border); }
.modality-foot .form-text { margin: 0; font-size: .76rem; line-height: 1.3; }
.modality-foot .btn { flex-shrink: 0; }
.desc-menu { width: min(440px, calc(100vw - 2rem)); }
.desc-list { max-height: 18rem; overflow-y: auto; margin: 0 -.25rem; padding: 0 .25rem; }
.desc-row { padding: .3rem 0 .3rem 1.6em; border-bottom: 1px solid var(--border); margin: 0; }
.desc-row:last-child { border-bottom: 0; }
.desc-row .form-check-label { display: flex; align-items: baseline; justify-content: space-between; gap: .75rem; width: 100%; font-size: .86rem; }
.desc-name { overflow-wrap: anywhere; }
.desc-raw { color: var(--muted); font-size: .76rem; font-weight: 450; }
.index-sub { font-size: .76rem; }
.desc-count { flex-shrink: 0; font-size: .75rem; font-weight: 650; color: var(--muted); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 999px; padding: 0 .45rem; }
.single-modality { display: inline-flex; align-items: center; gap: .3rem; font-size: .8rem; color: var(--muted); }

/* worklist rows: comments and "Laudar" on phones */
@media (max-width: 767.98px) {
  .table-cards .c-comments { order: 6; }
  .table-cards .c-count { order: 5; }
  .table-cards .c-status .cell-sub { display: inline; margin-left: .4rem; }
}
.c-status .cell-sub { max-width: 12rem; }
.c-actions .btn { white-space: nowrap; }
/* 1366 px screens: the image count gives way to the actions */
@media (min-width: 768px) and (max-width: 1439.98px) { .table-cards .c-count { display: none; } }

/* ==========================================================================
   Dark theme. Only tokens change; the municipality color stays the brand, and the brand used as text
   (--brand-text-dark) is computed on the server to keep 4.5:1 on these surfaces. The PDF is always light.
   ========================================================================== */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1117;
  --surface: #121a23;
  --surface-2: #18222d;
  --border: #263443;
  --border-strong: #3a4a5c;
  --text: #e6edf3;
  --text-2: #c5d0db;
  --muted: #9aa7b5;

  --brand-25: color-mix(in srgb, var(--brand) 7%, var(--surface));
  --brand-50: color-mix(in srgb, var(--brand) 14%, var(--surface));
  --brand-100: color-mix(in srgb, var(--brand) 24%, var(--surface));
  --brand-200: color-mix(in srgb, var(--brand) 38%, var(--surface));
  --brand-700: var(--brand-text-dark, color-mix(in srgb, var(--brand) 55%, #fff));
  --brand-800: color-mix(in srgb, var(--brand-700) 80%, #fff);
  --brand-900: color-mix(in srgb, var(--brand-700) 62%, #fff);

  --st-wait-bg: #36230c; --st-wait-fg: #fdba74; --st-wait-bd: #6b4512;
  --st-prog-bg: #14254a; --st-prog-fg: #a5c8ff; --st-prog-bd: #2b4a85;
  --st-done-bg: #0d2e20; --st-done-fg: #86efac; --st-done-bd: #1f6b47;
  --st-dlv-bg: #222c38;  --st-dlv-fg: #cbd5e1;  --st-dlv-bd: #3a4757;
  --tone-amber-bg: #36230c; --tone-amber-fg: #fdba74;
  --tone-blue-bg: #14254a;  --tone-blue-fg: #a5c8ff;
  --tone-green-bg: #0d2e20; --tone-green-fg: #86efac;
  --co-warn-bg: #2b2111; --co-warn-bd: #6b4f12; --co-warn-fg: #fcd9a6;
  --co-dang-bg: #2b1414; --co-dang-bd: #7a2a2a; --co-dang-fg: #fecaca;
  --co-info-bg: #12203a; --co-info-bd: #2b4a85; --co-info-fg: #c7dcff;
  --danger-fg: #fca5a5; --danger-bd: #7a2a2a; --danger-soft: #2b1414;
  --success-fg: #86efac; --success-bd: #1f6b47; --success-soft: #0d2e20;
  --btn-white-active: #223040; --btn-white-hover-bd: #4a5b6e;
  --placeholder: #7f8c9a;
  --check-border: #5d6d80;

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, .35);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .35), 0 1px 3px rgba(0, 0, 0, .4);
  --shadow-md: 0 6px 16px -4px rgba(0, 0, 0, .5);
  --shadow-lg: 0 18px 36px -10px rgba(0, 0, 0, .6);

  /* Bootstrap components (inputs, modals, dropdowns, tables) */
  --bs-body-bg: var(--surface);
  --bs-body-color: var(--text);
  --bs-emphasis-color: #ffffff;
  --bs-secondary-color: var(--muted);
  --bs-secondary-bg: var(--surface-2);
  --bs-tertiary-bg: var(--surface-2);
  --bs-border-color: var(--border);
  --bs-link-color: var(--brand-700);
  --bs-link-hover-color: var(--brand-800);
  --bs-form-invalid-color: #fca5a5;
  --bs-form-invalid-border-color: #f87171;
  --bs-form-valid-color: #86efac;
}
:root[data-theme="dark"] .text-success { color: var(--success-fg) !important; }
:root[data-theme="dark"] .text-danger { color: var(--danger-fg) !important; }
:root[data-theme="dark"] .modal-backdrop { --bs-backdrop-opacity: .7; }
:root[data-theme="dark"] .ql-snow .ql-picker { color: var(--text-2); }
:root[data-theme="dark"] .ql-snow .ql-picker-options { background: var(--surface); border-color: var(--border); }
:root[data-theme="dark"] .ql-snow .ql-picker.ql-expanded .ql-picker-label { border-color: var(--border); }
:root[data-theme="dark"] .app-toast { border-color: var(--border-strong); }
/* the series thumbnails already sit on black; the logo boxes stay white so any logo reads */
