/* Компоненты. Все цвета и размеры — из tokens.css. */

/* ---------- кнопки ---------- */
.btn { --h: 48px; position: relative; display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: var(--h); padding: 0 var(--s5); border-radius: var(--r-chip); font-weight: 520; font-size: var(--fs-15); line-height: 1;
  white-space: nowrap; transition: transform var(--t-fast) var(--ease-out), background-color var(--t-fast), color var(--t-fast), box-shadow var(--t-fast); }
.btn:active { transform: scale(.97); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; pointer-events: none; }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, var(--ink)); }
.btn-soft { background: var(--accent-wash); color: var(--accent); }
.btn-soft:hover { background: color-mix(in srgb, var(--accent-tone) 26%, var(--milk)); }
.btn-quiet { color: var(--ink-soft); }
.btn-quiet:hover { background: var(--oat); color: var(--ink); }
.btn-danger { color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, var(--milk)); }
.btn-block { width: 100%; }
.btn-sm { --h: 36px; padding: 0 var(--s4); font-size: var(--fs-13); border-radius: 12px; }
.btn-sm::after { content: ""; position: absolute; inset: -6px -2px; }  /* зона нажатия не меньше 48 px */
.icon-btn { position: relative; display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: var(--r-pill); color: var(--ink-soft);
  transition: background-color var(--t-fast), color var(--t-fast), transform var(--t-fast) var(--ease-out); }
.icon-btn:hover { background: var(--oat); color: var(--ink); }
.icon-btn:active { transform: scale(.92); }

/* ---------- отметка ---------- */
.check { position: relative; width: 30px; height: 30px; border-radius: var(--r-pill); flex: none; display: grid; place-items: center;
  border: 1.75px solid var(--ink-faint); color: var(--on-accent); background: transparent;
  transition: background-color var(--t-base) var(--ease-out), border-color var(--t-base) var(--ease-out), transform var(--t-base) var(--ease-spring); }
.check::before { content: ""; position: absolute; inset: -9px; }     /* зона нажатия 48 px */
.check svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; overflow: visible; }
.check .tick { stroke-dasharray: 22; stroke-dashoffset: 22; transition: stroke-dashoffset var(--t-slow) var(--ease-out) 60ms; }
.check:hover { border-color: var(--done); }
.check:active { transform: scale(.88); }
.check[aria-pressed="true"] { background: var(--done); border-color: var(--done); animation: check-pop var(--t-slow) var(--ease-spring); }
.check[aria-pressed="true"] .tick { stroke-dashoffset: 0; }
.check.is-optional:not([aria-pressed="true"]) { border-style: dashed; }
.check.is-skipped { border-color: var(--oat-line); background: var(--oat); color: var(--ink-soft); }
.check.is-paused { border-color: var(--oat-line); opacity: .6; }
@keyframes check-pop { 0% { transform: scale(.8); } 60% { transform: scale(1.14); } 100% { transform: scale(1); } }

/* ---------- чипы и бейджи ---------- */
.chip { display: inline-flex; align-items: center; gap: 6px; min-height: 28px; padding: 0 var(--s3); border-radius: var(--r-pill);
  font-size: var(--fs-13); font-weight: 480; background: var(--oat); color: var(--ink-soft); white-space: nowrap; }
.chip .icon { width: 16px; height: 16px; }
.chip-tone { background: var(--tone-wash); color: var(--tone-deep); }
.chip-accent { background: var(--accent-wash); color: var(--accent); }
.chip-warn { background: var(--warn-wash); color: var(--warn); }
.chip-done { background: var(--done-wash); color: var(--done); }
.chip-btn { cursor: pointer; transition: background-color var(--t-fast), transform var(--t-fast) var(--ease-out); position: relative; }
.chip-btn::after { content: ""; position: absolute; inset: -8px -2px; }
.chip-btn:hover { background: var(--oat-line); }
.chip-btn:active { transform: scale(.96); }
.chip-btn[aria-pressed="true"] { background: var(--accent-wash); color: var(--accent); }
.dot { width: 8px; height: 8px; border-radius: var(--r-pill); background: var(--tone, var(--rose)); display: inline-block; flex: none; }
.cat-mark { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 12px; background: var(--tone-wash); color: var(--tone-deep); flex: none; }
.cat-mark .icon { width: 20px; height: 20px; }
.cat-mark.sm { width: 28px; height: 28px; border-radius: 10px; }
.cat-mark.sm .icon { width: 16px; height: 16px; }

