/* Apothecount stylesheet. Mobile first; one column; no scripts.
   Tokens live on :root and are redefined for dark mode. */

@font-face {
  font-family: "Atkinson Hyperlegible";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/atkinson-hyperlegible-latin-400-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Atkinson Hyperlegible";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("fonts/atkinson-hyperlegible-latin-700-normal.woff2") format("woff2");
}

:root {
  color-scheme: light dark;

  --paper: #EDF2F1;
  --sheet: #FFFFFF;
  --sheet-quiet: #F6F9F8;
  --ink: #14343B;
  --ink-2: #4E6469;
  --ink-3: #6B8085;
  --foil: #D5DFE0;
  --line: #D9E3E4;
  --focus: #228B65;

  --ok: #228B65;
  --ok-text: #176B4D;
  --warn: #CF7D00;
  --warn-text: #8A5300;
  --late: #A11F2F;
  --late-text: #8E1B29;
  --neutral: #4E6469;
  --neutral-text: #14343B;

  --radius-sheet: 20px;
  --radius-control: 12px;
  --radius-cell: 4px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0E1B1F;
    --sheet: #17292E;
    --sheet-quiet: #132327;
    --ink: #E9F1F1;
    --ink-2: #A9BBBE;
    --ink-3: #7F9296;
    --foil: #2A3F45;
    --line: #2C4248;
    --focus: #5AD1A0;

    --ok: #2FA57A;
    --ok-text: #5AD1A0;
    --warn: #BF8720;
    --warn-text: #E3A93A;
    --late: #D54D4E;
    --late-text: #F08A85;
    --neutral: #A9BBBE;
    --neutral-text: #E9F1F1;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: var(--paper);
  color: var(--ink);
  font-family: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 1.0625rem;
  line-height: 1.5;
}

a {
  color: inherit;
}

.top,
main {
  width: min(100% - 2rem, 34rem);
  margin-inline: auto;
}

main {
  padding-bottom: 3rem;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Header: wordmark and navigation. */

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.25rem 0 0.75rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--ink);
  text-decoration: none;
  font-weight: 700;
  font-size: 1.25rem;
  letter-spacing: -0.01em;
}

.brand-mark {
  width: 1.5rem;
  height: 1.5rem;
  flex: none;
}

.brand-mark .pack {
  fill: var(--ink);
}

.brand-mark .cell-dot {
  fill: var(--paper);
}

.brand-mark .popped {
  fill: none;
  stroke: var(--paper);
  stroke-width: 1.2;
}

.nav {
  display: flex;
  gap: 0.25rem;
}

.nav a {
  padding: 0.4rem 0.7rem;
  border-radius: 999px;
  text-decoration: none;
  font-weight: 700;
  font-size: 0.9375rem;
  color: var(--ink-2);
}

.nav a[aria-current="page"] {
  color: var(--ink);
  background: var(--sheet);
}

.today {
  margin: 0.5rem 0 0;
  color: var(--ink-2);
  font-size: 0.9375rem;
}

/* Hero: the one sentence the page exists to say. */

.hero {
  padding: 0.5rem 0 1.5rem;
}

.hero h1,
.empty h1,
.page-title,
.sheet h1 {
  margin: 0;
  font-size: clamp(1.625rem, 6vw, 2.125rem);
  line-height: 1.15;
  letter-spacing: -0.015em;
  font-weight: 700;
  text-wrap: balance;
  max-width: 22ch;
}

.page-title {
  margin: 0.75rem 0 1rem;
}

.hero p,
.empty p,
.lede {
  margin: 0.75rem 0 0;
  color: var(--ink-2);
  max-width: 44ch;
}

.section-title {
  margin: 2rem 0 0.75rem;
  font-size: 1.125rem;
  color: var(--ink-2);
}

/* Messages. */

.flash,
.alert {
  margin: 0.75rem 0 1rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-control);
  background: var(--sheet);
  border-left: 4px solid var(--ok);
}

