/* ============================================
   Base64 Encode/Decode - Modern UI
   Public Access Version with Fixed Containers
   ============================================ */

/* CSS Variables for theming */
:root {
    --b64-primary: #6366f1;
    --b64-primary-dark: #4f46e5;
    --b64-secondary: #ec4899;
    --b64-success: #10b981;
    --b64-warning: #f59e0b;
    --b64-error: #ef4444;
    --b64-bg: #ffffff;
    --b64-surface: #f8fafc;
    --b64-surface-hover: #f1f5f9;
    --b64-text: #0f172a;
    --b64-text-secondary: #64748b;
    --b64-border: #e2e8f0;
    --b64-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --b64-shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    --b64-radius: 12px;
    --b64-radius-sm: 8px;
    --b64-transition: all 0.3s ease;
}

/* Dark mode variables */
[data-theme="dark"] {
    --b64-bg: #0f172a;
    --b64-surface: #1e293b;
    --b64-surface-hover: #334155;
    --b64-text: #f8fafc;
    --b64-text-secondary: #94a3b8;
    --b64-border: #334155;
    --b64-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.5), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
    --b64-shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.5), 0 10px 10px -5px rgba(0, 0, 0, 0.3);
}

/* Container */
.base64-converter-wrap {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    color: var(--b64-text);
    background: var(--b64-bg);
    line-height: 1.6;
    position: relative;
}

/* Theme Toggle */
.b64-theme-toggle {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: var(--b64-surface);
    border: 1px solid var(--b64-border);
    border-radius: 50px;
    padding: 0.5rem 1rem;
    cursor: pointer;
    transition: var(--b64-transition);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--b64-text-secondary);
    z-index: 10;
}

.b64-theme-toggle:hover {
    background: var(--b64-surface-hover);
    transform: translateY(-1px);
}

.b64-theme-toggle .toggle-icon {
    width: 18px;
    height: 18px;
}

/* Header Section */
.b64-header {
    text-align: center;
    margin-bottom: 3rem;
    padding-top: 1rem;
}

.b64-header h2 {
    font-size: 2.5rem;
    font-weight: 800;
    margin-bottom: 1rem;
    background: linear-gradient(135deg, var(--b64-primary) 0%, var(--b64-secondary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.b64-header p {
    font-size: 1.125rem;
    color: var(--b64-text-secondary);
    max-width: 600px;
    margin: 0 auto;
}

/* Main Card */
.b64-card {
    background: var(--b64-surface);
    border-radius: var(--b64-radius);
    box-shadow: var(--b64-shadow-lg);
    padding: 2.5rem;
    margin-bottom: 3rem;
    border: 1px solid var(--b64-border);
}

/* Tabs */
.b64-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid var(--b64-border);
    padding-bottom: 0;
    overflow-x: auto;
}

.b64-tab {
    padding: 0.75rem 1.5rem;
    background: none;
    border: none;
    color: var(--b64-text-secondary);
    font-weight: 600;
    cursor: pointer;
    position: relative;
    transition: var(--b64-transition);
    white-space: nowrap;
}

.b64-tab:hover {
    color: var(--b64-primary);
}

.b64-tab.active {
    color: var(--b64-primary);
}

.b64-tab.active::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--b64-primary);
}

/* Tab Content - CRITICAL: Must be properly displayed */
.b64-tab-content {
    display: none;
}

.b64-tab-content.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Form Elements */
.b64-form-group {
    margin-bottom: 1.5rem;
}

.b64-label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--b64-text);
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.b64-textarea {
    width: 100%;
    min-height: 200px;
    padding: 1rem;
    font-size: 1rem;
    border: 2px solid var(--b64-border);
    border-radius: var(--b64-radius-sm);
    background: var(--b64-bg);
    color: var(--b64-text);
    transition: var(--b64-transition);
    box-sizing: border-box;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    resize: vertical;
    line-height: 1.6;
}

