:root {
  color-scheme: light;
  --bg: #f4f3ef;
  --surface: #fcfcfb;
  --surface-2: #eceae4;
  --border: #dcd9d1;
  --text: #1c1c1a;
  --text-2: #52514e;
  --muted: #7a7873;
  --accent: #2f6f6a;
  --accent-ink: #ffffff;
  --accent-soft: #dcebe8;
  --danger: #b3261e;
  --safety-bg: #fff4e5;
  --safety-border: #e8a33d;
  --grid: #e6e4de;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #6250d6;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #262624;
    --border: #34332f;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #99978f;
    --accent: #5fb3aa;
    --accent-ink: #0d1f1d;
    --accent-soft: #1f3532;
    --danger: #f2817a;
    --safety-bg: #3a2a12;
    --safety-border: #c98500;
    --grid: #2c2b28;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #9085e9;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211;
  --surface: #1a1a19;
  --surface-2: #262624;
  --border: #34332f;
  --text: #f0efec;
  --text-2: #c3c2b7;
  --muted: #99978f;
  --accent: #5fb3aa;
  --accent-ink: #0d1f1d;
  --accent-soft: #1f3532;
  --danger: #f2817a;
  --safety-bg: #3a2a12;
  --safety-border: #c98500;
  --grid: #2c2b28;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #9085e9;
}

