/* =================================================================
   Portal-Alpateks — основной CSS
   Чистый CSS, без сборщиков. Все UI-токены определены в design-tokens.css
   (цвета, шрифты, отступы, тени, кнопки). Этот файл только описывает
   компоненты, ссылаясь на токены через var(--token-name).
   Подключение в base.html:
     <link rel="stylesheet" href="design-tokens.css">
     <link rel="stylesheet" href="main.css">
   ================================================================= */

/* --- Reset --- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-family);
    font-size: 15px;
    line-height: 1.5;
    color: var(--color-text);
    background: var(--color-bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

img {
    max-width: 100%;
    height: auto;
}

/* =================================================================
   Auth (login page)
   ================================================================= */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
}

.auth-container {
    width: 100%;
    max-width: 400px;
}

.auth-card {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 40px 32px;
}

.auth-logo {
    text-align: center;
    margin-bottom: 32px;
}

.auth-logo img {
    display: block;
    margin: 0 auto 16px;
}

.auth-title {
    font-size: 24px;
    font-weight: 700;
    color: var(--color-primary);
    margin-bottom: 4px;
}

.auth-subtitle {
    font-size: 14px;
    color: var(--color-text-muted);
}

.auth-form {
    margin-top: 24px;
}

.auth-footer {
    margin-top: 24px;
    text-align: center;
    font-size: 12px;
    color: var(--color-text-muted);
}

/* =================================================================
   Forms
   ================================================================= */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 6px;
}

.form-input {
    display: block;
    width: 100%;
    padding: var(--input-padding-y) var(--input-padding-x);
    font-size: var(--input-font-size);
    line-height: var(--input-line-height);
    font-family: inherit;
    color: var(--input-color);
    background: var(--input-bg);
    border: var(--input-border-width) solid var(--input-border-color);
    border-radius: var(--input-radius);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.form-input:focus {
    outline: none;
    border-color: var(--input-focus-border-color);
    box-shadow: var(--input-focus-ring);
}

.form-input::placeholder {
    color: var(--input-placeholder-color);
}

/* =================================================================
   Buttons
   ================================================================= */
.btn {
    display: inline-block;
    padding: var(--btn-padding-y) var(--btn-padding-x);
    font-size: var(--btn-font-size);
    font-weight: var(--btn-font-weight);
    line-height: var(--btn-line-height);
    font-family: inherit;
    text-align: center;
    text-decoration: none;
    background: var(--btn-bg);
    color: var(--btn-color);
    border: var(--btn-border-width) solid var(--btn-border-color);
    border-radius: var(--btn-radius);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.btn:hover {
    background: var(--btn-hover-bg);
    color: var(--btn-hover-color);
    border-color: var(--btn-hover-border-color);
}

.btn-primary {
    background: var(--btn-primary-bg);
    color: var(--btn-primary-color);
    border-color: var(--btn-primary-border-color);
}
.btn-primary:hover {
    background: var(--btn-primary-hover-bg);
    color: var(--btn-primary-hover-color);
    border-color: var(--btn-primary-hover-border-color);
}

/* Подсказка под полем формы (например, пояснение «Сколько единиц?») */
.ie-field-hint {
    font-size: 11px;
    margin-top: 4px;
    line-height: 1.4;
}

/* Группировка единиц в storage_list (для is_unique_unit).
   Агрегатор выглядит как обычная карточка tc-item-card; кнопка ▶ слева. */
.tc-group-head { cursor: pointer; }
.tc-group-head:hover { background: #f8fafc; }
.tc-group-head .tc-group-toggle-left {
    flex: 0 0 auto;
    width: 26px; height: 26px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    background: white;
    color: #64748b;
    font-size: 10px;
    cursor: pointer;
    padding: 0;
    margin-right: 6px;
    transition: background 0.1s, border-color 0.1s;
}
.tc-group-head .tc-group-toggle-left:hover { background: #f1f5f9; border-color: #3b82f6; color: #1e40af; }
.tc-group-hidden { display: none; }

/* Группировка единиц в item_list (для is_unique_unit) */
.it-group-head { cursor: pointer; }
.it-group-head .it-group-toggle {
    position: absolute;
    bottom: 4px; right: 4px;
    background: rgba(255,255,255,0.85);
    color: #1e40af;
    width: 18px; height: 18px;
    border-radius: 4px;
    font-size: 10px;
    display: flex; align-items: center; justify-content: center;
    font-weight: bold;
}
.it-group-hidden { display: none; }
.it-group-row td:first-child { padding-left: 24px; }

/* Наличие в списке артикулов (model_list.html) */
.ml-stock summary {
    cursor: pointer;
    font-size: 12px;
    list-style: none;
    padding: 2px 6px;
    border-radius: 4px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    display: inline-block;
}
.ml-stock summary::-webkit-details-marker { display: none; }
.ml-stock summary:hover { background: #f1f5f9; }
.ml-stock[open] summary { background: #dbeafe; border-color: #93c5fd; }
.ml-stock-list {
    margin-top: 4px;
    padding: 6px 8px;
    background: #f8fafc;
    border-radius: 4px;
    border: 1px solid #e2e8f0;
    font-size: 11px;
    min-width: 280px;
    max-width: 380px;
}
.ml-stock-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 2px 0;
    flex-wrap: wrap;
}
.ml-stock-qty {
    background: #3b82f6;
    color: white;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 8px;
    font-size: 10px;
    min-width: 22px;
    text-align: center;
}
.ml-stock-storage { font-weight: 500; color: #0f172a; }
.ml-stock-status { font-size: 11px; }
.ml-stock-responsible { color: #64748b; }
.ml-stock-project { color: #64748b; }

.btn-primary:hover {
    background: var(--color-primary-hover);
}

/* Серый стиль для неактивной кнопки «+ Добавить позицию» в шапке панели. */
.tc-add-item-btn:disabled,
.tc-add-item-btn[disabled] {
    background: #e2e8f0 !important;
    color: #94a3b8 !important;
    cursor: not-allowed;
    border-color: #cbd5e1;
    box-shadow: none;
}

.btn-ghost {
    background: var(--btn-ghost-bg);
    color: var(--btn-ghost-color);
    border-color: var(--btn-ghost-border-color);
}
.btn-ghost:hover {
    background: var(--btn-ghost-hover-bg);
    color: var(--btn-ghost-hover-color);
}

.btn-block {
    display: block;
    width: 100%;
}

/* =================================================================
   Messages
   ================================================================= */
.messages {
    margin-bottom: 16px;
}

.message {
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 13px;
    margin-bottom: 8px;
}

.message-error {
    background: #fef2f2;
    color: var(--color-error);
    border: 1px solid #fecaca;
}

.message-success {
    background: #f0fdf4;
    color: var(--color-success);
    border: 1px solid #bbf7d0;
}

.message-info {
    background: #eff6ff;
    color: var(--color-accent);
    border: 1px solid #bfdbfe;
}

/* =================================================================
   Home page (after login)
   ================================================================= */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    box-shadow: var(--shadow-sm);
}

.topbar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 16px;
}

.topbar-nav {
    display: flex;
    align-items: center;
    gap: 16px;
}

.user-info {
    font-size: 14px;
    color: var(--color-text-muted);
}

.logout-form {
    display: inline;
}

.home-content {
    max-width: 800px;
    margin: 40px auto;
    padding: 0 20px;
}

.welcome-card {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    padding: 32px;
}

.welcome-card h1 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 8px;
}

.welcome-card > p {
    color: var(--color-text-muted);
    margin-bottom: 24px;
}

.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 24px;
    font-size: 14px;
}

.alert-info {
    background: #eff6ff;
    color: #1e40af;
    border: 1px solid #bfdbfe;
}

.alert a {
    color: inherit;
    font-weight: 600;
}

.user-details {
    margin-top: 24px;
}

.user-details h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 12px;
}

.data-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    /* Лёгкая обводка + скругление углов — таблица выглядит «карточкой» */
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--color-surface);
    font-variant-numeric: tabular-nums;
}

.data-table th,
.data-table td {
    padding: 11px 16px;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
    font-size: 14px;
    vertical-align: middle;
}

/* Последняя строка — без нижней границы */
.data-table tbody tr:last-child td {
    border-bottom: none;
}

.data-table th {
    font-weight: 600;
    color: var(--color-text-muted);
    background: var(--color-bg);
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: 0.04em;
    /* В горизонтальных таблицах (списки) колонки тянутся по содержимому.
       В вертикальных (форма ключ-значение) отдельные шаблоны задают ширину явно. */
}

.data-table code {
    font-family: var(--font-mono);
    font-size: 13px;
    background: var(--color-bg);
    padding: 2px 6px;
    border-radius: 4px;
}

/* =================================================================
   Mobile
   ================================================================= */
@media (max-width: 480px) {
    .auth-card {
        padding: 28px 20px;
    }

    .welcome-card {
        padding: 20px;
    }

    .topbar {
        padding: 10px 16px;
    }
}

/* =================================================================
   Внутренние страницы (после логина)
   ================================================================= */
.page-content {
    max-width: 1400px;
    margin: 12px auto;
    padding: 0 24px;
}

.page-messages {
    margin-bottom: 20px;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}

.page-header h1 {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 2px;
    line-height: 1.2;
}

.page-subtitle {
    font-size: 13px;
    color: var(--color-text-muted);
}

.page-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.back-link {
    color: var(--color-text-muted);
    text-decoration: none;
}
.back-link:hover { text-decoration: underline; }

/* Topbar */
.topbar-brand-link {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 16px;
    color: var(--color-text);
    text-decoration: none;
}

.topbar-link {
    font-size: 14px;
    color: var(--color-text-muted);
    text-decoration: none;
    padding: 4px 8px;
    border-radius: 4px;
}
.topbar-link:hover {
    color: var(--color-text);
    background: var(--color-bg);
}

.user-info {
    font-size: 14px;
    color: var(--color-text-muted);
}

/* Quick links (на главной) */
.quick-links {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 12px;
    margin-top: 24px;
}

.quick-link {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px;
    background: var(--color-bg);
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--color-text);
    transition: background 0.15s;
}
.quick-link:hover {
    background: #e2e8f0;
}

