/* Acepadel: компоненти. Підключається після tokens.css.
   Класи .is-hover / .is-active / .is-focus потрібні лише на сторінці-довіднику, щоб показати стан;
   справжні стани роблять :hover, :active, :focus-visible і [disabled]. */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 400 var(--fs-body)/var(--lh-body) var(--font-body); }
h1, h2, h3, p, ul, ol, dl, dd, figure { margin: 0; }
ul, ol { padding: 0; list-style: none; }
[hidden] { display: none !important; }
.row { display: flex; flex-wrap: wrap; gap: var(--sp-3); align-items: center; }
a { color: var(--link); }
a:hover { color: var(--link-hover); }
.num { font-variant-numeric: tabular-nums; }
.display { font-family: var(--font-display); font-weight: 700; text-transform: uppercase; letter-spacing: .02em; }
.h1 { font: 700 var(--fs-h1)/var(--lh-h1) var(--font-display); text-transform: uppercase; }
.h2 { font: 700 var(--fs-h2)/var(--lh-h2) var(--font-display); text-transform: uppercase; letter-spacing: .02em; }
.h3 { font: 700 var(--fs-h3)/var(--lh-h3) var(--font-body); }
.small { font-size: var(--fs-small); line-height: var(--lh-small); }
.caption { font-size: var(--fs-caption); line-height: var(--lh-caption); font-weight: 500; }
.muted { color: var(--text-muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.container { max-width: var(--container); margin: 0 auto; padding: 0 var(--sp-5); }
@media (max-width: 767px) { .container { padding: 0 var(--sp-4); } .h1 { font-size: 32px; } :root { --fs-hero: 56px; } }

/* ---------- фокус для всього інтерактивного ---------- */
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible,
.is-focus { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ---------- іконки: один лінійний набір, 24 px, штрих 1.75 ---------- */
.icon { width: 24px; height: 24px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.icon--sm { width: 20px; height: 20px; }

/* ---------- кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: var(--tap); padding: 0 var(--sp-5);
  border: 2px solid transparent; border-radius: var(--r-pill);
  font: 700 var(--fs-small)/1 var(--font-body); text-decoration: none; cursor: pointer;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.btn--primary { background: var(--accent); color: var(--on-accent); }
.btn--primary:hover, .btn--primary.is-hover { background: var(--accent-hover); }
.btn--primary:active, .btn--primary.is-active { background: var(--accent-active); transform: scale(.98); }
.btn--dark { background: var(--surface-dark); color: var(--text-on-dark); }
.btn--dark:hover, .btn--dark.is-hover { background: #2B3138; }
.btn--dark:active, .btn--dark.is-active { background: #000; transform: scale(.98); }
.btn--outline { background: transparent; border-color: var(--text); color: var(--text); }
.btn--outline:hover, .btn--outline.is-hover { background: var(--surface); }
.btn--outline:active, .btn--outline.is-active { background: var(--border-soft); transform: scale(.98); }
.btn--ghost { background: transparent; color: var(--link); padding: 0 var(--sp-3); }
.btn--ghost:hover, .btn--ghost.is-hover { background: var(--link-bg); }
.btn--danger { background: var(--danger); color: #fff; }
.btn--danger:hover, .btn--danger.is-hover { background: #8F1D17; }
.btn--lg { min-height: 52px; padding: 0 var(--sp-6); font-size: var(--fs-body); }
.btn--block { width: 100%; }
.btn[disabled], .btn[aria-disabled="true"] { background: var(--border-soft); border-color: transparent; color: var(--text-muted); cursor: not-allowed; transform: none; }
.btn.is-loading { pointer-events: none; }
.btn.is-loading { opacity: .85; }
.spinner { width: 20px; height: 20px; border: 3px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- поля ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field__label { font-size: var(--fs-small); font-weight: 700; }
.field__hint { font-size: var(--fs-caption); color: var(--text-muted); }
.field__error { display: flex; align-items: flex-start; gap: 6px; font-size: var(--fs-small); font-weight: 500; color: var(--danger); }
.input, .select {
  width: 100%; min-height: 48px; padding: 0 var(--sp-4);
  background: var(--surface); color: var(--text);
  border: 1.5px solid var(--border-strong); border-radius: var(--r-sm);
  font: 400 var(--fs-body)/1.2 var(--font-body);
  transition: border-color var(--dur) var(--ease);
}
.input::placeholder { color: var(--text-muted); }
.input:hover, .input.is-hover, .select:hover { border-color: var(--text-muted); }
.input:focus-visible, .input.is-focus, .select:focus-visible { border-color: var(--focus); outline: 3px solid rgba(36, 86, 184, .28); outline-offset: 0; }
.input[aria-invalid="true"], .input.is-error { border-color: var(--danger); background: var(--danger-bg); }
.input[disabled], .select[disabled] { background: var(--border-soft); color: var(--text-muted); cursor: not-allowed; }
.select { appearance: none; padding-right: 44px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%2314171A' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; }
.input-wrap { position: relative; }
.input-wrap .input { padding-right: 52px; }
.input-wrap__btn { position: absolute; right: 2px; top: 2px; width: 44px; height: 44px; display: grid; place-items: center; background: none; border: 0; border-radius: var(--r-sm); color: var(--text-2); cursor: pointer; }
.input-wrap__btn:hover { background: var(--border-soft); }
.rules { display: grid; gap: 6px; font-size: var(--fs-caption); color: var(--text-muted); }
.rules li { display: flex; align-items: center; gap: 6px; }
.rules li.is-ok { color: var(--success); }

/* чекбокс: ціль ≥ 44 px, стан не лише кольором (галочка) */
.check { display: flex; align-items: center; gap: var(--sp-3); min-height: var(--tap); cursor: pointer; font-size: var(--fs-small); }
.check input { appearance: none; flex: none; width: 24px; height: 24px; margin: 0; background: var(--surface); border: 1.5px solid var(--border-strong); border-radius: 6px; display: grid; place-items: center; cursor: pointer; }
.check input:hover { border-color: var(--text-muted); }
.check input:checked { background: var(--surface-dark); border-color: var(--surface-dark); }
.check input:checked::after { content: ""; width: 11px; height: 6px; border-left: 2.5px solid var(--accent); border-bottom: 2.5px solid var(--accent); transform: translateY(-1px) rotate(-45deg); }
.check input[disabled] { background: var(--border-soft); cursor: not-allowed; }

/* ---------- вкладки ---------- */
.tabs { display: flex; gap: var(--sp-1); padding: var(--sp-1); background: var(--border-soft); border-radius: var(--r-pill); width: fit-content; max-width: 100%; overflow-x: auto; }
.tab { min-height: var(--tap); padding: 0 var(--sp-4); border: 0; border-radius: var(--r-pill); background: transparent; color: var(--text-2); font: 500 var(--fs-small)/1 var(--font-body); cursor: pointer; white-space: nowrap; }
.tab:hover, .tab.is-hover { background: rgba(255, 255, 255, .7); }
.tab[aria-selected="true"] { background: var(--surface-dark); color: var(--text-on-dark); font-weight: 700; }
.tab[disabled] { color: var(--text-muted); opacity: .6; cursor: not-allowed; }

/* ---------- картки ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--sp-5); box-shadow: var(--shadow-1); }
.card--interactive { transition: box-shadow var(--dur) var(--ease), border-color var(--dur) var(--ease); cursor: pointer; }
.card--interactive:hover, .card--interactive.is-hover { box-shadow: var(--shadow-2); border-color: var(--border-strong); }
.card--dark { background: var(--surface-dark); border-color: var(--surface-dark); color: var(--text-on-dark); }
.card--dashed { border-style: dashed; border-color: var(--border-strong); box-shadow: none; }
.card__head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: var(--sp-1) var(--sp-3); margin-bottom: var(--sp-3); }

/* ---------- бейджі, чипи, тренд ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: var(--r-pill); font-size: var(--fs-caption); font-weight: 700; background: var(--border-soft); color: var(--text-2); }
.badge--accent { background: var(--accent); color: var(--on-accent); }
.badge--success { background: var(--success-bg); color: var(--success); }
.badge--warning { background: var(--warning-bg); color: var(--warning); }
.badge--danger { background: var(--danger-bg); color: var(--danger); }
.chip { display: inline-flex; align-items: center; min-height: 32px; padding: 0 14px; border-radius: var(--r-pill); background: var(--border-soft); font-size: var(--fs-small); font-weight: 500; }
.trend { display: inline-flex; align-items: center; gap: 2px; font-size: var(--fs-small); font-weight: 700; font-variant-numeric: tabular-nums; }
.trend--up { color: var(--success); }
.trend--down { color: var(--danger); }
.trend--flat { color: var(--text-muted); }

/* ---------- таблиця ---------- */
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--fs-small); }
.table th { text-align: left; padding: var(--sp-3) var(--sp-4); font-weight: 700; color: var(--text-muted); border-bottom: 1px solid var(--border); white-space: nowrap; }
.table th button { all: unset; display: inline-flex; align-items: center; gap: 4px; min-height: var(--tap); cursor: pointer; font-weight: 700; color: inherit; }
.table th button:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.table th[aria-sort] { color: var(--text); }
.table td { padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--border-soft); }
.table tbody tr:hover, .table tr.is-hover { background: var(--accent-tint); }
.table tr.is-current { background: var(--accent-tint); box-shadow: inset 4px 0 0 var(--surface-dark); font-weight: 700; }
.table .num, .table th.num { text-align: right; }
.table th.num button { justify-content: flex-end; }

/* ---------- пагінація ---------- */
.pagination { display: flex; align-items: center; gap: var(--sp-1); flex-wrap: wrap; }
.page { min-width: var(--tap); min-height: var(--tap); display: inline-grid; place-items: center; padding: 0 var(--sp-2); border-radius: var(--r-pill); border: 0; background: transparent; color: var(--text); font: 500 var(--fs-small)/1 var(--font-body); text-decoration: none; cursor: pointer; }
.page:hover, .page.is-hover { background: var(--border-soft); }
.page[aria-current="page"] { background: var(--surface-dark); color: var(--text-on-dark); font-weight: 700; }
.page[aria-disabled="true"] { color: var(--text-muted); opacity: .5; cursor: not-allowed; }

/* ---------- тости, банери ---------- */
.toast { display: flex; align-items: flex-start; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); border-radius: var(--r-md); border: 1px solid var(--border); background: var(--surface); box-shadow: var(--shadow-2); font-size: var(--fs-small); max-width: 420px; }
.toast__text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.toast--success { border-color: #A8D8B8; background: var(--success-bg); color: #14532B; }
.toast--error { border-color: var(--danger-line); background: var(--danger-bg); color: #7A1710; }
.toast--warning { border-color: var(--warning-line); background: var(--warning-bg); color: var(--warning); }
.toast__close { all: unset; width: var(--tap); height: var(--tap); display: grid; place-items: center; border-radius: var(--r-sm); cursor: pointer; margin: -12px -12px -12px 0; }
.toast__close:hover { background: rgba(0, 0, 0, .06); }
.toast__close:focus-visible { outline: 3px solid var(--focus); }

/* ---------- модальне вікно (на довіднику показано в потоці) ---------- */
.modal-backdrop { background: rgba(20, 23, 26, .55); padding: var(--sp-5); display: grid; place-items: center; border-radius: var(--r-lg); }
.modal { width: 100%; max-width: 440px; background: var(--surface); border-radius: var(--r-lg); padding: var(--sp-5); box-shadow: var(--shadow-3); }
.modal__actions { display: flex; flex-wrap: wrap; gap: var(--sp-3); justify-content: flex-end; margin-top: var(--sp-5); }

/* ---------- скелетони, порожній стан ---------- */
.skeleton { display: block; border-radius: var(--r-sm); background: linear-gradient(90deg, var(--border-soft) 0, #F8F9F5 50%, var(--border-soft) 100%); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
.empty { text-align: center; padding: var(--sp-6) var(--sp-4); display: grid; gap: var(--sp-3); justify-items: center; }
.empty__title { font: 700 var(--fs-h2)/1.2 var(--font-display); text-transform: uppercase; }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }

/* ---------- колеса дати (День / Місяць / Рік) ---------- */
.wheels { position: relative; display: grid; grid-template-columns: 1fr 2fr 1.3fr; gap: 0; height: 220px; background: var(--surface); border: 1.5px solid var(--border-strong); border-radius: var(--r-md); overflow: hidden; }
.wheels__col { height: 100%; overflow-y: auto; scroll-snap-type: y mandatory; padding: 88px 0; box-sizing: border-box; scrollbar-width: none; overscroll-behavior: contain; position: relative; z-index: 1;
  -webkit-mask-image: linear-gradient(to bottom, transparent, #000 32%, #000 68%, transparent); mask-image: linear-gradient(to bottom, transparent, #000 32%, #000 68%, transparent); }
.wheels__col::-webkit-scrollbar { display: none; }
.wheels__col:focus-visible { outline: 3px solid rgba(36, 86, 184, .28); outline-offset: -3px; border-radius: var(--r-sm); }
.wheels__item { height: 44px; display: flex; align-items: center; justify-content: center; scroll-snap-align: center; font: 400 18px/1 var(--font-body); color: var(--text-muted); cursor: pointer; user-select: none; text-transform: capitalize; }
.wheels__item.is-on { color: var(--text); font-weight: 700; }
.wheels__col.is-untouched .wheels__item.is-on { color: var(--text-muted); font-weight: 400; }
.wheels__band { position: absolute; left: var(--sp-2); right: var(--sp-2); top: 88px; height: 44px; background: var(--accent-tint); border: 1.5px solid var(--accent); border-radius: var(--r-sm); z-index: 0; pointer-events: none; }
.wheels.is-pristine .wheels__band { background: var(--border-soft); border-color: var(--border); }
.field.has-error .wheels { border-color: var(--danger); }
@media (prefers-reduced-motion: reduce) { .wheels__col { scroll-behavior: auto; } }

/* ---------- автозбереження ---------- */
.autosave-status { margin: 0; font-size: var(--fs-small); font-weight: 500; }
.autosave-status.is-ok { color: var(--success); }
.autosave-status.is-err { color: var(--danger); }