/* ---------- поверхности ---------- */
.panel { background: var(--linen); border: 1px solid var(--oat-line); border-radius: var(--r-group); }
.panel-pad { padding: var(--s4) var(--s5); }
.float { background: var(--linen); border-radius: var(--r-sheet); box-shadow: var(--sh-float); }
.hair { height: 1px; background: var(--oat-line); border: 0; margin: 0; }

.list-row { display: flex; align-items: center; gap: var(--s3); min-height: 56px; padding: var(--s2) var(--s5); width: 100%; text-align: left; position: relative; }
.list-row + .list-row::before { content: ""; position: absolute; top: 0; left: var(--s5); right: var(--s5); height: 1px; background: var(--oat-line); }
button.list-row:hover, a.list-row:hover { background: color-mix(in srgb, var(--oat) 55%, transparent); }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .value { color: var(--ink-soft); font-size: var(--fs-13); }
.list-row:first-child { border-radius: var(--r-group) var(--r-group) 0 0; }
.list-row:last-child { border-radius: 0 0 var(--r-group) var(--r-group); }
.list-row:only-child { border-radius: var(--r-group); }
.section-title { font-weight: 560; font-size: var(--fs-15); color: var(--ink); margin: var(--s6) 0 var(--s2); padding: 0 var(--s1); }
.section-note { font-size: var(--fs-13); color: var(--ink-soft); padding: var(--s2) var(--s1) 0; }

/* ---------- поля ввода ---------- */
.field { display: grid; gap: 6px; }
.field > label, .field > .label { font-size: var(--fs-13); font-weight: 500; color: var(--ink-soft); padding-left: 2px; }
.field .hint { font-size: var(--fs-12); color: var(--ink-soft); padding-left: 2px; }
.input, .select, .textarea { width: 100%; min-height: 48px; padding: 0 var(--s4); background: var(--oat); border: 1.5px solid transparent; border-radius: var(--r-chip);
  font-size: 1rem; /* 16 px: iOS не приближает экран */ color: var(--ink); transition: border-color var(--t-fast), background-color var(--t-fast); }
.textarea { padding: var(--s3) var(--s4); min-height: 96px; line-height: 1.45; resize: vertical; }
.input::placeholder, .textarea::placeholder { color: var(--ink-faint); }
.input:hover, .select:hover, .textarea:hover { background: color-mix(in srgb, var(--oat) 80%, var(--oat-line)); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); background: var(--linen); }
.input[aria-invalid="true"] { border-color: var(--danger); }
.select { appearance: none; -webkit-appearance: none; padding-right: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238A8085' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; }
.error-text { color: var(--danger); font-size: var(--fs-13); padding-left: 2px; }
.form-grid { display: grid; gap: var(--s4); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); }

/* переключатель */
.switch { position: relative; width: 52px; height: 32px; flex: none; border-radius: var(--r-pill); background: var(--oat-line);
  transition: background-color var(--t-base) var(--ease-out); }
.switch::before { content: ""; position: absolute; inset: -8px -2px; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: var(--r-pill); background: var(--linen);
  box-shadow: 0 1px 3px rgba(59, 53, 56, .25); transition: transform var(--t-base) var(--ease-spring); }
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"]::after { transform: translateX(20px); }

/* сегменты */
.segmented { display: inline-flex; padding: 3px; gap: 2px; background: var(--oat); border-radius: var(--r-pill); max-width: 100%; }
.segmented > button { position: relative; min-height: 38px; padding: 0 var(--s3); border-radius: var(--r-pill); font-size: var(--fs-13); font-weight: 500;
  color: var(--ink-soft); transition: background-color var(--t-base) var(--ease-out), color var(--t-base), box-shadow var(--t-base); white-space: nowrap; }
.segmented > button[aria-pressed="true"], .segmented > button[aria-selected="true"] { background: var(--linen); color: var(--ink); box-shadow: 0 1px 3px rgba(59, 53, 56, .14); }
.segmented.full { display: flex; } .segmented.full > button { flex: 1; min-width: 0; }

/* прогресс-полоса */
.bar { height: 8px; border-radius: var(--r-pill); background: var(--oat); overflow: hidden; }
.bar > i { display: block; height: 100%; width: var(--p, 0%); border-radius: inherit; background: var(--tone-deep, var(--done)); transition: width var(--t-slow) var(--ease-out); }

