/* Токены из @zigmund-tech/ui (DESIGN.md, docs/mockups-miniapp.html). Кит светлый, тёмной темы нет. */
@font-face {
  font-family: "PT Root UI";
  src: url("fonts/pt-root-ui_vf.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --primary: #ff7c37;
  --brand-light: #fff1ea;
  --brand-softest: #fff7f2;
  --foreground: #292524;
  --muted-foreground: #78716d;
  --placeholder: #a8a29e;
  --background: #fafaf9;
  --card: #ffffff;
  --surface-secondary: #f5f5f4;
  --muted: #f5f5f4;
  --border: #e7e5e4;
  --border-light: #f0eeec;
  --success: #34a373;
  --success-bg: #dff7ed;
  --warning: #ff9800;
  --warning-bg: #fff4d6;
  --warning-text: #b86a00;
  --destructive: #e20f5a;
  --error-bg: #fde7ef;
  --r-lg: 0.625rem;
  --r-xl: 0.875rem;
  --r-input: 1rem;
  --r-dialog: 1.5rem;
  --r-pill: 1000px;
  --content-width: 480px;
  --nav-height: 68px;
}

* { box-sizing: border-box; margin: 0; }

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

body {
  background: var(--background);
  color: var(--foreground);
  font: 400 16px/1.4 "PT Root UI", system-ui, sans-serif;
  letter-spacing: -0.02em;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; letter-spacing: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
input, textarea, select { font: inherit; letter-spacing: inherit; color: inherit; }
b, strong { font-weight: 599; }

.h4 { font-size: 24px; font-weight: 599; line-height: 1.1; }
.h5 { font-size: 20px; font-weight: 599; line-height: 1.1; }
.h7 { font-size: 16px; font-weight: 500; line-height: 1.1; }
.h8 { font-size: 14px; font-weight: 500; line-height: 1.1; }
.t4 { font-size: 16px; }
.c2 { font-size: 14px; }
.c3 { font-size: 12px; }
.muted { color: var(--muted-foreground); }

/* Каркас */
#app {
  max-width: var(--content-width);
  margin: 0 auto;
  min-height: 100dvh;
  padding: 0 16px calc(24px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
}
#app.has-footer { padding-bottom: calc(120px + env(safe-area-inset-bottom)); }
#app.has-nav { padding-bottom: calc(var(--nav-height) + 32px + env(safe-area-inset-bottom)); }
#app.has-nav.has-footer { padding-bottom: calc(var(--nav-height) + 120px + env(safe-area-inset-bottom)); }

.mode-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  margin: 0 -16px;
  padding: 8px 16px;
  background: var(--warning-bg);
  color: var(--foreground);
  font-size: 13px;
  line-height: 1.3;
  display: flex;
  gap: 8px;
  align-items: flex-start;
  border-bottom: 1px solid rgba(255, 152, 0, 0.25);
  /* место под кнопку демо-пульта справа */
  padding-right: 56px;
}
.mode-bar svg { flex: none; margin-top: 1px; color: var(--warning); }

.screen-head { display: flex; flex-direction: column; gap: 4px; padding-top: 12px; }
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  align-self: flex-start;
  min-height: 32px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted-foreground);
  font-size: 14px;
  font-weight: 500;
}
.section-title { margin-top: 4px; }

/* Компоненты */
.card {
  background: var(--card);
  border-radius: var(--r-xl);
  box-shadow: 0 0 0 1px rgba(41, 37, 36, 0.1);
  overflow: hidden;
}
.card .in { padding: 16px; }
.card-btn {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: var(--card);
}
.sep { height: 1px; background: var(--border); margin: 12px 0; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.stack-12 { display: flex; flex-direction: column; gap: 12px; }

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 44px;
  padding: 0 24px;
  border-radius: var(--r-pill);
  border: 1px solid transparent;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  width: 100%;
}
.btn.primary { background: var(--primary); color: #fff; }
.btn.outline { background: var(--background); border-color: var(--border); color: var(--foreground); }
.btn.success { background: var(--success); color: #fff; }
.btn.destructive { background: rgba(226, 15, 90, 0.1); color: var(--destructive); }
.btn.ghost { background: transparent; color: var(--foreground); }
.btn:disabled { background: var(--muted); color: var(--muted-foreground); border-color: transparent; }
.btn.sm { height: 32px; padding: 0 14px; font-size: 14px; width: auto; }
.btn:active:not(:disabled) { filter: brightness(0.92); }
.row { display: flex; gap: 8px; }
.row > .btn { flex: 1; padding: 0 12px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 24px;
  padding: 0 10px;
  border-radius: var(--r-pill);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}
.badge.warn { background: var(--warning-bg); color: var(--warning-text); }
.badge.ok { background: var(--success-bg); color: var(--success); }
.badge.err { background: var(--error-bg); color: var(--destructive); }
.badge.neutral { background: var(--surface-secondary); color: var(--muted-foreground); }
.badge.brand { background: var(--brand-light); color: var(--primary); }

.alert {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--r-xl);
  font-size: 14px;
}
.alert svg { flex: none; margin-top: 1px; }
.alert.warn { background: var(--warning-bg); }
.alert.info { background: var(--surface-secondary); }
.alert.err { background: var(--error-bg); }
.alert.ok { background: var(--success-bg); }

.hint { font-size: 14px; color: var(--muted-foreground); }

.chip {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 4px 6px;
  border-radius: var(--r-lg);
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--foreground);
  font-size: 14px;
  font-weight: 450;
  text-align: center;
  line-height: 1.15;
}
.chip.today { background: var(--brand-light); font-weight: 600; }
.chip.on { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); font-weight: 600; }
.chip-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 6px; }
.chip-dot { position: relative; }
.chip-dot::after {
  content: "";
  position: absolute;
  top: 5px;
  right: 6px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--primary);
}


