body {
    font-family: 'Roboto', sans-serif;
    background-color: #1e1e1e;
    color: white;
    margin: 0;
    padding: 0;
    height: 100vh;
    overflow: auto;
    /* Улучшения для мобильных устройств */
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

.container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100%;
    background-color: #1e1e1e;
}

header {
    flex-shrink: 0;
    padding: 10px 0;
}

h1 {
    text-align: center;
    color: white;
    margin: 10px 0;
    font-size: 1.2em;
}

main {
    flex: 1;
    overflow: auto;
    position: relative;
    display: flex;
    flex-direction: column;
}

footer {
    flex-shrink: 0;
}

.gallery {
    padding: 10px;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    width: 100%;
    box-sizing: border-box;
    scroll-behavior: smooth;
    min-height: 100%;
    padding-bottom: 80px; /* Дополнительное пространство для фиксированной панели действий */
}

/* Индикатор прокрутки */
.scroll-indicator {
    text-align: center;
    padding: 10px;
    background-color: rgba(42, 42, 42, 0.8);
    color: #ccc;
    font-size: 0.9em;
    opacity: 0;
    position: fixed;
    bottom: 20px; /* По умолчанию внизу экрана, когда нет кнопок */
    left: 0;
    right: 0;
    pointer-events: none;
    z-index: 10;
    transform: translateY(100%);
    transition: opacity 0.3s ease, transform 0.3s ease, bottom 0.3s ease;
}

.scroll-indicator.visible {
    opacity: 1;
    transform: translateY(0);
}

.scroll-indicator.with-actions {
    bottom: 70px; /* Выше, чем панель с кнопками действий */
}

/* Заглушка загрузки */
.loading-placeholder {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: #ccc;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #007bff;
    animation: spin 1s ease-in-out infinite;
    margin-bottom: 15px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Улучшенная анимация для спиннера с плавным появлением и исчезновением */
.spinner {
    animation: spin 1s ease-in-out infinite, fadeIn 0.3s ease;
}

.image-loading-indicator {
    animation: fadeIn 0.3s ease;
}

.image-loading-indicator::before {
    animation: spin 1s ease-in-out infinite;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

/* Анимация появления изображений */
.receipt {
    opacity: 0;
    transform: translateY(20px);
    animation: fadeInUp 0.6s ease forwards;
}

.receipt.loaded {
    animation: imageLoaded 0.4s ease forwards;
}

@keyframes fadeInUp {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes imageLoaded {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Задержка анимации для каждого изображения */
.receipt:nth-child(1) { animation-delay: 0.05s; }
.receipt:nth-child(2) { animation-delay: 0.1s; }
.receipt:nth-child(3) { animation-delay: 0.15s; }
.receipt:nth-child(4) { animation-delay: 0.2s; }
.receipt:nth-child(5) { animation-delay: 0.25s; }
.receipt:nth-child(6) { animation-delay: 0.3s; }
.receipt:nth-child(7) { animation-delay: 0.35s; }
.receipt:nth-child(8) { animation-delay: 0.4s; }
.receipt:nth-child(9) { animation-delay: 0.45s; }

/* Скелетон для загружающегося изображения */
.image-skeleton {
    background: linear-gradient(90deg, #2a2a2a 25%, #333 50%, #2a2a2a 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
    border-radius: 8px;
    width: 100%;
    height: 120px;
    margin-bottom: 8px;
    position: relative;
    overflow: hidden;
}

@keyframes loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Улучшенная анимация пульсации для скелетона */
.image-skeleton::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.1), transparent);
    animation: shimmer 2s infinite;
}

@keyframes shimmer {
    0% { left: -100%; }
    100% { left: 100%; }
}

/* Индикатор загрузки для отдельного изображения */
.image-loading {
    position: relative;
    overflow: hidden;
}

.image-loading .image-skeleton {
    position: relative;
}

.image-loading .image-skeleton::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    z-index: 2;
}

/* Индикатор загрузки для изображений */
.image-loading-indicator {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    z-index: 10;
    backdrop-filter: blur(2px);
}

.image-loading-indicator::before {
    content: '';
    width: 28px;
    height: 28px;
    border: 3px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    border-top-color: #007bff;
    animation: spin 1s ease-in-out infinite;
    box-shadow: 0 0 10px rgba(0, 123, 255, 0.5);
}

.receipt {
    background-color: #2a2a2a;
    border-radius: 8px;
    padding: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    transition: border-color 0.3s;
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
    max-width: 200px;
    height: auto;
}

.receipt.selected {
    border: 2px solid #007bff;
}

.receipt img {
    width: 100%;
    height: 120px;
    object-fit: cover;
    border-radius: 8px;
    display: block;
    margin-bottom: 8px;
    max-width: 100%;
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease;
    transform: scale(0.95);
}

.receipt img.loaded {
    opacity: 1;
    transform: scale(1);
}

.receipt .date {
    font-size: 0.9em;
    color: #ccc;
    margin: 0;
}

.receipt .price {
    font-size: 1em;
    font-weight: bold;
    color: white;
    margin: 5px 0 0 0;
}

.actions {
    display: flex;
    justify-content: space-around;
    padding: 10px;
    background-color: #2a2a2a;
    border-top: 1px solid #444;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.3);
    transform: translateY(100%);
    transition: transform 0.3s ease;
}

.actions.visible {
    transform: translateY(0);
}

.actions button {
    padding: 12px 16px;
    border: none;
    border-radius: 5px;
    font-size: 0.9em;
    cursor: pointer;
    transition: background-color 0.3s, transform 0.1s ease;
    flex: 1;
    margin: 0 5px;
    font-weight: 500;
    min-height: 44px; /* Минимальная высота для удобного нажатия на мобильных */
    display: flex;
    align-items: center;
    justify-content: center;
}

.actions button:active {
    transform: scale(0.95);
}

#edit-btn {
    background-color: #28a745;
    color: white;
}