.quick-link-icon {
    font-size: 28px;
    line-height: 1;
}

.quick-link-title {
    font-weight: 600;
}

.quick-link-desc {
    font-size: 13px;
    color: var(--color-text-muted);
}

/* Search form */
.search-form {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}
.search-form .form-input {
    flex: 1;
    min-width: 240px;
}

/* Badges */
.badge {
    display: inline-block;
    padding: 2px 8px;
    font-size: 12px;
    font-weight: 600;
    border-radius: 4px;
}
.badge-success { background: #dcfce7; color: #15803d; }
.badge-error { background: #fee2e2; color: #b91c1c; }
.badge-info { background: #dbeafe; color: #1e40af; }

.data-table-hover tbody tr:hover {
    background: var(--color-bg);
}

.user-link {
    font-weight: 600;
    color: var(--color-text);
    text-decoration: none;
}
.user-link:hover {
    color: var(--color-accent);
}

.user-id-cell {
    font-size: 12px;
}

.actions {
    text-align: right;
}

.btn-sm {
    padding: 4px 10px;
    font-size: 13px;
}

.btn-danger {
    background: var(--btn-danger-bg);
    color: var(--btn-danger-color);
    border-color: var(--btn-danger-border-color);
}
.btn-danger:hover {
    background: var(--btn-danger-hover-bg);
    color: var(--btn-danger-hover-color);
    border-color: var(--btn-danger-hover-border-color);
}
.btn-danger:disabled {
    background: #cbd5e1;
    border-color: #cbd5e1;
    color: #475569;
    cursor: not-allowed;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 28px 16px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    color: var(--color-text-muted);
}
.empty-state p { margin-bottom: 12px; }

/* Pagination */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-top: 20px;
    padding: 16px;
}
.pagination-info {
    color: var(--color-text-muted);
    font-size: 14px;
}

/* Detail grid (карточка пользователя) */
.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
    gap: 16px;
}

.detail-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: var(--shadow-sm);
}

.detail-card h2 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--color-border);
}

/* Form sections */
.user-form {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-sm);
}

.form-section {
    margin-bottom: 14px;
    padding: 12px 14px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
}
.form-section:last-of-type {
    margin-bottom: 0;
}

.form-section-title {
    font-size: 12px;
    font-weight: 600;
    color: #475569;
    margin-bottom: 10px;
    text-transform: none;
    letter-spacing: 0;
    display: flex;
    align-items: center;
    gap: 6px;
}

.form-section-help {
    font-size: 13px;
    color: var(--color-text-muted);
    margin-bottom: 12px;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
}

.form-group-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
}
.form-group-checkbox label {
    margin: 0;
    font-weight: normal;
    cursor: pointer;
}

.form-checkbox {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.field-help {
    font-size: 12px;
    color: var(--color-text-muted);
    margin-top: 4px;
}

.field-error {
    font-size: 13px;
    color: var(--color-error);
    margin-top: 4px;
    font-weight: 500;
}

.form-actions {
    display: flex;
    gap: 8px;
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid var(--color-border);
}

/* Home page adjustments */
.welcome-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 32px;
    box-shadow: var(--shadow-sm);
}

.welcome-card h1 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 8px;
}
.welcome-card > p {
    color: var(--color-text-muted);
}

/* =================================================================
   Admin Hub (3-tile grid)
   ================================================================= */
.admin-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 16px;
}

.admin-tile {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 20px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    text-decoration: none;
    color: var(--color-text);
    transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
    box-shadow: var(--shadow-sm);
}
.admin-tile:hover {
    border-color: var(--color-accent);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.admin-tile-icon {
    font-size: 36px;
    line-height: 1;
    flex-shrink: 0;
}

.admin-tile-content {
    flex: 1;
    min-width: 0;
}

.admin-tile-content h2 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 4px;
}

.admin-tile-desc {
    font-size: 13px;
    color: var(--color-text-muted);
    margin-bottom: 8px;
}

.admin-tile-stats {
    display: flex;
    gap: 12px;
    font-size: 12px;
    color: var(--color-text-muted);
}
.admin-tile-stats strong {
    color: var(--color-text);
    font-weight: 600;
}

.admin-tile-arrow {
    font-size: 24px;
    color: var(--color-text-muted);
    flex-shrink: 0;
}
.admin-tile:hover .admin-tile-arrow {
    color: var(--color-accent);
}

/* =================================================================
   App Header (логотип, навигация, dropdown пользователя)
   ================================================================= */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 300;  /* выше preview-banner (200), чтобы кнопки в topbar работали в режиме превью */
}

.app-header-left {
    flex-shrink: 0;
}

.app-header-logo {
    height: 36px;
    width: 36px;
    display: block;
}

/* Логотип слева, центральная группа (навигация + кнопка ширины) по центру, юзер справа.
   Шапка — это трёхколоночный flex: left | mid | right. */
.app-header-nav {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 14px;
}

.app-header-center {
    flex: 0 0 auto;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-left: 14px;
}

/* Центральная группа: навигация + переключатель ширины — растягивается и центрируется. */
.app-header-mid {
    flex: 1 1 auto;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 24px;
    min-width: 0;
}

.app-nav-link {
    font-size: 13px;
    font-weight: 500;
    color: var(--color-text-muted);
    text-decoration: none;
    padding: 4px 0;
    border-bottom: 2px solid transparent;
    transition: color 0.15s, border-color 0.15s;
}
.app-nav-link:hover {
    color: var(--color-text);
}
.app-nav-link.active {
    color: var(--color-primary);
    border-bottom-color: var(--color-accent);
    font-weight: 600;
}

.app-header-right {
    flex-shrink: 0;
    position: relative;
}

.app-header-user {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px 6px 6px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius);
    cursor: pointer;
    font-family: inherit;
    font-size: 14px;
    color: var(--color-text);
    transition: background 0.15s, border-color 0.15s;
}
.app-header-user:hover {
    background: var(--color-bg);
    border-color: var(--color-border);
}

.user-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: var(--color-primary);
    color: white;
    border-radius: 50%;
    font-weight: 600;
    font-size: 14px;
}

.user-name-text {
    font-weight: 500;
}

.user-caret {
    font-size: 12px;
    color: var(--color-text-muted);
}

.user-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 220px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    padding: 8px 0;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: opacity 0.15s, transform 0.15s, visibility 0.15s;
}
.user-menu.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.user-menu-info {
    padding: 8px 16px;
    font-size: 13px;
    color: var(--color-text);
    line-height: 1.4;
}
.user-menu-info strong {
    display: block;
    margin-bottom: 4px;
    font-size: 14px;
}
.user-menu-info div {
    color: var(--color-text-muted);
    font-size: 12px;
}

