/* styles.css */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #6366f1;
    --primary-dark: #4f46e5;
    --secondary-color: #10b981;
    --secondary-dark: #059669;
    --error-color: #ef4444;
    --background-color: #e07c3c;
    --card-bg: #ffffff;
    --text-primary: #1f2937;
    --text-secondary: #6b7280;
    --border-color: #d1d5db;
    --border-focus: #6366f1;
    --border-valid: #10b981;
    --border-invalid: #ef4444;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    --radius: 8px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--background-color);
    color: var(--text-primary);
    line-height: 1.4;
    height: 100vh;
    overflow: hidden;
}

/* Исправление скролла: убираем дублирующий overflow на контейнере */
#app, .container {
    height: 100vh;
}

.container {
    max-width: 100%;
    height: 100vh;
    padding: 12px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

/* #main занимает всю высоту, чтобы flex: 1 у scroll-контейнера работал */
#main {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.hidden {
    display: none !important;
}

/* Loading */
.loading {
    text-align: center;
    padding: 20px;
    color: white;
    text-shadow: 0 1px 6px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100%;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top: 3px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 16px;
}

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

/* Error */
.error {
    text-align: center;
    padding: 20px;
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100%;
    position: relative;
}

.error h2 {
    color: var(--error-color);
    margin-bottom: 12px;
}

/* Main Content */
.header {
    text-align: center;
    margin-bottom: 16px;
    color: white;
    flex-shrink: 0;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
}

.header h1 {
    font-size: 1.4rem;
    text-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
    line-height: 1.3;
    font-weight: 600;
    margin: 0;
    flex: 1;
    text-align: center;
}

/* КОНТЕЙНЕР ДЛЯ ПРОКРУТКИ ФОРМЫ */
.form-scroll-container {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 80px; /* Место для фиксированной кнопки */
    border-radius: var(--radius);
    /* Визуальный намёк на скролл */
    background:
        linear-gradient(to top, rgba(255,255,255,0.95) 0px, transparent 30px),
        linear-gradient(to bottom, rgba(255,255,255,0.95) 0px, transparent 30px);
    background-attachment: local, local;
    background-color: transparent;
    scrollbar-width: thin;
}

/* Form Styles */
.promo-form {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: min-content;
}

/* ФИКСИРОВАННАЯ КНОПКА */
.form-actions-fixed {
    position: fixed;
    bottom: 12px;
    left: 12px;
    right: 12px;
    z-index: 1000;
    background: var(--card-bg);
    padding: 8px;
    border-radius: var(--radius);
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
}

.form-section {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex-shrink: 0;
}

.form-section label {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.9rem;
}

.form-section input,
.form-section select,
.form-section textarea {
    padding: 10px 12px;
    border: 2px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.95rem;
    font-family: inherit;
    transition: all 0.2s ease;
    width: 100%;
    background: white;
    color: var(--text-primary);
    min-height: 44px;
}

/* СТИЛИ ВАЛИДАЦИИ */
.form-section input:valid:not(:placeholder-shown),
.form-section select:valid,
.form-section textarea:valid:not(:placeholder-shown) {
    border-color: var(--border-valid);
    background-color: rgba(16, 185, 129, 0.05);
}

.form-section input:invalid:not(:focus):not(:placeholder-shown),
.form-section select:invalid:not(:focus),
.form-section textarea:invalid:not(:focus):not(:placeholder-shown) {
    border-color: var(--border-invalid);
    background-color: rgba(239, 68, 68, 0.05);
}

.form-section input:focus,
.form-section select:focus,
.form-section textarea:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.form-section textarea {
    resize: vertical;
    min-height: 70px;
    line-height: 1.4;
}

.form-section small {
    color: var(--text-secondary);
    font-size: 0.75rem;
    margin-top: -2px;
}

.char-counter {
    text-align: right;
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* НОВЫЕ СТИЛИ ДЛЯ ПЕРЕКЛЮЧАТЕЛЯ АВТОМОДЕРАЦИИ */
.toggle-section {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border-color);
}

.toggle-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    font-weight: 600;
    color: var(--text-primary);
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 26px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 34px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked + .toggle-slider {
    background-color: var(--secondary-color);
}

input:checked + .toggle-slider:before {
    transform: translateX(24px);
}

/* Buttons */
.btn {
    padding: 12px 16px;
    border: none;
    border-radius: 6px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 44px;
    width: 100%;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    background: var(--text-secondary) !important;
}

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

.btn-primary:hover:not(:disabled) {
    background: var(--primary-dark);
}

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

