/* Styles, light and dark themes. The print stylesheet arrives with the consultation screen. */

:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --surface: #eef0f3;
  --text: #101418;
  --muted: #454d56;
  --line: #737c86;
  --divider: #cdd2d8;
  --accent: #1c3f5e;
  --on-accent: #ffffff;
  --fill: #c3d3e2;
  --error: #9b1c1c;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101418;
    --surface: #1d242b;
    --text: #f2f4f6;
    --muted: #b4bec8;
    --line: #828d99;
    --divider: #333c45;
    --accent: #a9cdee;
    --on-accent: #0b1926;
    --fill: #31495e;
    --error: #ffaaa3;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
.invisible { visibility: hidden; }

html {
  /* Pull-to-refresh would throw away an unsaved entry. */
  overscroll-behavior-y: none;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.25 system-ui, Roboto, sans-serif;
}

#app {
  max-width: 480px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

button {
  min-width: 44px;
  min-height: 44px;
  margin: 0;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

button:disabled {
  opacity: 0.4;
  cursor: default;
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* Header */

.day-header {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 56px;
  padding: 4px 12px;
  border-bottom: 1px solid var(--divider);
}

.day-title { flex: 1; text-align: center; }
.day-title h1 { margin: 0; font-size: 19px; }
.relative { display: block; color: var(--muted); font-size: 13px; }
.nav { border: 0; font-size: 28px; }

.notice {
  margin: 8px 12px 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.notice span { display: block; }
.link { border: 0; padding: 0; text-decoration: underline; font-weight: 600; }

/* Fields */

main { flex: 1; }
.entry-form { padding: 0 12px 8px; }
.field { padding: 4px 0; border-bottom: 1px solid var(--divider); }
.label { font-weight: 600; }

.field-head {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 44px;
}

.field-head .label { margin-right: auto; }

.value {
  min-width: 40px;
  text-align: center;
  font-size: 26px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.value.empty { color: var(--muted); font-weight: 400; }

/* Must never look like an entered value. */
.hint {
  border-style: dashed;
  color: var(--muted);
  font-size: 14px;
  font-style: italic;
  white-space: nowrap;
}

.clear { border: 0; color: var(--muted); font-size: 24px; padding: 0; }
.help { border: 0; color: var(--muted); text-decoration: underline; }
.bristol .label { margin-right: 0; }
.bristol .help { margin-right: auto; }

.dose-line {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 48px;
  padding: 0;
  border: 0;
  text-align: left;
}

.dose-name { flex: 1; }
.dose-source { display: block; color: var(--muted); font-size: 13px; }
.dose-value { font-size: 24px; }
.dose-action { color: var(--muted); text-decoration: underline; }

.dose-options {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  padding: 6px 0;
}

.dose-options button { padding: 0 2px; }
.dose-options button:last-child { font-size: 14px; }

.dose-question,
.toggles {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.dose-question { padding: 6px 0; }
.field.toggles { padding: 8px 0; }

.counter {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) 44px 40px 44px 44px;
  align-items: center;
  gap: 2px;
  min-height: 56px;
}

.hint-slot .hint { padding: 0 4px; }
.step { font-size: 24px; padding: 0; }

.bristol-options {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  padding: 6px 0 4px;
}

.bristol-options button { padding: 2px; }
.bristol-options strong { display: block; font-size: 18px; }
.bristol-options small { display: block; font-size: 13px; }
.bristol-help { margin: 0 0 8px; padding-left: 24px; color: var(--muted); font-size: 14px; }

.track {
  display: flex;
  height: 44px;
  /* Keeps « hier : n » from touching the track just below it. */
  margin: 6px 0 4px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
  /* Vertical gestures scroll the page, horizontal ones move the slider. */
  touch-action: pan-y;
  user-select: none;
}

.track span {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  pointer-events: none;
}

.track.is-empty { border-style: dashed; background: transparent; color: var(--muted); }
.track .filled { background: var(--fill); }
.track .thumb { background: var(--accent); color: var(--on-accent); font-size: 17px; font-weight: 700; }

/* Selected states carry a mark or a weight, never colour alone. */
.option[aria-pressed="true"],
.toggle[aria-pressed="true"] {
  border: 2px solid var(--accent);
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 700;
}

.toggle { padding: 4px; font-size: 15px; line-height: 1.15; }
.toggle[aria-pressed="true"]::before { content: "✓ "; }
.toggle small { display: block; font-size: 12px; }

/* Folded sections */

.fold { border-bottom: 1px solid var(--divider); }

.fold summary {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  list-style: none;
  cursor: pointer;
  font-weight: 600;
}

.fold summary::-webkit-details-marker { display: none; }
.fold summary::after { content: "▾"; margin-left: auto; color: var(--muted); }
.fold[open] > summary::after { content: "▴"; }
.count { color: var(--muted); font-weight: 400; }

fieldset { min-width: 0; margin: 0 0 12px; padding: 0; border: 0; }
legend { padding: 4px 0; color: var(--muted); font-size: 14px; }

textarea {
  width: 100%;
  margin-bottom: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: inherit;
  font: inherit;
  resize: vertical;
}

/* Save bar */

.save-bar {
  position: sticky;
  bottom: 0;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--divider);
  background: var(--bg);
}

.status { margin: 0; text-align: center; font-weight: 600; }
.status:not(:empty) { padding-bottom: 6px; }
.status.error { color: var(--error); }

.save {
  width: 100%;
  min-height: 48px;
  border: 0;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 18px;
  font-weight: 700;
}

.blocked { padding: 16px; }
