/* Сальдо v2 — основа: каркас, типографика, компоненты, состояния, движение. Значения — только из tokens.css. */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 400 var(--text-md)/var(--leading-body) var(--font-body);
  font-feature-settings: "ss01" 1;
  -webkit-font-smoothing: antialiased;
  transition: background var(--duration-slow) var(--ease), color var(--duration-slow) var(--ease);
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, h4, p { margin: 0; }
h1, h2, h3 { font-family: var(--font-display); font-weight: 500; }
.num { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--font-mono); }
.muted { color: var(--fg-muted); }
.subtle { color: var(--fg-subtle); }
.money { color: var(--gold-ink); }
.visually-hidden { position: absolute !important; left: -10000px !important; top: auto; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
.ic { width: 20px; height: 20px; flex: none; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; border-radius: 8px; }
::selection { background: var(--accent-soft); }

/* ───────── Каркас ───────── */
.shell { min-height: 100dvh; display: flex; flex-direction: column; }
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: var(--space-6);
  padding: var(--space-4) var(--pad);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(1.2) blur(10px);
}
:root { --pad: var(--space-16); }
@media (max-width: 1279px) { :root { --pad: var(--space-8); } }
@media (max-width: 767px) { :root { --pad: var(--space-4); } }
@media (min-width: 1800px) { :root { --pad: var(--space-24); } }

.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; color: var(--fg); }
.brand svg { width: 28px; height: 28px; }
.brand b { font: 500 var(--text-lg)/1 var(--font-display); letter-spacing: -0.01em; }
.nav { display: flex; gap: var(--space-1); margin-left: var(--space-6); }
.nav a {
  position: relative; display: inline-flex; align-items: center; min-height: var(--tap); padding: 0 var(--space-3);
  color: var(--fg-muted); text-decoration: none; font-weight: 500; border-radius: var(--radius-pill);
  transition: color var(--duration-fast) var(--ease), background var(--duration-fast) var(--ease);
}
.nav a:hover { color: var(--fg); }
.nav a[aria-current="page"] { color: var(--fg); }
.nav a[aria-current="page"]::after {
  content: ""; position: absolute; left: var(--space-3); right: var(--space-3); bottom: 8px; height: 2px;
  border-radius: 2px; background: var(--fg);
}
.top-right { margin-left: auto; display: flex; align-items: center; gap: var(--space-2); }
.save-dot { font-size: var(--text-xs); color: var(--fg-subtle); min-width: 90px; text-align: right; }

.view { flex: 1; width: 100%; padding: var(--space-6) var(--pad) 180px; }
.view:focus { outline: none; }

/* Сводка закреплённых полей под шапкой */
.pins { display: flex; gap: var(--space-6); align-items: center; padding: 0 var(--pad) var(--space-2); overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: none; }
.pins::-webkit-scrollbar { display: none; }
@media (max-width: 1279px) { .pins { gap: var(--space-4); mask-image: linear-gradient(90deg, #000 calc(100% - 32px), transparent); } }
.pin { display: inline-flex; align-items: baseline; gap: var(--space-2); min-height: 32px; white-space: nowrap; color: var(--fg-muted); text-decoration: none; font-size: var(--text-sm); }
.pin:hover .pin-name { color: var(--fg); }
.pin-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c); align-self: center; }
.pin-val { color: var(--fg); font-weight: 500; font-variant-numeric: tabular-nums; }
.pin-val.is-neg { color: var(--danger); }
.pin-val.is-gold { color: var(--gold-ink); }

/* ───────── Кнопки ───────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: 48px; padding: 0 var(--space-6); border-radius: var(--radius-pill);
  border: 1px solid var(--border-strong); background: transparent; color: var(--fg);
  font-weight: 500; font-size: var(--text-md); white-space: nowrap; text-decoration: none;
  transition: background var(--duration-fast) var(--ease), border-color var(--duration-fast) var(--ease), transform var(--duration-fast) var(--ease), color var(--duration-fast) var(--ease);
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.98); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .4; pointer-events: none; }
.btn-primary { background: var(--accent); border-color: transparent; color: var(--accent-fg); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-ghost { border-color: transparent; color: var(--fg-muted); }
.btn-ghost:hover { color: var(--fg); background: var(--surface-2); }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn-sm, .btn-s { min-height: 40px; padding: 0 var(--space-4); font-size: var(--text-sm); }
.btn-icon { width: var(--tap); min-height: var(--tap); padding: 0; }
.btn.is-loading { pointer-events: none; color: transparent; position: relative; }
.btn.is-loading::after { content: "···"; position: absolute; color: var(--accent-fg); letter-spacing: .2em; animation: pulse 1s infinite; }
.link { color: var(--fg); text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }

/* ───────── Поля ───────── */
.label { display: block; font-size: var(--text-sm); color: var(--fg-muted); margin-bottom: 6px; font-weight: 500; }
.input, .select, .textarea {
  width: 100%; min-height: 48px; padding: 10px 16px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-md);
  color: var(--fg); font-size: var(--text-md);
  transition: border-color var(--duration-fast) var(--ease), box-shadow var(--duration-fast) var(--ease);
}
.input::placeholder, .textarea::placeholder { color: var(--fg-subtle); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px var(--accent-soft); }
.input.is-error { border-color: var(--danger); }
.input-num { text-align: right; font-variant-numeric: tabular-nums; }
.select { appearance: none; padding-right: 36px; background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%); background-position: calc(100% - 20px) 52%, calc(100% - 15px) 52%; background-size: 5px 5px; background-repeat: no-repeat; }
.textarea { min-height: 88px; resize: vertical; }
.hint { font-size: var(--text-sm); color: var(--fg-muted); margin-top: 6px; }
.err { font-size: var(--text-sm); color: var(--danger); margin-top: 6px; }
.check { display: inline-flex; align-items: center; gap: var(--space-2); min-height: var(--tap); cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.form-row { display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }

.chip {
  display: inline-flex; align-items: center; gap: var(--space-2); min-height: 40px; padding: 0 var(--space-4);
  border-radius: var(--radius-pill); border: 1px solid var(--border); background: var(--surface);
  color: var(--fg); font-size: var(--text-sm); font-weight: 500;
  transition: border-color var(--duration-fast) var(--ease), transform var(--duration-fast) var(--ease), background var(--duration-fast) var(--ease);
}
.chip:hover { border-color: var(--border-strong); }
.chip:active { transform: scale(.97); }
.chip.is-on { background: var(--fg); color: var(--bg); border-color: transparent; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c, var(--fg-subtle)); flex: none; }
.swatch { width: 12px; height: 12px; border-radius: 4px; background: var(--c, var(--p1)); flex: none; }
.seg { display: inline-flex; padding: 4px; gap: 2px; background: var(--surface-2); border-radius: var(--radius-pill); }
.seg-btn { min-height: 44px; padding: 0 var(--space-4); border: 0; border-radius: var(--radius-pill); background: transparent; color: var(--fg-muted); font-size: var(--text-sm); font-weight: 500; }
.seg-btn.is-on { background: var(--surface); color: var(--fg); box-shadow: var(--shadow-1); }
kbd { font: 500 var(--text-xs)/1 var(--font-mono); padding: 4px 6px; border-radius: 6px; border: 1px solid var(--border-strong); color: var(--fg-muted); }