.user-menu hr {
    border: none;
    border-top: 1px solid var(--color-border);
    margin: 4px 0;
}

.user-menu-item {
    display: block;
    padding: 8px 16px;
    font-size: 14px;
    color: var(--color-text);
    text-decoration: none;
    background: transparent;
    border: none;
    width: 100%;
    text-align: left;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s;
}
.user-menu-item:hover {
    background: var(--color-bg);
}
.user-menu-logout {
    color: var(--color-error);
    border-top: 1px solid var(--color-border);
    margin-top: 4px;
}

/* SortableJS (для drag&drop списков) */
.sortable-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.sortable-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 16px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    margin-bottom: 8px;
    transition: box-shadow 0.15s, border-color 0.15s;
}
.sortable-item:hover {
    border-color: var(--color-accent);
    box-shadow: var(--shadow-sm);
}

.sortable-handle {
    cursor: grab;
    color: var(--color-text-muted);
    font-size: 18px;
    user-select: none;
    padding: 4px 8px;
}
.sortable-handle:active {
    cursor: grabbing;
}

.sortable-ghost {
    opacity: 0.4;
    background: var(--color-bg);
}

.sortable-content {
    flex: 1;
}

.sortable-meta {
    color: var(--color-text-muted);
    font-size: 13px;
}

.sortable-actions {
    display: flex;
    gap: 4px;
}

/* =================================================================
   Access Checkboxes (галочки доступов в шаблонах)
   ================================================================= */
.access-category {
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 16px 20px;
    margin-bottom: 16px;
    background: var(--color-bg);
}

.access-category legend {
    font-weight: 600;
    font-size: 14px;
    padding: 0 8px;
    color: var(--color-text);
    background: var(--color-bg);
}

.access-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 8px;
    margin-top: 8px;
}

.access-checkbox {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 12px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}
.access-checkbox:hover {
    border-color: var(--color-accent);
}
.access-checkbox input[type="checkbox"] {
    margin-top: 3px;
    width: 16px;
    height: 16px;
    cursor: pointer;
    flex-shrink: 0;
}
.access-checkbox:has(input:checked) {
    border-color: var(--color-accent);
    background: #f0f7ff;
}

.access-checkbox-content {
    flex: 1;
    min-width: 0;
}
.access-checkbox-content strong {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 2px;
}
.access-checkbox-content code {
    font-size: 11px;
    color: var(--color-text-muted);
    font-family: var(--font-mono);
    background: var(--color-bg);
    padding: 1px 4px;
    border-radius: 3px;
}
.access-checkbox-content .field-help {
    margin-top: 4px;
    font-size: 12px;
    color: var(--color-text-muted);
}

/* =================================================================
   Sub Panel (фильтры + быстрые действия)
   ================================================================= */
.sub-panel {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
    flex-wrap: wrap;
    padding: 10px 12px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
}

.filter-form {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    flex: 1;
    min-width: 300px;
}
.filter-form .form-input {
    min-width: 180px;
    flex: 1;
}
.filter-form .form-input[type="search"] {
    flex: 2;
    min-width: 240px;
}

.quick-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.quick-nav {
    display: flex;
    gap: 4px;
    padding-left: 12px;
    border-left: 1px solid var(--color-border);
}

/* =================================================================
   Row Action Menu (⋮) — дропдаун на каждой строке
   ================================================================= */
.table-wrap {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    overflow: hidden;
}

.row-action-btn {
    width: 32px;
    height: 32px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 18px;
    color: var(--color-text-muted);
    transition: background 0.15s, border-color 0.15s;
}
.row-action-btn:hover {
    background: var(--color-bg);
    border-color: var(--color-border);
    color: var(--color-text);
}

.row-action-menu {
    position: absolute;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    min-width: 200px;
    z-index: 1000;
    padding: 4px 0;
    transform: translateX(-90%) translateY(4px);
}
.row-action-menu[hidden] {
    display: none;
}
.row-action-menu.open {
    display: block;
}

.row-action-item {
    display: block;
    width: 100%;
    padding: 8px 16px;
    font-size: 14px;
    color: var(--color-text);
    background: transparent;
    border: none;
    text-align: left;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s;
}
.row-action-item:hover {
    background: var(--color-bg);
}
.row-action-item.row-action-danger {
    color: var(--color-error);
}
.row-action-menu hr {
    border: none;
    border-top: 1px solid var(--color-border);
    margin: 4px 0;
}

/* =================================================================
   Modal (нативный <dialog>)
   ================================================================= */
.modal {
    border: none;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 0;
    max-width: 720px;
    width: 90vw;
    max-height: 90vh;
    overflow: hidden;
    background: var(--color-surface);
    /* Центрирование нативного <dialog> */
    margin: auto;
    inset: 0;
    position: fixed;
}
.modal.modal-sm {
    max-width: 480px;
}
.modal.modal-lg {
    max-width: 820px;
}
.modal::backdrop {
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(2px);
}
.modal[open] {
    display: flex;
    flex-direction: column;
}

.modal-form {
    display: flex;
    flex-direction: column;
    max-height: 90vh;
    width: 100%;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-bg);
}
.modal-header h2 {
    font-size: 18px;
    font-weight: 600;
    margin: 0;
}

.modal-close {
    width: 32px;
    height: 32px;
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 24px;
    color: var(--color-text-muted);
    border-radius: var(--radius);
    line-height: 1;
}
.modal-close:hover {
    background: var(--color-border);
    color: var(--color-text);
}

.modal-body {
    padding: 20px 24px;
    overflow-y: auto;
    flex: 1;
}

.modal-errors {
    padding: 12px 16px;
    background: #fef2f2;
    color: var(--color-error);
    border: 1px solid #fecaca;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 13px;
}
.modal-errors ul {
    margin: 0;
    padding-left: 20px;
}

.modal-footer {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    padding: 16px 24px;
    border-top: 1px solid var(--color-border);
    background: var(--color-bg);
}

/* =================================================================
   Toast (всплывающее уведомление)
   ================================================================= */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 12px 20px;
    background: var(--color-text);
    color: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    z-index: 9999;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.2s, transform 0.2s;
    font-size: 14px;
    max-width: 400px;
}
.toast.show {
    opacity: 1;
    transform: translateY(0);
}
.toast-success {
    background: #16a34a;
}
.toast-error {
    background: var(--color-error);
}
.toast-info {
    background: var(--color-accent);
}

/* =================================================================
   Preview Banner (плашка в режиме превью)
   ================================================================= */
.preview-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    background: #fef3c7;
    border-bottom: 1px solid #fbbf24;
    color: #92400e;
    font-size: 14px;
    position: sticky;
    top: 0;
    z-index: 200;
}
.preview-banner-exit {
    background: #92400e;
    color: white;
    border: none;
    padding: 4px 12px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
}
.preview-banner-exit:hover {
    background: #78350f;
}

/* =================================================================
   Category Cards (карточки разделов в редакторе шаблона)
   ================================================================= */
.category-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
}

.category-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 16px;
    transition: border-color 0.15s, background 0.15s;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.category-card.category-on {
    border-color: var(--color-success);
    background: linear-gradient(to bottom, #f0fdf4, var(--color-surface));
}

.category-card-header {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    flex: 1;
}

.category-card-icon {
    font-size: 28px;
    line-height: 1;
    flex-shrink: 0;
}

.category-card-info h3 {
    font-size: 15px;
    font-weight: 600;
    margin: 0 0 4px 0;
}

.category-card-stat {
    font-size: 12px;
    color: var(--color-text-muted);
    margin: 0;
}

.category-card-toggle {
    margin: 0;
}

.category-toggle-btn {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text-muted);
    transition: all 0.15s;
}

.category-toggle-btn:hover {
    background: var(--color-border);
}

.category-toggle-btn .toggle-track {
    width: 36px;
    height: 20px;
    background: #cbd5e1;
    border-radius: 10px;
    position: relative;
    transition: background 0.2s;
    flex-shrink: 0;
}

.category-toggle-btn .toggle-thumb {
    width: 16px;
    height: 16px;
    background: white;
    border-radius: 50%;
    position: absolute;
    top: 2px;
    left: 2px;
    transition: left 0.2s;
    box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.category-toggle-btn.on .toggle-track {
    background: var(--color-success);
}

.category-toggle-btn.on .toggle-thumb {
    left: 18px;
}

.category-toggle-btn.on {
    background: #f0fdf4;
    border-color: var(--color-success);
    color: #15803d;
}

.preview-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* Checked access в категории */
.access-checkbox.checked {
    border-color: var(--color-accent);
    background: #f0f7ff;
}

/* =================================================================
   User Stats (карточки статистики на хабе «Пользователи»)
   ================================================================= */
.user-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: var(--shadow-sm);
}

