/* Nevrayne Design System — компоненты. Подключать после tokens.css. */

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: var(--weight-regular) var(--text-md)/1.55 var(--font);
}
h1, h2, h3, h4, p { margin: 0; }
h1 { font-size: var(--text-3xl); line-height: 1.05; letter-spacing: -.035em; font-weight: var(--weight-bold); }
h2 { font-size: var(--text-2xl); line-height: 1.15; letter-spacing: -.025em; font-weight: var(--weight-bold); }
h3 { font-size: var(--text-lg); line-height: 1.3; letter-spacing: -.01em; font-weight: var(--weight-bold); }
h4 { font-size: var(--text-md); font-weight: var(--weight-bold); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.muted { color: var(--ink-2); }
.small { font-size: var(--text-sm); }
.num { font-variant-numeric: tabular-nums slashed-zero; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-3); }
.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: var(--s-4); }
.grid { display: grid; gap: var(--s-4); grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: var(--s-5); min-width: 0; }

/* значки: одна линия, толщина 2 */
.ic { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- кнопки ---------- */
.btn {
  height: var(--h-md);
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  padding: 0 var(--s-4);
  border: 1px solid transparent; border-radius: var(--r-md);
  background: var(--accent); color: var(--on-accent);
  font-size: var(--text-md); font-weight: var(--weight-medium); line-height: 1; white-space: nowrap;
  cursor: pointer; position: relative;
  transition: background var(--t-fast), border-color var(--t-fast), transform var(--t-instant) var(--ease-out);
}
.btn:hover { background: var(--accent-hover); }
.btn:active { transform: scale(.97); }
.btn.soft { background: var(--accent-soft); color: var(--accent-text); }
.btn.soft:hover { background: var(--accent-soft); border-color: var(--accent); }
.btn.line { background: var(--surface); color: var(--ink); border-color: var(--line-control); }
.btn.line:hover { background: var(--surface-3); }
.btn.ghost { background: transparent; color: var(--ink); }
.btn.ghost:hover { background: var(--surface-3); }
.btn.danger { background: var(--bad); color: var(--on-bad); }
.btn.danger:hover { background: var(--bad); filter: brightness(.9); }
.btn.sm { height: var(--h-sm); padding: 0 var(--s-3); font-size: var(--text-sm); border-radius: 10px; }
.btn.lg { height: var(--h-lg); padding: 0 var(--s-5); border-radius: 14px; }
.btn.icon { width: var(--h-md); padding: 0; }
.btn.icon.sm { width: var(--h-sm); }
.btn:disabled { background: var(--surface-3); color: var(--ink-disabled); border-color: transparent; cursor: not-allowed; transform: none; }
.btn[aria-busy="true"] { color: transparent !important; pointer-events: none; }
.btn[aria-busy="true"]::after {
  content: ""; position: absolute; width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--on-accent); border-right-color: transparent;
  animation: spin 700ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- поля ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label { font-size: var(--text-sm); font-weight: var(--weight-medium); }
.input {
  width: 100%; height: var(--h-md); padding: 0 var(--s-3);
  background: var(--surface); border: 1px solid var(--line-control); border-radius: var(--r-md);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
textarea.input { height: auto; min-height: 88px; max-height: 240px; padding: var(--s-2) var(--s-3); resize: none; field-sizing: content; }
input[type="search"]::-webkit-search-cancel-button, input[type="search"]::-webkit-search-decoration { appearance: none; }

/* ---------- свой выпадающий список (controls.js) ---------- */
.select { position: relative; }
.select-button { display: flex; align-items: center; justify-content: space-between; gap: var(--s-2); text-align: left; cursor: pointer; }
.select-button > .ic { color: var(--ink-2); transition: transform var(--t-base) var(--ease-spring); }
.select-button[aria-expanded="true"] { border-color: var(--accent); }
.select-button[aria-expanded="true"] > .ic { transform: rotate(180deg); }
.listbox { position: fixed; inset: auto; margin: 0; padding: 6px; overflow-y: auto; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow-2); }
.listbox:popover-open { display: flex; flex-direction: column; gap: 2px; animation: list-in var(--t-base) var(--ease-out); }
.listbox.up:popover-open { animation-name: list-in-up; }
.option { display: flex; flex: none; align-items: center; justify-content: space-between; gap: var(--s-3); min-height: var(--h-md); padding: 0 var(--s-3); border-radius: var(--r-sm); font-size: var(--text-md); cursor: pointer; transition: background var(--t-instant); }
.option.active { background: var(--surface-3); }
.option[aria-selected="true"] { background: var(--accent-soft); color: var(--accent-text); font-weight: var(--weight-medium); }
.option[aria-selected="true"].active { box-shadow: inset 0 0 0 1.5px var(--accent); }
.option[aria-disabled="true"] { color: var(--ink-disabled); cursor: not-allowed; }
.option > .ic { visibility: hidden; }
.option[aria-selected="true"] > .ic { visibility: visible; }
@keyframes list-in { from { opacity: 0; transform: translateY(-6px) scale(.97); } }
@keyframes list-in-up { from { opacity: 0; transform: translateY(6px) scale(.97); } }

/* ---------- дата и время (pickers.js) ---------- */
.placeholder { color: var(--ink-2); }
.picker { padding: var(--s-3); max-height: calc(100vh - 16px); }
.picker:popover-open { gap: var(--s-2); }
.picker-date { width: min(316px, calc(100vw - 16px)); }
.cal-head { display: flex; align-items: center; justify-content: space-between; gap: 2px; }
.cal-head b { flex: 1; text-align: center; font-size: var(--text-md); }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-week { text-align: center; font-size: var(--text-xs); color: var(--ink-2); }
.cal-day { height: 38px; padding: 0; border: 0; border-radius: 10px; background: transparent; cursor: pointer; font-size: var(--text-sm); font-variant-numeric: tabular-nums; transition: background var(--t-fast); }
.cal-day:hover { background: var(--surface-3); }
.cal-day.other { color: var(--ink-2); opacity: .65; }
.cal-day.today { box-shadow: inset 0 0 0 1.5px var(--accent); font-weight: var(--weight-bold); }
.cal-day[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); opacity: 1; font-weight: var(--weight-bold); }
.cal-day:disabled { color: var(--ink-disabled); background: transparent; cursor: not-allowed; }
.cal-foot { display: flex; justify-content: space-between; gap: var(--s-2); }
.picker-time { width: 200px; }
.time-cols { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-2); }
.time-col { position: relative; height: 210px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; padding: 2px; border-radius: var(--r-md); scrollbar-width: none; }
.time-col .option { justify-content: center; min-height: 36px; font-variant-numeric: tabular-nums; }
.time-col .option:hover { background: var(--surface-3); }
.time-col .option[aria-selected="true"] { background: var(--accent-soft); }

