/* App styles on top of Pico CSS. No inline styles anywhere: the CSP forbids them. */

:root {
  --pico-font-size: 100%;
  --bp-normal: #2e9e5b;
  --bp-elevated: #d4a20b;
  --bp-stage1: #e07b1f;
  --bp-stage2: #d93526;
  --bp-left: #3b6fd8;
  --bp-right: #b04fc8;
}

/* Header and navigation */
.site-header nav {
  flex-wrap: wrap;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  text-decoration: none;
}
.brand img {
  display: block;
}
.nav-links {
  flex-wrap: wrap;
}
.nav-links a[aria-current="page"] {
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 0.35em;
}
.inline-form {
  margin: 0;
  display: inline;
}
button.small,
a[role="button"].small {
  padding: 0.3rem 0.7rem;
  font-size: 0.875rem;
  width: auto;
  margin: 0;
}

@media (max-width: 640px) {
  .site-header nav {
    flex-direction: column;
    align-items: flex-start;
  }
  .nav-links {
    margin-left: calc(var(--pico-nav-element-spacing-horizontal) * -1);
  }
  .site-header nav li {
    padding-block: 0.25rem;
  }
}

/* Layout helpers */
.narrow {
  max-width: 28rem;
}
.center {
  text-align: center;
}
.login {
  padding-top: 10vh;
}
.login hgroup h1 {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.muted {
  color: var(--pico-muted-color);
}
.error-text {
  color: var(--pico-del-color);
}
.hidden {
  display: none;
}
.row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}
.row > *,
.row > input,
.row > select {
  /* inputs need the extra selector: Pico's own input margin rule is more specific */
  margin-bottom: 0;
}
/* A full-size button next to an input: same height as the input, but only as wide as its
   text (Pico makes submit buttons full width). */
.row > button {
  width: auto;
  flex: none;
}
.spacer {
  flex: 1;
}

/* htmx loading indicator (htmx's own <style> is disabled for CSP). */
.htmx-indicator {
  opacity: 0;
  transition: opacity 200ms ease-in;
}
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
  opacity: 1;
  transition-delay: 200ms;
}

/* Badges and tags */
.badge,
.tag {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  line-height: 1.4;
  white-space: nowrap;
  vertical-align: middle;
}
.tag {
  background: var(--pico-secondary-background);
  color: var(--pico-secondary-inverse);
}
.badge.arm-left {
  background: color-mix(in srgb, var(--bp-left) 15%, transparent);
  color: var(--bp-left);
}
.badge.arm-right {
  background: color-mix(in srgb, var(--bp-right) 15%, transparent);
  color: var(--bp-right);
}
.badge.review {
  background: color-mix(in srgb, var(--bp-stage1) 18%, transparent);
  color: var(--bp-stage1);
  white-space: normal;
}
.badge.cat-normal {
  background: color-mix(in srgb, var(--bp-normal) 18%, transparent);
  color: var(--bp-normal);
}
.badge.cat-elevated {
  background: color-mix(in srgb, var(--bp-elevated) 20%, transparent);
  color: color-mix(in srgb, var(--bp-elevated) 70%, var(--pico-color));
}
.badge.cat-stage1 {
  background: color-mix(in srgb, var(--bp-stage1) 18%, transparent);
  color: var(--bp-stage1);
}
.badge.cat-stage2,
.badge.cat-crisis {
  background: color-mix(in srgb, var(--bp-stage2) 18%, transparent);
  color: var(--bp-stage2);
}
.badge.cat-crisis {
  font-weight: 700;
}

/* Page head and filters */
.page-head h1 {
  margin-bottom: 0;
}
.page-head {
  margin-bottom: var(--pico-spacing);
}
.range-filter {
  margin: var(--pico-spacing) 0;
}
.presets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-bottom: 0.5rem;
}
.preset {
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--pico-muted-border-color);
  text-decoration: none;
  font-size: 0.875rem;
}
.preset.active {
  background: var(--pico-primary-background);
  border-color: var(--pico-primary-background);
  color: var(--pico-primary-inverse);
}
.custom-range input,
.custom-range select {
  width: auto;
  flex: 1 1 9rem;
  margin-bottom: 0;
}

