/* === Базовые стили === */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Теплая палитра */
    --bg: #FFF5EB;
    --bg-card: #FFFFFF;
    --primary: #E07A5F;
    --primary-hover: #C86A52;
    --secondary: #81B29A;
    --secondary-hover: #6A9A82;
    --text: #3D405B;
    --text-light: #6B6E8A;
    --border: #F2E9E4;
    --shadow: rgba(61, 64, 91, 0.08);

    /* Размеры */
    --radius: 16px;
    --radius-sm: 10px;
}

html {
    font-size: 18px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

.container {
    max-width: 500px;
    margin: 0 auto;
    padding: 16px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* === Шапка === */
header {
    text-align: center;
    padding: 20px 0 10px;
}

header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text);
}

/* === Карточки === */
.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: 0 4px 20px var(--shadow);
    margin-bottom: 20px;
}

.hidden {
    display: none !important;
}

/* === Загрузка файла === */
.upload-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 50px 30px;
    border: 3px dashed var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.2s ease;
    background: linear-gradient(135deg, #FFF9F5 0%, #FFF5EB 100%);
}

.upload-area:hover,
.upload-area:focus,
.upload-area.dragover {
    border-color: var(--primary);
    background: linear-gradient(135deg, #FFF5EB 0%, #FFE8D6 100%);
    transform: scale(1.01);
}

.upload-icon {
    font-size: 4rem;
    margin-bottom: 16px;
}

.upload-text {
    font-size: 1.1rem;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 8px;
}

.upload-hint {
    font-size: 0.9rem;
    color: var(--text-light);
}

/* === Превью === */
.preview-container {
    background: #F8F8F8;
    border-radius: var(--radius-sm);
    padding: 12px;
    margin-bottom: 16px;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 200px;
    max-height: 300px;
    overflow: hidden;
}

#preview {
    max-width: 100%;
    max-height: 280px;
    object-fit: contain;
    border-radius: 8px;
}

/* === Инфо-бар === */
.info-bar {
    display: flex;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--bg);
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
    font-size: 0.9rem;
}

#original-size {
    color: var(--text-light);
}

#new-size {
    color: var(--primary);
    font-weight: 600;
}

/* === Контролы === */
.controls {
    margin-bottom: 24px;
}

.size-inputs {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    margin-bottom: 12px;
}

.input-group {
    flex: 1;
}

.input-group label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-light);
    margin-bottom: 6px;
}

.input-with-unit {
    display: flex;
    align-items: center;
    background: var(--bg);
    border-radius: var(--radius-sm);
    border: 2px solid var(--border);
    overflow: hidden;
    transition: border-color 0.2s;
}

.input-with-unit:focus-within {
    border-color: var(--primary);
}

.input-with-unit input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 14px 12px;
    font-size: 1.1rem;
    color: var(--text);
    width: 100%;
    min-width: 0;
}

.input-with-unit input:focus {
    outline: none;
}

.input-with-unit .unit {
    padding-right: 12px;
    color: var(--text-light);
    font-size: 0.9rem;
}

/* Кнопка связи пропорций */
.link-button {
    width: 48px;
    height: 48px;
    border: 2px solid var(--border);
    border-radius: 50%;
    background: var(--bg);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
    margin-bottom: 1px;
}

.link-button .link-icon {
    font-size: 1.3rem;
    transition: transform 0.2s;
}

.link-button.active {
    background: var(--secondary);
    border-color: var(--secondary);
}

.link-button:not(.active) .link-icon {
    opacity: 0.4;
}

.link-button:active {
    transform: scale(0.95);
}

/* Подсказка про пропорции */
.proportions-hint {
    text-align: center;
    font-size: 0.85rem;
    color: var(--secondary);
    padding: 8px;
    background: rgba(129, 178, 154, 0.1);
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    transition: all 0.2s;
}

.proportions-hint.inactive {
    color: var(--text-light);
    background: var(--bg);
}

/* Быстрые размеры */
.quick-sizes {
    margin-top: 16px;
}

.quick-label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-light);
    margin-bottom: 10px;
}

