/* Общие стили */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: white;
    min-height: 100vh;
    color: #333;
}

/* Авторизация */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}

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

.auth-card {
    background: white;
    border-radius: 16px;
    padding: 40px 30px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.1);
    text-align: center;
}

.auth-card h1 {
    font-size: 28px;
    margin-bottom: 10px;
    color: #333;
}

.auth-card p {
    color: #666;
    margin-bottom: 30px;
}

.input-group {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.input-group input {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid #e1e5e9;
    border-radius: 8px;
    font-size: 16px;
    transition: border-color 0.2s;
}

.input-group input:focus {
    outline: none;
    border-color: #667eea;
}

.input-group button {
    padding: 12px 24px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    cursor: pointer;
    transition: background 0.2s;
    white-space: nowrap;
}

.input-group button:hover {
    background: #5a6fd8;
}

.error {
    color: #e74c3c;
    font-size: 14px;
    margin-top: 10px;
}

/* Основной интерфейс */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    background: white;
    min-height: 100vh;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 2px solid #f0f0f0;
}

header h1 {
    font-size: 28px;
    color: #333;
}

.header-actions {
    display: flex;
    gap: 15px;
    align-items: center;
}

.session-info {
    font-size: 14px;
    color: #666;
    padding: 8px 12px;
    background: #f8f9fa;
    border-radius: 6px;
    border: 1px solid #e9ecef;
    display: flex;
    align-items: center;
    gap: 6px;
}

.session-info.warning {
    background: #fff3cd;
    border-color: #ffeaa7;
    color: #856404;
}

/* Кнопки */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    display: inline-block;
    font-weight: 500;
}

.btn-primary {
    background: #667eea;
    color: white;
}

.btn-primary:hover {
    background: #5a6fd8;
    transform: translateY(-1px);
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #5a6268;
}

.btn-logout {
    background: #e74c3c;
    color: white;
}

.btn-logout:hover:not(:disabled) {
    background: #c0392b;
}

.btn-logout:disabled {
    background: #bdc3c7;
    color: #7f8c8d;
    cursor: not-allowed;
    opacity: 0.7;
}