/* Readings list */
.day {
  margin-bottom: calc(var(--pico-spacing) * 1.5);
}
.day-title {
  font-size: 1rem;
  border-bottom: 1px solid var(--pico-muted-border-color);
  padding-bottom: 0.25rem;
  margin-bottom: 0.5rem;
}
.day-title::first-letter {
  text-transform: uppercase;
}
.session {
  padding: 0.25rem 0 0.5rem;
  border-bottom: 1px dashed var(--pico-muted-border-color);
}
.session:last-child {
  border-bottom: none;
}
.arm-diff {
  display: block;
  padding-left: 4rem;
}
.reading {
  display: grid;
  grid-template-columns: 3.5rem 4.5rem minmax(10rem, auto) 1fr auto;
  gap: 0.5rem 0.75rem;
  align-items: center;
  padding: 0.35rem 0;
}
.reading.needs-review {
  background: color-mix(in srgb, var(--bp-stage1) 7%, transparent);
  border-radius: var(--pico-border-radius);
}
.reading-time {
  font-variant-numeric: tabular-nums;
  color: var(--pico-muted-color);
}
.reading-values {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  flex-wrap: wrap;
}
.reading-values .bp {
  font-size: 1.25rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.reading-values .pulse {
  color: var(--pico-muted-color);
  font-variant-numeric: tabular-nums;
}
.reading-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
  min-width: 0;
}
.reading-meta .note {
  color: var(--pico-muted-color);
  font-size: 0.875rem;
}
.reading-actions {
  display: flex;
  gap: 0.35rem;
  align-items: center;
  justify-content: flex-end;
}
.small-link {
  font-size: 0.875rem;
}
@media (max-width: 720px) {
  .reading {
    grid-template-columns: 3.5rem 1fr auto;
  }
  .reading-arm {
    grid-column: 3;
    grid-row: 1;
    justify-self: end;
  }
  .reading-values {
    grid-column: 2;
    grid-row: 1;
  }
  .reading-meta {
    grid-column: 2 / 4;
  }
  .reading-actions {
    grid-column: 1 / 4;
    justify-content: flex-start;
  }
  .arm-diff {
    padding-left: 0;
  }
}

/* Edit forms */
.reading-edit {
  padding: var(--pico-spacing);
  margin: 0.5rem 0;
  border: 1px solid var(--pico-muted-border-color);
  border-radius: var(--pico-border-radius);
  background: var(--pico-card-background-color);
}
.reading-edit .row {
  margin-bottom: 0.75rem;
}
.fields-values input {
  font-size: 1.15rem;
  font-variant-numeric: tabular-nums;
}
.manual-add {
  margin: var(--pico-spacing) 0;
}

/* Needs-review section */
.review-section h2 {
  font-size: 1.15rem;
}
.review-card {
  display: grid;
  grid-template-columns: minmax(8rem, 14rem) 1fr;
  gap: var(--pico-spacing);
  align-items: start;
}
.review-card .reading-edit {
  margin-top: 0;
}
.review-photo {
  width: 100%;
  border-radius: var(--pico-border-radius);
  display: block;
}
.review-photo.placeholder {
  aspect-ratio: 3 / 4;
  display: grid;
  place-items: center;
  border: 1px dashed var(--pico-muted-border-color);
}
@media (max-width: 720px) {
  .review-card {
    grid-template-columns: 1fr;
  }
  .review-photo {
    max-height: 50vh;
    object-fit: contain;
  }
}
.empty {
  padding: 2rem 0;
  text-align: center;
}

/* Chart tokens: series colours validated for colour-vision deficiency (light and dark). */
:root {
  --viz-sys: #2a78d6;
  --viz-dia: #eb6834;
  --viz-pulse: #6250d6;
  --viz-text: #0b0b0b;
  --viz-muted: #6f6d68;
  --viz-grid: #e1e0d9;
  --viz-axis: #c3c2b7;
  --viz-tooltip-bg: #ffffff;
}
/* Screen only, like Pico's dark theme: printouts always use the light palette. */
@media only screen and (prefers-color-scheme: dark) {
  :root {
    --viz-sys: #3987e5;
    --viz-dia: #d95926;
    --viz-pulse: #9085e9;
    --viz-text: #f0efec;
    --viz-muted: #9a988f;
    --viz-grid: #2c2f36;
    --viz-axis: #3b3f47;
    --viz-tooltip-bg: #1d222b;
  }
}

