/* TrialWatch UI components, built only from the tokens in brand.css. Macros that render them are in
   templates/components.html; STYLE.md ("UI") says how to use them. One-page styles stay in that page. */

/* --- Base ------------------------------------------------------------------------------------- */
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: var(--fs-base)/var(--lh) var(--font); }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: var(--radius-sm); }
h1 { font-size: var(--fs-lg); margin: 0 0 var(--sp-1); }
h2 { font-size: var(--fs-md); margin: var(--sp-6) 0 10px; }
code, pre { background: var(--code); border-radius: var(--radius-sm); font: var(--fs-sm)/1.45 var(--font-mono); }
code { padding: 1px 5px; }
pre { padding: var(--sp-3); overflow-x: auto; white-space: pre-wrap; word-break: break-word; margin: 0; }
mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 1px; }
main { max-width: 1200px; margin: 0 auto; padding: var(--sp-5) var(--sp-4) 64px; }

/* Text helpers */
.muted { color: var(--muted); }
.small { font-size: var(--fs-sm); }
.sub { color: var(--muted); margin: 0 0 var(--sp-4); }
.flag { color: var(--notfull); font-weight: 700; }

/* --- App header (brand bar) --------------------------------------------------------------------- */
.app-header { display: flex; gap: var(--sp-5); align-items: center; flex-wrap: wrap; padding: 10px var(--sp-5);
              background: var(--header-bg); color: var(--header-text); position: sticky; top: 0; z-index: 2; }
.app-header a { color: var(--header-link); }
.app-header a:hover { color: var(--header-text); }
.brand { display: inline-flex; align-items: center; gap: var(--sp-2); font-weight: 700; letter-spacing: -.01em;
         font-size: var(--fs-md); }
.app-header .brand, .app-header .brand:hover { color: var(--header-text); text-decoration: none; }
.brand img { width: 26px; height: 26px; display: block; }
/* The "alpha" tag after the name: an early version, results may change */
.alpha { font-size: var(--fs-xs); font-weight: 700; text-transform: uppercase; letter-spacing: .06em; line-height: 1;
         padding: 3px 6px; border-radius: var(--radius-pill); background: var(--undecided-bg); color: var(--undecided); }
.app-nav { display: flex; gap: var(--sp-1) var(--sp-4); flex-wrap: wrap; }
.app-nav a { padding: 2px 0; border-bottom: 2px solid transparent; }
.app-nav a[aria-current="page"] { color: var(--header-text); border-bottom-color: var(--brand-accent); }
.app-header .who { margin-left: auto; display: flex; gap: 10px; align-items: center; color: var(--header-link); }
.app-header .who form { margin: 0; }
.app-header button.secondary, .app-header .button.secondary { color: var(--header-text); border-color: var(--header-link); }

/* --- Page header -------------------------------------------------------------------------------- */
.page-header { margin-bottom: var(--sp-4); }
.page-header .sub { margin: 0; }

/* --- Button ------------------------------------------------------------------------------------- */
/* <button> or <a class="button">; variants: (primary) · secondary · danger; size: small */
button, .button { display: inline-block; font: inherit; font-weight: 600; padding: 7px var(--sp-3);
  border-radius: var(--radius-sm); border: 1px solid var(--primary); cursor: pointer; text-align: center;
  background: var(--primary); color: var(--on-primary); line-height: 1.3; }
.button:hover, button:hover { text-decoration: none; filter: brightness(1.1); }
button:disabled, .button[aria-disabled="true"] { opacity: .45; cursor: not-allowed; filter: none; }
button.secondary, .button.secondary { background: transparent; color: var(--link); border-color: currentColor; }
button.danger, .button.danger { background: var(--danger); border-color: var(--danger); color: var(--on-danger); }
button.small, .button.small { padding: 3px var(--sp-2); font-size: var(--fs-sm); }
.actions { display: flex; gap: var(--sp-2); align-items: center; flex-wrap: wrap; margin: -4px 0 var(--sp-4); }
.actions form { margin: 0; }

/* --- Badge -------------------------------------------------------------------------------------- */
/* tones: full · not-full · undecided · error · info · none */
.badge { display: inline-block; padding: 1px var(--sp-2); border-radius: var(--radius-pill); font-size: 12.5px;
         font-weight: 600; white-space: nowrap; color: var(--muted); background: var(--code); }
