/* =============================================
   CSS Variables
   ============================================= */
:root {
    --sidebar-width: 240px;
    --sidebar-collapsed-width: 56px;
    --topbar-height: 52px;
    --transition: 0.2s ease;

    /* Sidebar */
    --sidebar-bg: #111111;
    --sidebar-text: rgba(255, 255, 255, 0.65);
    --sidebar-text-hover: #ffffff;
    --sidebar-hover-bg: rgba(255, 255, 255, 0.07);
    --sidebar-active-bg: rgba(255, 255, 255, 0.13);
    --sidebar-active-text: #ffffff;
    --sidebar-border: rgba(255, 255, 255, 0.07);
    --sidebar-section-text: rgba(255, 255, 255, 0.3);

    /* Layout */
    --topbar-bg: #ffffff;
    --topbar-border: #e8e8e8;
    --page-bg: #f5f5f5;
    --card-bg: #ffffff;

    /* Text */
    --text-primary: #111111;
    --text-muted: #888888;
    --border-color: #e5e5e5;

    /* Accents — только функциональные */
    --accent-danger: #dc3545;
    --accent-danger-light: #fff5f5;
    --accent-warning: #e67e00;
    --accent-warning-light: #fff8f0;
    --accent-success: #1a7f4b;
    --accent-success-light: #f0faf5;
    --accent-info: #0d6efd;
}

/* Alpine cloak */
[x-cloak] { display: none !important; }

/* =============================================
   Base
   ============================================= */
*, *::before, *::after { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 14px;
    color: var(--text-primary);
    background: var(--page-bg);
    -webkit-font-smoothing: antialiased;
}

a { color: inherit; }
a:hover { color: inherit; }

/* =============================================
   App Layout
   ============================================= */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* =============================================
   Sidebar
   ============================================= */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: width var(--transition);
    overflow: hidden;
}

.sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
}

/* Header */
.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--topbar-height);
    padding: 0 14px;
    border-bottom: 1px solid var(--sidebar-border);
    flex-shrink: 0;
}

.sidebar-logo {
    font-size: 20px;
    font-weight: 700;
    color: #ffffff;
    letter-spacing: -0.03em;
    white-space: nowrap;
    overflow: hidden;
    opacity: 1;
    transition: opacity var(--transition);
}

.sidebar.collapsed .sidebar-logo {
    opacity: 0;
    width: 0;
}

.sidebar-toggle {
    background: none;
    border: none;
    color: var(--sidebar-text);
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    line-height: 1;
    flex-shrink: 0;
    transition: color var(--transition), background var(--transition);
}

.sidebar-toggle:hover {
    color: var(--sidebar-text-hover);
    background: var(--sidebar-hover-bg);
}

/* Nav */
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 12px 0;
}

.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: var(--sidebar-border); border-radius: 4px; }

.sidebar-section {
    padding: 16px 16px 4px;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--sidebar-section-text);
    white-space: nowrap;
    overflow: hidden;
    transition: opacity var(--transition);
}

.sidebar.collapsed .sidebar-section {
    opacity: 0;
}

.sidebar.collapsed .sidebar-header {
    justify-content: center;
    padding: 0;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 16px;
    color: var(--sidebar-text);
    text-decoration: none;
    white-space: nowrap;
    transition: color var(--transition), background var(--transition);
    position: relative;
}

.sidebar-link:hover {
    color: var(--sidebar-text-hover);
    background: var(--sidebar-hover-bg);
    text-decoration: none;
}

.sidebar-link.active {
    color: var(--sidebar-active-text);
    background: var(--sidebar-active-bg);
}

.sidebar-link .link-icon {
    width: 24px;
    text-align: center;
    font-size: 14px;
    flex-shrink: 0;
}

.sidebar-link .link-text {
    font-size: 13.5px;
    overflow: hidden;
    opacity: 1;
    transition: opacity var(--transition);
}

.sidebar.collapsed .link-text {
    opacity: 0;
    width: 0;
}

/* Tooltip when collapsed */
.sidebar.collapsed .sidebar-link {
    justify-content: center;
    padding: 9px 0;
    gap: 0;
}

/* =============================================
   Main Content
   ============================================= */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    transition: margin-left var(--transition);
    min-width: 0;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.sidebar.collapsed ~ .main-content {
    margin-left: var(--sidebar-collapsed-width);
}

/* =============================================
   Topbar
   ============================================= */
