html { font-size: var(--font-size-base); }

body {
  /* a long word breaks instead of widening the page (zoom 200 % on a small phone, WCAG 1.4.10) */
  overflow-wrap: anywhere;
  font-family: var(--font-family);
  background-color: var(--color-bg);
  color: var(--color-text);
}

a, button, .btn, input, select, textarea { min-height: var(--tap-size); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--tap-size);
  padding: var(--space-2) var(--space-4);
}

.btn-primary {
  --bs-btn-bg: var(--color-primary);
  --bs-btn-border-color: var(--color-primary);
  --bs-btn-hover-bg: #163d6b;
  --bs-btn-hover-border-color: #163d6b;
}

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

.env-banner {
  background-color: var(--color-banner-bg);
  color: var(--color-banner-text);
  border-bottom: 1px solid var(--color-banner-border);
  padding: var(--space-2) var(--space-4);
  text-align: center;
  font-weight: 600;
}

.app-main { padding-top: var(--space-6); padding-bottom: var(--space-8); }

.skip-link {
  position: absolute;
  left: var(--space-2);
  top: -100px;
  z-index: 10;
  padding: var(--space-2) var(--space-4);
  background: var(--color-bg);
  color: var(--color-primary);
  border: 2px solid var(--color-primary);
}
.skip-link:focus { top: var(--space-2); }