/* ---------- файл (pickers.js) ---------- */
.filefield { display: flex; flex-direction: column; gap: var(--s-2); min-width: 0; }
.dropzone { display: flex; align-items: center; gap: var(--s-3); width: 100%; padding: var(--s-4); text-align: left; background: var(--surface); border: 1.5px dashed var(--line-control); border-radius: var(--r-md); cursor: pointer; transition: background var(--t-fast), border-color var(--t-fast), transform var(--t-base) var(--ease-spring); }
.dropzone > .ic { width: 24px; height: 24px; color: var(--accent-text); }
.dropzone span { display: flex; flex-direction: column; }
.dropzone small, .files small { color: var(--ink-2); font-size: var(--text-xs); }
.dropzone:hover { background: var(--surface-2); border-color: var(--accent); }
.dropzone.over { background: var(--accent-soft); border-color: var(--accent); border-style: solid; transform: scale(1.015); }
.dropzone:disabled { cursor: not-allowed; background: var(--surface-3); border-color: var(--line); color: var(--ink-disabled); }
.files { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--s-2); }
.files li { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); padding: var(--s-2) var(--s-2) var(--s-2) var(--s-3); background: var(--surface-2); border-radius: var(--r-md); animation: file-in var(--t-base) var(--ease-out); }
.files li > span { display: flex; flex-direction: column; min-width: 0; font-size: var(--text-sm); }
.files b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.filefield .hint:empty { display: none; }
@keyframes file-in { from { opacity: 0; transform: translateY(-6px); } }

/* свои подсказки вместо системных: <button data-tip="Имя"> */
[data-tip] { position: relative; }
[data-tip]::after { content: attr(data-tip); position: absolute; z-index: 30; bottom: calc(100% + 8px); left: 50%; transform: translate(-50%, 4px); padding: 6px 10px; border-radius: var(--r-sm); background: var(--ink); color: var(--bg); font-size: var(--text-xs); font-weight: var(--weight-medium); line-height: 1.3; white-space: nowrap; opacity: 0; visibility: hidden; pointer-events: none; transition: opacity var(--t-fast), transform var(--t-fast) var(--ease-out), visibility var(--t-fast); }
[data-tip]:hover::after, [data-tip]:focus-visible::after { opacity: 1; visibility: visible; transform: translate(-50%, 0); transition-delay: 250ms; }

