/* ==========================================================================
   Reformator Module - Modern 2026 Design
   Адаптив: mobile-first, идеально на всех устройствах
   ========================================================================== */

.reformator {
    padding: clamp(16px, 4vw, 32px) 0;
}

/* ==========================================================================
   Main Layout - Mobile First
   ========================================================================== */
.reformator-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: clamp(16px, 4vw, 24px);
    margin-top: clamp(16px, 4vw, 24px);
}

@media (min-width: 768px) {
    .reformator-layout {
        grid-template-columns: 280px 1fr;
        gap: var(--spacing-lg);
        margin-top: var(--spacing-lg);
    }
}

@media (min-width: 1024px) {
    .reformator-layout {
        grid-template-columns: 280px 1fr;
    }
}

/* ==========================================================================
   Sidebar - Mobile First
   ========================================================================== */
.reformator-sidebar {
    background: var(--white);
    border-radius: clamp(16px, 4vw, 20px);
    border: 1px solid var(--gray-200);
    padding: clamp(16px, 4vw, 24px);
    height: fit-content;
    order: 2;
}

@media (min-width: 768px) {
    .reformator-sidebar {
        order: 1;
        position: sticky;
        top: clamp(80px, 10vh, 100px);
        border-radius: var(--border-radius-lg);
        padding: var(--spacing-lg);
    }
}

.sidebar-section {
    margin-bottom: clamp(16px, 4vw, 24px);
}

.sidebar-section:last-child {
    margin-bottom: 0;
}

.sidebar-section h3 {
    font-size: clamp(0.875rem, 3vw, 1rem);
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: clamp(12px, 3vw, 16px);
    text-transform: uppercase;
    letter-spacing: 0.02em;
    display: flex;
    align-items: center;
    gap: 8px;
}

.sidebar-section h3::before {
    content: '';
    width: 4px;
    height: 1.2em;
    background: var(--primary-500);
    border-radius: var(--border-radius-full);
}

/* ==========================================================================
   File Upload Area - Mobile First
   ========================================================================== */