.stat-value {
    font-size: 36px;
    font-weight: 700;
    color: var(--color-text);
    line-height: 1;
    margin-bottom: 8px;
}

.stat-label {
    font-size: 13px;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 500;
}

.stat-card-success .stat-value { color: #15803d; }
.stat-card-error .stat-value { color: #b91c1c; }
.stat-card-warning .stat-value { color: #b45309; }

/* =================================================================
   Access Matrix (страница доступа юзера)
   ================================================================= */
.access-matrix-block {
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 16px 20px;
    margin-bottom: 16px;
    background: var(--color-surface);
    box-shadow: var(--shadow-sm);
}

.access-matrix-block legend {
    font-weight: 600;
    font-size: 16px;
    padding: 0 8px;
    color: var(--color-text);
}

.access-matrix-block legend .muted {
    color: var(--color-text-muted);
    font-weight: 400;
    font-size: 13px;
}

.access-matrix-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 8px;
    margin-top: 12px;
}

.access-matrix-row {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-bg);
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}

.access-matrix-row:hover {
    border-color: var(--color-accent);
}

.access-matrix-row:has(input:checked) {
    background: #f0f7ff;
    border-color: var(--color-accent);
}

.access-matrix-row:has(input:disabled) {
    opacity: 0.6;
    cursor: not-allowed;
}

.access-matrix-row:has(input:disabled):hover {
    border-color: var(--color-border);
}

.access-matrix-toggle {
    width: 18px;
    height: 18px;
    cursor: pointer;
    flex-shrink: 0;
    margin-top: 1px;
}

.access-matrix-row:has(input:disabled) .access-matrix-toggle {
    cursor: not-allowed;
}

.access-matrix-info {
    flex: 1;
    min-width: 0;
}

.access-matrix-info strong {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 2px;
}

.access-matrix-info code {
    font-size: 11px;
    color: var(--color-text-muted);
    font-family: var(--font-mono);
    background: var(--color-surface);
    padding: 1px 4px;
    border-radius: 3px;
}

/* =================================================================
   Block Checkboxes (чек-боксы блоков в должности)
   ================================================================= */
.blocks-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 12px;
}

.block-checkbox {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}

.block-checkbox:hover {
    border-color: var(--color-accent);
}

.block-checkbox:has(input:checked) {
    background: #f0f7ff;
    border-color: var(--color-accent);
}

.block-checkbox input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    flex-shrink: 0;
    margin-top: 2px;
}

.block-checkbox-content {
    flex: 1;
}

.block-checkbox-content strong {
    display: block;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 2px;
}

/* =================================================================
   Admin Grid 2 Columns (блоки + доступы)
   ================================================================= */
.admin-grid-2col {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 24px;
}

.block-summary {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    border-radius: var(--radius);
    margin-bottom: 4px;
    font-size: 13px;
}

.block-summary strong {
    font-weight: 600;
}

.block-summary .muted {
    color: var(--color-text-muted);
    font-size: 12px;
}


@media (max-width: 768px) {
    .admin-grid-2col {
        grid-template-columns: 1fr;
    }
}

/* =================================================================
   Block Tabs (табы для выбора блока в user_access_matrix)
   ================================================================= */
.block-tabs {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.block-tab-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    color: var(--color-text);
    text-align: left;
    transition: all 0.15s;
}

.block-tab-btn:hover {
    border-color: var(--color-accent);
    background: var(--color-bg);
}

.block-tab-btn.active {
    background: var(--color-accent);
    color: white;
    border-color: var(--color-accent);
}

.block-tab-icon {
    font-size: 16px;
}

.block-tab-name {
    flex: 1;
}

.block-tab-btn.active .block-tab-panel {
    /* показываем/скрываем через атрибут hidden */
}

/* =================================================================
   Block Tab Checkbox (чек-бокс на табе для вкл/выкл блока)
   ================================================================= */
.block-tab-checkbox {
    width: 16px;
    height: 16px;
    cursor: pointer;
    flex-shrink: 0;
    margin: 0;
}

.block-tab-btn.active .block-tab-checkbox {
    /* На активном табе чек-бокс виден отлично */
}

/* =================================================================
   Storage Layout (Total Commander style):
   1) Один select «Филиал» сверху
   2) Frame с двумя одинаковыми панелями A/B (по селекту + карточка)
   3) Отдельная панель «Получатель» под ними
   4) Черновик с drag&drop-записями
   ================================================================= */

/* === Верхняя панель выбора филиала === */
.storage-branch-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    margin-bottom: 16px;
    box-shadow: var(--shadow-sm);
    flex-wrap: wrap;
}

/* === Широкий режим (на всю ширину экрана) — переключатель .tc-wide на <body> ===

Когда на <body> стоит класс tc-wide:
- снимается max-width у .page-content и всех оберток
- таблицы и фреймы тоже могут тянуться на всю ширину

По умолчанию (без класса) .page-content ограничен 1400px.
=== */

/* Сам <main> без класса уже не имеет max-width (мы сняли в .page-content выше),
   но на некоторых страницах есть обёртки. Снимем ограничение глобально. */
body.tc-wide .page-content,
body.tc-wide main,
body.tc-wide .page,
body.tc-wide .page-header,
body.tc-wide .page-actions,
body.tc-wide .storage-branch-bar,
body.tc-wide .storage-draft,
body.tc-wide .tc-frame,
body.tc-wide .tc-panel,
body.tc-wide .recipient-frame,
body.tc-wide .items-page,
body.tc-wide .catalog-page,
body.tc-wide .brand-list-page,
body.tc-wide .model-list-page,
body.tc-wide .warehouse-section,
body.tc-wide .audit-page,
body.tc-wide .rule-list,
body.tc-wide .data-table,
body.tc-wide .filter-bar,
body.tc-wide .table-wrap {
    max-width: none !important;
}

/* Дополнительно: на широком режиме таблица тянется на всю ширину */
body.tc-wide .data-table {
    width: 100%;
    table-layout: auto;
}

/* В стандартном режиме (без .tc-wide) — таблицы тянутся на ширину контейнера,
       скролл появляется только если реально не помещаются. */
body:not(.tc-wide) .table-wrap {
    overflow-x: auto;
    margin: 0;
}

/* Кнопка переключателя ширины (в topbar, рядом с аватаром) */
.tc-width-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    font-size: 13px;
    font-weight: 600;
    /* Тёмно-синяя кнопка — контрастная и в покое, и в активном состоянии.
       В покое: тёмно-синий фон + светлый текст.
       Активно (.tc-wide): яркий accent — отличается. */
    background: #1e293b;
    color: #f1f5f9;
    border: 1.5px solid #475569;
    border-radius: var(--radius);
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.05s;
}

.tc-width-toggle:hover {
    background: #334155;
    color: #ffffff;
    border-color: #64748b;
}

.tc-width-toggle:active {
    transform: scale(0.97);
}

.tc-width-toggle-icon {
    font-size: 16px;
    line-height: 1;
}

.tc-wide .tc-width-toggle {
    background: var(--color-accent);
    color: white;
    border-color: var(--color-accent);
}

.tc-wide .tc-width-toggle:hover {
    background: #2563eb;
}

/* === Segmented control: какие панели показывать (A / A+B / B) === */
.tc-side-toggle {
    display: inline-flex;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--color-surface);
}

.tc-side-btn {
    padding: 6px 12px;
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    background: transparent;
    border: none;
    border-right: 1px solid var(--color-border);
    cursor: pointer;
    color: var(--color-text-muted);
    transition: background 0.15s, color 0.15s;
    min-width: 40px;
}

.tc-side-btn:last-child { border-right: none; }

.tc-side-btn:hover {
    background: var(--color-bg);
    color: var(--color-text);
}

.tc-side-btn.active {
    background: var(--color-primary);
    color: white;
}

/* Когда активен режим "только A" — скрываем панель B и черновик */
.tc-side-A .tc-frame > .tc-panel[data-side="B"],
.tc-side-A .tc-frame > .tc-draft-col {
    display: none !important;
}
/* Когда активен режим "только B" — скрываем панель A и черновик */
.tc-side-B .tc-frame > .tc-panel[data-side="A"],
.tc-side-B .tc-frame > .tc-draft-col {
    display: none !important;
}