.topbar {
    height: var(--topbar-height);
    background: var(--topbar-bg);
    border-bottom: 1px solid var(--topbar-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 50;
    flex-shrink: 0;
}

.topbar-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

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

/* =============================================
   Page Content
   ============================================= */
.page-content {
    flex: 1;
    padding: 24px;
}

/* =============================================
   Cards
   ============================================= */
.card {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: none;
    background: var(--card-bg);
}

.card-header {
    background: transparent;
    border-bottom: 1px solid var(--border-color);
    padding: 14px 20px;
    font-weight: 600;
}

.card-body { padding: 20px; }

/* =============================================
   Buttons — монохромные по умолчанию
   ============================================= */
.btn {
    font-size: 13px;
    font-weight: 500;
    border-radius: 6px;
    padding: 6px 14px;
    transition: all var(--transition);
    line-height: 1.5;
}

/* Primary → чёрный */
.btn-primary {
    background: var(--text-primary);
    border-color: var(--text-primary);
    color: #fff;
}
.btn-primary:hover, .btn-primary:focus {
    background: #333;
    border-color: #333;
    color: #fff;
}

/* Secondary → серый бордер */
.btn-secondary {
    background: #fff;
    border-color: var(--border-color);
    color: var(--text-primary);
}
.btn-secondary:hover {
    background: #f5f5f5;
    border-color: #ccc;
    color: var(--text-primary);
}

/* Light → такой же */
.btn-light {
    background: #f5f5f5;
    border-color: var(--border-color);
    color: var(--text-primary);
}
.btn-light:hover {
    background: #eee;
    border-color: #ccc;
    color: var(--text-primary);
}

/* Warning → акцент */
.btn-warning {
    background: var(--accent-warning);
    border-color: var(--accent-warning);
    color: #fff;
}
.btn-warning:hover {
    background: #c86d00;
    border-color: #c86d00;
    color: #fff;
}

/* Danger → акцент */
.btn-danger {
    background: var(--accent-danger);
    border-color: var(--accent-danger);
    color: #fff;
}
.btn-danger:hover {
    background: #b02a37;
    border-color: #b02a37;
    color: #fff;
}

/* Success → акцент */
.btn-success {
    background: var(--accent-success);
    border-color: var(--accent-success);
    color: #fff;
}
.btn-success:hover {
    background: #145f38;
    border-color: #145f38;
    color: #fff;
}

/* Icon-only кнопки */
.btn-icon {
    background: none;
    border: none;
    color: var(--text-muted);
    padding: 6px 8px;
    border-radius: 6px;
    cursor: pointer;
    transition: color var(--transition), background var(--transition);
    line-height: 1;
    font-size: 15px;
    display: inline-flex;
    align-items: center;
}
.btn-icon:hover {
    color: var(--text-primary);
    background: #f0f0f0;
}
.btn-icon.danger:hover {
    color: var(--accent-danger);
    background: var(--accent-danger-light);
}

/* Outline variants */
.btn-outline-secondary {
    color: var(--text-muted);
    border-color: var(--border-color);
    background: transparent;
}
.btn-outline-secondary:hover {
    color: var(--text-primary);
    background: #f5f5f5;
    border-color: #ccc;
}

/* =============================================
   Forms
   ============================================= */
.form-control, .form-select {
    font-size: 13px;
    border-color: var(--border-color);
    border-radius: 6px;
    padding: 6px 10px;
    color: var(--text-primary);
    background-color: #fff;
    transition: border-color var(--transition), box-shadow var(--transition);
}
.form-control:focus, .form-select:focus {
    border-color: #999;
    box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.06);
}
.form-control::placeholder { color: var(--text-muted); }

.form-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 4px;
}

.form-check-input:checked {
    background-color: var(--text-primary);
    border-color: var(--text-primary);
}

/* =============================================
   Tables
   ============================================= */
.table {
    font-size: 13px;
    color: var(--text-primary);
    border-color: var(--border-color);
}

.table th {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
    padding: 10px 12px;
    white-space: nowrap;
    background: #fafafa;
}

.table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}

.table tbody tr:last-child td { border-bottom: none; }