.file-upload-area {
    border: 2px dashed var(--gray-300);
    border-radius: clamp(12px, 3vw, 16px);
    padding: clamp(20px, 5vw, 32px) clamp(16px, 4vw, 24px);
    text-align: center;
    background: var(--gray-50);
    transition: var(--transition);
    cursor: pointer;
    min-height: clamp(180px, 30vh, 220px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.file-upload-area:hover,
.file-upload-area.dragover {
    border-color: var(--primary-500);
    background: var(--primary-50);
}

@media (hover: none) and (pointer: coarse) {
    .file-upload-area:active {
        background: var(--primary-50);
        border-color: var(--primary-500);
    }
}

.upload-icon {
    font-size: clamp(2rem, 8vw, 2.5rem);
    margin-bottom: clamp(8px, 2vw, 12px);
    color: var(--gray-500);
}

.upload-text {
    font-weight: 500;
    color: var(--gray-700);
    margin-bottom: clamp(4px, 1vw, 8px);
    font-size: clamp(0.875rem, 3vw, 1rem);
}

.upload-hint {
    font-size: clamp(0.7rem, 2.5vw, 0.75rem);
    color: var(--gray-500);
    margin-bottom: clamp(12px, 3vw, 16px);
}

/* ==========================================================================
   Buttons - Mobile First
   ========================================================================== */
.btn-block {
    width: 100%;
    margin-bottom: 8px;
    padding: clamp(10px, 3vw, 12px) clamp(12px, 4vw, 16px);
    font-size: clamp(0.8125rem, 3vw, 0.875rem);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.btn-sm {
    padding: clamp(6px, 2vw, 8px) clamp(12px, 4vw, 16px);
    font-size: clamp(0.75rem, 2.5vw, 0.8125rem);
    min-height: 36px;
}

.btn-icon {
    margin-right: 6px;
    font-size: 1.1em;
}

/* ==========================================================================
   Stats Section - Mobile First
   ========================================================================== */
.stats-item {
    display: flex;
    justify-content: space-between;
    padding: clamp(8px, 2vw, 10px) 0;
    border-bottom: 1px solid var(--gray-100);
    font-size: clamp(0.8125rem, 2.5vw, 0.875rem);
}

.stats-item:last-child {
    border-bottom: none;
}

.stats-label {
    color: var(--gray-600);
    display: flex;
    align-items: center;
    gap: 6px;
}

.stats-value {
    font-weight: 600;
    color: var(--gray-800);
    background: var(--gray-100);
    padding: 2px 10px;
    border-radius: var(--border-radius-full);
    min-width: 40px;
    text-align: center;
}

/* ==========================================================================
   Main Editor Area - Mobile First
   ========================================================================== */
.reformator-main {
    background: var(--white);
    border-radius: clamp(16px, 4vw, 20px);
    border: 1px solid var(--gray-200);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    order: 1;
    display: flex;
    flex-direction: column;
    height: fit-content;
}

@media (min-width: 768px) {
    .reformator-main {
        border-radius: var(--border-radius-lg);
        order: 2;
    }
}

/* ==========================================================================
   Toolbar - Mobile First
   ========================================================================== */
.editor-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: clamp(8px, 2vw, 12px);
    background: var(--gray-50);
    border-bottom: 1px solid var(--gray-200);
    position: relative;
    z-index: 10;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: var(--gray-400) var(--gray-200);
}

.editor-toolbar::-webkit-scrollbar {
    height: 4px;
}

.editor-toolbar::-webkit-scrollbar-track {
    background: var(--gray-200);
}

.editor-toolbar::-webkit-scrollbar-thumb {
    background: var(--gray-400);
    border-radius: 4px;
}

.editor-toolbar::-webkit-scrollbar-thumb:hover {
    background: var(--primary-400);
}

.toolbar-group {
    display: flex;
    gap: 2px;
    padding: 0 4px;
    border-right: 1px solid var(--gray-200);
    flex-shrink: 0;
}

.toolbar-group:last-child {
    border-right: none;
}

.ml-auto {
    margin-left: auto;
}

@media (max-width: 768px) {
    .ml-auto {
        margin-left: 0;
    }
}

.toolbar-btn {
    width: clamp(32px, 8vw, 36px);
    height: clamp(32px, 8vw, 36px);
    min-width: 32px;
    min-height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: var(--border-radius-sm);
    color: var(--gray-700);
    font-size: clamp(0.875rem, 3vw, 1rem);
    cursor: pointer;
    transition: var(--transition);
    padding: 0;
}

.toolbar-btn:hover {
    background: var(--gray-200);
    color: var(--gray-900);
}

.toolbar-btn:active {
    transform: scale(0.95);
}

.toolbar-btn.active {
    background: var(--primary-100);
    color: var(--primary-700);
}

.toolbar-icon {
    font-size: clamp(1rem, 4vw, 1.25rem);
    line-height: 1;
}

/* Touch optimization */
@media (hover: none) and (pointer: coarse) {
    .toolbar-btn {
        -webkit-tap-highlight-color: transparent;
    }
    
    .toolbar-btn:active {
        background: var(--gray-200);
        transform: none;
    }
}

/* ==========================================================================
   Editor Containers - Mobile First
   ========================================================================== */
.editor-container {
    min-height: clamp(400px, 60vh, 500px);
    max-height: clamp(500px, 80vh, 750px);
    overflow-y: auto;
    position: relative;
    flex: 1;
    -webkit-overflow-scrolling: touch;
}

.visual-editor {
    padding: clamp(16px, 4vw, 24px);
    min-height: clamp(400px, 50vh, 500px);
    outline: none;
    font-family: var(--font-primary);
    line-height: 1.6;
    color: var(--gray-900);
    font-size: clamp(0.9375rem, 3vw, 1rem);
}

.visual-editor:focus {
    box-shadow: inset 0 0 0 2px var(--primary-100);
}

.visual-editor p {
    margin-bottom: 1em;
}

.visual-editor blockquote {
    margin: 1em 0;
    padding-left: clamp(12px, 3vw, 16px);
    border-left: 3px solid var(--primary-500);
    color: var(--gray-700);
    font-style: italic;
}

.visual-editor a {
    color: var(--primary-600);
    text-decoration: underline;
    word-break: break-all;
}

.visual-editor ul,
.visual-editor ol {
    margin: 1em 0;
    padding-left: clamp(1.5em, 5vw, 2em);
}

.visual-editor img {
    max-width: 100%;
    height: auto;
}

/* Code Editor */
.code-editor {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.code-textarea {
    width: 100%;
    min-height: clamp(400px, 50vh, 500px);
    padding: clamp(16px, 4vw, 24px);
    font-family: 'Monaco', 'Menlo', 'Courier New', monospace;
    font-size: clamp(0.8125rem, 2.5vw, 0.875rem);
    line-height: 1.6;
    border: none;
    outline: none;
    resize: vertical;
    background: var(--gray-900);
    color: var(--gray-100);
    white-space: pre-wrap;
    word-wrap: break-word;
    tab-size: 2;
    flex: 1;
}

/* ==========================================================================
   Editor Footer - Mobile First
   ========================================================================== */
.editor-footer {
    display: flex;
    flex-direction: column;
    gap: clamp(8px, 2vw, 12px);
    padding: clamp(12px, 3vw, 16px) clamp(16px, 4vw, 24px);
    background: var(--gray-50);
    border-top: 1px solid var(--gray-200);
}

@media (min-width: 480px) {
    .editor-footer {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }
}

.footer-info {
    font-size: clamp(0.75rem, 2.5vw, 0.875rem);
    color: var(--gray-600);
}

.info-badge {
    background: var(--white);
    padding: 4px clamp(8px, 2vw, 12px);
    border-radius: var(--border-radius-full);
    border: 1px solid var(--gray-200);
    font-weight: 500;
}

.footer-actions {
    display: flex;
    gap: 8px;
}

/* ==========================================================================
   Modal Styles - Mobile First
   ========================================================================== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
    padding: clamp(12px, 3vw, 20px);
}

.modal-content {
    background: var(--white);
    border-radius: clamp(16px, 4vw, 24px);
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-xl);
    display: flex;
    flex-direction: column;
}

.modal-content.modal-lg {
    max-width: min(700px, 95%);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: clamp(16px, 4vw, 24px);
    border-bottom: 1px solid var(--gray-200);
    flex-shrink: 0;
}

.modal-header h3 {
    font-size: clamp(1.1rem, 4vw, 1.25rem);
    font-weight: 600;
    color: var(--gray-900);
    margin: 0;
}

.modal-close {
    background: transparent;
    border: none;
    font-size: clamp(1.25rem, 5vw, 1.5rem);
    line-height: 1;
    cursor: pointer;
    color: var(--gray-500);
    transition: var(--transition);
    width: clamp(32px, 8vw, 40px);
    height: clamp(32px, 8vw, 40px);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--border-radius-full);
}

.modal-close:hover {
    background: var(--gray-100);
    color: var(--gray-900);
}

.modal-body {
    padding: clamp(16px, 4vw, 24px);
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    display: flex;
    flex-direction: column-reverse;
    gap: 8px;
    padding: clamp(16px, 4vw, 24px);
    border-top: 1px solid var(--gray-200);
    flex-shrink: 0;
}

@media (min-width: 480px) {
    .modal-footer {
        flex-direction: row;
        justify-content: flex-end;
        gap: var(--spacing-sm);
    }
}

.modal-footer .btn {
    width: 100%;
    padding: clamp(10px, 3vw, 12px);
    font-size: clamp(0.875rem, 3vw, 0.9375rem);
}

@media (min-width: 480px) {
    .modal-footer .btn {
        width: auto;
        min-width: 100px;
    }
}

.modal-info {
    margin-top: var(--spacing-sm);
    font-size: clamp(0.75rem, 2.5vw, 0.875rem);
    color: var(--gray-600);
    background: var(--gray-50);
    padding: clamp(8px, 2vw, 12px);
    border-radius: var(--border-radius-sm);
    word-break: break-word;
}

/* ==========================================================================
   Form Controls - Mobile First
   ========================================================================== */
.form-group {
    margin-bottom: clamp(16px, 4vw, 20px);
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    color: var(--gray-700);
    font-size: clamp(0.8125rem, 2.5vw, 0.875rem);
}

.form-control {
    width: 100%;
    padding: clamp(10px, 3vw, 12px) clamp(12px, 3vw, 14px);
    border: 1px solid var(--gray-300);
    border-radius: var(--border-radius-md);
    font-family: var(--font-primary);
    font-size: clamp(0.875rem, 3vw, 0.9375rem);
    transition: var(--transition);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-500);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: clamp(8px, 2vw, 12px);
    cursor: pointer;
    color: var(--gray-700);
    font-size: clamp(0.875rem, 3vw, 0.9375rem);
    min-height: 44px;
}

.checkbox-label input[type="checkbox"] {
    width: clamp(18px, 4vw, 20px);
    height: clamp(18px, 4vw, 20px);
    accent-color: var(--primary-600);
}

/* ==========================================================================
   Excel Table Styles - Mobile First
   ========================================================================== */
.excel-table {
    width: 100%;
    border-collapse: collapse;
    margin: var(--spacing-md) 0;
    font-size: clamp(0.8125rem, 2.5vw, 0.9375rem);
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
}

@media (min-width: 640px) {
    .excel-table {
        display: table;
        white-space: normal;
    }
}

.excel-table th {
    background: var(--gray-100);
    font-weight: 600;
    padding: clamp(8px, 2vw, 12px);
    text-align: left;
    border: 1px solid var(--gray-300);
}

.excel-table td {
    padding: clamp(6px, 1.5vw, 10px) clamp(8px, 2vw, 12px);
    border: 1px solid var(--gray-300);
}

.excel-table tr:nth-child(even) {
    background: var(--gray-50);
}

.excel-table tr:hover {
    background: var(--primary-50);
}

/* ==========================================================================
   Final Code Textarea
   ========================================================================== */
#finalCodeTextarea {
    white-space: pre-wrap;
    word-wrap: break-word;
    font-family: 'Monaco', 'Menlo', 'Courier New', monospace;
    font-size: clamp(0.8125rem, 2.5vw, 0.875rem);
    line-height: 1.6;
    min-height: clamp(200px, 40vh, 300px);
    resize: vertical;
    background: var(--gray-900);
    color: var(--gray-100);
    padding: clamp(12px, 3vw, 16px);
    border-radius: var(--border-radius-md);
    width: 100%;
    border: none;
}

/* ==========================================================================
   Landscape Mode Optimization
   ========================================================================== */
@media (max-height: 600px) and (orientation: landscape) {
    .modal-content {
        max-height: 95vh;
    }
    
    .modal-body {
        max-height: 50vh;
    }
    
    .editor-container {
        min-height: 300px;
        max-height: 400px;
    }
    
    .visual-editor,
    .code-textarea {
        min-height: 250px;
    }
}

/* ==========================================================================
   Small Height Devices
   ========================================================================== */
@media (max-height: 700px) {
    .reformator-sidebar {
        top: 60px;
    }
    
    .editor-container {
        min-height: 350px;
    }
}

/* ==========================================================================
   Touch Device Optimizations
   ========================================================================== */
@media (hover: none) and (pointer: coarse) {
    .toolbar-btn,
    .btn,
    .file-upload-area,
    .modal-close,
    .checkbox-label {
        cursor: default;
        -webkit-tap-highlight-color: transparent;
    }
    
    .visual-editor {
        -webkit-user-select: text;
        user-select: text;
    }
    
    .visual-editor [contenteditable="true"] {
        -webkit-tap-highlight-color: rgba(79, 70, 229, 0.2);
    }
}

/* ==========================================================================
   High-DPI Screens
   ========================================================================== */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .reformator-sidebar,
    .reformator-main,
    .modal-content {
        border-width: 0.5px;
    }
}

/* ==========================================================================
   Print Styles
   ========================================================================== */
@media print {
    .reformator-sidebar,
    .editor-toolbar,
    .editor-footer,
    .modal,
    .btn {
        display: none !important;
    }
    
    .reformator-layout {
        grid-template-columns: 1fr;
    }
    
    .reformator-main {
        border: 1px solid #000;
        box-shadow: none;
    }
    
    .visual-editor {
        padding: 0;
    }
    
    .page-title {
        -webkit-text-fill-color: initial;
        background: none;
        color: #000;
    }
}

/* ==========================================================================
   Loading States
   ========================================================================== */
.reformator.loading .visual-editor {
    opacity: 0.5;
    pointer-events: none;
}

.reformator.loading::after {
    content: '';
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    border: 3px solid var(--gray-200);
    border-top-color: var(--primary-600);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    z-index: 1001;
}

@keyframes spin {
    to { transform: translate(-50%, -50%) rotate(360deg); }
}