/* Кнопка сохранения */
.btn-save {
    background: linear-gradient(135deg, #27ae60, #2ecc71);
    color: white;
    animation: pulseSave 2s infinite;
    box-shadow: 0 4px 15px rgba(39, 174, 96, 0.3);
    position: relative;
    overflow: hidden;
}

.btn-save:hover {
    background: linear-gradient(135deg, #229954, #27ae60);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(39, 174, 96, 0.4);
}

.btn-save::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
    transition: left 0.5s;
}

.btn-save:hover::before {
    left: 100%;
}

@keyframes pulseSave {
    0% {
        box-shadow: 0 4px 15px rgba(39, 174, 96, 0.3);
    }
    50% {
        box-shadow: 0 4px 20px rgba(39, 174, 96, 0.5);
    }
    100% {
        box-shadow: 0 4px 15px rgba(39, 174, 96, 0.3);
    }
}

.btn-icon {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    padding: 8px;
    border-radius: 6px;
    transition: background 0.2s;
    min-width: 40px;
    min-height: 40px;
}

.btn-icon:hover {
    background: #f0f0f0;
}

/* Заголовок вкладки с кнопками */
.header-buttons {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

/* Поиск товаров */
.search-container {
    display: flex;
    align-items: center;
}

.search-input {
    padding: 10px 16px;
    border: 2px solid #e1e5e9;
    border-radius: 8px;
    font-size: 14px;
    min-width: 250px;
    transition: all 0.2s ease;
    background: white;
}

.search-input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.search-input::placeholder {
    color: #999;
    font-style: italic;
}

/* Мобильная плавающая кнопка сохранения */
.mobile-save-button {
    display: none;
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(135deg, #27ae60, #2ecc71);
    color: white;
    border: none;
    border-radius: 50px;
    padding: 16px 24px;
    cursor: pointer;
    box-shadow: 0 8px 25px rgba(39, 174, 96, 0.3);
    z-index: 1000;
    animation: pulseMobile 2s infinite;
    font-size: 16px;
    font-weight: 600;
    min-width: 200px;
    text-align: center;
    transition: all 0.3s ease;
}

.mobile-save-button:hover {
    transform: translateX(-50%) scale(1.05);
    box-shadow: 0 10px 30px rgba(39, 174, 96, 0.4);
}

.mobile-save-button .save-text {
    font-size: 16px;
    font-weight: 600;
}

@keyframes pulseMobile {
    0% {
        box-shadow: 0 8px 25px rgba(39, 174, 96, 0.3);
        transform: translateX(-50%) scale(1);
    }
    50% {
        box-shadow: 0 8px 30px rgba(39, 174, 96, 0.5);
        transform: translateX(-50%) scale(1.02);
    }
    100% {
        box-shadow: 0 8px 25px rgba(39, 174, 96, 0.3);
        transform: translateX(-50%) scale(1);
    }
}

/* Вкладки */
.tabs {
    display: flex;
    margin-bottom: 30px;
    background: #f8f9fa;
    border-radius: 12px;
    padding: 4px;
}

.tab-btn {
    flex: 1;
    padding: 12px 20px;
    background: none;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 500;
    transition: all 0.2s;
    color: #666;
}

.tab-btn.active {
    background: white;
    color: #667eea;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

.tab-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 15px;
}

.tab-header h2 {
    color: #333;
    font-size: 24px;
}

/* Таблица товаров */
.table-container {
    overflow-x: auto;
    border-radius: 12px;
    border: 1px solid #e1e5e9;
    background: white;
}

.products-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 600px;
    table-layout: fixed;
}

.products-table th,
.products-table td {
    padding: 15px;
    text-align: left;
    border-bottom: 1px solid #e1e5e9;
    vertical-align: middle;
}

.products-table th {
    background: #f8f9fa;
    font-weight: 600;
    color: #555;
    position: sticky;
    top: 0;
}

.products-table tbody tr:hover {
    background: #f8f9fa;
}

.product-name {
    font-weight: 500;
    width: 30%;
}

.quantity-cell {
    width: 25%;
    text-align: center;
}

.quantity-controls {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    justify-content: center;
}

.hidden-col {
    display: none;
}

.actions {
    width: 15%;
    text-align: center;
}

.qty-btn {
    width: 40px;
    height: 40px;
    border: 2px solid #667eea;
    background: white;
    color: #667eea;
    border-radius: 8px;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.qty-btn:hover {
    background: #667eea;
    color: white;
    transform: scale(1.1);
}

.qty-btn:active {
    transform: scale(0.95);
}

.quantity {
    min-width: 40px;
    text-align: center;
    font-weight: 600;
    font-size: 18px;
    padding: 8px;
    cursor: pointer;
    border-radius: 6px;
    transition: background 0.2s;
}

.quantity:hover {
    background: #f0f0f0;
}

/* Подсветка измененных товаров */
.quantity.changed {
    background: linear-gradient(135deg, #fff3cd, #ffeaa7);
    border: 2px solid #f39c12;
    animation: quantityPulse 2s infinite;
}

@keyframes quantityPulse {
    0% {
        background: linear-gradient(135deg, #fff3cd, #ffeaa7);
    }
    50% {
        background: linear-gradient(135deg, #ffeaa7, #f39c12);
    }
    100% {
        background: linear-gradient(135deg, #fff3cd, #ffeaa7);
    }
}

.actions {
    display: flex;
    gap: 5px;
    min-width: 100px;
}

/* Фильтр дат */
.date-filter {
    display: flex;
    gap: 15px;
    align-items: center;
    flex-wrap: wrap;
}

.date-filter label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
}

.date-filter input {
    padding: 8px 12px;
    border: 2px solid #e1e5e9;
    border-radius: 6px;
    font-size: 14px;
}

.date-filter input:focus {
    outline: none;
    border-color: #667eea;
}

/* Аналитика */
.analytics-container {
    overflow-x: auto;
    border-radius: 12px;
    border: 1px solid #e1e5e9;
    background: white;
}

.analytics-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 800px;
}

.analytics-table th,
.analytics-table td {
    padding: 12px;
    text-align: center;
    border-bottom: 1px solid #e1e5e9;
    border-right: 1px solid #e1e5e9;
    position: relative;
    min-width: 80px;
}

.analytics-table th:first-child,
.analytics-table td:first-child {
    text-align: left;
    min-width: 200px;
    position: sticky;
    left: 0;
    background: white;
    z-index: 2;
}

.analytics-table th {
    background: #f8f9fa;
    font-weight: 600;
    color: #555;
    position: sticky;
    top: 0;
    z-index: 3;
}

.analytics-table th:first-child {
    z-index: 4;
}

.analytics-cell {
    height: 70px;
    position: relative;
    padding: 4px;
    overflow: hidden;
    min-width: 80px;
    transition: all 0.3s ease;
}

.analytics-cell .cell-content {
    height: 100%;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sold-block {
    flex: 1;
    background: linear-gradient(135deg, #ffe6e6, #ffe0e0);
    border: 1px solid #ffcccc;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    color: #d63384;
    position: relative;
    transition: all 0.2s ease;
}

.sold-block::before {
    content: '📦';
    font-size: 10px;
    margin-right: 3px;
}

.sold-block:hover {
    transform: scale(1.05);
    box-shadow: 0 2px 8px rgba(214, 51, 132, 0.2);
}

.remaining-block {
    flex: 1;
    background: linear-gradient(135deg, #e6f7e6, #e0f5e0);
    border: 1px solid #ccf2cc;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    color: #198754;
    position: relative;
    transition: all 0.2s ease;
}

.remaining-block::before {
    content: '📋';
    font-size: 10px;
    margin-right: 3px;
}

.remaining-block:hover {
    transform: scale(1.05);
    box-shadow: 0 2px 8px rgba(25, 135, 84, 0.2);
}

.analytics-cell.today .sold-block {
    background: linear-gradient(135deg, #fff2e6, #ffefe6);
    border-color: #ffd9b3;
    color: #ff6b35;
    box-shadow: 0 2px 4px rgba(102, 126, 234, 0.1);
}

.analytics-cell.today .remaining-block {
    background: linear-gradient(135deg, #e6f3ff, #e0f0ff);
    border-color: #b3d9ff;
    color: #0066cc;
    box-shadow: 0 2px 4px rgba(102, 126, 234, 0.1);
}

.analytics-cell.empty {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ccc;
    font-size: 14px;
    font-weight: normal;
}

.analytics-cell.updated {
    animation: cellUpdate 0.6s ease;
}

@keyframes cellUpdate {
    0% { 
        background-color: #fff3cd; 
        transform: scale(1);
    }
    50% { 
        background-color: #ffeaa7; 
        transform: scale(1.02);
    }
    100% { 
        background-color: transparent; 
        transform: scale(1);
    }
}

.analytics-legend {
    display: flex;
    gap: 20px;
    margin-bottom: 15px;
    padding: 12px;
    background: #f8f9fa;
    border-radius: 8px;
    font-size: 14px;
    flex-wrap: wrap;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.legend-item .legend-box {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    border: 1px solid;
}

.legend-sold {
    background: linear-gradient(135deg, #ffe6e6, #ffe0e0);
    border-color: #ffcccc;
    color: #d63384;
}

.legend-remaining {
    background: linear-gradient(135deg, #e6f7e6, #e0f5e0);
    border-color: #ccf2cc;
    color: #198754;
}

.legend-today {
    background: linear-gradient(135deg, #e6f3ff, #e0f0ff);
    border-color: #b3d9ff;
    color: #0066cc;
    font-size: 12px;
}

/* Модальные окна */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.modal.show {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 1;
}

.modal.closing {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 0;
}

.modal-content {
    background: white;
    border-radius: 12px;
    padding: 30px;
    max-width: 500px;
    width: 100%;
    transform: scale(0.9);
    transition: transform 0.3s ease;
}

.modal.show .modal-content {
    transform: scale(1);
}

.modal.closing .modal-content {
    transform: scale(0.9);
}

.modal-content h3 {
    margin-bottom: 20px;
    color: #333;
    font-size: 22px;
}

.modal-content form {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.modal-content input {
    padding: 12px 16px;
    border: 2px solid #e1e5e9;
    border-radius: 8px;
    font-size: 16px;
    transition: border-color 0.2s;
}

.modal-content input:focus {
    outline: none;
    border-color: #667eea;
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 10px;
}

/* Анимации */
.analytics-cell.updated {
    animation: cellUpdate 0.6s ease;
}

@keyframes cellUpdate {
    0% { 
        background-color: #fff3cd; 
        transform: scale(1);
    }
    50% { 
        background-color: #ffeaa7; 
        transform: scale(1.02);
    }
    100% { 
        background-color: transparent; 
        transform: scale(1);
    }
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOutRight {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Скрытые столбцы */
.hidden-col {
    display: none;
}

/* Адаптивность */
@media (max-width: 768px) {
    .container {
        padding: 10px;
        padding-bottom: 100px; /* Добавляем отступ для плавающей кнопки */
    }
    
    header {
        flex-direction: column;
        gap: 15px;
        text-align: center;
    }
    
    header h1 {
        font-size: 24px;
    }
    
    .header-actions {
        flex-direction: column;
        gap: 10px;
        width: 100%;
    }
    
    .session-info {
        order: -1;
        font-size: 12px;
        padding: 6px 10px;
    }
    
    .tab-header {
        flex-direction: column;
        align-items: stretch;
        text-align: center;
    }
    
    .header-buttons {
        flex-direction: column;
        gap: 10px;
        align-items: stretch;
    }
    
    .search-container {
        order: 3; /* Поиск будет последним */
        width: 100%;
    }
    
    .search-input {
        width: 100%;
        min-width: auto;
        font-size: 16px; /* Увеличиваем размер для мобильных */
        padding: 15px 16px; /* Увеличиваем padding для соответствия высоте кнопок */
        height: 50px; /* Явно задаем высоту */
        box-sizing: border-box;
    }
    
    /* Скрываем обычную кнопку сохранения на мобильных */
    .btn-save {
        display: none !important;
    }
    
    /* Показываем мобильную кнопку сохранения */
    .mobile-save-button {
        display: block;
    }
    
    .tabs {
        margin-bottom: 20px;
    }
    
    .tab-btn {
        padding: 15px 20px;
        font-size: 16px;
    }
    
    /* Таблица товаров на мобильных - скрываем только нужные столбцы */
    .hidden-col {
        display: none !important;
    }
    
    .products-table .actions {
        display: table-cell !important;
        width: 20%;
    }
    
    .product-name {
        width: 50%;
    }
    
    .quantity-cell {
        width: 30%;
    }
    
    .qty-btn {
        width: 50px;
        height: 50px;
        font-size: 20px;
    }
    
    .quantity {
        font-size: 20px;
        min-width: 50px;
        padding: 10px 8px;
    }
    
    .btn-icon {
        min-width: 50px;
        min-height: 50px;
        font-size: 20px;
    }
    
    .date-filter {
        flex-direction: column;
        align-items: stretch;
    }
    
    .date-filter label {
        justify-content: space-between;
    }
    
    .modal-content {
        margin: 20px;
        padding: 20px;
    }
    
    .modal-actions {
        flex-direction: column;
    }
    
    .analytics-legend {
        flex-direction: column;
        gap: 10px;
        font-size: 13px;
    }
    
    .analytics-table th:first-child,
    .analytics-table td:first-child {
        min-width: 100px;
        font-size: 12px;
    }
    
    .analytics-table th,
    .analytics-table td {
        min-width: 65px;
        padding: 4px 2px;
        font-size: 11px;
    }
    
    .analytics-cell {
        height: 55px;
    }
    
    .sold-block,
    .remaining-block {
        font-size: 10px;
        border-radius: 3px;
    }
    
    .sold-block::before,
    .remaining-block::before {
        font-size: 8px;
        margin-right: 1px;
    }
    
    .legend-box {
        width: 16px !important;
        height: 16px !important;
        font-size: 8px !important;
    }
}

@media (max-width: 480px) {
    .auth-card {
        padding: 30px 20px;
    }
    
    .input-group {
        flex-direction: column;
    }
    
    .container {
        padding: 5px;
        padding-bottom: 100px;
    }
    
    .products-table th,
    .products-table td {
        padding: 10px 8px;
    }
    
    .quantity-cell {
        gap: 8px;
    }
    
    .mobile-save-button {
        min-width: 180px;
        padding: 14px 20px;
        font-size: 15px;
    }
}