/* Основные стили */
* { 
    box-sizing: border-box; 
    margin: 0; 
    padding: 0;
    -webkit-tap-highlight-color: rgba(0,0,0,0.1);
    -webkit-touch-callout: none;
}

html {
    touch-action: manipulation;
    height: 100%;
}

body { 
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; 
    background: #f5f5f5; 
    color: #333; 
    line-height: 1.6;
    min-height: 100vh;
    min-height: -webkit-fill-available;
    overflow-x: hidden;
}

body.dark-theme { 
    background: #1a1a1a; 
    color: #f0f0f0; 
}

body.dark-theme .adaptive-workspace { 
    background: #2d2d2d; 
}

/* Контейнер */
.adaptive-workspace { 
    display: flex; 
    flex-direction: column; 
    min-height: 100vh; 
    max-width: 1400px; 
    margin: 0 auto; 
    background: white; 
    box-shadow: 0 0 20px rgba(0,0,0,0.1);
}

/* Мобильное меню */
.mobile-menu {
    background: #f8f9fa;
    border-bottom: 1px solid #dee2e6;
    padding: 15px 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

body.dark-theme .mobile-menu {
    background: #2a2a2a;
    border-color: #4a4a4a;
}

.btn-block {
    display: block;
    width: 100%;
    text-align: left;
    padding: 12px 15px;
    margin-bottom: 5px;
}

/* Мобильное уведомление */
.mobile-toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.8);
    color: white;
    padding: 12px 20px;
    border-radius: 25px;
    font-size: 14px;
    z-index: 1001;
    max-width: 90%;
    text-align: center;
    backdrop-filter: blur(10px);
}

/* ==================== ШАПКА ДЛЯ МОБИЛЬНЫХ ==================== */