/* полосы прокрутки */
* { scrollbar-width: thin; scrollbar-color: var(--line-control) transparent; }
.input::placeholder { color: var(--ink-2); }
.input:focus-visible { outline: 2px solid transparent; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent); }
.input:disabled { background: var(--surface-3); color: var(--ink-disabled); border-color: var(--line); }
.hint { font-size: var(--text-sm); color: var(--ink-2); }
.field.invalid .input { border-color: var(--bad); }
.field.invalid .hint { color: var(--bad); }
.field.invalid .input:focus-visible { box-shadow: 0 0 0 3px var(--bad); }
.shake { animation: shake var(--t-slow); }
@keyframes shake { 25% { transform: translateX(-7px); } 50% { transform: translateX(5px); } 75% { transform: translateX(-2px); } }

.check { display: flex; align-items: center; gap: var(--s-3); min-height: var(--h-sm); cursor: pointer; }
.check input { appearance: none; margin: 0; flex: none; cursor: pointer; background: var(--surface); border: 1.5px solid var(--line-control); transition: background var(--t-base), border-color var(--t-base); position: relative; }
.check input[type="checkbox"]:not(.switch) { width: 20px; height: 20px; border-radius: 6px; }
.check input[type="radio"] { width: 20px; height: 20px; border-radius: 50%; }
.check input[type="checkbox"]:not(.switch)::after {
  content: ""; position: absolute; left: 6px; top: 2px; width: 5px; height: 10px;
  border: solid var(--on-accent); border-width: 0 2px 2px 0;
  transform: rotate(45deg) scale(0); transition: transform var(--t-base) var(--ease-spring);
}
.check input:checked { background: var(--accent); border-color: var(--accent); }
.check input[type="checkbox"]:not(.switch):checked::after { transform: rotate(45deg) scale(1); }
.check input[type="radio"]:checked { background: var(--surface); border-width: 6px; }
.check input.switch { width: 44px; height: 26px; border-radius: var(--r-full); }
.check input.switch::after {
  content: ""; position: absolute; top: 3.5px; left: 3.5px; width: 16px; height: 16px; border-radius: 50%;
  background: var(--line-control); transition: transform var(--t-base) var(--ease-spring), background var(--t-base);
}
.check input.switch:checked::after { transform: translateX(18px); background: var(--on-accent); }

/* сегменты и вкладки с едущим индикатором */
.segmented, .tabs { display: inline-flex; position: relative; max-width: 100%; overflow-x: auto; }
.segmented { background: var(--surface-3); border-radius: var(--r-md); padding: 3px; }
.tabs { gap: var(--s-2); border-bottom: 1px solid var(--line); }
.segmented button, .tabs button {
  position: relative; z-index: 1; border: 0; background: transparent; cursor: pointer; white-space: nowrap;
  height: var(--h-sm); padding: 0 var(--s-3);
  font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--ink-2);
  transition: color var(--t-fast);
}
.tabs button { height: var(--h-md); }
.segmented button { border-radius: 9px; }
.segmented button:focus-visible, .tabs button:focus-visible { outline-offset: -2px; }
.segmented [aria-selected="true"], .segmented [aria-pressed="true"], .tabs [aria-selected="true"] { color: var(--ink); }
.indicator { position: absolute; left: 0; width: 0; transition: transform var(--t-slow) var(--ease-spring), width var(--t-slow) var(--ease-spring); }
.segmented .indicator { top: 3px; bottom: 3px; background: var(--surface); border-radius: 9px; box-shadow: var(--shadow-1); }
.tabs .indicator { bottom: 0; height: 3px; background: var(--accent); border-radius: var(--r-full); }

.search { position: relative; }
.search .ic { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--ink-2); pointer-events: none; }
.search .input { padding-left: 38px; }

