/* =========================================
   1. VARIABLES & RESET
   ========================================= */
@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;600;700&display=swap');

:root {
    /* Brand Colors */
    --primary: #E30613;          /* Фирменный красный */
    --primary-hover: #c40511;    /* Темно-красный для ховера */
    --dark: #202020;             /* Темный текст */
    --gray: #777777;             /* Серый текст */
    --light-gray: #f4f6f9;       /* Фон страницы */
    --border: #e0e0e0;           /* Границы */
    --white: #ffffff;
    
    /* System Colors */
    --success: #28a745;
    --danger: #dc3545;
    
    /* Spacing & Layout */
    --radius: 8px;
    --shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
    --shadow-hover: 0 8px 25px rgba(227, 6, 19, 0.15); /* Красноватая тень */
    --container-width: 1200px;
    --header-height: 70px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    outline: none;
}

body {
    font-family: 'Montserrat', sans-serif;
    background-color: var(--light-gray);
    color: var(--dark);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { text-decoration: none; color: inherit; }
ul { list-style: none; }
img { max-width: 100%; display: block; }

/* =========================================
   2. LOGIN SCREEN
   ========================================= */
.login-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background: linear-gradient(135deg, #2b2b2b 0%, #1a1a1a 100%);
}

.login-card {
    background: var(--white);
    padding: 40px;
    border-radius: var(--radius);
    width: 100%;
    max-width: 400px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    text-align: center;
    position: relative;
    overflow: hidden;
}

.login-card::top {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 5px;
    background: var(--primary);
}

.login-logo {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 30px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.login-logo span { color: var(--primary); }

.login-form input {
    width: 100%;
    padding: 12px 15px;
    margin-bottom: 20px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 16px;
    transition: 0.3s;
    text-align: center;
    letter-spacing: 5px; /* Для пароля */
}

.login-form input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(227, 6, 19, 0.1);
}

.btn-login {
    width: 100%;
    padding: 12px;
    background: var(--primary);
    color: var(--white);
    border: none;
    border-radius: var(--radius);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: 0.3s;
}

.btn-login:hover { background: var(--primary-hover); }

.login-error {
    color: var(--danger);
    margin-bottom: 15px;
    font-size: 13px;
    display: none;
}

/* =========================================
   3. HEADER & LAYOUT
   ========================================= */
.app-header {
    background: var(--white);
    height: var(--header-height);
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-container {
    max-width: var(--container-width);
    margin: 0 auto;
    padding: 0 20px;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.brand {
    font-size: 20px;
    font-weight: 700;
    text-transform: uppercase;
}
.brand span { color: var(--primary); }

.logout-link {
    font-weight: 500;
    font-size: 13px;
    color: var(--gray);
    transition: 0.2s;
    display: flex;
    align-items: center;
    gap: 5px;
}
.logout-link:hover { color: var(--primary); }

.main-content {
    max-width: var(--container-width);
    margin: 30px auto;
    padding: 0 20px;
    min-height: calc(100vh - var(--header-height) - 60px);
}

/* =========================================
   4. CONTROLS BAR
   ========================================= */
.controls-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    flex-wrap: wrap;
    gap: 15px;
}

.search-wrap {
    flex-grow: 1;
    max-width: 400px;
    position: relative;
}

.search-input {
    width: 100%;
    padding: 12px 15px 12px 40px;
    border: 1px solid var(--border);
    border-radius: 50px; /* Round search */
    font-size: 14px;
    transition: 0.3s;
}

.search-input:focus {
    border-color: var(--dark);
}

.search-icon {
    position: absolute;
    left: 15px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--gray);
}

.btn-add {
    background: var(--primary);
    color: var(--white);
    padding: 12px 25px;
    border-radius: 50px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 10px rgba(227, 6, 19, 0.3);
    transition: 0.3s;
}

.btn-add:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(227, 6, 19, 0.4);
}

/* =========================================
   5. PRODUCT GRID & CARDS
   ========================================= */
.product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 25px;
}

