﻿/* --- БАЗОВІ НАЛАШТУВАННЯ ТА КОЛЬОРИ --- */
:root {
    --primary-color: #4f46e5;
    --primary-hover: #4338ca;
    --danger-color: #ef4444;
    --success-color: #10b981;
    --warning-bg: #fffbeb;
    --warning-text: #b45309;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --bg-body: #f8fafc;
    --border-color: #e2e8f0;
}

html {
    font-size: 16px;
    min-height: 100%;
    position: relative;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Inter', -apple-system, system-ui, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    line-height: 1.5;
}

/* --- Layout (Шапка та Підвал) --- */
.main-header {
    background-color: #ffffff;
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 0;
    margin-bottom: 2rem;
}

.header-container {
    max-width: 1100px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
}

.logo {
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--primary-color);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 8px;
}

.top-nav {
    display: flex;
    align-items: center;
    gap: 20px;
}

    .top-nav a {
        text-decoration: none;
        color: var(--text-muted);
        font-weight: 500;
        transition: color 0.2s;
    }

        .top-nav a:hover {
            color: var(--primary-color);
        }

.content-area {
    min-height: calc(100vh - 250px);
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 20px;
}

.main-footer {
    text-align: center;
    padding: 2rem 0;
    color: var(--text-muted);
    font-size: 0.875rem;
    border-top: 1px solid var(--border-color);
    margin-top: 3rem;
    background: #fff;
}

/* --- Авторизація --- */
.auth-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 70vh;
}

    .auth-wrapper .form-wrapper {
        max-width: 600px;
        width: 100%;
        margin: 40px auto;
    }

.auth-nav {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-left: 20px;
    border-left: 1px solid var(--border-color);
    padding-left: 20px;
}

.user-greeting {
    font-weight: 600;
    color: #475569;
    margin-right: 10px;
    font-size: 0.9rem;
}

.btn-logout-link {
    background-color: #fee2e2;
    color: #dc2626;
    border: 1px solid #fecaca;
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 5px;
}

    .btn-logout-link:hover {
        background-color: #dc2626;
        color: white;
        border-color: #dc2626;
        box-shadow: 0 2px 4px rgba(220, 38, 38, 0.2);
    }

.btn-login-accent {
    background-color: var(--primary-color);
    color: white !important;
    padding: 6px 15px;
    border-radius: 6px;
    transition: background 0.2s;
    text-decoration: none;
}

    .btn-login-accent:hover {
        background-color: var(--primary-hover);
        text-decoration: none;
    }

.auth-links a {
    color: var(--primary-color);
    text-decoration: none;
    font-size: 0.9rem;
}

    .auth-links a:hover {
        text-decoration: underline;
    }

/* --- Таблиця складу (Inventory) --- */
.inventory-wrapper {
    background: #fff;
    padding: 2rem;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.inventory-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.inventory-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: auto;
}

    .inventory-table th {
        text-align: left;
        padding: 12px;
        background: #f1f5f9;
        color: var(--text-muted);
        font-size: 0.75rem;
        text-transform: uppercase;
        border-bottom: 2px solid var(--border-color);
    }

        .inventory-table th a {
            text-decoration: none;
            color: inherit;
            display: inline-block;
            width: 100%;
        }

            .inventory-table th a:hover {
                color: var(--primary-color);
            }

    .inventory-table td {
        padding: 1rem;
        border-bottom: 1px solid var(--border-color);
    }

        .inventory-table td:not(.title-column),
        .inventory-table th:not(:first-child) {
            white-space: nowrap;
            width: 1%;
            padding-left: 15px;
            padding-right: 15px;
        }

.title-column {
    white-space: normal;
    word-break: break-word;
    min-width: 200px;
}

.row-warning {
    background-color: var(--warning-bg);
}

.restock-label {
    font-size: 0.7rem;
    color: var(--warning-text);
    background: #fef3c7;
    padding: 2px 6px;
    border-radius: 4px;
    display: inline-block;
}