.badge.full { color: var(--full); background: var(--full-bg); }
.badge.not-full { color: var(--notfull); background: var(--notfull-bg); }
.badge.undecided, .badge.error { color: var(--undecided); background: var(--undecided-bg); }
.badge.info { color: var(--info); background: var(--info-bg); }

/* --- Card (panel) ------------------------------------------------------------------------------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-md);
         padding: var(--sp-4); box-shadow: var(--shadow-1); }
.panel-title { margin: 0 0 var(--sp-2); font-size: var(--fs-base); }
/* A big number or time at the top of a card, e.g. the home page's at-a-glance cards */
.figure { margin: 0 0 var(--sp-1); font-size: var(--fs-lg); font-weight: 700; font-variant-numeric: tabular-nums; }
.grid.glance { margin-bottom: var(--sp-4); grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.notice { margin-bottom: var(--sp-4); }

/* --- Alert -------------------------------------------------------------------------------------- */
/* tones: (error) · warn · info · success */
.alert { padding: 10px 14px; border-radius: var(--radius-sm); background: var(--notfull-bg); color: var(--notfull);
         margin-bottom: var(--sp-4); border-left: 4px solid currentColor; }
.alert a { color: inherit; text-decoration: underline; }
.alert.warn { background: var(--undecided-bg); color: var(--undecided); }
.alert.info { background: var(--info-bg); color: var(--info); }
.alert.success { background: var(--full-bg); color: var(--full); }

/* --- Layout ------------------------------------------------------------------------------------- */
.grid { display: grid; gap: var(--sp-4); grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid.two { grid-template-columns: minmax(0, 3fr) minmax(260px, 1fr); align-items: start; }
@media (max-width: 900px) { .grid.two { grid-template-columns: 1fr; } }
.row { display: flex; gap: var(--sp-2); }
.row > * { flex: 1; }
.row.end { align-items: center; justify-content: space-between; }
.row.end > * { flex: 0 0 auto; }
.col { display: flex; flex-direction: column; gap: var(--sp-2); }
.narrow { max-width: 420px; }
.medium { max-width: 520px; }
.wide-form { max-width: 760px; }
.more { margin: 10px 0 0; }

/* --- Table -------------------------------------------------------------------------------------- */
table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line);
        border-radius: var(--radius-md); overflow: hidden; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }
table.inner { border: 0; border-radius: 0; }
table.inner th, table.inner td { padding: var(--sp-1) 6px; }
.chart td.yes { color: var(--full); font-weight: 600; text-align: center; }
.chart td.no { color: var(--muted); text-align: center; }

/* --- Form field --------------------------------------------------------------------------------- */
form.step { display: flex; flex-direction: column; gap: var(--sp-2); }
form.step h3 { margin: 0; font-size: var(--fs-base); }
form.step.wide { gap: 10px; }
form.upload { margin-top: var(--sp-3); }
form.inline { display: inline-flex; gap: 6px; align-items: center; flex-wrap: wrap; margin: 0; }
form.inline select, form.inline input { width: auto; }
.nowrap { white-space: nowrap; }
form.search { display: flex; gap: var(--sp-2); margin-bottom: var(--sp-2); max-width: 520px; }
form.search.public-filter { flex-wrap: wrap; align-items: flex-end; max-width: none; }
form.search.public-filter input[type=text] { flex: 1 1 240px; width: auto; }
form.search.public-filter select { width: auto; }
form.search.public-filter input.city { flex: 0 1 140px; }
form.search.public-filter label { flex-direction: row; align-items: center; gap: 6px; white-space: nowrap; }
label { font-size: var(--fs-sm); color: var(--muted); display: flex; flex-direction: column; gap: 3px; }
label.check { flex-direction: row; align-items: center; gap: 6px; color: var(--text); }
input:not([type]), input[type=text], input[type=number], input[type=date], input[type=email], input[type=password], select, textarea {
  font: inherit; font-size: 14px; padding: 6px var(--sp-2); border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--bg); color: var(--text); width: 100%; }
input:focus-visible, select:focus-visible, textarea:focus-visible { border-color: var(--focus); }
input.short { width: 8em; }
input.tiny { width: 4em; }
textarea { min-height: 54px; resize: vertical; }
textarea.config { min-height: 220px; font: var(--fs-sm)/1.45 var(--font-mono); }
select[multiple] { padding: var(--sp-1); }
select option:disabled { color: var(--muted); }
fieldset { border: 1px solid var(--line); border-radius: var(--sp-2); padding: 10px var(--sp-3); margin: 0; }
legend { font-size: var(--fs-sm); color: var(--muted); padding: 0 var(--sp-1); }

