/* =====================================================================
   TessaMed app styling. Maps the Brand Kit tokens (tessamed-tokens.css)
   onto the app's existing Bootstrap 5.3 markup. Loaded by base.html after
   its own <style> and before each page's extra_css, so pages can still
   override. Brand rules followed: flat (no drop shadows), DM Sans and
   JetBrains Mono self-hosted, pill buttons, navy shell, cream canvas.
   Deliberately NOT changed yet: Bootstrap's red "danger" colours (clinical
   meaning) and hard-coded page colours inside <script> blocks.
   ===================================================================== */

/* ── Fonts (Fontsource 5.2.8, SIL OFL 1.1, latin subset, variable weight) ── */
@font-face {
  font-family: 'DM Sans'; font-style: normal; font-display: swap; font-weight: 100 1000;
  src: url('../fonts/dm-sans-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: 'DM Sans'; font-style: italic; font-display: swap; font-weight: 100 1000;
  src: url('../fonts/dm-sans-latin-wght-italic.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: 'JetBrains Mono'; font-style: normal; font-display: swap; font-weight: 100 800;
  src: url('../fonts/jetbrains-mono-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;
}

:root {
  /* Muted text in the app (19 Oct 2026): the brand's #6B6F7D measures 4.43:1 on the off-white
     #F4F1E9 used behind group rows and headers, under the 4.5:1 WCAG AA minimum. #656977 measures
     4.85:1 there and 5.47:1 on white. The token file keeps #6B6F7D for the website. */
  --tm-muted: #656977;
  /* Legacy app variables (read by about 60 templates) now point at the brand */
  --primary: var(--tm-cobalt);
  --primary-dark: var(--tm-night);
  --primary-light: #8EA6FF;
  --accent: var(--tm-orange);
  --bg: var(--tm-cream);
  --card-bg: var(--tm-white);

  /* App-only tokens the Brand Kit does not define */
  --tm-input-border: #8F8A7E;   /* 3.4:1 on white - meets the 3:1 rule for form borders */
  --tm-cobalt-pressed: #2450E0;

  /* Bootstrap 5.3 variables */
  --bs-font-sans-serif: var(--tm-font-sans);
  --bs-body-font-family: var(--tm-font-sans);
  --bs-font-monospace: var(--tm-font-mono);
  --bs-body-color: var(--tm-body);
  --bs-body-color-rgb: 58, 58, 78;
  --bs-body-bg: var(--tm-cream);
  --bs-body-bg-rgb: 255, 252, 245;
  --bs-secondary-color: var(--tm-secondary);
  --bs-tertiary-bg: var(--tm-off);
  --bs-primary: #2D5DFF;
  --bs-primary-rgb: 45, 93, 255;
  --bs-primary-text-emphasis: #2B59F4;
  --bs-primary-bg-subtle: var(--tm-room-og);
  --bs-primary-border-subtle: #B9C8FF;
  --bs-link-color: #2B59F4;
  --bs-link-color-rgb: 43, 89, 244;
  --bs-link-hover-color: #1B1F3B;
  --bs-link-hover-color-rgb: 27, 31, 59;
  --bs-border-color: var(--tm-border);
  --bs-border-radius: 8px;
  --bs-border-radius-sm: 6px;
  --bs-border-radius-lg: 16px;
  --bs-focus-ring-color: rgba(45, 93, 255, 0.35);
}

body {
  font-family: var(--tm-font-sans);
  color: var(--tm-body);
  background: var(--tm-cream);
  -webkit-font-smoothing: antialiased;
}
code, kbd, pre, samp, .font-monospace { font-family: var(--tm-font-mono); }

/* ── Shell: navy top bar ── */
.navbar-medpro {
  background: var(--tm-night);
  box-shadow: none;
  border-bottom: 1px solid var(--tm-hairline-night);
}
.navbar-medpro .navbar-brand { color: var(--tm-on-night); font-weight: 400; padding-top: 2px; padding-bottom: 2px; }
.navbar-medpro .nav-link { color: var(--tm-on-night-muted); }
.navbar-medpro .nav-link:hover,
.navbar-medpro .nav-link:focus,
.navbar-medpro .nav-link.active { color: var(--tm-on-night); }
.navbar-medpro .nav-link.active { box-shadow: inset 0 -2px 0 var(--tm-cobalt); }

/* ── Logo component (templates/_brand_logo.html) ── */
.tm-lockup { display: inline-flex; align-items: center; line-height: 1; vertical-align: middle; }
.tm-wordmark { font-family: var(--tm-font-sans); font-weight: 400; letter-spacing: -0.03em; white-space: nowrap; }
.tm-mark { flex: 0 0 auto; display: block; }

/* ── Cards: white, hairline border, flat. Headers stay coloured (navy) so
      any existing white header text keeps its contrast ── */
.card {
  background: var(--tm-white);
  border: 1px solid var(--tm-border);
  border-radius: var(--tm-radius-card);
  box-shadow: none;
}
/* Light card headers (decision, 19 Oct 2026): white, navy text, a hairline under them - the
   navy bar on every card competed with the sidebar and the patient banner. */
.card-header {
  background: var(--tm-white);
  color: var(--tm-night);
  font-weight: 500;
  border-bottom: 1px solid var(--tm-line);
  /* (headers with a background of their own keep light text - see below) */
  border-radius: calc(var(--tm-radius-card) - 1px) calc(var(--tm-radius-card) - 1px) 0 0 !important;
}
.stat-card { border-radius: var(--tm-radius-card); }

/* ── Buttons: pills; one cobalt primary, navy-outline secondaries; hover = slight fade ── */
.btn { border-radius: var(--tm-radius-pill); font-weight: 500; }
.btn-primary {
  --bs-btn-color: #fff; --bs-btn-bg: var(--tm-cobalt); --bs-btn-border-color: var(--tm-cobalt);
  --bs-btn-hover-color: #fff; --bs-btn-hover-bg: var(--tm-cobalt); --bs-btn-hover-border-color: var(--tm-cobalt);
  --bs-btn-active-color: #fff; --bs-btn-active-bg: var(--tm-cobalt-pressed); --bs-btn-active-border-color: var(--tm-cobalt-pressed);
  --bs-btn-disabled-color: #fff; --bs-btn-disabled-bg: var(--tm-cobalt); --bs-btn-disabled-border-color: var(--tm-cobalt);
  --bs-btn-focus-shadow-rgb: 45, 93, 255;
}
.btn-outline-primary {
  --bs-btn-color: var(--tm-night); --bs-btn-border-color: var(--tm-night);
  --bs-btn-hover-color: var(--tm-cream); --bs-btn-hover-bg: var(--tm-night); --bs-btn-hover-border-color: var(--tm-night);
  --bs-btn-active-color: var(--tm-cream); --bs-btn-active-bg: var(--tm-night-2); --bs-btn-active-border-color: var(--tm-night-2);
  --bs-btn-disabled-color: var(--tm-night); --bs-btn-disabled-border-color: var(--tm-night);
  --bs-btn-focus-shadow-rgb: 27, 31, 59;
}
.btn-medpro {
  background: var(--tm-cobalt); color: #fff; border: 1px solid var(--tm-cobalt); border-radius: var(--tm-radius-pill);
}
.btn-medpro:hover, .btn-medpro:focus { background: var(--tm-cobalt); color: #fff; }
.btn-medpro-outline {
  border: 1.5px solid var(--tm-night); color: var(--tm-night); background: transparent; border-radius: var(--tm-radius-pill);
}
.btn-medpro-outline:hover, .btn-medpro-outline:focus { background: var(--tm-night); color: var(--tm-cream); }
.btn-primary:hover, .btn-medpro:hover { opacity: .88; }
.btn:focus-visible { box-shadow: var(--tm-focus-ring); }

/* ── Forms: 8px radius, 1.5px border, navy border and ring on focus ── */
.form-control, .form-select { border: 1.5px solid var(--tm-input-border); border-radius: var(--tm-radius-input); }
.form-control:focus, .form-select:focus { border-color: var(--tm-night); box-shadow: var(--tm-focus-ring); }
.input-group-text { border: 1.5px solid var(--tm-input-border); background: var(--tm-off); }
.form-label { font-size: 13px; font-weight: 500; color: var(--tm-secondary); }
.form-check-input:checked { background-color: var(--tm-cobalt); border-color: var(--tm-cobalt); }
.form-check-input:focus { border-color: var(--tm-night); box-shadow: var(--tm-focus-ring); }

/* ── Tables: 14px text, hairline rules, mono uppercase column labels ── */
.table { --bs-table-border-color: var(--tm-line); font-size: 14px; }
.table th {
  font-family: var(--tm-font-mono); font-size: 12px; font-weight: 500;
  letter-spacing: 1.5px; text-transform: uppercase; color: var(--tm-muted);
}
.table-dark th, .table > thead.table-dark th { color: inherit; }

/* ── Badges, alerts, dropdowns, modals ── */
.badge, .badge-medpro { border-radius: var(--tm-radius-pill); font-weight: 500; }
.alert { border-radius: 12px; }
.dropdown-menu { border: 1px solid var(--tm-border); border-radius: 12px; box-shadow: none; }
.modal-content { border: 1px solid var(--tm-border); border-radius: var(--tm-radius-card); }
.modal-header { border-bottom-color: var(--tm-line); }
.modal-footer { border-top-color: var(--tm-line); }

/* ── Calm layer (16 October 2026): one quiet system on every page, including the
      ~80 templates not yet restyled by hand. Bootstrap's contextual colours are
      remapped to the status tones (never red), motion is off, elevation is flat
      and the contextual buttons share the navy outline. Pages still override. ── */
:root {
  --bs-success: #2B59F4;    --bs-success-rgb: 43, 89, 244;
  --bs-success-text-emphasis: #2B59F4; --bs-success-bg-subtle: var(--tm-room-og); --bs-success-border-subtle: #B9C8FF;
  --bs-info: #0370A4;       --bs-info-rgb: 3, 112, 164;
  --bs-info-text-emphasis: #0370A4;    --bs-info-bg-subtle: var(--tm-room-an);    --bs-info-border-subtle: #9FDCFB;
  --bs-warning: #F0A800;    --bs-warning-rgb: 240, 168, 0;
  --bs-warning-text-emphasis: #8F6400; --bs-warning-bg-subtle: var(--tm-room-op); --bs-warning-border-subtle: #F3DFA3;
  --bs-danger: #B84401;     --bs-danger-rgb: 184, 68, 1;
  --bs-danger-text-emphasis: #B84401;  --bs-danger-bg-subtle: var(--tm-room-or);  --bs-danger-border-subtle: #F9C9AE;
  --bs-secondary: #555565;  --bs-secondary-rgb: 85, 85, 101;
  --bs-secondary-text-emphasis: #3A3A4E; --bs-secondary-bg-subtle: var(--tm-off); --bs-secondary-border-subtle: var(--tm-border);
  --bs-dark: #1B1F3B;       --bs-dark-rgb: 27, 31, 59;
  --bs-light: #F4F1E9;      --bs-light-rgb: 244, 241, 233;
}
.text-warning { color: var(--tm-amber-text) !important; }   /* amber is a fill, not a text colour */
.bg-info.text-dark, .text-bg-info { color: #fff !important; }  /* info is now a dark sky: white text keeps 5.4:1 */

/* Contextual buttons. .btn-primary stays the one cobalt action. .btn-secondary (usually
   Cancel) and every outline variant share the navy outline. The filled contextual variants
   become solid navy rather than outline, because pages mark a toggle's selected option with
   a filled class (btn-success) against an outline one: both must still look different. */
.btn-secondary,
.btn-outline-secondary, .btn-outline-success, .btn-outline-danger, .btn-outline-warning, .btn-outline-info, .btn-outline-dark {
  --bs-btn-color: var(--tm-night); --bs-btn-bg: transparent; --bs-btn-border-color: var(--tm-night);
  --bs-btn-hover-color: var(--tm-cream); --bs-btn-hover-bg: var(--tm-night); --bs-btn-hover-border-color: var(--tm-night);
  --bs-btn-active-color: var(--tm-cream); --bs-btn-active-bg: var(--tm-night-2); --bs-btn-active-border-color: var(--tm-night-2);
  --bs-btn-disabled-color: var(--tm-muted); --bs-btn-disabled-bg: transparent; --bs-btn-disabled-border-color: var(--tm-border);
  --bs-btn-focus-shadow-rgb: 27, 31, 59;
}
.btn-success, .btn-danger, .btn-warning, .btn-info, .btn-dark {
  --bs-btn-color: var(--tm-cream); --bs-btn-bg: var(--tm-night); --bs-btn-border-color: var(--tm-night);
  --bs-btn-hover-color: var(--tm-cream); --bs-btn-hover-bg: var(--tm-night-2); --bs-btn-hover-border-color: var(--tm-night-2);
  --bs-btn-active-color: var(--tm-cream); --bs-btn-active-bg: var(--tm-night-2); --bs-btn-active-border-color: var(--tm-night-2);
  --bs-btn-disabled-color: var(--tm-cream); --bs-btn-disabled-bg: var(--tm-muted); --bs-btn-disabled-border-color: var(--tm-muted);
  --bs-btn-focus-shadow-rgb: 27, 31, 59;
}

/* Contextual table rows: pastel rooms, body text */
.table-primary, .table-success { --bs-table-bg: var(--tm-room-og); --bs-table-color: var(--tm-body); --bs-table-border-color: var(--tm-line); --bs-table-hover-bg: var(--tm-room-og); --bs-table-striped-bg: var(--tm-room-og); }
.table-info     { --bs-table-bg: var(--tm-room-an); --bs-table-color: var(--tm-body); --bs-table-border-color: var(--tm-line); --bs-table-hover-bg: var(--tm-room-an); --bs-table-striped-bg: var(--tm-room-an); }
.table-warning  { --bs-table-bg: var(--tm-room-op); --bs-table-color: var(--tm-body); --bs-table-border-color: var(--tm-line); --bs-table-hover-bg: var(--tm-room-op); --bs-table-striped-bg: var(--tm-room-op); }
.table-danger   { --bs-table-bg: var(--tm-room-or); --bs-table-color: var(--tm-body); --bs-table-border-color: var(--tm-line); --bs-table-hover-bg: var(--tm-room-or); --bs-table-striped-bg: var(--tm-room-or); }
.table-secondary, .table-light { --bs-table-bg: var(--tm-off); --bs-table-color: var(--tm-body); --bs-table-border-color: var(--tm-line); --bs-table-hover-bg: var(--tm-off); --bs-table-striped-bg: var(--tm-off); }
.table-dark     { --bs-table-bg: var(--tm-night); --bs-table-color: var(--tm-on-night); --bs-table-border-color: var(--tm-hairline-night); }

/* No motion, no elevation, no hover lift */
body *:not(.spinner-border):not(.spinner-grow) { animation: none !important; }
.card, .dropdown-menu, .modal-content, .toast, .alert, .list-group-item, .popover, .offcanvas, .accordion-item,
.shadow, .shadow-sm, .shadow-lg, .btn:not(:focus-visible), .form-control:not(:focus), .form-select:not(:focus) { box-shadow: none !important; }
.card:hover, .btn:hover, [class*="tile"]:hover, [class*="-card"]:hover { transform: none !important; }

/* Type: headings are medium weight, bold is 600, nothing heavier */
h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6 { font-weight: 500; }
b, strong { font-weight: 600; }
.fw-bold, .fw-bolder { font-weight: 600 !important; }

@media print {
  body { background: #fff !important; }
  .card { border-color: #ccc; }
}

/* ── Accessibility floor (19 Oct 2026) ── */
/* No reading text under 12 px: Bootstrap's .875em shrinks below that inside smaller text */
small, .small, .form-text, kbd { font-size: max(12px, .875em); }
/* Touch screens: every button and field at least 44 px tall (WCAG 2.5.5 target size) */
@media (pointer: coarse) {
  /* inline-flex drops the space between an icon and its label, so the gap puts it back */
  .btn, .page-link, .tm-seg a { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: .35em; }
  .btn { min-width: 44px; }
  .btn.text-start { justify-content: flex-start; }
  button, .form-control, .form-select, select,
  input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=hidden]) { min-height: 44px; }
}

/* ── One product (16 Nov 2026): shared pieces the module pages inherit ──
   The core pages were restyled by hand in October; the module pages (989 of the app's 1,439 routes)
   reach practices now and mostly build their look from inline styles. These rules cover what a
   stylesheet can reach; scripts/ui_palette.py rewrites the hard-coded colours it cannot. */
:root {
  /* Line tones: the border beside a status tint (the calm layer's border-subtle values, as tokens) */
  --tm-cobalt-line: #B9C8FF;
  --tm-sky-line: #9FDCFB;
  --tm-pink-line: #F3B9EA;
  --tm-orange-line: #F9C9AE;
  --tm-amber-line: #F3DFA3;
  /* The soft cobalt, as a token: light blue or green text and accents (a WhatsApp-green icon, a "done"
     border) that sit on white as often as on navy. The same value as the older --primary-light. */
  --tm-cobalt-soft: #8EA6FF;
}

/* Stat tiles on staff pages: the dashboard's white tile with a light navy number, whatever fill a module
   page gave its own. Thirteen templates painted them as blue, green, orange and red gradients.
   - Staff pages only (the sidebar is there): the patient portal's home tiles are a different thing.
   - Colour, edge and type only. The tile's own layout, the order of what is in it, and a coloured left
     border a page set from its data are left alone (the hairline is an inset shadow, not a border). */
.tm-shell > .tm-side ~ .tm-main .stat-card {
  background: var(--tm-white) !important; background-image: none !important; color: var(--tm-night) !important;
  box-shadow: inset 0 0 0 1px var(--tm-border) !important; border-radius: var(--tm-radius-card);
  align-items: flex-start; text-align: left; min-height: 0; padding: 18px 22px; height: 100%;
}
.tm-shell > .tm-side ~ .tm-main .stat-card .stat-value { font-size: 34px; font-weight: 300; letter-spacing: -1px; line-height: 1.1; color: var(--tm-night); }
.tm-shell > .tm-side ~ .tm-main .stat-card .stat-label {
  font-family: var(--tm-font-mono); font-size: 12px; letter-spacing: 2px; text-transform: uppercase;
  color: var(--tm-muted); opacity: 1; margin-top: 6px;
}
.tm-shell > .tm-side ~ .tm-main a.stat-card { text-decoration: none; }
.tm-shell > .tm-side ~ .tm-main a.stat-card:hover { box-shadow: inset 0 0 0 1px var(--tm-night) !important; }
/* A tile that is the chosen filter: a navy edge (it was a white outline on the old coloured fill) */
.tm-shell > .tm-side ~ .tm-main .stat-card.stat-on { box-shadow: inset 0 0 0 2px var(--tm-night) !important; outline: none; }

/* Bootstrap pieces the calm layer had not reached: tabs, pills, lists, hover rows, progress.
   :where() keeps these at zero specificity, so a page's own rules still win. */
:where(.tm-content, .modal) .nav-tabs { border-bottom: 1px solid var(--tm-border); }
:where(.tm-content, .modal) .nav-tabs .nav-link { color: var(--tm-secondary); font-weight: 500; border: 0; border-bottom: 2px solid transparent; border-radius: 0; }
:where(.tm-content, .modal) .nav-tabs .nav-link:hover { color: var(--tm-night); border-bottom-color: var(--tm-border); }
:where(.tm-content, .modal) .nav-tabs .nav-link.active { color: var(--tm-night); background: transparent; border-bottom-color: var(--tm-cobalt); }
:where(.tm-content, .modal) .nav-pills .nav-link { color: var(--tm-night); border-radius: var(--tm-radius-pill); font-weight: 500; }
:where(.tm-content, .modal) .nav-pills .nav-link.active { background: var(--tm-night); color: var(--tm-cream); }
.list-group {
  --bs-list-group-color: var(--tm-body); --bs-list-group-border-color: var(--tm-line);
  --bs-list-group-action-hover-bg: var(--tm-sand); --bs-list-group-action-active-bg: var(--tm-off);
  --bs-list-group-active-bg: var(--tm-night); --bs-list-group-active-border-color: var(--tm-night); --bs-list-group-active-color: var(--tm-cream);
}
.table-hover { --bs-table-hover-bg: var(--tm-sand); --bs-table-hover-color: var(--tm-body); }
.progress { --bs-progress-bg: var(--tm-off); --bs-progress-bar-bg: var(--tm-cobalt); --bs-progress-border-radius: var(--tm-radius-pill); }
.breadcrumb { --bs-breadcrumb-divider-color: var(--tm-muted); --bs-breadcrumb-item-active-color: var(--tm-secondary); font-size: 14px; }

/* Header content written for the old navy bar turns navy, unless the header (or the element)
   keeps its own background - module templates rely on this instead of each being edited. */
.card-header:not([style*="background"]):not([class*="bg-"]) .text-white:not(.btn):not(.badge):not([class*="bg-"]):not([style*="background"]),
.card-header:not([style*="background"]):not([class*="bg-"]) a[style*="color:#fff"]:not([style*="background"]) { color: var(--tm-night) !important; }
.card-header:not([style*="background"]):not([class*="bg-"]) .btn-outline-light {
  --bs-btn-color: var(--tm-night); --bs-btn-border-color: var(--tm-night);
  --bs-btn-hover-color: var(--tm-cream); --bs-btn-hover-bg: var(--tm-night); --bs-btn-hover-border-color: var(--tm-night);
  --bs-btn-active-color: var(--tm-cream); --bs-btn-active-bg: var(--tm-night); --bs-btn-active-border-color: var(--tm-night);
}
.card-header:not([style*="background"]):not([class*="bg-"]) .btn-close-white { filter: none; }
/* A header that keeps its own (usually dark) background keeps the light text it always had */
.card-header[style*="background"], .card-header[class*="bg-"] { color: var(--tm-on-night); }
/* ... unless that background is a light one. The colour rewrite of 16 Nov 2026 (scripts/ui_palette.py) turned
   the pale header fills of the module pages into light tokens; cream text cannot be read on them, as it
   could not on the pale colours they replace. A header whose own background is a light token takes navy
   text. Only the value of the background counts, in both spellings; a test checks every fill the tool can
   write (tests/ux/test_ui_palette.py). */
.card-header:is(
  [style*="background:var(--tm-sand)"], [style*="background: var(--tm-sand)"],
  [style*="background:var(--tm-off)"], [style*="background: var(--tm-off)"],
  [style*="background:var(--tm-border)"], [style*="background: var(--tm-border)"],
  [style*="background:var(--tm-on-night-muted)"], [style*="background: var(--tm-on-night-muted)"],
  [style*="background:var(--tm-white)"], [style*="background: var(--tm-white)"],
  [style*="background:var(--tm-cream)"], [style*="background: var(--tm-cream)"],
  [style*="background:var(--tm-amber)"], [style*="background: var(--tm-amber)"],
  [style*="background:var(--tm-room-"], [style*="background: var(--tm-room-"],
  [style*="background:var(--tm-cobalt-line)"], [style*="background: var(--tm-cobalt-line)"],
  [style*="background:var(--tm-sky-line)"], [style*="background: var(--tm-sky-line)"],
  [style*="background:var(--tm-pink-line)"], [style*="background: var(--tm-pink-line)"],
  [style*="background:var(--tm-orange-line)"], [style*="background: var(--tm-orange-line)"],
  [style*="background:var(--tm-amber-line)"], [style*="background: var(--tm-amber-line)"]
) { color: var(--tm-night); }
