/*
 * Design tokens and overrides for the calculators.
 *
 * Bootstrap 5.3 drives its components from CSS custom properties, so the
 * whole palette is set by redefining a handful of variables rather than by
 * overriding component rules. Dark mode comes from Bootstrap's own
 * `data-bs-theme` attribute, set in the head from the system preference.
 *
 * Choices worth stating:
 *
 *   Teal accent rather than the stock Bootstrap blue. It stays clearly
 *   distinct from the red and amber that alerts and invalid fields need, so
 *   a warning never reads as decoration.
 *
 *   Tabular figures in results. Dosing tables are columns of numbers that
 *   get compared down the column, and proportional digits make 1 and 7 sit
 *   at different widths.
 *
 *   Nothing here is branded. This is a personal site, not a CHOA or Emory
 *   product, and institutional marks would imply an endorsement that does
 *   not exist.
 */

:root,
[data-bs-theme='light'] {
  --ct-accent: #0f766e;
  --ct-accent-hover: #115e59;
  --ct-accent-contrast: #ffffff;
  --ct-surface: #ffffff;
  --ct-page: #f6f8f8;

  --bs-body-bg: var(--ct-page);
  --bs-link-color-rgb: 15, 118, 110;
  --bs-link-hover-color-rgb: 17, 94, 89;
}

[data-bs-theme='dark'] {
  /* Lifted for contrast against a dark surface; the 700 teal is too dim. */
  --ct-accent: #2dd4bf;
  --ct-accent-hover: #5eead4;
  --ct-accent-contrast: #04211f;
  --ct-surface: #17212b;
  --ct-page: #0f171e;

  --bs-body-bg: var(--ct-page);
  --bs-link-color-rgb: 45, 212, 191;
  --bs-link-hover-color-rgb: 94, 234, 212;
}

body {
  min-height: 100vh;
}

/* ------------------------------------------------------------ accent --- */

.btn-primary {
  --bs-btn-bg: var(--ct-accent);
  --bs-btn-border-color: var(--ct-accent);
  --bs-btn-color: var(--ct-accent-contrast);
  --bs-btn-hover-bg: var(--ct-accent-hover);
  --bs-btn-hover-border-color: var(--ct-accent-hover);
  --bs-btn-active-bg: var(--ct-accent-hover);
  --bs-btn-active-border-color: var(--ct-accent-hover);
  --bs-btn-disabled-bg: var(--ct-accent);
  --bs-btn-disabled-border-color: var(--ct-accent);
}

.btn-outline-primary {
  --bs-btn-color: var(--ct-accent);
  --bs-btn-border-color: var(--ct-accent);
  --bs-btn-hover-bg: var(--ct-accent);
  --bs-btn-hover-border-color: var(--ct-accent);
  --bs-btn-hover-color: var(--ct-accent-contrast);
  --bs-btn-active-bg: var(--ct-accent);
  --bs-btn-active-border-color: var(--ct-accent);
  --bs-btn-active-color: var(--ct-accent-contrast);
}

.navbar.bg-primary {
  background-color: var(--ct-accent) !important;
}

/*
 * In dark mode the bar becomes a dark surface with an accent hairline. A wide
 * band of bright teal is the single largest light source on the page, which
 * is exactly what dark mode exists to avoid on a night shift.
 */
[data-bs-theme='dark'] .navbar.bg-primary {
  background-color: var(--ct-surface) !important;
  border-bottom: 1px solid rgba(45, 212, 191, 0.28);
}

[data-bs-theme='dark'] .navbar .navbar-brand {
  color: var(--ct-accent);
}

/* ---------------------------------------------------------- structure -- */

.navbar-brand {
  font-size: 1.1rem;
  letter-spacing: 0.01em;
}

/* Keep long dosing tables readable rather than stretched across a wide screen. */
main,
.container {
  max-width: 1100px;
}

fieldset legend.form-label {
  margin-bottom: 0.5rem;
}

.form-label {
  font-weight: 500;
}