/* В режиме "только одна" панель на всю ширину frame */
.tc-side-A .tc-frame,
.tc-side-B .tc-frame {
    grid-template-columns: 1fr;
}

.storage-branch-bar-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    color: var(--color-text-muted);
    white-space: nowrap;
}

.storage-branch-bar .form-input {
    max-width: 360px;
}

.storage-branch-bar-fixed {
    padding: 10px 14px;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-weight: 600;
    color: var(--color-text);
}

.storage-branch-bar-info {
    font-size: 13px;
    margin-left: auto;
}

/* === TC layout: 2 панели + узкая колонка черновика между ними === */
.tc-layout,
.tc-frame {
    display: grid;
    grid-template-columns: 1fr 150px 1fr;
    gap: 0;
    margin-bottom: 16px;
    align-items: stretch;
    width: 100%;
    max-width: 100%;
}

@media (max-width: 700px) {
    .tc-layout,
    .tc-frame {
        grid-template-columns: 1fr;
    }
}

/* Колонка черновика (между панелями) */
.tc-draft-col {
    display: flex;
    flex-direction: column;
    background: var(--color-bg);
    min-height: 320px;
    min-width: 0;
    overflow: hidden;
}

.tc-draft-col-header {
    padding: 8px 6px;
    text-align: center;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    font-weight: 600;
    font-size: 12px;
}

.tc-draft-col-title {
    display: block;
}

.tc-draft-col-count {
    display: block;
    margin-top: 2px;
    font-size: 11px;
}

.tc-draft-col-body {
    flex: 1;
    padding: 6px 4px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow-y: auto;
    min-height: 0;
}

.tc-draft-col-body:empty::before {
    content: 'Пусто';
    color: var(--color-text-muted);
    text-align: center;
    font-style: italic;
    font-size: 11px;
    padding: 12px 0;
}

.tc-draft-col-footer {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 6px 4px;
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
}

.tc-draft-col-footer .btn {
    width: 100%;
    font-size: 11px;
    padding: 5px 4px;
}

/* Мини-блок перемещения в колонке черновика */
.draft-mini {
    position: relative;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 5px;
    padding: 5px 4px 4px 6px;
    font-size: 11px;
    line-height: 1.25;
    display: flex;
    flex-direction: column;
    gap: 1px;
    transition: border-color 0.15s, background 0.15s;
}

.draft-mini:hover {
    border-color: var(--color-primary);
    background: #fff;
}

.draft-mini-arrow {
    font-size: 11px;
    font-weight: 700;
    color: var(--color-primary);
    text-align: center;
    margin-bottom: 2px;
    letter-spacing: 0.5px;
}

.draft-mini-brand {
    font-weight: 600;
    color: var(--color-text);
    word-break: break-word;
    line-height: 1.15;
    font-size: 10px;
    overflow-wrap: anywhere;
}

.draft-mini-code {
    color: var(--color-text-muted);
    font-family: var(--font-mono);
    font-size: 9px;
    word-break: break-all;
    line-height: 1.15;
    overflow-wrap: anywhere;
}

.draft-mini-qty {
    color: var(--color-text);
    font-weight: 600;
}

.draft-mini-remove {
    position: absolute;
    top: 1px;
    right: 1px;
    background: transparent;
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    font-size: 13px;
    line-height: 1;
    padding: 1px 3px;
    border-radius: 3px;
}

.draft-mini-remove:hover {
    background: var(--color-danger);
    color: #fff;
}

.tc-panel {
    background: var(--color-surface);
    display: flex;
    flex-direction: column;
    min-height: 320px;
    min-width: 0; /* ВАЖНО для grid 1fr 1fr: иначе колонка растягивается под min-content карточек */
    border: 0;
}

/* Единый «TC-рамка»: внешний border на .tc-frame, внутренние разделители на детях */
.tc-frame {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    background: var(--color-surface);
    box-shadow: var(--shadow-sm);
}
.tc-frame > .tc-panel:not(:last-child) {
    border-right: 1px solid var(--color-border);
}
.tc-frame > .tc-draft-col {
    border-right: 1px solid var(--color-border);
}

.tc-side-A .tc-frame > .tc-panel[data-side="B"],
.tc-side-B .tc-frame > .tc-panel[data-side="A"] {
    display: none;
}
/* При скрытии соседа убираем разделитель у оставшегося */
.tc-side-A .tc-frame > .tc-panel[data-side="A"],
.tc-side-B .tc-frame > .tc-panel[data-side="B"] {
    border-right: 0;
}

.tc-panel-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--color-bg);
    border-bottom: 1px solid var(--color-border);
}

.tc-panel-tag {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    background: var(--color-primary);
    color: white;
    border-radius: 6px;
    font-weight: 700;
    font-size: 14px;
    flex-shrink: 0;
}

.tc-panel-select {
    flex: 1;
    font-weight: 500;
}

.tc-panel-body {
    flex: 1;
    padding: 16px;
    display: flex;
    flex-direction: column;
}

/* Атрибут [hidden] должен побеждать любой display:flex/grid (иначе плейсхолдер
   виден одновременно с позициями). */
.tc-panel-body > [hidden] {
    display: none !important;
}

/* Позиции в панели растягиваются на всё свободное место сверху;
   плейсхолдер (см. .tc-panel-empty) уходит вниз благодаря margin-top:auto. */
.tc-panel-items {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
}

.tc-panel-empty {
    /* Плейсхолдер теперь узкая подсказка внизу панели,
       а не большой блок на всю высоту. */
    flex: 0 0 auto;
    margin-top: auto;
    align-self: stretch;
    text-align: center;
    color: var(--color-text-muted);
    font-size: 12px;
    font-style: italic;
    padding: 10px 12px;
    border: 1px dashed var(--color-border);
    border-radius: var(--radius);
    background: #f8fafc;
    transition: border-color 0.15s, background 0.15s;
}

.tc-panel-card {
    flex: 1;
    background: var(--color-surface);
    border: 2px solid var(--color-border);
    border-radius: var(--radius);
    padding: 16px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    cursor: grab;
    transition: border-color 0.15s, background 0.15s, opacity 0.15s;
}

.tc-panel-card:hover {
    border-color: var(--color-accent);
}

.tc-panel-card.dragging {
    opacity: 0.5;
    cursor: grabbing;
}

.tc-panel-card.drop-target {
    border-color: var(--color-success);
    background: #f0fdf4;
    box-shadow: 0 0 0 2px var(--color-success) inset;
}

.tc-panel-empty.drop-target {
    border-color: var(--color-success);
    background: #f0fdf4;
    color: var(--color-success);
    font-style: normal;
    font-weight: 600;
}

.tc-card-row {
    display: flex;
    align-items: center;
    gap: 14px;
}

.tc-card-icon {
    font-size: 36px;
    line-height: 1;
    width: 56px;
    height: 56px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--color-bg);
    border-radius: 50%;
    flex-shrink: 0;
}

.tc-card-info {
    flex: 1;
    min-width: 0;
}

.tc-card-info strong {
    display: block;
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 2px;
}

.tc-card-info .muted {
    font-size: 12px;
    color: var(--color-text-muted);
}

.tc-card-actions {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
    margin-top: 12px;
}

/* === Панель «Получатель» (отдельный frame под tc-frame) === */
.recipient-frame {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    margin-bottom: 16px;
    overflow: hidden;
}

.recipient-frame-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    background: var(--color-bg);
    border-bottom: 1px solid var(--color-border);
}

.recipient-frame-header h2 {
    font-size: 15px;
    font-weight: 600;
    margin: 0;
}

.recipient-frame-body {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.recipient-hint {
    font-size: 12px;
    color: var(--color-text-muted);
    margin: 4px 0 0 0;
}

/* === Карточка-деталь получателя (drop-target) === */
.recipient-detail {
    margin-top: 4px;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 16px;
    min-height: 96px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    transition: border-color 0.15s, background 0.15s;
}

.recipient-detail[data-empty="0"] {
    background: var(--color-surface);
}

.recipient-detail.drop-target {
    border-color: var(--color-success);
    background: #f0fdf4;
    box-shadow: 0 0 0 2px var(--color-success) inset;
}

.storage-detail-empty {
    text-align: center;
    color: var(--color-text-muted);
    font-size: 13px;
    font-style: italic;
}

.storage-detail-content {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.storage-detail-row {
    display: flex;
    align-items: center;
    gap: 14px;
}

.storage-detail-icon {
    font-size: 32px;
    line-height: 1;
    width: 48px;
    height: 48px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--color-bg);
    border-radius: 50%;
    flex-shrink: 0;
}

.storage-detail-info {
    flex: 1;
    min-width: 0;
}

.storage-detail-info strong {
    display: block;
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 2px;
}

.storage-detail-info .muted {
    font-size: 12px;
    color: var(--color-text-muted);
}

.storage-half-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    color: var(--color-text-muted);
}