/* Dashboard tiles */
.tiles {
  display: grid;
  grid-template-columns: 1.7fr 1fr 1fr 1fr;
  gap: var(--pico-spacing);
  margin-bottom: var(--pico-spacing);
}
.stat-tile {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
@media (max-width: 900px) {
  .tiles {
    grid-template-columns: 1fr 1fr;
  }
  .stat-tile.latest {
    grid-column: span 2;
  }
}
.stat-value {
  font-size: 1.6rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}
.stat-value.big {
  font-size: 2.4rem;
}
.stat-value .pulse {
  font-size: 1.1rem;
  font-weight: 400;
  color: var(--pico-muted-color);
}
.today {
  display: flex;
  flex-direction: column;
  font-size: 1.05rem;
  font-weight: 600;
}
.today .todo {
  color: var(--pico-muted-color);
  font-weight: 400;
}
.notice {
  padding: 0.6rem 1rem;
  border-radius: var(--pico-border-radius);
  background: color-mix(in srgb, var(--bp-stage1) 12%, transparent);
}
.notice a {
  color: var(--pico-color);
  text-decoration: none;
}
.empty-state {
  text-align: center;
}

/* Charts */
.section-title {
  font-size: 1.15rem;
  margin: calc(var(--pico-spacing) * 1.5) 0 0.5rem;
}
.chart-box {
  position: relative;
  width: 100%;
}
.chart-box.large {
  height: 320px;
}
.chart-box.small {
  height: 220px;
}
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.25rem;
  padding: 0;
  margin: 0 0 0.5rem;
  font-size: 0.875rem;
}
.chart-legend li {
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0;
}
.swatch {
  display: inline-block;
  width: 14px;
  height: 3px;
  border-radius: 2px;
}
.swatch.sys {
  background: var(--viz-sys);
}
.swatch.dia {
  background: var(--viz-dia);
}
.swatch.ref {
  height: 0;
  border-top: 2px dashed var(--viz-muted);
}
.chart-note {
  font-size: 0.8rem;
  margin-top: 0.4rem;
}
.table-wrap {
  overflow-x: auto;
}
/* The TypeScript version's pages had no doctype, so browsers used quirks mode, where tables
   reset to `line-height: normal`. Keep that compact look in standards mode. */
table {
  line-height: normal;
}
/* Same reason: in quirks mode a line holding only a small inline box is not raised to the
   parent's line height, so these lines were shorter there. */
.category-table .badge {
  vertical-align: top;
}
.report-header small {
  display: block;
}
.summary-table td,
.summary-table th,
.category-table td {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
meter.share {
  width: 6rem;
  vertical-align: middle;
}
/* Meter bars take the category colour instead of the browser's green. */
meter.share.cat-normal::-webkit-meter-optimum-value {
  background: var(--bp-normal);
}
meter.share.cat-normal::-moz-meter-bar {
  background: var(--bp-normal);
}
meter.share.cat-elevated::-webkit-meter-optimum-value {
  background: var(--bp-elevated);
}
meter.share.cat-elevated::-moz-meter-bar {
  background: var(--bp-elevated);
}
meter.share.cat-stage1::-webkit-meter-optimum-value {
  background: var(--bp-stage1);
}
meter.share.cat-stage1::-moz-meter-bar {
  background: var(--bp-stage1);
}
meter.share.cat-stage2::-webkit-meter-optimum-value {
  background: var(--bp-stage2);
}
meter.share.cat-stage2::-moz-meter-bar {
  background: var(--bp-stage2);
}
meter.share.cat-crisis::-webkit-meter-optimum-value {
  background: var(--bp-stage2);
}
meter.share.cat-crisis::-moz-meter-bar {
  background: var(--bp-stage2);
}

/* Doctor report */
.report-toolbar {
  padding-top: var(--pico-spacing);
}
.report-header h1 {
  margin-bottom: 0.25rem;
}
.report-table {
  font-size: 0.875rem;
}
.report-table td,
.report-table th {
  padding: 0.3rem 0.5rem;
  font-variant-numeric: tabular-nums;
}
.report-table tr.day-start td {
  border-top: 1px solid var(--pico-muted-border-color);
}
.report-table td:first-child {
  white-space: nowrap;
}

@media print {
  @page {
    size: A4;
    margin: 14mm 12mm;
  }
  .no-print {
    display: none;
  }
  body.report {
    font-size: 10pt;
  }
  .report .container {
    max-width: none;
    padding: 0;
  }
  .report .section-title {
    font-size: 12pt;
    margin: 10pt 0 4pt;
  }
  .report .chart-box.small {
    height: 200px;
  }
  .avoid-break {
    break-inside: avoid;
  }
  .report-table thead {
    display: table-header-group;
  }
  .report-table tr {
    break-inside: avoid;
  }
  .report .badge {
    border: 1px solid currentColor;
  }
  .report table {
    margin-bottom: 6pt;
  }
}

/* Settings */
.success-text {
  color: var(--pico-ins-color);
}
.grow {
  flex: 1 1 12rem;
}
.new-token {
  border-left: 4px solid var(--bp-normal);
}
.token-input {
  flex: 1 1 16rem;
  font-family: var(--pico-font-family-monospace);
  font-size: 0.85rem;
}
