/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
}

/* Container */
.container {
    max-width: 1600px;
    margin: 0 auto;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    min-height: calc(100vh - 40px);
}

/* Header Styles */
.header {
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 50%, #667eea 100%);
    color: white;
    padding: 40px 30px;
    text-align: center;
    position: relative;
    overflow: hidden;
}

.header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><defs><pattern id="grain" width="100" height="100" patternUnits="userSpaceOnUse"><circle cx="20" cy="20" r="1" fill="rgba(255,255,255,0.1)"/><circle cx="80" cy="40" r="0.8" fill="rgba(255,255,255,0.08)"/><circle cx="40" cy="80" r="1.2" fill="rgba(255,255,255,0.06)"/><circle cx="90" cy="90" r="0.6" fill="rgba(255,255,255,0.1)"/><circle cx="10" cy="60" r="0.9" fill="rgba(255,255,255,0.07)"/></pattern></defs><rect width="100" height="100" fill="url(%23grain)"/></svg>');
    opacity: 0.3;
    animation: float 20s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { 
        transform: translateX(0px) translateY(0px); 
    }
    33% { 
        transform: translateX(10px) translateY(-10px); 
    }
    66% { 
        transform: translateX(-5px) translateY(5px); 
    }
}

.header-content {
    position: relative;
    z-index: 2;
}

.header h1 {
    font-size: 2.8em;
    margin: 25px 0 15px 0;
    font-weight: 300;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
    background: linear-gradient(45deg, #ffffff, #f0f8ff);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-badges {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: 25px;
    flex-wrap: wrap;
}

.badge {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    padding: 8px 20px;
    border-radius: 25px;
    font-size: 0.9em;
    font-weight: 600;
    border: 1px solid rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(5px);
    transition: all 0.3s ease;
    cursor: pointer;
}

.badge:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

/* Tab Navigation */
.converter-tabs {
    display: flex;
    background: #f8f9fa;
    border-bottom: 1px solid #e9ecef;
}

.tab-button {
    flex: 1;
    padding: 20px;
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 1.1em;
    font-weight: 600;
    color: #6c757d;
    transition: all 0.3s ease;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.tab-button:hover {
    background: rgba(102, 126, 234, 0.1);
    color: #667eea;
}

.tab-button.active {
    background: white;
    color: #2c3e50;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
}

.tab-button.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(135deg, #667eea, #764ba2);
}

.tab-icon {
    font-size: 1.3em;
}

/* Tab Content */
.tab-content {
    display: none;
    padding: 30px;
    min-height: 600px;
}

.tab-content.active {
    display: block;
}

/* Converter Layout */
.converter-layout {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 30px;
    height: 100%;
}

/* File Section */
.file-section {
    background: white;
    border-radius: 15px;
    padding: 25px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.08);
    height: fit-content;
}

.file-section h3 {
    color: #2c3e50;
    margin-bottom: 20px;
    font-size: 1.3em;
    display: flex;
    align-items: center;
    gap: 10px;
}

.file-section h4 {
    color: #6c757d;
    margin-bottom: 20px;
    font-size: 1em;
    font-weight: 500;
}

/* File Input */
.file-input-wrapper {
    position: relative;
    margin-bottom: 20px;
}

.file-input {
    width: 100%;
    padding: 20px;
    border: 2px dashed #667eea;
    border-radius: 10px;
    background: #f8f9ff;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: center;
    color: #667eea;
    font-weight: 500;
    font-size: 1.1em;
}

.file-input:hover {
    background: #667eea;
    color: white;
    transform: translateY(-2px);
}

.file-input.dragover {
    background: #667eea;
    color: white;
    border-color: #764ba2;
}

input[type="file"] {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
    z-index: 10;
}

/* Text to BMP Input Sections */
.input-section {
    margin-bottom: 20px;
}

.input-section label {
    display: block;
    font-weight: 600;
    color: #2c3e50;
    margin-bottom: 5px;
    font-size: 0.9em;
}

.input-section textarea {
    width: 100%;
    height: 150px;
    padding: 10px;
    margin: 10px 0;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
    transition: border-color 0.3s ease;
    resize: vertical;
}

.input-section textarea:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.2);
}

#canvas-info {
    background: #e8f5e8;
    padding: 10px;
    border-radius: 5px;
    font-family: monospace;
    font-size: 0.9em;
    margin: 10px 0;
    border: 1px solid #c3e6cb;
}