/* Мобильная шапка (по умолчанию для мобильных) */
@media (max-width: 768px) {
    .adaptive-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 8px 12px;
        min-height: 55px;
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        color: white;
        gap: 8px;
    }
    
    /* Левая часть: меню + логотип */
    .header-left-mobile {
        display: flex;
        align-items: center;
        gap: 8px;
        flex-shrink: 0;
    }
    
    /* Кнопка меню */
    .header-left-mobile .btn-compact {
        width: 36px;
        height: 36px;
        padding: 0;
        font-size: 1.1rem;
        background: rgba(255, 255, 255, 0.2);
        border-radius: 8px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    /* Логотип на мобильных */
    .header-logo-mobile {
        width: 28px;
        height: 28px;
        flex-shrink: 0;
    }
    
    .header-logo-mobile img {
        width: 100%;
        height: 100%;
        object-fit: contain;
    }
    
    /* Центральная часть: заголовок и слоган */
    .header-center-mobile {
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: center;
        min-width: 0;
    }
    
    /* Обертка заголовка */
    .mobile-title-wrapper {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        text-align: center;
        max-width: 100%;
        overflow: hidden;
    }
    
    /* Заголовок на мобильных */
    .mobile-title {
        font-size: 0.95rem;
        font-weight: 500;
        margin: 0;
        line-height: 1.2;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 100%;
    }
    
    /* Слоган на мобильных */
    .mobile-subtitle {
        font-size: 0.7rem;
        opacity: 0.9;
        line-height: 1.1;
        margin-top: 2px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 100%;
    }
    
    /* Правая часть: кнопки */
    .header-right-mobile {
        display: flex;
        align-items: center;
        gap: 6px;
        flex-shrink: 0;
    }
    
    .header-right-mobile .btn-compact {
        width: 36px;
        height: 36px;
        padding: 0;
        font-size: 1.1rem;
        background: rgba(255, 255, 255, 0.2);
        border-radius: 8px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    /* Скрываем старые элементы на мобильных */
    .header-left,
    .header-center,
    .header-right,
    .logo-title,
    .adaptive-title,
    .header-subtitle,
    .title-wrapper {
        display: none !important;
    }
}

/* Десктопная версия (скрываем мобильные элементы) */
@media (min-width: 769px) {
    .header-left-mobile,
    .header-center-mobile,
    .header-right-mobile,
    .mobile-title-wrapper,
    .mobile-title,
    .mobile-subtitle,
    .header-logo-mobile {
        display: none !important;
    }
}

.telegram-icon {
    font-size: 2rem;
    color: var(--primary-color);
}

/* ==================== СТРЕЛКИ ДЛЯ ПРОКРУТКИ ЭМОДЗИ НА МОБИЛЬНЫХ ==================== */

@media (max-width: 768px) {
    /* Эмодзи с горизонтальной прокруткой и стрелками */
    .emoji-section {
        margin-top: 15px;
        position: relative;
    }
    
    .emoji-scroll-container {
        position: relative;
        width: 100%;
        overflow: hidden;
        padding: 0 40px;
    }
    
    .emoji-grid {
        display: flex;
        flex-wrap: nowrap;
        gap: 8px;
        overflow-x: auto;
        overflow-y: hidden;
        scroll-behavior: smooth;
        padding: 10px 0;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }
    
    .emoji-grid::-webkit-scrollbar {
        display: none;
    }
    
    .emoji-grid button {
        flex: 0 0 auto;
        width: 44px;
        height: 44px;
        min-width: 44px;
        font-size: 1.4rem;
        padding: 8px;
        border: 1px solid #ddd;
        border-radius: 8px;
        background: white;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        transition: all 0.2s;
    }
    
    body.dark-theme .emoji-grid button {
        background: #3a3a3a;
        border-color: #555;
    }
    
    /* Стрелки для прокрутки эмодзи */
    .emoji-scroll-arrow {
        position: absolute;
        top: 50%;
        transform: translateY(-50%);
        width: 36px;
        height: 36px;
        background: rgba(102, 126, 234, 0.9);
        color: white;
        border: none;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        z-index: 10;
        font-size: 1.2rem;
        box-shadow: 0 2px 8px rgba(0,0,0,0.2);
        transition: all 0.2s;
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }
    
    .emoji-scroll-arrow.visible {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }
    
    .emoji-scroll-arrow:hover {
        background: #667eea;
        transform: translateY(-50%) scale(1.1);
    }
    
    .emoji-scroll-arrow:active {
        transform: translateY(-50%) scale(0.95);
        background: #5a5fcf;
    }
    
    .emoji-scroll-arrow.left {
        left: 5px;
    }
    
    .emoji-scroll-arrow.right {
        right: 5px;
    }
    
    /* Эффект при нажатии на стрелку на мобильных */
    .emoji-scroll-arrow:active {
        animation: arrowClick 0.2s ease;
    }
    
    @keyframes arrowClick {
        0% { transform: translateY(-50%) scale(1); }
        50% { transform: translateY(-50%) scale(0.9); }
        100% { transform: translateY(-50%) scale(1); }
    }
    
    /* Градиентные края для индикации возможности прокрутки */
    .emoji-scroll-container::before,
    .emoji-scroll-container::after {
        content: '';
        position: absolute;
        top: 0;
        bottom: 0;
        width: 40px;
        z-index: 5;
        pointer-events: none;
        opacity: 0;
        transition: opacity 0.3s;
    }
    
    .emoji-scroll-container::before {
        left: 0;
        background: linear-gradient(to right, rgba(255,255,255,0.9), transparent);
    }
    
    .emoji-scroll-container::after {
        right: 0;
        background: linear-gradient(to left, rgba(255,255,255,0.9), transparent);
    }
    
    body.dark-theme .emoji-scroll-container::before {
        background: linear-gradient(to right, rgba(45,45,45,0.9), transparent);
    }
    
    body.dark-theme .emoji-scroll-container::after {
        background: linear-gradient(to left, rgba(45,45,45,0.9), transparent);
    }
    
    .emoji-scroll-container.scroll-start::after,
    .emoji-scroll-container.scroll-middle::before,
    .emoji-scroll-container.scroll-middle::after,
    .emoji-scroll-container.scroll-end::before {
        opacity: 1;
    }
    
    /* Индикатор прокрутки */
    .emoji-scroll-indicator {
        display: flex;
        justify-content: center;
        gap: 6px;
        margin-top: 10px;
    }
    
    .scroll-dot {
        width: 8px;
        height: 8px;
        border-radius: 50%;
        background: #ddd;
        transition: all 0.3s;
        cursor: pointer;
    }
    
    .scroll-dot.active {
        background: #667eea;
        transform: scale(1.2);
    }
    
    body.dark-theme .scroll-dot {
        background: #555;
    }
    
    body.dark-theme .scroll-dot.active {
        background: #667eea;
    }
}

/* ==================== СКРЫТЬ СТРЕЛКИ ПРОКРУТКИ ЭМОДЗИ В ДЕСКТОПНОЙ ВЕРСИИ ==================== */

@media (min-width: 769px) {
    /* Скрываем стрелки прокрутки эмодзи в десктопной версии */
    .emoji-scroll-arrow {
        display: none !important;
    }
    
    /* Убираем отступы для контейнера эмодзи в десктопной версии */
    .emoji-scroll-container {
        padding: 0 !important;
    }
    
    /* Убираем градиентные края в десктопной версии */
    .emoji-scroll-container::before,
    .emoji-scroll-container::after {
        display: none !important;
    }
    
    /* Скрываем индикатор прокрутки в десктопной версии */
    .emoji-scroll-indicator {
        display: none !important;
    }
}

/* Специальные стили для очень маленьких экранов */
@media (max-width: 480px) {
    .emoji-grid {
        gap: 6px;
    }
    
    .emoji-grid button {
        width: 40px;
        height: 40px;
        min-width: 40px;
        font-size: 1.3rem;
    }
    
    .emoji-scroll-arrow {
        width: 32px;
        height: 32px;
        font-size: 1rem;
    }
}

/* Для ландшафтного режима на мобильных */
@media (max-width: 768px) and (orientation: landscape) {
    .emoji-grid button {
        width: 36px;
        height: 36px;
        min-width: 36px;
        font-size: 1.2rem;
    }
    
    .emoji-scroll-arrow {
        width: 30px;
        height: 30px;
        font-size: 0.9rem;
    }
}

/* ==================== УБРАТЬ ПОЛОСЫ ПРОКРУТКИ В ДЕСКТОПНОЙ ВЕРСИИ ==================== */

@media (min-width: 769px) {
    /* Полностью убираем полосы прокрутки у текстового поля ввода */
    #postText {
        overflow-y: auto;
        scrollbar-width: none; /* Firefox */
        -ms-overflow-style: none; /* IE и Edge */
    }
    
    /* Скрываем скроллбар для WebKit браузеров (Chrome, Safari, Edge) */
    #postText::-webkit-scrollbar {
        display: none;
        width: 0;
        height: 0;
    }
    
    /* Полностью убираем полосы прокрутки у предпросмотра текста */
    .text-preview {
        overflow-y: auto;
        scrollbar-width: none; /* Firefox */
        -ms-overflow-style: none; /* IE и Edge */
    }
    
    /* Скрываем скроллбар для предпросмотра */
    .text-preview::-webkit-scrollbar {
        display: none;
        width: 0;
        height: 0;
    }
    
    /* Полностью убираем полосы прокрутки у предпросмотра кнопок */
    .buttons-preview {
        overflow-y: auto;
        scrollbar-width: none; /* Firefox */
        -ms-overflow-style: none; /* IE и Edge */
    }
    
    /* Скрываем скроллбар для предпросмотра кнопок */
    .buttons-preview::-webkit-scrollbar {
        display: none;
        width: 0;
        height: 0;
    }
    
    /* Автоматическая высота для предпросмотра текста */
    .text-preview {
        max-height: none !important;
        min-height: 150px;
        height: auto;
    }
    
    /* Автоматическая высота для предпросмотра кнопок */
    .buttons-preview {
        max-height: none !important;
        min-height: 80px;
        height: auto;
    }
    
    /* Фиксированная высота для текстового поля ввода */
    #postText {
        min-height: 200px;
        max-height: 400px;
        resize: vertical;
    }
}

