/* Глобальные стили */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg: #f8faf7;
    --text: #2d3729;
    --accent: #4a7c59;
    --accent-light: #6b9a76;
    --accent-hover: #3d6449;
    --card-bg: #ffffff;
    --border: #dce5d8;
    --shadow: rgba(74, 124, 89, 0.1);
    --shadow-strong: rgba(74, 124, 89, 0.15);
    --font-main: 'Georgia', 'Times New Roman', serif;
    --font-ui: 'Segoe UI', 'Helvetica Neue', sans-serif;
}

body {
    font-family: var(--font-main);
    font-size: 18px;
    line-height: 1.7;
    color: var(--text);
    background: var(--bg);
    background-image: 
        radial-gradient(circle at 20% 30%, rgba(74, 124, 89, 0.05) 0%, transparent 50%),
        radial-gradient(circle at 80% 70%, rgba(74, 124, 89, 0.03) 0%, transparent 50%);
    min-height: 100vh;
}

/* Декоративный контейнер */
.wrapper {
    max-width: 1240px;
    margin: 40px auto;
    padding: 20px;
    background: white;
    border-radius: 20px;
    box-shadow: 0 10px 30px var(--shadow-strong);
    border: 1px solid var(--border);
    position: relative;
    overflow: hidden;
}

.wrapper::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border: 2px solid var(--accent);
    border-radius: 18px;
    pointer-events: none;
    z-index: -1;
}

.container {
    padding: 0;
}

h1, h2, h3 {
    font-family: var(--font-ui);
    color: var(--text);
    margin-bottom: 24px;
    font-weight: 600;
    line-height: 1.3;
}

h1 {
    font-size: 2.8rem;
    text-align: center;
    color: var(--accent);
    margin-bottom: 40px;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.1);
}

a {
    color: var(--accent);
    text-decoration: none;
    border-bottom: 1px dashed var(--accent);
    transition: all 0.2s ease;
}

a:hover {
    color: var(--accent-hover);
    border-bottom-style: solid;
    padding-bottom: 1px;
}

/* Каталог */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 32px;
    padding: 20px 0;
}

.card {
    background: var(--card-bg);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 6px 16px var(--shadow);
    transition: all 0.3s ease;
    border: 1px solid var(--border);
    height: 100%;
    display: flex;
    flex-direction: column;
}

.card:hover {
    transform: translateY(-6px);
    box-shadow: 0 12px 24px var(--shadow-strong);
    border-color: var(--accent);
}

.card img {
    width: 100%;
    height: 220px;
    object-fit: cover;
    border-bottom: 1px solid var(--border);
    transition: transform 0.4s ease;
}

.card:hover img {
    transform: scale(1.05);
}

.card-body {
    padding: 20px;
    flex-grow: 1;
}

.card-title {
    font-size: 1.4rem;
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 10px;
}

.card-title a {
    border: none;
}

/* Админка */
.btn {
    display: inline-block;
    padding: 10px 20px;
    border-radius: 10px;
    font-weight: 500;
    text-align: center;
    cursor: pointer;
    border: none;
    font-size: 16px;
    font-family: var(--font-ui);
    transition: all 0.2s ease;
    box-shadow: 0 2px 6px rgba(0,0,0,0.1);
}

.btn-add {
    background: var(--accent);
    color: white;
}

.btn-add:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

.btn-edit {
    background: #5d8a66;
    color: white;
}

.btn-edit:hover {
    background: #4a7c59;
}

.btn-delete {
    background: #c53e4a;
    color: white;
}

.btn-delete:hover {
    background: #a5323e;
}

.btn-logout {
    background: #6b778c;
    color: white;
    font-size: 16px;
    padding: 12px 24px;
    margin-bottom: 20px;
    display: block;
    width: fit-content;
    margin-left: auto;
}

.btn-logout:hover {
    background: #5a6474;
}

/* Форма */
.form {
    max-width: 800px;
    margin: 30px auto;
    background: white;
    padding: 40px;
    border-radius: 18px;
    box-shadow: 0 10px 30px var(--shadow);
    border: 1px solid var(--border);
}

.form-group {
    margin-bottom: 24px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--accent);
    font-family: var(--font-ui);
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 16px;
    font-family: var(--font-main);
    background: #f9fbf8;
    transition: border 0.2s ease;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(74, 124, 89, 0.2);
}

