/* Компоненты дизайн-системы (перенос из docs/design-system/index.html). */

.icon--sm {
  width: 16px;
  height: 16px;
}

.mono {
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 20px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
}

/* --- Кнопки (дополнение к app.css) --- */

.btn--secondary {
  background: var(--color-surface);
  border-color: var(--color-border-strong);
  color: var(--color-text);
}
.btn--secondary:hover {
  background: var(--color-neutral-bg);
  text-decoration: none;
}
.btn--danger {
  background: var(--color-danger-bg);
  border-color: var(--color-danger);
  color: var(--color-danger-text);
}
.btn--danger:hover {
  background: var(--color-danger);
  color: #fff;
  text-decoration: none;
}
.btn--danger-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--color-danger);
}
.btn--danger-ghost:hover {
  background: var(--color-danger-bg);
  color: var(--color-danger-text);
  text-decoration: none;
}
.btn--sm {
  padding: 6px 12px;
  min-height: 32px;
  font-size: 13px;
}
.btn--icon {
  padding: 9px;
}

/* --- Поля форм --- */

.field__hint {
  font-size: 12px;
  color: var(--color-text-secondary);
  margin-top: var(--space-1);
}

.input,
.textarea,
.select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  font-size: 14px;
  line-height: 20px;
  min-height: 40px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus,
.textarea:focus,
.select:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: var(--focus-ring);
}
.input::placeholder,
.textarea::placeholder {
  color: var(--color-text-muted);
}
.form-label {
  display: inline-flex;
  align-items: baseline;
  gap: var(--space-1);
}

.form-required,
.inline-field-error {
  color: var(--color-danger-text);
}

.inline-field-error {
  display: block;
  width: 100%;
}

.inline-field-error[hidden] {
  display: none;
}

.inline-field-invalid,
.inline-field-invalid:focus,
.ts-control.inline-field-invalid {
  border-color: var(--color-danger) !important;
}

.input--error,
.textarea--error,
.select--error {
  border-color: var(--color-danger);
}
.input--error:focus,
.textarea--error:focus,
.select--error:focus {
  box-shadow: 0 0 0 3px rgba(229, 72, 77, 0.2);
}
.input:disabled,
.select:disabled,
.textarea:disabled {
  background: var(--color-neutral-bg);
  color: var(--color-text-muted);
  cursor: not-allowed;
}
.textarea {
  min-height: 80px;
  resize: vertical;
}
.select {
  appearance: none;
  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='%236B7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 32px;
}

.phone-input {
  display: flex;
  align-items: center;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  overflow: hidden;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.phone-input:focus-within {
  border-color: var(--color-accent);
  box-shadow: var(--focus-ring);
}
.phone-input__prefix {
  padding: 0 12px;
  color: var(--color-text-secondary);
  font-size: 14px;
  border-right: 1px solid var(--color-border);
  user-select: none;
  line-height: 38px;
}
.phone-input .input,
.phone-input input {
  border: none;
  box-shadow: none;
  min-height: 38px;
}

/* --- Бейджи --- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px 10px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 500;
  line-height: 18px;
}
.badge--success {
  background: var(--color-success-bg);
  color: var(--color-success-text);
}
.badge--warning {
  background: var(--color-warning-bg);
  color: var(--color-warning-text);
}
.badge--danger {
  background: var(--color-danger-bg);
  color: var(--color-danger-text);
}
.badge--info {
  background: var(--color-info-bg);
  color: var(--color-info-text);
}
.badge--neutral {
  background: var(--color-neutral-bg);
  color: var(--color-neutral-text);
}
.badge--complete {
  background: var(--color-complete-bg);
  color: var(--color-complete-text);
}

/* --- Подгрузка списков --- */

.list-feed__footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4) 0 var(--space-2);
}

.list-feed__status {
  margin: 0;
  color: var(--color-text-muted);
  font-size: 14px;
}

.list-feed__more {
  min-width: 160px;
}

.list-feed__sentinel {
  width: 100%;
  height: 1px;
}

.list-feed__error {
  margin: 0 0 var(--space-4);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--color-danger-bg);
  color: var(--color-danger-text);
  font-size: 14px;
}

/* --- Таблицы --- */

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
}
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.table th {
  text-align: left;
  padding: var(--space-3) var(--space-4);
  color: var(--color-text-secondary);
  font-weight: 500;
  font-size: 12px;
  line-height: 16px;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-bg);
  white-space: nowrap;
}
.table td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  color: var(--color-text);
  white-space: nowrap;
}
.table tbody tr:last-child td {
  border-bottom: none;
}
.table tbody tr:hover td {
  background: var(--color-neutral-bg);
}
.table__id {
  font-family: var(--font-mono);
  color: var(--color-text-secondary);
  font-variant-numeric: tabular-nums;
}
.table__actions {
  width: 1%;
  white-space: nowrap;
  text-align: right;
}
.table__archived {
  opacity: 0.65;
  background: var(--color-neutral-bg);
}