.table-hover tbody tr:hover td { background: #f9f9f9; }

/* Цветные строки таблиц — только лёгкий акцент */
.bg-table-warning { background-color: var(--accent-warning-light) !important; }
.bg-table-success { background-color: var(--accent-success-light) !important; }
.bg-table-danger  { background-color: var(--accent-danger-light) !important; }

/* =============================================
   Badges / Статусы
   ============================================= */
.badge {
    font-size: 11px;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 4px;
    letter-spacing: 0.02em;
}

.badge-neutral {
    background: #f0f0f0;
    color: var(--text-muted);
}

/* =============================================
   Alerts — только акцентные
   ============================================= */
.alert {
    border-radius: 8px;
    font-size: 13px;
    border: none;
    padding: 12px 16px;
}
.alert-danger  { background: var(--accent-danger-light);  color: var(--accent-danger); }
.alert-warning { background: var(--accent-warning-light); color: var(--accent-warning); }
.alert-success { background: var(--accent-success-light); color: var(--accent-success); }

/* =============================================
   Pagination
   ============================================= */
.pagination {
    gap: 4px;
}
.page-link {
    border-radius: 6px !important;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 5px 11px;
    font-size: 13px;
}
.page-link:hover {
    background: #f5f5f5;
    color: var(--text-primary);
    border-color: #ccc;
}
.page-item.active .page-link {
    background: var(--text-primary);
    border-color: var(--text-primary);
    color: #fff;
}

/* =============================================
   Utilities
   ============================================= */
.text-muted { color: var(--text-muted) !important; }

.divider {
    height: 1px;
    background: var(--sidebar-border);
    margin: 8px 0;
}

/* Скрытые колонки таблицы (Alpine :class — устаревший метод) */
.col-hidden { display: none !important; }

/* Скрытие колонок через класс на таблице (#products-table) */
#products-table.hide-stock     .col-stock     { display: none !important; }
#products-table.hide-limit     .col-limit     { display: none !important; }
#products-table.hide-cell      .col-cell      { display: none !important; }
#products-table.hide-active    .col-active    { display: none !important; }
#products-table.hide-wb_sw     .col-wb_sw     { display: none !important; }
#products-table.hide-ozon_sw   .col-ozon_sw   { display: none !important; }
#products-table.hide-yndx_sw   .col-yndx_sw   { display: none !important; }
#products-table.hide-price_base .col-price_base { display: none !important; }
#products-table.hide-price_wb  .col-price_wb  { display: none !important; }
#products-table.hide-price_ozon .col-price_ozon { display: none !important; }
#products-table.hide-price_yndx .col-price_yndx { display: none !important; }
#products-table.hide-film      .col-film      { display: none !important; }

/* Убираем синий outline у Bootstrap */
:focus-visible { outline: 2px solid rgba(0, 0, 0, 0.2); outline-offset: 2px; }
.btn:focus-visible { outline: 2px solid rgba(0, 0, 0, 0.25); }

/* =============================================
   Columns dropdown
   ============================================= */
.cols-dropdown {
    min-width: 220px;
    padding: 8px 0;
}

.cols-dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 16px;
    cursor: pointer;
    transition: background var(--transition);
}

.cols-dropdown-item:hover { background: #f5f5f5; }

.cols-dropdown-item label {
    font-size: 13px;
    color: var(--text-primary);
    cursor: pointer;
    margin: 0;
    flex: 1;
}

.cols-dropdown-divider {
    height: 1px;
    background: var(--border-color);
    margin: 6px 0;
}

.cols-dropdown-group {
    padding: 4px 16px 2px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
}

/* =============================================
   Filter Drawer (правый сайдбар)
   ============================================= */
.filter-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.25);
    z-index: 200;
    backdrop-filter: blur(1px);
}

.filter-drawer {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 320px;
    background: #fff;
    z-index: 201;
    display: flex;
    flex-direction: column;
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.1);
    transform: translateX(100%);
    transition: transform 0.25s ease;
}

.filter-drawer.open {
    transform: translateX(0);
}

.filter-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.filter-drawer-title {
    font-size: 14px;
    font-weight: 600;
    margin: 0;
}

.filter-drawer-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.filter-drawer-footer {
    padding: 14px 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.filter-section-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 8px;
}

/* Marketplace checkboxes */
.mp-checkbox-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.mp-checkbox-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    transition: background var(--transition);
}

.mp-checkbox-item:hover {
    background: #f8f8f8;
}

.mp-checkbox-item input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    margin: 0;
    accent-color: var(--text-primary);
}

.mp-checkbox-item img {
    width: 18px;
    height: 18px;
    object-fit: contain;
}

.mp-checkbox-item span {
    font-size: 13px;
    color: var(--text-primary);
    flex: 1;
}

/* =============================================
   Column drawer checklist
   ============================================= */
.cols-check-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 0;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    margin: 0;
}

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

.cols-check-item input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    margin: 0;
    flex-shrink: 0;
    accent-color: var(--text-primary);
}

.cols-check-item span {
    font-size: 13px;
    color: var(--text-primary);
    flex: 1;
}

/* =============================================
   Active Filter Chips
   ============================================= */
.filter-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}

.filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #f0f0f0;
    color: var(--text-primary);
    font-size: 12px;
    font-weight: 500;
    padding: 4px 10px;
    border-radius: 20px;
    white-space: nowrap;
}

.filter-chip button {
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 13px;
    line-height: 1;
    display: flex;
    align-items: center;
    transition: color var(--transition);
}

.filter-chip button:hover {
    color: var(--accent-danger);
}

