/*
 * Purpose: The portal's shared components, named after shadcn's with a tr- prefix (for TRipple): buttons first.
 * Where it fits: Loaded on every admin page through STYLES in config/unfold.py, after admin-base.css, whose tokens it uses; page stylesheets add only what is page-specific.
 * Author: Imre Draskovits <imre.draskovits@newcastle.ac.uk>
 * Created: 2026-11-15
 */

/* ── Button ───────────────────────────────────────────────────────────────
   One button for the whole portal, in the setup wizard's shape. Pick a
   variant and, if needed, a size:
   - tr-button--default: the main action, filled in Antwarp Blue;
   - tr-button--outline: any other action, outlined in grey;
   - tr-button--destructive: an irreversible action, filled red;
   - tr-button--destructive-outline: a removal that is not the page's main
     action, outlined red until hovered;
   - tr-button--caution: a significant but reversible action, filled rufous;
   - tr-button--sm: smaller text and padding, for tables and toolbars;
   - tr-button--icon: a square icon-only button (give it an aria-label).
   An arrow, when a button has one, comes after its label. */
.tr-button {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.4rem 0.9rem; border-radius: var(--radius-md);
  font-size: 0.85rem; font-weight: 600; cursor: pointer;
  border: 1px solid transparent; text-decoration: none; line-height: 1.4;
  transition: background-color 0.15s, border-color 0.15s;
}
.tr-button .material-symbols-outlined { font-size: 16px; line-height: 1; }
.tr-button:focus-visible { outline: 2px solid var(--antwarp-blue); outline-offset: 2px; }
.tr-button:disabled, .tr-button[aria-disabled="true"] { opacity: 0.4; cursor: not-allowed; pointer-events: none; }

