/* === БЛОК 010 | app.css | v4.0 | База и Переменные === */
:root, [data-theme="dark"] {
    --bg-dark: #0f172a; --bg-panel: #1e293b; --bg-card: #232f42; 
    --accent: #3b82f6; --accent-hover: #2563eb; 
    --danger: #ef4444; --success: #10b981; --warning: #f59e0b; --border: #334155; 
    --text-main: #f8fafc; --text-muted: #94a3b8; --overlay: rgba(0, 0, 0, 0.75); 
    --touch: 44px; --sidebar: 280px;
    --radius: 12px; --space-1: 8px; --space-2: 16px;
    --shadow: 0 4px 12px rgba(0,0,0,0.3);
}

* { margin: 0; padding: 0; box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
body { background: var(--bg-dark); color: var(--text-main); display: flex; flex-direction: column; width: 100vw; height: 100vh; overflow: hidden; }

/* Утилиты flex/grid */
.flex { display: flex; } 
.flex-col { display: flex; flex-direction: column; } 
.flex-1 { flex: 1 1 auto; overflow: hidden; } 
.flex-shrink-0 { flex-shrink: 0 !important; }

.items-center { align-items: center; } 
.items-start { align-items: flex-start; }
.justify-between { justify-content: space-between; } 
.justify-center { justify-content: center; }

.gap-1 { gap: var(--space-1); } .gap-2 { gap: var(--space-2); } 
.p-1 { padding: var(--space-1); } .p-2 { padding: var(--space-2); } 
.px-1 { padding-left: var(--space-1); padding-right: var(--space-1); } 
.px-2 { padding-left: var(--space-2); padding-right: var(--space-2); }
.mt-1 { margin-top: var(--space-1); } .mt-2 { margin-top: var(--space-2); } 
.mb-1 { margin-bottom: var(--space-1); } .mb-2 { margin-bottom: var(--space-2); }

/* Цвета и границы */
.bg-panel { background: var(--bg-panel); } .bg-dark { background: var(--bg-dark); } .bg-card { background: var(--bg-card); }
.brd { border: 1px solid var(--border); } .brd-b { border-bottom: 1px solid var(--border); } 
.brd-t { border-top: 1px solid var(--border); } .brd-r { border-right: 1px solid var(--border); } .brd-l { border-left: 1px solid var(--border); }
.rounded { border-radius: var(--radius); } 
.shadow-card { box-shadow: var(--shadow); }

.text-accent { color: var(--accent); } 
.text-muted { color: var(--text-muted); font-size: 12px; } 
.text-danger { color: var(--danger); } 
.text-warning { color: var(--warning); } 
.text-success { color: var(--success); }
.font-bold { font-weight: 700; } 
.text-xs { font-size: 11px; } .text-sm { font-size: 13px; } .text-lg { font-size: 16px; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.w-100 { width: 100%; } .h-100 { height: 100%; } .hidden { display: none !important; }

/* Скроллбары */
.scroll { overflow-y: auto; -webkit-overflow-scrolling: touch; scrollbar-width: thin; scrollbar-color: var(--border) var(--bg-dark); } 
.scroll::-webkit-scrollbar { width: 6px; }
.scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
/* === КОНЕЦ БЛОКА 010 === */

/* === БЛОК 020 | app.css | v4.0 | Элементы Форм (Touch-зоны) === */
.btn { background: var(--bg-panel); color: var(--text-main); border: 1px solid var(--border); min-height: var(--touch); padding: 0 16px; border-radius: 10px; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; transition: 0.15s; white-space: nowrap; font-size: 14px;}
.btn:active { transform: scale(0.97); } .btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-accent { background: var(--accent); color: #fff; border: none; }
.btn-success { background: var(--success); color: #fff; border: none; }
.btn-warning { background: var(--warning); color: #fff; border: none; }
.btn-danger { background: var(--bg-panel); color: var(--danger); border-color: var(--danger); }
.btn-icon { background: none; border: none; padding: 0; min-width: var(--touch); min-height: var(--touch); color: var(--text-main); cursor: pointer; display: flex; align-items: center; justify-content: center; transition: 0.15s; }

.input { width: 100%; min-height: var(--touch); padding: 0 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg-dark); color: var(--text-main); font-size: 14px; outline: none; transition: border-color 0.2s; }
.input:focus { border-color: var(--accent); }
textarea.input { padding: 12px; resize: vertical; min-height: 80px; font-family: inherit; }

/* Кастомный Select */
select.input { appearance: none; cursor: pointer; background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%2394a3b8%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E"); background-repeat: no-repeat; background-position: right 12px top 50%; background-size: 10px auto; padding-right: 30px; }

/* Чекбоксы и списки */
input[type="checkbox"] { accent-color: var(--accent); width: 20px; height: 20px; cursor: pointer; flex-shrink: 0; margin-top: 2px; }
label { display: flex; align-items: flex-start; gap: 8px; line-height: 1.3; cursor: pointer; word-break: break-word; }

/* Отключение ховера на мобильных (TMA/Touch) */
@media (hover: none) {
    .btn:hover { transform: none !important; }
    .accordion-header:hover { background: var(--bg-dark) !important; }
}
/* === КОНЕЦ БЛОКА 020 === */
/* === БЛОК 030 | app.css | v4.6 | Лейаут Админки и Сайдбары === */
.main-area { display: flex; flex: 1; overflow: hidden; position: relative; width: 100vw; }

/* Центральная зона скролла - min-width:0 критически важно для сжатия Flexbox! */
#main-scroll-area { flex: 1; min-width: 0; overflow-y: auto; overflow-x: hidden; padding: 16px; background: var(--bg-dark); }

/* Сайдбары в нормальном потоке на Десктопе */
.sidebar { width: var(--sidebar); min-width: var(--sidebar); background: var(--bg-panel); display: flex; flex-direction: column; flex-shrink: 0; z-index: 10; transition: transform 0.3s ease; }
.sidebar-left { border-right: 1px solid var(--border); }
.sidebar-right { border-left: 1px solid var(--border); width: 320px; min-width: 320px; }

.nav-link { display: flex; align-items: center; gap: 12px; padding: 12px 16px; color: var(--text-main); font-size: 14px; cursor: pointer; border-bottom: 1px solid var(--border); transition: 0.1s; user-select: none; }
.nav-link.active { border-left: 4px solid var(--accent); background: var(--bg-dark); font-weight: bold; color: var(--accent); padding-left: 12px; }
/* === КОНЕЦ БЛОКА 030 === */
/* === БЛОК 040 | app.css | v3.4 | ИСПРАВЛЕНИЕ: Модальные окна (Скролл) === */
.modal { position: fixed; inset: 0; background: var(--overlay); z-index: 1000; display: flex; align-items: center; justify-content: center; backdrop-filter: blur(4px); padding: 10px; }
.modal-box { background: var(--bg-panel); width: 100%; max-width: 600px; border-radius: 12px; overflow: hidden; display: flex; flex-direction: column; max-height: 95vh; box-shadow: 0 10px 30px rgba(0,0,0,0.5); }
.modal-box.large { max-width: 800px; }

/* Внутренний контейнер модалки, который должен скроллиться */
.modal-box > .scroll { flex: 1 1 auto; overflow-y: auto; padding: 16px; }

.tabs-nav { display: flex; border-bottom: 1px solid var(--border); background: var(--bg-dark); overflow-x: auto; scrollbar-width: none; flex-shrink: 0; }
.tabs-nav::-webkit-scrollbar { display: none; }
.tab-btn { flex: 1; min-width: max-content; background: none; border: none; padding: 12px 16px; color: var(--text-muted); font-size: 13px; font-weight: bold; cursor: pointer; white-space: nowrap; border-bottom: 2px solid transparent; transition: 0.2s; }
.tab-btn.active { color: var(--accent); border-bottom: 2px solid var(--accent); background: var(--bg-panel); }
.tab-pane { display: none; flex-direction: column; gap: 12px; padding: 16px; overflow-y: auto; flex: 1 1 auto; }
.tab-pane.active { display: flex; }

/* === БЛОК 050 | app.css | v3.4 | Таблицы и Липкий Скролл === */
/* ИСПРАВЛЕНИЕ: Горизонтальный скроллбар прилипает к низу экрана */
.table-wrapper { 
    width: 100%; 
    overflow-x: auto; 
    -webkit-overflow-scrolling: touch; 
    border: 1px solid var(--border); 
    border-radius: 8px; 
    background: var(--bg-panel); 
    padding-bottom: 8px;
    /* Убираем жесткую высоту, чтобы скролл был внизу экрана */
}
.table-wrapper::-webkit-scrollbar { height: 10px; }
.table-wrapper::-webkit-scrollbar-thumb { background: var(--accent); border-radius: 5px; }
.table-wrapper::-webkit-scrollbar-track { background: var(--bg-dark); }

/* Табличный вид */
.data-container.view-table { display: flex; flex-direction: column; min-width: max-content; width: 100%; }
.view-table .tbl-header { display: grid; background: var(--bg-dark); font-size: 12px; font-weight: bold; color: var(--text-muted); border-bottom: 2px solid var(--border); position: sticky; top: 0; z-index: 5; }
.view-table .tbl-header > div { padding: 10px 8px; display: flex; align-items: center; user-select: none; border-right: 1px solid var(--border); }
.view-table .u-item { display: grid; align-items: center; border-bottom: 1px solid var(--border); transition: background 0.1s; }
.view-table .u-item:hover { background: var(--bg-dark); }
.view-table .u-item > div { padding: 8px; border-right: 1px solid var(--border); height: 100%; display: flex; flex-direction: column; justify-content: center; overflow: hidden; position: relative;}
.view-table .c-val { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; font-size: 13px; }
.view-table .c-lbl { display: none; }

/* Инлайн редактор в таблице */
.inline-input { width: 100%; height: 100%; min-height: 28px; background: transparent; border: 1px dashed transparent; color: var(--accent); font-size: 13px; outline: none; padding: 2px 4px; }
.inline-input:hover { border-color: var(--border); background: var(--bg-dark); }
.inline-input:focus { border-color: var(--accent); background: var(--bg-dark); color: var(--text-main); }

/* === БЛОК 060 | app.css | v5.1 | Карточки: Фиксация размера и 3 строки заголовка === */
:root { --card-bg: #121b28; --card-border: #1e3a5f; --card-border-hover: #3b82f6; }

.card-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); padding: 8px; }

/* ФИКС: Жесткая высота 320px, чтобы они были идеально ровными */
.card { background: var(--card-bg); border: 1px solid var(--card-border); border-radius: 16px; padding: 16px; display: flex; flex-direction: column; transition: all 0.2s ease; position: relative; cursor: pointer; box-shadow: 0 4px 6px rgba(0,0,0,0.1); height: 320px; }
.card:hover { border-color: var(--card-border-hover); box-shadow: 0 8px 16px rgba(0,0,0,0.4); transform: translateY(-2px); }

.card .main-cb { position: absolute; top: 16px; right: 16px; z-index: 10; margin: 0; }
.card .main-cb input { width: 20px; height: 20px; cursor: pointer; border-radius: 4px; accent-color: var(--accent); }

.card-header { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 12px; padding-bottom: 12px; border-bottom: 1px solid rgba(255,255,255,0.05); padding-right: 30px; flex-shrink: 0; }
.card-header .flex-1 { min-width: 0; } 

/* ФИКС ЗАГОЛОВКА: Шрифт мельче, ровно 3 строки и троеточие */
.card-title-text { 
    font-size: 13px !important; 
    line-height: 1.3; 
    display: -webkit-box; 
    -webkit-line-clamp: 3; 
    -webkit-box-orient: vertical; 
    overflow: hidden; 
    text-overflow: ellipsis; 
    white-space: normal; 
}

/* ФИКС ТЕЛА: Если полей много, они будут скроллиться внутри карточки */
.card-body { display: flex; flex-wrap: wrap; gap: 12px 8px; flex: 1; overflow-y: auto; align-content: flex-start; padding-right: 4px; }
.card-body::-webkit-scrollbar { width: 4px; }
.card-body::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 4px; }

.col-settings-btn { position: relative; z-index: 100; }
.col-settings-dropdown { position: absolute; right: 0; top: 100%; z-index: 9999; max-height: 70vh; overflow-y: auto; background: var(--bg-panel); border: 1px solid var(--border); border-radius: 12px; width: 340px; max-width: 90vw; box-shadow: 0 10px 40px rgba(0,0,0,0.9); }

.accordion-item { border: 1px solid var(--border); border-radius: 12px; margin-bottom: 8px; overflow: hidden; background: var(--bg-panel); }
.accordion-header { padding: 16px 12px; font-weight: bold; background: var(--bg-dark); cursor: pointer; display: flex; justify-content: space-between; align-items: center; user-select: none; transition: background 0.2s; font-size: 14px; color: var(--accent); }
.accordion-item.active .accordion-header .icon { transform: rotate(180deg); }
.accordion-body { display: none; padding: 12px; flex-direction: column; gap: 12px; border-top: 1px solid var(--border); }
.accordion-item.active .accordion-body { display: flex; }

.modal-header { position: sticky; top: 0; z-index: 30; background: var(--bg-dark); border-bottom: 1px solid var(--border); padding: 16px; border-radius: 16px 16px 0 0; display: flex; justify-content: space-between; align-items: center; }
.modal-content { flex: 1; overflow-y: auto; padding: 16px; }
.modal-footer { position: sticky; bottom: 0; z-index: 30; background: var(--bg-dark); border-top: 1px solid var(--border); padding: 16px; border-radius: 0 0 16px 16px; display: flex; gap: 8px; }
/* === КОНЕЦ БЛОКА 060 === */
/* === БЛОК 070 | app.css | v3.4 | ИСПРАВЛЕНИЕ: ФРОНТЕНД (Центрирование и Корзина) === */
/* Карточка товара на витрине */
.product-card {
    display: flex; flex-direction: column; align-items: center; justify-content: space-between; text-align: center;
    background: var(--bg-panel); border: 1px solid var(--border); border-radius: 12px; padding: 16px; height: 100%;
}

/* ИСПРАВЛЕНИЕ: Центрирование картинки */
.product-card img { width: 100%; aspect-ratio: 1/1; object-fit: contain; border-radius: 8px; margin: 0 auto 12px auto; display: block; background: #fff; }

.product-card .price-block { margin-top: auto; padding-top: 12px; width: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; }

/* ИСПРАВЛЕНИЕ: Огромные центрированные кнопки корзины */
.cart-controls { display: flex; align-items: center; justify-content: center; gap: 12px; width: 100%; margin-top: 12px; }
.cart-btn { 
    width: 48px; height: 48px; flex-shrink: 0;
    border-radius: 12px; background: var(--bg-dark); color: var(--text-main); 
    border: 1px solid var(--border); font-size: 24px; font-weight: bold; cursor: pointer;
    display: flex; align-items: center; justify-content: center; transition: 0.1s;
}
.cart-btn:active { background: var(--accent); color: white; transform: scale(0.9); }
.cart-input { 
    width: 64px; height: 48px; text-align: center; font-size: 18px; font-weight: bold; 
    border: 1px solid var(--border); border-radius: 10px; background: var(--bg-dark); color: var(--text-main);
}

/* Выпадающий список категорий в админке (чтобы не был уродливым) */
#admin-cat-dropdown { z-index: 100; box-shadow: 0 10px 25px rgba(0,0,0,0.8); max-width: 350px; }
#admin-cat-tree details summary { padding: 4px 0; outline: none; display: flex; align-items: flex-start; gap: 8px; }

/* === БЛОК 080 | app.css | v5.1 | Мобильная сетка: строго 2 карточки === */
.search-wrapper { position: relative; width: 100%; max-width: 400px; margin: 0 auto; }
.search-wrapper::after { content: ''; position: absolute; right: 12px; top: 14px; width: 14px; height: 14px; border: 2px solid transparent; border-top-color: var(--accent); border-radius: 50%; opacity: 0; transition: opacity 0.2s; }
.search-wrapper.loading::after { opacity: 1; animation: spin 1s linear infinite; }
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

#toast-container { position: fixed; bottom: 70px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 9999; pointer-events: none;}
.toast { background: var(--success); color: white; padding: 12px 20px; border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.5); font-size: 14px; font-weight: bold; animation: slideIn 0.3s ease-out; transition: opacity 0.3s; pointer-events: auto;}
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

.drag-item { cursor: grab; transition: opacity 0.2s; background: var(--bg-dark); }
.drag-item:active { cursor: grabbing; }
.drag-item.dragging { opacity: 0.4; box-shadow: 0 0 10px rgba(59, 130, 246, 0.5); border-color: var(--accent); }

@media (max-width: 992px) {
    .sidebar { position: absolute; top: 0; bottom: 0; z-index: 30; box-shadow: 0 0 30px rgba(0,0,0,0.8); }
    .sidebar-left { left: 0; transform: translateX(-100%); }
    .sidebar-right { right: 0; transform: translateX(100%); }
    .sidebar.open { transform: translateX(0); }
}

@media (max-width: 767px) {
    #main-scroll-area { padding: 4px; overflow-x: hidden; }
    
    .card-grid {
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 6px !important;
        padding: 0 2px !important;
    }
    
    /* ФИКС: Жесткая высота 260px на телефонах */
    .card { padding: 8px; border-radius: 10px; height: 260px; }
    .card-header { gap: 6px; padding-right: 20px; padding-bottom: 8px; margin-bottom: 8px; flex-direction: column; align-items: flex-start; }
    
    .text-xs { font-size: 11px !important; }
    .text-sm { font-size: 12px !important; }
    
    .card-header img { width: 40px !important; height: 40px !important; }
    .card .main-cb { top: 8px; right: 8px; }
    .card .main-cb input { width: 18px; height: 18px; }
    
    .modal { padding: 0 !important; }
    .modal-box { width: 100% !important; height: 100vh !important; max-width: 100% !important; max-height: 100vh !important; border-radius: 0 !important; border: none !important; margin: 0 !important; }
    .modal-box.large { width: 100% !important; }
    .modal-header { border-radius: 0 !important; }
    .modal-footer { border-radius: 0 !important; padding-bottom: calc(16px + env(safe-area-inset-bottom)); flex-direction: column; gap: 8px;}
    .modal-footer .btn { width: 100%; }
}
/* === КОНЕЦ БЛОКА 080 === */