.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font-size: 14px; font-weight: 500; }
.input, .textarea, .select {
  width: 100%;
  min-height: 44px;
  border-radius: var(--r-input);
  border: 1px solid var(--border);
  background: var(--card);
  padding: 0 16px;
  font-size: 16px;
}
.textarea { padding: 12px 16px; min-height: 88px; resize: vertical; }
.input:focus, .textarea:focus, .select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(255, 124, 55, 0.2);
}
.field-row { display: flex; gap: 8px; }
.field-row > .field { flex: 1; min-width: 0; }
/* Шрифт не уменьшаем: меньше 16px iOS приближает страницу при фокусе. Место для «дд.мм.гггг» даём отступами и шириной */
.input[type="date"], .input[type="time"] { padding: 0 10px; }
.field-row > .field:has(> .input[type="date"]) { flex: 1.4; }

.radio {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 0;
  background: none;
  border: 0;
  text-align: left;
  font-size: 16px;
}
.radio i { width: 20px; height: 20px; border-radius: 50%; border: 1.5px solid var(--border); flex: none; }
.radio.on i { border: 6px solid var(--primary); }
.radio small { display: block; color: var(--muted-foreground); font-size: 13px; }

.list-item { display: flex; align-items: center; gap: 10px; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .chev { color: var(--placeholder); flex: none; }
.item-meta { display: flex; align-items: center; gap: 6px; color: var(--muted-foreground); font-size: 14px; margin-top: 6px; }
.item-title { font-size: 16px; font-weight: 599; line-height: 1.15; }

.kv { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; padding: 4px 0; }
.kv span:first-child { color: var(--muted-foreground); }
.kv span:last-child { text-align: right; }

.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }

/* Пустые и итоговые экраны */
.center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 10px;
  padding: 32px 8px;
}
.center.compact { flex: none; padding: 24px 8px; }
.media {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  margin-bottom: 6px;
}
.media.ok { background: var(--success-bg); color: var(--success); }
.media.neutral { background: var(--surface-secondary); color: var(--muted-foreground); }
.media.brand { background: var(--brand-light); color: var(--primary); }
.media.err { background: var(--error-bg); color: var(--destructive); }

/* Нижняя панель действий */
.footer-bar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: min(100%, var(--content-width));
  z-index: 30;
  padding: 12px 16px calc(16px + env(safe-area-inset-bottom));
  background: var(--background);
  border-top: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
/* у психолога панель стоит над нижним меню, иначе меню её закрывает */
body.has-nav .footer-bar {
  bottom: calc(var(--nav-height) + env(safe-area-inset-bottom));
  padding-bottom: 16px;
}

/* Закреплённое меню психолога (ТЗ п. 6.1) */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: min(100%, var(--content-width));
  z-index: 30;
  height: calc(var(--nav-height) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
}
.nav-item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 6px 2px;
  border: 0;
  background: none;
  color: var(--muted-foreground);
  font-size: 11px;
  font-weight: 500;
  line-height: 1.1;
  text-align: center;
}
.nav-item.on { color: var(--primary); }
.nav-item .counter {
  position: absolute;
  top: 4px;
  left: calc(50% + 4px);
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: var(--r-pill);
  background: var(--destructive);
  color: #fff;
  font-size: 11px;
  font-weight: 599;
  display: grid;
  place-items: center;
}

/* Шторка */
#overlay:empty { display: none; }
.backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(41, 37, 36, 0.4);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet {
  width: min(100%, var(--content-width));
  max-height: 92dvh;
  overflow-y: auto;
  background: var(--card);
  border-radius: var(--r-dialog) var(--r-dialog) 0 0;
  padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.grab { width: 40px; height: 4px; border-radius: 2px; background: var(--border); margin: 0 auto 6px; }

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-height) + 24px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(8px);
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: var(--r-pill);
  background: var(--foreground);
  color: #fff;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 80;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Демо-пульт */
#demo-fab {
  position: fixed;
  top: 4px;
  right: 8px;
  z-index: 70;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--card);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
  font-size: 15px;
  line-height: 1;
}
.demo-note { font-size: 12px; color: var(--muted-foreground); }
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 8px 0;
  background: none;
  border: 0;
  text-align: left;
  font-size: 15px;
}
.toggle-row .sw {
  flex: none;
  width: 40px;
  height: 24px;
  border-radius: var(--r-pill);
  background: var(--border);
  position: relative;
  transition: background 0.15s;
}
.toggle-row .sw::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s;
}
.toggle-row.on .sw { background: var(--primary); }
.toggle-row.on .sw::after { transform: translateX(16px); }

/* Авторизация */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.spinner.big { width: 32px; height: 32px; color: var(--primary); }
@keyframes spin { to { transform: rotate(360deg); } }
