/* =====================================================================================================
   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-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;
}
.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; }
/* 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; }
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; }

/* 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 an equal-width tab bar), before anything can overlap. */
@media (max-width: 1080px) {
  .navbar { grid-template-columns: 1fr auto; gap: var(--space-2); height: auto; padding: var(--space-2) var(--space-3); }
  .nav-links { grid-column: 1 / -1; grid-row: 2; justify-self: stretch; }
  .nav-links { display: grid; grid-template-columns: repeat(4, 1fr); gap: 2px; border-radius: var(--radius); overflow: visible; }
  .nav-link { flex-direction: column; gap: 2px; padding: 0.35rem 0.2rem; border-radius: var(--radius-sm); font-size: 0.72rem; font-weight: 600; justify-content: center; }
  .nav-link .icon { display: block; width: 18px; height: 18px; }
  .nav-link .nav-label { display: none; }
  .nav-link .nav-label-short { display: inline; }
}

/* 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; }
  .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); }
  .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; }
  .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; }
  .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; }
}