* { 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: calc(72px + env(safe-area-inset-bottom));
}
button, input, textarea, select { font: inherit; color: inherit; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
h2 { font-size: 1.05rem; margin-bottom: .2em; }
h3 { font-size: 1rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.error { color: var(--danger); }
[hidden] { display: none !important; }

/* ---- верхняя панель и вкладки ---- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}
.topbar-inner {
  max-width: 680px; margin: 0 auto; padding: 8px 16px;
  display: flex; align-items: center; gap: 8px;
}
.topbar-title { flex: 1; text-align: center; min-width: 0; }
#title { font-weight: 600; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surface);
  font-size: 1.5rem; line-height: 1; cursor: pointer;
}
.icon-btn:disabled { opacity: .3; cursor: default; }
.icon-btn.invisible { visibility: hidden; }

.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: flex; justify-content: center;
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  flex: 1; max-width: 136px; padding: 8px 0 10px;
  border: 0; background: none; color: var(--muted);
  font-size: .75rem; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.tab-ico { font-size: 1.25rem; line-height: 1.2; }
.tabs button.active { color: var(--accent); font-weight: 600; }

main { max-width: 680px; margin: 0 auto; padding: 12px 16px; }

/* ---- карточки и поля ---- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px;
}
.field { margin: 10px 0; }
.field:first-of-type { margin-top: 4px; }
/* вопрос слева, ответ справа в одну строку */
.field.row { display: flex; align-items: center; justify-content: space-between; gap: 6px 12px; flex-wrap: wrap; }
.field.row .choices, .field.row .stepper { margin-top: 0; }
/* два поля рядом */
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 10px 0; }
.pair .field { margin: 0; min-width: 0; }
.pair input[type="time"] { width: 100%; min-width: 0; }
.field-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.field-label { font-weight: 500; }
.field.info { color: var(--text-2); font-weight: 500; }
.field-hint { color: var(--muted); font-size: .8rem; margin-top: 2px; }

.scale-ends { display: flex; justify-content: space-between; color: var(--muted); font-size: .7rem; line-height: 1.1; padding-right: 36px; margin-top: -2px; }

.choices { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.choice {
  padding: 5px 12px; min-height: 36px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer;
}
.choice.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

input[type="text"], input[type="time"], input[type="number"], input[type="date"],
input[type="password"], textarea {
  width: 100%; padding: 8px 10px; margin-top: 4px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface);
}
input[type="time"], input[type="number"], input[type="date"] { width: auto; min-width: 8em; }
textarea { min-height: 64px; resize: vertical; }
input:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

.stepper { display: flex; align-items: center; gap: 6px; margin-top: 4px; }
.stepper input { margin: 0; width: 3.6em; min-width: 0; text-align: center; padding: 6px 4px; }
.stepper button { width: 36px; height: 36px; flex: none; border-radius: 50%; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-size: 1.2rem; }

.btn {
  display: inline-block; padding: 10px 18px; min-height: 44px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer;
  text-decoration: none; text-align: center; color: inherit;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.danger { color: var(--danger); }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
.link-btn { border: 0; background: none; color: var(--muted); text-decoration: underline; cursor: pointer; padding: 8px 0; }

.outing { border-top: 1px solid var(--grid); padding-top: 10px; margin-top: 10px; }
.outing:first-child { border-top: 0; margin-top: 0; padding-top: 0; }
.outing-head { display: flex; justify-content: space-between; align-items: baseline; }
.outing-head h3 { margin: 0; }
.outings > .btn { margin-top: 8px; }

.safety {
  background: var(--safety-bg); border: 2px solid var(--safety-border);
  border-radius: var(--radius); padding: 14px 16px; margin-top: 12px; font-size: 1.05rem;
}
.safety a { color: inherit; font-weight: 700; }

/* ---- недельные опросники ---- */
.q { padding: 12px 0; border-top: 1px solid var(--grid); }
.q:first-of-type { border-top: 0; }
.q-text { margin-bottom: 4px; }
.q .choices { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.q .choice { border-radius: 10px; padding: 6px 10px; font-size: .9rem; text-align: left; }
.score { font-size: 1.1rem; font-weight: 600; }

/* ---- графики ---- */
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; margin-bottom: 14px; }
.seg button { border: 0; background: var(--surface); padding: 8px 14px; min-height: 40px; cursor: pointer; }
.seg button.on { background: var(--accent); color: var(--accent-ink); }

.chart { position: relative; margin-bottom: 18px; }
.chart-title { font-weight: 600; font-size: .95rem; margin-bottom: 2px; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; touch-action: pan-y; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .8rem; color: var(--text-2); margin-bottom: 4px; }
.legend i { display: inline-block; width: 12px; height: 4px; border-radius: 2px; vertical-align: middle; margin-right: 5px; }
.grid-line { stroke: var(--grid); stroke-width: 1; }
.axis-text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.end-label { fill: var(--text-2); font-size: 11px; }
.crosshair { stroke: var(--muted); stroke-width: 1; }
.hit { fill: transparent; }
.s1 { --c: var(--series-1); } .s2 { --c: var(--series-2); }
.s3 { --c: var(--series-3); } .s4 { --c: var(--series-4); }
.legend i.s1, .legend i.s2, .legend i.s3, .legend i.s4 { background: var(--c); }
path.line { fill: none; stroke: var(--c); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
circle.dot { fill: var(--c); stroke: var(--surface); stroke-width: 2; }
path.bar { fill: var(--c); }
.threshold { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 4; opacity: .6; }
.tooltip {
  position: absolute; pointer-events: none; z-index: 5;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 6px 10px; font-size: .8rem; box-shadow: 0 4px 16px rgb(0 0 0 / .12);
  white-space: nowrap;
}
.tooltip b { display: block; margin-bottom: 2px; }
.tooltip i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--c); }

.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
.tile { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; }
.tile-value { font-size: 1.4rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.tile-label { font-size: .8rem; color: var(--text-2); }

/* ---- отчёт ---- */
.table-wrap { overflow-x: auto; }
table.report { border-collapse: collapse; width: 100%; font-size: .8rem; font-variant-numeric: tabular-nums; }
table.report th, table.report td { border-bottom: 1px solid var(--grid); padding: 5px 6px; text-align: right; white-space: nowrap; }
table.report th:first-child, table.report td:first-child { text-align: left; }
table.report td.note { text-align: left; white-space: normal; min-width: 14em; }
table.report th { color: var(--text-2); font-weight: 600; }
.flag { color: var(--danger); font-weight: 700; }

/* ---- вход ---- */
.login-body { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card { width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; }
.login-card label { display: block; margin-top: 14px; font-weight: 500; }
.login-card .btn { width: 100%; margin-top: 20px; }

/* ---- печать (PDF) ---- */
@media print {
  :root { color-scheme: light; --bg: #fff; --surface: #fff; --text: #000; --text-2: #333; --muted: #555; --grid: #ccc; --border: #bbb;
          --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a; --series-4: #6250d6; }
  body { padding: 0; background: #fff; }
  .topbar, .tabs, .no-print, .view:not(#view-report) { display: none !important; }
  main { max-width: none; padding: 0; }
  .card { border: 0; padding: 0; break-inside: avoid; }
  .chart { break-inside: avoid; }
  table.report { font-size: 9pt; }
}

/* стрелки браузера в числовых полях не нужны: рядом есть кнопки − и + */
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
/* блок безопасности в строчном поле — всегда на всю ширину под вопросом */
.field.row .safety { flex-basis: 100%; }

/* кнопки-цифры вместо ползунков */
.num-row { display: grid; grid-template-columns: repeat(11, 1fr); gap: 3px; margin-top: 4px; }
.num-btn {
  min-width: 0; height: 36px; padding: 0; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer;
  font-variant-numeric: tabular-nums;
}
.num-btn.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.num-row + .scale-ends { padding-right: 0; margin-top: 2px; }
.num-row.outings-count { grid-template-columns: repeat(7, 1fr); margin-bottom: 4px; }