/* ---------- знак: прорисовка линии от точки к кольцу ---------- */
.mark { display: block; width: 100%; height: 100%; }
.mark.draw .m-line { stroke-dasharray: 1; animation: draw var(--t-draw) var(--ease-move) 120ms backwards; }
.mark.draw .m-dot, .mark.draw .m-ring { transform-box: fill-box; transform-origin: center; animation: dot-in var(--t-slow) var(--ease-spring) backwards; }
.mark.draw .m-ring { animation-delay: var(--t-draw); }
@keyframes draw { from { stroke-dashoffset: 1; opacity: 0; } 8% { opacity: 1; } }
@keyframes dot-in { from { transform: scale(0); } }

/* ---------- статус-пилы ---------- */
.pill {
  --c: var(--off); --b: var(--off-soft);
  display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px 0 8px;
  border-radius: var(--r-full); background: var(--b); color: var(--c);
  font-size: var(--text-xs); font-weight: 600; line-height: 1; white-space: nowrap;
  transition: background var(--t-base), color var(--t-base);
}
.pill svg { width: 14px; height: 14px; flex: none; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.pill.ok   { --c: var(--ok);   --b: var(--ok-soft); }
.pill.run  { --c: var(--run);  --b: var(--run-soft); }
.pill.wait { --c: var(--wait); --b: var(--wait-soft); }
.pill.bad  { --c: var(--bad);  --b: var(--bad-soft); }
.pill.run svg { animation: spin 900ms linear infinite; }
.pill.live svg circle { animation: breathe 2.4s var(--ease-move) infinite; transform-origin: center; }
@keyframes breathe { 50% { transform: scale(.6); } }
.pill.lg { height: 34px; padding: 0 14px 0 12px; font-size: var(--text-sm); }
.pill.lg svg { width: 16px; height: 16px; }
.pill.dot-only { width: 26px; padding: 0; justify-content: center; }
.pill.changed { animation: pillpop var(--t-slow) var(--ease-spring); }
@keyframes pillpop { 40% { transform: scale(1.08); } }

/* ---------- путь: точка → линия → кольцо ---------- */
.path-steps { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; list-style: none; margin: 0; padding: 0; }
.path-steps li { position: relative; padding-top: 28px; text-align: center; font-size: var(--text-sm); color: var(--ink-2); }
.path-steps li::before {
  content: ""; position: absolute; top: 2px; left: calc(50% - 8px); width: 16px; height: 16px; border-radius: 50%;
  border: 2.5px solid var(--line-control); background: var(--surface); z-index: 1;
  transition: background var(--t-base), border-color var(--t-base), box-shadow var(--t-base);
}
.path-steps li + li::after { content: ""; position: absolute; top: 8.5px; right: 50%; width: 100%; height: 3px; background: linear-gradient(var(--accent), var(--accent)) left / 0% 100% no-repeat, var(--line); transition: background-size var(--t-slow) var(--ease-move); }
.path-steps li.done::before { background: var(--accent); border-color: var(--accent); }
.path-steps li.now { color: var(--ink); font-weight: var(--weight-medium); }
.path-steps li.now::before { border-color: var(--accent); box-shadow: 0 0 0 5px var(--accent-soft); }
.path-steps li.done + li::after, .path-steps li.now::after { background-size: 100% 100%; }

.progress { height: 8px; background: var(--surface-3); border-radius: var(--r-full); overflow: hidden; }
.progress > i { display: block; height: 100%; width: 100%; background: var(--accent); border-radius: inherit; transform-origin: left; transform: scaleX(var(--v, 0)); transition: transform var(--t-slow) var(--ease-out); }

.loader { width: 56px; height: 56px; }
.loader path { fill: none; stroke: var(--accent); stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 1; animation: travel 1.5s var(--ease-move) infinite; }
.loader .a { fill: var(--accent); }
.loader .z { fill: none; stroke: var(--accent); stroke-width: 2.4; }
@keyframes travel { 0% { stroke-dashoffset: 1; } 55%, 70% { stroke-dashoffset: 0; } 100% { stroke-dashoffset: -1; } }

.skeleton { height: 14px; border-radius: 7px; background: linear-gradient(100deg, var(--surface-3) 30%, var(--surface-2) 50%, var(--surface-3) 70%) 0 0 / 300% 100%; animation: shimmer 1.4s linear infinite; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }

/* ---------- сообщения ---------- */
.banner { --c: var(--run); --b: var(--run-soft); display: flex; gap: var(--s-3); align-items: flex-start; flex-wrap: wrap; padding: var(--s-3) var(--s-4); border-radius: var(--r-md); background: var(--b); }
.banner > svg { color: var(--c); margin-top: 2px; }
.banner > div { flex: 1; min-width: 180px; }
.banner.wait { --c: var(--wait); --b: var(--wait-soft); }
.banner.bad { --c: var(--bad); --b: var(--bad-soft); }

.toasts { position: fixed; z-index: 50; left: 50%; bottom: var(--s-5); transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: var(--s-2); width: max-content; max-width: calc(100vw - 32px); }
.toast { display: flex; align-items: center; gap: var(--s-4); padding: var(--s-2) var(--s-2) var(--s-2) var(--s-4); min-height: 48px; background: var(--ink); color: var(--bg); border-radius: 14px; box-shadow: var(--shadow-3); font-size: var(--text-sm); font-weight: var(--weight-medium); animation: toast-in var(--t-slow) var(--ease-spring); }
.toast button { border: 0; background: transparent; color: inherit; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; padding: var(--s-2) var(--s-3); font-weight: var(--weight-bold); }
.toast.out { animation: toast-out var(--t-base) var(--ease-in) forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(24px) scale(.94); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(12px); } }

