/* =============================================================
   KapitalOS · Components
   Переиспользуемые компоненты дизайн-системы.
   Эти классы будут использованы и на лендинге, и на экранах системы.
   ============================================================= */

/* ---------- Логотип / вордмарк ---------- */
.logo {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: var(--fw-bold);
  font-size: 1.125rem;
  letter-spacing: var(--tracking-tight);
  color: var(--text);
}
.logo:hover { color: var(--text); }
.logo__mark {
  width: 30px; height: 30px;
  border-radius: 9px;
  background: var(--grad-brand);
  display: grid; place-items: center;
  box-shadow: var(--shadow-brand);
  flex-shrink: 0;
}
.logo__mark svg { width: 18px; height: 18px; }
.logo__os { font-family: var(--font-mono); font-weight: var(--fw-semibold); color: var(--primary); }

/* ---------- Кнопки ---------- */
.btn {
  --btn-bg: var(--white);
  --btn-fg: var(--text);
  --btn-bd: var(--border-strong);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 0.7rem 1.15rem;
  min-height: 44px;
  border: 1px solid var(--btn-bd);
  border-radius: var(--r-sm);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  transition: transform var(--t-fast) var(--ease),
              box-shadow var(--t-base) var(--ease),
              background var(--t-fast) var(--ease),
              border-color var(--t-fast) var(--ease),
              color var(--t-fast) var(--ease);
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn svg { width: 18px; height: 18px; flex-shrink: 0; }

.btn--primary {
  --btn-bg: var(--primary);
  --btn-fg: var(--text-on-brand);
  --btn-bd: transparent;
  background: var(--grad-brand);
  box-shadow: var(--shadow-brand);
}
.btn--primary:hover { color: var(--text-on-brand); box-shadow: 0 16px 34px rgba(30,64,175,.34); }

.btn--ghost { --btn-bg: transparent; --btn-bd: transparent; --btn-fg: var(--text); }
.btn--ghost:hover { --btn-bg: var(--bg-muted); transform: none; }

.btn--outline { --btn-bg: var(--white); --btn-bd: var(--border-strong); }
.btn--outline:hover { --btn-bd: var(--brand-400); color: var(--primary); box-shadow: var(--shadow-sm); }

.btn--lg { padding: 0.95rem 1.6rem; min-height: 52px; font-size: var(--fs-base); border-radius: var(--r-md); }
.btn--sm { padding: 0.5rem 0.8rem; min-height: 38px; font-size: var(--fs-xs); }
.btn--block { width: 100%; }

.btn[disabled], .btn[aria-disabled="true"] {
  opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none;
}

/* ---------- Бейджи / пилюли ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 0.25rem 0.6rem;
  border-radius: var(--r-full);
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
  line-height: 1.4;
  white-space: nowrap; /* статусы в 2 слова («На складе», «Частично продано») не переносятся */
  background: var(--bg-muted);
  color: var(--text-muted);
  border: 1px solid transparent;
}
.badge--brand { background: var(--brand-50); color: var(--brand-700); }
.badge--positive { background: var(--positive-soft); color: var(--positive); }
.badge--negative { background: var(--negative-soft); color: var(--negative); }
.badge--warning { background: var(--warning-soft); color: var(--warning); }
.badge--info { background: var(--info-soft); color: var(--info-600); }
.badge--dot::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: currentColor; display: inline-block;
}

/* Дельта-индикатор (рост/падение метрики) */
.delta { display: inline-flex; align-items: center; gap: 3px; font-family: var(--font-mono);
  font-size: var(--fs-xs); font-weight: var(--fw-medium); font-variant-numeric: tabular-nums; }
.delta--up { color: var(--positive); }
.delta--down { color: var(--negative); }
.delta svg { width: 14px; height: 14px; }

/* ---------- Карточки ---------- */
.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
}
.card--pad { padding: var(--space-6); }
.card--hover { transition: transform var(--t-base) var(--ease), box-shadow var(--t-base) var(--ease), border-color var(--t-base) var(--ease); }
.card--hover:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); border-color: var(--border-strong); }

/* ---------- KPI-карточка (плитка дашборда «Обзор») ---------- */
.kpi {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.kpi__label {
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--text-subtle);
}
.kpi__value {
  font-family: var(--font-mono);
  font-size: var(--fs-xl);
  font-weight: var(--fw-semibold);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
  color: var(--text);
  white-space: nowrap;
}
.kpi__meta { display: flex; align-items: center; gap: var(--space-2); font-size: var(--fs-xs); color: var(--text-subtle); }

