/* =====================================================================================================
   DailyMed Explorer design system
   Modalis branding (modalis.ai): Manrope text, Comfortaa headings, dark blue #28709e, flat surfaces with a frosted top bar.
   Sections: 1 tokens · 2 base · 3 layout shells · 4 components · 5 utilities · 6 responsive
   Templates use only these classes; colours, fonts, radii and shadows are defined only in section 1.
   ===================================================================================================== */

/* 1. Tokens ------------------------------------------------------------------------------------------ */
@font-face {
  font-family: "Manrope";
  src: url("../fonts/manrope-latin-wght-normal.woff2") format("woff2");
  font-weight: 200 800;
  font-display: swap;
}
@font-face {
  font-family: "Comfortaa";
  src: url("../fonts/comfortaa-latin-wght-normal.woff2") format("woff2");
  font-weight: 300 700;
  font-display: swap;
}

:root {
  --primary: #28709e;
  --primary-hover: #1ba1e2;   /* modalis.ai: blue buttons turn light blue on hover */
  --primary-soft: #f2f6fa;
  --primary-tint: rgba(40, 112, 158, 0.1);
  --accent: #1ba1e2;
  /* second colour (modalis.ai teal) for data and selection only: chart bars, chosen filters, open row, avatar */
  --data: #009999;
  --data-strong: #007a7a;      /* white text on it passes AA */
  --data-soft: #e6f5f5;
  --text: #000000;
  --text-2: #1f2328;           /* secondary text that must stay strong (labels, headers) */
  --muted: #474d55;            /* captions and hints: neutral grey, ~8:1 on white */
  --line: rgba(15, 23, 42, 0.10);
  --line-strong: rgba(15, 23, 42, 0.18);
  --surface: #ffffff;
  --surface-soft: #f5f6f8;     /* neutral fill: tracks, chips, section footers */
  --table-head: #e9ecf1;       /* clearly darker than cards so the header row stands out */
  --callout-bg: #eef4f9;       /* explanatory text: tinted, never used for data */
  --gray: #ced4da;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --success: #1e7a4c;
  --success-soft: #e9f6ef;
  --warn-soft: #fff7e0;
  --warn-line: #f0c541;

  --glass-bg: rgba(255, 255, 255, 0.68);
  --glass-strong: rgba(255, 255, 255, 0.9);
  --glass-border: rgba(255, 255, 255, 0.85);
  --glass-blur: 16px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 28px rgba(15, 23, 42, 0.06);
  --shadow-lift: 0 12px 40px rgba(15, 23, 42, 0.12);

  --radius: 10px;
  --radius-sm: 8px;
  --sidebar-bg: #f4f5f7;
  --canvas-inset: 8px;       /* gap between the grey frame and the white work area */
  --pill: 999px;
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;

  --font-text: "Manrope", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-head: "Comfortaa", "Manrope", system-ui, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --navbar-height: 48px;
  --panel-width: 264px;
  /* the filter panel sticks below the navbar and is capped to the free space, so it is never pushed under it */
  --panel-top: calc(var(--navbar-height) + var(--space-2) + var(--space-4));
}

