/**
 * EAN Manager - Frontend Styles
 * Stylowanie zgodne z BeTheme i nowoczesne standardy UX
 */

/* ==========================================================================
   BeTheme Compatibility Variables
   ========================================================================== */

:root {
    --ean-primary-color: var(--mfn-primary-color, #667eea);
    --ean-secondary-color: var(--mfn-secondary-color, #764ba2);
    --ean-text-color: var(--mfn-text-color, #2d3748);
    --ean-border-color: var(--mfn-border-color, #dee2e6);
    --ean-background-color: var(--mfn-background-color, #ffffff);
    --ean-success-color: var(--mfn-success-color, #48bb78);
    --ean-error-color: var(--mfn-error-color, #f56565);
    --ean-font-family: var(--mfn-font-family, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif);
    --ean-border-radius: var(--mfn-border-radius, 6px);
    --ean-box-shadow: var(--mfn-box-shadow, 0 2px 4px rgba(0, 0, 0, 0.1));
}

/* ==========================================================================
   Podstawowe style dla tabel EAN - BeTheme Compatible
   ========================================================================== */

.ean-enhanced-table,
.mfn-table.ean-enhanced-table,
.column-table.ean-enhanced-table,
table.ean-enhanced-table {
    position: relative;
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1.5rem;
    font-family: var(--ean-font-family);
}

/* BeTheme compatible header styles */
.ean-enhanced-table .ean-column-header,
.mfn-table .ean-column-header,
.column-table .ean-column-header,
.mfn-builder-content .ean-column-header,
.bebuilder-content .ean-column-header,
th.ean-column-header {
    background-color: var(--mfn-table-header-bg, var(--mfn-color-theme, #f8f9fa));
    color: var(--mfn-table-header-color, var(--mfn-color-text, var(--ean-text-color)));
    font-weight: var(--mfn-font-weight-bold, 600);
    font-family: var(--mfn-font-content, var(--ean-font-family));
    text-align: center;
    padding: 12px 8px;
    border: 1px solid var(--mfn-border-color, var(--ean-border-color));
    width: 80px;
    min-width: 80px;
    transition: background-color 0.3s ease;
}

/* BeTheme compatible cell styles */
.ean-cell,
.mfn-table .ean-cell,
.column-table .ean-cell,
.mfn-builder-content .ean-cell,
.bebuilder-content .ean-cell,
td.ean-cell {
    text-align: center;
    vertical-align: middle;
    padding: 8px 4px;
    border: 1px solid var(--mfn-border-color, var(--ean-border-color));
    position: relative;
    width: 80px;
    min-width: 80px;
    background-color: var(--mfn-color-background, var(--ean-background-color));
    font-family: var(--mfn-font-content, var(--ean-font-family));
    color: var(--mfn-color-text, var(--ean-text-color));
}

/* ==========================================================================
   Przycisk rozwijania EAN
   ========================================================================== */

.ean-toggle,
.mfn-table .ean-toggle,
.column-table .ean-toggle,
.mfn-builder-content .ean-toggle,
.bebuilder-content .ean-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    background: linear-gradient(135deg, var(--ean-primary-color) 0%, var(--ean-secondary-color) 100%);
    color: white;
    border: none;
    border-radius: var(--mfn-border-radius, var(--ean-border-radius));
    padding: 6px 10px;
    font-size: var(--mfn-font-size-small, 11px);
    font-weight: var(--mfn-font-weight-medium, 500);
    font-family: var(--mfn-font-content, var(--ean-font-family));
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--mfn-box-shadow, var(--ean-box-shadow));
    min-height: 28px;
    user-select: none;
}

.ean-toggle:hover,
.ean-toggle:focus {
    background: linear-gradient(135deg, color-mix(in srgb, var(--ean-primary-color) 85%, black) 0%, color-mix(in srgb, var(--ean-secondary-color) 85%, black) 100%);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
    transform: translateY(-1px);
}

.ean-toggle:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.ean-toggle:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.3);
}

.ean-icon {
    font-size: 10px;
    transition: transform 0.3s ease;
    line-height: 1;
}

/* ==========================================================================
   Kontener z kodem EAN
   ========================================================================== */

.ean-code-container {
    margin-top: 8px;
    background: #ffffff;
    border: 1px solid #e1e5e9;
    border-radius: 8px;
    padding: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    position: relative;
}

.ean-code-container::before {
    content: '';
    position: absolute;
    top: -5px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-bottom: 5px solid #e1e5e9;
}

.ean-code-container::after {
    content: '';
    position: absolute;
    top: -4px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-bottom: 5px solid #ffffff;
}

.ean-code {
    font-family: 'Courier New', Consolas, monospace;
    font-size: 13px;
    font-weight: 600;
    color: #2d3748;
    letter-spacing: 0.5px;
    flex: 1;
}

/* ==========================================================================
   Przycisk kopiowania
   ========================================================================== */

.ean-copy {
    background: #48bb78;
    color: white;
    border: none;
    border-radius: 4px;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.ean-copy:hover {
    background: #38a169;
    transform: scale(1.1);
}

.ean-copy:active {
    transform: scale(0.95);
}

.ean-copy:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(72, 187, 120, 0.5);
}

.ean-copy-success {
    background: #38a169 !important;
    animation: copySuccess 0.6s ease;
}

@keyframes copySuccess {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); }
}

/* ==========================================================================
   Stan braku kodu EAN
   ========================================================================== */

.ean-not-available {
    color: #a0aec0;
    font-style: italic;
    font-size: 14px;
}

/* ==========================================================================
   Toast notyfikacje
   ========================================================================== */

.ean-toast {
    position: fixed;
    top: 20px;
    right: 20px;
    background: white;
    color: #2d3748;
    padding: 12px 16px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 9999;
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 300px;
    max-width: 400px;
    border-left: 4px solid;
    font-size: 14px;
    font-weight: 500;
}

.ean-toast-success {
    border-left-color: #48bb78;
}

.ean-toast-error {
    border-left-color: #f56565;
}

.ean-toast-message {
    flex: 1;
}

.ean-toast-close {
    background: none;
    border: none;
    color: #a0aec0;
    cursor: pointer;
    font-size: 18px;
    padding: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ean-toast-close:hover {
    color: #2d3748;
}

/* ==========================================================================
   Shortcode EAN
   ========================================================================== */

.ean-shortcode-container {
    display: inline-block;
    margin: 4px 0;
}

.ean-inline {
    font-family: 'Courier New', Consolas, monospace;
    font-weight: 600;
    color: #2d3748;
    background: #edf2f7;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
}

/* ==========================================================================
   Widget wyszukiwania
   ========================================================================== */

.ean-search-form {
    position: relative;
}

.ean-search-input-group {
    display: flex;
    border-radius: 6px;
    overflow: hidden;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.ean-search-field {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid #d1d5db;
    border-right: none;
    font-size: 14px;
    outline: none;
    background: white;
}

.ean-search-field:focus {
    border-color: #667eea;
    box-shadow: inset 0 0 0 1px #667eea;
}

.ean-search-submit {
    background: #667eea;
    color: white;
    border: none;
    padding: 10px 16px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.2s ease;
}

.ean-search-submit:hover {
    background: #5a6fd8;
}

/* Sugestie wyszukiwania */
.ean-search-suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid #d1d5db;
    border-top: none;
    border-radius: 0 0 6px 6px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    max-height: 200px;
    overflow-y: auto;
}

.ean-search-suggestion {
    padding: 8px 12px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.2s ease;
}

.ean-search-suggestion:hover {
    background: #f7fafc;
}

.suggestion-label {
    flex: 1;
    font-size: 14px;
}

.suggestion-type {
    font-size: 11px;
    color: #667eea;
    background: #edf2f7;
    padding: 2px 6px;
    border-radius: 3px;
    font-weight: 500;
    text-transform: uppercase;
}

/* ==========================================================================
   Podświetlanie wyników wyszukiwania
   ========================================================================== */

.ean-search-highlight {
    background: #fef5e7;
    color: #d69e2e;
    padding: 1px 3px;
    border-radius: 3px;
    font-weight: 600;
}

/* ==========================================================================
   BeBuilder Specific Enhancements
   ========================================================================== */

/* BeBuilder table wrapper */
.mfn-builder-content .ean-enhanced-table,
.bebuilder-content .ean-enhanced-table {
    width: 100%;
    max-width: none;
    margin: 0 0 1.5rem 0;
}

/* BeBuilder responsive container */
.mfn-builder-content .ean-table-responsive,
.bebuilder-content .ean-table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--mfn-border-radius, 6px);
}

/* BeBuilder specific table classes */
.bebuilder-ean-table.betheme-ean-compatible {
    border: 1px solid var(--mfn-border-color, #dee2e6);
    border-radius: var(--mfn-border-radius, 6px);
    overflow: hidden;
}

/* ==========================================================================
   Responsywność
   ========================================================================== */

.ean-table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 1rem;
}

@media (max-width: 768px) {
    .ean-enhanced-table .ean-column-header,
    .mfn-table .ean-column-header,
    .mfn-builder-content .ean-column-header,
    .ean-cell,
    .mfn-table .ean-cell,
    .mfn-builder-content .ean-cell {
        width: 60px;
        min-width: 60px;
        padding: 6px 2px;
    }
    
    .ean-toggle,
    .mfn-table .ean-toggle,
    .mfn-builder-content .ean-toggle {
        font-size: 10px;
        padding: 4px 6px;
        min-height: 24px;
    }
    
    .ean-code-container {
        padding: 8px;
        font-size: 11px;
    }
    
    .ean-code {
        font-size: 11px;
    }
    
    .ean-copy {
        width: 20px;
        height: 20px;
        font-size: 10px;
    }
    
    .ean-toast {
        right: 10px;
        left: 10px;
        min-width: auto;
        max-width: none;
    }
}

@media (max-width: 480px) {
    .ean-enhanced-table .ean-column-header,
    .ean-cell {
        width: 50px;
        min-width: 50px;
    }
    
    .ean-toggle {
        font-size: 9px;
        padding: 3px 5px;
    }
    
    .ean-code-container {
        flex-direction: column;
        align-items: stretch;
        gap: 6px;
    }
    
    .ean-copy {
        align-self: center;
    }
}

/* ==========================================================================
   Dark mode support
   ========================================================================== */

@media (prefers-color-scheme: dark) {
    .ean-enhanced-table .ean-column-header {
        background-color: #2d3748;
        color: #e2e8f0;
        border-color: #4a5568;
    }
    
    .ean-cell {
        border-color: #4a5568;
    }
    
    .ean-code-container {
        background: #2d3748;
        border-color: #4a5568;
        color: #e2e8f0;
    }
    
    .ean-code-container::before {
        border-bottom-color: #4a5568;
    }
    
    .ean-code-container::after {
        border-bottom-color: #2d3748;
    }
    
    .ean-code {
        color: #e2e8f0;
    }
    
    .ean-toast {
        background: #2d3748;
        color: #e2e8f0;
    }
    
    .ean-search-field {
        background: #2d3748;
        color: #e2e8f0;
        border-color: #4a5568;
    }
    
    .ean-search-suggestions {
        background: #2d3748;
        border-color: #4a5568;
    }
    
    .ean-search-suggestion:hover {
        background: #4a5568;
    }
}

/* ==========================================================================
   Accessibility
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
    .ean-toggle,
    .ean-copy,
    .ean-icon,
    .ean-code-container {
        transition: none;
        animation: none;
    }
}

/* Focus indicators */
.ean-toggle:focus-visible,
.ean-copy:focus-visible {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .ean-toggle {
        background: #000000;
        border: 2px solid #ffffff;
    }
    
    .ean-copy {
        background: #000000;
        border: 1px solid #ffffff;
    }
    
    .ean-code-container {
        border: 2px solid #000000;
    }
}

/* ==========================================================================
   Print styles
   ========================================================================== */

@media print {
    .ean-toggle {
        display: none;
    }
    
    .ean-code-container {
        display: block !important;
        box-shadow: none;
        border: 1px solid #000;
    }
    
    .ean-copy {
        display: none;
    }
    
    .ean-code {
        color: #000;
    }
    
    .ean-toast {
        display: none;
    }
}