.tr-button--default { background: var(--antwarp-blue); color: #fff; border-color: var(--antwarp-blue); }
.tr-button--default:hover { background: var(--antwarp-blue-hover); border-color: var(--antwarp-blue-hover); color: #fff; }

.tr-button--outline { background: #fff; color: var(--color-base-950, #25211d); border-color: var(--color-base-300, #ddd1bc); }
.tr-button--outline:hover { background: var(--neutral-hover-bg); border-color: var(--neutral-hover-border); }

.tr-button--destructive { background: var(--danger); color: #fff; border-color: var(--danger); }
.tr-button--destructive:hover { background: var(--danger-strong); border-color: var(--danger-strong); color: #fff; }

.tr-button--destructive-outline { background: #fff; color: var(--danger); border-color: var(--danger-line); }
.tr-button--destructive-outline:hover { background: var(--danger); color: #fff; border-color: var(--danger); }

.tr-button--caution { background: var(--cinnamon-rufous); color: #fff; border-color: var(--cinnamon-rufous); }
.tr-button--caution:hover { background: #a24f22; border-color: #a24f22; color: #fff; }

.tr-button--sm { padding: 0.3rem 0.75rem; font-size: 0.75rem; }

.tr-button--icon {
  justify-content: center; width: 30px; height: 30px; padding: 0; flex-shrink: 0; color: var(--color-base-700, #5f5549);
}
.tr-button--icon .material-symbols-outlined { font-size: 18px; }
.tr-button--icon.tr-button--destructive-outline { color: var(--danger); }
.tr-button--icon.tr-button--destructive-outline:hover { color: #fff; }

/* ── Badge ────────────────────────────────────────────────────────────────
   A short state in words, on a colour from the participant timeline:
   tr-badge--blue (under way), --violet (finished), --rufous (stopped early or
   paused), --red (aborted, refused), --grey (everything else). Each colour
   has a -tint, a pale fill with dark text, for the quieter state beside it.
   tr-badge--tiny is the schema grid's small "Sham" tag. Python writes them
   through record_list.badge(); a trial's status through trial_status(),
   which adds tr-trial-status. */
.tr-badge {
  display: inline-flex; align-items: center;
  padding: 0.1rem 0.55rem; border-radius: var(--radius-full);
  font-size: 0.75rem; font-weight: 600; white-space: nowrap;
}
.tr-badge--blue { background: var(--antwarp-blue); color: #fff; }
.tr-badge--blue-tint { background: var(--antwarp-blue-wash); color: var(--antwarp-blue-ink); box-shadow: inset 0 0 0 1px var(--antwarp-blue-tint); }
.tr-badge--violet { background: var(--red-violet); color: #fff; }
.tr-badge--violet-tint { background: var(--red-violet-wash); color: var(--red-violet); box-shadow: inset 0 0 0 1px var(--red-violet-tint); }
.tr-badge--rufous { background: var(--cinnamon-rufous); color: #fff; }
.tr-badge--rufous-tint { background: var(--cinnamon-rufous-wash); color: var(--cinnamon-rufous-ink); box-shadow: inset 0 0 0 1px var(--cinnamon-rufous-tint); }
.tr-badge--red { background: var(--danger); color: #fff; }
.tr-badge--red-tint { background: var(--danger-wash); color: var(--danger-strong); box-shadow: inset 0 0 0 1px var(--danger-line-soft); }
.tr-badge--grey { background: var(--neutral-hover-bg); color: var(--color-base-700, #5f5549); box-shadow: inset 0 0 0 1px var(--color-base-200, #eee8dc); }
.tr-badge--tiny { font-size: 0.55rem; padding: 1px 4px; }

/* ── Alert ────────────────────────────────────────────────────────────────
   A notice in the page, in the setup wizard's shape: a pale fill, a strong
   left edge, an optional icon in front.
   - tr-alert--info: something to know, in Antwarp Blue's own tint;
   - tr-alert--warning: something to look at, in Cinnamon Rufous;
   - tr-alert--success: done or settled, in Red Violet, the portal's colour
     for finished;
   - tr-alert--destructive: blocking, or about to be lost, in red. */
.tr-alert {
  display: flex; align-items: flex-start; gap: 0.5rem;
  border: 1px solid; border-left-width: 4px; border-radius: var(--radius-md);
  padding: 0.7rem 1rem; margin: 0.75rem 0 1rem;
  font-size: 0.85rem;
}
.tr-alert > .material-symbols-outlined { font-size: 20px; flex-shrink: 0; }
.tr-alert ul { margin: 0.35rem 0 0 1.1rem; list-style: disc; }
.tr-alert a { color: inherit; font-weight: 600; text-decoration: underline; }
.tr-alert--info { background: var(--antwarp-blue-wash); border-color: var(--antwarp-blue-tint); border-left-color: var(--antwarp-blue); color: var(--antwarp-blue-ink); }
.tr-alert--warning { background: var(--cinnamon-rufous-wash); border-color: var(--cinnamon-rufous-tint); border-left-color: var(--cinnamon-rufous); color: var(--cinnamon-rufous-ink); }
.tr-alert--success { background: var(--red-violet-wash); border-color: var(--red-violet-tint); border-left-color: var(--red-violet); color: var(--red-violet); }
.tr-alert--destructive { background: var(--danger-faint); border-color: var(--danger-line-soft); border-left-color: var(--danger); color: var(--danger); }

/* ── Table ────────────────────────────────────────────────────────────────
   A data table in the setup wizard's shape: headings in sentence case on a
   light band, quiet row lines, cells centred vertically. tr-table--flush is
   for a table that runs to its card's edges: the outer cells take the card's
   1.5rem padding. Unfold's change lists keep their own table. */
.tr-table { width: 100%; border-collapse: collapse; }
.tr-table th {
  font-size: 0.8rem; font-weight: 600; color: var(--color-base-950, #25211d);
  padding: 0.6rem 0.85rem; text-align: left;
  border-bottom: 1px solid var(--color-base-200, #eee8dc);
  background: var(--color-base-50, #fcfbf8);
}
.tr-table td {
  padding: 0.55rem 0.85rem; font-size: 0.83rem;
  color: var(--color-base-800, #4e473e);
  border-bottom: 1px solid var(--color-base-100, #f6f3ed);
  vertical-align: middle;
}
.tr-table tr:last-child td { border-bottom: none; }
.tr-table th.num, .tr-table td.num { text-align: right; }
.tr-table--flush th:first-child, .tr-table--flush td:first-child { padding-left: 1.5rem; }
.tr-table--flush th:last-child, .tr-table--flush td:last-child { padding-right: 1.5rem; }

/* ── Tooltip ──────────────────────────────────────────────────────────────
   An info button whose text shows on hover and on keyboard focus, and stays
   open when clicked or tapped (tooltip.js); Esc, a click outside or another
   tip closes it. Written only by the tooltip and
   card_title tags (trial_extras), so the markup is the same everywhere. */
.tr-tooltip {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0; border: 0; background: none; border-radius: 50%;
  color: var(--color-base-600, #746757); cursor: pointer; vertical-align: middle;
  position: relative;
}
/* A touch-sized target around the 16px icon, without moving the layout. */
.tr-tooltip::before { content: ""; position: absolute; inset: -8px; }
.tr-tooltip .material-symbols-outlined { font-size: 16px; line-height: 1; }
.tr-tooltip:hover, .tr-tooltip:focus-visible { color: var(--antwarp-blue); }
.tr-tooltip:focus-visible { outline: 2px solid var(--antwarp-blue); outline-offset: 1px; }

/* The floating box tooltip.js places, fixed to the window so nothing crops it.
   It takes the pointer, so it stays while read (tooltip.js); hidden, it takes none. */
.tr-tooltip-content {
  position: fixed; top: 0; left: 0; z-index: 1000;
  width: max-content; max-width: min(260px, calc(100vw - 16px)); padding: 6px 10px; border-radius: var(--radius-md);
  background: var(--color-base-900, #423d36); color: #fff;
  font-size: 0.72rem; font-weight: 400; line-height: 1.45;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  opacity: 0; visibility: hidden; transition: opacity 0.15s;
}
.tr-tooltip-content.is-shown { opacity: 1; visibility: visible; }

/* ── Alert dialog ─────────────────────────────────────────────────────────
   A native <dialog> that asks before an action with consequences, or
   explains something: a round tone icon, a title and a line under it, the
   details, then Cancel and the action. dialog.js opens and closes it. Pick
   a tone:
   - tr-alert-dialog--default: going ahead, or an explanation, in Antwarp Blue;
   - tr-alert-dialog--caution: a pause or another reversible change, in
     Cinnamon Rufous;
   - tr-alert-dialog--destructive: irreversible, in red;
   - tr-alert-dialog--export: a data export, in Red Violet (orange is
     "today").
   Its buttons are tr-buttons: Cancel is --outline, the action the tone's own
   variant (--default, --caution, --destructive or --export). The icon
   glyphs are the darker shades that pass 3:1 on their tint. */
.tr-alert-dialog {
  /* Centred: Unfold's reset takes away the browser's own dialog margins. */
  position: fixed; inset: 0; margin: auto; height: fit-content;
  width: calc(100% - 2rem); max-width: 30rem;
  padding: 1.5rem; border: none; border-radius: var(--radius-lg);
  box-shadow: var(--modal-shadow); color: var(--color-base-900, #423d36);
}
.tr-alert-dialog::backdrop { background: rgba(0, 0, 0, 0.5); }
.tr-alert-dialog-header { display: flex; align-items: flex-start; gap: 0.75rem; margin-bottom: 1rem; }
.tr-alert-dialog-icon {
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  width: 2.25rem; height: 2.25rem; border-radius: 50%;
}
.tr-alert-dialog-title { margin: 0; font-size: 1rem; font-weight: 700; color: var(--color-base-950, #25211d); }
.tr-alert-dialog-description { margin: 0.15rem 0 0; font-size: 0.8rem; color: var(--color-base-600, #746757); }
.tr-alert-dialog-text { margin: 0 0 1.25rem; font-size: 0.875rem; line-height: 1.5; }
.tr-alert-dialog-list { margin: 0 0 1.25rem; padding-left: 1.1rem; list-style: disc; font-size: 0.875rem; line-height: 1.5; }
.tr-alert-dialog-list li + li { margin-top: 0.35rem; }
.tr-alert-dialog-description[hidden], .tr-alert-dialog-text[hidden] { display: none; }
.tr-alert-dialog-footer { display: flex; justify-content: flex-end; gap: 0.6rem; }
.tr-alert-dialog-footer .tr-button { justify-content: center; }
/* A footer button hidden by script (export's Cancel and Stop) stays hidden: tr-button sets display. */
.tr-alert-dialog-footer .tr-button[hidden] { display: none; }

.tr-alert-dialog--default .tr-alert-dialog-icon { background: var(--antwarp-blue-tint); color: var(--antwarp-blue-hover); }
.tr-alert-dialog--caution .tr-alert-dialog-icon { background: var(--cinnamon-rufous-tint); color: var(--cinnamon-rufous-ink); }
.tr-alert-dialog--destructive .tr-alert-dialog-icon { background: var(--danger-wash); color: var(--danger); }
.tr-alert-dialog--export .tr-alert-dialog-icon { background: var(--red-violet-wash); color: var(--red-violet); }

/* ── Danger colour helpers ────────────────────────────────────────────────
   The one red set (--danger* in admin-base.css) for a word, a filled chip or
   a dot, where Tailwind's reds were used before. */
.tr-text-danger { color: var(--danger); }
.tr-fill-danger { background: var(--danger-wash); color: var(--danger); }
.tr-dot-danger { background: var(--danger-bright); }

/* Fold-out: one bordered row with its title and meta on the left and Show / Hide
   plus a chevron on the right, in place of the browser's own triangle. Native
   <details>, so it is keyboard accessible; used by every disclosure in the portal. */
details.tr-fold > summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.6rem 0.9rem;
    border: 1px solid var(--color-base-200, #eee8dc);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    cursor: pointer;
    list-style: none;
}

details.tr-fold > summary::-webkit-details-marker { display: none; }
details.tr-fold > summary:focus-visible { outline: 2px solid var(--antwarp-blue); outline-offset: 2px; }
details.tr-fold > summary:hover { background: var(--color-base-50, #fcfbf8); border-color: var(--antwarp-blue); }
.tr-fold-action { display: inline-flex; align-items: center; gap: 0.25rem; color: var(--antwarp-blue); font-weight: 600; }
.tr-fold-chevron { font-size: 20px; transition: transform 0.15s; }
.tr-fold[open] .tr-fold-chevron { transform: rotate(180deg); }
.tr-fold .tr-fold-hide,
.tr-fold[open] .tr-fold-show { display: none; }
.tr-fold[open] .tr-fold-hide { display: inline; }
details.tr-fold[open] > summary { margin-bottom: 1rem; }

/* ── Info button ──────────────────────────────────────────────────────────
   A small ⓘ beside a heading or field name that opens an info dialog
   (admin/components/info_button.html and info_dialog.html). */
.ts-info-btn { display: inline-flex; vertical-align: middle; padding: 0; border: 0; background: none; color: var(--color-base-800, #4e473e); cursor: pointer; }
.ts-info-btn .material-symbols-outlined { font-size: 16px; }
.ts-info-btn:hover { color: var(--antwarp-blue); }
