/* Finmerce · Design system A · базовые компоненты.
   Только var(--…) из tokens.css. Описание — public/docs/design-system.md, раздел «Компоненты». */

/* ---------- Кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: var(--h-control); padding: 0 var(--space-4);
  border: 1px solid var(--line-strong); border-radius: var(--r-m);
  background: var(--surface); color: var(--ink);
  font: var(--t-body); font-weight: 500; text-decoration: none; white-space: nowrap; cursor: pointer;
  transition: background var(--dur-fast) ease-out, color var(--dur-fast) ease-out, border-color var(--dur-fast) ease-out;
}
.btn:hover { background: var(--surface-2); border-color: var(--ink-2); }
.btn:active { background: var(--surface-selected); }
.btn.block { width: 100%; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; }
.btn[aria-busy="true"] { cursor: progress; }

.btn-primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover, .btn.primary:hover, .btn-primary:active, .btn.primary:active { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-danger { border-color: var(--danger-line); color: var(--red); }
.btn-danger:hover { background: var(--red-bg); border-color: var(--danger-line); }
/* Исторический вариант с заливкой (используется в старых экранах). */
.btn.danger { background: var(--red); border-color: var(--red); color: var(--on-accent); }
.btn.danger:hover { background: var(--danger-hover); border-color: var(--danger-hover); color: var(--danger-hover-ink); }
.btn.ghost { background: var(--surface); }

.btn-link {
  display: inline-flex; align-items: center; gap: var(--space-1); padding: 0; min-height: 0;
  border: 0; background: none; color: var(--accent); font: var(--t-body); font-weight: 500; cursor: pointer; text-decoration: none;
}
.btn-link:hover { background: none; color: var(--accent-hover); text-decoration: underline; }

.btn-s { min-height: var(--h-control-s); padding: 0 10px; font: var(--t-small); font-weight: 500; }

.iconbtn {
  display: inline-grid; place-items: center; flex: none;
  width: var(--h-control); height: var(--h-control); padding: 0;
  border: 1px solid var(--line-strong); border-radius: var(--r-m);
  background: var(--surface); color: var(--ink-2); cursor: pointer;
  transition: background var(--dur-fast) ease-out, color var(--dur-fast) ease-out, border-color var(--dur-fast) ease-out;
}
.iconbtn:hover { background: var(--surface-2); border-color: var(--ink-2); color: var(--ink); }
.iconbtn:disabled { opacity: .45; cursor: not-allowed; }

.btn:focus-visible, .iconbtn:focus-visible, .btn-link:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }

/* ---------- Поля ---------- */
.input, .select {
  width: 100%; min-height: var(--h-control); padding: 0 10px;
  border: 1px solid var(--line-strong); border-radius: var(--r-m);
  background: var(--surface); color: var(--ink); font: var(--t-body);
  transition: border-color var(--dur-fast) ease-out;
}
.input.mono { font-family: var(--mono); }
.input::placeholder { color: var(--ink-disabled); }
.input:focus, .select:focus { border-color: var(--accent); outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.input:disabled, .select:disabled { opacity: .45; cursor: not-allowed; }
.input[readonly] { background: var(--surface-2); }
.input.is-error, .select.is-error, .field.is-error .input, .field.is-error .select { border-color: var(--red); }
.select { cursor: pointer; }
.field { display: flex; flex-direction: column; gap: var(--space-1); min-width: 0; }
.field > label, .field-label { font: var(--t-small); color: var(--ink-2); }
.field-error { font: var(--t-caption); text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--red); }
.field-hint { font: var(--t-small); color: var(--ink-2); }

input[type="checkbox"], input[type="radio"] { width: 18px; height: 18px; accent-color: var(--accent); }