/* ---------- Иконка-плашка ---------- */
.icon-badge {
  width: 44px; height: 44px;
  border-radius: var(--r-md);
  display: grid; place-items: center;
  background: var(--brand-50);
  color: var(--primary);
  flex-shrink: 0;
}
.icon-badge svg { width: 22px; height: 22px; }
.icon-badge--positive { background: var(--positive-soft); color: var(--positive); }
.icon-badge--warning { background: var(--warning-soft); color: var(--warning); }
.icon-badge--info { background: var(--info-soft); color: var(--info-600); }
.icon-badge--wb { background: rgba(126, 34, 206, .10); color: #7E22CE; }

/* ---------- Фича-карточка ---------- */
.feature {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-6);
}
.feature__title { font-size: var(--fs-md); font-weight: var(--fw-semibold); }
.feature__text { color: var(--text-muted); font-size: var(--fs-sm); line-height: var(--lh-base); }

/* ---------- Карта капитала (переиспользуется на лендинге и в «Обзоре») ---------- */
.capmap { display: grid; gap: var(--space-3); }
.capmap__total { display: flex; justify-content: space-between; align-items: baseline; gap: var(--space-4); padding-bottom: var(--space-3); border-bottom: 1px solid var(--border); }
.capmap__total .v { font-family: var(--font-mono); font-size: var(--fs-xl); font-weight: 700; font-variant-numeric: tabular-nums; }
.capmap__row { display: grid; grid-template-columns: 132px 1fr auto; gap: var(--space-3); align-items: center; font-size: var(--fs-sm); }
.capmap__bar { height: 10px; border-radius: var(--r-full); background: var(--bg-muted); overflow: hidden; }
.capmap__bar i { display: block; height: 100%; border-radius: var(--r-full); background: var(--grad-brand); }
.capmap__row .num { font-weight: 600; font-variant-numeric: tabular-nums; }
@media (max-width: 560px) { .capmap__row { grid-template-columns: 92px 1fr auto; } }

/* ---------- Поля ввода ---------- */
.field { display: flex; flex-direction: column; gap: var(--space-2); }
.field__label { font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--text); }
.input {
  width: 100%;
  padding: 0.75rem 0.9rem;
  min-height: 46px;
  background: var(--bg-inset);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  color: var(--text);
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
.input::placeholder { color: var(--text-subtle); }
.input:focus { outline: none; border-color: var(--brand-400); background: var(--white); box-shadow: 0 0 0 4px var(--ring); }

/* ---------- Таблица (база для экранов Поставки/Продажи/Остатки/Транзакции) ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--bg-elevated); }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.table thead th {
  text-align: left;
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--text-subtle);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  background: var(--bg-muted);
  white-space: nowrap;
}
.table tbody td { padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--border); overflow-wrap: anywhere; word-break: break-word; }
/* Длинное название товара не должно ломать таблицу — переносим и ограничиваем ширину текстовых ячеек */
.table tbody td:not(.num) { max-width: 340px; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background var(--t-fast) var(--ease); }
.table tbody tr:hover { background: var(--bg-muted); }
.table .num { text-align: right; white-space: nowrap; }
.th-sortable { cursor: pointer; user-select: none; }
.th-sortable:hover { color: var(--text-muted); }

/* ---------- Разделитель ---------- */
.divider { height: 1px; background: var(--border); border: 0; }

/* ---------- Аватар ---------- */
.avatar {
  width: 40px; height: 40px; border-radius: var(--r-full);
  background: var(--brand-50); color: var(--brand-700);
  display: grid; place-items: center; font-weight: var(--fw-semibold);
  font-size: var(--fs-sm); flex-shrink: 0;
}

/* =============================================================
   Навигация (верхний бар) — общий для всех страниц
   ============================================================= */
.nav {
  position: sticky;
  top: 0;
  z-index: var(--z-nav);
  height: var(--nav-h);
  display: flex;
  align-items: center;
  background: rgba(247, 249, 252, 0.8);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid transparent;
  transition: border-color var(--t-base) var(--ease), background var(--t-base) var(--ease);
}
.nav.is-scrolled { border-bottom-color: var(--border); background: rgba(247, 249, 252, 0.92); }
.nav__inner { display: flex; align-items: center; gap: var(--space-6); width: 100%; }
.nav__links { display: flex; align-items: center; gap: var(--space-1); margin-inline: auto; }
.nav__link {
  padding: 0.5rem 0.85rem;
  border-radius: var(--r-sm);
  color: var(--text-muted);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  transition: color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
.nav__link:hover { color: var(--text); background: var(--bg-muted); }
.nav__actions { display: flex; align-items: center; gap: var(--space-3); }
.nav__burger {
  display: none;
  width: 44px; height: 44px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--white);
  place-items: center;
}
.nav__burger svg { width: 22px; height: 22px; }

@media (max-width: 920px) {
  .nav__links, .nav__actions .btn--show-desktop { display: none; }
  /* ссылки скрыты → их auto-отступ пропал; прижимаем «Войти» и меню к правому краю */
  .nav__actions { margin-left: auto; }
  .nav__burger { display: grid; }
  .nav__links--open {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-1);
    position: absolute;
    top: var(--nav-h);
    left: 0; right: 0;
    margin: 0;
    padding: var(--space-4);
    background: var(--white);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
  }
  .nav__links--open .nav__link { padding: var(--space-3); font-size: var(--fs-base); }
}

