/* Компоненты: кнопки, поля, карточки, таблицы (на узком экране — карточками), бейджи, модалки, тосты. */

/* ---------- Кнопки ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 34px;
  padding: 6px 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font-weight: 600;
  font-size: 13px;
  line-height: 1.2;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}
.btn:hover { background: var(--surface-2); border-color: var(--amber); text-decoration: none; color: var(--text); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn--primary { background: var(--amber); border-color: var(--amber); color: var(--on-amber); }
.btn--primary:hover { background: var(--amber-bright); border-color: var(--amber-bright); color: var(--on-amber); }
.btn--danger { background: var(--danger-strong); border-color: var(--danger-strong); color: #1a0a06; }
.btn--danger:hover { background: var(--danger); border-color: var(--danger); color: #1a0a06; }
.btn--danger-ghost { color: var(--danger); border-color: rgba(240, 120, 90, 0.4); }
.btn--danger-ghost:hover { background: var(--danger-bg); border-color: var(--danger); color: var(--danger); }
.btn--sm { min-height: 28px; padding: 4px 10px; font-size: 12px; }
.btn--block { width: 100%; min-height: 40px; }
.btn .icon { width: 16px; height: 16px; }

/* ---------- Поля ---------- */
.input {
  width: 100%;
  min-height: 36px;
  padding: 7px 10px;
  background: var(--input-bg);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
}
.input:hover { border-color: rgba(226, 162, 76, 0.5); }
.input:focus { outline: none; border-color: var(--amber); box-shadow: 0 0 0 3px rgba(226, 162, 76, 0.18); }
.input:disabled { opacity: 0.6; cursor: not-allowed; }
.input[aria-invalid] { border-color: var(--danger); }
.input--sm { width: auto; min-height: 32px; padding: 5px 8px; font-size: 13px; }
.input--num { font-variant-numeric: tabular-nums; }
.input--mono { font-family: var(--font-mono); font-size: 13px; }
.input--area { resize: vertical; min-height: 72px; }
select.input { padding-right: 28px; }
input[type="date"].input { color-scheme: dark; }

.form { display: grid; gap: 12px; }
.form__grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.form__error, .field__error { color: var(--danger); font-size: 12px; }
.form__error { padding: 8px 10px; background: var(--danger-bg); border-radius: var(--radius-sm); font-size: 13px; }
.form__actions { display: flex; justify-content: flex-end; }
.field { display: grid; gap: 5px; align-content: start; min-width: 0; }
.field--wide { grid-column: 1 / -1; }
.field__label { font-size: 12px; font-weight: 600; color: var(--text-2); }
.field__hint { font-size: 12px; color: var(--muted); }
.field--check { align-self: end; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; color: var(--text); }
.checkbox { width: 16px; height: 16px; accent-color: var(--amber); }

/* ---------- Карточки ---------- */
.card {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.card__head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px 16px;
  padding: 14px 16px 0;
}
.card__title { font-size: 15px; }
.card__subtitle { font-size: 12px; color: var(--muted); margin-top: 2px; }
.card__actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.card__body { padding: 14px 16px 16px; min-width: 0; }
.card--flush > .card__body { padding: 8px 0 4px; }
.card--flush > .card__body > .empty, .card--flush > .card__body > .loading, .card--flush > .card__body > div > .empty { margin: 8px 16px 12px; }

/* ---------- Таблицы ---------- */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { padding: 9px 12px; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--line); }
.table thead th {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
  background: var(--surface);
}
.table th:first-child, .table td:first-child { padding-left: 16px; }
.table th:last-child, .table td:last-child { padding-right: 16px; }
.table .num { text-align: right; }
.table tbody tr:hover { background: rgba(226, 162, 76, 0.04); }
.table tbody tr:last-child td, .table tbody tr:last-child th { border-bottom: 0; }
.table tfoot td { border-top: 1px solid var(--line-strong); border-bottom: 0; color: var(--text); font-weight: 600; }
.table tr.is-muted td, .table tr.is-muted th { color: var(--faint); }
.table tr.is-muted a { color: var(--muted); }
.cell-actions { text-align: right; white-space: nowrap; width: 1%; }
.cell-stack { display: flex; flex-direction: column; align-items: flex-start; gap: 1px; min-width: 0; }
.cell-stack--end { align-items: flex-end; }
.cell-sub { font-size: 11px; color: var(--muted); }
.table tr.is-limit td { background: rgba(224, 103, 75, 0.07); }
.table tr.is-limit td:first-child { box-shadow: inset 3px 0 0 var(--danger-strong); }

/* Узкий экран: строка таблицы — карточка, у ячейки — подпись колонки (data-label). */
@media (max-width: 720px) {
  .table--stack thead { display: none; }
  .table--stack, .table--stack tbody, .table--stack tfoot, .table--stack tr, .table--stack td { display: block; width: 100%; }
  .table--stack tr { padding: 10px 16px; border-bottom: 1px solid var(--line); }
  .table--stack tbody tr:last-child { border-bottom: 0; }
  .table--stack td,
  .table--stack td:first-child,
  .table--stack td:last-child {
    display: grid;
    grid-template-columns: minmax(84px, 34%) minmax(0, 1fr);
    gap: 10px;
    padding: 5px 0;
    border: 0;
    text-align: left;
    white-space: normal;
  }
  .table--stack td::before {
    content: attr(data-label);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--muted);
  }
  .table--stack td.num { text-align: left; }
  .table--stack td.cell-actions { width: 100%; }
  .table--stack tr.is-limit td:first-child { box-shadow: none; }
  .table--stack tr.is-limit { box-shadow: inset 3px 0 0 var(--danger-strong); background: rgba(224, 103, 75, 0.07); }
  .table--stack tr.is-limit td { background: none; }
  .table-wrap { overflow-x: visible; }
}