.alert {
  border-left-color: var(--late);
}

/* Sheets: the white blocks everything sits on. */

.sheet {
  background: var(--sheet);
  border-radius: var(--radius-sheet);
  padding: 1.125rem 1.125rem 1rem;
  margin-top: 0.75rem;
}

.sheet.quiet {
  background: var(--sheet-quiet);
}

.sheet.narrow {
  max-width: 26rem;
  margin: 1.5rem auto 0;
}

.sheet h2 {
  margin: 0 0 0.75rem;
  font-size: 1.125rem;
}

.sheet h1 + .stack,
.sheet h1 + .lede {
  margin-top: 1rem;
}

.muted {
  color: var(--ink-2);
}

.note {
  margin: 1.5rem 0 0;
  max-width: 46ch;
  font-size: 0.9375rem;
  color: var(--ink-3);
}

.sub {
  display: block;
  font-size: 0.9375rem;
  color: var(--ink-2);
}

/* The list of medications. */

.meds {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.75rem;
}

.med {
  background: var(--sheet);
  border-radius: var(--radius-sheet);
  padding: 1.125rem 1.125rem 1rem;
}

[data-urgency="fine"] {
  --status: var(--ok);
  --status-text: var(--ok-text);
}

[data-urgency="order-now"] {
  --status: var(--warn);
  --status-text: var(--warn-text);
}

[data-urgency="late"] {
  --status: var(--late);
  --status-text: var(--late-text);
}

[data-urgency="ordered"],
[data-urgency="paused"],
[data-urgency=""] {
  --status: var(--neutral);
  --status-text: var(--neutral-text);
}

.med-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.med-name {
  margin: 0;
  font-size: 1.25rem;
  line-height: 1.25;
  font-weight: 700;
}

.med-name a {
  text-decoration: none;
}

.med-name a:hover {
  text-decoration: underline;
}

.strength {
  font-weight: 400;
  color: var(--ink-2);
}

.med-dose {
  margin: 0.25rem 0 0;
  color: var(--ink-2);
}

.med-error {
  margin: 0.5rem 0 0;
  color: var(--late-text);
}

/* Status chip: icon, word and colour together, never colour alone. */

.chip {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  margin-top: 0.1rem;
  padding: 0.25rem 0.65rem 0.25rem 0.5rem;
  border-radius: 999px;
  font-size: 0.875rem;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  color: var(--status-text);
  background: color-mix(in oklab, var(--status) 14%, var(--sheet));
}

.chip-icon {
  width: 1rem;
  height: 1rem;
  flex: none;
}

/* The blister strip: one cell a week of the horizon, filled from the
   left with the supply that is left; the mark is the point to order.
   Cells are tiny SVGs so their fill needs no inline style. */

.strip {
  position: relative;
  display: flex;
  gap: 3px;
  margin-top: 1rem;
  padding: 6px 0;
}

.strip .cell {
  flex: 1;
  height: 16px;
  display: block;
  border-radius: var(--radius-cell);
  background: var(--foil);
  overflow: hidden;
}

.strip .cell rect {
  fill: var(--status);
}

.strip .mark-layer {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.strip .mark-layer line {
  stroke: var(--ink);
  stroke-width: 2px;
}

.strip-caption {
  margin: 0.25rem 0 0;
  font-size: 0.9375rem;
  color: var(--ink-2);
}

.strip-caption strong,
.facts strong {
  color: var(--ink);
}

.facts {
  list-style: none;
  margin: 0.875rem 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem 1rem;
  font-size: 1rem;
  line-height: 1.35;
  color: var(--ink-2);
}

.facts strong {
  white-space: nowrap;
}

/* Details and history on a medication's page. */

.details {
  margin: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem 1rem;
}

.details div {
  display: flex;
  flex-direction: column;
}

.details dt {
  font-size: 0.9375rem;
  color: var(--ink-2);
}

.details dd {
  margin: 0;
  font-weight: 700;
}

.notes {
  margin-top: 0.75rem;
  color: var(--ink-2);
}

.notes p {
  margin: 0 0 0.5rem;
}

.history {
  list-style: none;
  margin: 0;
  padding: 0;
}

.history li {
  display: grid;
  grid-template-columns: 6.5rem 1fr auto;
  gap: 0.5rem;
  padding: 0.6rem 0;
  border-top: 1px solid var(--line);
  align-items: baseline;
}

.history .when {
  color: var(--ink-2);
  white-space: nowrap;
}

.history .tools a {
  font-size: 0.9375rem;
  color: var(--ink-2);
}

/* Forms. */

.stack {
  display: grid;
  gap: 1rem;
}

.stack > h2,
.stack > p {
  margin: 0;
}

details.danger-zone summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--ink-2);
}