/* --- Пагинация --- */

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  margin-top: var(--space-4);
}
.pagination__btn {
  min-height: 36px;
  min-width: 36px;
  padding: 7px 10px;
  border: 1px solid var(--color-border-strong);
  background: var(--color-surface);
  border-radius: var(--radius-md);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-secondary);
  text-decoration: none;
  font-size: 14px;
}
.pagination__btn:hover {
  background: var(--color-neutral-bg);
  color: var(--color-text);
  text-decoration: none;
}
.pagination__btn--active {
  background: var(--color-accent);
  color: #fff;
  border-color: var(--color-accent);
}
.pagination__btn--active:hover {
  background: var(--color-accent-hover);
  color: #fff;
}
.pagination__info {
  font-size: 14px;
  color: var(--color-text-secondary);
  padding: 0 var(--space-2);
}

/* --- Фильтры --- */

.search-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: center;
}
.search-row .input {
  width: 260px;
}
.search-field {
  position: relative;
  display: flex;
  align-items: center;
}
.search-field__icon {
  position: absolute;
  left: 10px;
  color: var(--color-text-muted);
  pointer-events: none;
}
.search-field .input {
  padding-left: 36px;
}

/* --- Toolbar списков: поиск сжимается, кнопка фильтров — фиксированная --- */

.search-field--toolbar-grow,
.inventory-search-field--grow,
.orders-search-field--grow,
.customers-search-field--grow,
.inventory-history__search {
  flex: 1 1 0;
  min-width: 0;
}

.search-field--toolbar-grow .input,
.inventory-search-field--grow .input,
.orders-search-field--grow .input,
.customers-search-field--grow .input,
.inventory-history__search .input {
  width: 100%;
  min-width: 0;
}

.list-toolbar-row,
.inventory-list__filters-bar .inventory-list__toolbar,
.orders-list__filters-v4 .orders-list__toolbar,
.customers-list__filters-v4 .customers-list__toolbar,
.inventory-history__toolbar-row {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
}

.filters-toggle,
.inventory-filters-toggle,
.orders-filters-toggle,
.customers-filters-toggle,
.inventory-history__filters-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  flex: 0 0 auto;
  box-sizing: border-box;
  width: 56px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text-secondary);
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
}

.filters-toggle:hover,
.inventory-filters-toggle:hover,
.orders-filters-toggle:hover,
.customers-filters-toggle:hover,
.inventory-history__filters-toggle:hover {
  background: var(--color-neutral-bg);
  color: var(--color-text);
}

.filters-toggle:focus-visible,
.inventory-filters-toggle:focus-visible,
.orders-filters-toggle:focus-visible,
.customers-filters-toggle:focus-visible,
.inventory-history__filters-toggle:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.filters-toggle__chevron,
.inventory-filters-toggle__chevron,
.orders-filters-toggle__chevron,
.customers-filters-toggle__chevron,
.inventory-history__filters-chevron {
  flex-shrink: 0;
  transition: transform 0.2s ease;
}

.filters-toggle__chevron.is-open,
.inventory-filters-toggle__chevron.is-open,
.orders-filters-toggle__chevron.is-open,
.customers-filters-toggle__chevron.is-open,
.inventory-history__filters-chevron.is-open {
  transform: rotate(180deg);
}

.filters-toggle__label,
.orders-filters-toggle__label,
.customers-filters-toggle__label {
  display: none;
  white-space: nowrap;
}

@media (min-width: 601px) {
  .filters-toggle--labeled,
  .orders-filters-toggle,
  .customers-filters-toggle {
    width: auto;
    min-width: 112px;
    padding: 0 12px;
  }

  .filters-toggle--labeled .filters-toggle__label,
  .orders-filters-toggle__label,
  .customers-filters-toggle__label {
    display: inline;
  }
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 6px 12px;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-pill);
  background: var(--color-surface);
  font-size: 13px;
  cursor: pointer;
  color: var(--color-text-secondary);
  text-decoration: none;
}
.chip:hover {
  border-color: var(--color-border-strong);
  background: var(--color-neutral-bg);
  text-decoration: none;
}
.chip.is-active {
  background: var(--color-success-bg);
  border-color: var(--color-success);
  color: var(--color-success-text);
}

/* List pages: разделитель между фильтрами и списком */
.customers-list__main > .customers-status-chips,
.orders-list__main > .customers-status-chips,
.catalog-list--v3 .catalog-sort,
.inventory-list--v5 .inventory-list__filters-bar {
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--color-border);
}