.product-card {
    background: var(--white);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    transition: 0.3s ease;
    border: 1px solid transparent;
    display: flex;
    flex-direction: column;
    position: relative;
}

.product-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-hover);
    border-color: rgba(227, 6, 19, 0.1);
}

.card-img-wrap {
    height: 200px;
    width: 100%;
    background: #f9f9f9;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.card-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: 0.5s;
}

.product-card:hover .card-img {
    transform: scale(1.05);
}

.card-body {
    padding: 20px;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}

.card-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--dark);
    line-height: 1.3;
}

.card-sku {
    font-size: 12px;
    color: var(--gray);
    margin-bottom: 10px;
}

.card-price {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary);
    margin-top: auto; /* Push to bottom of body */
}

.card-price s {
    font-size: 13px;
    color: #999;
    font-weight: 400;
    margin-right: 5px;
}

.card-actions {
    padding: 15px 20px;
    border-top: 1px solid #f0f0f0;
    display: flex;
    gap: 10px;
    background: #fafafa;
}

.btn-card {
    flex: 1;
    padding: 8px;
    border-radius: 4px;
    border: 1px solid var(--border);
    background: var(--white);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: 0.2s;
    text-align: center;
}

.btn-edit:hover {
    border-color: var(--dark);
    background: var(--dark);
    color: var(--white);
}

.btn-delete:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: #fff5f5;
}

/* =========================================
   6. MODAL & FORMS
   ========================================= */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(3px);
    z-index: 1000;
    display: none; /* JS toggles this */
    justify-content: center;
    align-items: flex-start; /* Start from top so it can scroll */
    overflow-y: auto;
    padding: 20px;
}

.modal-overlay.active { display: flex; }

.modal-content {
    background: var(--white);
    width: 100%;
    max-width: 800px;
    border-radius: var(--radius);
    box-shadow: 0 15px 50px rgba(0,0,0,0.3);
    margin-top: 20px;
    margin-bottom: 20px;
    animation: slideDown 0.3s ease;
    overflow: hidden;
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}

.modal-header {
    padding: 20px 30px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-title { font-size: 18px; font-weight: 700; }

.btn-close {
    background: none; border: none; font-size: 24px; cursor: pointer; color: var(--gray);
}
.btn-close:hover { color: var(--primary); }

/* Tabs inside Modal */
.modal-tabs {
    display: flex;
    background: #f9f9f9;
    border-bottom: 1px solid #eee;
}

.tab-btn {
    padding: 15px 25px;
    border: none;
    background: none;
    font-weight: 600;
    color: var(--gray);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: 0.2s;
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    background: var(--white);
}

.modal-body {
    padding: 30px;
}

.tab-content { display: none; }
.tab-content.active { display: block; }

/* Form Elements */
.form-group { margin-bottom: 20px; }

.form-label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    font-size: 13px;
    color: #444;
}

.form-control {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 14px;
    font-family: inherit;
    transition: 0.2s;
}

textarea.form-control { resize: vertical; min-height: 80px; }

.form-control:focus {
    border-color: var(--dark);
    background: #fffcfc;
}

.form-row {
    display: flex;
    gap: 20px;
}
.form-col { flex: 1; }

/* --- UPDATED: Image Uploader --- */
.img-uploader-area {
    display: block; /* Важно: чтобы label вел себя как блок */
    width: 100%;
    border: 2px dashed #ddd;
    border-radius: var(--radius);
    padding: 30px;
    text-align: center;
    cursor: pointer;
    transition: 0.3s;
    background: #fafafa;
    position: relative;
    margin-bottom: 25px; /* Увеличенный отступ снизу */
}

.img-uploader-area:hover {
    border-color: var(--primary);
    background: #fffafa;
}

.img-preview-container {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    margin-top: 0;
    width: 100%;
}

.img-preview-item {
    width: 100px;
    height: 100px;
    border-radius: 4px;
    overflow: hidden;
    position: relative;
    border: 1px solid #eee;
    background: #fff;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.img-preview-item img {
    width: 100%; 
    height: 100%; 
    object-fit: cover;
}