/* ---------- лист (диалог) ---------- */
.sheet-overlay { position: fixed; z-index: 50; top: var(--app-top, 0px); left: 0; right: 0; height: var(--app-h, 100%);
  display: flex; align-items: flex-end; justify-content: center; background: var(--scrim);
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); animation: scrim-in 240ms ease-out both; }
.sheet-overlay.is-closing { animation: scrim-out 240ms ease-in both; pointer-events: none; }
.sheet { margin: 0; width: 100%; max-height: calc(var(--app-h, 100vh) - var(--safe-top) - 16px); min-height: 0;
  padding: 0; color: var(--ink); background: var(--linen); border-radius: var(--r-sheet) var(--r-sheet) 0 0;
  box-shadow: var(--sh-pop); overflow: hidden; display: flex; flex-direction: column;
  animation: sheet-in 340ms cubic-bezier(.22, 1, .36, 1) both; will-change: transform; }
.sheet.is-closing { animation: sheet-out 240ms cubic-bezier(.5, 0, .9, .4) both; pointer-events: none; }
/* выезд снизу целиком; на компьютере (шторка по центру) см. ниже */
@keyframes sheet-in { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes sheet-out { from { transform: translateY(0); } to { transform: translateY(100%); } }
@keyframes scrim-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes scrim-out { from { opacity: 1; } to { opacity: 0; } }
@keyframes sheet-pop-in { from { transform: translateY(18px) scale(.97); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes sheet-pop-out { from { transform: none; opacity: 1; } to { transform: translateY(12px) scale(.98); opacity: 0; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-out { from { opacity: 1; } to { opacity: 0; } }
.sheet:focus, .sheet-head .h-title:focus { outline: none; }
.sheet > form { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.sheet-grab { flex: none; display: grid; place-items: center; height: 24px; cursor: grab; touch-action: none; }
.sheet-grab::before { content: ""; width: 40px; height: 4px; border-radius: 4px; background: var(--oat-line); }
.sheet-head { flex: none; display: flex; align-items: center; justify-content: space-between; gap: var(--s3); padding: 0 var(--s3) var(--s2) var(--s5); }
.sheet-head .h-title { min-width: 0; overflow-wrap: anywhere; }
.sheet-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: var(--s2) var(--s5) var(--s6); -webkit-overflow-scrolling: touch; }
.sheet-body:last-child { padding-bottom: calc(var(--s6) + var(--safe-bottom)); }
.sheet-foot { flex: none; padding: var(--s3) var(--s5) calc(var(--s4) + var(--safe-bottom)); display: flex; gap: var(--s3); border-top: 1px solid var(--oat-line); background: var(--linen); }
.sheet-foot .btn { flex: 1; min-width: 0; }
@media (min-width: 700px) {
  .sheet-overlay { align-items: center; }
  .sheet { width: 520px; max-width: calc(100vw - 48px); border-radius: var(--r-sheet); animation-name: sheet-pop-in; animation-duration: 260ms; }
  .sheet.is-closing { animation-name: sheet-pop-out; animation-duration: 200ms; }
  .sheet.wide { width: 720px; }
  .sheet-grab { display: none; }
  .sheet-head { padding-top: var(--s5); }
  .sheet-foot { padding-bottom: var(--s4); }
}
/* «Уменьшение движения» (iPhone: Универсальный доступ): без сдвигов и масштаба, но с короткой плавной сменой прозрачности,
   чтобы открытие и закрытие всё равно были заметны. Специфичность выше общего правила «1 мс» в base.css. */
@media (prefers-reduced-motion: reduce) {
  .sheet-overlay { animation-name: scrim-in; animation-duration: 180ms !important; }
  .sheet-overlay.is-closing { animation-name: scrim-out; animation-duration: 180ms !important; }
  .sheet, .sheet.wide { animation-name: fade-in; animation-duration: 180ms !important; }
  .sheet.is-closing { animation-name: fade-out; animation-duration: 180ms !important; }
}

/* ---------- уведомления ---------- */
.toasts { position: fixed; z-index: 60; left: 0; right: 0; bottom: calc(var(--nav-h) + var(--nav-safe) + var(--s3)); display: grid; justify-items: center; gap: var(--s2);
  padding: 0 var(--s4); pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: var(--s3); max-width: 480px; padding: var(--s3) var(--s3) var(--s3) var(--s5);
  background: var(--ink); color: var(--milk); border-radius: var(--r-pill); box-shadow: var(--sh-pop); font-size: var(--fs-15);
  animation: toast-in var(--t-base) var(--ease-spring) both; }
.toast.is-leaving { animation: toast-out var(--t-base) var(--ease-out) both; }
.toast .btn { min-height: 36px; padding: 0 var(--s3); color: var(--accent-tone); font-size: var(--fs-13); }
.toast.is-error { background: var(--danger); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(14px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px) scale(.98); } }
@media (min-width: 900px) { .toasts { bottom: var(--s6); left: 96px; } }

/* ---------- пустые состояния и скелетоны ---------- */
.empty { display: grid; justify-items: center; text-align: center; gap: var(--s3); padding: var(--s10) var(--s6); }
.empty .badge { display: grid; place-items: center; width: 72px; height: 72px; border-radius: var(--r-pill); background: var(--accent-wash); color: var(--accent); }
.empty .badge .icon { width: 32px; height: 32px; }
.empty p { color: var(--ink-soft); max-width: 32ch; }
.skeleton { background: linear-gradient(100deg, var(--oat) 30%, color-mix(in srgb, var(--oat) 60%, var(--linen)) 50%, var(--oat) 70%); background-size: 220% 100%;
  animation: shimmer 1.4s linear infinite; border-radius: var(--r-chip); }
@keyframes shimmer { to { background-position: -120% 0; } }

/* ---------- прочее ---------- */
.stack { display: grid; gap: var(--s3); }
.row { display: flex; align-items: center; gap: var(--s3); }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.callout { display: flex; gap: var(--s3); padding: var(--s3) var(--s4); border-radius: var(--r-card); background: var(--warn-wash); color: var(--ink); font-size: var(--fs-13); line-height: 1.45; }
.callout .icon { color: var(--warn); margin-top: 1px; }
.callout.is-info { background: var(--accent-wash); } .callout.is-info .icon { color: var(--accent); }
.kbd-hint { font-size: var(--fs-12); color: var(--ink-soft); }
.pre-wrap { white-space: pre-wrap; overflow-wrap: anywhere; }
.reveal { overflow: hidden; display: grid; grid-template-rows: 0fr; transition: grid-template-rows var(--t-slow) var(--ease-out); }
.reveal > div { min-height: 0; }
.reveal.is-open { grid-template-rows: 1fr; }

/* очень узкие экраны (320 px): сегменты чуть теснее, чтобы четыре режима поместились */
@media (max-width: 340px) { .segmented > button { padding: 0 var(--s2); font-size: var(--fs-12); } }

/* ---------- формы на iPhone: ничего не шире колонки, флажки и поля в стиле приложения ---------- */
/* Нативные поля даты/времени в Safari имеют собственную минимальную ширину и распирают сетку: делаем их обычными блоками и разрешаем колонкам сжиматься. */
input[type="date"], input[type="time"], input[type="datetime-local"], input[type="month"] {
  -webkit-appearance: none; appearance: none; display: block; width: 100%; min-width: 0; max-width: 100%; min-height: 48px; text-align: left; }
input[type="date"]::-webkit-date-and-time-value, input[type="time"]::-webkit-date-and-time-value { text-align: left; min-width: 0; margin: 0; }
.form-row, .care-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-row > *, .care-grid > *, .field, .form-grid > * { min-width: 0; }
.sheet-body, .sheet > form, .sheet form .sheet-body { overflow-x: hidden; }   /* внутри шторки не прокручивается вбок */
.sheet-body { overscroll-behavior-x: none; }
/* у полей видна рамка в обеих темах: в тёмной теме фон поля почти не отличался от фона шторки */
.input, .select, .textarea { border-color: var(--oat-line); }
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); }
.input[aria-invalid="true"] { border-color: var(--danger); }

/* флажки: свой вид вместо чёрных нативных квадратов */
input[type="checkbox"] { -webkit-appearance: none; appearance: none; flex: none; width: 24px; height: 24px; margin: 0; border-radius: 8px;
  border: 1.75px solid var(--ink-faint); background: transparent center / 16px no-repeat;
  transition: background-color var(--t-fast) var(--ease-out), border-color var(--t-fast) var(--ease-out); }
input[type="checkbox"]:checked { background-color: var(--accent); border-color: var(--accent);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none' stroke='%23FFFDFB' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4.5 10.5l3.6 3.6 7.4-8.2'/%3E%3C/svg%3E"); }
:root[data-theme="dark"] input[type="checkbox"]:checked {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none' stroke='%231D191C' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4.5 10.5l3.6 3.6 7.4-8.2'/%3E%3C/svg%3E"); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) input[type="checkbox"]:checked {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none' stroke='%231D191C' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4.5 10.5l3.6 3.6 7.4-8.2'/%3E%3C/svg%3E"); } }
input[type="checkbox"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