/* Buttons */
.process-btn {
    width: 100%;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    border: none;
    padding: 15px;
    border-radius: 10px;
    font-size: 1.1em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-top: 15px;
}

.process-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.4);
}

.process-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.copy-btn {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 10px 16px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.9em;
    transition: all 0.3s ease;
    font-weight: 500;
}

.copy-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-1px);
}

.small-copy-btn {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 4px 8px;
    border-radius: 12px;
    cursor: pointer;
    font-size: 0.7em;
    transition: all 0.3s ease;
}

.small-copy-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Status */
.status {
    margin-top: 20px;
    padding: 15px;
    border-radius: 10px;
    font-weight: 500;
    white-space: pre-line;
    max-height: 200px;
    overflow-y: auto;
    font-size: 0.9em;
    transition: opacity 0.5s ease, transform 0.5s ease;
}

.status.success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.status.error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.status.processing {
    background: #d1ecf1;
    color: #0c5460;
    border: 1px solid #bee5eb;
}

/* Results Section */
.results-section {
    background: white;
    border-radius: 15px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.08);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.results-header {
    background: linear-gradient(135deg, #16a085, #1abc9c);
    color: white;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
}

.zoom-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.1);
    padding: 8px 12px;
    border-radius: 25px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(5px);
}

.zoom-btn {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 8px 12px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.9em;
    transition: all 0.3s ease;
    font-weight: 500;
    min-width: 40px;
    text-align: center;
}

.zoom-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.zoom-btn:active {
    transform: translateY(0);
}