.form-group textarea {
    min-height: 200px;
    resize: vertical;
}

/* Галерея */
.gallery-container {
    margin: 30px 0;
    text-align: center;
}

.gallery {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    justify-content: center;
    margin-bottom: 20px;
}

.gallery img {
    width: 160px;
    height: 160px;
    object-fit: cover;
    border-radius: 12px;
    cursor: pointer;
    border: 3px solid transparent;
    transition: all 0.2s ease;
    box-shadow: 0 4px 10px rgba(0,0,0,0.08);
    touch-action: manipulation;
}

.gallery img:hover {
    border-color: var(--accent);
    transform: scale(1.03);
}

/* Пагинация */
.pagination {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin: 20px 0;
    flex-wrap: wrap;
}

.pagination button,
.pagination a {
    min-width: 44px;
    height: 44px;
    border: 1px solid var(--border);
    background: white;
    border-radius: 12px;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    font-family: var(--font-ui);
}

.pagination button:hover,
.pagination a:hover {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.pagination button.page-active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
    font-weight: 600;
}

/* Модальное окно */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(45, 55, 41, 0.94);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    backdrop-filter: blur(4px);
}

.modal-content {
    max-width: 90%;
    max-height: 90%;
    position: relative;
}

.modal-content img {
    max-width: 100%;
    max-height: 85vh;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.4);
    cursor: zoom-out;
}

/* Управление в модальном окне */
.controls {
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(255, 255, 255, 0.95);
    padding: 12px 20px;
    border-radius: 16px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    z-index: 10000;
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.4);
}

.controls button {
    width: 44px;
    height: 44px;
    border: none;
    background: #fff;
    border-radius: 50%;
    font-size: 18px;
    font-weight: bold;
    color: #333;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.controls button:hover {
    background: var(--accent);
    color: white;
    transform: scale(1.08);
}

.controls button:active {
    transform: scale(0.98);
}

.controls span.zoom {
    min-width: 70px;
    text-align: center;
    font-family: 'Courier New', monospace;
    font-size: 15px;
    font-weight: 600;
    color: #212529;
}

/* Логин */
.login-container {
    max-width: 420px;
    margin: 100px auto;
    background: white;
    padding: 50px 40px;
    border-radius: 20px;
    box-shadow: 0 15px 40px var(--shadow-strong);
    text-align: center;
    border: 1px solid var(--border);
    position: relative;
    overflow: hidden;
}

.login-container::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 8px;
    background: var(--accent);
    border-radius: 8px 8px 0 0;
}

.login-container h1 {
    margin-bottom: 20px;
    font-size: 26px;
    color: var(--accent);
    font-family: var(--font-ui);
}

.login-container input {
    width: 100%;
    padding: 14px;
    margin: 12px 0;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 16px;
    background: #f9fbf8;
    font-family: var(--font-main);
    transition: border 0.2s;
}

.login-container input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(74, 124, 89, 0.2);
}

.login-container button {
    width: 100%;
    padding: 14px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    font-family: var(--font-ui);
    transition: background 0.2s ease;
    margin-top: 10px;
}

.login-container button:hover {
    background: var(--accent-hover);
}

/* Описание товара */
.description {
    margin: 30px 0;
    line-height: 1.8;
    color: #444;
    font-size: 1.1rem;
}

.description h3, .description h4 {
    color: var(--accent);
    margin: 20px 0 10px;
}

.description p {
    margin-bottom: 12px;
}

.description blockquote {
    border-left: 4px solid var(--accent);
    margin: 20px 0;
    padding: 10px 20px;
    background: #f0f7ed;
    font-style: italic;
    color: #666;
}

/* ============= Менеджер фото и Редактор (Новые стили) ============= */

.photo-manager-item { 
    position: relative; 
    display: inline-block; 
    margin: 5px; 
    vertical-align: top; 
}

.photo-manager-item img { 
    width: 150px; 
    height: 150px; 
    object-fit: cover; 
    border-radius: 8px; 
    border: 2px solid transparent; 
    pointer-events: none; 
}

.photo-manager-item.is-main img { 
    border-color: var(--accent); 
    box-shadow: 0 0 0 2px rgba(74, 124, 89, 0.3); 
}