/* =============================================
   Page Load Preloader
   ============================================= */
#page-preloader {
    position: fixed;
    inset: 0;
    background: #ffffff;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 1;
    transition: opacity 0.2s ease;
}

#page-preloader.done {
    opacity: 0;
    pointer-events: none;
}

/* =============================================
   Preloader Overlay
   ============================================= */
.preloader-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.65);
    z-index: 999;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(2px);
}

.preloader-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid #e0e0e0;
    border-top-color: var(--text-primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* =============================================
   Table — sticky header + inline edit styles
   ============================================= */

/* Обёртка с ограниченной высотой для sticky */
.table-sticky-wrap {
    overflow-y: auto;
    max-height: calc(100vh - 220px);
    border-radius: 8px;
}

.table-sticky-wrap .table thead th {
    position: sticky;
    z-index: 10;
    background: #fafafa;
}

/* Single-row thead — прибит к 0 */
.table-sticky-wrap .table thead tr:first-child th {
    top: 0;
    box-shadow: 0 1px 0 var(--border-color);
}

.table td .form-control-sm {
    font-size: 12px;
    padding: 4px 7px;
    min-width: 74px;
}

/* Логотипы маркетплейсов в заголовке — фикс размер */
.table th .mp-logo,
.table td .mp-logo {
    width: 18px;
    height: 18px;
    object-fit: contain;
    display: block;
    margin: 0 auto;
    flex-shrink: 0;
}

.table td.price-cell {
    min-width: 96px;
}

.price-input-wrap {
    display: flex;
    align-items: center;
    gap: 5px;
}

.price-input-wrap .price-logo {
    width: 14px;
    height: 14px;
    object-fit: contain;
    opacity: 0.45;
    flex-shrink: 0;
}

.table td.center-cell,
.table th.center-cell {
    text-align: center;
    vertical-align: middle;
}

/* Свитчи в таблице — компактнее стандартного BS */
.table-switch {
    display: inline-block;
    position: relative;
    width: 32px;
    height: 18px;
    flex-shrink: 0;
}

.table-switch input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

.table-switch-track {
    position: absolute;
    inset: 0;
    background: #ddd;
    border-radius: 18px;
    cursor: pointer;
    transition: background var(--transition);
}

.table-switch-track::after {
    content: '';
    position: absolute;
    width: 12px;
    height: 12px;
    background: #fff;
    border-radius: 50%;
    top: 3px;
    left: 3px;
    transition: transform var(--transition);
    box-shadow: 0 1px 3px rgba(0,0,0,.2);
}

.table-switch input:checked + .table-switch-track {
    background: var(--text-primary);
}

.table-switch input:checked + .table-switch-track::after {
    transform: translateX(14px);
}

.table-switch input:disabled + .table-switch-track {
    opacity: 0.35;
    cursor: not-allowed;
}

/* =============================================
   Stats Row (показатели — стиль DataLens)
   ============================================= */
.stats-row {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.stat-card {
    flex: 1;
    min-width: 180px;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 18px 22px 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,.08);
}

.stat-card-label {
    font-size: 12px;
    font-weight: 400;
    color: var(--text-muted);
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.stat-card-value {
    font-size: 30px;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1;
    letter-spacing: -0.02em;
}

.stat-card-value small {
    font-size: 16px;
    font-weight: 400;
    color: var(--text-muted);
    margin-left: 3px;
    letter-spacing: 0;
}

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

/* =============================================
   Bulk Action Bar
   ============================================= */
.bulk-action-bar {
    position: fixed;
    bottom: 0;
    left: var(--sidebar-width);
    right: 0;
    background: var(--text-primary);
    color: #fff;
    padding: 12px 24px;
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 95;
    box-shadow: 0 -2px 16px rgba(0, 0, 0, 0.2);
    transition: left var(--transition);
}

.bulk-action-count {
    font-size: 13px;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.7);
    margin-right: 4px;
}

.sidebar.collapsed ~ .main-content .bulk-action-bar {
    left: var(--sidebar-collapsed-width);
}

/* ── Drop zone ───────────────────────────────────────────────── */
.drop-zone {
    border: 2px dashed var(--border-color);
    border-radius: 8px;
    padding: 40px 24px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
    color: var(--text-muted);
}
.drop-zone:hover,
.drop-zone--over {
    border-color: var(--accent-primary);
    background: rgba(var(--accent-primary-rgb, 13, 110, 253), 0.04);
    color: var(--text-primary);
}

/* ── ZenBi logo ──────────────────────────────────────────────── */
.sidebar-logo-accent {
    color: #fc3f1d;
}
.login-logo {
    font-size: 32px;
    font-weight: 700;
    letter-spacing: -0.04em;
    color: var(--text-primary);
}