/* --- Форми (Загальні) --- */
.form-wrapper {
    max-width: 500px;
    margin: 2rem auto;
    background: white;
    padding: 2rem;
    border-radius: 12px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
}

.form-header {
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 1rem;
}

.form-group {
    margin-bottom: 1.25rem;
}

    .form-group label {
        display: block;
        margin-bottom: 0.5rem;
        font-weight: 600;
    }

.input-field {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    box-sizing: border-box;
}

    .input-field:focus {
        outline: none;
        border-color: var(--primary-color);
        box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
    }

.form-group-checkbox {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 1rem;
    background: #f8fafc;
    border-radius: 8px;
    margin-bottom: 1.5rem;
}

/* Кнопки */
.btn-save, .btn-create {
    background-color: var(--primary-color);
    color: white;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
}

    .btn-save:hover, .btn-create:hover {
        background-color: var(--primary-hover);
    }

.btn-cancel {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.875rem;
    margin-left: 1rem;
}

.btn-delete-confirm {
    background-color: var(--danger-color);
    color: white;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}

/* Валідація */
.error-text {
    color: var(--danger-color);
    font-size: 0.75rem;
}

.error-msg {
    color: var(--danger-color);
    background: #fef2f2;
    padding: 0.5rem;
    border-radius: 4px;
}

    .error-msg ul {
        list-style: none;
        padding: 0;
        margin: 0;
    }

/* Бейджі та Статуси */
.badge {
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-pop {
    background: #e0e7ff;
    color: #4338ca;
}

.badge-reg {
    background: #f1f5f9;
    color: #475569;
}

.status-indicator {
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 5px;
}

.in-stock {
    color: var(--success-color);
    font-weight: 600;
}

.out-of-stock {
    color: var(--text-muted);
    font-weight: 500;
}

/* Деталі товару */
.details-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    border-bottom: 1px solid #eee;
    padding-bottom: 15px;
}

.detail-item {
    display: flex;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px dotted #e2e8f0;
}

.detail-label {
    color: var(--text-muted);
    font-weight: 500;
}

.detail-value {
    font-weight: 600;
    color: var(--text-main);
}

    .detail-value.price {
        color: var(--primary-color);
        font-size: 1.1rem;
    }

/* Службові класи */
.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

.text-nowrap {
    white-space: nowrap;
}

/* Дії (Редагування, Видалення) */
.action-links {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

    .action-links a {
        text-decoration: none !important;
        transition: transform 0.2s ease;
        display: inline-block;
    }

        .action-links a:hover {
            transform: scale(1.2);
        }

/* --- Пагінація --- */
.pagination-container {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
    margin-top: 25px;
    padding-bottom: 30px;
}

.pagination-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 32px;
    min-width: 32px;
    padding: 0 12px;
    background-color: #ffffff;
    border: 1px solid #b8c2cc;
    color: #2d3748;
    text-decoration: none !important;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.85rem;
    transition: all 0.2s ease;
}

    .pagination-btn:hover {
        background-color: #edf2f7;
        border-color: var(--primary-color);
        color: var(--primary-color);
    }

    .pagination-btn.active {
        background-color: var(--primary-color) !important;
        border-color: var(--primary-hover) !important;
        color: #ffffff !important;
        cursor: default;
        box-shadow: 0 2px 4px rgba(79, 70, 229, 0.3);
    }

    .pagination-btn:first-child,
    .pagination-btn:last-child {
        background-color: #f8fafc;
        color: #475569;
    }

/* Стиль для відсутніх товарів */
.row-out-of-stock {
    background-color: #f1f5f9;
    opacity: 0.8;
}

    .row-out-of-stock:hover {
        opacity: 1;
        background-color: #e2e8f0;
    }