.b64-textarea:focus {
    outline: none;
    border-color: var(--b64-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

/* Action Toggle */
.b64-action-group {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.b64-action-btn {
    flex: 1;
    min-width: 140px;
    padding: 1rem;
    background: var(--b64-bg);
    border: 2px solid var(--b64-border);
    border-radius: var(--b64-radius-sm);
    cursor: pointer;
    transition: var(--b64-transition);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    color: var(--b64-text-secondary);
}

.b64-action-btn:hover {
    border-color: var(--b64-primary);
    color: var(--b64-primary);
}

.b64-action-btn.active {
    background: linear-gradient(135deg, var(--b64-primary) 0%, var(--b64-primary-dark) 100%);
    border-color: var(--b64-primary);
    color: white;
    box-shadow: 0 4px 6px -1px rgba(99, 102, 241, 0.2);
}

.b64-action-icon {
    width: 24px;
    height: 24px;
}

/* Options Grid */
.b64-options-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.b64-option-card {
    background: var(--b64-bg);
    border: 2px solid var(--b64-border);
    border-radius: var(--b64-radius-sm);
    padding: 1.5rem;
    transition: var(--b64-transition);
}

.b64-option-card:hover {
    border-color: var(--b64-primary);
}

.b64-option-title {
    font-weight: 700;
    margin-bottom: 0.75rem;
    color: var(--b64-text);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* File Upload */
.b64-file-drop {
    border: 2px dashed var(--b64-border);
    border-radius: var(--b64-radius-sm);
    padding: 2rem;
    text-align: center;
    transition: var(--b64-transition);
    cursor: pointer;
    background: var(--b64-bg);
}

.b64-file-drop:hover,
.b64-file-drop.dragover {
    border-color: var(--b64-primary);
    background: rgba(99, 102, 241, 0.05);
}

.b64-file-drop-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto 1rem;
    color: var(--b64-primary);
}

.b64-file-drop-text {
    color: var(--b64-text-secondary);
    margin-bottom: 0.5rem;
}

.b64-file-drop-hint {
    font-size: 0.875rem;
    color: var(--b64-text-secondary);
}

.b64-file-input {
    display: none;
}

.b64-file-info {
    display: none;
    padding: 1rem;
    background: var(--b64-surface-hover);
    border-radius: var(--b64-radius-sm);
    margin-top: 1rem;
    align-items: center;
    gap: 0.75rem;
}

.b64-file-info.active {
    display: flex;
}

.b64-file-remove {
    margin-left: auto;
    color: var(--b64-error);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
}

.b64-file-remove:hover {
    text-decoration: underline;
}

/* Buttons */
.b64-btn {
    padding: 0.875rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    border: none;
    border-radius: var(--b64-radius-sm);
    cursor: pointer;
    transition: var(--b64-transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    text-decoration: none;
}

.b64-btn-primary {
    background: linear-gradient(135deg, var(--b64-primary) 0%, var(--b64-primary-dark) 100%);
    color: white;
    box-shadow: 0 4px 6px -1px rgba(99, 102, 241, 0.2);
}

.b64-btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(99, 102, 241, 0.3);
}

.b64-btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.b64-btn-secondary {
    background: var(--b64-surface-hover);
    color: var(--b64-text);
    border: 1px solid var(--b64-border);
}

.b64-btn-secondary:hover {
    background: var(--b64-border);
}

.b64-btn-success {
    background: var(--b64-success);
    color: white;
}

.b64-btn-group {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    margin-top: 1.5rem;
}

/* Loading Animation */
.b64-loading {
    display: none;
    text-align: center;
    padding: 3rem;
}

.b64-loading.active {
    display: block;
}

.b64-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--b64-border);
    border-top-color: var(--b64-primary);
    border-radius: 50%;
    animation: b64-spin 1s linear infinite;
    margin: 0 auto 1rem;
}

@keyframes b64-spin {
    to { transform: rotate(360deg); }
}

/* Results Section - CRITICAL: Must display properly */
.b64-results {
    display: none;
    margin-top: 2rem;
    animation: b64-fade-in 0.5s ease;
}

.b64-results.active {
    display: block !important;
}

@keyframes b64-fade-in {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Output Display - CRITICAL IDs for JS */
.b64-output-container {
    position: relative;
    background: #1e1e1e;
    border-radius: var(--b64-radius-sm);
    padding: 1.5rem;
    margin-top: 1.5rem;
    border: 1px solid #333;
}

.b64-output {
    width: 100%;
    min-height: 150px;
    background: transparent;
    border: none;
    color: #d4d4d4;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.875rem;
    line-height: 1.6;
    resize: vertical;
    outline: none;
}

.b64-output-stats {
    display: flex;
    gap: 1.5rem;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid #333;
    font-size: 0.875rem;
    color: #888;
    flex-wrap: wrap;
}

.b64-stat {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Copy Button */
.b64-copy-btn {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #fff;
    padding: 0.5rem 1rem;
    border-radius: var(--b64-radius-sm);
    cursor: pointer;
    font-size: 0.875rem;
    transition: var(--b64-transition);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    z-index: 5;
}

.b64-copy-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.b64-copy-btn.copied {
    background: var(--b64-success);
    border-color: var(--b64-success);
}

/* Export Grid */
.b64-export-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
}

.b64-export-card {
    background: var(--b64-bg);
    border: 2px solid var(--b64-border);
    border-radius: var(--b64-radius-sm);
    padding: 2rem;
    text-align: center;
    transition: var(--b64-transition);
    cursor: pointer;
}

.b64-export-card:hover {
    border-color: var(--b64-primary);
    transform: translateY(-4px);
    box-shadow: var(--b64-shadow);
}

.b64-export-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto 1rem;
    background: linear-gradient(135deg, var(--b64-primary) 0%, var(--b64-secondary) 100%);
    border-radius: var(--b64-radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.5rem;
}

.b64-export-title {
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: var(--b64-text);
}

.b64-export-desc {
    font-size: 0.875rem;
    color: var(--b64-text-secondary);
    margin-bottom: 1.5rem;
}

/* Error Message */
.b64-error {
    display: none;
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #991b1b;
    padding: 1rem 1.5rem;
    border-radius: var(--b64-radius-sm);
    margin-top: 1rem;
    align-items: center;
    gap: 0.75rem;
}

[data-theme="dark"] .b64-error {
    background: #450a0a;
    border-color: #7f1d1d;
    color: #fecaca;
}

.b64-error.active {
    display: flex;
}

/* Success Message */
.b64-success-msg {
    display: none;
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    color: #166534;
    padding: 1rem 1.5rem;
    border-radius: var(--b64-radius-sm);
    margin-top: 1rem;
}

[data-theme="dark"] .b64-success-msg {
    background: #052e16;
    border-color: #166534;
    color: #bbf7d0;
}

.b64-success-msg.active {
    display: block;
}

/* Helper Text */
.b64-helper {
    font-size: 0.875rem;
    color: var(--b64-text-secondary);
    margin-top: 0.5rem;
}

/* Character Counter */
.b64-counter {
    text-align: right;
    font-size: 0.875rem;
    color: var(--b64-text-secondary);
    margin-top: 0.5rem;
}

/* SEO Content Section */
.b64-seo-content {
    margin-top: 4rem;
    padding-top: 3rem;
    border-top: 2px solid var(--b64-border);
}

.b64-seo-content h1 {
    font-size: 2.25rem;
    font-weight: 800;
    margin-bottom: 1.5rem;
    color: var(--b64-text);
    line-height: 1.2;
}

.b64-seo-content h2 {
    font-size: 1.75rem;
    font-weight: 700;
    margin-top: 2.5rem;
    margin-bottom: 1rem;
    color: var(--b64-text);
}

.b64-seo-content h3 {
    font-size: 1.375rem;
    font-weight: 600;
    margin-top: 2rem;
    margin-bottom: 0.75rem;
    color: var(--b64-text);
}

.b64-seo-content p {
    margin-bottom: 1.25rem;
    color: var(--b64-text-secondary);
    line-height: 1.8;
}

.b64-seo-content ul,
.b64-seo-content ol {
    margin-bottom: 1.5rem;
    padding-left: 1.5rem;
}

.b64-seo-content li {
    margin-bottom: 0.75rem;
    color: var(--b64-text-secondary);
}

.b64-seo-content strong {
    color: var(--b64-text);
    font-weight: 600;
}

.b64-seo-content a {
    color: var(--b64-primary);
    text-decoration: none;
    font-weight: 500;
    border-bottom: 1px solid transparent;
    transition: var(--b64-transition);
}

.b64-seo-content a:hover {
    border-bottom-color: var(--b64-primary);
}

.b64-seo-content code {
    background: var(--b64-surface-hover);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.9em;
    color: var(--b64-primary);
}

/* FAQ Section */
.b64-faq {
    margin-top: 2rem;
}

.b64-faq-item {
    background: var(--b64-surface);
    border: 1px solid var(--b64-border);
    border-radius: var(--b64-radius-sm);
    margin-bottom: 1rem;
    overflow: hidden;
}

.b64-faq-question {
    padding: 1.25rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: var(--b64-transition);
    color: var(--b64-text);
}

.b64-faq-question:hover {
    background: var(--b64-surface-hover);
}

.b64-faq-answer {
    padding: 0 1.25rem;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease;
    color: var(--b64-text-secondary);
}

.b64-faq-item.active .b64-faq-answer {
    padding: 0 1.25rem 1.25rem;
    max-height: 500px;
}

.b64-faq-icon {
    transition: transform 0.3s ease;
    color: var(--b64-primary);
}

.b64-faq-item.active .b64-faq-icon {
    transform: rotate(180deg);
}

/* Breadcrumb */
.b64-breadcrumb {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 2rem;
    font-size: 0.875rem;
    color: var(--b64-text-secondary);
    flex-wrap: wrap;
}

.b64-breadcrumb a {
    color: var(--b64-primary);
    text-decoration: none;
}

.b64-breadcrumb a:hover {
    text-decoration: underline;
}

/* Responsive */
@media (max-width: 768px) {
    .base64-converter-wrap {
        padding: 1rem;
    }
    
    .b64-header h2 {
        font-size: 1.875rem;
    }
    
    .b64-card {
        padding: 1.5rem;
    }
    
    .b64-tabs {
        overflow-x: auto;
        flex-wrap: nowrap;
    }
    
    .b64-action-group {
        flex-direction: column;
    }
    
    .b64-action-btn {
        width: 100%;
    }
    
    .b64-btn-group {
        flex-direction: column;
    }
    
    .b64-btn {
        width: 100%;
    }
    
    .b64-output-container {
        padding: 1rem;
    }
    
    .b64-copy-btn {
        position: static;
        margin-bottom: 1rem;
        width: 100%;
        justify-content: center;
    }
    
    .b64-output-stats {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .b64-seo-content h1 {
        font-size: 1.75rem;
    }
    
    .b64-seo-content h2 {
        font-size: 1.375rem;
    }
}

/* Print styles */
@media print {
    .b64-theme-toggle,
    .b64-tabs,
    .b64-input-section,
    .b64-btn-group,
    .b64-copy-btn {
        display: none !important;
    }
    
    .b64-results {
        display: block !important;
    }
    
    .b64-tab-content {
        display: block !important;
    }
    
    .b64-output {
        white-space: pre-wrap;
        word-wrap: break-word;
        color: #000;
        background: #fff;
        min-height: auto;
    }
    
    .b64-output-container {
        background: #fff;
        border: 1px solid #ccc;
    }
}

/* Selection styling */
::selection {
    background: var(--b64-primary);
    color: white;
}

/* Scrollbar styling */
.b64-textarea::-webkit-scrollbar,
.b64-output::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.b64-textarea::-webkit-scrollbar-track,
.b64-output::-webkit-scrollbar-track {
    background: transparent;
}

.b64-textarea::-webkit-scrollbar-thumb,
.b64-output::-webkit-scrollbar-thumb {
    background: var(--b64-border);
    border-radius: 4px;
}

.b64-textarea::-webkit-scrollbar-thumb:hover,
.b64-output::-webkit-scrollbar-thumb:hover {
    background: var(--b64-text-secondary);
}

/* Ensure visibility helpers */
.b64-is-visible {
    display: block !important;
}

.b64-is-hidden {
    display: none !important;
}