details.danger-zone[open] summary {
  margin-bottom: 0.75rem;
}

.row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  gap: 1rem;
}

.field label {
  display: block;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.hint {
  margin: 0 0 0.4rem;
  font-size: 0.9375rem;
  color: var(--ink-2);
}

.error {
  margin: 0.35rem 0 0;
  font-size: 0.9375rem;
  color: var(--late-text);
  font-weight: 700;
}

input:not([type="checkbox"]):not([type="radio"]),
textarea,
select {
  width: 100%;
  min-height: 2.9rem;
  padding: 0.55rem 0.8rem;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-control);
  background: var(--sheet);
  color: var(--ink);
  font: inherit;
}

textarea {
  resize: vertical;
}

.is-invalid input,
.is-invalid textarea {
  border-color: var(--late);
}

input[type="checkbox"] {
  width: 1.4rem;
  height: 1.4rem;
  margin: 0;
  accent-color: var(--ok);
}

.actions {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  margin-top: 0.25rem;
}

.actions.wrap {
  flex-wrap: wrap;
  margin-top: 1rem;
}

.inline {
  display: inline;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.9rem;
  padding: 0.55rem 1.1rem;
  border-radius: var(--radius-control);
  border: 1.5px solid var(--line);
  background: var(--sheet);
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

.btn-primary {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
}

.btn-quiet {
  border-color: transparent;
  background: transparent;
  color: var(--ink-2);
}

.btn-danger {
  border-color: var(--late);
  color: var(--late-text);
}

.danger-zone {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}

/* The order screen. */

.order-lines {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.5rem;
}

.order-line {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: flex-start;
  background: var(--sheet);
  border-radius: var(--radius-sheet);
  padding: 0.9rem 1rem;
}

.order-line.is-on-order {
  opacity: 0.7;
}

.tick {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  flex: 1;
  cursor: pointer;
}

.tick input {
  margin-top: 0.2rem;
}

.packs {
  flex: none;
  width: 6.5rem;
  text-align: right;
}

.packs input {
  min-height: 2.5rem;
  text-align: right;
}

.message {
  margin: 0.5rem 0 1rem;
  padding: 1rem;
  border-radius: var(--radius-control);
  background: var(--sheet-quiet);
  font: inherit;
  font-size: 1rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.orders {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.75rem;
}

.order-row p {
  margin: 0.4rem 0 0;
}

.order-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
}

.order-head p {
  margin: 0;
}

/* Empty state. */

.empty {
  padding: 2rem 0;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.95em;
  padding: 0.1em 0.35em;
  border-radius: 6px;
  background: var(--sheet);
}

/* Keyboard focus. */

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
  border-radius: 6px;
}

input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline-offset: 0;
  border-color: var(--focus);
}

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

/* A little more air on larger screens. */

@media (min-width: 40rem) {
  .top {
    padding-top: 2rem;
  }

  .hero {
    padding: 0.75rem 0 2rem;
  }

  .med,
  .sheet {
    padding: 1.375rem 1.5rem 1.25rem;
  }

  .details {
    grid-template-columns: 1fr 1fr 1fr;
  }
}