.catalog-list--v3 .catalog-sort,
.inventory-list--v5 .inventory-list__filters-bar {
  margin-bottom: var(--space-4);
}

/* --- Вкладки --- */

.tabs {
  display: flex;
  gap: var(--space-1);
  border-bottom: 1px solid var(--color-border);
  margin-bottom: var(--space-5);
}
.tab {
  padding: var(--space-3) var(--space-4);
  font-size: 14px;
  font-weight: 500;
  color: var(--color-text-secondary);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
  background: transparent;
  border-top: none;
  border-left: none;
  border-right: none;
  transition: color 0.15s, border-color 0.15s;
  text-decoration: none;
}
.tab:hover {
  color: var(--color-text);
  text-decoration: none;
}
.tab.is-active {
  color: var(--color-accent);
  border-bottom-color: var(--color-accent);
}
.tab:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-md) var(--radius-md) 0 0;
}
.tab-panel {
  display: none;
}
.tab-panel.is-active {
  display: block;
}

/* --- Пустые состояния --- */

.empty {
  text-align: center;
  padding: var(--space-12) var(--space-6);
  background: var(--color-surface);
  border: 1px dashed var(--color-border-strong);
  border-radius: var(--radius-lg);
}
.empty__icon {
  color: var(--color-text-muted);
  margin-bottom: var(--space-4);
}
.empty__title {
  font-size: 18px;
  font-weight: 600;
  margin: 0 0 var(--space-2);
}
.empty__text {
  color: var(--color-text-secondary);
  margin: 0 auto var(--space-5);
  max-width: 360px;
}

.list-empty {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  min-height: min(44vh, 320px);
  padding: var(--space-6) var(--space-4);
}

.empty--list {
  border: none;
  background: transparent;
  padding: var(--space-6) var(--space-4);
  max-width: 420px;
  width: 100%;
}

.empty--list .empty__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 72px;
  height: 72px;
  margin: 0 auto var(--space-5);
  border-radius: var(--radius-pill);
  background: var(--color-neutral-bg);
  color: var(--color-text-muted);
}

.empty--list .empty__icon .icon {
  width: 32px;
  height: 32px;
}

.empty--list .empty__title {
  font-size: 17px;
}

.empty--list .empty__text {
  font-size: 14px;
  line-height: 1.55;
  margin-bottom: 0;
}

/* --- Мобильная адаптивность --- */

@media (max-width: 900px) {
  .search-row .input {
    width: 100%;
  }
  .search-field {
    flex: 1;
    min-width: 140px;
  }
}

@media (max-width: 640px) {
  .search-row .input {
    width: 100%;
  }
  .table-wrap--mobile-cards .table,
  .table-wrap--mobile-cards .table thead,
  .table-wrap--mobile-cards .table tbody,
  .table-wrap--mobile-cards .table th,
  .table-wrap--mobile-cards .table td,
  .table-wrap--mobile-cards .table tr {
    display: block;
    width: 100%;
  }
  .table-wrap--mobile-cards .table thead {
    display: none;
  }
  .table-wrap--mobile-cards .table tr {
    padding: var(--space-4);
    border-bottom: 1px solid var(--color-border);
  }
  .table-wrap--mobile-cards .table td {
    display: flex;
    justify-content: space-between;
    padding: var(--space-1) 0;
    border: none;
    white-space: normal;
  }
  .table-wrap--mobile-cards .table td::before {
    content: attr(data-label);
    color: var(--color-text-secondary);
    font-size: 12px;
    margin-right: var(--space-3);
  }
  .table-wrap--mobile-cards .table td.table__actions {
    justify-content: flex-end;
    padding-top: var(--space-2);
  }
  .table-wrap--mobile-cards .table td.table__actions::before {
    display: none;
  }
}

/* --- Flash-сообщения (django.contrib.messages) --- */

.flash-messages {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

.flash-messages__item {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-lg);
  font-size: 14px;
  line-height: 1.45;
}

.flash-messages__text {
  margin: 0;
}

.flash-messages__item--error,
.flash-messages__item--danger {
  background: var(--color-danger-bg);
  color: var(--color-danger-text);
  border: 1px solid rgba(229, 72, 77, 0.2);
}

.flash-messages__item--warning {
  background: var(--color-warning-bg);
  color: var(--color-warning-text);
  border: 1px solid rgba(139, 108, 54, 0.15);
}

.flash-messages__item--success {
  background: var(--color-success-bg);
  color: var(--color-success-text);
  border: 1px solid rgba(90, 125, 104, 0.2);
}

.flash-messages__item--info {
  background: var(--color-info-bg);
  color: var(--color-info-text);
  border: 1px solid rgba(59, 130, 246, 0.15);
}