/* ---------- Сегмент ---------- */
.seg {
  display: inline-flex; padding: 0; gap: 0; overflow: hidden;
  border: 1px solid var(--line-strong); border-radius: var(--r-m); background: var(--surface);
}
.seg button {
  min-height: calc(var(--h-control) - 2px); padding: 0 var(--space-4);
  border: 0; background: transparent; color: var(--ink-2);
  font: var(--t-body); font-weight: 500; cursor: pointer; white-space: nowrap;
  transition: background var(--dur-fast) ease-out, color var(--dur-fast) ease-out;
}
.seg button:not(.active):hover { color: var(--ink); background: var(--surface-2); }
.seg button.active, .seg button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }
.seg button:disabled { opacity: .45; cursor: not-allowed; }
.seg { --seg-thumb-bg: var(--accent); }

/* ---------- Статус, бейдж, динамика ---------- */
.status { display: inline-flex; align-items: center; gap: var(--space-2); font: var(--t-body); font-weight: 600; color: var(--green); }
.status::before { content: ""; width: 8px; height: 8px; border-radius: var(--r-pill); background: currentColor; flex: none; }
.status.is-warn { color: var(--amber); }
.status.is-warn::before { background: var(--amber-dot); }
.status.is-muted { color: var(--ink-2); }
.status.is-muted::before { background: var(--ink-disabled); }
.status.is-error { color: var(--red); }

.badge {
  display: inline-block; padding: var(--space-1) var(--space-2); border-radius: var(--r-s);
  background: var(--accent-soft); color: var(--accent);
  font: var(--t-badge); text-transform: uppercase; letter-spacing: .06em;
}

.delta { display: inline-flex; align-items: baseline; gap: var(--space-1); font: var(--t-small); font-weight: 600; color: var(--ink-2); }
.delta.up { color: var(--green); }
.delta.down { color: var(--red); }
.delta.flat { color: var(--ink-2); }
.delta-base { color: var(--ink-2); font-weight: 400; }

/* ---------- Карточки ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-m); box-shadow: none; }
.card-pad { padding: var(--space-5); }
.card h2, .card-title { margin: 0 0 var(--space-3); font: var(--t-h2); color: var(--ink); }
.card-sectioned { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-m); overflow: hidden; }
.card-sectioned > header, .card-sectioned > .card-header { padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--line-2); font: var(--t-h2); color: var(--ink); }
.card-sectioned > .card-body { padding: var(--space-5); }
.card-sectioned > footer, .card-sectioned > .card-footer { display: flex; justify-content: flex-end; gap: var(--space-2); padding: var(--space-3) var(--space-5); border-top: 1px solid var(--line-2); }

.kpi {
  display: flex; flex-direction: column; gap: 6px; padding: var(--space-4) 18px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-m); min-width: 0;
}
.kpi-label { font: var(--t-caption); text-transform: uppercase; letter-spacing: .06em; color: var(--ink-2); }
.kpi-value { font: var(--t-kpi); letter-spacing: -.01em; font-variant-numeric: tabular-nums; color: var(--ink); }
.kpi-note { font: var(--t-small); color: var(--ink-2); }
.kpi-primary { border-top: 3px solid var(--accent); }
.kpi-warn { background: var(--amber-bg); border-color: var(--amber-line); }
.kpi-warn .kpi-label, .kpi-warn .kpi-value, .kpi-warn .kpi-note { color: var(--amber); }

/* ---------- Таблицы ---------- */
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-m); overflow-x: auto; }
.table { width: 100%; min-width: 720px; border-collapse: collapse; font: var(--t-body); color: var(--ink); }
.table th {
  height: 40px; padding: 0 var(--space-3); background: var(--surface-2); border-bottom: 1px solid var(--line);
  font: var(--t-th); color: var(--ink-2); text-align: left; white-space: nowrap;
}
.table td { height: var(--h-row); padding: 0 var(--space-3); border-bottom: 1px solid var(--line-2); }
.table th:first-child, .table td:first-child { padding-left: var(--space-5); }
.table th:last-child, .table td:last-child { padding-right: var(--space-5); }
.table .num, .table th.num { text-align: right; font-family: var(--mono); font-weight: 500; font-variant-numeric: tabular-nums; }
.table th.num { font-family: var(--sans); }
.table .name { font-weight: 500; }
.table .muted { color: var(--ink-2); }
.table .actions { text-align: right; white-space: nowrap; }
.table.is-zebra tbody tr:nth-child(even) { background: var(--surface-zebra); }
.table tbody tr.is-clickable { cursor: pointer; }
.table tbody tr.is-clickable:hover, .table tbody tr.is-selected { background: var(--surface-selected); }
.table tbody tr.is-selected { font-weight: 600; }
.table tbody tr.is-problem { background: var(--amber-bg); }
.table tbody tr.is-muted td { color: var(--ink-2); }
.table tbody tr.is-subtotal { background: var(--surface-2); font-weight: 600; }
.table tbody tr.before-total td { border-bottom: 2px solid var(--line-total); }
.table tbody tr.total td { height: 48px; border-bottom: 0; font-weight: 600; }
.table .pos { color: var(--green); }
.table .neg { color: var(--red); }