.pill { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 12px; border-radius: var(--radius-pill); background: var(--surface-2); color: var(--fg-muted); font-size: var(--text-sm); font-weight: 500; white-space: nowrap; }
.pill-ok { color: var(--success); }
.pill-warn { color: var(--warning); }
.pill-bad { color: var(--danger); }
.pill-ok::before, .pill-warn::before, .pill-bad::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.sheet { background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-2); }
.empty { padding: var(--space-16) 0; color: var(--fg-muted); text-align: left; max-width: 60ch; }
.empty h2 { color: var(--fg); font-size: var(--text-2xl); letter-spacing: -0.02em; margin-bottom: var(--space-3); }

/* ───────── Окна, меню, уведомления, подсказки (разметка — ui-core.js) ───────── */
.modal-wrap { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: var(--space-4); }
.modal-scrim { position: absolute; inset: 0; background: var(--scrim); backdrop-filter: blur(4px); animation: fade var(--duration-base) var(--ease); }
.modal { position: relative; width: min(560px, 100%); max-height: calc(100dvh - 32px); display: flex; flex-direction: column; background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-2); animation: rise var(--duration-slow) var(--ease-out); }
.modal-wide { width: min(1040px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: var(--space-6) var(--space-6) var(--space-2) var(--space-8); }
.modal-head h2 { font-size: var(--text-xl); letter-spacing: -0.01em; }
.modal-head .btn { width: var(--tap); padding: 0; border-color: transparent; }
.modal-body { padding: var(--space-2) var(--space-8) var(--space-6); overflow: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: var(--space-2); padding: var(--space-4) var(--space-8) var(--space-6); flex-wrap: wrap; }
.modal-text { color: var(--fg-muted); max-width: 60ch; }
.modal-wrap.leave .modal { animation: sink 180ms var(--ease) forwards; }
.modal-wrap.leave .modal-scrim { animation: fade 180ms var(--ease) reverse forwards; }

.menu { position: fixed; z-index: 70; min-width: 240px; max-width: 340px; max-height: 70vh; overflow: auto; padding: 6px; background: var(--surface); border-radius: var(--radius-md); box-shadow: var(--shadow-2); border: 1px solid var(--border); animation: rise var(--duration-base) var(--ease-out); }
.menu.leave { animation: sink 140ms var(--ease) forwards; }
.menu-item { display: flex; align-items: center; gap: var(--space-3); width: 100%; min-height: var(--tap); padding: 6px 12px; border: 0; background: transparent; border-radius: var(--radius-sm); text-align: left; font-size: var(--text-sm); }
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-2); outline: none; }
.menu-item.is-danger { color: var(--danger); }
.menu-item:disabled { opacity: .45; }
.menu-label { flex: 1; display: flex; flex-direction: column; }
.menu-label small { color: var(--fg-muted); font-size: var(--text-xs); }
.menu-sep { height: 1px; margin: 4px 8px; background: var(--border); }
.menu-head { padding: 10px 12px 4px; font-size: var(--text-xs); color: var(--fg-subtle); }

