* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #64748b;
    --success-color: #16a34a;
    --success-hover: #15803d;
    --error-color: #dc2626;
    --background: #f8fafc;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 2rem 1rem;
    color: var(--text-primary);
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    background: var(--surface);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

header {
    background: linear-gradient(135deg, var(--primary-color) 0%, #1e40af 100%);
    color: white;
    padding: 2rem;
    text-align: center;
}

header h1 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    font-weight: 700;
}

header p {
    opacity: 0.9;
    font-size: 1rem;
}

main {
    padding: 2rem;
}

.search-section {
    margin-bottom: 2rem;
}

textarea {
    width: 100%;
    padding: 1rem;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    font-family: 'Courier New', monospace;
    resize: vertical;
    transition: border-color 0.2s;
    margin-bottom: 1rem;
}

textarea:focus {
    outline: none;
    border-color: var(--primary-color);
}

.button-group {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.2s;
    box-shadow: var(--shadow);
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn:active {
    transform: translateY(0);
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-secondary {
    background: var(--secondary-color);
    color: white;
}

.btn-secondary:hover {
    background: #475569;
}

.btn-success {
    background: var(--success-color);
    color: white;
}

.btn-success:hover {
    background: var(--success-hover);
}

.btn-info {
    background: #0ea5e9;
    color: white;
}

.btn-info:hover {
    background: #0284c7;
}

.btn-icon {
    font-size: 1.2rem;
}

.loading {
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
}

.spinner {
    border: 4px solid var(--border);
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.result-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.result-header h2 {
    color: var(--text-primary);
    font-size: 1.5rem;
}

.export-buttons {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

#resultCount {
    color: var(--primary-color);
    font-weight: 700;
}

.table-container {
    overflow-x: auto;
    border-radius: 8px;
    border: 1px solid var(--border);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
}

thead {
    background: var(--background);
}

th {
    padding: 1rem;
    text-align: left;
    font-weight: 600;
    color: var(--text-primary);
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}

td {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
}

tbody tr:hover {
    background: var(--background);
}

tbody tr:last-child td {
    border-bottom: none;
}

.product-image {
    width: 60px;
    height: 60px;
    object-fit: contain;
    border-radius: 4px;
    border: 1px solid var(--border);
    background: white;
    cursor: pointer;
    transition: transform 0.2s;
}

.product-image:hover {
    transform: scale(1.5);
    z-index: 10;
    box-shadow: var(--shadow-lg);
}

.no-image {
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-secondary);
    font-size: 0.75rem;
    text-align: center;
}

.status-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 600;
}

.status-success {
    background: #dcfce7;
    color: #166534;
}

.status-error {
    background: #fee2e2;
    color: #991b1b;
}

.error-message {
    background: #fee2e2;
    color: #991b1b;
    padding: 1rem;
    border-radius: 8px;
    border-left: 4px solid var(--error-color);
    margin-top: 1rem;
}

footer {
    background: var(--background);
    padding: 1.5rem;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* ========== TOGGLE FONTE ========== */
.toggle-fonte-btn {
    cursor: pointer;
    font-size: 1.2rem;
    margin-left: 0.5rem;
    opacity: 0.7;
    transition: opacity 0.2s, transform 0.2s;
    display: inline-block;
    user-select: none;
}

.toggle-fonte-btn:hover {
    opacity: 1;
    transform: scale(1.1);
}

/* Tabs */
.tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 2rem;
    border-bottom: 2px solid var(--border);
}

.tab-btn {
    padding: 1rem 1.5rem;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border-bottom: 3px solid transparent;
    transition: all 0.2s;
}

.tab-btn:hover {
    color: var(--primary-color);
}

.tab-btn.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

.tab-icon {
    font-size: 1.2rem;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* File Upload */
.file-upload-area {
    margin-bottom: 1rem;
}

.drop-zone {
    border: 3px dashed var(--border);
    border-radius: 12px;
    padding: 3rem 2rem;
    text-align: center;
    transition: all 0.3s;
    cursor: pointer;
    background: var(--background);
}

.drop-zone:hover,
.drop-zone.drag-over {
    border-color: var(--primary-color);
    background: #eff6ff;
}

.drop-zone-content {
    pointer-events: none;
}

.drop-zone-icon {
    font-size: 4rem;
    display: block;
    margin-bottom: 1rem;
}

.drop-zone h3 {
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.drop-zone p {
    color: var(--text-secondary);
    margin: 0.5rem 0;
}

.file-info {
    font-size: 0.85rem;
    margin-top: 1rem !important;
}

.selected-file {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background: var(--background);
    border-radius: 8px;
    border: 2px solid var(--success-color);
    margin-top: 1rem;
}

.file-icon {
    font-size: 2rem;
}

.file-name {
    flex: 1;
    font-weight: 600;
    color: var(--text-primary);
}

.btn-remove {
    width: 32px;
    height: 32px;
    border: none;
    background: var(--error-color);
    color: white;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.btn-remove:hover {
    background: #b91c1c;
    transform: rotate(90deg);
}

/* NF-e Info Card */
.nfe-info-card {
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 2rem;
    border-left: 4px solid var(--primary-color);
}

.nfe-info-card h3 {
    color: var(--text-primary);
    margin-bottom: 1rem;
    font-size: 1.2rem;
}

.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.info-item {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.info-item label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 600;
}

.info-item span {
    font-size: 1rem;
    color: var(--text-primary);
    font-weight: 500;
}

@media (max-width: 768px) {
    body {
        padding: 1rem 0.5rem;
    }

    header h1 {
        font-size: 1.5rem;
    }

    main {
        padding: 1rem;
    }

    .tabs {
        overflow-x: auto;
    }

    .tab-btn {
        white-space: nowrap;
    }

    .result-header {
        flex-direction: column;
        align-items: stretch;
    }

    .button-group {
        flex-direction: column;
    }

    .btn {
        width: 100%;
        justify-content: center;
    }

    table {
        font-size: 0.85rem;
    }

    th, td {
        padding: 0.75rem 0.5rem;
    }

    .drop-zone {
        padding: 2rem 1rem;
    }

    .drop-zone-icon {
        font-size: 3rem;
    }

    .info-grid {
        grid-template-columns: 1fr;
    }
}