.table-foot {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap;
  padding: var(--space-3) var(--space-5); border-top: 1px solid var(--line);
  font: var(--t-small); color: var(--ink-2);
}

.pager { display: flex; gap: var(--space-1); align-items: center; }
.pager a, .pager button {
  display: inline-grid; place-items: center; min-width: var(--h-control-s); height: var(--h-control-s); padding: 0 var(--space-2);
  border: 1px solid var(--line-strong); border-radius: var(--r-m); background: var(--surface); color: var(--ink);
  font: var(--t-small); text-decoration: none; cursor: pointer;
}
.pager a:hover, .pager button:hover { background: var(--surface-2); }
.pager [aria-current="page"] { background: var(--chip); border-color: var(--chip); color: var(--chip-ink); }
.pager button:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- Шапка страницы ---------- */
.page-header { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: var(--space-4); }
.page-header-text { min-width: 0; }
.page-header-title { font: var(--t-h1); color: var(--ink); margin: 0; }
.page-header-sub { font: var(--t-small); color: var(--ink-2); margin: var(--space-1) 0 0; }
.page-header.is-compact { align-items: center; }
.page-header.is-compact .page-header-title { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.page-header-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); margin-left: auto; }

/* ---------- Уведомления ---------- */
.notice {
  display: flex; align-items: flex-start; gap: var(--space-3); padding: 14px var(--space-5);
  border: 1px solid transparent; border-radius: var(--r-m); font: var(--t-small);
}
.card .notice, .card-sectioned .notice { padding: 10px var(--space-3); }
.notice.warn { background: var(--amber-bg); border-color: var(--amber-line); color: var(--amber-ink); }
.notice.error { background: var(--red-bg); border-color: var(--danger-line); color: var(--red); }
.notice.info { background: var(--blue-bg); color: var(--blue-ink); }
.notice-body { flex: 1; min-width: 0; }

.toast {
  display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-4);
  background: var(--accent); color: var(--on-accent); border-radius: var(--r-m);
  box-shadow: var(--shadow-pop); font: var(--t-small);
}

/* ---------- Дроп-зона и пустое состояние ---------- */
.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--space-2);
  padding: var(--space-6); text-align: center; background: var(--surface);
  border: 1px dashed var(--line-strong); border-radius: var(--r-m); color: var(--ink-2); font: var(--t-small);
  transition: background var(--dur-fast) ease-out, border-color var(--dur-fast) ease-out;
}
.dropzone:hover, .dropzone.is-over { background: var(--surface-selected); border-color: var(--accent); }

.empty, .empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  padding: var(--space-7) var(--space-4); text-align: center; color: var(--ink-2);
}
.empty-state-compact { padding: 14px var(--space-2); }
.empty-title, .empty-state-title { font: var(--t-h3); color: var(--ink); }
.empty p, .empty-state p { margin: 0; max-width: 36em; font: var(--t-small); line-height: 1.5; }

@media (max-width: 767px) {
  .card-pad { padding: var(--space-4); }
  .notice { padding: 10px var(--space-3); }
  .iconbtn { width: var(--h-control); height: var(--h-control); }
}
@media (prefers-reduced-motion: reduce) {
  .btn, .iconbtn, .input, .select, .seg button, .dropzone { transition: none; }
}

.private-money-text { display: inline-block; text-align: right; }

.money { display: inline-block; min-width: var(--money-width); text-align: right; }