/* === DnD-черновик === */
.storage-draft {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 14px 16px;
    margin-bottom: 16px;
}

.storage-draft-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.storage-draft-header h3 {
    font-size: 14px;
    font-weight: 600;
    margin: 0;
}

.storage-draft-actions {
    display: flex;
    gap: 6px;
}

.storage-draft-hint {
    font-size: 12px;
    color: var(--color-text-muted);
    margin: 0 0 10px 0;
    line-height: 1.5;
}

/* Карточки складов (для быстрого редактирования/удаления) */
.storage-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 8px;
    margin: 12px 0;
}
.storage-card {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: white;
    border: 1px solid var(--color-border, #e2e8f0);
    border-radius: var(--radius, 6px);
    transition: border-color 0.15s, box-shadow 0.15s;
}
.storage-card:hover {
    border-color: #2563eb;
    box-shadow: 0 0 0 1px #2563eb;
}
.storage-card-main {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
}
.storage-card-icon {
    font-size: 22px;
    flex-shrink: 0;
}
.storage-card-info {
    min-width: 0;
    flex: 1;
}
.storage-card-name {
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.storage-card-meta {
    font-size: 11px;
    margin-top: 2px;
}
.storage-card-notes {
    margin-left: 4px;
}
.storage-card-actions {
    flex-shrink: 0;
}

/* Dropdown «Управление складами» в шапке */
.storage-mng-wrap {
    position: relative;
    display: inline-block;
}
.storage-mng-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.15);
    min-width: 280px;
    max-height: 70vh;
    overflow-y: auto;
    z-index: 50;
}
.storage-mng-header {
    padding: 8px 12px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    border-bottom: 1px solid #f1f5f9;
    background: #f8fafc;
}
.storage-mng-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border-bottom: 1px solid #f1f5f9;
}
.storage-mng-item:last-child {
    border-bottom: none;
}
.storage-mng-item:hover {
    background: #f8fafc;
}
.storage-mng-name {
    flex: 1;
    font-size: 13px;
}
.storage-mng-actions {
    display: flex;
    gap: 4px;
}

.storage-draft-items {
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: 200px;
    overflow-y: auto;
}

.storage-draft-items li {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    font-size: 13px;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 4px;
    margin-bottom: 4px;
}

.storage-draft-items li > strong { font-weight: 600; }

.storage-draft-time {
    font-size: 11px;
    color: var(--color-text-muted);
    font-family: var(--font-mono);
    flex-shrink: 0;
    min-width: 42px;
}

.storage-draft-empty {
    color: var(--color-text-muted);
    font-style: italic;
    background: transparent !important;
    border: 1px dashed var(--color-border) !important;
    text-align: center;
    padding: 10px !important;
    margin: 0 !important;
}

/* =================================================================
   Item Modal (модалка Позиции — крупнее стандартной)
   ================================================================= */
/* .modal.modal-lg теперь определяется в основной секции Modal */

/* Сетка хештегов в модалке позиции */
.item-tags-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 4px 0;
    max-height: 120px;
    overflow-y: auto;
}

.item-tag-checkbox {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 14px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.item-tag-checkbox:hover {
    background: var(--color-surface);
    border-color: var(--color-accent);
}

.item-tag-checkbox:has(input:checked) {
    background: #f0f7ff;
    border-color: var(--color-accent);
}

.item-tag-checkbox input[type="checkbox"] {
    margin: 0;
    cursor: pointer;
}

/* Кнопка «+ Новая позиция» на странице складов */
.storage-create-item-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 16px;
    background: var(--color-surface);
    border: 1px dashed var(--color-border);
    border-radius: var(--radius);
    margin-bottom: 16px;
}

.storage-create-item-bar-text {
    font-size: 13px;
    color: var(--color-text-muted);
}

.storage-create-item-bar-text strong {
    color: var(--color-text);
}

/* =================================================================
   Autocomplete (поиск артикула в модалке)
   ================================================================= */
.autocomplete {
    position: relative;
}

.autocomplete-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 1000;
    margin-top: 4px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    max-height: 320px;
    overflow-y: auto;
    font-size: 14px;
}

.autocomplete-dropdown[hidden] {
    display: none;
}

.autocomplete-item {
    padding: 8px 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--color-border);
    transition: background 0.1s;
}

.autocomplete-item:last-child {
    border-bottom: none;
}

.autocomplete-item:hover,
.autocomplete-item.active {
    background: #f0f7ff;
}

.ac-item-main {
    font-weight: 500;
    color: var(--color-text);
    margin-bottom: 2px;
}

.ac-item-sub {
    font-size: 12px;
    color: var(--color-text-muted);
}

.autocomplete-empty {
    padding: 16px;
    text-align: center;
    color: var(--color-text);
    font-size: 13px;
    line-height: 1.5;
}