/* Кнопка історії (Градиент) */
.btn-history {
    text-decoration: none;
    background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
    color: white !important;
    padding: 8px 18px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.9rem;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: none;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(79, 70, 229, 0.2);
}

    .btn-history:hover {
        transform: translateY(-1px);
        box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
        background: linear-gradient(135deg, #4f46e5 0%, #4338ca 100%);
    }

/* Кнопка експорту (Нейтральна) */
.btn-export {
    text-decoration: none;
    background-color: #f1f5f9;
    color: #475569 !important;
    padding: 8px 16px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.85rem;
    border: 1px solid #e2e8f0;
    transition: all 0.2s;
}

    .btn-export:hover {
        background-color: #e2e8f0;
        color: #1e293b !important;
    }

/* Байджи для типов изменений */
.log-badge {
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.bg-plus {
    background: #dcfce7;
    color: #166534;
}

.bg-minus {
    background: #fee2e2;
    color: #991b1b;
}

/* Пагинация (Додатковий блок) */
.pagination-wrapper {
    margin-top: 30px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.pagination-nav {
    display: flex;
    align-items: center;
    gap: 6px;
    background: #ffffff;
    padding: 6px;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    border: 1px solid #e2e8f0;
}

.page-btn {
    min-width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    color: #475569;
    font-weight: 500;
    border-radius: 8px;
    transition: all 0.2s;
    border: 1px solid transparent;
}

    .page-btn:hover:not(.active) {
        background: #f1f5f9;
        color: #1e293b;
    }

    .page-btn.active {
        background: #2563eb;
        color: white;
        box-shadow: 0 4px 6px -1px rgba(37, 99, 235, 0.2);
    }

.nav-btn {
    padding: 0 15px;
    font-size: 0.9em;
}

.page-dots {
    color: #cbd5e1;
    padding: 0 5px;
}

.pagination-info {
    font-size: 0.85rem;
    color: #64748b;
}

/* --- КАРДИНАЛЬНЕ ВИПРАВЛЕННЯ КЛІКІВ --- */
.qty-picker {
    display: flex !important;
    align-items: center;
    justify-content: center;
    gap: 10px;
    position: relative;
    transform: translateZ(0);
    z-index: 999;
}

.btn-qty-round {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #ffffff;
    display: flex !important;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    font-weight: bold;
    cursor: pointer !important;
    transition: all 0.2s ease;
    border: 2px solid;
    text-decoration: none;
    pointer-events: auto !important;
    position: relative;
}

.btn-qty-minus-red {
    border-color: #fee2e2;
    color: #ef4444;
}

    .btn-qty-minus-red:hover {
        background: #ef4444;
        color: #fff;
        border-color: #ef4444;
    }

.btn-qty-plus-green {
    border-color: #dcfce7;
    color: #10b981;
}

    .btn-qty-plus-green:hover {
        background: #10b981;
        color: #fff;
        border-color: #10b981;
    }

form[id*="form-minus"],
form[id*="form-plus"],
form[id*="dec"],
form[id*="inc"] {
    position: absolute !important;
    width: 0 !important;
    height: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: hidden !important;
    clip: rect(0 0 0 0) !important;
    pointer-events: none !important;
    display: block !important;
}

.inventory-table thead {
    position: relative;
    z-index: 1;
    pointer-events: none !important;
}

    .inventory-table thead th * {
        pointer-events: auto;
    }

.inventory-table tbody tr:first-child td {
    padding-top: 30px !important;
}

/* --- ULTIMATE MOBILE ADAPTATION: FULL WIDTH & CLEAN HEADER --- */
@media screen and (max-width: 768px) {

    /* 1. ШАПКА ТА НАВІГАЦІЯ (Виправлено) */
    .header-container {
        flex-direction: column !important;
        padding: 10px 5px !important;
        gap: 12px !important;
        align-items: center !important;
        text-align: center !important;
    }

    .auth-nav {
        border: none !important;
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
        display: flex !important;
        flex-direction: column !important; /* Елементи входу/виходу один під одним */
        gap: 8px !important;
        align-items: center !important;
    }

        /* Стиль для посилань у шапці (Вхід/Вихід/Профіль) */
        .auth-nav a, .btn-login-accent {
            width: 100% !important;
            max-width: 280px; /* Щоб кнопки не були надто довгими у шапці */
            padding: 10px !important;
            text-align: center !important;
            border-radius: 8px !important;
            font-size: 0.9rem !important;
        }

    /* 2. МАКСИМАЛЬНЕ РОЗШИРЕННЯ КОНТЕНТУ */
    html, body {
        overflow-x: hidden !important;
    }

    .content-area, .container, .inventory-wrapper {
        padding: 0 5px !important;
        margin: 0 !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    /* 3. БЛОКИ КЕРУВАННЯ (Імпорт/Експорт/Пошук) */
    .inventory-header,
    .import-section,
    form[method="get"],
    form[enctype="multipart/form-data"],
    .log-filters {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        width: 100% !important;
        padding: 12px !important;
        margin-bottom: 15px !important;
        background: #f8fafc !important;
        border-radius: 12px !important;
        box-sizing: border-box !important;
    }

    /* Кнопки та поля вводу на всю ширину */
    .btn-create, .btn-history, .btn-export, .btn-save,
    button, .input-field, select, input[type="file"] {
        width: 100% !important;
        max-width: 100% !important;
        margin: 5px 0 !important;
        box-sizing: border-box !important;
        min-height: 48px !important;
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
        text-align: center !important;
    }

    /* 4. АДАПТАЦІЯ ТАБЛИЦЬ (Товари та Логи) */
    .inventory-table thead, .logs-table thead, .history-table thead {
        display: none !important;
    }

    .inventory-table, .logs-table, .history-table,
    .inventory-table tbody, .logs-table tbody, .history-table tbody,
    .inventory-table tr, .logs-table tr, .history-table tr,
    .inventory-table td, .logs-table td, .history-table td {
        display: block !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

        .inventory-table tr, .logs-table tr, .history-table tr {
            background: #ffffff !important;
            border: 1px solid #e2e8f0 !important;
            border-radius: 12px !important;
            margin-bottom: 15px !important;
            padding: 15px !important;
            box-shadow: 0 2px 8px rgba(0,0,0,0.05) !important;
            text-align: center !important;
        }

        .inventory-table td, .logs-table td, .history-table td {
            padding: 8px 0 !important;
            border: none !important;
            display: flex !important;
            justify-content: center !important;
            align-items: center !important;
        }

            .title-column, .logs-table td:first-child {
                font-weight: 800 !important;
                font-size: 1.2rem !important;
                color: var(--primary-color);
                border-bottom: 1px solid #f1f5f9 !important;
                margin-bottom: 10px !important;
                padding-bottom: 10px !important;
            }

            /* 5. МІТКИ ДЛЯ ЛОГІВ */
            .logs-table td::before, .history-table td::before {
                content: attr(data-label) ": ";
                font-weight: 700;
                margin-right: 8px;
                color: #64748b;
                font-size: 0.85rem;
            }

            .inventory-table td::before {
                display: none !important;
            }

    /* 6. QTY PICKER */
    .qty-picker {
        display: inline-flex !important;
        background: #f1f5f9 !important;
        padding: 8px 18px !important;
        border-radius: 30px !important;
        margin: 10px auto !important;
        gap: 25px !important;
    }

    .btn-qty-round {
        width: 44px !important;
        height: 44px !important;
        background: white !important;
        box-shadow: 0 2px 4px rgba(0,0,0,0.1) !important;
    }

    /* 7. ДІЇ (Іконки) */
    .action-links {
        display: flex !important;
        justify-content: center !important;
        gap: 40px !important;
        margin-top: 10px !important;
        padding-top: 15px !important;
        border-top: 1px solid #f1f5f9 !important;
    }

        .action-links a {
            font-size: 1.4rem !important;
        }
}