/* ---------- Бейджи ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
  border: 1px solid transparent;
}
.badge--ok { color: var(--ok); background: var(--ok-bg); border-color: rgba(143, 202, 120, 0.3); }
.badge--warn { color: var(--warn); background: var(--warn-bg); border-color: rgba(240, 189, 87, 0.3); }
.badge--danger { color: var(--danger); background: var(--danger-bg); border-color: rgba(243, 154, 126, 0.35); }
.badge--info { color: var(--info); background: var(--info-bg); border-color: rgba(156, 188, 240, 0.3); }
.badge--accent { color: var(--amber-bright); background: var(--amber-wash); border-color: var(--line-strong); }
.badge--muted { color: var(--muted); background: rgba(168, 147, 122, 0.1); border-color: rgba(168, 147, 122, 0.25); }

/* ---------- Сведения ---------- */
.info-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px 24px; }
.info-list__row { display: grid; gap: 3px; min-width: 0; align-content: start; }
.info-list dt { font-size: 11px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.info-list dd { color: var(--text); overflow-wrap: anywhere; }

.meter { display: block; width: 100%; min-width: 60px; height: 4px; border-radius: 2px; background: var(--surface-3); overflow: hidden; }
.meter__fill { display: block; height: 100%; border-radius: 2px; }
.meter__fill--accent { background: var(--amber); }
.meter__fill--warn { background: var(--warn); }
.meter__fill--danger { background: var(--danger-strong); }

.callout { padding: 12px 14px; border-radius: var(--radius-sm); font-size: 13px; line-height: 1.5; color: var(--text-2); }
.callout--warn { background: var(--warn-bg); border: 1px solid rgba(240, 189, 87, 0.35); }
.callout--warn strong { color: var(--warn); }
.callout--info { background: var(--info-bg); border: 1px solid rgba(156, 188, 240, 0.3); }
.callout--info strong { color: var(--info); }
.callout--danger { background: var(--danger-bg); border: 1px solid rgba(243, 154, 126, 0.35); }
.callout--danger strong { color: var(--danger); }

/* ---------- Состояния ---------- */
.empty { display: grid; justify-items: center; gap: 8px; padding: 40px 16px; text-align: center; }
.empty__mark { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line-strong); box-shadow: inset 0 0 0 6px var(--amber-wash); margin-bottom: 4px; }
.empty__title { color: var(--text); font-weight: 600; font-size: 15px; }
.empty__text { color: var(--muted); max-width: 440px; }
.empty .btn { margin-top: 6px; }

.loading { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 32px 16px; color: var(--muted); }
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--line-strong); border-top-color: var(--amber); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.error-block { display: grid; justify-items: center; gap: 10px; padding: 28px 16px; color: var(--danger); text-align: center; }
.is-loading { opacity: 0.55; transition: opacity 0.15s; pointer-events: none; }

/* ---------- Модальные окна ---------- */
.modal {
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100vh - 32px);
  padding: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  color: var(--text-2);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}
.modal:not([open]) { display: none; }
.modal--sm { width: min(420px, calc(100vw - 24px)); }
.modal--lg { width: min(760px, calc(100vw - 24px)); }
.modal::backdrop { background: rgba(8, 5, 3, 0.72); }
.modal__header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 18px 0; }
.modal__title { font-size: 16px; }
.modal__close {
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}
.modal__close:hover { background: var(--surface-2); color: var(--text); }
.modal__body { display: grid; gap: 14px; padding: 14px 18px; overflow-y: auto; }
.modal__text { color: var(--text-2); }
.modal__footer { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; padding: 12px 18px 16px; border-top: 1px solid var(--line); }

/* ---------- Тосты ---------- */
.toasts {
  position: fixed;
  inset: auto 16px 16px auto;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  overflow: visible;
  color: inherit;
  z-index: 1000;
  display: grid;
  gap: 8px;
  width: min(380px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 10px 10px 12px;
  background: var(--surface-3);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
  color: var(--text);
  pointer-events: auto;
  animation: toast-in 0.18s ease-out;
}
.toast.is-leaving { opacity: 0; transform: translateY(6px); transition: opacity 0.18s, transform 0.18s; }
.toast__dot { width: 8px; height: 8px; margin-top: 6px; border-radius: 50%; flex: none; background: var(--info); }
.toast--success .toast__dot { background: var(--ok); }
.toast--error { border-color: rgba(243, 154, 126, 0.5); }
.toast--error .toast__dot { background: var(--danger); }
.toast__text { flex: 1; font-size: 13px; overflow-wrap: anywhere; }
.toast__close { border: 0; background: none; color: var(--muted); font-size: 18px; line-height: 1; cursor: pointer; padding: 0 4px; }
.toast__close:hover { color: var(--text); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }

@media (max-width: 560px) {
  .form__grid { grid-template-columns: minmax(0, 1fr); }
}