#edit-btn:hover {
    background-color: #218838;
}

#delete-btn {
    background-color: #dc3545;
    color: white;
}

#delete-btn:hover {
    background-color: #c82333;
}

.cancel-btn {
    background-color: #6c757d;
    color: white;
    font-size: 1.2em;
    font-weight: bold;
    padding: 10px 15px;
}

.cancel-btn:hover {
    background-color: #5a6268;
}

.error-message {
    color: #ff6b6b;
    text-align: center;
    padding: 10px;
    background-color: rgba(255, 107, 107, 0.1);
    border-radius: 4px;
    margin: 5px 10px;
    font-size: 0.9em;
}

/* Мобильная адаптация */
@media (max-width: 768px) {
    .container {
        max-width: 100%;
    }
    .gallery {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 8px;
        padding: 8px;
        padding-bottom: 80px; /* Сохраняем отступ для мобильных */
    }
    .receipt {
        padding: 6px;
        max-width: 150px;
    }
    .receipt img {
        height: 100px;
    }
    .receipt .date {
        font-size: 0.8em;
    }
    .receipt .price {
        font-size: 0.9em;
    }
    .actions {
        padding: 8px;
    }
    
    .actions button {
        padding: 10px 8px;
        font-size: 0.85em;
        margin: 0 2px;
        min-height: 48px; /* Увеличиваем для мобильных */
    }
    
    .scroll-indicator.with-actions {
        bottom: 80px; /* Выше, чем панель с кнопками действий на мобильных */
    }
    
    /* Улучшения для мобильных устройств */
    .receipt {
        transform: translateZ(0); /* Аппаратное ускорение */
        backface-visibility: hidden;
    }
    
    .receipt img {
        transform: translateZ(0);
        backface-visibility: hidden;
    }
    
    /* Улучшенная обработка касаний */
    .receipt:active {
        transform: scale(0.95);
        transition: transform 0.1s ease;
    }
}

/* Для очень маленьких экранов */
@media (max-width: 480px) {
    .gallery {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 5px;
        padding: 5px;
        padding-bottom: 80px; /* Сохраняем отступ для маленьких экранов */
    }
    .receipt {
        padding: 4px;
        max-width: 120px;
    }
    .receipt img {
        height: 80px;
    }
    .receipt .date {
        font-size: 0.7em;
    }
    .receipt .price {
        font-size: 0.8em;
    }
    
    /* Дополнительные улучшения для маленьких экранов */
    .receipt {
        transform: translateZ(0);
        backface-visibility: hidden;
    }
    
    .receipt img {
        transform: translateZ(0);
        backface-visibility: hidden;
    }
    
    /* Уменьшаем отступы для экономии места */
    header {
        padding: 5px 0;
    }
    
    h1 {
        font-size: 1em;
        margin: 5px 0;
    }
    
    .actions {
        padding: 6px;
    }
    
    .actions button {
        padding: 8px 6px;
        font-size: 0.8em;
        margin: 0 1px;
        min-height: 50px; /* Еще больше для очень маленьких экранов */
    }
    
    .scroll-indicator.with-actions {
        bottom: 85px; /* Выше, чем панель с кнопками действий на очень маленьких экранах */
    }
}

/* Для больших экранов - увеличиваем количество колонок */
@media (min-width: 1200px) {
    .gallery {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 15px;
    }
    .receipt {
        max-width: 180px;
    }
    .receipt img {
        height: 110px;
    }
}

@media (min-width: 1600px) {
    .gallery {
        grid-template-columns: repeat(5, minmax(0, 1fr));
    }
    .receipt {
        max-width: 160px;
    }
    .receipt img {
        height: 100px;
    }
}