/* 2. Base -------------------------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; font-size: 15px; }  /* rem base: one notch smaller than 16px */
body {
  margin: 0;
  min-height: 100vh;
  font: 400 14px/1.5 var(--font-text);
  color: var(--text);
  background: var(--sidebar-bg);  /* the grey frame shared by top bar and sidebar (Databricks-style) */
}
h1, h2, h3 { font-family: var(--font-head); font-weight: 700; letter-spacing: -0.03em; line-height: 1.2; margin: 0 0 var(--space-3); }
h1 { font-size: 1.7rem; }
h2 { font-size: 1.2rem; margin-top: var(--space-6); }
h3 { font-size: 0.98rem; }
p { margin: 0 0 var(--space-3); }
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }
a:hover { text-decoration: underline; }
code { font-family: var(--font-mono); font-size: 0.84em; background: var(--surface-soft); color: var(--text-2); border: 1px solid var(--line); padding: 0.05rem 0.35rem; border-radius: 6px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
img { max-width: 100%; }

/* 3. Layout shells ----------------------------------------------------------------------------------- */
/* Content surfaces are flat: white, one thin border, no shadow (clear to read, as in analytics tools).
   Frosted glass is kept only for the top bar and floating layers (menus, sign-in card). */
.surface { background: var(--surface); border: 1px solid var(--line); }
.frosted {
  background: var(--glass-strong);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(140%);
  backdrop-filter: blur(var(--glass-blur)) saturate(140%);
}

.navbar {
  position: sticky; top: 0; z-index: 20;
  height: var(--navbar-height);
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: var(--space-4);
  padding: 0 var(--space-4);
  border: 0;
  background: var(--sidebar-bg);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(140%);
  backdrop-filter: blur(var(--glass-blur)) saturate(140%);
}
.brand { justify-self: start; display: flex; align-items: center; gap: var(--space-3); color: var(--text); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand img { height: 18px; width: auto; }
.brand a { color: inherit; }
.brand a:hover { text-decoration: none; }
.brand-logo { display: inline-flex; align-items: center; }
a.brand-name:hover { color: var(--primary); }
.brand-name { font-family: var(--font-head); font-weight: 700; letter-spacing: -0.03em; font-size: 0.92rem; padding-left: var(--space-3); border-left: 1px solid var(--line); }
.nav-links { justify-self: center; display: flex; align-items: center; gap: var(--space-1); min-width: 0; max-width: 100%; overflow-x: auto; scrollbar-width: none; padding: 3px; border: 1px solid var(--line); border-radius: 12px; background: rgba(15, 23, 42, 0.05); }
.nav-links::-webkit-scrollbar { display: none; }
.nav-link { display: inline-flex; align-items: center; gap: var(--space-2); padding: 0.3rem 0.85rem; border-radius: var(--pill); color: var(--text); font-weight: 500; font-size: 0.9rem; white-space: nowrap; }
.nav-link .icon, .nav-link .nav-label-short { display: none; }
@media (hover: hover) {  /* real pointers only: on touch screens a tapped tab would keep its hover colour */
  .nav-link:hover { background: var(--primary-hover); color: #fff; text-decoration: none; }  /* same as the active tab's hover */
  .nav-link.active:hover { background: var(--primary-hover); color: #fff; }
}
.nav-link.active { background: var(--primary); color: #fff; }
/* new tab content fades in (app.js sets .tab-entering on <html> for a tab switch) */
.tab-entering #main { animation: tab-enter 0.2s ease; }
@keyframes tab-enter { from { opacity: 0; } }
.nav-right { justify-self: end; display: flex; align-items: center; gap: var(--space-3); }
.btn.nav-admin { border-color: var(--primary); color: var(--primary); background: #fff; }
.btn.nav-admin:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: #fff; }
.btn.nav-admin.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.nav-admin.active:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.avatar { box-shadow: 0 0 0 2px #fff, 0 0 0 3px rgba(0, 153, 153, 0.35); }
.menu > summary:hover .avatar { background: var(--data); }

.app-shell { display: grid; grid-template-columns: var(--panel-width) minmax(0, 1fr); min-height: calc(100vh - var(--navbar-height)); }
/* full-height sidebar below the top bar: always exactly the free height, so it never moves */
.panel {
  position: sticky; top: var(--navbar-height); align-self: start;
  height: calc(100vh - var(--navbar-height)); overflow-y: auto;
  padding: var(--space-4) var(--space-4) var(--space-5); background: var(--sidebar-bg);
  border: 0; border-radius: 0;
}
/* metrics strip (Label Monitor's Overview key figures; the look DailyMed Explorer's strip had) */
.metrics { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); margin-bottom: var(--space-4); border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.metric { padding: var(--space-3) var(--space-5); min-width: 0; }
.metric + .metric { border-left: 1px solid var(--line); }
.metric-label { font-size: 0.78rem; font-weight: 700; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.05em; }
.metric-value { font-family: var(--font-text); font-size: 1.75rem; font-weight: 700; letter-spacing: -0.02em; color: var(--text); font-variant-numeric: tabular-nums; }
/* Label Monitor: a label's images from DailyMed, one of the label's sections (.label-section) */
.label-images > summary .title-row { display: inline-flex; }
.label-images-body { padding: var(--space-3); display: grid; gap: var(--space-3); }
.label-images-body > .caption { margin: 0; }
.label-images-foot { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap; padding-top: var(--space-3); border-top: 1px solid var(--line); }
.image-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: var(--space-3); }
.image-grid li { display: grid; gap: var(--space-1); min-width: 0; }
.image-thumb { display: flex; align-items: center; justify-content: center; height: 120px; padding: var(--space-2); border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fff; }
.image-thumb:hover { border-color: var(--primary-hover); }
.image-thumb img { max-width: 100%; max-height: 100%; object-fit: contain; }
.image-meta { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1) var(--space-2); font-size: 0.75rem; min-width: 0; }
.image-name { flex: 1 0 100%; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }  /* its own line */
.image-meta > a { margin-left: auto; }
/* "Show all": one grid, the images after the first 4 hidden (and so not loaded) until the toggle is checked */
.image-gallery { display: grid; gap: var(--space-3); }
.image-toggle:not(:checked) ~ .image-grid > li:nth-child(n+5) { display: none; }
.image-toggle-button { width: fit-content; cursor: pointer; }
.image-toggle-button .when-open, .image-toggle:checked ~ .image-toggle-button .when-closed { display: none; }
.image-toggle:checked ~ .image-toggle-button .when-open { display: inline-flex; }
.image-toggle-button .when-closed { display: inline-flex; }
.image-toggle-button > span { align-items: center; gap: var(--space-1); }
.image-toggle:focus-visible ~ .image-toggle-button { outline: 2px solid var(--primary); outline-offset: 2px; }

/* Label Monitor: one panel frame on every tab; the data status sits at the bottom */
.panel-frame { display: flex; flex-direction: column; }
.panel-shared { padding-bottom: var(--space-2); margin-bottom: var(--space-4); border-bottom: 1px solid var(--line); }
.panel-status { margin-top: auto; padding-top: var(--space-4); border-top: 1px solid var(--line); }
.panel-status .panel-title { margin-bottom: var(--space-2); font-size: 0.9rem; }
.facts-compact { font-size: 0.8rem; gap: var(--space-1); margin-bottom: 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-4); }
/* filter drawer: plain panel on desktop; a toggle ("Filters · N active") on small screens */
.filter-toggle, .btn.filter-done { display: none; }
.filter-drawer > summary { list-style: none; }
.filter-drawer > summary::-webkit-details-marker { display: none; }
.panel-title { font-size: 1rem; margin: 0; }
.panel-head a { font-size: 0.82rem; font-weight: 600; }
/* the work area is a white canvas set into the frame: fine inset, rounded, hairline border; fluid width */
.main {
  --main-pad-x: var(--space-6);
  min-width: 0; padding: var(--space-5) var(--main-pad-x) var(--space-6);
  margin: 0 var(--canvas-inset) var(--canvas-inset) 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  min-height: calc(100vh - var(--navbar-height) - var(--canvas-inset));
}
.page-header { margin: 0 0 var(--space-5); padding-bottom: var(--space-4); border-bottom: 1px solid var(--line); }
.page-header h1 {
  margin: 0; font-size: 1.85rem; gap: var(--space-3); font-weight: 700; color: #000;
  -webkit-text-stroke: 0.45px currentColor;  /* Comfortaa's heaviest weight is 700; a hairline stroke makes it bolder */
  paint-order: stroke fill;
}
.page-icon { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border-radius: 10px; background: var(--primary); color: #fff; flex: 0 0 auto; -webkit-text-stroke: 0; }  /* inverted, like the active view tab */
.page-icon .icon { width: 22px; height: 22px; stroke-width: 2.4; }
.page-sub { margin: var(--space-2) 0 0; color: var(--muted); font-size: 0.92rem; max-width: 90ch; }
.page { padding: var(--space-5) var(--space-6) var(--space-6); }

.auth-shell {
  min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: var(--space-6) var(--space-4);
  background:
    radial-gradient(900px 600px at 8% -10%, rgba(27, 161, 226, 0.08), transparent 60%),
    radial-gradient(800px 600px at 100% 20%, rgba(0, 153, 153, 0.06), transparent 60%),
    linear-gradient(180deg, #ffffff 0%, var(--primary-soft) 100%);
}
.auth-logo { height: 20px; width: auto; margin-bottom: var(--space-4); }  /* about the height of the "Log in" heading */
.auth-card { width: 100%; max-width: 380px; padding: var(--space-6) 2.25rem; border-radius: 14px; box-shadow: var(--shadow); }
.auth-card h1 { font-size: 1.25rem; text-align: center; margin-bottom: var(--space-5); }
.auth-footer { display: flex; gap: var(--space-5); margin-top: var(--space-6); font-size: 0.85rem; }
.auth-footer a { color: var(--muted); }
.auth-footer a[aria-current="page"] { color: var(--text); font-weight: 600; }

/* public legal pages: the signed-out shell with a wide, left-aligned reading column */
.legal-shell { justify-content: flex-start; }
.auth-card.legal-card { max-width: 760px; padding: var(--space-6) 2.5rem; line-height: 1.6; }
.legal-card h1 { text-align: left; font-size: 1.6rem; margin: var(--space-4) 0 var(--space-1); }
.legal-card h2 { font-size: 1.05rem; margin: var(--space-6) 0 var(--space-2); }
.legal-card p, .legal-card li { font-size: 0.92rem; }
.legal-card p { margin: 0 0 var(--space-3); }
.legal-card ul { margin: 0 0 var(--space-3); padding-left: 1.25rem; }
.legal-card li + li { margin-top: var(--space-2); }
.legal-card a { color: var(--primary); }
.legal-back { display: inline-flex; align-items: center; gap: var(--space-2); font-size: 0.85rem; text-decoration: none; }
.legal-updated { color: var(--muted); font-size: 0.85rem !important; }

/* 4. Components -------------------------------------------------------------------------------------- */
.card { padding: var(--space-5); border-radius: var(--radius); margin-bottom: var(--space-4); }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  padding: 0.5rem 1.1rem; border-radius: var(--pill); border: 1px solid var(--line-strong);
  font: 600 0.88rem/1.2 var(--font-text); color: var(--text); background: rgba(255, 255, 255, 0.7);
  cursor: pointer; white-space: nowrap; text-decoration: none; transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.btn:hover { border-color: var(--primary); color: var(--primary); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover, .btn-primary:focus-visible { background: var(--primary-hover); border-color: var(--primary-hover); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-soft); border-color: transparent; }
.btn-danger:hover { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-sm { padding: 0.28rem 0.7rem; font-size: 0.8rem; }
.btn-block { width: 100%; padding: 0.7rem 1rem; }
.btn[aria-disabled="true"] { opacity: 0.4; pointer-events: none; }
/* a download the license does not allow: visible and hoverable (the tooltip says why), never clickable */
.btn.btn-locked { opacity: 0.55; pointer-events: auto; cursor: not-allowed; }
.btn.btn-locked:hover { border-color: var(--line-strong); color: var(--text); }
.btn-link { background: none; border: 0; padding: 0; font: inherit; color: var(--primary); cursor: pointer; }
.btn-link:hover { color: var(--primary-hover); }

/* form fields */
.field { display: block; margin-bottom: var(--space-4); font-size: 0.84rem; font-weight: 600; color: var(--text-2); }
.field > .input, .field > select, .field > .ts-wrapper { margin-top: var(--space-1); }
.input {
  display: block; width: 100%; padding: 0.6rem 0.85rem; font: 400 0.92rem var(--font-text); color: var(--text);
  background: rgba(255, 255, 255, 0.85); border: 1px solid var(--line); border-radius: var(--radius-sm);
}
.input::placeholder { color: #6b7280; }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(27, 161, 226, 0.18); }
.search { position: relative; }
.search svg { position: absolute; left: 1.1rem; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--primary); pointer-events: none; }
.search .input {
  padding: 0.75rem 3rem 0.75rem 2.9rem; border-radius: var(--pill); font-size: 1rem; background: #fff;
  border: 1.5px solid rgba(40, 112, 158, 0.45); box-shadow: 0 0 0 4px rgba(40, 112, 158, 0.06);
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
  animation: search-glow 2.4s ease-in-out 0.2s 1;  /* on page load: glows once, together with the query bar pulse */
}
.search .input::placeholder { color: #4b5563; }
/* active search look, faded in: on focus and while the query bar is hovered (same trigger as its gradient swap) */
.search .input:focus, .query-bar:hover .search .input { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(27, 161, 226, 0.18); }
@keyframes search-glow { 50% { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(27, 161, 226, 0.18); } }
.search-kbd {
  position: absolute; right: 1rem; top: 50%; transform: translateY(-50%); pointer-events: none;
  min-width: 1.5rem; padding: 0.05rem 0.4rem; text-align: center; border-radius: 6px;
  border: 1px solid var(--line-strong); background: var(--surface-soft); color: var(--text-2);
  font: 700 0.75rem/1.4 var(--font-mono);
}
.search .input:focus ~ .search-kbd, .search .input:not(:placeholder-shown) ~ .search-kbd { display: none; }
/* the same search field in a sidebar: compact, no load glow */
.search-compact svg { left: 0.75rem; width: 16px; height: 16px; }
.search-compact .input { padding: 0.5rem 0.75rem 0.5rem 2.2rem; border-radius: var(--radius-sm); font-size: 0.88rem; border-width: 1px; box-shadow: none; animation: none; }
/* work area: the query bar card and the canvas, stacked on the grey frame */
.workarea { display: flex; flex-direction: column; gap: var(--canvas-inset); min-width: 0; padding: 0 var(--canvas-inset) var(--canvas-inset) 0; }
.workarea > .main { margin: 0; flex: 1 1 auto; }
/* query bar: shared by all views, a separate card above the canvas (it never scrolls away) */
.query-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3) var(--space-5);
  padding: var(--space-3) var(--space-5);
  background: radial-gradient(circle at 15% 30%, rgba(27, 161, 226, 0.12), transparent 35%), radial-gradient(circle at 85% 70%, rgba(0, 153, 153, 0.10), transparent 35%), #f2f6fa; border: 1px solid var(--line); border-radius: 12px;
  position: relative; isolation: isolate;  /* holds the swapped-colour layer below */
}
/* Search active (hover, focus, typing): the same glows with the colours swapped fade in on top, so teal takes the
   upper left. Nothing moves; only opacity changes, which is smooth on every device and screen width.
   On page load the swapped layer fades in and out once. */
.query-bar::before {
  content: ""; position: absolute; inset: 0; z-index: -1; border-radius: inherit; pointer-events: none;
  background: radial-gradient(circle at 15% 30%, rgba(0, 153, 153, 0.12), transparent 35%), radial-gradient(circle at 85% 70%, rgba(27, 161, 226, 0.10), transparent 35%), #f2f6fa;
  opacity: 0;
  transition: opacity 0.3s ease;
  animation: qb-pulse 2.4s ease-in-out 0.2s 1;
}
.query-bar:hover::before, .query-bar:focus-within::before { opacity: 1; }
@keyframes qb-pulse { 50% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  .query-bar::before, .search .input { animation: none; transition: none; }
  .tab-entering #main { animation: none; }
}
.query-bar .search { flex: 1 1 420px; min-width: 0; }
.query-options { display: flex; align-items: center; gap: var(--space-4); flex-wrap: wrap; }
.query-help { display: inline-flex; color: var(--muted); cursor: help; }
.query-help:hover, .query-help:focus-visible { color: var(--primary); }
.match-count { font-size: 0.88rem; color: var(--text-2); white-space: nowrap; padding-left: var(--space-4); border-left: 1px solid var(--line); }
.match-count strong { color: var(--text); font-size: 0.95rem; }
.toggle { display: inline-flex; align-items: center; gap: var(--space-2); font-size: 0.88rem; cursor: pointer; }
.toggle input { width: 1rem; height: 1rem; accent-color: var(--primary); }
.toggle-wrap { display: flex; align-items: flex-start; line-height: 1.45; }  /* multi-line label: box on the first line */
.toggle-wrap input { flex: 0 0 auto; margin-top: 0.15rem; }
.field-narrow { max-width: 360px; }
.form-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--space-4); }
.form-row .field { flex: 1 1 220px; margin-bottom: 0; }

/* Tom Select (searchable multi-selects), themed with the tokens */
.ts-wrapper .ts-control { border-radius: var(--radius-sm); border: 1px solid var(--line); background: rgba(255, 255, 255, 0.85); padding: 0.45rem 0.6rem; font-family: var(--font-text); font-size: 0.9rem; box-shadow: none; }
.ts-wrapper.focus .ts-control { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(27, 161, 226, 0.18); }
.ts-wrapper.multi .ts-control > div { background: var(--data-soft); color: var(--data-strong); border: 1px solid rgba(0, 153, 153, 0.35); border-radius: var(--pill); padding: 0.05rem 0.55rem; font-weight: 600; }
.ts-wrapper.multi .ts-control > div.active { background: var(--data-strong); color: #fff; }
.ts-wrapper.plugin-remove_button .item .remove { border-left: 0; color: inherit; margin-left: 0.2rem; }
.ts-dropdown { border-radius: var(--radius-sm); border: 1px solid var(--line); box-shadow: var(--shadow-lift); font-family: var(--font-text); font-size: 0.88rem; margin-top: 4px; }
.ts-dropdown .active { background: var(--surface-soft); color: var(--text); }
.ts-dropdown .selected { background: var(--primary-tint); }

/* notes */
.note { padding: var(--space-3) var(--space-4); border-radius: var(--radius-sm); margin: var(--space-3) 0; font-size: 0.9rem; background: var(--surface-soft); border: 1px solid var(--line); }
.note-info, .callout {
  display: flex; gap: var(--space-3); align-items: flex-start;
  background: var(--callout-bg); border: 0;
  color: var(--text-2); font-size: 0.82rem; line-height: 1.5;
}
.callout .icon { color: var(--primary); margin-top: 1px; }
.note-error { background: var(--danger-soft); border-color: rgba(180, 35, 24, 0.2); color: var(--danger); }
.note-success { background: var(--success-soft); border-color: rgba(30, 122, 76, 0.2); color: var(--success); }
.note-warn { background: var(--warn-soft); border-color: var(--warn-line); }
.otp-value { display: block; width: fit-content; margin: var(--space-2) 0; padding: var(--space-2) var(--space-3); font-size: 1.3rem; user-select: all; }

/* status bar: fixed to the bottom edge of the main panel (sticky), full width, small type, like an editor's status
   bar; the content scrolls behind it. On small screens it sticks to the bottom of the screen. Always one row. */
.main:has(> #main > .status-bar) { padding-bottom: 0; }  /* the bar is the panel's last row, down to its edge */
#main:has(> .status-bar) { display: flex; flex-direction: column; min-height: 100%; }  /* short views: bar still at the bottom */
.view-body { flex: 1 0 auto; }
.status-bar { position: sticky; bottom: 0; z-index: 2; display: flex; align-items: center; margin: 0 calc(-1 * var(--main-pad-x)); padding: 0.35rem var(--main-pad-x); background: var(--surface); border-top: 1px solid var(--line); font-size: 0.75rem; color: var(--muted); }
.status-values { display: flex; margin: 0; white-space: nowrap; }
.status-value { display: flex; gap: var(--space-2); padding: 0 var(--space-4); border-left: 1px solid var(--line); }
.status-value:first-child { padding-left: 0; border-left: 0; }
.status-value dt, .status-value dd { margin: 0; }
.status-value dd { color: var(--text-2); font-weight: 600; font-variant-numeric: tabular-nums; }

/* tables */
.table-card { border-radius: var(--radius); overflow: hidden; background: var(--surface); border: 1px solid var(--line-strong); }
.table-scroll { overflow: auto; max-height: 580px; }
.table { border-collapse: separate; border-spacing: 0; width: max-content; min-width: 100%; font-size: 0.85rem; }
.table th { position: sticky; top: 0; z-index: 1; background: var(--table-head); text-align: left; font-weight: 700; font-size: 0.78rem; color: var(--text); border-bottom: 1px solid var(--line-strong); white-space: nowrap; }
.table th, .table td { padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); vertical-align: top; }
.table th:last-child, .table td:last-child { border-right: 0; }
.table th { border-right-color: var(--line-strong); }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:nth-child(even) { background: rgba(15, 23, 42, 0.015); }
.table tbody tr:hover { background: rgba(40, 112, 158, 0.05); }
.table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-expandable tbody tr { cursor: pointer; }
.clip { max-width: 18rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.table tbody tr.expanded { background: var(--data-soft); }
.table tbody tr.expanded .clip { white-space: normal; max-width: 34rem; word-break: break-word; }
.table-full { width: 100%; }
.cell-actions { white-space: nowrap; }
.pagination { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; margin: var(--space-3) 0; font-size: 0.86rem; color: var(--text-2); }

/* collapsible sections */
.disclosure { border-radius: var(--radius); margin: var(--space-4) 0; padding: var(--space-3) var(--space-5); }
.disclosure > summary { cursor: pointer; font-weight: 600; }
.disclosure[open] > summary { margin-bottom: var(--space-3); }
.sort-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: var(--space-3); }
.sort-grid .field { margin-bottom: 0; }

/* user menu */
.menu { position: relative; }
.menu > summary { list-style: none; cursor: pointer; }
.menu > summary::-webkit-details-marker { display: none; }
.menu-panel { position: absolute; right: 0; top: calc(100% + var(--space-2)); min-width: 240px; padding: var(--space-3); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-lift); }
.menu-panel .menu-email { font-size: 0.82rem; color: var(--text-2); padding: var(--space-1) var(--space-2) var(--space-2); border-bottom: 1px solid var(--line); margin-bottom: var(--space-2); word-break: break-all; }
.menu-item { display: block; width: 100%; text-align: left; padding: 0.45rem var(--space-2); border-radius: var(--radius-sm); color: var(--text); background: none; border: 0; font: 500 0.9rem var(--font-text); cursor: pointer; }
.menu-item:hover { background: var(--surface-soft); text-decoration: none; }
.avatar { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; border-radius: 50%; background: var(--data-strong); color: #fff; font-weight: 700; font-size: 0.85rem; text-transform: uppercase; }

/* charts */
.charts { display: grid; gap: var(--space-4); margin-top: var(--space-3); }
.charts > h2 { margin: 0; }
.chart-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-4); }
.chart-wide { grid-column: 1 / -1; }
.chart { padding: var(--space-4) var(--space-5); border-radius: var(--radius); min-width: 0; }
.bars { list-style: none; margin: 0; padding: 0; }
.bars li { display: grid; grid-template-columns: minmax(8rem, 15rem) 1fr 4.5rem; gap: var(--space-3); align-items: center; font-size: 0.8rem; margin: 4px 0; }
.bar-label { text-align: right; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 10px; border-radius: var(--pill); background: var(--data-soft); }
.bar { display: block; height: 100%; min-width: 3px; border-radius: var(--pill); background: var(--data); }
.bar-value { font-variant-numeric: tabular-nums; font-weight: 600; }

/* spinner and loading */
.spinner { width: 1.6rem; height: 1.6rem; border: 3px solid var(--primary-tint); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite; margin: 0 auto var(--space-3); }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-bar { position: fixed; top: 0; left: 0; z-index: 50; height: 3px; width: 0; opacity: 0; background: var(--primary); }
.loading-bar.htmx-request { opacity: 1; width: 70%; transition: width 2s ease-out; }
#main.htmx-request { opacity: 0.6; transition: opacity 0.2s; }
.tag { display: inline-block; font-size: 0.72rem; font-weight: 700; padding: 0.1rem 0.5rem; border-radius: var(--pill); background: var(--surface-soft); color: var(--text-2); border: 1px solid var(--line); }
.tag-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.tag-success { background: var(--success-soft); border-color: rgba(30, 122, 76, 0.25); color: var(--success); }
.tag-muted { color: var(--muted); }
.tag-data { background: var(--data-soft); border-color: rgba(0, 153, 153, 0.35); color: var(--data-strong); }
.tag-button { cursor: pointer; font-family: inherit; line-height: inherit; }  /* a tag that is also a toggle (admin license) */
.tag-button:hover { border-color: var(--primary-hover); color: var(--primary); }

/* select: one look in every browser. The closed control is styled with appearance:none; app.js upgrades
   every select to Tom Select, so the open list matches the multi-selects too (native list without JS). */
select.input {
  -webkit-appearance: none; appearance: none; padding-right: 2.2rem; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%231f2328' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 0.75rem center; background-size: 16px;
}
/* Tom Select copies the select's classes onto its wrapper; only the inner control is drawn. */
.ts-wrapper.input { padding: 0; border: 0; background: none; box-shadow: none; min-height: 0; }
.ts-wrapper.single .ts-control { padding: 0.6rem 2.2rem 0.6rem 0.85rem; cursor: pointer; font-size: 0.92rem; }
.ts-wrapper.single .ts-control::after {
  content: ""; position: absolute; right: 0.75rem; top: 50%; width: 16px; height: 16px; margin-top: -8px; border: 0;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%231f2328' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat center / 16px;
}
.ts-wrapper.single.dropdown-active .ts-control::after { transform: rotate(180deg); }
.ts-wrapper.single .ts-control .item { color: var(--text); }

/* sections: one bordered card per block in the main panel (head · controls · body · foot) */
.section { background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius); margin-bottom: var(--space-5); overflow: hidden; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap; padding: var(--space-3) var(--space-5); border-bottom: 1px solid var(--line); }
.section-head h3 { margin: 0; }
.section-actions { display: flex; align-items: center; gap: var(--space-2); }
.section-body { padding: var(--space-4) var(--space-5); }
.section-foot { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap; padding: var(--space-2) var(--space-5); border-top: 1px solid var(--line); background: var(--surface-soft); }
.section-foot .caption, .section-foot .pagination { margin: 0; }
.section .table-scroll { max-height: 600px; }
.section-title-count { font-family: var(--font-text); }
.foot-right { display: flex; align-items: center; gap: var(--space-4); flex-wrap: wrap; margin-left: auto; }
.inline-field { display: inline-flex; align-items: center; gap: var(--space-2); font-size: 0.82rem; font-weight: 600; color: var(--text-2); }
.inline-field .ts-wrapper, .inline-field select { width: 5.5rem; margin: 0; }
.input-sm, .ts-wrapper.input-sm.single .ts-control { padding-top: 0.3rem; padding-bottom: 0.3rem; font-size: 0.82rem; }

.summary-chevron { transition: transform 0.15s; }
.watch-section > summary { list-style: none; cursor: pointer; }
.watch-section > summary::-webkit-details-marker { display: none; }
.watch-section:not([open]) > summary { border-bottom: 0; }
details[open] > summary .summary-chevron { transform: rotate(90deg); }

/* sortable column headers */
.table th:has(.th-sort) { padding: 0; }
.th-sort { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); padding: 0.5rem 0.75rem; color: inherit; cursor: pointer; user-select: none; }
.th-sort:hover { background: rgba(15, 23, 42, 0.05); color: var(--text); text-decoration: none; }
.sort-ind { display: inline-flex; align-items: center; color: var(--muted); opacity: 0.45; }
.sort-ind .icon { width: 14px; height: 14px; }
.sort-ind sup { font-size: 0.65rem; font-weight: 700; margin-left: 1px; }
.th-sort:hover .sort-ind { opacity: 0.8; }
.th-sort.sorted { color: var(--primary); }
.th-sort.sorted .sort-ind { color: var(--primary); opacity: 1; }

/* chips: multi-value cells (NDCs, routes, dosage forms, …) */
.chips { display: flex; gap: 4px; flex-wrap: nowrap; }
.table tbody tr.expanded .chips { flex-wrap: wrap; }
.chip { display: inline-block; padding: 0.05rem 0.5rem; border-radius: var(--pill); background: #eef1f5; border: 1px solid var(--line); font-size: 0.76rem; font-weight: 600; white-space: nowrap; color: var(--text); }

/* one-time password with copy button */
.otp-row { display: flex; align-items: center; gap: var(--space-2); margin: var(--space-2) 0; }
.otp-row .otp-value { margin: 0; }
.btn.copied { background: var(--success-soft); border-color: var(--success); color: var(--success); }

/* main panel rhythm: one gap between every block; tables get extra room around them */
#main { display: flex; flex-direction: column; gap: var(--space-5); }
#main > * { margin-top: 0; margin-bottom: 0; }
#main > .section { margin: var(--space-2) 0; }

/* icons and icon buttons */
.icon { width: 18px; height: 18px; flex: 0 0 auto; }
.btn .icon { width: 16px; height: 16px; }
.btn-icon { padding: 0; width: 34px; height: 34px; }
.btn-icon.btn-sm { width: 30px; height: 30px; }
.icon-actions { display: inline-flex; gap: var(--space-1); }
.icon-actions form { margin: 0; }
.title-row { display: flex; align-items: center; gap: var(--space-2); }

/* tooltip (one floating element positioned by app.js; never clipped by scroll containers) */
.tooltip {
  position: fixed; z-index: 100; pointer-events: none; max-width: 260px;
  padding: 0.3rem 0.55rem; border-radius: 6px; background: #111827; color: #fff;
  font: 600 0.75rem/1.3 var(--font-text); box-shadow: var(--shadow-lift);
  opacity: 0; transition: opacity 0.12s;
}
.tooltip.visible { opacity: 1; }

/* side menu (admin and future sections) */
.side-menu { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-1); }
.side-menu-item { display: flex; align-items: center; gap: var(--space-3); padding: 0.55rem 0.75rem; border-radius: var(--radius-sm); color: var(--text); font-weight: 600; font-size: 0.92rem; }
.side-menu-item:hover { background: var(--surface-soft); text-decoration: none; }
.side-menu-item.active { background: var(--primary); color: #fff; }
.side-menu-item.active:hover { background: var(--primary-hover); color: #fff; }
.side-menu-sep { height: 1px; background: var(--line); margin: var(--space-3) 0; }

/* 5. Utilities --------------------------------------------------------------------------------------- */
.muted { color: var(--muted); }
.caption { font-size: 0.82rem; color: var(--muted); margin: var(--space-2) 0 var(--space-3); }
.stack { display: grid; gap: var(--space-3); }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); }
.center { text-align: center; }
.row.center { justify-content: center; margin-top: var(--space-4); }
.inline-form { display: inline; margin: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

/* 5b. Platform and service components ----------------------------------------------------------------- */
/* navbar: brand plus the service switcher on the left */
.brand-wrap { justify-self: start; display: flex; align-items: center; gap: var(--space-2); min-width: 0; }
.switcher > summary { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; border-radius: var(--radius-sm); color: var(--text-2); }
.switcher > summary:hover, .switcher[open] > summary { background: rgba(15, 23, 42, 0.07); }
.switcher > summary.active { color: var(--primary); }  /* on an admin page */
.switcher > summary { position: relative; }
.notice-dot { position: absolute; top: -4px; right: -6px; min-width: 1.1rem; padding: 0 0.3rem; border-radius: var(--pill); background: var(--danger); color: #fff; font-size: 0.66rem; font-weight: 700; line-height: 1.1rem; text-align: center; }
.notice-panel:empty { display: none; }
.notice { display: grid; gap: var(--space-1); }
.notice-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.notice-detail { margin: 0; white-space: pre-line; }
.notice .caption { margin: 0; }
.menu-sep { height: 1px; background: var(--line); margin: var(--space-2) 0; }
.menu-item.active { background: var(--primary-tint); color: var(--primary); }
.nav-badge { display: inline-block; min-width: 1.3rem; padding: 0 0.35rem; border-radius: var(--pill); background: var(--data); color: #fff; font-size: 0.7rem; font-weight: 700; text-align: center; line-height: 1.3rem; }
.auth-product { margin: calc(-1 * var(--space-3)) 0 var(--space-4); font-family: var(--font-head); font-weight: 700; font-size: 0.95rem; letter-spacing: -0.02em; color: var(--text-2); }

/* pages without a side panel (platform home, no access) */
.app-shell-full { grid-template-columns: minmax(0, 1fr); }
.app-shell-full > .main { margin-left: var(--canvas-inset); }
/* Formulation Explorer: sheet tabs above a table (Formulations, Analytics, Lookup) and workbook headers kept as
   written (their line breaks show) */
.sub-tabs { display: flex; flex-wrap: wrap; gap: var(--space-1); margin: 0 0 var(--space-4); padding: 3px; border: 1px solid var(--line); border-radius: 12px; width: fit-content; max-width: 100%; }
.sub-tab { padding: 0.35rem 0.85rem; border-radius: 9px; font-size: 0.86rem; font-weight: 600; color: var(--text-2); }
.sub-tab:hover { background: var(--surface-soft); text-decoration: none; }
.sub-tab.active { background: var(--primary); color: #fff; }
.sheet-table th { white-space: pre-line; vertical-align: bottom; }
.upload-form .input[type="file"] { padding: var(--space-2); font-size: 0.82rem; }
/* Formulation Explorer's Data editor: an Excel skin on Tabulator, scoped to .xl-editor (Excel's grid greys, its green
   active cell, the Name Box and formula bar above, sheet tabs and the status bar below) */
.xl-main { gap: var(--space-3) !important; }
.xl-page-header { margin-bottom: 0; }
.xl-editor {
  --xl-font: Aptos, "Aptos Narrow", Calibri, "Segoe UI", Arial, sans-serif;
  --xl-grid: #e1e1e1; --xl-head: #f5f5f5; --xl-head-line: #c8c8c8; --xl-green: #107c41; --xl-green-soft: #e0efe6; --xl-header: #dce6f2; --xl-header-selected: #c9dfd8;
  display: flex; flex-direction: column; height: calc(100vh - var(--navbar-height) - 190px); min-height: 420px;
  border: 1px solid var(--xl-head-line); border-radius: 6px; overflow: hidden; background: #fff;
  font-family: var(--xl-font); font-size: 13px;
}
.xl-loading .xl-grid { opacity: 0.5; }
.xl-formula { display: flex; align-items: center; gap: 6px; padding: 5px 6px; border-bottom: 1px solid var(--xl-head-line); background: #fff; }
.xl-namebox, .xl-fxinput { font: inherit; height: 24px; border: 1px solid var(--xl-head-line); border-radius: 3px; padding: 0 6px; background: #fff; color: #000; }
.xl-namebox { width: 92px; text-align: left; }
.xl-fx { color: #666; font-style: italic; font-family: Georgia, serif; padding: 0 4px; border-left: 1px solid var(--xl-head-line); border-right: 1px solid var(--xl-head-line); }
.xl-fxinput { flex: 1; min-width: 0; }
.xl-namebox:focus, .xl-fxinput:focus { outline: none; border-color: var(--xl-green); }
.xl-download { flex: none; }
.xl-notice { margin: 0 !important; border-radius: 0; border-width: 0 0 1px; }
.xl-grid { flex: 1; min-height: 0; position: relative; }
.xl-grid > .table-scroll { height: 100%; overflow: auto; }
.xl-bottom { display: flex; align-items: stretch; border-top: 1px solid var(--xl-head-line); background: var(--xl-head); min-height: 28px; }
.xl-tabs { display: flex; padding-left: 6px; }
.xl-tab { display: flex; align-items: center; padding: 0 14px; color: #333; border-right: 1px solid var(--xl-head-line); font-size: 12.5px; }
.xl-tab:hover { background: #ebebeb; text-decoration: none; }
.xl-tab.active { background: #fff; color: var(--xl-green); font-weight: 600; box-shadow: inset 0 -2px 0 var(--xl-green); }
.xl-status { margin-left: auto; display: flex; align-items: center; padding: 0 12px; color: #444; font-size: 12px; white-space: pre; }
#main .xl-editor .tabulator { border: 0; background: #fff; font-family: var(--xl-font); font-size: 13px; height: 100%; }
#main .xl-editor .tabulator .tabulator-header { background: var(--xl-head); border-bottom: 1px solid var(--xl-head-line); color: #444; font-weight: 400; }
#main .xl-editor .tabulator .tabulator-header .tabulator-col { background: var(--xl-head); border-right: 1px solid var(--xl-head-line); }
#main .xl-editor .tabulator .tabulator-header .tabulator-col .tabulator-col-content { padding: 2px 4px; }
#main .xl-editor .tabulator .tabulator-header .tabulator-col.tabulator-range-highlight,
#main .xl-editor .tabulator .tabulator-header .tabulator-col.tabulator-range-selected { background: #d3f0e0; color: var(--xl-green); box-shadow: inset 0 -2px 0 var(--xl-green); }
#main .xl-editor .tabulator-row { background: #fff; min-height: 22px; border-bottom: 0; }
#main .xl-editor .tabulator-row.tabulator-row-even { background: #fff; }
#main .xl-editor .tabulator-row:hover, #main .xl-editor .tabulator-row.tabulator-selectable:hover { background: #fff; }
#main .xl-editor .tabulator-row .tabulator-cell {
  border-right: 1px solid var(--xl-grid); border-bottom: 1px solid var(--xl-grid); padding: 2px 4px; height: 22px; line-height: 17px; color: #000;
}
#main .xl-editor .tabulator-row .tabulator-cell.xl-num { text-align: right; font-variant-numeric: tabular-nums; }
#main .xl-editor .tabulator-row .tabulator-cell.xl-rownum,
#main .xl-editor .tabulator-row .tabulator-cell.tabulator-row-header { background: var(--xl-head); color: #444; border-right: 1px solid var(--xl-head-line); text-align: center; }
#main .xl-editor .tabulator-row .tabulator-cell.tabulator-range-row-header.tabulator-range-highlight { background: #d3f0e0; color: var(--xl-green); box-shadow: inset -2px 0 0 var(--xl-green); }
/* every cell is opaque: frozen rows and columns cover what scrolls under them (selection tints included) */
#main .xl-editor .tabulator-row .tabulator-cell { background-color: var(--xl-fill, #fff); }
#main .xl-editor .tabulator-row.xl-header-row .tabulator-cell { font-weight: 700; white-space: pre-line; height: auto; vertical-align: bottom; background-color: var(--xl-header); }
#main .xl-editor .tabulator-row.xl-header-row .tabulator-cell.tabulator-row-header { background: var(--xl-head); font-weight: 400; }
#main .xl-editor .tabulator-row .tabulator-cell.tabulator-range-selected:not(.tabulator-range-only-cell-selected):not(.tabulator-range-row-header) { background-color: var(--xl-green-soft); }
#main .xl-editor .tabulator-row.xl-header-row .tabulator-cell.tabulator-range-selected:not(.tabulator-range-only-cell-selected):not(.tabulator-range-row-header) { background-color: var(--xl-header-selected); }
#main .xl-editor .tabulator .tabulator-cell.tabulator-range-only-cell-selected,
#main .xl-editor .tabulator .tabulator-range-overlay .tabulator-range-cell-active { box-shadow: none; border: 2px solid var(--xl-green); }
#main .xl-editor .tabulator .tabulator-range-overlay .tabulator-range { border: 1px solid var(--xl-green); }
#main .xl-editor .tabulator .tabulator-range-overlay .tabulator-range.tabulator-range-active::after { background: var(--xl-green); }
#main .xl-editor .tabulator-row .tabulator-cell.tabulator-editing { border: 2px solid var(--xl-green); padding: 0; }
#main .xl-editor .tabulator-range-fill-handle { width: 7px; height: 7px; right: -4px; bottom: -4px; border-radius: 0; background-color: var(--xl-green); border: 1px solid #fff; z-index: 12; }
#main .xl-editor .tabulator .tabulator-tableholder .tabulator-range-overlay .tabulator-range.tabulator-range-fill-preview { border: 1px dashed #444; }
.xl-date-editor { position: relative; display: flex; align-items: stretch; width: 100%; height: 100%; background: #fff; }
.xl-date-editor .xl-editor-input { flex: 1; min-width: 0; }
.xl-date-button { flex: none; display: flex; align-items: center; padding: 0 4px; border: 0; border-left: 1px solid #e1e1e1; background: #f5f5f5; color: #107c41; cursor: pointer; }
.xl-date-button:hover { background: #e0efe6; }
.xl-date-native { position: absolute; left: 0; bottom: 0; width: 100%; height: 0; padding: 0; border: 0; opacity: 0; pointer-events: none; }
.xl-editor-input { width: 100%; height: 100%; border: 0; outline: none; padding: 1px 3px; font: inherit; background: #fff; }
#main .xl-editor .tabulator-cell.xl-error:not(.tabulator-frozen), #main .xl-editor .tabulator-cell.xl-warning:not(.tabulator-frozen) { position: relative; }  /* frozen cells stay sticky (also positioned) */
#main .xl-editor .tabulator-cell.xl-error::after, #main .xl-editor .tabulator-cell.xl-warning::after {
  content: ""; position: absolute; top: 0; right: 0; border-style: solid; border-width: 0 7px 7px 0; border-color: transparent var(--danger) transparent transparent;
}
#main .xl-editor .tabulator-cell.xl-warning::after { border-right-color: #e8a317; }
#main .xl-editor .tabulator-row .tabulator-cell.xl-error { background-color: var(--danger-soft); }
body .tabulator-menu { font-family: Aptos, Calibri, "Segoe UI", Arial, sans-serif; font-size: 13px; border-radius: 6px; padding: 4px 0; box-shadow: var(--shadow); }
body .tabulator-menu .tabulator-menu-item { padding: 5px 22px; }
body .tabulator-menu .tabulator-menu-item:not(.tabulator-menu-item-disabled):hover { background: #e9f4ee; }
/* the workbook's own look (read from the version's file): Calibri 11 pt, its row heights; fills and fonts per cell */
.xl-workbook { --xl-font: Calibri, Carlito, "Segoe UI", Arial, sans-serif; }
#main .xl-editor.xl-workbook .tabulator { font-size: 14.667px; }
#main .xl-editor.xl-workbook .tabulator-row { min-height: var(--xl-row-h, 20px); }
#main .xl-editor.xl-workbook .tabulator-row .tabulator-cell { height: var(--xl-row-h, 20px); line-height: calc(var(--xl-row-h, 20px) - 4px); padding: 1px 4px; }
#main .xl-editor.xl-workbook .tabulator-row.xl-header-row .tabulator-cell { font-weight: 400; background-color: var(--xl-fill, #fff); }
#main .xl-editor .tabulator-row.xl-header-row .tabulator-cell:not(.tabulator-row-header) {
  display: inline-flex; flex-direction: column; justify-content: flex-end; min-height: var(--xl-header-h, 0px); padding-right: 20px; line-height: 1.2;
}
#main .xl-editor .tabulator-row.xl-header-row .tabulator-cell[data-valign="middle"] { justify-content: center; }
#main .xl-editor .tabulator-row.xl-header-row .tabulator-cell[data-valign="top"] { justify-content: flex-start; }
#main .xl-editor .tabulator-row.xl-header-row .tabulator-cell:not(.tabulator-frozen):not(.tabulator-row-header) { position: relative; }
.xl-head-text { display: block; white-space: pre-line; overflow: hidden; }
/* AutoFilter: Excel's small arrow box in every header cell, and its menu */
.xl-filter-button {
  position: absolute; right: 2px; bottom: 2px; display: inline-flex; align-items: center; justify-content: center; gap: 1px;
  min-width: 16px; height: 16px; padding: 0 1px; border: 1px solid #c8c8c8; border-radius: 2px; background: #fff; color: #444; cursor: pointer; line-height: 0;
}
.xl-filter-button:hover { border-color: var(--xl-green); background: #f3faf6; }
.xl-filter-button.xl-filter-on { color: var(--xl-green); border-color: var(--xl-green); }
#main .xl-editor.xl-filtered .tabulator-row:not(.xl-header-row) .tabulator-cell.xl-rownum { color: #0563c1; }
.xl-menu {
  position: fixed; z-index: 1000; width: 260px; display: grid; gap: 2px; padding: 6px; background: #fff; color: #000;
  border: 1px solid #c8c8c8; border-radius: 6px; box-shadow: var(--shadow); font-family: Aptos, Calibri, "Segoe UI", Arial, sans-serif; font-size: 13px;
}
.xl-menu-item { all: unset; box-sizing: border-box; display: flex; align-items: center; gap: 8px; padding: 4px 8px; border-radius: 3px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.xl-menu-item:hover:not(:disabled), .xl-menu-item:focus-visible { background: #e9f4ee; }
.xl-menu-item:disabled { color: #a0a0a0; cursor: default; }
.xl-menu-mark { display: inline-flex; width: 12px; color: var(--xl-green, #107c41); }
.xl-menu-item:disabled .xl-menu-mark { color: inherit; }
.xl-menu-line { height: 1px; margin: 3px 0; background: #e1e1e1; }
.xl-menu-search { font: inherit; height: 26px; padding: 0 8px; border: 1px solid #c8c8c8; border-radius: 3px; }
.xl-menu-search:focus { outline: none; border-color: #107c41; }
.xl-menu-list { max-height: min(260px, 40vh); overflow: auto; margin-top: 4px; padding: 4px; border: 1px solid #e1e1e1; border-radius: 3px; display: grid; align-content: start; }
.xl-menu-list label { display: flex; align-items: center; gap: 6px; padding: 2px 2px; white-space: nowrap; cursor: pointer; }
.xl-menu-list label[hidden] { display: none; }
.xl-menu-list input { accent-color: #107c41; margin: 0; }
.xl-menu-buttons { display: flex; justify-content: flex-end; gap: 6px; margin-top: 6px; }
/* search, CSV and the filter's count */
.xl-find { flex: 0 1 200px; min-width: 110px; display: flex; align-items: center; gap: 4px; height: 24px; padding: 0 6px; border: 1px solid var(--xl-head-line); border-radius: 3px; background: #fff; color: #666; }
.xl-find[hidden] { display: none; }
.xl-find:focus-within { border-color: var(--xl-green); }
.xl-find svg { width: 14px; height: 14px; flex: none; }
.xl-find-input { flex: 1; min-width: 0; border: 0; outline: none; font: inherit; background: transparent; color: #000; }
.xl-csv { position: relative; flex: none; }
.xl-csv > summary { list-style: none; }
.xl-csv > summary::-webkit-details-marker { display: none; }
.xl-csv-menu { position: absolute; right: 0; top: calc(100% + 4px); z-index: 50; min-width: 170px; display: grid; padding: 4px; background: #fff; border: 1px solid #c8c8c8; border-radius: 6px; box-shadow: var(--shadow); }
.xl-csv-menu a { padding: 5px 10px; border-radius: 3px; color: #000; white-space: nowrap; }
.xl-csv-menu a:hover { background: #e9f4ee; text-decoration: none; }
.xl-csv-menu a[hidden] { display: none; }
.xl-clear { all: unset; cursor: pointer; display: flex; align-items: center; padding: 0 12px; color: var(--xl-green); font-size: 12px; font-weight: 600; border-right: 1px solid var(--xl-head-line); }
.xl-clear:hover, .xl-clear:focus-visible { background: #ebebeb; }
.xl-clear[hidden], .xl-found[hidden] { display: none; }
.xl-found { display: flex; align-items: center; padding: 0 12px; color: #444; font-size: 12px; white-space: nowrap; }
@media (max-width: 560px) {
  .xl-namebox, .xl-fx, .xl-fxinput { display: none; }
  .xl-find { flex: 1 1 auto; }
  .xl-bottom { flex-wrap: wrap; }  /* the filter's count and Clear go under the sheet tabs */
  .xl-tab { padding: 0 10px; min-height: 28px; }
  .xl-clear { order: 3; min-height: 26px; border-right: 0; border-top: 1px solid var(--xl-head-line); }
  .xl-found { order: 4; flex: 1; min-height: 26px; border-top: 1px solid var(--xl-head-line); }
  .xl-status:empty { display: none; }
}
/* Formulation Explorer's analyses: chart cards (airy, Modalis colours; the figures come from the server), the ranking
   tables, the formulation list and the response goals in the sidebar */
.fx-main { gap: var(--space-4) !important; }
.fx-chart { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: var(--space-5) var(--space-5) var(--space-3); box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 24px -16px rgba(15, 23, 42, 0.12); }
.fx-chart-head h2 { margin: 0; font-family: var(--font-text); font-size: 1.15rem; font-weight: 700; letter-spacing: -0.01em; }
.fx-chart-head p { margin: var(--space-1) 0 0; color: var(--muted); font-size: 0.85rem; }
.fx-plot { position: relative; min-height: 180px; margin-top: var(--space-2); }
.fx-plot-area { width: 100%; }
.fx-empty { margin: var(--space-6) 0; text-align: center; color: var(--muted); }
.fx-rank-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-4); }
.fx-rank-grid .section { margin: 0; }
.fx-rank-good .section-head h3::before, .fx-rank-bad .section-head h3::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 8px; vertical-align: middle; }
.fx-rank-good .section-head h3::before { background: var(--data); }
.fx-rank-bad .section-head h3::before { background: #e8743b; }
.fx-status { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 0.78rem; background: var(--surface-soft); color: var(--text-2); }
.fx-status-reached { background: #fff4dc; color: #8a5a00; }
.fx-status-ahead { background: var(--data-soft); color: var(--data-strong); }
.fx-list > summary { cursor: pointer; list-style: none; }
.fx-list > summary::-webkit-details-marker { display: none; }
.fx-list-actions { display: flex; gap: var(--space-2); padding: var(--space-3) var(--space-5) 0; }
.fx-more > summary { cursor: pointer; margin-bottom: var(--space-3); }
.checks-inline { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-4); }
.checks-inline legend { width: 100%; }
.fx-goals > summary { cursor: pointer; list-style: none; }
.fx-goals > summary::-webkit-details-marker { display: none; }
.fx-goals[open] > summary { margin-bottom: var(--space-2); }
.fx-goal-form { display: grid; gap: var(--space-2); }
.fx-goal { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 4px var(--space-2); font-size: 0.82rem; }
.fx-goal-name { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fx-goal-mode { font: inherit; font-size: 0.8rem; height: 28px; padding: 0 6px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); color: var(--text); }
.fx-goal-target { display: none; grid-column: 1 / -1; height: 28px; font-size: 0.8rem; }
.fx-goal:has(.fx-goal-mode option[value="Target"]:checked) .fx-goal-target { display: block; }
.fx-row-target td { background: var(--data-soft); }
.field > .caption { display: block; margin-top: var(--space-1); font-weight: 400; }
.fx-range { width: 100%; accent-color: var(--primary); margin-top: var(--space-2); }
.fx-wide-left { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
.fx-verdict-card .section-body { display: grid; gap: var(--space-3); padding: var(--space-4) var(--space-5); }
.fx-big { margin: 0; font-size: 2.2rem; font-weight: 700; letter-spacing: -0.02em; color: var(--primary); }
.fx-read { margin: 0 0 var(--space-3); padding-left: 1.1rem; display: grid; gap: var(--space-2); font-size: 0.9rem; }
.fx-clusters { margin: 0 0 var(--space-3); padding-left: 1.3rem; display: grid; gap: var(--space-1); font-size: 0.9rem; }
.fx-rank-grid > .fx-chart { margin: 0; }
.fx-plain { margin: 0; padding: 0; list-style: none; display: grid; gap: var(--space-2); }
.fx-plain li { font-size: 0.88rem; line-height: 1.5; padding: var(--space-2) var(--space-3); border-radius: 10px; background: var(--surface-soft); }
.fx-plain li.fx-verdict-good { background: var(--data-soft); }
.fx-plain li.fx-verdict-bad { background: #fdeee6; }
.fx-about { margin-bottom: var(--space-5); }
.fx-about-body { max-width: 92ch; line-height: 1.6; font-size: 0.92rem; }
.fx-about-body h4 { margin: var(--space-4) 0 var(--space-1); font-size: 0.95rem; }
.fx-about-body h4:first-child { margin-top: 0; }
.fx-about-body p { margin: 0 0 var(--space-2); }
.fx-about-body ul { margin: 0 0 var(--space-2); padding-left: 1.2rem; display: grid; gap: 2px; }
.fx-version-short { display: none; }
.fx-add { display: flex; gap: var(--space-2); margin-bottom: var(--space-2); }
.fx-add .input { flex: 1; min-width: 0; }
.fx-step { margin: var(--space-4) 0 var(--space-2); font-size: 0.9rem; }
.fx-ranges .input { min-width: 0; }
.fx-number { width: 110px; text-align: right; }
.fx-unit { width: 120px; }
.fx-inline { padding: 0; }

.fx-assessment .section-body { display: grid; gap: var(--space-4); padding: var(--space-4) var(--space-5); }
.fx-verdict-group h4 { margin: 0 0 var(--space-2); font-size: 0.95rem; }
.fx-verdict-group ul { margin: 0; padding: 0; list-style: none; display: grid; gap: var(--space-2); }
.fx-verdict-group li { font-size: 0.88rem; line-height: 1.5; padding: var(--space-2) var(--space-3); border-radius: 10px; background: var(--surface-soft); }
.fx-verdict-group li.fx-verdict-strong { background: #fff4dc; }
.fx-verdict-where { color: var(--muted); margin-right: 4px; }
.fx-verdict-text { display: block; font-weight: 600; color: var(--text-2); }
.fx-pill { display: inline-block; margin-right: 6px; padding: 0 8px; border-radius: 999px; background: #f0a020; color: #fff; font-size: 0.75rem; font-weight: 700; }
@media (max-width: 900px) { .fx-rank-grid { grid-template-columns: minmax(0, 1fr); } }
.xl-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.xl-issues { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; max-height: 220px; overflow: auto; }
.xl-issue { all: unset; cursor: pointer; display: block; font-size: 0.8rem; padding: 2px 6px; border-left: 3px solid; border-radius: 2px; }
.xl-issue:hover, .xl-issue:focus-visible { background: var(--surface-soft); }
.xl-issue-error { border-color: var(--danger); color: var(--danger); }
.xl-issue-warning { border-color: #e8a317; color: var(--text-2); }
.xl-keys summary { cursor: pointer; }
.service-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: var(--space-4); max-width: 960px; }
.service-card { display: grid; gap: var(--space-2); align-content: start; justify-items: start; padding: var(--space-5); border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface); color: var(--text); }
.service-card:hover { border-color: var(--primary-hover); box-shadow: var(--shadow); text-decoration: none; }
.service-icon { display: inline-flex; padding: var(--space-2); border-radius: var(--radius-sm); background: var(--primary); color: #fff; }
.service-icon .icon { width: 22px; height: 22px; }
.service-name { font-family: var(--font-head); font-weight: 700; font-size: 1.15rem; }
.service-text { color: var(--muted); font-size: 0.9rem; }

/* side panel blocks: titled groups, key facts, link lists */
.panel-block { margin-bottom: var(--space-5); }
.panel-block .panel-title { margin-bottom: var(--space-3); }
.panel-back { font-size: 0.82rem; font-weight: 600; padding-bottom: var(--space-3); margin-bottom: var(--space-4); border-bottom: 1px solid var(--line); }  /* the way back, set apart from the panel below */
.facts { display: grid; gap: var(--space-2); margin: 0 0 var(--space-3); font-size: 0.86rem; }
.facts > div { display: flex; justify-content: space-between; gap: var(--space-3); }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-weight: 600; text-align: right; }
.facts-row { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-6); }
.facts-row > div { display: grid; justify-content: start; }
.facts-row dd { text-align: left; font-size: 1rem; }
.link-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-2); font-size: 0.88rem; }
.checks { border: 0; margin: 0 0 var(--space-4); padding: 0; display: grid; gap: var(--space-2); }
.checks legend { padding: 0; margin-bottom: var(--space-2); font-size: 0.84rem; font-weight: 600; color: var(--text-2); }
.form-pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-2); }
.form-pair .field { margin-bottom: var(--space-4); min-width: 0; }
.form-pair .input { min-width: 0; width: 100%; }  /* date inputs: shrink with the panel instead of overflowing it */
.form-pair input[type="date"] { padding-left: var(--space-2); padding-right: var(--space-1); font-size: 0.82rem; }
.form-pair input[type="date"]::-webkit-calendar-picker-indicator { margin-left: 2px; padding: 0; }

/* key figures: a row of tiles; a tile with a link filters to its rows */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: var(--space-3); margin-bottom: var(--space-5); }
.tile { display: grid; gap: 2px; padding: var(--space-3) var(--space-4); border: 1px solid var(--line-strong); border-radius: var(--radius); background: transparent; color: var(--text); }
.tile-value { font-family: var(--font-head); font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile-label { font-size: 0.8rem; color: var(--muted); font-weight: 600; }
.tile-primary { border-color: rgba(40, 112, 158, 0.35); }
.tile-data { border-color: rgba(0, 153, 153, 0.35); }
.tile-warn { border-color: var(--warn-line); }
.tile-danger { border-color: rgba(180, 35, 24, 0.35); }
.period { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; margin: 0 0 var(--space-4); font-weight: 600; }
.period .caption { margin: 0; font-weight: 400; }

/* rows per day, as in FDA's 7/14-day reports */

/* alerts and markers */
.alert-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-2); }
.alert-list li { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--space-2) var(--space-3); padding: var(--space-2) var(--space-3); border-radius: var(--radius-sm); background: var(--surface-soft); font-size: 0.88rem; }
.alert-list li.unread { background: var(--data-soft); box-shadow: inset 3px 0 0 var(--data); }
.alert-when { color: var(--muted); font-size: 0.8rem; min-width: 6.5rem; }
.alert-drug { font-weight: 600; }
.change-links { white-space: nowrap; }
.change-links a { display: inline-flex; align-items: center; gap: 2px; margin-right: var(--space-2); }
.change-links .icon { width: 14px; height: 14px; }
.tag-warn { background: var(--warn-soft); border-color: var(--warn-line); color: var(--text-2); }
.tag-danger { background: var(--danger-soft); border-color: rgba(180, 35, 24, 0.25); color: var(--danger); }
.table tbody tr.row-new { box-shadow: inset 3px 0 0 var(--data); }
.nowrap { white-space: nowrap; }
.appl { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.doc-link { display: inline-flex; align-items: center; gap: 2px; margin-right: var(--space-3); white-space: nowrap; }
.doc-link .icon, td .icon { width: 14px; height: 14px; vertical-align: -2px; }
.btn.btn-watching { border-color: var(--data); color: var(--data-strong); background: var(--data-soft); }
/* where a figure comes from: Drugs@FDA is the FDA reference, DailyMed labels are labeling in use */
.source { display: inline-block; font-size: 0.7rem; font-weight: 700; padding: 0.05rem 0.45rem; border-radius: var(--radius-sm); white-space: nowrap; }
.source-fda { background: var(--primary-tint); color: var(--primary); }
.source-label { background: var(--surface-soft); color: var(--text-2); border: 1px solid var(--line); }

/* label text from openFDA: one article per SPL, sections as disclosures */
.spl { padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--line); }
.spl:last-of-type { border-bottom: 0; }
.spl-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: var(--space-2); margin-bottom: var(--space-3); }
.spl-head h4 { margin: 0; font-size: 1rem; }
.spl-meta { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); font-size: 0.82rem; }
.spl-summary { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-6); margin: 0 0 var(--space-3); font-size: 0.86rem; }
.spl-summary dt { color: var(--muted); font-size: 0.78rem; }
.spl-summary dd { margin: 0; }
.label-section { border: 1px solid var(--line); border-radius: var(--radius-sm); margin-bottom: var(--space-2); }
.label-section > summary { cursor: pointer; padding: var(--space-2) var(--space-3); font-weight: 600; font-size: 0.9rem; }
.label-section[open] > summary { border-bottom: 1px solid var(--line); }
.label-text { padding: var(--space-3); white-space: pre-line; font-size: 0.86rem; line-height: 1.55; max-height: 420px; overflow-y: auto; }

/* 6. Responsive -------------------------------------------------------------------------------------- */
/* The centred views need ~960px next to the brand and account area: below 1080px the navbar switches to two
   rows (brand + account, then the views as a tab bar), before anything can overlap. The tab bar is always one row,
   however many views a service has: the tabs share it by the width of their labels, icon and label side by side
   like on desktop. */
@media (max-width: 1080px) {
  .nav-spacer { display: none; }
  .navbar { grid-template-columns: 1fr auto; gap: var(--space-2); height: auto; padding: var(--space-2) var(--space-3) var(--space-3); }  /* a little more room below: the tab bar stands apart from the panel */
  .nav-links { grid-column: 1 / -1; grid-row: 2; justify-self: stretch; }
  .nav-links { display: flex; gap: 2px; border-radius: var(--radius); overflow: hidden; }
  .nav-link { flex: 1 1 auto; min-width: 0; gap: 6px; padding: 0.4rem 0.5rem; border-radius: var(--radius-sm); font-size: 0.8rem; font-weight: 600; justify-content: center; }
  .nav-link .icon { display: block; flex: none; width: 16px; height: 16px; }
  .nav-link .nav-label { display: none; }
  .nav-link .nav-label-short { display: inline; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  .nav-link .nav-badge { flex: none; }  /* Label Monitor's unread count keeps its size */
}
/* Phones: labels only, a step smaller, so six views still fit one row of a 375px screen and stay readable. */
@media (max-width: 560px) {
  .nav-links { gap: 1px; padding: 2px; }
  .nav-link { padding: 0.45rem 0.1rem; font-size: clamp(0.66rem, 2.9vw, 0.78rem); letter-spacing: -0.01em; }
  .nav-link .icon { display: none; }
}

/* Phones: keep "DailyMed Explorer" next to the logo. Below ~560px the first row gets tight, so the logo and name
   shrink a step and the Admin button shows only its icon (the tooltip and aria-label still say "Administration"). */
@media (max-width: 560px) {
  .brand { gap: var(--space-2); }
  .brand img { height: 16px; }
  .brand-name { font-size: 0.8rem; padding-left: var(--space-2); }
  .btn.nav-admin { padding: 0; width: 32px; height: 32px; }
  .nav-admin-label { display: none; }
  .nav-right { gap: var(--space-2); }
}

/* Desktop: the page itself does not scroll. Top bar and sidebar stay put; the white canvas keeps its rounded shape
   and its content scrolls inside it (as in Databricks). Works for any top-bar height (one or two rows). */
@media (min-width: 901px) {
  html:has(> body.app-page) { overflow: hidden; }  /* the frame never scrolls, only the canvas */
  body.app-page { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
  body.app-page > .navbar { position: static; flex: 0 0 auto; }
  body.app-page > .app-shell { flex: 1 1 auto; min-height: 0; }
  body.app-page .panel { position: static; align-self: stretch; height: auto; }
  body.app-page .main { align-self: stretch; min-height: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-gutter: stable; }
  body.app-page .workarea { align-self: stretch; min-height: 0; }
  body.app-page .workarea > .main { min-height: 0; }
  body.app-page .query-bar { flex: 0 0 auto; }
}

/* Wide screens: the query bar is always one row (the search box gives way first), and the count comes right after
   the search, before the options; its divider moves to its right side. Below this the options wrap under the search. */
@media (min-width: 1180px) {
  .query-bar { flex-wrap: nowrap; }
  .query-options { flex: none; }
  .match-count { order: -1; padding: 0 var(--space-4) 0 0; border-left: 0; border-right: 1px solid var(--line); }
  /* the number gets a fixed 10-character slot, so a new count never resizes the search box */
  .match-count strong { display: inline-block; min-width: 10ch; text-align: right; font-variant-numeric: tabular-nums; }
}

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .app-shell:has(> .panel-frame) { grid-template-rows: auto 1fr; }  /* Label Monitor: short pages give the spare height to the content, not to the panel */
  .panel { position: static; height: auto; padding: var(--space-2) var(--canvas-inset) var(--canvas-inset); }
  .filter-toggle {
    display: flex; align-items: center; gap: var(--space-3); cursor: pointer;
    padding: var(--space-2) var(--space-3); border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
    background: var(--surface); font-weight: 700;
  }
  .filter-toggle .summary-chevron { margin-left: auto; display: inline-flex; }
  .filter-drawer[open] > .filter-toggle { margin-bottom: var(--space-4); }
  .filter-drawer .panel-head { display: none; }
  .btn.filter-done { display: flex; margin-top: var(--space-2); }
  /* Formulation Explorer: the data version in one line under the folded sidebar */
  .fx-version { padding-top: var(--space-2); }
  .fx-version > .panel-title, .fx-version > .facts { display: none; }
  .fx-version .fx-version-short { display: flex; align-items: center; gap: var(--space-2); margin: 0; }
  .fx-version .fx-version-short .icon { width: 14px; height: 14px; flex: none; }
  .main { --main-pad-x: var(--space-3); padding: var(--space-4) var(--main-pad-x) var(--space-6); margin: 0 var(--canvas-inset) var(--canvas-inset); min-height: 0; }
  .workarea { padding: 0 var(--canvas-inset) var(--canvas-inset); }
  .workarea > .main { margin: 0; }
  .query-bar { padding: var(--space-3); gap: var(--space-3); }
  .match-count { padding-left: 0; border-left: 0; }
  .metric { padding: var(--space-3) var(--space-4); }
  .metric-value { font-size: 1.4rem; }
  .page-header h1 { font-size: 1.5rem; }
  .chart-grid { grid-template-columns: 1fr; }
  .bars li { grid-template-columns: minmax(6rem, 10rem) 1fr 3.5rem; }
  .auth-card { padding: var(--space-5); }
  .auth-card.legal-card { padding: var(--space-5) var(--space-4); }
}

@media (max-width: 560px) {
  /* phones: still one row (fits down to 320px wide) */
  .status-bar { font-size: 0.7rem; }
  /* metrics become a compact list: label left, value right */
  .metrics { grid-auto-flow: row; grid-auto-columns: auto; }
  .metric { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-3); padding: var(--space-2) var(--space-4); }
  .metric + .metric { border-left: 0; border-top: 1px solid var(--line); }
  .metric-value { font-size: 1.15rem; }
  .status-value { gap: var(--space-1); padding: 0 var(--space-2); }
  .section-head, .section-foot { padding-left: var(--space-3); padding-right: var(--space-3); }
}

/* Large and 4K screens: the layout stays anchored to the edges (top bar full width, sidebar left, work area
   filling the rest), as in Databricks. Tables simply get wider; charts get more columns; type grows a step. */
@media (min-width: 1920px) {
  :root { --panel-width: 288px; }
  .main { --main-pad-x: var(--space-6); padding-left: var(--main-pad-x); padding-right: var(--main-pad-x); }
  .chart-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .chart-wide { grid-column: auto; }
  .clip { max-width: 22rem; }
}
@media (min-width: 2400px) {
  html { font-size: 16px; }
  body { font-size: 15px; }
  :root { --panel-width: 312px; --navbar-height: 54px; }
  .clip { max-width: 26rem; }
}
@media (min-width: 3200px) {
  html { font-size: 18px; }
  body { font-size: 16.5px; }
  :root { --panel-width: 360px; --navbar-height: 60px; }
}
