/*
  Общие стили: система Growth OS (growth-os/src/web/app.html) и красный акцент.
  Значения только из tokens.css. Компоненты React в этом пакете рисуют эти классы;
  имена .panel, .pill, .title-row, .form-error остались от каркаса как синонимы.
*/

/* ---------- основа ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { margin: 0; background: var(--canvas); color: var(--ink); font: 400 var(--fs-base)/1.43 var(--font); font-feature-settings: "ss01" on, "cv11" on; -webkit-font-smoothing: antialiased; }
h1, h2, h3, h4, p, figure, ul, ol, dl, dd { margin: 0; }
ul, ol { padding: 0; list-style: none; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--line-strong); }
a:hover { text-decoration-color: var(--ink); }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
svg.i { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- типографика ---------- */
h1 { font-size: var(--fs-2xl); line-height: 1.2; letter-spacing: -.025em; font-weight: 600; }
h2 { font-size: var(--fs-lg); line-height: 1.4; font-weight: 600; letter-spacing: -.01em; }
h3 { font-size: var(--fs-md); line-height: 1.4; font-weight: 600; }
.sub { color: var(--mid); }
p.sub { margin-top: 6px; max-width: 720px; }
span.sub, small.sub { display: block; font-size: var(--fs-sm); }
.caption { font-size: var(--fs-xs); line-height: 1.33; letter-spacing: .05em; text-transform: uppercase; color: var(--mid); font-weight: 500; }
.muted { color: var(--mid); }
.nowrap { white-space: nowrap; }
.crumbs { color: var(--mid); margin-bottom: 10px; }
.crumbs a { color: var(--mid); text-decoration: none; }
.crumbs a:hover { color: var(--ink); }
.finding { margin-bottom: var(--sp-3); }

/* ---------- раскладка ---------- */
.page-head, .title-row { display: flex; justify-content: space-between; align-items: flex-end; gap: var(--sp-4); flex-wrap: wrap; margin-bottom: var(--sp-6); }
.page-head > div:first-child, .title-row > div:first-child { min-width: 0; }
.actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: center; }
.actions.end { justify-content: flex-end; margin-left: auto; }
.grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: var(--sp-4); }
.grid.top { align-items: start; }
.span-3 { grid-column: span 3; } .span-4 { grid-column: span 4; } .span-5 { grid-column: span 5; } .span-6 { grid-column: span 6; }
.span-7 { grid-column: span 7; } .span-8 { grid-column: span 8; } .span-9 { grid-column: span 9; } .span-12 { grid-column: span 12; }
.stack, .form-stack { display: grid; gap: var(--sp-4); }
.stack.tight { gap: var(--sp-2); }

/* ---------- карточки ---------- */
.card, .panel { background: var(--paper); border: 1px solid var(--hairline); border-radius: var(--r-card); padding: var(--sp-5); box-shadow: var(--card-shadow); min-width: 0; }
.card.soft { background: var(--surface-alt); box-shadow: none; border: 0; }
.card > header, .panel > header { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap; margin-bottom: var(--sp-3); }
.card .meta, .panel .meta { color: var(--mid); font-size: var(--fs-sm); }
a.card { display: block; text-decoration: none; transition: box-shadow .15s; }