/* ==================== ВОССТАНАВЛИВАЕМ СКРОЛЛ НА МОБИЛЬНЫХ ==================== */

@media (max-width: 768px) {
    /* На мобильных возвращаем скролл */
    .text-preview {
        max-height: 200px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .buttons-preview {
        max-height: 250px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    #postText {
        min-height: 150px;
        max-height: 300px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* ==================== АДАПТАЦИЯ ПОД РАЗНЫЕ РАЗМЕРЫ ==================== */

/* Маленькие мобильные (до 480px) */
@media (max-width: 480px) {
    .adaptive-header {
        padding: 6px 10px;
        min-height: 50px;
        gap: 6px;
    }
    
    .header-left-mobile {
        gap: 6px;
    }
    
    .header-left-mobile .btn-compact,
    .header-right-mobile .btn-compact {
        width: 34px;
        height: 34px;
        font-size: 1rem;
    }
    
    .header-logo-mobile {
        width: 24px;
        height: 24px;
    }
    
    .mobile-title {
        font-size: 0.85rem;
    }
    
    .mobile-subtitle {
        font-size: 0.65rem;
    }
}

/* Очень маленькие мобильные (до 360px) */
@media (max-width: 360px) {
    .adaptive-header {
        padding: 5px 8px;
        min-height: 45px;
        gap: 4px;
    }
    
    .header-left-mobile .btn-compact,
    .header-right-mobile .btn-compact {
        width: 32px;
        height: 32px;
        font-size: 0.9rem;
    }
    
    .header-logo-mobile {
        width: 22px;
        height: 22px;
    }
    
    .mobile-title {
        font-size: 0.8rem;
    }
    
    .mobile-subtitle {
        font-size: 0.6rem;
        display: none;
    }
}

/* Сверхмаленькие экраны (до 320px) */
@media (max-width: 320px) {
    .mobile-title {
        font-size: 0.75rem;
    }
    
    .mobile-subtitle {
        font-size: 0.55rem;
        display: none;
    }
}

/* Ландшафтная ориентация на мобильных */
@media (max-width: 768px) and (orientation: landscape) {
    .adaptive-header {
        min-height: 45px;
        padding: 6px 10px;
    }
    
    .mobile-title {
        font-size: 0.85rem;
    }
    
    .mobile-subtitle {
        font-size: 0.65rem;
        display: none;
    }
}

/* Высокие мобильные экраны */
@media (max-width: 768px) and (min-height: 700px) {
    .adaptive-header {
        min-height: 60px;
        padding: 10px 12px;
    }
    
    .header-left-mobile .btn-compact,
    .header-right-mobile .btn-compact {
        width: 38px;
        height: 38px;
    }
    
    .header-logo-mobile {
        width: 30px;
        height: 30px;
    }
    
    .mobile-title {
        font-size: 1rem;
    }
    
    .mobile-subtitle {
        font-size: 0.75rem;
    }
}

/* ==================== ДЕСКТОПНАЯ ВЕРСИЯ ==================== */

/* Десктопная шапка (старая версия) */
@media (min-width: 769px) {
    .adaptive-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 15px 20px;
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        color: white;
        position: relative;
        z-index: 100;
        min-height: 70px;
    }
    
    /* Левая часть */
    .header-left {
        flex: 1;
        display: flex;
        justify-content: flex-start;
        min-width: 44px;
    }
    
    /* Центральная часть */
    .header-center {
        flex: 3;
        display: flex;
        justify-content: center;
        align-items: center;
        text-align: center;
        padding: 0 10px;
    }
    
    /* Правая часть */
    .header-right {
        flex: 1;
        display: flex;
        justify-content: flex-end;
        gap: 8px;
        min-width: 44px;
    }
    
    /* Обертка заголовка */
    .title-wrapper {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        max-width: 100%;
    }
    
    /* Логотип и заголовок в одной строке */
    .logo-title {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 12px;
        margin-bottom: 5px;
        flex-wrap: wrap;
    }
    
    /* Логотип */
    .header-logo {
        width: 32px;
        height: 32px;
        flex-shrink: 0;
    }
    
    .header-logo img {
        width: 100%;
        height: 100%;
        object-fit: contain;
    }
    
    /* Заголовок */
    .adaptive-title {
        font-size: 1.5rem;
        font-weight: 500;
        margin: 0;
        line-height: 1.3;
        text-align: center;
        word-break: break-word;
        overflow-wrap: break-word;
        max-width: 100%;
    }
    
    /* Подзаголовок */
    .header-subtitle {
        font-size: 0.85rem;
        opacity: 0.9;
        text-align: center;
        line-height: 1.4;
        max-width: 100%;
        word-break: break-word;
    }
}

/* Большие экраны */
@media (min-width: 1200px) {
    .adaptive-title {
        font-size: 1.7rem;
    }
    
    .header-subtitle {
        font-size: 1rem;
    }
}

/* Темная тема */
body.dark-theme .adaptive-header {
    background: linear-gradient(135deg, #4c5cb8 0%, #5d2e7a 100%);
}

/* API панель под шапкой */
.api-header-panel {
    background: #f8f9fa;
    border-bottom: 1px solid #dee2e6;
    padding: 15px 20px;
}

body.dark-theme .api-header-panel {
    background: #2a2a2a;
    border-color: #4a4a4a;
}

.api-fields-split {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    align-items: start;
}

.api-left-column, .api-right-column {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.api-field-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
}

.api-field-row {
    display: flex;
    gap: 10px;
    width: 100%;
}

.api-field-row input {
    flex: 1;
    min-width: 0;
    cursor: text !important;
    user-select: text !important;
    -webkit-user-select: text !important;
    -moz-user-select: text !important;
    -ms-user-select: text !important;
}

.api-field-buttons {
    display: flex;
    gap: 10px;
    margin-top: 5px;
}

.api-field-buttons button {
    flex: 1;
}

.api-field-hint {
    font-size: 0.8rem;
    color: #6c757d;
    margin-top: 4px;
    line-height: 1.4;
}

body.dark-theme .api-field-hint {
    color: #aaa;
}

/* Адаптивность для разделенной панели */
@media (max-width: 1024px) {
    .api-fields-split {
        gap: 20px;
    }
}

@media (max-width: 768px) {
    .api-fields-split {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    .api-field-row {
        flex-direction: column;
    }
    
    .api-field-buttons {
        width: 100%;
    }
    
    .api-field-buttons button {
        min-height: 44px;
    }
}

@media (max-width: 480px) {
    .api-field-buttons {
        flex-direction: column;
    }
}

/* Улучшение полей ввода */
.api-header-panel input {
    padding: 12px 15px;
    border: 1px solid #ced4da;
    border-radius: 8px;
    font-size: 16px !important;
    min-height: 48px;
    width: 100%;
}

body.dark-theme .api-header-panel input {
    background: #3a3a3a;
    border-color: #555;
    color: #f0f0f0;
}

.api-header-panel input:hover {
    border-color: #667eea;
}

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

/* Основной контейнер */
.adaptive-container { 
    display: flex; 
    flex: 1; 
    padding: 20px; 
    gap: 20px; 
}

@media (max-width: 1024px) {
    .adaptive-container {
        flex-direction: column;
        padding: 15px;
        gap: 15px;
    }
}

.left-panel, .right-panel { 
    flex: 1; 
    display: flex; 
    flex-direction: column; 
    gap: 20px; 
}

@media (max-width: 1024px) {
    .left-panel, .right-panel {
        gap: 15px;
    }
}

/* Секции */
.adaptive-section { 
    background: #fafafa; 
    border-radius: 12px; 
    border: 1px solid #e0e0e0; 
    display: flex; 
    flex-direction: column;
    overflow: hidden;
}

body.dark-theme .adaptive-section { 
    background: #3a3a3a; 
    border-color: #4a4a4a; 
}

.section-header { 
    padding: 15px 20px; 
    background: #f0f0f0; 
    border-bottom: 1px solid #e0e0e0; 
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

body.dark-theme .section-header { 
    background: #2a2a2a; 
    border-color: #4a4a4a; 
}

.section-header h3 { 
    font-size: 1rem; 
    font-weight: 500; 
    margin: 0; 
}

.section-content { 
    padding: 20px; 
    flex: 1; 
    display: flex; 
    flex-direction: column; 
}

@media (max-width: 768px) {
    .section-content {
        padding: 15px;
    }
}

/* Кнопки */
.btn-compact, .btn-small, .btn-primary, .btn-secondary { 
    padding: 12px 16px; 
    border: none; 
    border-radius: 8px; 
    cursor: pointer; 
    font-size: 0.95rem; 
    transition: all 0.2s; 
    font-family: inherit;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

@media (max-width: 768px) {
    .btn-compact, .btn-small, .btn-primary, .btn-secondary {
        padding: 10px 14px;
        font-size: 0.9rem;
    }
}

.btn-compact { 
    background: rgba(255,255,255,0.2); 
    color: white; 
    font-size: 1.2rem; 
    padding: 10px 14px; 
    min-width: 44px;
    min-height: 44px;
}

.btn-small { 
    background: #e9ecef; 
    color: #495057; 
    padding: 10px 14px; 
}

.btn-primary { 
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); 
    color: white; 
    font-weight: 500; 
}

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

.btn-danger { 
    background: #dc3545; 
    color: white; 
}

.btn-send { 
    background: #28a745; 
    color: white; 
}

.btn-large { 
    padding: 14px 24px; 
    font-size: 1rem; 
}

@media (max-width: 768px) {
    .btn-large {
        padding: 12px 20px;
        font-size: 0.95rem;
        width: 100%;
    }
}

.btn-small:hover, .btn-primary:hover { 
    opacity: 0.9; 
    transform: translateY(-1px); 
}

/* Активное состояние для мобильных */
.btn-small:active, .btn-primary:active, .btn-format:active {
    transform: scale(0.98);
}

/* Форматирование */
.adaptive-formatting { 
    display: flex; 
    gap: 8px; 
    margin-bottom: 15px; 
    flex-wrap: wrap; 
    justify-content: center;
}

.btn-format { 
    width: 44px; 
    height: 44px; 
    border: 1px solid #ddd; 
    background: white; 
    border-radius: 8px; 
    cursor: pointer; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    font-weight: bold;
    font-size: 14px;
    transition: all 0.2s;
}

@media (max-width: 768px) {
    .btn-format {
        width: 40px;
        height: 40px;
        font-size: 13px;
    }
}

body.dark-theme .btn-format { 
    background: #3a3a3a; 
    border-color: #555; 
    color: #f0f0f0; 
}

.btn-format.active {
    background: #667eea;
    color: white;
    transform: scale(0.95);
}

/* Текстовое поле */
.textarea-wrapper { 
    margin-bottom: 15px; 
    position: relative;
}

textarea { 
    width: 100%; 
    padding: 15px; 
    border: 2px solid #ddd; 
    border-radius: 8px; 
    font-size: 16px !important; 
    line-height: 1.6; 
    font-family: inherit; 
    resize: vertical; 
    min-height: 120px; 
    box-sizing: border-box;
    transition: border-color 0.2s;
}

@media (max-width: 768px) {
    textarea {
        padding: 12px;
        font-size: 16px !important;
        min-height: 100px;
    }
}

body.dark-theme textarea { 
    background: #2a2a2a; 
    border-color: #4a4a4a; 
    color: #f0f0f0; 
}

textarea:focus {
    border-color: #667eea;
    outline: none;
}

/* Эмодзи */
.emoji-section { 
    margin-top: 15px; 
}

.emoji-section h4 { 
    font-size: 0.9rem; 
    color: #666; 
    margin-bottom: 10px; 
    font-weight: 500; 
}

@media (min-width: 769px) {
    .emoji-grid { 
        display: grid; 
        grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); 
        gap: 6px; 
    }
    
    .emoji-grid button { 
        background: none; 
        border: 1px solid #ddd; 
        border-radius: 8px; 
        padding: 8px; 
        cursor: pointer; 
        font-size: 1.4rem; 
        display: flex; 
        align-items: center; 
        justify-content: center; 
        aspect-ratio: 1; 
        transition: all 0.2s;
    }
    
    body.dark-theme .emoji-grid button { 
        border-color: #555; 
        background: #3a3a3a; 
    }
    
    .emoji-grid button:active {
        background: #667eea;
        color: white;
        transform: scale(0.95);
    }
}

/* Контролы кнопок */
.buttons-controls { 
    margin-top: auto; 
    padding-top: 15px; 
}

.row-controls { 
    display: flex; 
    gap: 10px; 
    align-items: center; 
    margin-bottom: 10px; 
    flex-wrap: wrap; 
}

.row-controls select { 
    padding: 10px 12px; 
    border: 2px solid #ddd; 
    border-radius: 8px; 
    background: white; 
    font-size: 0.95rem; 
    cursor: pointer; 
    min-height: 44px;
    flex: 1;
    min-width: 120px;
}

body.dark-theme .row-controls select { 
    background: #3a3a3a; 
    border-color: #555; 
    color: #f0f0f0; 
}

.url-info { 
    font-size: 0.85rem; 
    color: #666; 
    padding: 12px 15px; 
    background: #fff3cd; 
    border-radius: 8px; 
    border-left: 4px solid #ffc107; 
    line-height: 1.5;
}

body.dark-theme .url-info { 
    background: #443c29; 
    color: #ffd54f; 
    border-left-color: #ffb300; 
}

/* Предпросмотр */
.preview-controls { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    margin-bottom: 15px; 
    flex-wrap: wrap; 
    gap: 10px; 
}

.text-preview { 
    padding: 20px; 
    background: white; 
    border: 2px solid #ddd; 
    border-radius: 8px; 
    margin-bottom: 15px; 
    line-height: 1.6; 
    flex: 1; 
    overflow-wrap: break-word;
    white-space: pre-wrap;
    word-break: break-word;
    min-height: 100px;
}

.text-preview strong {
    font-weight: bold;
}

.text-preview em {
    font-style: italic;
}

.text-preview u {
    text-decoration: underline;
}

.text-preview s {
    text-decoration: line-through;
}

.text-preview code {
    background: #f0f0f0;
    padding: 2px 4px;
    border-radius: 3px;
    font-family: monospace;
}

body.dark-theme .text-preview code {
    background: #333;
    color: #f0f0f0;
}

.text-preview a.preview-link {
    color: #3390ec;
    text-decoration: none;
}

.text-preview a.preview-link:hover {
    text-decoration: underline;
}

.text-preview .spoiler {
    background: #333;
    color: transparent;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 3px;
}

.text-preview .spoiler.revealed {
    background: #666;
    color: #fff;
}

@media (max-width: 768px) {
    .text-preview {
        padding: 15px;
        font-size: 14px;
        max-height: 200px;
    }
}

body.dark-theme .text-preview { 
    background: #2a2a2a; 
    border-color: #4a4a4a; 
}

.buttons-preview { 
    padding: 20px; 
    background: white; 
    border: 2px solid #ddd; 
    border-radius: 8px; 
    display: flex; 
    flex-direction: column; 
    gap: 10px; 
    min-height: 80px;
}

@media (max-width: 768px) {
    .buttons-preview {
        padding: 15px;
        max-height: 250px;
    }
}

body.dark-theme .buttons-preview { 
    background: #2a2a2a; 
    border-color: #4a4a4a; 
}

/* Кнопки Telegram */
.telegram-button-row { 
    display: flex; 
    gap: 8px; 
    margin-bottom: 8px; 
    width: 100%; 
}

.telegram-button-row:last-child { 
    margin-bottom: 0; 
}

.telegram-preview-button { 
    flex: 1; 
    padding: 12px 16px; 
    background: #3390ec; 
    color: white; 
    border: none; 
    border-radius: 8px; 
    font-size: 14px; 
    font-weight: 500; 
    cursor: pointer; 
    text-align: center; 
    white-space: nowrap; 
    overflow: hidden; 
    text-overflow: ellipsis; 
    transition: all 0.2s; 
    min-height: 44px; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    font-family: inherit;
    user-select: none;
}

@media (max-width: 768px) {
    .telegram-preview-button {
        padding: 14px;
        font-size: 13px;
        min-height: 48px;
        white-space: normal;
        word-break: break-word;
    }
}

.telegram-preview-button:hover { 
    background: #2c7fd1; 
}

.telegram-preview-button:active {
    transform: scale(0.98);
}

.telegram-preview-button.invalid-button { 
    background: #dc3545; 
    text-decoration: line-through; 
    opacity: 0.7; 
}

.telegram-preview-button.no-url { 
    background: #6c757d; 
    cursor: not-allowed; 
    opacity: 0.6; 
}

.telegram-preview-button.callback-button { 
    background: #6f42c1; 
}

.telegram-preview-button.callback-button:hover { 
    background: #5a32a3; 
}

/* Ряды кнопок */
#buttonRows { 
    flex: 1; 
    display: flex; 
    flex-direction: column; 
    gap: 15px; 
    margin-bottom: 15px; 
}

.button-row-container { 
    background: white; 
    border: 2px solid #eee; 
    border-radius: 10px; 
    overflow: hidden;
}

body.dark-theme .button-row-container { 
    background: #3a3a3a; 
    border-color: #4a4a4a; 
}

.button-row-header { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    padding: 15px; 
    background: #f8f9fa; 
    border-bottom: 1px solid #eee; 
    flex-wrap: wrap;
    gap: 10px;
}

@media (max-width: 480px) {
    .button-row-header {
        flex-direction: column;
        align-items: stretch;
        text-align: center;
    }
}

body.dark-theme .button-row-header { 
    background: #2a2a2a; 
    border-color: #4a4a4a; 
}

.button-grid { 
    display: grid; 
    gap: 15px; 
    padding: 20px; 
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); 
}

@media (max-width: 768px) {
    .button-grid {
        grid-template-columns: 1fr;
        padding: 15px;
        gap: 12px;
    }
}

/* Инпуты кнопок */
.button-input-container { 
    display: flex; 
    flex-direction: column; 
    gap: 8px; 
}

.button-input-container input { 
    padding: 12px 15px; 
    border: 2px solid #ddd; 
    border-radius: 8px; 
    font-size: 16px !important; 
    width: 100%; 
    min-height: 44px;
}

.button-input-container .url-hint { 
    font-size: 0.8rem; 
    min-height: 16px; 
    margin-top: -2px; 
    padding: 0 5px;
}

/* Нижняя панель */
.bottom-panel { 
    padding: 20px; 
    background: #f8f9fa; 
    border-top: 1px solid #dee2e6; 
}

@media (max-width: 768px) {
    .bottom-panel {
        padding: 15px;
    }
}

body.dark-theme .bottom-panel { 
    background: #2a2a2a; 
    border-color: #4a4a4a; 
}

.action-buttons { 
    display: flex; 
    gap: 15px; 
    align-items: center; 
    margin-bottom: 15px; 
    flex-wrap: wrap; 
}

@media (max-width: 768px) {
    .action-buttons {
        flex-direction: column;
        gap: 10px;
    }
}

.save-buttons { 
    display: flex; 
    gap: 10px; 
    margin-left: auto; 
}

@media (max-width: 768px) {
    .save-buttons {
        margin-left: 0;
        justify-content: center;
        width: 100%;
        flex-wrap: wrap;
    }
}

/* URL секция */
.url-section { 
    background: white; 
    border: 2px solid #dee2e6; 
    border-radius: 12px; 
    padding: 20px; 
    margin-top: 15px;
}

@media (max-width: 768px) {
    .url-section {
        padding: 15px;
    }
}

body.dark-theme .url-section { 
    background: #3a3a3a; 
    border-color: #4a4a4a; 
}

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

.url-header h4 { 
    margin: 0; 
    font-size: 1rem; 
}

.url-actions { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    margin-top: 15px; 
    flex-wrap: wrap; 
    gap: 10px; 
}

/* Футер */
.adaptive-footer { 
    padding: 15px 20px; 
    background: #343a40; 
    color: white; 
    font-size: 0.85rem; 
}

body.dark-theme .adaptive-footer { 
    background: #1a1a1a; 
}

.footer-info { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    flex-wrap: wrap; 
    gap: 10px; 
}

.status-offline { 
    color: #dc3545; 
}

.status-online { 
    color: #28a745; 
}

.status-saved { 
    color: #17a2b8; 
}

/* Модальные окна */
.modal { 
    position: fixed; 
    top: 0; 
    left: 0; 
    width: 100%; 
    height: 100%; 
    background: rgba(0,0,0,0.7); 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    z-index: 1000; 
    padding: 20px; 
    backdrop-filter: blur(5px);
}

.modal.hidden { 
    display: none; 
}

.modal-content { 
    background: white; 
    border-radius: 16px; 
    width: 100%; 
    max-width: 500px; 
    max-height: 80vh; 
    overflow-y: auto; 
    box-shadow: 0 10px 40px rgba(0,0,0,0.3); 
    animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-50px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

body.dark-theme .modal-content { 
    background: #3a3a3a; 
    color: #f0f0f0; 
}

.modal-header { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    padding: 20px; 
    border-bottom: 1px solid #dee2e6; 
    position: sticky;
    top: 0;
    background: inherit;
    z-index: 1;
}

.modal-header h3 { 
    margin: 0; 
    font-size: 1.3rem; 
}

.modal-close { 
    background: none; 
    border: none; 
    font-size: 1.8rem; 
    cursor: pointer; 
    color: #666; 
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

body.dark-theme .modal-close {
    color: #aaa;
}

.modal-body { 
    padding: 20px; 
    max-height: 50vh;
    overflow-y: auto;
}

.modal-body ul, .modal-body ol {
    padding-left: 20px;
    margin: 10px 0;
}

.modal-body li {
    margin-bottom: 8px;
}

.modal-footer { 
    padding: 20px; 
    border-top: 1px solid #dee2e6; 
    text-align: right; 
    position: sticky;
    bottom: 0;
    background: inherit;
}

/* Утилиты */
.hidden { 
    display: none !important; 
}

.empty-state { 
    padding: 40px 20px; 
    text-align: center; 
    color: #6c757d; 
    font-style: italic; 
    background: #f8f9fa; 
    border-radius: 8px; 
    font-size: 0.95rem;
}

body.dark-theme .empty-state { 
    background: #2a2a2a; 
    color: #aaa; 
}

/* Анимации */
@keyframes spin { 
    0% { transform: rotate(0deg); } 
    100% { transform: rotate(360deg); } 
}

@keyframes successPulse { 
    0% { background-color: #28a745; } 
    50% { background-color: #218838; } 
    100% { background-color: #28a745; } 
}

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

.copy-success { 
    animation: successPulse 0.5s ease-in-out; 
}

/* Специальные стили для мобильных */
@media (max-width: 768px) {
    .is-mobile .btn-compact,
    .is-mobile .btn-small,
    .is-mobile .btn-primary {
        touch-action: manipulation;
    }
    
    .is-mobile .textarea-wrapper textarea {
        font-size: 16px !important;
        line-height: 1.5;
    }
    
    .is-mobile .telegram-button-row {
        flex-direction: column;
    }
    
    .is-mobile .telegram-preview-button {
        width: 100%;
        margin-bottom: 8px;
    }
    
    .is-mobile .button-grid {
        grid-template-columns: 1fr;
    }
    
    .is-mobile .api-field-row {
        flex-direction: column;
    }
    
    .is-mobile .api-field-row input,
    .is-mobile .api-field-row button {
        width: 100%;
    }
    
    .is-mobile .action-buttons {
        flex-direction: column;
    }
    
    .is-mobile .save-buttons {
        justify-content: stretch;
    }
    
    .is-mobile .save-buttons button {
        flex: 1;
        min-width: 0;
    }
    
    .is-mobile .modal-content {
        margin: 10px;
        max-height: 85vh;
    }
    
    .is-mobile .modal-body {
        max-height: 60vh;
    }
}

/* Особо маленькие экраны */
@media (max-width: 360px) {
    .adaptive-header h1 {
        font-size: 1.2rem;
    }
    
    .btn-compact, .btn-small, .btn-primary {
        padding: 10px 12px;
        font-size: 0.85rem;
    }
    
    .section-header h3 {
        font-size: 0.9rem;
    }
    
    .api-field-hint {
        font-size: 0.75rem;
    }
    
    .emoji-grid {
        grid-template-columns: repeat(auto-fill, minmax(36px, 1fr));
    }
    
    .emoji-grid button {
        font-size: 1.2rem;
        padding: 6px;
    }
}

/* Высокие экраны */
@media (min-height: 800px) and (max-width: 768px) {
    .text-preview {
        max-height: 300px;
    }
    
    .buttons-preview {
        max-height: 350px;
    }
}

/* Портретный режим */
@media (orientation: portrait) and (max-width: 768px) {
    .adaptive-container {
        flex-direction: column;
    }
    
    .left-panel, .right-panel {
        width: 100%;
    }
}

/* Ландшафтный режим */
@media (orientation: landscape) and (max-height: 500px) {
    .adaptive-header {
        padding: 10px 15px;
    }
    
    .api-header-panel {
        padding: 10px 15px;
    }
    
    .adaptive-container {
        padding: 10px;
    }
    
    .section-content {
        padding: 15px;
    }
}

/* Поддержка темной темы системного уровня */
@media (prefers-color-scheme: dark) {
    body:not(.light-theme) {
        background: #1a1a1a;
        color: #f0f0f0;
    }
    
    body:not(.light-theme) .adaptive-workspace {
        background: #2d2d2d;
    }
}

/* Улучшение доступности */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Подсветка фокуса для клавиатурной навигации */
@media (any-pointer: coarse) {
    *:focus {
        outline: 3px solid #667eea;
        outline-offset: 2px;
    }
}

/* Стили для кнопок загрузки из файла */
.api-field-buttons {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.api-field-buttons button {
    flex: 1;
    min-width: 120px;
}

@media (max-width: 480px) {
    .api-field-buttons {
        flex-direction: column;
    }
    
    .api-field-buttons button {
        width: 100%;
        min-width: 0;
    }
}

/* Стили для мобильных кнопок сохранения */
.mobile-save-buttons {
    display: none;
    gap: 10px;
    width: 100%;
    margin-top: 10px;
}

.mobile-save-buttons button {
    flex: 1;
    min-height: 44px;
    font-size: 0.9rem;
    padding: 12px;
}

.mobile-save-buttons .btn-small {
    background: #f8f9fa;
    border: 2px solid #dee2e6;
    color: #495057;
    font-weight: 500;
}

body.dark-theme .mobile-save-buttons .btn-small {
    background: #3a3a3a;
    border-color: #555;
    color: #f0f0f0;
}

.mobile-save-buttons .btn-danger {
    background: #dc3545;
    border-color: #dc3545;
    color: white;
}

body.dark-theme .mobile-save-buttons .btn-danger {
    background: #c82333;
    border-color: #bd2130;
}

/* Медиа-запросы для отображения/скрытия кнопок */
@media (max-width: 768px) {
    .mobile-save-buttons {
        display: flex !important;
    }
    
    .save-buttons {
        display: none !important;
    }
    
    .mobile-save-buttons button:active {
        transform: scale(0.98);
        transition: transform 0.1s;
    }
}

@media (min-width: 769px) {
    .mobile-save-buttons {
        display: none !important;
    }
    
    .save-buttons {
        display: flex !important;
    }
}

/* Эффекты при наведении/нажатии */
.mobile-save-buttons .btn-small:hover,
.mobile-save-buttons .btn-small:focus {
    background: #e9ecef;
    border-color: #adb5bd;
}

body.dark-theme .mobile-save-buttons .btn-small:hover,
body.dark-theme .mobile-save-buttons .btn-small:focus {
    background: #4a4a4a;
    border-color: #666;
}

.mobile-save-buttons .btn-danger:hover,
.mobile-save-buttons .btn-danger:focus {
    background: #c82333;
    border-color: #bd2130;
}

body.dark-theme .mobile-save-buttons .btn-danger:hover,
body.dark-theme .mobile-save-buttons .btn-danger:focus {
    background: #b21f2d;
    border-color: #a71e2a;
}

/* Статус редактирования */
.edit-status {
    background: #e8f5e8;
    border-left: 4px solid #28a745;
    padding: 10px 15px;
    margin: 10px 20px;
    border-radius: 4px;
    word-break: break-word;
}

body.dark-theme .edit-status {
    background: #2a3c2a;
    border-left-color: #34c759;
}

/* Мобильная оптимизация */
.mobile-only {
    display: none;
}

@media (max-width: 768px) {
    .mobile-only {
        display: block;
    }
    
    .desktop-only {
        display: none;
    }
    
    /* Увеличение области касания для мобильных */
    button, input[type="button"], input[type="submit"] {
        min-height: 44px;
        min-width: 44px;
    }
    
    select, .btn-format {
        min-height: 44px;
    }
}

/* Предотвращение масштабирования при фокусе на iOS */
input, textarea, select {
    font-size: 16px !important;
}

/* Улучшение видимости фокуса для мобильных */
*:focus {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}