/* «Добавить новый в справочник» в конце dropdown */
.autocomplete-add-new {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-top: 2px dashed var(--color-accent);
    background: linear-gradient(to right, #f0f7ff 0%, #f8fafc 100%);
    color: var(--color-text);
    text-decoration: none;
    cursor: pointer;
    transition: background 0.15s;
}

.autocomplete-add-new:hover {
    background: linear-gradient(to right, #dbeafe 0%, #f0f7ff 100%);
}

.autocomplete-add-new .ac-add-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: var(--color-accent);
    color: white;
    border-radius: 50%;
    font-weight: 700;
    font-size: 16px;
    flex-shrink: 0;
}

.autocomplete-add-new .ac-add-text {
    flex: 1;
    min-width: 0;
}

.autocomplete-add-new .ac-add-text strong {
    display: block;
    font-size: 13px;
    color: var(--color-text);
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.autocomplete-add-new .ac-add-sub {
    font-size: 11px;
    color: var(--color-text-muted);
    margin-top: 1px;
}

/* =================================================================
   Inline tag creator (создание хештега в модалке)
   ================================================================= */
.item-tag-creator {
    display: flex;
    gap: 6px;
    align-items: center;
    margin-bottom: 8px;
    padding: 6px;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
}

.item-tag-creator .form-input {
    /* Поле НЕ растягивается на всю ширину. Растёт только по содержимому (через JS). */
    flex: 0 0 auto;
    width: 5ch;
    min-width: 5ch;
    max-width: 100%;
    font-size: 13px;
    padding: 6px 4px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
}

.item-tag-creator .item-tag-color {
    /* Цвет всегда слева, фиксированный размер */
    order: 0;
    width: 32px;
    height: 32px;
    padding: 2px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    cursor: pointer;
    background: var(--color-surface);
    flex: 0 0 auto;
}

.item-tag-creator .form-input {
    order: 1;
}

.item-tag-creator .btn {
    /* Кнопка всегда сразу за полем ввода. Белый фон, обводка и текст — цвет пикера. */
    order: 2;
    flex: 0 0 auto;
    font-size: 13px;
    font-weight: 700;
    padding: 6px 14px;
    background: #fff;
    color: var(--tag-color, #3b82f6);
    border: 2px solid var(--tag-color, #3b82f6);
    border-radius: var(--radius);
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.item-tag-creator .btn:hover {
    background: var(--tag-color-soft, #f1f5f9);
}
.item-tag-creator .btn:disabled { opacity: 0.6; cursor: default; }

/* Зеркало для расчёта ширины поля ввода (скрыто). */
.item-tag-mirror {
    position: absolute;
    visibility: hidden;
    white-space: pre;
    pointer-events: none;
    font-size: 13px;
    padding: 6px 4px;
    border: 1px solid transparent;
}

/* Обёртка color-picker'а: иконка палитры + квадрат цвета */
.item-tag-color-wrap {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 6px 2px 4px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    cursor: pointer;
    height: 32px;
    flex: 0 0 auto;
}
.item-tag-color-wrap:hover { background: #f1f5f9; }
.item-tag-color-icon {
    font-size: 14px;
    line-height: 1;
    pointer-events: none;
}
.item-tag-creator input[type="color"] {
    width: 22px;
    height: 22px;
    padding: 0;
    border: none;
    border-radius: 3px;
    background: transparent;
    cursor: pointer;
    flex: 0 0 auto;
}
.item-tag-creator input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.item-tag-creator input[type="color"]::-webkit-color-swatch { border: none; border-radius: 3px; }
.item-tag-creator input[type="color"]::-moz-color-swatch { border: none; border-radius: 3px; }

/* Кнопка-тумблер «Удалить хештеги» (используется в .ie-tags-section и в любом списке тегов) */
.tag-delete-mode-btn {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 4px 10px; font-size: 12px; font-weight: 600;
    background: #fff; color: #475569;
    border: 1px solid #cbd5e1; border-radius: 4px;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.tag-delete-mode-btn:hover { background: #f1f5f9; }
.tag-delete-mode-btn[aria-pressed="true"] {
    background: #fef2f2; color: #b91c1c;
    border-color: #fca5a5;
}
/* Крестики удаления у тегов (в режиме удаления) */
.item-tags-grid.item-tag-delete-mode .item-tag-checkbox {
    position: relative; padding-right: 26px !important;
}
.item-tags-grid .item-tag-remove {
    display: none;
    position: absolute; right: 4px; top: 50%;
    transform: translateY(-50%);
    width: 18px; height: 18px;
    align-items: center; justify-content: center;
    background: transparent; color: #dc2626;
    border: none; border-radius: 3px;
    cursor: pointer; font-size: 16px; line-height: 1;
    padding: 0;
}
.item-tags-grid .item-tag-remove:hover { background: #fee2e2; }
.item-tags-grid.item-tag-delete-mode .item-tag-remove { display: inline-flex; }

/* === Popover-подтверждение удаления хештега === */
.ie-tag-confirm-popover {
    position: absolute;
    z-index: 100000;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.18);
    padding: 8px 10px;
    font-size: 13px;
    min-width: 220px;
    max-width: 280px;
    animation: ie-tag-confirm-in 0.14s ease-out;
}
@keyframes ie-tag-confirm-in {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}
.ie-tag-confirm-text {
    margin-bottom: 8px;
    color: #334155;
    line-height: 1.35;
}
.ie-tag-confirm-text b { color: #0f172a; }
.ie-tag-confirm-actions {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
}
.ie-tag-confirm-cancel,
.ie-tag-confirm-ok {
    padding: 5px 12px;
    font-size: 12px;
    font-weight: 600;
    border-radius: 4px;
    cursor: pointer;
    line-height: 1;
    transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}
.ie-tag-confirm-cancel {
    background: #fff;
    color: #475569;
    border: 1px solid #cbd5e1;
}
.ie-tag-confirm-cancel:hover { background: #f1f5f9; color: #1e293b; }
.ie-tag-confirm-ok {
    background: #dc2626;
    color: #fff;
    border: 1px solid #b91c1c;
}
.ie-tag-confirm-ok:hover { background: #b91c1c; }
.ie-tag-confirm-loading { opacity: 0.7; pointer-events: none; }

/* =================================================================
   Двухпанельный DnD-интерфейс (storage_list.html)
   ================================================================= */

/* Панели становятся выше — больше места для позиций */
.tc-frame .tc-panel {
    min-height: 540px;
}

/* Контейнер с прокруткой для позиций внутри панели */
.tc-panel-body[data-tc-body] {
    overflow-y: auto;
    max-height: calc(100vh - 320px);
    min-height: 420px;
}

.tc-panel-loading {
    padding: 16px;
    text-align: center;
}

.tc-panel-empty-inline {
    padding: 24px 12px;
    text-align: center;
    border: 1px dashed var(--color-border);
    border-radius: var(--radius);
    color: var(--color-text-muted);
}

/* Подсветка панели при dragover */
.tc-panel-body.drop-target {
    background: #f0fdf4;
    outline: 2px dashed var(--color-success);
    outline-offset: -8px;
}

/* Карточка позиции в панели — компактный зеркальный дизайн */
.tc-item-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 6px 10px;
    margin-bottom: 6px;
    cursor: grab;
    transition: border-color 0.15s, background 0.15s, box-shadow 0.15s, opacity 0.15s;
    user-select: none;
}

.tc-item-card:hover {
    border-color: var(--color-primary);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
}

.tc-item-card.dragging {
    opacity: 0.4;
    cursor: grabbing;
    border-style: dashed;
}

/* Зеркальная строка: [icon | title+meta | qty | price | actions] */
.tc-item-card-row {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 36px;
}

/* Панель B — зеркальная компоновка карточек (icon справа, action слева) */
[data-tc-items="B"] .tc-item-card-row {
    flex-direction: row-reverse;
}

.tc-item-icon {
    font-size: 18px;
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--color-bg);
    border-radius: 6px;
    flex-shrink: 0;
}

.tc-item-icon-photo {
    background: #fff;
    border: 1px solid var(--color-border);
    overflow: hidden;
    padding: 0;
}

.tc-item-icon-photo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.tc-item-info {
    flex: 1;
    min-width: 0;
}

.tc-item-title {
    font-weight: 600;
    font-size: 13px;
    line-height: 1.25;
    margin-bottom: 1px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tc-item-meta {
    font-size: 11px;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    align-items: center;
    line-height: 1.2;
}

.tc-item-qty {
    text-align: right;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0;
    min-width: 50px;
}

.tc-item-qty strong {
    font-size: 14px;
    font-weight: 700;
    line-height: 1.1;
}

.tc-item-qty .muted {
    font-size: 10px;
    line-height: 1;
}

.tc-item-price {
    text-align: right;
    flex-shrink: 0;
    min-width: 60px;
    font-size: 11px;
    color: var(--color-text-muted);
    font-variant-numeric: tabular-nums;
}

/* Кнопки действий в карточке (справа от qty/price) */
.tc-item-actions {
    display: flex;
    flex-direction: column;
    gap: 3px;
    flex-shrink: 0;
    margin-left: 2px;
}

.tc-item-action {
    border: 1px solid var(--color-border);
    background: var(--color-bg);
    border-radius: 5px;
    padding: 0;
    width: 26px;
    height: 22px;
    font-size: 13px;
    font-weight: 700;
    line-height: 1;
    color: var(--color-primary);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.tc-item-action:hover {
    border-color: var(--color-primary);
    background: var(--color-primary);
    color: #fff;
}

.tc-item-action.tc-item-action-more {
    font-size: 11px;
    color: var(--color-text-muted);
}

.tc-item-action.tc-item-action-more:hover {
    border-color: var(--color-text-muted);
    background: var(--color-text-muted);
}

.tc-item-action:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Селектор типа контейнера в панели (Склад / Сотрудник) */
.tc-panel-mode {
    max-width: 140px;
    flex-shrink: 0;
}

/* Чтобы select заполнил оставшееся место */
.tc-panel-pick {
    flex: 1;
    min-width: 0;
}

/* Модалка выбора количества (узкая) */
.modal.modal-sm {
    max-width: 440px;
    width: 92%;
}

.modal-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}

.modal-row > label {
    min-width: 100px;
    font-weight: 500;
}

.modal-row > input[type="number"] {
    flex: 1;
    min-width: 120px;
    max-width: 200px;
}

.modal-icon {
    font-size: 48px;
    width: 200px;
    height: 200px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--color-bg);
    border-radius: 10px;
    flex-shrink: 0;
    overflow: hidden;
    border: 1px solid var(--color-border);
}

.modal-icon.modal-icon-photo {
    background: #fff;
    padding: 0;
}

.modal-icon.modal-icon-photo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.modal-summary {
    padding: 8px 12px;
    background: var(--color-bg);
    border-radius: var(--radius);
    font-size: 13px;
}

.modal-summary strong {
    margin-left: 6px;
}

.modal-errors {
    color: var(--color-danger);
    font-size: 12px;
    padding: 6px 10px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: var(--radius);
    margin-top: 8px;
}

/* Черновик — увеличим max-height для прокрутки */
.storage-draft-items {
    max-height: 280px;
}

/* Если высота панели позволяет — увеличиваем */
@media (min-height: 900px) {
    .tc-frame .tc-panel {
        min-height: 660px;
    }
    .tc-panel-body[data-tc-body] {
        min-height: 540px;
    }
}

/* === Модалка подтверждения применения черновика === */
.mc-list {
    list-style: decimal inside;
    margin: 8px 0;
    padding: 0;
    max-height: 50vh;
    overflow-y: auto;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-bg);
}

.mc-list li {
    padding: 8px 12px;
    border-bottom: 1px solid var(--color-border);
    font-size: 13px;
}

.mc-list li:last-child {
    border-bottom: none;
}

.mc-list .mc-qty {
    font-weight: 700;
    color: var(--color-primary);
}

.mc-list .mc-arrow {
    color: var(--color-text-muted);
    margin: 0 6px;
}

/* === Модалка редактирования позиции === */
.mie-photo-row {
    display: flex;
    gap: 14px;
    align-items: center;
    padding: 12px;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    margin-bottom: 14px;
}

.mie-photo-row img {
    width: 80px;
    height: 80px;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid var(--color-border);
    background: #fff;
}

.mie-name {
    font-weight: 600;
    font-size: 16px;
    margin-bottom: 4px;
}

.mie-meta {
    font-size: 12px;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.form-group-full {
    grid-column: 1 / -1;
}

.form-group label {
    font-size: 12px;
    font-weight: 500;
    color: var(--color-text);
}

/* tc-item-edit-link — кликабельные ссылки в карточке */
.tc-item-edit-link {
    color: inherit;
    text-decoration: none;
    border-bottom: 1px dotted transparent;
    transition: border-color 0.15s, color 0.15s;
}

.tc-item-edit-link:hover {
    color: var(--color-primary);
    border-bottom-color: var(--color-primary);
}

.tc-item-code {
    margin-left: 6px;
    padding: 1px 5px;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 3px;
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--color-text-muted);
    vertical-align: middle;
}

/* === Расширенное редактирование позиции (выбор/создание Model) === */
.mie-block {
    margin-bottom: 16px;
    padding: 12px;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
}

.mie-block-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 8px;
}

.mie-current-model {
    margin-bottom: 8px;
    padding: 6px 10px;
    background: var(--color-surface);
    border-radius: var(--radius);
    border: 1px solid var(--color-border);
}

.mie-search-row {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}

.mie-search-row .form-input {
    flex: 1;
}

.mie-model-results {
    max-height: 240px;
    overflow-y: auto;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    margin-bottom: 8px;
}

.mie-model-results:empty {
    display: none;
}

.mie-result-item {
    padding: 6px 10px;
    cursor: pointer;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    justify-content: space-between;
    gap: 8px;
    align-items: center;
}

.mie-result-item:last-child {
    border-bottom: none;
}

.mie-result-item:hover {
    background: var(--color-bg);
}

.mie-result-item.selected {
    background: #f0fdf4;
    border-left: 3px solid var(--color-success);
}

.mie-result-info {
    flex: 1;
    min-width: 0;
}

.mie-result-name {
    font-size: 13px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mie-result-meta {
    font-size: 11px;
    color: var(--color-text-muted);
}

.mie-result-code {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--color-text-muted);
    flex-shrink: 0;
}

.mie-create-details {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 8px 12px;
}

.mie-create-details summary {
    cursor: pointer;
    font-weight: 500;
    font-size: 13px;
    color: var(--color-primary);
    user-select: none;
}

/* Кнопка «Открыть в справочнике» в модалке позиции */
.mie-open-editor-btn {
    margin-left: 8px;
    font-size: 11px;
    padding: 3px 8px;
    text-transform: none;
    letter-spacing: 0;
    color: var(--color-primary);
    border: 1px solid var(--color-primary);
    background: transparent;
}

.mie-open-editor-btn:hover {
    background: var(--color-primary);
    color: #fff;
}

/* Кнопка выбора бренда в модалке артикула (как input, но кликабельная) */
.mm-brand-trigger-wrap {
    position: relative;
    display: flex;
    align-items: center;
}
.mm-brand-trigger-wrap input[readonly] {
    cursor: pointer;
    background: white;
    padding-right: 28px;
}
.mm-brand-trigger-wrap input[readonly]:hover {
    border-color: #2563eb;
}
.mm-brand-clear {
    position: absolute;
    right: 4px;
    background: transparent;
    border: none;
    color: #94a3b8;
    font-size: 18px;
    line-height: 1;
    width: 24px;
    height: 24px;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.mm-brand-clear:hover {
    background: #f1f5f9;
    color: #dc2626;
}

/* === Dropdown бренда внутри модалки артикула === */
.mm-brand-wrap {
    position: relative;
    display: flex;
    align-items: center;
    gap: 4px;
}
.mm-brand-trigger {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    background: white;
    cursor: pointer;
    font: inherit; font-size: 13px;
    text-align: left;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: border-color 0.15s;
}
.mm-brand-trigger:hover {
    border-color: #2563eb;
}
.mm-brand-caret {
    color: #94a3b8;
    font-size: 10px;
}
.mm-brand-clear {
    background: transparent;
    border: 1px solid #cbd5e1;
    color: #94a3b8;
    border-radius: 4px;
    width: 28px;
    height: 30px;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
}
.mm-brand-clear:hover {
    background: #f1f5f9;
    color: #dc2626;
}
.mm-brand-dropdown {
    position: absolute;
    top: 100%; left: 0; right: 0;
    margin-top: 4px;
    background: white;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    z-index: 10;
    max-height: 360px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.mm-brand-dropdown[hidden] { display: none; }
.mm-brand-search {
    width: 100%;
    padding: 6px 12px;
    border: none;
    border-bottom: 1px solid #e2e8f0;
    font: inherit; font-size: 12px;
    box-sizing: border-box;
    outline: none;
}
.mm-brand-list {
    flex: 1;
    overflow-y: auto;
}
.mm-brand-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 12px;
    cursor: pointer;
    font-size: 12px;
    line-height: 1.3;
    border-bottom: 1px solid #f1f5f9;
    transition: background 0.1s;
    min-height: 22px;
}
.mm-brand-item:last-child { border-bottom: none; }
.mm-brand-item:hover { background: #f0fdf4; }
.mm-brand-item.selected { background: #dcfce7; }
.mm-brand-item-create {
    background: #eff6ff;
    color: #1d4ed8;
    font-weight: 500;
}
.mm-brand-item-create:hover { background: #dbeafe; }
.mm-brand-item-icon { flex-shrink: 0; }
.mm-brand-item-name { flex: 1; }
.mm-brand-empty {
    padding: 8px 12px;
    text-align: center;
    color: #94a3b8;
    font-size: 12px;
}

/* Кнопка редактирования бренда (✎) рядом с триггером */
.mm-brand-edit-btn {
    width: 32px;
    height: 32px;
    background: transparent;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    color: #475569;
    font-size: 14px;
    cursor: pointer;
    margin-left: 4px;
    flex-shrink: 0;
    transition: all 0.15s;
}
.mm-brand-edit-btn:hover {
    background: #eff6ff;
    border-color: #2563eb;
    color: #2563eb;
}
.mm-brand-edit-btn[hidden] { display: none; }

/* Кнопка «Входящие фото» — outline в стиле Telegram (без заливки). */
/* Кнопка «Фото» (ссылка на /inbox/). Стандартный размер .btn .btn-sm
   + фирменный синий telegram + иконка-самолетик слева.
   Чистый outline (без заливки) -- синяя рамка, белый фон. */
.tg-photo-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    text-decoration: none;
    background: #ffffff;
    color: #229ED9;
    border: 1.5px solid #229ED9;
}
.tg-photo-btn:hover {
    background: #229ED9;
    color: #ffffff;
    border-color: #229ED9;
}
.tg-photo-btn img {
    border-radius: 50%;
    display: block;
}
.tg-photo-btn-label {
    line-height: 1;
}
.tg-photo-btn-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 16px;
    height: 16px;
    padding: 0 5px;
    background: #ef4444;
    color: #ffffff;
    border-radius: 9px;
    font-size: 11px;
    font-weight: 600;
    line-height: 1;
}
.tg-photo-btn-badge[hidden] { display: none; }
.tg-photo-btn:hover .tg-photo-btn-badge { background: #ffffff; color: #ef4444; }
.tg-photo-btn-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 6px;
    background: #ef4444;
    color: #ffffff;
    border-radius: 9px;
    font-size: 11px;
    font-weight: 600;
    line-height: 1;
    margin-left: 2px;
}
.tg-photo-btn-badge[hidden] { display: none; }
.tg-photo-btn:hover .tg-photo-btn-badge { background: #ffffff; color: #ef4444; }