/* =============================================================
   AI-виджет (чат с подсказками) — правый нижний угол, на всех страницах
   ============================================================= */
.assistant { position: fixed; right: clamp(16px, 3vw, 28px); bottom: clamp(16px, 3vw, 28px); z-index: var(--z-assistant); }

.assistant__fab {
  display: flex; align-items: center; gap: var(--space-3);
  height: 60px; padding: 0 1.2rem 0 0.75rem;
  border: none; border-radius: var(--r-full);
  background: var(--grad-brand); color: var(--text-on-brand);
  box-shadow: var(--shadow-brand);
  transition: transform var(--t-base) var(--ease), box-shadow var(--t-base) var(--ease);
}
.assistant__fab:hover { transform: translateY(-2px) scale(1.02); box-shadow: 0 18px 38px rgba(30,64,175,.4); }
.assistant__fab-ico {
  width: 40px; height: 40px; flex-shrink: 0;
  display: grid; place-items: center; border-radius: 50%;
  background: rgba(255,255,255,.18);
}
.assistant__fab-ico svg { width: 24px; height: 24px; color: #fff; }
.assistant__fab-text { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.15; }
.assistant__fab-text b { font-weight: var(--fw-semibold); font-size: var(--fs-sm); }
.assistant__fab-text i { font-style: normal; font-size: var(--fs-xs); color: rgba(255,255,255,.82); }
@media (max-width: 480px) { .assistant__fab-text i { display: none; } }
.assistant__fab .assistant__pulse {
  width: 8px; height: 8px; border-radius: 50%; background: #7CF2C0;
  box-shadow: 0 0 0 0 rgba(124,242,192,.7); animation: pulse 2.2s infinite;
}
@keyframes pulse { 0%{box-shadow:0 0 0 0 rgba(124,242,192,.6)} 70%{box-shadow:0 0 0 10px rgba(124,242,192,0)} 100%{box-shadow:0 0 0 0 rgba(124,242,192,0)} }
@media (prefers-reduced-motion: reduce){ .assistant__fab .assistant__pulse{ animation:none; } }

.assistant__panel {
  position: absolute;
  right: 0; bottom: 72px;
  width: min(380px, calc(100vw - 32px));
  height: min(560px, calc(100dvh - 120px));
  display: flex; flex-direction: column;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-xl);
  overflow: hidden;
  transform-origin: bottom right;
  opacity: 0; transform: translateY(12px) scale(0.96); pointer-events: none;
  transition: opacity var(--t-base) var(--ease-out), transform var(--t-base) var(--ease-out);
}
.assistant.is-open .assistant__panel { opacity: 1; transform: none; pointer-events: auto; }