/* The vertical option groups are the primary input on most pages. */
.btn-group-vertical .btn {
  text-align: left;
  padding-left: 1rem;
}

/* ------------------------------------------------------------ results -- */

#resultCard {
  background-color: var(--ct-surface);
  border-color: rgba(var(--bs-emphasis-color-rgb), 0.12);
}

#output table {
  /* Digits line up down the column, which is how a dosing table is read. */
  font-variant-numeric: tabular-nums;
  margin-bottom: 0;
}

#output caption {
  padding-top: 0;
  font-size: 0.9rem;
}

#output th {
  font-weight: 600;
  white-space: nowrap;
}

/* --------------------------------------------------------------- misc -- */

.btn-copy {
  min-width: 7rem;
}

footer,
.site-footer {
  font-size: 0.925rem;
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}

/* ======================================================== layout ======= */

/*
 * The navbar is full bleed and holds its own container, so the accent band
 * spans the viewport while its contents line up with page content. The bar
 * used to sit inside a container, which left a strip of accent colour
 * floating in the middle of the window with page background either side.
 */
.site-nav {
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.06), 0 2px 12px rgba(0, 0, 0, 0.04);
}

.site-nav .container {
  max-width: 1100px;
}

body {
  padding-bottom: 3rem;
}

/* Breathing room under the bar, which previously butted straight into the h1. */
.page-head {
  padding: 2.25rem 0 1.25rem;
}

.page-title {
  font-size: clamp(1.6rem, 1.2rem + 1.6vw, 2.25rem);
  font-weight: 650;
  letter-spacing: -0.01em;
  margin-bottom: 0.5rem;
}

.page-lead {
  color: rgba(var(--bs-emphasis-color-rgb), 0.7);
  max-width: 62ch;
  margin-bottom: 0;
}

/* ==================================================== home page ======== */

.calc-section {
  margin-bottom: 2.25rem;
}

.section-heading {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ct-accent);
  margin-bottom: 0.75rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid rgba(var(--bs-emphasis-color-rgb), 0.1);
}

/*
 * A card per calculator, generated from the registry. The landing page used
 * to be one sentence, which meant the only way to discover a calculator was
 * to open a dropdown and read it.
 */
.calc-card {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 1.1rem 1.15rem;
  background-color: var(--ct-surface);
  border: 1px solid rgba(var(--bs-emphasis-color-rgb), 0.12);
  border-radius: 0.6rem;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.calc-card:hover,
.calc-card:focus-visible {
  border-color: var(--ct-accent);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.07);
  transform: translateY(-1px);
  color: inherit;
}

.calc-card-title {
  font-weight: 600;
  font-size: 1.02rem;
  margin-bottom: 0.35rem;
}

.calc-card-text {
  font-size: 0.9rem;
  line-height: 1.45;
  color: rgba(var(--bs-emphasis-color-rgb), 0.68);
  flex-grow: 1;
}

.calc-card-go {
  margin-top: 0.85rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ct-accent);
}

/* ==================================================== calculator ======= */

/* The form and the result each sit on a surface, so the page has structure
 * rather than everything floating on one flat background. */
.ct-panel {
  background-color: var(--ct-surface);
  border: 1px solid rgba(var(--bs-emphasis-color-rgb), 0.12);
  border-radius: 0.6rem;
  padding: 1.35rem;
}

/*
 * Numeric fields were as wide as the column, which for a two to four
 * character number reads as a text area and makes the form look empty.
 */
.ct-panel input.form-control[type='number'],
.ct-panel input.form-control[inputmode='decimal'],
.ct-panel select.form-select {
  max-width: 15rem;
}

/* --------------------------------------------- which field to fill in -- */

/*
 * On several pages the field being solved for is set readonly, so it is an
 * output rather than an input. Bootstrap renders readonly almost identically
 * to an editable field, so all four boxes looked equally fillable and nothing
 * said which one was the answer.
 */