.btn-success:hover:not(:disabled) {
    background: var(--secondary-dark);
}

.btn-success:not(:disabled) {
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(16, 185, 129, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
    }
}

/* Success */
.success {
    text-align: center;
    padding: 30px 20px;
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100%;
    position: relative;
}

.success-icon {
    font-size: 3rem;
    margin-bottom: 16px;
    color: var(--secondary-color);
}

.success h2 {
    color: var(--secondary-color);
    margin-bottom: 12px;
    font-size: 1.3rem;
}

/* КНОПКИ ЗАКРЫТИЯ ПРИЛОЖЕНИЯ */
.close-app-btn {
    position: absolute;
    top: 0;
    right: 0;
    background: rgba(255, 255, 255, 0.95);
    border: none;
    font-size: 0.9rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
    z-index: 1000;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
    border: 1px solid rgba(0, 0, 0, 0.1);
}

.close-app-btn:hover {
    background: white;
    color: var(--error-color);
    transform: scale(1.05);
}

/* Кастомный селект */
.form-section select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%236b7280'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 14px;
    padding-right: 36px;
}

/* АДАПТАЦИЯ ДЛЯ ОЧЕНЬ МАЛЕНЬКИХ ЭКРАНОВ */
@media (max-height: 600px) {
    .container {
        padding: 8px;
    }
    
    .header {
        margin-bottom: 12px;
        min-height: 36px;
    }
    
    .header h1 {
        font-size: 1.2rem;
    }
    
    .promo-form {
        padding: 12px;
        gap: 10px;
    }
    
    .form-section {
        gap: 4px;
    }
    
    .form-section label {
        font-size: 0.85rem;
    }
    
    .form-section input,
    .form-section select,
    .form-section textarea {
        padding: 8px 10px;
        font-size: 0.9rem;
    }
    
    .form-section textarea {
        min-height: 60px;
    }
    
    .btn {
        padding: 10px 14px;
        min-height: 40px;
        font-size: 0.9rem;
    }
    
    .char-counter, .form-section small {
        font-size: 0.7rem;
    }
    
    .close-app-btn {
        width: 22px;
        height: 22px;
        font-size: 0.8rem;
    }
    
    .success {
        padding: 20px 16px;
    }
    
    .success-icon {
        font-size: 2.5rem;
        margin-bottom: 12px;
    }
    
    .success h2 {
        font-size: 1.1rem;
    }
    
    /* АДАПТАЦИЯ ПЕРЕКЛЮЧАТЕЛЯ */
    .toggle-switch {
        width: 44px;
        height: 24px;
    }
    
    .toggle-slider:before {
        height: 16px;
        width: 16px;
        left: 4px;
        bottom: 4px;
    }
    
    input:checked + .toggle-slider:before {
        transform: translateX(20px);
    }
}

/* Улучшения для состояний */
.form-section input:not(:placeholder-shown),
.form-section textarea:not(:placeholder-shown) {
    border-width: 2px;
}

/* Подсветка активного поля */
.form-section:focus-within label {
    color: var(--primary-color);
}

/* Специфические стили для разных типов полей */
#titleInput:valid:not(:placeholder-shown) {
    border-left: 4px solid var(--border-valid);
}

#postTextInput:valid:not(:placeholder-shown) {
    border-left: 4px solid var(--border-valid);
}

#channelSelect:valid {
    border-left: 4px solid var(--border-valid);
}

#startDateInput:valid,
#endDateInput:valid {
    border-left: 4px solid var(--border-valid);
}

/* ГОРИЗОНТАЛЬНАЯ ОРИЕНТАЦИЯ */
@media (max-height: 400px) and (orientation: landscape) {
    .form-scroll-container {
        margin-bottom: 70px;
    }
    
    .form-actions-fixed {
        bottom: 8px;
        left: 8px;
        right: 8px;
        padding: 6px;
    }
    
    .promo-form {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 8px;
        padding: 8px;
    }
    
    .form-section {
        flex: 1 1 calc(50% - 4px);
        min-width: 0;
    }
    
    .form-section:nth-child(1),
    .form-section:nth-child(2),
    .toggle-section {
        flex: 1 1 100%;
    }
    
    .form-section textarea {
        min-height: 40px;
    }
}

/* Узкие экраны */
@media (max-width: 360px) {
    .container {
        padding: 8px;
    }
    
    .promo-form {
        padding: 12px;
    }
    
    .header h1 {
        font-size: 1.2rem;
    }
    
    .form-actions-fixed {
        left: 8px;
        right: 8px;
    }
}