/* ---------- cards ---------- */
.card {
  position: relative;
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.card.error {
  border-color: var(--danger);
}
.input[aria-invalid='true'] {
  border-color: var(--danger);
  background: var(--danger-soft);
}
.card-title {
  font-size: 1.05rem;
  margin-bottom: 4px;
}
.card-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.card-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}
.card-link {
  display: block;
  color: inherit;
  text-decoration: none;
}
.card-link:hover {
  border-color: var(--border-strong);
}
.stack > * + * {
  margin-top: 12px;
}
.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin-top: 4px;
}
.notes {
  color: var(--text-2);
  margin: 10px 0 0;
}
/* Notes with light markdown (notesBlock): headings, lists, bold, italic. */
.md {
  overflow-wrap: anywhere;
}
.md p,
.md ul,
.md ol,
.md h4 {
  margin: 0;
}
.md > * + * {
  margin-top: 6px;
}
.md ul,
.md ol {
  padding-left: 1.4em;
}
.md li + li,
.md li > ul,
.md li > ol {
  margin-top: 2px;
}
.md h4 {
  font-size: 1em;
  font-weight: 700;
  line-height: 1.3;
}
.md .md-h1 {
  font-size: 1.15em;
}
.md .md-h2 {
  font-size: 1.05em;
}
.md > h4:not(:first-child) {
  margin-top: 10px;
}
.md-hint {
  margin: 4px 0 0;
}
.row {
  display: flex;
  align-items: center;
}
.gap {
  gap: 8px;
}
.wrap {
  flex-wrap: wrap;
}
.center {
  justify-content: center;
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 8px 16px;
  border-radius: 999px;
  border: 2px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font: 600 0.92rem/1.2 var(--font);
  transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1), background-color 0.15s;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  touch-action: manipulation;
}
.btn:hover {
  background: var(--surface-2);
}
/* A springy squish on press. */
.btn:active:not(:disabled),
.icon-btn:active:not(:disabled),
.chip-btn:active,
.chip-toggle:active,
.rail-btn:active,
.top-action:active {
  transform: scale(0.94);
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn-primary {
  background: var(--btn-primary);
  border-color: var(--line);
  color: var(--btn-primary-ink);
}
.btn-primary:hover {
  background: var(--btn-primary-hover);
}
.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}
.btn-danger:hover {
  background: var(--danger);
  filter: brightness(0.95);
}
.btn-danger-text {
  color: var(--danger);
}
.btn-text {
  border-color: transparent;
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
  /* Without this the thick underline breaks around descenders like the g in "Regimen". */
  text-decoration-skip-ink: none;
  background: transparent;
  color: var(--accent);
}
.btn-sm {
  min-height: 34px;
  padding: 5px 10px;
  font-size: 0.85rem;
}
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 999px;
  border: 0;
  transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
}
.icon-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}
.icon-btn:disabled {
  opacity: 0.3;
}
.icon {
  flex-shrink: 0;
}
.chip-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  border-radius: 999px;
  border: 2px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-2);
  font: 500 0.82rem var(--font);
  cursor: pointer;
  transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.chip-btn:hover {
  color: var(--text);
  border-color: var(--line);
}

/* segmented */
.segmented {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 3px;
  border-radius: 22px;
  background: var(--surface-2);
  border: 2px solid var(--border-strong);
  max-width: 100%;
}
.segmented button {
  border: 0;
  background: transparent;
  color: var(--text-2);
  font: 550 0.84rem var(--font);
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}
.segmented button.on {
  background: var(--flag-blue);
  color: var(--on-blue);
}
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