/* --- Tabs --------------------------------------------------------------------------------------- */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: var(--sp-3); }
.tabs a { padding: var(--sp-1) 10px; border-radius: var(--radius-pill); border: 1px solid var(--line);
          font-size: var(--fs-sm); color: var(--text); }
.tabs a.on, .tabs a[aria-current="page"] { background: var(--text); color: var(--bg); border-color: var(--text); }

/* --- Stat list and key-value list --------------------------------------------------------------- */
.stat { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--line); }
.stat:last-child { border-bottom: 0; }
.stat b { font-variant-numeric: tabular-nums; }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: var(--sp-1) 14px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; }

/* --- Pager -------------------------------------------------------------------------------------- */
.pager { display: flex; gap: var(--sp-3); align-items: center; margin: var(--sp-2) 0; }
.selected-bar { display: flex; gap: var(--sp-2); align-items: center; flex-wrap: wrap; margin: var(--sp-2) 0; }

/* --- Bar chart (templates/charts.html): checked trials by result per country or sponsor ---------- */
.grid.charts { margin: var(--sp-4) 0; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); }
.bar-chart .chart-head { display: flex; gap: var(--sp-2); align-items: baseline; justify-content: space-between; flex-wrap: wrap; }
.chart-controls { display: flex; gap: var(--sp-2); align-items: center; }
.chart-controls[hidden] { display: none; }
.chart-controls label { flex-direction: row; align-items: center; gap: 6px; }
.chart-controls select { width: auto; }
.legend { display: flex; gap: var(--sp-3); flex-wrap: wrap; list-style: none; padding: 0; margin: 0 0 var(--sp-2); color: var(--muted); }
.legend li { display: flex; align-items: center; gap: 6px; }
.swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.swatch.full, .bar .full { background: var(--full); fill: var(--full); }
.swatch.not-full, .bar .not-full { background: var(--notfull); fill: var(--notfull); }
.swatch.undecided, .bar .undecided { background: var(--undecided); fill: var(--undecided); }
ol.bars { list-style: none; padding: 0; margin: 0; }
.bar-row a { display: grid; grid-template-columns: minmax(0, 11em) minmax(0, 1fr) 6.5em; gap: var(--sp-2);
             align-items: center; min-height: 32px; padding: 2px var(--sp-1); border-radius: var(--radius-sm); color: var(--text); }