.quick-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.quick-btn {
    padding: 10px 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.quick-btn:hover,
.quick-btn:active {
    border-color: var(--primary);
    background: #FFF5F0;
}

.quick-btn.active {
    border-color: var(--primary);
    background: var(--primary);
    color: white;
}

/* === Кнопки действий === */
.actions {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
}

.btn {
    flex: 1;
    padding: 14px 12px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all 0.2s;
    min-width: 0;
}

.btn span {
    font-size: 1.1rem;
}

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

.btn-primary:hover,
.btn-primary:active {
    background: var(--primary-hover);
    transform: scale(0.98);
}

.btn-secondary {
    background: var(--bg);
    color: var(--text);
    border: 2px solid var(--border);
}

.btn-secondary:hover,
.btn-secondary:active {
    background: var(--border);
}

.btn-text {
    background: none;
    border: none;
    color: var(--text-light);
    padding: 12px;
    font-size: 0.95rem;
    cursor: pointer;
    width: 100%;
}

.btn-text:hover {
    color: var(--primary);
}

/* === Футер === */
footer {
    margin-top: auto;
    text-align: center;
    padding: 20px;
    color: var(--text-light);
    font-size: 0.85rem;
}

/* === Модальное окно === */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(61, 64, 91, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 100;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 24px;
    width: 100%;
    max-width: 340px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    animation: modalIn 0.2s ease;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(10px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-content h2 {
    font-size: 1.2rem;
    text-align: center;
    margin-bottom: 20px;
    color: var(--text);
}

.filename-input {
    margin-bottom: 20px;
}

.filename-input label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-light);
    margin-bottom: 8px;
}

.input-with-ext {
    display: flex;
    align-items: center;
    background: var(--bg);
    border-radius: var(--radius-sm);
    border: 2px solid var(--border);
    overflow: hidden;
    transition: border-color 0.2s;
}

.input-with-ext:focus-within {
    border-color: var(--primary);
}

.input-with-ext input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 14px 12px;
    font-size: 1rem;
    color: var(--text);
    min-width: 0;
}

.input-with-ext input:focus {
    outline: none;
}

.input-with-ext .ext {
    padding-right: 14px;
    color: var(--text-light);
    font-size: 0.9rem;
    font-weight: 500;
}

.modal-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 12px;
}

.btn-full {
    width: 100%;
}

/* === Плашка обновления === */
.update-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: var(--secondary);
    color: white;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    z-index: 100;
    font-size: 0.95rem;
    animation: slideDown 0.3s ease;
}

.update-banner.hidden {
    display: none;
}

@keyframes slideDown {
    from {
        transform: translateY(-100%);
    }
    to {
        transform: translateY(0);
    }
}

.update-banner button {
    background: white;
    color: var(--secondary);
    border: none;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
}

/* === Плашка установки PWA === */
.install-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-card);
    padding: 14px 16px;
    box-shadow: 0 -4px 20px var(--shadow);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    z-index: 50;
    animation: slideUp 0.3s ease;
}

.install-banner.hidden {
    display: none;
}

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

.install-content {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
}

.install-icon {
    font-size: 1.5rem;
    flex-shrink: 0;
}

.install-text {
    font-size: 0.9rem;
    color: var(--text);
    line-height: 1.3;
}

.install-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.install-action-btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}

.install-action-btn:active {
    background: var(--primary-hover);
}

.install-dismiss {
    background: none;
    border: none;
    color: var(--text-light);
    font-size: 1.2rem;
    padding: 8px;
    cursor: pointer;
    line-height: 1;
}

/* Отступ снизу когда плашка видна */
body.has-install-banner .container {
    padding-bottom: 80px;
}

/* === Анимации === */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.card:not(.hidden) {
    animation: fadeIn 0.3s ease;
}

/* === Адаптив для больших экранов === */
@media (min-width: 600px) {
    .container {
        padding: 40px 20px;
    }

    header {
        padding: 30px 0 20px;
    }

    header h1 {
        font-size: 1.8rem;
    }

    .card {
        padding: 32px;
    }

    .upload-area {
        padding: 70px 40px;
    }

    .preview-container {
        min-height: 250px;
        max-height: 400px;
    }

    #preview {
        max-height: 380px;
    }
}

/* === Убираем стрелки у input[number] === */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type="number"] {
    -moz-appearance: textfield;
}

/* === iOS-специфичное === */
@supports (-webkit-touch-callout: none) {
    /* Убираем зум при фокусе на input (iOS) */
    input[type="number"] {
        font-size: 16px;
    }
}