/* ---------- badges / pills / chips ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 550;
  background: var(--surface-2);
  color: var(--text-2);
  white-space: nowrap;
}
.badge-hrt {
  background: var(--flag-pink);
  color: var(--on-pink);
}
.badge-pre {
  background: var(--pre-soft);
  color: var(--pre);
}
.pill {
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 600;
  margin-top: 4px;
}
.pill-ok {
  background: var(--ok-soft);
  color: var(--ok);
}
.pill-warn {
  background: var(--warn-soft);
  color: var(--warn);
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.82rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.chip-warn {
  background: var(--warn-soft);
  color: var(--warn);
}
.chip-x {
  border: 0;
  background: none;
  color: inherit;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0 2px;
}
.extras {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

/* ---------- forms ---------- */
.form > * + *,
.form fieldset > * + * {
  margin-top: 12px;
}
fieldset {
  border: 0;
  padding: 0;
  margin: 0;
  min-width: 0;
}
/* Floated legends sit inside the fieldset box instead of breaking its top border. */
legend {
  float: left;
  width: 100%;
  font-weight: 650;
  font-size: 0.95rem;
  padding: 0;
  margin-bottom: 4px;
  color: var(--text);
}
/* Every sibling, not just the next one: a hidden element (e.g. a <datalist>) can sit right after the legend. */
legend ~ * {
  clear: both;
}
.form fieldset > legend + * {
  margin-top: 0;
}
.form fieldset + fieldset {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}
.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}
.label {
  font-size: 0.86rem;
  font-weight: 550;
  color: var(--text-2);
}
.hint {
  font-size: 0.82rem;
  color: var(--muted);
  margin: 0;
}
.field-error {
  color: var(--danger);
  font-size: 0.85rem;
  margin: 0;
}
.input {
  width: 100%;
  min-height: 42px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font: 16px/1.3 var(--font); /* 16px stops iOS zoom-on-focus */
  min-width: 0;
}
textarea.input {
  resize: vertical;
}
select.input {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 32px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
}
.input:focus {
  border-color: var(--line);
  outline: 3px solid var(--flag-blue);
  outline-offset: 0;
}
input[type='date'].input,
input[type='datetime-local'].input,
input[type='time'].input {
  min-height: 42px;
  /* iOS Safari gives date inputs an intrinsic width that ignores width: 100%, so they
     ran past the right edge of dialogs on iPhone, and it centers their text. */
  min-width: 0;
  max-width: 100%;
  -webkit-appearance: none;
  appearance: none;
}
input[type='date'].input::-webkit-date-and-time-value,
input[type='datetime-local'].input::-webkit-date-and-time-value,
input[type='time'].input::-webkit-date-and-time-value {
  text-align: left;
}
.input-unit {
  width: auto;
  min-width: 96px;
  flex: 0 0 auto;
}
.input-n {
  width: 70px;
  flex: 0 0 70px;
}
.grid-2,
.grid-3 {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr;
}
@media (min-width: 560px) {
  .grid-2 {
    grid-template-columns: 1fr 1fr;
  }
  .grid-3 {
    grid-template-columns: repeat(3, 1fr);
  }
}
.grid-2.tight {
  grid-template-columns: 1fr auto;
  align-items: end;
}
.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}
/* In a form, one per line (two in a row ran together), only as wide as the label. */
.form fieldset > .check {
  display: flex;
  width: fit-content;
}
input[type='checkbox'] {
  /* flex: none so a wrapping label can't squeeze the box narrower than its neighbors. */
  flex: none;
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--accent);
}
.quick {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.computed {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}
.computed-item {
  background: var(--accent-soft);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
}
.computed-item.warn {
  background: var(--warn-soft);
  color: var(--warn);
}
.computed-item strong {
  font-size: 1rem;
}

/* analyte rows */
.analyte {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.analyte:last-of-type {
  border-bottom: 0;
}
.analyte-label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
}
.analyte-inputs {
  display: flex;
  gap: 8px;
}
.analyte-inputs .input:first-child {
  flex: 1;
  font-variant-numeric: tabular-nums;
}
.conv {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  align-items: center;
  font-size: 0.85rem;
  color: var(--text-2);
  margin-top: 6px;
  min-height: 0;
}
.conv:empty {
  display: none;
}
.conv .pill {
  margin-top: 0;
}
.analyte-more {
  margin-top: 8px;
}
.analyte-more summary,
details.method summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.85rem;
}
.analyte-more[open] summary {
  margin-bottom: 8px;
}