/* ---------- кнопки ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: var(--r-in); border: 0; background: var(--canvas); color: var(--ink); font-size: var(--fs-base); font-weight: 500; cursor: pointer; white-space: nowrap; text-decoration: none; transition: background-color var(--t-fast), box-shadow var(--t-fast), transform var(--t-fast) var(--ease-out); }
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:not(.accent, .primary, .outline, .ghost, .danger) { box-shadow: inset 0 0 0 1px var(--hairline); }
.btn:hover { background: var(--surface-sunk); }
.btn.accent { background: var(--accent); color: var(--on-accent); }
.btn.accent:hover { background: var(--accent-hover); }
.btn.primary { background: var(--ink); color: var(--on-ink); }
.btn.primary:hover { background: var(--ink-hover); }
/* Tailwind рисует свой .outline чёрной рамкой, поэтому здесь он снят; фокус с клавиатуры остаётся. */
.btn.outline:not(:focus-visible), .badge.outline { outline: 0; }
.btn.outline { background: transparent; box-shadow: inset 0 0 0 1px var(--hairline); }
.btn.outline:hover { background: var(--canvas); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--canvas); }
.btn.danger { background: transparent; color: var(--err-ink); }
.btn.danger:hover { background: var(--err-soft); }
.btn.sm { height: 32px; padding: 0 12px; }
.btn.lg { height: 48px; padding: 0 20px; font-size: var(--fs-md); font-weight: 600; }
.btn.block { display: flex; width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.card-link { display: inline-flex; align-items: center; gap: 2px; padding: 0; border: 0; background: none; color: var(--ink); font-weight: 500; cursor: pointer; text-underline-offset: 3px; }
.card-link:hover { text-decoration: underline; }

/* ---------- значки ---------- */
.badge, .pill { display: inline-flex; align-items: center; gap: 5px; font-size: var(--fs-xs); font-weight: 500; line-height: 20px; padding: 0 8px; border-radius: var(--r-in); white-space: nowrap; background: var(--surface-sunk); color: var(--ink-soft); }
.badge svg.i { width: 13px; height: 13px; }
.badge.solid { background: var(--ink-soft); color: var(--on-ink); }
.badge.outline { background: transparent; box-shadow: inset 0 0 0 1px var(--hairline); color: var(--ink); }
.badge.dim { color: var(--mid); }
.badge.accent, .pill.accent { background: var(--accent); color: var(--on-accent); }
.badge.ok, .pill.pos { background: var(--ok-soft); color: var(--ok-ink); }
.badge.warn, .pill.warn { background: var(--warn-soft); color: var(--warn-ink); }
.badge.err, .pill.neg { background: var(--err-soft); color: var(--err-ink); }
.count { font-size: var(--fs-xs); font-weight: 500; background: var(--ink-soft); color: var(--on-ink); border-radius: var(--r-in); padding: 0 7px; min-width: 20px; text-align: center; line-height: 20px; }

/* ---------- поля ---------- */
.field { display: grid; gap: 6px; min-width: 0; }
.field > label { font-size: var(--fs-sm); font-weight: 500; }
.field .hint { color: var(--mid); font-size: var(--fs-xs); }
.input { display: block; width: 100%; min-height: 36px; padding: 8px 12px; border: 0; border-radius: var(--r-in); background: var(--canvas); box-shadow: inset 0 0 0 1px var(--hairline); outline: none; }
.input::placeholder { color: var(--light); opacity: 1; }
.input:focus { box-shadow: 0 0 0 2px var(--ink); background: var(--paper); }
.input[aria-invalid="true"] { box-shadow: 0 0 0 2px var(--err-ink); }
select.input { appearance: none; padding-right: 32px; cursor: pointer; 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='%23868686' 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 12px center; }
textarea.input { min-height: 120px; resize: vertical; line-height: 1.5; }
input.input[type="datetime-local"] { min-width: 0; appearance: none; }
.check { display: flex; gap: 10px; align-items: flex-start; color: var(--ink-2); font-size: var(--fs-sm); cursor: pointer; }
.check input { width: 18px; height: 18px; margin: 1px 0 0; accent-color: var(--ink); flex: none; }
.check a { color: var(--ink); }

/* ---------- ошибки и сообщения: всегда значок и текст ---------- */
.error-text { display: flex; align-items: flex-start; gap: 6px; color: var(--err-ink); font-size: var(--fs-sm); }
.error-text svg.i { margin-top: 1px; }
.form-error { display: flex; align-items: flex-start; gap: 6px; color: var(--err-ink); font-size: var(--fs-sm); }
.form-error::before { content: ""; flex: none; width: 16px; height: 16px; margin-top: 1px; background: currentColor; -webkit-mask: var(--error-mask) center / 16px no-repeat; mask: var(--error-mask) center / 16px no-repeat; }
:root { --error-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 3 2.5 20h19L12 3Zm0 7v4.5m0 2.75v.25'/%3E%3C/svg%3E"); }
.notice { display: flex; align-items: flex-start; gap: var(--sp-2); padding: 10px 12px; border-radius: var(--r-in); background: var(--surface-alt); box-shadow: inset 0 0 0 1px var(--hairline); color: var(--ink-soft); font-size: var(--fs-sm); }
.notice > div { min-width: 0; }
/* Сообщение появляется мягко: видно, что оно новое, но экран не дёргается. */
.notice, .error-text { animation: rise-in var(--t-base) var(--ease-out) both; }
.notice svg.i { margin-top: 2px; }
.notice.accent { background: var(--accent-soft); box-shadow: none; color: var(--accent-ink); }
.notice.ok { background: var(--ok-soft); box-shadow: none; color: var(--ok-ink); }
.notice.warn { background: var(--warn-soft); box-shadow: none; color: var(--warn-ink); }
.notice.err { background: var(--err-soft); box-shadow: none; color: var(--err-ink); }

/* ---------- вкладки ---------- */
.seg, .tabs { display: inline-flex; gap: 2px; padding: 3px; background: var(--surface-sunk); border-radius: var(--r-in); max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.tabs { margin-bottom: var(--sp-4); }
.page-head + .seg { margin-bottom: var(--sp-4); }
.seg > a, .seg > button, .tabs > a { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border: 0; border-radius: var(--r-in); background: transparent; color: var(--mid); font-weight: 500; white-space: nowrap; text-decoration: none; cursor: pointer; }
.seg > [aria-pressed="true"], .seg > [aria-current="page"], .tabs > [aria-selected="true"] { background: var(--paper); color: var(--ink); box-shadow: var(--card-shadow); }
.seg .count, .tabs .num { line-height: 18px; min-width: 18px; padding: 0 6px; }

/* ---------- таблицы ---------- */
table { width: 100%; border-collapse: collapse; }
.table-wrap { overflow-x: auto; }
th { text-align: left; font-size: var(--fs-xs); font-weight: 500; letter-spacing: .05em; text-transform: uppercase; color: var(--mid); padding: var(--sp-3); border-bottom: 1px solid var(--hairline); white-space: nowrap; }
td { padding: var(--sp-3); border-bottom: 1px solid var(--hairline); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
th.num, td.num, th.n, td.n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
/* Таблица в карточке идёт от края до края: строки читаются лучше, а край текста совпадает с заголовком. */
td:first-child, th:first-child { padding-left: var(--sp-5); }
td:last-child, th:last-child { padding-right: var(--sp-5); }
.card > .table-wrap, .panel > .table-wrap { margin-inline: calc(var(--sp-5) * -1); }
.card > .table-wrap:last-child, .panel > .table-wrap:last-child { margin-bottom: calc(var(--sp-3) * -1); }
.card > .table-wrap:first-child, .panel > .table-wrap:first-child { margin-top: calc(var(--sp-2) * -1); }
td .btn { margin-block: -6px; }

/* ---------- списки ---------- */
.rows { display: grid; }
.row { display: flex; align-items: center; gap: var(--sp-3); min-height: var(--tap); padding: 10px 0; }
.row + .row { border-top: 1px solid var(--hairline); }
.row.wrap { flex-wrap: wrap; }
.row.start { align-items: flex-start; }

/* ---------- показатели ---------- */
.stat { min-width: 0; }
.stat-row { display: flex; flex-wrap: wrap; align-items: flex-start; gap: var(--sp-4) var(--sp-5); }
.stat .k { font-size: var(--fs-xs); line-height: 1.33; letter-spacing: .05em; text-transform: uppercase; color: var(--mid); font-weight: 500; }
.stat .v { font-size: var(--fs-2xl); line-height: 1.11; letter-spacing: -.025em; font-weight: 600; margin-top: var(--sp-2); font-variant-numeric: tabular-nums; }
.stat .h { color: var(--mid); font-size: var(--fs-sm); margin-top: var(--sp-1); }
.stat.accent .v { color: var(--accent-ink); }
.meter { height: 6px; background: var(--canvas); border-radius: var(--r-pill); overflow: hidden; display: flex; }
.meter b { display: block; height: 100%; background: var(--accent); }
.avatar { width: 28px; height: 28px; border-radius: var(--r-pill); background: var(--hairline); color: var(--ink-soft); display: inline-grid; place-items: center; font-size: var(--fs-xs); font-weight: 600; flex: none; }

/* ---------- пустые состояния ---------- */
.empty { padding: var(--sp-10) var(--sp-5); text-align: center; color: var(--mid); }
.empty-screen { display: grid; place-items: center; align-content: center; gap: var(--sp-2); min-height: 280px; padding: var(--sp-6); text-align: center; }
.empty-screen h1 { font-size: var(--fs-xl); line-height: 1.33; }
.empty-screen p { color: var(--mid); max-width: 40ch; }

/* ---------- бренд и подвал ---------- */
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { flex: none; }
.brand-word { display: block; flex: none; }
.brand-logo { display: block; color: var(--ink); }
.brand-name { font-weight: 600; line-height: 1.3; }
.brand-name span { display: block; font-weight: 400; color: var(--mid); font-size: var(--fs-xs); }

/* ---------- нижняя панель и окно поверх ---------- */
.tabbar { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); background: var(--surface-alt); border-top: 1px solid var(--hairline); padding: 6px 6px calc(8px + env(safe-area-inset-bottom)); }
.tabbar a, .tabbar button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: var(--tap); padding: var(--sp-1) 0; border: 0; background: none; font-size: var(--fs-xs); color: var(--mid); text-decoration: none; cursor: pointer; }
.tabbar a, .tabbar button { min-width: 0; }
.tabbar svg { flex: none; }
.tabbar .tab-label { max-width: 100%; padding-inline: 2px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.tabbar [aria-current="page"] { color: var(--accent-ink); font-weight: 600; }
.sheet-bg { position: fixed; inset: 0; z-index: 40; background: var(--scrim); display: flex; justify-content: center; align-items: flex-end; padding: var(--sp-4); overflow-y: auto; overscroll-behavior: contain; }
.sheet { width: min(560px, 100%); background: var(--paper); border-radius: var(--r-card); padding: var(--sp-3); box-shadow: var(--sheet-shadow); display: flex; flex-direction: column; gap: 2px; }

/* ---------- телефон ---------- */
@media (max-width: 900px) {
  h1 { font-size: var(--fs-xl); line-height: 1.33; }
  .page-head, .title-row { margin-bottom: var(--sp-4); }
  .grid { grid-template-columns: minmax(0, 1fr); }
  .grid > * { grid-column: 1 / -1 !important; }
  .stat .v { font-size: var(--fs-xl); }
}
@media (max-width: 767px) {
  .btn, .btn.sm { min-height: var(--tap); }
  .input { min-height: var(--tap); }
  .seg > a, .seg > button, .tabs > a { min-height: 38px; padding-inline: 9px; gap: 4px; }
  th:first-child, td:first-child { padding-left: var(--sp-4); }
  th:last-child, td:last-child { padding-right: var(--sp-4); }
  .card, .panel { padding: var(--sp-4); }
  .card > .table-wrap, .panel > .table-wrap { margin-inline: calc(var(--sp-4) * -1); }
  td .btn { margin-block: -4px; }
  /* Иначе первая колонка сжимается, и вторая строка переносится на четыре. */
  td:has(> .sub) { min-width: 150px; }
}
/* ---------- движение ---------- */
/* Экран появляется коротко и сразу видим: анимация добавляет, а не прячет. */
@keyframes view-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes sheet-in { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
@keyframes scrim-in { from { opacity: 0; } to { opacity: 1; } }
/* Экран раздела выходит частями (`.rise`) после предзагрузки — см. apps/admin/src/app/loading.tsx. */
.sheet-bg { animation: scrim-in var(--t-base) var(--ease-out); }
.sheet { animation: sheet-in var(--t-view) var(--ease-out); }
/* Предзагрузка: серые плашки повторяют раскладку экрана, по ним бежит мягкий блик. */
@keyframes skel-shine { from { background-position: 120% 0; } to { background-position: -20% 0; } }
@keyframes skel-in { from { opacity: 0; } to { opacity: 1; } }
.skel { display: block; border-radius: var(--r-sm); background: linear-gradient(100deg, var(--surface-sunk) 30%, var(--surface-alt) 50%, var(--surface-sunk) 70%) 0 0 / 300% 100%; animation: skel-shine 1.4s var(--ease-out) infinite; }
.skel.round { border-radius: var(--r-pill); }
.skel.text { height: 12px; border-radius: 6px; }
.skel-card { display: grid; gap: var(--sp-3); align-content: start; }
.skel-lines { display: grid; gap: 8px; }
/* Появление содержимого после предзагрузки: части экрана выходят одна за другой. */
@keyframes rise-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
/* `backwards`, не `both`: застывшая после конца анимация с transform делает элемент рамкой для
   `position: fixed` внутри — перетаскиваемая компания на рассадке уезжала от курсора на ширину меню. */
.rise > * { animation: rise-in var(--t-view) var(--ease-out) backwards; }
.rise > *:nth-child(2) { animation-delay: 40ms; }
.rise > *:nth-child(3) { animation-delay: 80ms; }
.rise > *:nth-child(4) { animation-delay: 120ms; }
.rise > *:nth-child(n + 5) { animation-delay: 160ms; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; animation: none !important; }
  /* Без бегущего блика плашки всё равно видны: заливка остаётся. */
  .skel { background: var(--surface-sunk); }
}