.setup-steps > li { margin-bottom: var(--space-4); }
.qr-box { margin: var(--space-3) 0; padding: var(--space-3); background: #ffffff; display: inline-block; }
.qr-code { max-width: 100%; height: auto; display: block; }
.recovery-codes { list-style: none; padding: 0; columns: 2; font-size: 1.1rem; }
.recovery-codes li { margin-bottom: var(--space-2); }
.recovery-codes code { color: var(--color-text); }

@media print {
  .env-banner, .skip-link, #recovery-actions, .btn, .form-text { display: none; }
}

/* Grid and chart of the nights (SVG from the server; classes, never inline styles: CSP) */
.nights-figure { margin: 0 0 var(--space-6); }
.nights-svg { width: 100%; height: auto; display: block; background: #ffffff; }
.nights-svg text { font-family: var(--font-family); font-size: 11px; fill: var(--color-text); }
.nights-svg .axis-line { stroke: var(--night-axis); stroke-width: 1; }
.nights-svg .row-frame { fill: #ffffff; stroke: var(--night-border); stroke-width: 0.75; }
.nights-svg .row-missing { fill: #eceef1; stroke: var(--night-border); stroke-width: 0.75; }
.nights-svg .st-sleep { fill: var(--night-sleep); }
.nights-svg .st-awake, .nights-svg .st-untimed { fill: var(--night-awake); }
.nights-svg .st-other { fill: var(--night-other); }
.nights-svg .chart-line { fill: none; stroke: var(--chart-line); stroke-width: 2; }
.nights-svg .chart-dot { fill: var(--chart-line); }
.nights-svg .chart-col { fill: transparent; }
.nights-svg .chart-col:focus { outline: 2px solid var(--color-focus); }
.legend { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-6); }
.legend-swatch { display: inline-block; width: 1.25rem; height: 0.9rem; vertical-align: middle;
  margin-right: var(--space-2); border: 1px solid var(--night-border); }
.legend-swatch.st-sleep { background: var(--night-sleep); }
.legend-swatch.st-awake { background: var(--night-awake); }
.legend-swatch.st-other { background: var(--night-other); }
.legend-swatch.st-out { background: #ffffff; }
.nights-table td, .nights-table th { vertical-align: top; }
.nights-table .row-missing-text { color: #5a6068; background: #eceef1; }
.markers { margin: 0; padding-left: 1.1rem; }
.period-nav { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-4); align-items: center; margin-bottom: var(--space-4); }
.averages dt { font-weight: 600; }

/* Patient access (L1.4) */
.draft-label { font-weight: 600; }
.invite-steps > li { margin-bottom: var(--space-3); font-size: 1.1rem; }
.invite-address { font-family: var(--font-mono, monospace); word-break: break-all; }
.invite-sheet { max-width: 40rem; }
@media print {
  .invite-sheet { max-width: none; }
  .invite-sheet .qr-box { border: 1px solid #000; }
}

/* --- Diary of the patient (L1.5-2): ported from the spike; classes only (CSP) --- */
.dq-title {
  font-size: 1.25rem;
}

.dq-progress {
  width: 100%;
  height: var(--space-3);
}

.dq-progress-text,
.dq-estimate {
  margin-bottom: var(--space-1);
}

.dq-estimate {
  color: #57606a;
}

.dq {
  margin-top: var(--space-4);
}

.dq-question {
  font-size: 1.375rem;
  margin-bottom: var(--space-4);
}

.dq-question:focus {
  outline: none;
}

.dq-choices {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
  border: 0;
  padding: 0;
}

.dq-choice {
  min-width: calc(var(--tap-size) * 1.5);
}

/* Scales with a label on every value (D-151 B4): one button under the other. */
.dq-choices-stack {
  flex-direction: column;
  max-width: 28rem;
}

.dq-wide {
  width: 100%;
  max-width: 28rem;
  margin-bottom: var(--space-3);
}

.dq-label {
  display: block;
  margin-bottom: var(--space-2);
  font-weight: 600;
}

.dq-count {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.dq-count-value {
  min-width: 5ch;
  font-family: var(--bs-font-monospace);
  font-size: 2rem;
  font-weight: 700;
  text-align: center;
}

/* Single time picker (D-138): a box that opens a modal dialog; tap areas >= 48 px. */
.dq-tp {
  margin-bottom: var(--space-3);
}

/* Optional times: "Non ricordo" beside the box, wrapping below it on narrow screens (D-143). */
.dq-tp-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

/* Switch between single awakenings and total duration: apart from the other commands (D-143). */
.dq-switch {
  margin-top: var(--space-8);
  padding-top: var(--space-4);
  border-top: 1px solid #d0d7de;
}

/* D-151 A1: never wider than its container (zoom 200%, 320 px). */
.dq-tp-box {
  min-height: calc(var(--tap-size) * 1.25);
  min-width: min(14rem, 100%);
  max-width: 100%;
  text-align: left;
}

.dq-tp-value {
  overflow-wrap: anywhere;
  font-family: var(--bs-font-monospace);
  font-size: 2rem;
  font-weight: 700;
}

.dq-tp-empty .dq-tp-value {
  font-family: inherit;
  font-size: 1.125rem;
  font-weight: 600;
}

.dq-tp-dialog {
  width: min(32rem, calc(100vw - 2 * var(--space-3)));
  max-height: calc(100vh - 2 * var(--space-3));
  overflow-y: auto;
  padding: var(--space-4);
  border: 1px solid var(--bs-border-color);
  border-radius: var(--bs-border-radius-lg);
  background: var(--bs-body-bg);
  color: var(--bs-body-color);
}

.dq-tp-dialog::backdrop {
  background: rgb(0 0 0 / 0.5);
}

.dq-tp-title {
  margin-bottom: var(--space-2);
  font-size: 1.25rem;
  font-weight: 700;
}

.dq-tp-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-4);
}

.dq-tp-step {
  margin: var(--space-3) 0 var(--space-2);
  font-weight: 600;
}

.dq-tp-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(calc(var(--tap-size) * 1.25), 1fr));
  gap: var(--space-2);
  max-width: 28rem;
}

.dq-tp-btn {
  min-height: var(--tap-size);
  font-family: var(--bs-font-monospace);
  /* ":30" broke between "3" and "0" on a real Android phone (Nokia, Brave, 24/11/2026):
     Bootstrap 5 buttons wrap, and the phone's monospace font is wider than in CI. */
  white-space: nowrap;
  padding-inline: var(--space-1);
}

.dq-tp-other {
  grid-column: 1 / -1;
  font-family: inherit;
}

/* Quick minutes over the limit (D-134): visibly unavailable, still focusable for the message. */
.dq-over {
  border-style: dashed;
  opacity: 0.55;
}

.dq-limit {
  margin-top: var(--space-2);
}

.dq-more input {
  max-width: 10rem;
}

.dq-row {
  margin-bottom: var(--space-4);
  padding: var(--space-3);
  border: 1px solid #d0d7de;
  border-radius: var(--space-2);
}

.dq-row-title {
  font-size: 1rem;
  font-weight: 700;
}

.dq-fixed {
  margin-top: var(--space-4);
  padding: var(--space-3);
  border-left: 4px solid var(--color-primary);
  background-color: #f6f8fa;
}

.dq-error {
  color: #a40e26;
  font-weight: 600;
}

.dq-nav {
  display: flex;
  flex-wrap: wrap; /* three buttons in correction mode (D-148): they wrap at 320 px */
  justify-content: space-between;
  gap: var(--space-3);
  margin-top: var(--space-6);
  max-width: 28rem;
}

.dq-nav .btn {
  flex: 1 1 7rem;
}

.dq-sum-row {
  padding: var(--space-2) 0;
  border-bottom: 1px solid #d0d7de;
}

.dq-sum dd {
  margin-bottom: 0;
}

.dq-edit {
  min-height: var(--tap-size);
  padding-left: var(--space-2);
}

.dq-warnings {
  margin-bottom: var(--space-4);
  padding: var(--space-3);
  border: 2px solid var(--color-banner-border);
  border-radius: var(--space-2);
}

.dq-warnings-title {
  font-weight: 700;
}


/* --- time line of the night (07 §5.3, D-144): solid colours chosen by luminance, no
   frame, no outlines of the exits; coloured = in bed, white = not in bed. Values and checks
   in PLAN.md P6b. Only the therapist colour of other activities has a light pattern. --- */
.g-figure {
  margin: var(--space-4) 0;
  max-width: 40rem;
}

.g-svg {
  display: block;
  width: 100%;
  height: auto;
}

.g-hour {
  font-size: 11px;
  fill: var(--color-text);
}

.g-tick-h {
  stroke: #57606a;
  stroke-width: 1;
}

.g-tick-m {
  stroke: #afb8c1;
  stroke-width: 1;
}

.g-bar,
.g-out {
  fill: #ffffff;
}

.g-border {
  fill: none;
  stroke: #8c959f;
  stroke-width: 0.75;
}

.g-sleep {
  fill: #16294a;
}

.g-awake {
  fill: #4f96d8;
}

.g-other-p {
  fill: #666666;
}

.g-other-t-bg {
  fill: #e06c66;
}

.g-other-t-line {
  fill: #ffffff;
}

.g-untimed-label {
  margin: var(--space-1) 0 var(--space-3);
  font-size: 1rem;
}

.g-legend,
.g-list {
  padding-left: 0;
  list-style: none;
  font-size: 1rem;
}

.g-legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-4);
}

.g-legend li {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.g-swatch {
  flex: none;
  width: 24px;
  height: 16px;
}

.g-list-title,
.dq-sum-title {
  margin-top: var(--space-4);
  font-size: 1rem;
  font-weight: 700;
}

.dq-confirm {
  margin: var(--space-6) 0 var(--space-4);
}

.dq-confirm .dq-alert .btn {
  margin-top: var(--space-2);
}

.dq-alert {
  padding: var(--space-3) var(--space-4);
  border: 2px solid var(--color-text);
  border-radius: var(--space-2);
  font-weight: 600;
}

.dq-note { margin: var(--space-1) 0; font-size: 1rem; }

/* Bootstrap draws the tick of a checked box and the dot of a radio with a data: image, which the
   policy (img-src 'self') blocks: the same drawings as files (L1.6). */
.form-check-input:checked[type=checkbox] { --bs-form-check-bg-image: url("../img/check.svg"); }
.form-check-input:checked[type=radio] { --bs-form-check-bg-image: url("../img/radio.svg"); }

/* The label of a box or a choice is the area to touch: at least 48 px (RNF-ACS-02). */
.form-check-label { display: inline-flex; align-items: center; min-height: var(--tap-size); }