#toasts { position: fixed; left: 50%; top: 84px; transform: translateX(-50%); z-index: 80; display: flex; flex-direction: column; gap: var(--space-2); align-items: center; pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: var(--space-3); min-height: 48px; padding: 6px 6px 6px 18px; max-width: min(560px, calc(100vw - 32px)); background: var(--fg); color: var(--bg); border-radius: var(--radius-pill); box-shadow: var(--shadow-2); font-size: var(--text-sm); font-weight: 500; animation: rise var(--duration-slow) var(--ease-out); }
.toast:not(:has(button)) { padding-right: 20px; }
.toast .ic { width: 18px; height: 18px; }
.toast .btn { min-height: 36px; padding: 0 14px; color: var(--bg); border-color: color-mix(in srgb, var(--bg) 30%, transparent); font-size: var(--text-sm); }
.toast .btn:hover { background: color-mix(in srgb, var(--bg) 12%, transparent); }
.toast.leave { animation: sink 200ms var(--ease) forwards; }

.tooltip { position: fixed; z-index: 75; pointer-events: none; max-width: 300px; padding: 10px 14px; background: var(--fg); color: var(--bg); border-radius: var(--radius-sm); font-size: var(--text-sm); box-shadow: var(--shadow-2); }
.tooltip[hidden] { display: block; opacity: 0; }

.assist-host { position: relative; }
.assist { position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 30; max-height: 260px; overflow: auto; padding: 6px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow-2); }
.assist-item { display: flex; align-items: center; gap: var(--space-2); padding: 10px 12px; border-radius: var(--radius-sm); cursor: pointer; font-size: var(--text-sm); }
.assist-item small { margin-left: auto; color: var(--fg-muted); }
.assist-item.is-on, .assist-item:hover { background: var(--surface-2); }
.ref { padding: 0 6px; border-radius: 6px; background: color-mix(in srgb, var(--c) 22%, transparent); font-weight: 500; }
.ref em { font-style: normal; color: var(--fg-muted); }
.ref-bad { background: color-mix(in srgb, var(--danger) 16%, transparent); text-decoration: wavy underline var(--danger); }

/* ───────── Движение ───────── */
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes sink { to { opacity: 0; transform: translateY(8px) scale(.98); } }
@keyframes pulse { 50% { opacity: .35; } }
@keyframes enter { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
@keyframes enterNew { 0% { opacity: 0; transform: translateY(-8px) scale(.98); } 100% { opacity: 1; transform: none; } }
@keyframes bump { 0% { color: var(--accent-bright); } 100% { color: inherit; } }
@keyframes recalc { 0% { filter: brightness(1.12); } 100% { filter: none; } }
@keyframes flash { 0%, 100% { box-shadow: 0 0 0 0 transparent; } 30% { box-shadow: 0 0 0 4px var(--accent-soft); } }
@keyframes leaving { to { opacity: 0; transform: translateX(16px); } }
.enter { animation: enter var(--duration-slow) var(--ease-out) both; animation-delay: calc(var(--i, 0) * 45ms); }
.enter-new { animation: enterNew var(--duration-slow) var(--ease-out) both; }
.bump { animation: bump 1s var(--ease); }
.recalc { animation: recalc 900ms var(--ease); animation-delay: var(--wave-delay, 0ms); }
.flash { animation: flash 1.2s var(--ease); }
.leaving { animation: leaving 220ms var(--ease) forwards; }
[data-motion="off"] *, [data-motion="off"] *::before, [data-motion="off"] *::after { animation: none !important; transition: none !important; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
}
::view-transition-old(root), ::view-transition-new(root) { animation-duration: var(--duration-slow); animation-timing-function: var(--ease); }

/* ───────── Режим «Полёт» (Автопилот) ───────── */
body[data-mode="flight"] .top { background: color-mix(in srgb, var(--bg) 80%, transparent); }
body[data-mode="flight"] .nav, body[data-mode="flight"] .top-right .light-only { display: none; }
body:not([data-mode="flight"]) .flight-only { display: none; }
body[data-mode="flight"] .view { padding-bottom: var(--space-12); }

/* ───────── Адаптивность ───────── */
@media (max-width: 1023px) {
  .save-dot { display: none; }
  .nav { margin-left: var(--space-2); gap: 0; }
  .nav a { padding: 0 var(--space-2); }
  .nav a[aria-current="page"]::after { left: var(--space-2); right: var(--space-2); }
  .top { gap: var(--space-3); }
  .brand b { display: none; }
  .top-right { gap: var(--space-1); }
  #btn-flight { padding: 0 var(--space-3); }
}
@media (max-width: 767px) {
  .top { gap: var(--space-2); flex-wrap: wrap; padding-top: var(--space-2); padding-bottom: var(--space-2); }
  .nav { order: 3; width: 100%; margin: 0; justify-content: space-between; }
  .nav a { flex: 1; justify-content: center; }
  .save-dot { display: none; }
  .view { padding-top: var(--space-4); }
  #toasts { top: 112px; }
}
