/* The Carnet (patients' app): mobile first, light and dark. */
:root {
  --bg: #f4f8fc;
  --surface: #ffffff;
  --border: #dde6ef;
  --text: #1a1a1a;
  --muted: #5d6b7c;
  --primary: #2c74b0;
  --primary-soft: #e4f1fb;
  --primary-ink: #ffffff;
  --danger: #b3261e;
  --danger-bg: #fdecea;
  --ok: #1a7f37;
  --sos-bg: #fff4e5;
  --sos-border: #f3c98b;
  --chart-line: #2c74b0;
  --chart-grid: #e6edf4;
  --chart-text: #5d6b7c;
  --chart-surface: #ffffff;
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1720;
    --surface: #18222e;
    --border: #2a3846;
    --text: #e8eef4;
    --muted: #9aabbd;
    --primary: #6fb1e8;
    --primary-soft: #1d3247;
    --primary-ink: #0b1620;
    --danger: #f2948e;
    --danger-bg: #3a1d1b;
    --ok: #6fcf8a;
    --sos-bg: #2e2416;
    --sos-border: #6b5228;
    --chart-line: #7cb8ea;
    --chart-grid: #263443;
    --chart-text: #9aabbd;
    --chart-surface: #18222e;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
h1 { font-size: 1.2rem; margin: 0; }
h2 { font-size: 1rem; margin: 1.5rem 0 0.6rem; color: var(--muted); font-weight: 600; }
a { color: var(--primary); }
[hidden] { display: none !important; }
button, input, textarea, select { font: inherit; color: inherit; }

.center { max-width: 420px; margin: 0 auto; padding: 2.5rem 16px; }
.center-text { text-align: center; }
.brand { display: flex; flex-direction: column; align-items: center; gap: 0.6rem; margin-bottom: 1.5rem; }
.brand img { border-radius: 16px; }
.page { max-width: 640px; margin: 0 auto; padding: 1rem 16px 3rem; }
.stack { display: flex; flex-direction: column; gap: 0.9rem; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 0.85rem; }
.lead { margin: 0; }
.big { font-size: 2.5rem; margin: 0; color: var(--ok); }

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 0.6rem;
  padding: calc(0.6rem + env(safe-area-inset-top)) 12px 0.6rem;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.top h1 { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top img { border-radius: 8px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 10px; border: 0; background: transparent;
  font-size: 1.8rem; line-height: 1; display: grid; place-items: center; cursor: pointer;
}
.icon-btn svg { fill: none; stroke: currentColor; stroke-width: 2; }
.icon-btn svg rect { fill: currentColor; stroke: none; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin: 0; }
.card.note { border-color: var(--primary); background: var(--primary-soft); }
.card.note p { margin: 0.3rem 0 0; white-space: pre-line; }
fieldset.card { min-width: 0; }
legend { font-weight: 600; padding: 0 0.3rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 46px; padding: 0.6rem 1.1rem; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  text-decoration: none; font-weight: 600; cursor: pointer;
}
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.link { border: 0; background: none; color: var(--muted); font-weight: 400; text-decoration: underline; min-height: 0; margin: 0 auto; display: block; }
.btn.block { display: flex; width: 100%; margin: 0.5rem 0; }
.btn:disabled { opacity: 0.6; }
.actions { display: flex; gap: 0.6rem; flex-wrap: wrap; }
.actions .btn { flex: 1; }

.field { display: flex; flex-direction: column; gap: 0.35rem; }
.field > span, .label { font-weight: 500; }
input[type="text"], input[type="number"], input[type="date"], input[type="time"], input:not([type]), input[type="password"], textarea {
  width: 100%; min-height: 46px; padding: 0.6rem 0.75rem;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface);
}
textarea { resize: vertical; }
input:focus, textarea:focus, button:focus-visible { outline: 3px solid color-mix(in srgb, var(--primary) 45%, transparent); outline-offset: 1px; }
.pin { font-size: 1.6rem; letter-spacing: 0.5em; text-align: center; }
.with-unit { display: flex; align-items: center; gap: 0.5rem; }
.with-unit input { max-width: 10rem; }

.msg { margin: 0; padding: 0.6rem 0.8rem; border-radius: 10px; background: var(--primary-soft); }
.msg.error { background: var(--danger-bg); color: var(--danger); }

/* Segmented choices: scales, yes / no, options */
.seg { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.seg button {
  flex: 1 0 2.6rem; min-height: 44px; padding: 0.4rem 0.5rem;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface); cursor: pointer;
}
.seg button[aria-checked="true"] { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); font-weight: 600; }
.seg.vertical { flex-direction: column; }
.seg.vertical button, .seg.multi button { text-align: left; flex: 0 0 auto; }
.seg.multi button { flex: 1 1 auto; }
.seg.tabs button { flex: 1; }
.q.missing { border-color: var(--danger); }
.q legend { font-weight: 500; margin-bottom: 0.5rem; }
.q .num { color: var(--muted); }

/* Home */
.tiles { display: grid; gap: 0.6rem; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.tile {
  display: flex; flex-direction: column; gap: 0.2rem; padding: 0.9rem 1rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); text-decoration: none;
}
.tile span { color: var(--muted); font-size: 0.9rem; }
.tile small { color: var(--primary); font-size: 0.8rem; margin-top: 0.2rem; }

.sos { background: var(--sos-bg); border: 1px solid var(--sos-border); border-radius: var(--radius); padding: 0.7rem 1rem; }
.sos summary { font-weight: 600; cursor: pointer; }
.sos p { margin: 0.5rem 0; font-size: 0.92rem; }
.sos ul { margin: 0; padding-left: 1.1rem; }
.sos li { margin: 0.25rem 0; }

.list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.45rem; }
.row {
  display: flex; gap: 0.7rem; align-items: center; width: 100%; padding: 0.75rem 0.9rem; text-align: left;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); text-decoration: none; cursor: pointer;
}
.row > span { display: flex; flex-direction: column; min-width: 0; }
.row small { color: var(--muted); font-size: 0.85rem; }
.row .clip { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .bits { display: flex; flex-wrap: wrap; gap: 0 0.8rem; }
.doc-icon { font-size: 1.4rem; }

/* Weight */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.5rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.7rem 0.8rem; display: flex; flex-direction: column; }
.stat small { color: var(--muted); font-size: 0.8rem; }
.stat strong { font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 0.8rem; }
.chart { padding: 0.5rem; }

/* Line chart (chart.js) */
.lc { position: relative; touch-action: pan-y; }
.lc svg { display: block; }
.lc-grid { stroke: var(--chart-grid); stroke-width: 1; }
.lc-axis { fill: var(--chart-text); font-size: 11px; font-variant-numeric: tabular-nums; }
.lc-line { fill: none; stroke: var(--chart-line); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.lc-dot { fill: var(--chart-line); stroke: var(--chart-surface); stroke-width: 2; }
.lc-hot { fill: var(--chart-line); stroke: var(--chart-surface); stroke-width: 2; }
.lc-cross { stroke: var(--chart-text); stroke-width: 1; stroke-dasharray: 3 3; }
.lc-tip {
  position: absolute; pointer-events: none; white-space: nowrap;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 8px;
  padding: 0.3rem 0.55rem; font-size: 0.8rem; box-shadow: 0 2px 8px rgb(0 0 0 / 12%);
  display: flex; flex-direction: column;
}
.lc-tip span { color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: calc(1.2rem + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 0.6rem 1rem; border-radius: 10px; z-index: 20;
  transition: opacity 0.4s; max-width: calc(100% - 32px);
}
.toast.error { background: var(--danger); color: #fff; }
.toast.out { opacity: 0; }