/* extra labs + meds */
.extra-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 8px 0;
  border-bottom: 1px dashed var(--border);
  position: relative;
}
.extra-row .icon-btn {
  position: absolute;
  right: -8px;
  top: 4px;
}
.extra-row > :first-child {
  grid-column: 1 / -1;
  margin-right: 36px;
}
@media (min-width: 700px) {
  .extra-row {
    grid-template-columns: 2fr 1fr 1fr 1fr 1fr 40px;
    border-bottom: 0;
    padding: 4px 0;
  }
  .extra-row > :first-child {
    grid-column: auto;
    margin-right: 0;
  }
  .extra-row .icon-btn {
    position: static;
  }
}
.med-row {
  display: grid;
  grid-template-columns: 1fr 40px;
  gap: 4px 8px;
  padding: 12px;
  border-radius: 12px;
  background: var(--surface-2);
  margin-bottom: 8px;
}
.med-cat {
  grid-column: 1;
  font-size: 0.78rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.med-row .icon-btn {
  grid-column: 2;
  grid-row: 1 / span 2;
}
.med-fields {
  grid-column: 1;
  display: grid;
  gap: 6px;
  grid-template-columns: 1fr;
}
@media (min-width: 480px) {
  .med-fields {
    grid-template-columns: 1fr 1fr;
  }
}
.dose {
  display: flex;
  gap: 6px;
  min-width: 0;
}
.dose > .input:first-child {
  flex: 1 1 auto;
  min-width: 64px;
}
.dose > .input-unit {
  min-width: 84px;
}
.meds {
  display: grid;
  gap: 6px;
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
  font-size: 0.92rem;
}
.meds li {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
.med-route {
  flex: none;
  width: 18px;
  height: 18px;
  margin-top: 1px;
  color: var(--muted);
}
/* Details wrap under the name, not under the icon. */
.med-text {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  column-gap: 8px;
}
.med-name {
  font-weight: 600;
}
.med-detail {
  color: var(--muted);
}

/* ratings */
.rating-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.rating-value {
  min-width: 2ch;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: center;
}
.rating-scale {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--muted);
}
/* Unrated: the thumb has to sit somewhere, so it's grey, not a colored fill that reads as a 5. */
.rating.unset .range {
  accent-color: var(--muted);
  opacity: 0.6;
}
.range {
  flex: 1;
  accent-color: var(--accent);
  min-height: 32px;
}
.change-list {
  display: grid;
  gap: 10px;
}
@media (min-width: 760px) {
  .change-list {
    grid-template-columns: 1fr 1fr;
  }
}
.change-item {
  background: var(--surface-2);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.change-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.ratings {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  margin: 12px 0 0;
}
.rating-item dt {
  font-size: 0.82rem;
  color: var(--text-2);
}
.rating-item dd {
  margin: 2px 0 0;
}
/* A 0–10 rating: a bar, with the number beside it (inside, it sank below the bar's middle
   and was hard to read on the fill or past a short one). */
.meter-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.meter {
  --v: 0;
  flex: 1;
  position: relative;
  height: 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  overflow: hidden;
}
.meter::before {
  content: '';
  position: absolute;
  inset: 0 auto 0 0;
  width: calc(var(--v) * 10%);
  background: var(--accent);
  border-radius: 999px;
}
.meter-num {
  flex: none;
  min-width: 4ch;
  text-align: right;
  font-size: 0.8rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  color: var(--text-2);
}
.rating-note {
  display: block;
  font-size: 0.85rem;
  color: var(--text-2);
  margin-top: 2px;
}

/* chips select (hair areas) */
.chip-select {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}
.chip-toggle {
  padding: 6px 12px;
  border-radius: 999px;
  border: 2px solid var(--border-strong);
  transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
  background: var(--surface);
  color: var(--text-2);
  font: 500 0.85rem var(--font);
  cursor: pointer;
}
.chip-toggle.on {
  background: var(--flag-blue);
  border-color: var(--flag-blue);
  color: var(--on-blue);
}