.assistant__head {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  background: var(--grad-brand); color: var(--text-on-brand);
}
.assistant__head-icon { width: 38px; height: 38px; border-radius: var(--r-sm); background: rgba(255,255,255,.16); display: grid; place-items: center; }
.assistant__head-icon svg { width: 22px; height: 22px; }
.assistant__head h3 { color: var(--text-on-brand); font-size: var(--fs-base); }
.assistant__head p { font-size: var(--fs-xs); color: rgba(255,255,255,.8); }
.assistant__close { margin-left: auto; width: 34px; height: 34px; display: grid; place-items: center; border-radius: var(--r-sm); background: rgba(255,255,255,.12); border: none; color: #fff; }
.assistant__close:hover { background: rgba(255,255,255,.24); }
.assistant__close svg { width: 18px; height: 18px; }

.assistant__body { flex: 1; overflow-y: auto; padding: var(--space-4); display: flex; flex-direction: column; gap: var(--space-3); background: var(--slate-50); }

.msg { max-width: 86%; padding: 0.7rem 0.9rem; border-radius: var(--r-md); font-size: var(--fs-sm); line-height: 1.5; }
.msg--bot { align-self: flex-start; background: var(--white); border: 1px solid var(--border); border-bottom-left-radius: 4px; box-shadow: var(--shadow-xs); }
.msg--user { align-self: flex-end; background: var(--primary); color: var(--text-on-brand); border-bottom-right-radius: 4px; }
.msg strong { font-weight: var(--fw-semibold); }
.msg .factor { display: flex; justify-content: space-between; gap: var(--space-4); font-family: var(--font-mono); font-size: var(--fs-xs); padding: 2px 0; }
.msg .factor b { font-weight: var(--fw-semibold); }

.assistant__chips { display: flex; flex-wrap: wrap; gap: var(--space-2); padding: 0 var(--space-4) var(--space-3); background: var(--slate-50); }
.chip {
  padding: 0.45rem 0.7rem; border-radius: var(--r-full);
  background: var(--white); border: 1px solid var(--border-strong);
  font-size: var(--fs-xs); color: var(--text-muted); cursor: pointer;
  transition: all var(--t-fast) var(--ease); text-align: left;
}
.chip:hover { border-color: var(--brand-400); color: var(--primary); background: var(--brand-50); }

.assistant__form { display: flex; gap: var(--space-2); padding: var(--space-3) var(--space-4); border-top: 1px solid var(--border); background: var(--white); }
.assistant__input { flex: 1; min-height: 42px; padding: 0.5rem 0.8rem; border: 1px solid var(--border-strong); border-radius: var(--r-full); background: var(--bg-inset); font-size: var(--fs-sm); }
.assistant__input:focus { outline: none; border-color: var(--brand-400); background: #fff; box-shadow: 0 0 0 3px var(--ring); }
.assistant__send { width: 42px; height: 42px; flex-shrink: 0; border: none; border-radius: 50%; background: var(--primary); color: #fff; display: grid; place-items: center; transition: background var(--t-fast) var(--ease); }
.assistant__send:hover { background: var(--primary-hover); }
.assistant__send svg { width: 18px; height: 18px; }
.assistant__note { font-size: 10px; color: var(--text-subtle); text-align: center; padding: 0 var(--space-4) var(--space-3); background: var(--white); }

/* индикатор «печатает» */
.typing { display: inline-flex; gap: 4px; align-items: center; }
.typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--slate-400); animation: blink 1.2s infinite; }
.typing span:nth-child(2){ animation-delay: .2s; } .typing span:nth-child(3){ animation-delay: .4s; }
@keyframes blink { 0%,60%,100%{opacity:.25} 30%{opacity:1} }

/* =============================================================
   Модальное окно + тост (переиспользуемые)
   ============================================================= */
.modal-overlay {
  position: fixed; inset: 0; z-index: var(--z-modal);
  background: rgba(11, 18, 32, .5); backdrop-filter: blur(2px);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 5vh 16px; overflow-y: auto;
  opacity: 0; pointer-events: none; transition: opacity var(--t-base) var(--ease);
}
.modal-overlay.is-open { opacity: 1; pointer-events: auto; }
.modal {
  width: 100%; max-width: 660px; margin: auto;
  background: var(--bg-elevated); border-radius: var(--r-xl);
  box-shadow: var(--shadow-xl);
  transform: translateY(14px) scale(.98); transition: transform var(--t-base) var(--ease-out);
}
.modal-overlay.is-open .modal { transform: none; }
.modal__head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); padding: var(--space-5) var(--space-6); border-bottom: 1px solid var(--border); }
.modal__head h3 { font-size: var(--fs-lg); }
.modal__close { width: 36px; height: 36px; border: none; background: none; border-radius: var(--r-sm); color: var(--text-subtle); display: grid; place-items: center; }
.modal__close:hover { background: var(--bg-muted); color: var(--text); }
.modal__close svg { width: 20px; height: 20px; }
.modal__body { padding: var(--space-6); }
.modal__foot { display: flex; justify-content: flex-end; gap: var(--space-3); padding: var(--space-5) var(--space-6); border-top: 1px solid var(--border); }

