/* Общие компоненты сайта и админки: шапка, блоки, плитки, чипы, кнопки, поля, таблицы, окна, тосты. */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scrollbar-gutter: stable; }
body {
  margin: 0; touch-action: manipulation; min-height: 100dvh;
  background: var(--bg); color: var(--text-1);
  font: 400 14px/1.5 var(--font-ui);
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, h4, p { margin: 0; }
h1, h2, h3 { font-weight: 600; letter-spacing: -0.015em; text-wrap: balance; }
p { text-wrap: pretty; }
a { color: inherit; text-decoration: none; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
img, svg { display: block; }
ul, ol { margin: 0; padding: 0; list-style: none; }
[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--accent-hover); outline-offset: 2px; border-radius: var(--r-xs); }

.mono { font-family: var(--font-mono); font-feature-settings: normal; letter-spacing: 0; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.ok { color: var(--ok); } .err { color: var(--err); } .warn { color: var(--warn); }
.skip { position: absolute; left: 12px; top: -48px; z-index: 100; padding: 8px 12px; border-radius: var(--r-sm); background: var(--accent); color: #fff; font-size: 13px; }
.skip:focus { top: 12px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.ic { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round; }
.ic-sm { width: 14px; height: 14px; }
.ic-lg { width: 20px; height: 20px; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

/* ─── Шапка ─────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 30;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(14px) saturate(140%); -webkit-backdrop-filter: blur(14px) saturate(140%);
  border-bottom: 1px solid transparent;
  transition: border-color var(--t-med) var(--ease);
}
.topbar.is-scrolled { border-bottom-color: var(--border); }
.topbar-in {
  display: flex; align-items: center; gap: var(--sp-4);
  max-width: var(--page, 1240px); margin: 0 auto; height: 64px;
  padding: 0 var(--sp-6);
}
.brand { font-size: 14px; font-weight: 600; letter-spacing: 0.02em; white-space: nowrap; }
.brand .dot { color: var(--accent-hover); }
.topbar-sep { width: 1px; height: 18px; background: var(--border-strong); flex: none; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: var(--sp-2); }

.nav { position: relative; display: flex; align-items: center; gap: 2px; }
.nav a {
  position: relative; z-index: 1;
  display: inline-flex; align-items: center; gap: 7px;
  height: 32px; padding: 0 12px; border-radius: var(--r-sm);
  font-size: 13.5px; font-weight: 500; color: var(--text-2); white-space: nowrap;
  transition: color var(--t-fast) var(--ease);
}
.nav a:hover { color: var(--text-1); }
.nav a[aria-current="page"] { color: var(--on-accent); }
.nav-pill {
  position: absolute; z-index: 0; top: 0; left: 0; height: 32px; border-radius: var(--r-sm);
  background: var(--accent); width: 0; opacity: 0;
  transition: transform var(--t-slow) var(--ease-out), width var(--t-slow) var(--ease-out), opacity var(--t-fast);
}
.nav-pill.no-anim { transition: none; }
.nav-count {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  display: inline-grid; place-items: center;
  background: var(--surface-3); color: var(--text-1); font-size: 11px; font-weight: 600;
}
.nav a[aria-current="page"] .nav-count { background: rgba(255,255,255,.2); }
.nav-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--warn); }

/* ─── Шапка — одна на сайт и админку: лого слева, вкладки по центру (текст + линия), справа своё ─── */
.topbar { border-bottom-color: var(--border); }
.topbar-in { display: grid; grid-template-columns: 1fr auto 1fr; max-width: none; height: 54px; padding: 0 var(--sp-6); }
.topbar-in .nav { justify-self: center; align-self: stretch; gap: var(--sp-5); }
.topbar-right { justify-self: end; margin-left: 0; }
.topbar .nav a { height: auto; padding: 4px 2px; border-radius: var(--r-xs); font-size: 13px; color: var(--text-2); gap: 6px; }
.topbar .nav a:hover, .topbar .nav a[aria-current="page"] { color: var(--text-1); }
.topbar .nav a[aria-current="page"] .nav-count { background: var(--accent-soft); color: var(--accent-hover); }
.topbar .nav-pill { top: auto; bottom: -1px; height: 2px; border-radius: 2px 2px 0 0; }
@media (max-width: 640px) {
  .topbar-in { grid-template-columns: 1fr auto; height: auto; padding: 10px var(--sp-4) 0; row-gap: 4px; }
  .topbar-in .nav { grid-column: 1 / -1; grid-row: 2; justify-self: center; padding: 4px 0 10px; }
  .topbar .nav-pill { bottom: 0; }
}

/* ─── Блок (контейнер раздела) и плитка ──────────────────── */
.block {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--r-xl);
  padding: var(--sp-6); box-shadow: var(--inset-hairline);
}
.block-flush { padding: 0; overflow: hidden; }
.block-head { display: flex; align-items: flex-start; gap: var(--sp-4); margin-bottom: var(--sp-5); }
.block-head > div:first-child { min-width: 0; flex: 1; }
.block-flush .block-head { padding: var(--sp-5) var(--sp-5) 0; margin-bottom: var(--sp-4); }
.block-title { font-size: 20px; line-height: 1.3; }
.block-title-sm { font-size: 15px; line-height: 1.4; letter-spacing: -0.01em; display: flex; align-items: center; gap: var(--sp-2); }
.block-title-sm .ic { color: var(--text-2); }
.block-sub { margin-top: 4px; font-size: 13px; color: var(--text-2); }

.tile {
  background: var(--surface-2); border-radius: var(--r-lg); padding: var(--sp-4);
  min-width: 0;
}

/* ─── Чипы ───────────────────────────────────────────────── */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 26px; padding: 0 10px; border-radius: var(--r-sm);
  background: var(--surface-3); color: var(--text-1);
  font-size: 12.5px; font-weight: 500; white-space: nowrap;
}
.chip .ic { width: 14px; height: 14px; color: var(--text-2); }
.chip-ok   { background: var(--ok-soft);   color: var(--ok); }
.chip-err  { background: var(--err-soft);  color: var(--err); }
.chip-warn { background: var(--warn-soft); color: var(--warn); }
.chip-acc  { background: var(--accent-soft); color: var(--accent-hover); }
.chip-ok .ic, .chip-err .ic, .chip-warn .ic, .chip-acc .ic { color: currentColor; }

.pip { width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); flex: none; }
.pip-ok { background: var(--ok); } .pip-err { background: var(--err); } .pip-warn { background: var(--warn); }
.pip-acc { background: var(--accent-hover); }
.pip-live { position: relative; }
.pip-live::after {
  content: ""; position: absolute; inset: 0; border-radius: 50%; background: inherit;
  animation: ping 2.4s var(--ease) infinite;
}
@keyframes ping { 0% { transform: scale(1); opacity: .6; } 70%, 100% { transform: scale(2.6); opacity: 0; } }

/* ─── Кнопки ─────────────────────────────────────────────── */
.btn {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 36px; padding: 0 14px; border-radius: var(--r-md);
  font-size: 13.5px; font-weight: 500; white-space: nowrap; user-select: none;
  transition: background-color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease),
    color var(--t-fast) var(--ease), transform var(--t-fast) var(--ease), opacity var(--t-fast);
}
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-ghost { background: var(--surface-2); color: var(--text-1); }
.btn-ghost:hover:not(:disabled) { background: #202024; }
.btn-line { border: 1px solid var(--border); color: var(--text-2); height: 32px; padding: 0 11px; font-size: 13px; }
.btn-line:hover:not(:disabled) { color: var(--text-1); border-color: var(--border-strong); }
.btn-lg { height: 46px; padding: 0 20px; font-size: 14.5px; border-radius: var(--r-md); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-icon { width: 32px; height: 32px; padding: 0; border-radius: var(--r-sm); }
.btn-danger { background: var(--err-soft); color: var(--err); }
.btn-danger:hover:not(:disabled) { background: rgba(240, 84, 90, .2); }
.btn .spin { display: none; }
.btn.is-loading { color: transparent; pointer-events: none; }
.btn.is-loading .spin { display: block; position: absolute; color: var(--on-accent); }
.btn-ghost.is-loading .spin { color: var(--text-1); }
.spin { width: 16px; height: 16px; animation: rot .8s linear infinite; }
@keyframes rot { to { transform: rotate(360deg); } }
@media (hover: hover) { .btn-ghost:hover .ic, .btn-line:hover .ic { color: var(--text-1); } }

/* ─── Поля ───────────────────────────────────────────────── */
.label { display: block; font-size: 13px; font-weight: 500; color: var(--text-1); margin-bottom: var(--sp-2); }
.input, .textarea, .select select {
  width: 100%; min-width: 0;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-md);
  color: var(--text-1); font-size: 14px; outline: none;
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease), background-color var(--t-fast);
}
.input { height: 40px; padding: 0 12px; }
.textarea { padding: 10px 12px; resize: vertical; min-height: 84px; line-height: 1.5; }
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.input:hover, .textarea:hover, .select select:hover { border-color: var(--border-strong); }
.input:focus, .textarea:focus, .select select:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.is-invalid, .is-invalid:hover, .is-invalid:focus { border-color: var(--err) !important; box-shadow: 0 0 0 3px var(--err-soft) !important; }
.shake { animation: shake 320ms var(--ease); }
@keyframes shake { 20% { transform: translateX(-4px); } 45% { transform: translateX(4px); } 70% { transform: translateX(-2px); } 100% { transform: none; } }
.hint { margin-top: var(--sp-2); font-size: 12.5px; color: var(--text-3); }
.hint a { color: var(--accent-hover); }
.hint a:hover { text-decoration: underline; text-underline-offset: 3px; }
.field-err { margin-top: var(--sp-2); font-size: 12.5px; color: var(--err); }

.search { position: relative; flex: 1; min-width: 200px; }
.search .ic { position: absolute; left: 12px; top: 50%; translate: 0 -50%; color: var(--text-3); pointer-events: none; }
.search .input { padding-left: 36px; height: 36px; font-size: 13.5px; background: var(--surface-1); }

.select { position: relative; display: inline-block; }
.select select { appearance: none; height: 36px; padding: 0 32px 0 12px; font-size: 13.5px; cursor: pointer; background: var(--surface-1); }
select option { background: var(--surface-2); color: var(--text-1); }
.select .ic { position: absolute; right: 10px; top: 50%; translate: 0 -50%; color: var(--text-3); pointer-events: none; }

/* чекбокс с прорисовкой галочки */
.check { display: flex; align-items: flex-start; gap: var(--sp-3); cursor: pointer; font-size: 13.5px; line-height: 1.45; }
.check-box {
  position: relative; flex: none; width: 18px; height: 18px; margin-top: 1px;
  border: 1.5px solid var(--border-strong); border-radius: 5px;
  transition: background-color var(--t-fast), border-color var(--t-fast);
}
.check input { position: absolute; opacity: 0; width: 18px; height: 18px; margin: 0; cursor: pointer; }
.check-box svg { position: absolute; inset: 1px; width: 13px; height: 13px; color: #fff; stroke-dasharray: 1; stroke-dashoffset: 1; transition: stroke-dashoffset var(--t-med) var(--ease); }
.check input:checked + .check-box { background: var(--accent); border-color: var(--accent); }
.check input:checked + .check-box svg { stroke-dashoffset: 0; }
.check input:focus-visible + .check-box { outline: 2px solid var(--accent-hover); outline-offset: 2px; }

/* переключатель */
.switch { position: relative; display: inline-block; vertical-align: middle; width: 36px; height: 20px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 10px; background: var(--surface-3); border: 1px solid var(--border); transition: background-color var(--t-med) var(--ease); }
.switch span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: var(--text-2); transition: transform var(--t-med) var(--ease-out), background-color var(--t-med); }
.switch input:checked + span { background: var(--accent); border-color: var(--accent); }
.switch input:checked + span::after { transform: translateX(16px); background: #fff; }
.switch input:focus-visible + span { outline: 2px solid var(--accent-hover); outline-offset: 2px; }

/* ─── Сегменты (как Premade / Default / My sets) ─────────── */
.seg {
  position: relative; display: inline-flex; gap: 2px; padding: 3px;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--r-md);
  max-width: 100%; overflow-x: auto; scrollbar-width: none;
}
.seg::-webkit-scrollbar { display: none; }
.seg button {
  position: relative; z-index: 1; display: inline-flex; align-items: center; gap: 6px;
  height: 28px; padding: 0 11px; border-radius: 7px;
  font-size: 13px; font-weight: 500; color: var(--text-2); white-space: nowrap;
  transition: color var(--t-fast) var(--ease);
}
.seg button:hover { color: var(--text-1); }
.seg button[aria-checked="true"], .seg button[aria-selected="true"] { color: var(--on-accent); }
.seg-pill {
  position: absolute; z-index: 0; top: 3px; left: 0; height: 28px; border-radius: 7px; background: var(--accent);
  transition: transform var(--t-slow) var(--ease-out), width var(--t-slow) var(--ease-out);
}
.seg-pill.no-anim { transition: none; }
.seg-logo { width: 16px; height: 16px; border-radius: 4px; object-fit: cover; }

/* ─── Таблица ────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; position: relative; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left; font-weight: 500; color: var(--text-3); font-size: 12.5px;
  padding: 10px var(--sp-4); border-bottom: 1px solid var(--border); white-space: nowrap;
  background: var(--surface-1);
}
.table td { padding: 11px var(--sp-4); border-bottom: 1px solid var(--border); vertical-align: middle; white-space: nowrap; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background-color var(--t-fast); }
.table tbody tr:hover { background: rgba(255,255,255,.02); }
.table .ta-r { text-align: right; }
.table .cell-key { font-family: var(--font-mono); font-size: 12.5px; }
.table .cell-sub { display: block; font-size: 12px; color: var(--text-3); }
.st { display: inline-flex; align-items: center; gap: 7px; font-weight: 500; }

/* ─── Пусто и скелетон ───────────────────────────────────── */
.empty { display: grid; justify-items: center; gap: 6px; padding: var(--sp-10) var(--sp-4); text-align: center; color: var(--text-2); font-size: 13.5px; }
.empty .ic { width: 22px; height: 22px; color: var(--text-3); margin-bottom: 4px; }
.empty b { color: var(--text-1); font-weight: 500; }
.skel { display: block; height: 12px; border-radius: 4px; background: linear-gradient(90deg, var(--surface-2) 0%, #222226 50%, var(--surface-2) 100%); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ─── Всплывающее меню ───────────────────────────────────── */
.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 40; min-width: 180px;
  padding: 4px; background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: var(--r-md);
  box-shadow: var(--shadow-pop); transform-origin: top right;
  opacity: 1; transform: none;
  transition: opacity var(--t-med) var(--ease-out), transform var(--t-med) var(--ease-out), display var(--t-med) allow-discrete;
}
@starting-style { .menu { opacity: 0; transform: scale(.96) translateY(-4px); } }
.menu button {
  display: flex; align-items: center; gap: 10px; width: 100%; height: 34px; padding: 0 10px;
  border-radius: 7px; font-size: 13.5px; color: var(--text-2); text-align: left;
}
.menu button:hover, .menu button:focus-visible { background: var(--surface-3); color: var(--text-1); outline: none; }
.menu button[aria-selected="true"] { color: var(--text-1); }
.menu button .ic { margin-left: auto; color: var(--accent-hover); visibility: hidden; }
.menu button[aria-selected="true"] .ic { visibility: visible; }

/* ─── Окно ───────────────────────────────────────────────── */
.modal {
  width: min(460px, calc(100vw - 32px)); max-height: calc(100dvh - 48px); overscroll-behavior: contain;
  padding: var(--sp-6); margin: auto; border: 1px solid var(--border-strong); border-radius: var(--r-xl);
  background: var(--surface-1); color: var(--text-1); box-shadow: var(--shadow-pop);
  opacity: 1; transform: none;
  transition: opacity var(--t-med) var(--ease-out), transform var(--t-med) var(--ease-out),
    overlay var(--t-med) allow-discrete, display var(--t-med) allow-discrete;
}
.modal:focus, .modal:focus-visible { outline: none; }
.modal:not([open]) { opacity: 0; transform: scale(.97) translateY(6px); }
@starting-style { .modal[open] { opacity: 0; transform: scale(.97) translateY(6px); } }
.modal::backdrop {
  background: rgba(0, 0, 0, .6); backdrop-filter: blur(4px);
  opacity: 1; transition: opacity var(--t-med), overlay var(--t-med) allow-discrete, display var(--t-med) allow-discrete;
}
.modal:not([open])::backdrop { opacity: 0; }
@starting-style { .modal[open]::backdrop { opacity: 0; } }
.modal-head { display: flex; align-items: flex-start; gap: var(--sp-3); margin-bottom: var(--sp-5); }
.modal-head > div { flex: 1; min-width: 0; }
.modal-title { font-size: 17px; letter-spacing: -0.01em; }
.modal-x { color: var(--text-3); width: 28px; height: 28px; display: grid; place-items: center; border-radius: var(--r-xs); margin: -4px -6px 0 0; }
.modal-x:hover { color: var(--text-1); background: var(--surface-3); }
.modal-actions { display: flex; gap: var(--sp-2); justify-content: flex-end; margin-top: var(--sp-6); }
.modal-wide { width: min(560px, calc(100vw - 32px)); }

/* ─── Тосты ──────────────────────────────────────────────── */
.toasts { position: fixed; z-index: 60; left: 50%; bottom: var(--sp-6); translate: -50% 0; display: grid; gap: var(--sp-2); justify-items: center; pointer-events: none; width: max-content; max-width: calc(100vw - 32px); }
.toast {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px 10px 12px;
  background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: var(--r-md);
  box-shadow: var(--shadow-pop); font-size: 13.5px; pointer-events: auto;
  animation: toast-in var(--t-slow) var(--ease-out);
}
.toast.out { animation: toast-out var(--t-med) var(--ease) forwards; }
.toast .ic { color: var(--text-2); }
.toast-undo { position: relative; overflow: hidden; gap: 12px; padding: 6px 6px 6px 8px; }
.toast-ic { width: 28px; height: 28px; flex: none; display: grid; place-items: center; border-radius: var(--r-sm); background: var(--surface-3); }
.toast-ic .ic { width: 15px; height: 15px; color: var(--text-1); }
.toast-act {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; margin-left: 4px; padding: 0 10px 0 9px;
  border-radius: var(--r-sm); background: var(--accent-soft); color: var(--accent-hover); font-weight: 500; font-size: 13px;
  transition: background-color var(--t-fast), color var(--t-fast);
}
.toast-act .ic { width: 14px; height: 14px; color: currentColor; }
.toast-act:hover { background: rgba(91, 93, 250, .22); color: #fff; }
.toast-timer { position: absolute; left: 0; right: 0; bottom: 0; height: 2px; background: var(--accent-hover); opacity: .55; transform-origin: left; animation: toast-timer linear forwards; }
.toast-undo:hover .toast-timer { animation-play-state: paused; }
@keyframes toast-timer { from { transform: scaleX(1); } to { transform: scaleX(0); } }

/* свои скроллбары: тонкие, в цвет интерфейса */
* { scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, .14) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, .12); border-radius: 10px; border: 3px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background-color: rgba(255, 255, 255, .22); }
::-webkit-scrollbar-corner { background: transparent; }
.toast.t-ok .ic { color: var(--ok); } .toast.t-err .ic { color: var(--err); }
.toast.bump { animation: bump 260ms var(--ease); }
@keyframes bump { 40% { transform: scale(1.03); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px) scale(.98); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(6px) scale(.98); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; scroll-behavior: auto !important; }
  .pip-live::after { display: none; }
}