dialog.modal { width: min(420px, calc(100vw - 32px)); padding: var(--s-5); border: 1px solid var(--line); border-radius: var(--r-xl); background: var(--surface); color: var(--ink); box-shadow: var(--shadow-3); }
dialog.modal[open] { animation: pop var(--t-slow) var(--ease-spring); }
dialog.modal::backdrop { background: var(--scrim); backdrop-filter: blur(3px); }
@keyframes pop { from { opacity: 0; transform: translateY(16px) scale(.94); } }
.actions { display: flex; justify-content: flex-end; gap: var(--s-2); flex-wrap: wrap; margin-top: var(--s-5); }

.menu-wrap { position: relative; }
.menu { position: absolute; z-index: 20; top: calc(100% + 6px); left: 0; min-width: 210px; padding: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow-2); transform-origin: top left; animation: menu-in var(--t-base) var(--ease-out); }
.menu button { display: flex; align-items: center; gap: var(--s-3); width: 100%; height: var(--h-md); padding: 0 var(--s-3); border: 0; border-radius: var(--r-sm); background: transparent; cursor: pointer; text-align: left; font-size: var(--text-sm); font-weight: var(--weight-medium); }
.menu button:hover, .menu button:focus-visible { background: var(--surface-3); outline-offset: -2px; }
.menu button.destructive { color: var(--bad); }
@keyframes menu-in { from { opacity: 0; transform: scale(.94) translateY(-4px); } }

.tip { position: relative; display: inline-flex; }
.tip > [role="tooltip"] { position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translate(-50%, 4px); padding: 6px 10px; border-radius: var(--r-sm); background: var(--ink); color: var(--bg); font-size: var(--text-xs); white-space: nowrap; opacity: 0; visibility: hidden; pointer-events: none; transition: opacity var(--t-fast), transform var(--t-fast) var(--ease-out), visibility var(--t-fast); }
.tip:hover > [role="tooltip"], .tip:focus-within > [role="tooltip"] { opacity: 1; visibility: visible; transform: translate(-50%, 0); transition-delay: 250ms; }

.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--s-3); padding: var(--s-6) var(--s-4); }
.empty svg.art { width: 120px; height: 56px; fill: none; stroke: var(--line-control); stroke-width: 3; stroke-linecap: round; }

/* ---------- таблица ---------- */
.table-scroll { overflow-x: auto; position: relative; }
table.table { width: 100%; border-collapse: collapse; white-space: nowrap; font-variant-numeric: tabular-nums; font-size: var(--text-sm); }
.table th { text-align: left; padding: var(--s-2) var(--s-3); color: var(--ink-2); font-weight: var(--weight-medium); border-bottom: 1px solid var(--line); }
.table td { padding: var(--s-3); border-bottom: 1px solid var(--line); }
.table tbody tr { transition: background var(--t-fast); }
.table tbody tr:hover { background: var(--surface-2); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition-duration: 1ms !important; transition-delay: 0ms !important; }
}
:root[data-motion="off"] *, :root[data-motion="off"] *::before, :root[data-motion="off"] *::after { animation: none !important; transition-duration: 1ms !important; transition-delay: 0ms !important; }

@media (forced-colors: active) {
  .btn, .pill, .menu, .toast { border: 1px solid CanvasText; }
  .indicator { background: Highlight; }
}