.modal-tabs { display: flex; gap: 2px; padding: 3px; background: var(--bg-muted); border: 1px solid var(--border); border-radius: var(--r-sm); margin-bottom: var(--space-5); }
.modal-tab { flex: 1; padding: 10px; border: none; background: none; border-radius: 6px; font-weight: var(--fw-medium); font-size: var(--fs-sm); color: var(--text-muted); }
.modal-tab.is-active { background: var(--bg-elevated); color: var(--primary); box-shadow: var(--shadow-xs); }

/* Панель вкладки (используется и вне модалок, напр. на странице новой партии) */
.tab-pane { display: flex; flex-direction: column; gap: var(--space-5); }
.tab-pane[hidden] { display: none; }

/* Переключатель (toggle) */
.switch { position: relative; display: inline-block; width: 42px; height: 24px; flex-shrink: 0; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch__slider { position: absolute; inset: 0; background: var(--border-strong); border-radius: var(--r-full); cursor: pointer; transition: background var(--t-fast) var(--ease); }
.switch__slider::before { content: ""; position: absolute; height: 18px; width: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; box-shadow: var(--shadow-xs); transition: transform var(--t-fast) var(--ease); }
.switch input:checked + .switch__slider { background: var(--primary); }
.switch input:checked + .switch__slider::before { transform: translateX(18px); }
.switch input:focus-visible + .switch__slider { outline: 3px solid var(--ring); outline-offset: 2px; }

.toast {
  position: fixed; bottom: 26px; left: 50%; z-index: var(--z-toast);
  transform: translateX(-50%) translateY(24px);
  display: flex; align-items: center; gap: 8px;
  background: var(--slate-900); color: #fff;
  padding: 12px 18px; border-radius: var(--r-full); box-shadow: var(--shadow-xl);
  font-size: var(--fs-sm); opacity: 0; pointer-events: none;
  transition: opacity var(--t-base) var(--ease), transform var(--t-base) var(--ease);
}
.toast.is-on { opacity: 1; transform: translateX(-50%); }
.toast svg { width: 18px; height: 18px; color: #7CF2C0; }
/* Тост-ошибка — красный, с иконкой внимания вместо зелёной галочки */
.toast--error { background: #B91C1C; }
.toast--error svg { color: #FFE0E0; }

/* Инлайновая ошибка формы (логин, команда, смена пароля, лимиты тарифа и т.п.) */
.auth-error {
  color: var(--negative, #DC2626);
  font-size: var(--fs-sm);
  line-height: 1.5;
  background: var(--negative-bg, rgba(220,38,38,.08));
  border: 1px solid var(--negative-border, rgba(220,38,38,.22));
  border-radius: var(--r-sm);
  padding: 10px 12px;
}
.auth-error a { color: inherit; font-weight: 600; text-decoration: underline; }

/* Плашка блокировки кабинета при истёкшей подписке (нижняя, поверх контента) */
.kos-locklock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: var(--z-toast, 1000);
  display: flex; align-items: center; justify-content: center; gap: 14px; flex-wrap: wrap;
  background: #B91C1C; color: #fff;
  padding: 12px 18px; font-size: var(--fs-sm); line-height: 1.4;
  box-shadow: 0 -6px 20px rgba(0,0,0,.18);
}
.kos-locklock svg { flex-shrink: 0; }
.kos-locklock a { color: #fff; font-weight: 700; text-decoration: underline; white-space: nowrap; }

/* Баннер-объявление платформы (кабинет и публичный сайт) */
.kos-banner { padding: 10px 20px; text-align: center; font-size: 14px; font-weight: 500; line-height: 1.5; }
.kos-banner--info { background: #EFF6FF; color: #1E40AF; border-bottom: 1px solid #DBEAFE; }
.kos-banner--success { background: #ECFDF5; color: #047857; border-bottom: 1px solid #D1FAE5; }
.kos-banner--warning { background: #FFFBEB; color: #B45309; border-bottom: 1px solid #FDE68A; }