#zoom-level {
    color: white;
    font-weight: 600;
    font-size: 0.95em;
    min-width: 50px;
    text-align: center;
    background: rgba(255, 255, 255, 0.1);
    padding: 6px 10px;
    border-radius: 15px;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.results-content {
    flex: 1;
    padding: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.output-area {
    flex: 1;
    height: calc(100vh - 400px);
    min-height: 400px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
    line-height: 1.4;
    padding: 20px;
    border: none;
    resize: none;
    background: #f8f9fa;
    color: #2c3e50;
    overflow-y: auto;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 400px;
    color: #6c757d;
    font-style: italic;
}

.empty-icon {
    font-size: 4em;
    margin-bottom: 20px;
    opacity: 0.5;
}

/* Four Parts Layout for Deskpro PDF */
.parts-container {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 1fr;
    gap: 15px;
    padding: 20px;
    height: calc(100vh - 400px);
    min-height: 500px;
    overflow-y: auto;
}

.part {
    background: #f8f9fa;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid #e9ecef;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.part-header {
    padding: 12px;
    font-weight: 600;
    font-size: 0.9em;
    text-align: center;
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.part-content {
    padding: 12px;
    overflow-y: auto;
    font-family: 'Courier New', monospace;
    font-size: 0.8em;
    line-height: 1.3;
    white-space: pre;
    background: white;
    flex: 1;
    min-height: 0;
}

.part-total {
    border-top: 1px solid #e9ecef;
    background: #f8f9fa;
    padding: 8px 12px;
    font-family: 'Courier New', monospace;
    font-size: 0.75em;
    overflow-y: auto;
    flex-shrink: 0;
    max-height: 120px;
}

/* Part Header Colors */
.warp-header { 
    background: linear-gradient(135deg, #e74c3c, #c0392b); 
}

.weft-header { 
    background: linear-gradient(135deg, #3498db, #2980b9); 
}

.drafting-header { 
    background: linear-gradient(135deg, #2ecc71, #27ae60); 
}

.pegplan-header { 
    background: linear-gradient(135deg, #f39c12, #e67e22); 
}

/* BMP Results Layout */
.bmp-results-container {
    display: flex;
    flex-direction: row;
    height: 100%;
    gap: 15px;
    padding: 15px;
}

.bmp-result-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #f8f9fa;
    border-radius: 10px;
    border: 1px solid #e9ecef;
    overflow: hidden;
}

.bmp-section-header {
    color: white;
    padding: 12px 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.bmp-section-header h4 {
    margin: 0;
    font-size: 0.9em;
    font-weight: 600;
}

.peg-plan-header {
    background: linear-gradient(135deg, #e74c3c, #c0392b);
}

.weft-data-header {
    background: linear-gradient(135deg, #3498db, #2980b9);
}

.bmp-output-area {
    flex: 1;
    min-height: 400px;
    font-family: 'Courier New', monospace;
    font-size: 0.8em;
    line-height: 1.3;
    padding: 12px;
    border: none;
    resize: none;
    background: white;
    color: #2c3e50;
    overflow-y: auto;
}

/* BMP Preview Container */
.bmp-preview-container {
    width: 100%;
    height: calc(100vh - 400px);
    min-height: 400px;
    overflow: auto;
    border: 1px solid #e9ecef;
    border-radius: 5px;
    background: #f8f9fa;
    padding: 20px;
    text-align: center;
    position: relative;
}

.bmp-preview-container .empty-state {
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #6c757d;
    font-style: italic;
}

.bmp-preview-container .empty-icon {
    font-size: 4em;
    margin-bottom: 20px;
    opacity: 0.5;
}

.color-legend {
    margin-top: 20px;
    font-size: 0.9em;
    color: #666;
    text-align: center;
}

/* Canvas Preview */
#bmp-preview-canvas {
    border: 1px solid #ddd;
    border-radius: 5px;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
    background: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s ease;
    transform-origin: top left;
}

/* =============================================== */
/* BMP TO DRAFT & PEGPLAN SPECIFIC STYLES */
/* =============================================== */

/* Three-column weaving results layout */
.weaving-results-container {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 20px;
    padding: 20px;
    height: calc(100vh - 400px);
    min-height: 500px;
    overflow-y: auto;
}

.weaving-section {
    background: #f8f9fa;
    border-radius: 10px;
    border: 1px solid #e9ecef;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.weaving-section-header {
    color: white;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    flex-shrink: 0;
}

.weaving-section-header h3 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
}

/* Weaving section header colors */
.design-header {
    background: linear-gradient(135deg, #9b59b6, #8e44ad);
}

.draft-header {
    background: linear-gradient(135deg, #16a085, #1abc9c);
}

/* Weaving controls and info */
.weaving-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.weaving-info {
    background: rgba(255, 255, 255, 0.1);
    padding: 6px 12px;
    border-radius: 15px;
    font-size: 0.8rem;
    border: 1px solid rgba(255, 255, 255, 0.2);
    white-space: nowrap;
}

/* Canvas container for BMP to Draft */
.weaving-canvas-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: white;
    position: relative;
    min-height: 300px;
    overflow: auto;
}

.weaving-canvas-container canvas {
    max-width: 100%;
    max-height: 100%;
    border: 1px solid #ddd;
    border-radius: 5px;
    background: white;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
}

/* Pegplan canvas should be smaller */
#bmptodraft-pegplan-canvas {
    max-width: 80%;
    height: auto;
}

/* Output area for sequence display */
.weaving-output-area {
    flex: 1;
    padding: 20px;
    background: white;
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    line-height: 1.4;
    overflow-y: auto;
    white-space: pre;
    border: none;
    resize: none;
    color: #2c3e50;
    min-height: 300px;
}

/* Loading Spinner */
.loading-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid #f3f3f3;
    border-radius: 50%;
    border-top-color: #667eea;
    animation: spin 1s ease-in-out infinite;
    margin-right: 8px;
}

@keyframes spin {
    to { 
        transform: rotate(360deg); 
    }
}

/* Responsive Design */
@media (max-width: 1400px) {
    .parts-container {
        grid-template-columns: 1fr 1fr;
    }
    
    .weaving-results-container {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 768px) {
    .header {
        padding: 30px 20px;
    }
    
    .header h1 {
        font-size: 2.2em;
    }
    
    .header-badges {
        gap: 10px;
    }
    
    .badge {
        padding: 6px 15px;
        font-size: 0.8em;
    }
    
    .converter-layout {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    .parts-container {
        grid-template-columns: 1fr;
    }
    
    .bmp-results-container {
        flex-direction: column;
    }
    
    .weaving-results-container {
        grid-template-columns: 1fr;
    }
    
    .container {
        margin: 10px;
        min-height: calc(100vh - 20px);
    }
    
    .tab-button {
        padding: 15px 10px;
        font-size: 0.9em;
    }
    
    .input-section textarea {
        font-size: 0.8em;
    }
    
    .color-legend {
        font-size: 0.8em;
    }
    
    .header-controls {
        justify-content: center;
    }
    
    .weaving-section-header {
        padding: 12px 15px;
    }
    
    .weaving-section-header h3 {
        font-size: 1rem;
    }
    
    .weaving-info {
        font-size: 0.7rem;
        padding: 4px 8px;
    }
}