/* Button to delete/remove image */
.btn-remove-img {
    position: absolute;
    top: 5px;
    right: 5px;
    background: rgba(227, 6, 19, 0.9);
    color: white;
    border: none;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    font-size: 14px;
    font-weight: bold;
    line-height: 1;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10;
    transition: 0.2s;
}

.btn-remove-img:hover {
    background: var(--primary);
    transform: scale(1.1);
}
/* --- END UPDATED Image Uploader --- */


.modal-footer {
    padding: 20px 30px;
    border-top: 1px solid #eee;
    background: #f9f9f9;
    display: flex;
    justify-content: flex-end;
    gap: 15px;
}

.btn-secondary {
    background: white;
    border: 1px solid var(--border);
    color: var(--dark);
    padding: 10px 20px;
    border-radius: 4px;
    font-weight: 600;
    cursor: pointer;
}
.btn-secondary:hover { background: #f0f0f0; }

.btn-save {
    background: var(--primary);
    color: white;
    border: none;
    padding: 10px 30px;
    border-radius: 4px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(227, 6, 19, 0.3);
}
.btn-save:hover { background: var(--primary-hover); }
.btn-save:disabled { background: #ccc; cursor: not-allowed; box-shadow: none; }

/* =========================================
   7. UTILS & LOADING
   ========================================= */
.loader-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(255,255,255,0.8);
    z-index: 2000;
    display: none;
    justify-content: center;
    align-items: center;
    flex-direction: column;
}

.loader-overlay.active { display: flex; }

.spinner {
    width: 50px;
    height: 50px;
    border: 5px solid #f3f3f3;
    border-top: 5px solid var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 15px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.notification {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: #333;
    color: #fff;
    padding: 15px 25px;
    border-radius: var(--radius);
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
    z-index: 3000;
    transform: translateY(100px);
    opacity: 0;
    transition: 0.3s;
}

.notification.show { transform: translateY(0); opacity: 1; }
.notification.success { background: var(--success); }
.notification.error { background: var(--danger); }

/* =========================================
   8. MOBILE RESPONSIVE
   ========================================= */
@media (max-width: 768px) {
    .controls-bar { flex-direction: column; align-items: stretch; }
    .search-wrap { max-width: 100%; }
    .header-container { padding: 0 15px; }
    .main-content { margin: 20px auto; padding: 0 15px; }
    
    .form-row { flex-direction: column; gap: 0; }
    
    .modal-content {
        margin: 10px;
        max-height: calc(100vh - 40px);
        display: flex;
        flex-direction: column;
    }
    
    .modal-body {
        overflow-y: auto;
        padding: 20px;
    }
    
    .modal-tabs {
        overflow-x: auto;
        white-space: nowrap;
    }
    
    .tab-btn { padding: 12px 15px; font-size: 13px; }
}

/* =========================================
   9. CUSTOM CATEGORY CHECKBOXES
   ========================================= */
.category-list-wrap {
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 10px;
    max-height: 150px;
    overflow-y: auto;
    background: #fff;
    /* Custom scrollbar */
    scrollbar-width: thin;
    scrollbar-color: #ddd #f9f9f9;
}

.category-list-wrap::-webkit-scrollbar {
    width: 6px;
}
.category-list-wrap::-webkit-scrollbar-thumb {
    background-color: #ddd;
    border-radius: 3px;
}

.cat-checkbox-item {
    display: flex;
    align-items: center;
    margin-bottom: 5px;
    font-size: 13px;
    cursor: pointer;
    user-select: none;
}
.cat-checkbox-item:hover {
    color: var(--primary);
}

.cat-checkbox-item input {
    margin-right: 8px;
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--primary); /* Красный цвет галочки */
}

.cat-checkbox-item:last-child { margin-bottom: 0; }

#btnShowNewCat {
    background: none; 
    border: none; 
    color: var(--primary); 
    font-weight: 600; 
    font-size: 12px; 
    cursor: pointer; 
    padding: 0;
    margin-top: 5px;
    text-align: left;
}
#btnShowNewCat:hover { text-decoration: underline; }