.photo-actions { 
    position: absolute; 
    top: 5px; 
    right: 5px; 
    display: flex; 
    gap: 4px; 
    opacity: 0; 
    transition: opacity 0.2s; 
    background: rgba(0,0,0,0.6); 
    padding: 4px; 
    border-radius: 6px; 
    z-index: 10; 
}

.photo-manager-item:hover .photo-actions { 
    opacity: 1; 
}

.btn-mini { 
    width: 28px; 
    height: 28px; 
    font-size: 14px; 
    border-radius: 4px; 
    border: none; 
    cursor: pointer; 
    color: white; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    padding: 0; 
}

.btn-main { 
    background: var(--accent); 
}

.btn-del { 
    background: #c53e4a; 
}

.main-badge { 
    position: absolute; 
    bottom: 5px; 
    left: 5px; 
    background: var(--accent); 
    color: white; 
    padding: 2px 8px; 
    border-radius: 4px; 
    font-size: 11px; 
    font-family: var(--font-ui); 
    pointer-events: none; 
}

#editor { 
    min-height: 300px; 
    background: white; 
}

.loading-overlay { 
    position: fixed; 
    top:0; 
    left:0; 
    width:100%; 
    height:100%; 
    background:rgba(255,255,255,0.8); 
    z-index:9999; 
    display:none; 
    justify-content:center; 
    align-items:center; 
    font-size:24px; 
}

/* ============= АДАПТИВНЫЙ ДИЗАЙН (все устройства <= 768px) ============= */

@media (max-width: 768px) {
    body {
        font-size: 16px;
        line-height: 1.6;
    }

    .wrapper {
        margin: 16px;
        padding: 16px;
        border-radius: 16px;
    }

    .wrapper::before {
        border-radius: 14px;
    }

    h1 {
        font-size: 2.2rem;
        margin-bottom: 24px;
        text-align: center;
    }

    .container {
        padding: 0;
    }

    .grid {
        grid-template-columns: 1fr;
        gap: 20px;
        padding: 16px 0;
    }

    .card img {
        height: 180px;
    }

    .card-body {
        padding: 16px;
    }

    .card-title {
        font-size: 1.25rem;
    }

    .btn {
        font-size: 15px;
        padding: 9px 16px;
    }

    .btn-logout {
        width: 100%;
        margin-bottom: 16px;
        text-align: center;
    }

    .btn-add {
        width: 100%;
        margin: 0 auto 20px;
    }

    .form {
        padding: 30px 20px;
        margin: 20px 10px;
    }

    .form-group label {
        font-size: 15px;
    }

    .form-group input,
    .form-group textarea {
        font-size: 15px;
        padding: 10px 14px;
    }

    #editor {
        min-height: 200px;
    }

    .gallery {
        gap: 10px;
    }

    .gallery img {
        width: 80px;
        height: 80px;
        border-radius: 8px;
    }

    .pagination {
        gap: 6px;
        flex-wrap: wrap;
    }

    .pagination button,
    .pagination a {
        min-width: 36px;
        height: 36px;
        font-size: 14px;
    }

    .description {
        font-size: 1rem;
        line-height: 1.7;
        padding: 0 10px;
    }

    .modal-content img {
        max-height: 80vh;
    }

    .controls {
        bottom: 16px;
        gap: 6px;
        padding: 8px 12px;
    }

    .controls button {
        width: 36px;
        height: 36px;
        font-size: 16px;
    }

    .controls span.zoom {
        min-width: 50px;
        font-size: 13px;
    }

    .login-container {
        margin: 40px 16px;
        padding: 30px 20px;
    }

    .login-container h1 {
        font-size: 24px;
    }

    .login-container input,
    .login-container button {
        font-size: 16px;
        padding: 12px;
    }
}

/* Очень маленькие экраны (до 480px) */
@media (max-width: 480px) {
    h1 {
        font-size: 1.9rem;
    }

    .card img {
        height: 160px;
    }

    .btn {
        font-size: 14px;
        padding: 8px 12px;
    }

    .gallery img {
        width: 70px;
        height: 70px;
    }

    .description {
        font-size: 16px;
    }

    #editor {
        min-height: 180px;
    }
}