.form-control[readonly] {
  background-color: rgba(var(--bs-emphasis-color-rgb), 0.04);
  border-style: dashed;
  border-color: rgba(var(--bs-emphasis-color-rgb), 0.25);
  color: rgba(var(--bs-emphasis-color-rgb), 0.55);
  cursor: not-allowed;
}

.form-control[readonly]:focus {
  box-shadow: none;
  border-color: rgba(var(--bs-emphasis-color-rgb), 0.25);
}

/* Editable fields get a clear accent focus ring, so tabbing through the form
 * always shows where you are. */
.form-control:not([readonly]):focus,
.form-select:focus {
  border-color: var(--ct-accent);
  box-shadow: 0 0 0 0.2rem rgba(15, 118, 110, 0.18);
}

[data-bs-theme='dark'] .form-control:not([readonly]):focus,
[data-bs-theme='dark'] .form-select:focus {
  box-shadow: 0 0 0 0.2rem rgba(45, 212, 191, 0.22);
}

/* ------------------------------------------------ which option is on --- */

/*
 * The selected option carried only a fill colour. A check mark states it
 * outright, which matters because the choice changes which fields the form
 * expects you to complete.
 */
.btn-group-vertical .btn-check + .btn,
.btn-group .btn-check + .btn {
  position: relative;
  padding-left: 2.25rem;
}

.btn-group-vertical .btn-check + .btn::before,
.btn-group .btn-check + .btn::before {
  content: '';
  position: absolute;
  left: 0.85rem;
  top: 50%;
  width: 0.95rem;
  height: 0.95rem;
  margin-top: -0.475rem;
  border: 1.5px solid currentColor;
  opacity: 0.45;
}

.btn-group-vertical .btn-check:checked + .btn,
.btn-group .btn-check:checked + .btn {
  font-weight: 600;
}

/*
 * Round for radio, square for checkbox. The shape is the only thing telling a
 * clinician whether the options are exclusive, and on the total daily dose
 * page the characteristics are additive: each one selected adds to the dose.
 * They were drawn as round markers directly under a group of real radios,
 * which read as "pick one" for a question where the answer is "pick all that
 * apply".
 */
.btn-check[type='radio'] + .btn::before {
  border-radius: 50%;
}

.btn-check[type='checkbox'] + .btn::before {
  border-radius: 0.22rem;
}

.btn-check[type='radio']:checked + .btn::before {
  background-color: currentColor;
  box-shadow: inset 0 0 0 0.19rem var(--ct-accent);
  opacity: 1;
}

.btn-check[type='checkbox']:checked + .btn::before {
  background-color: currentColor;
  opacity: 1;
}

/* The tick, drawn rather than loaded, so it needs no icon font. */
.btn-check[type='checkbox']:checked + .btn::after {
  content: '';
  position: absolute;
  left: 1.16rem;
  top: 50%;
  width: 0.3rem;
  height: 0.58rem;
  margin-top: -0.35rem;
  border: solid var(--ct-accent);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.btn-check:focus-visible + .btn {
  box-shadow: 0 0 0 0.2rem rgba(15, 118, 110, 0.25);
}

/* ------------------------------------------------------- result card --- */

#calcExplain {
  padding: 1rem 1.15rem;
  background-color: rgba(var(--bs-emphasis-color-rgb), 0.03);
  border: 1px dashed rgba(var(--bs-emphasis-color-rgb), 0.14);
  border-radius: 0.6rem;
}

/*
 * The equation is typeset to SVG at build time. MathJax emits an intrinsic
 * width in ex units, which for this formula is about 63ex and overflows the
 * column. Scaling to the container keeps the whole formula visible rather
 * than clipping the right-hand side, and the SVG uses currentColor so it
 * follows the theme without a second copy for dark mode.
 */
#calcExplain mjx-container {
  margin: 0 !important;
  display: block;
}

#calcExplain svg {
  max-width: 100%;
  height: auto;
}

#resultCard {
  border-radius: 0.6rem;
}