.bar-row a:hover, .bar-row a:focus-visible { background: var(--code); text-decoration: none; }
.bar-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--fs-sm); }
svg.bar { width: 100%; height: 14px; display: block; border-radius: 3px; background: var(--code); }
.bar-value { font-size: var(--fs-sm); font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.bar-row.extra { display: none; }
.bar-chart.all .bar-row.extra { display: block; }
.chart-detail { min-height: 1.5em; margin: var(--sp-2) 0; }

/* --- Phones ------------------------------------------------------------------------------------- */
/* The menu: on phones the nav folds into a <details> in base.html; on wider screens it is always open */
.menu > summary { display: none; }
.menu > summary::-webkit-details-marker { display: none; }
.app-nav-wrap { display: contents; }
/* Long identifiers and quotes wrap instead of widening the page */
td, dd, .result-card, .trace-body { overflow-wrap: anywhere; }

@media (max-width: 640px) {
  .app-header { gap: var(--sp-2) var(--sp-3); padding: 10px var(--sp-4); }
  .app-header .who { margin-left: 0; width: 100%; }
  main { padding: var(--sp-4) var(--sp-3) 48px; }
  dl.kv { grid-template-columns: 1fr; }
  dl.kv dd { margin-bottom: 6px; }

  .menu { margin-left: auto; }
  .menu > summary { display: block; cursor: pointer; list-style: none; color: var(--header-text);
                    padding: var(--sp-2) var(--sp-3); border: 1px solid var(--header-link); border-radius: var(--radius-sm); }
  .menu:not([open]) .app-nav { display: none; }
  .menu[open] { width: 100%; margin-left: 0; }
  .menu[open] > summary { width: max-content; margin-left: auto; }
  .menu .app-nav { flex-direction: column; gap: 0; padding-top: var(--sp-2); }
  .menu .app-nav a { padding: 10px 0; border-bottom: 1px solid var(--line); }
  .menu .app-nav a[aria-current="page"] { border-bottom-color: var(--brand-accent); }

  /* Controls big enough to tap */
  button, .button, input:not([type=checkbox]):not([type=radio]), select { min-height: 44px; font-size: 16px; }
  button.small, .button.small { min-height: 36px; }

  /* The home page's filter: one field per line */
  form.search.public-filter { flex-direction: column; align-items: stretch; }
  form.search.public-filter input[type=text], form.search.public-filter input.city,
  form.search.public-filter select { flex: 0 0 auto; width: 100%; }
  form.search.public-filter label { justify-content: space-between; }
  form.search.public-filter label input { width: auto; flex: 1; }
  form.search { flex-wrap: wrap; }
  .pager { flex-wrap: wrap; }

  /* A table marked .stack becomes one card per row, each cell with its column's name (data-label) */
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: 100%; }
  table.stack { border: 0; background: none; }
  table.stack tr:first-child:has(th) { display: none; }
  table.stack tr { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-md);
                   margin-bottom: var(--sp-3); padding: var(--sp-2) var(--sp-3); }
  table.stack td { border: 0; padding: 3px 0; }
  table.stack td[data-label]::before { content: attr(data-label); display: block; font-size: var(--fs-xs);
                                       text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
  table.stack td:empty, table.stack .hide-phone { display: none; }

  /* Charts: the name above its bar */
  .bar-row a { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "name value" "bar bar"; row-gap: 2px;
               padding: var(--sp-1); min-height: 44px; }
  .bar-name { grid-area: name; }
  .bar-value { grid-area: value; }
  svg.bar { grid-area: bar; }
  .chart-controls { width: 100%; }
  .chart-controls label { flex: 1; }
  .chart-controls select { flex: 1; }

  .hero-search .row { flex-wrap: wrap; }
  .hero-search button { flex: 1 1 100%; }
  .result-card .facts { grid-template-columns: 1fr; }
  .result-card .facts dd { margin-bottom: var(--sp-1); }
  .result-card { padding: var(--sp-3); }
}

/* --- Patient search (ADR-008): the search box, how a query was read, results, a trial's patient view */
.hero-search { display: flex; flex-direction: column; gap: var(--sp-1); margin: 0 0 var(--sp-4); max-width: 760px; }
.hero-search p { margin: 0; }
.hero-search .row { gap: var(--sp-2); }
.hero-search input[type="search"] { flex: 1; font-size: var(--fs-md); padding: var(--sp-2) var(--sp-3); }
.hero-search button { flex: 0 0 auto; }
.find-panel { margin-bottom: var(--sp-4); }
.find-panel .hero-search { margin-bottom: 0; }
.interpretation { background: var(--info-bg); color: var(--text); border-radius: var(--radius-sm);
                  padding: 10px 14px; margin: 0 0 var(--sp-3); }
.refine { margin: 0 0 var(--sp-3); }
.refine summary { cursor: pointer; color: var(--link); font-size: var(--fs-sm); }
.refine-form { display: grid; gap: var(--sp-2) var(--sp-3); grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
               align-items: end; margin-top: var(--sp-2); }
.refine-form label { display: flex; flex-direction: column; gap: var(--sp-1); font-size: var(--fs-sm); }
.radius-counts a[aria-current="true"] { font-weight: 700; }
.result-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-md);
               padding: var(--sp-3) var(--sp-4); margin: 0 0 var(--sp-3); box-shadow: var(--shadow-1); }
.result-card h3 { font-size: var(--fs-base); margin: 0 0 var(--sp-1); }
.result-card .conditions { margin: 0 0 var(--sp-2); color: var(--muted); }
.result-card .facts { display: grid; grid-template-columns: max-content 1fr; gap: 2px var(--sp-3); margin: 0 0 var(--sp-2); }
.result-card .facts dt { color: var(--muted); }
.result-card .facts dd { margin: 0; }
.result-card .card-links { margin: 0; }
.grid.patient { margin-bottom: var(--sp-3); }
details.criteria { margin: var(--sp-2) 0; }
details.criteria summary { cursor: pointer; color: var(--link); }
details.criteria h4 { font-size: var(--fs-sm); margin: var(--sp-2) 0 var(--sp-1); }
.disclaimer { border-top: 1px solid var(--line); margin-top: var(--sp-5); padding-top: var(--sp-3); }
.app-footer { max-width: 1200px; margin: 0 auto; padding: 0 var(--sp-4) var(--sp-5); }
