/* ============================================================
   Buscador de Produtos NFe — Design System
   Dark mode premium com glassmorphism
   ============================================================ */

/* Reset & Base */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #0a0e1a;
    --bg-secondary: #111827;
    --bg-card: rgba(17, 24, 39, 0.7);
    --bg-card-hover: rgba(30, 41, 59, 0.8);
    --bg-input: rgba(15, 23, 42, 0.9);
    --border: rgba(99, 102, 241, 0.15);
    --border-hover: rgba(99, 102, 241, 0.35);
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent: #6366f1;
    --accent-light: #818cf8;
    --accent-glow: rgba(99, 102, 241, 0.25);
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --xml-color: #06b6d4;
    --product-color: #8b5cf6;
    --supplier-color: #f97316;
    --download-color: #10b981;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.4);
    --transition: 0.2s ease;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}

/* Subtle animated gradient background */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background:
        radial-gradient(ellipse 80% 60% at 20% 10%, rgba(99, 102, 241, 0.08), transparent),
        radial-gradient(ellipse 60% 50% at 80% 80%, rgba(139, 92, 246, 0.06), transparent);
    pointer-events: none;
    z-index: 0;
}

/* ============================================================
   Header
   ============================================================ */

.header {
    position: relative;
    z-index: 10;
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(20px);
    background: rgba(10, 14, 26, 0.85);
}

.header-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 16px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo {
    display: flex;
    align-items: center;
    gap: 14px;
}

.logo-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius);
    background: linear-gradient(135deg, var(--accent), var(--product-color));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.3);
}

.logo h1 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.logo-subtitle {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 400;
}

.btn-reindex {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-reindex:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-hover);
    color: var(--text-primary);
}

.btn-reindex.loading svg {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ============================================================
   Stats
   ============================================================ */

.stats-section {
    position: relative;
    z-index: 10;
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px 24px 0;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}

.stat-card {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 18px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    backdrop-filter: blur(12px);
    transition: all var(--transition);
}

.stat-card:hover {
    border-color: var(--border-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.stat-icon {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.xml-icon {
    background: rgba(6, 182, 212, 0.12);
    color: var(--xml-color);
}

.product-icon {
    background: rgba(139, 92, 246, 0.12);
    color: var(--product-color);
}

.supplier-icon {
    background: rgba(249, 115, 22, 0.12);
    color: var(--supplier-color);
}

.stat-info {
    display: flex;
    flex-direction: column;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.2;
}

.stat-label {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-weight: 400;
}

/* ============================================================
   Search
   ============================================================ */

.search-section {
    position: relative;
    z-index: 10;
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px;
}

.search-wrapper {
    position: relative;
}

.search-icon {
    position: absolute;
    left: 20px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    z-index: 2;
    pointer-events: none;
}

.search-input {
    width: 100%;
    padding: 18px 20px 18px 56px;
    background: var(--bg-input);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 1.05rem;
    font-weight: 400;
    outline: none;
    transition: all var(--transition);
}

.search-input::placeholder {
    color: var(--text-muted);
}

.search-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-glow);
}

.search-hint {
    margin-top: 10px;
    text-align: center;
    font-size: 0.78rem;
    color: var(--text-muted);
}

.hint-kbd {
    display: inline-block;
    padding: 2px 8px;
    background: rgba(99, 102, 241, 0.1);
    border: 1px solid rgba(99, 102, 241, 0.2);
    border-radius: 4px;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--accent-light);
    letter-spacing: 0.03em;
}

/* ============================================================
   Results
   ============================================================ */

.results-section {
    position: relative;
    z-index: 10;
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 24px 40px;
}

/* Empty / No results / Loading states */
.empty-state,
.no-results,
.loading-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-state svg,
.no-results svg {
    opacity: 0.3;
    margin-bottom: 16px;
}

.empty-state h3,
.no-results h3 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.empty-state p,
.no-results p {
    font-size: 0.9rem;
    max-width: 400px;
    margin: 0 auto;
}

/* Spinner */
.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 16px;
}

/* Results header */
.results-header {
    margin-bottom: 16px;
}

.results-header h2 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-secondary);
}

/* Table */
.table-wrapper {
    overflow-x: auto;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg-card);
    backdrop-filter: blur(12px);
}

.results-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

.results-table thead {
    background: rgba(99, 102, 241, 0.06);
}

.results-table th {
    padding: 14px 16px;
    text-align: left;
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.results-table td {
    padding: 14px 16px;
    border-bottom: 1px solid rgba(99, 102, 241, 0.06);
    vertical-align: middle;
}

.results-table tbody tr {
    transition: background var(--transition);
}

.results-table tbody tr:hover {
    background: rgba(99, 102, 241, 0.04);
}

.results-table tbody tr:last-child td {
    border-bottom: none;
}

/* Product name cell */
.product-name {
    font-weight: 500;
    color: var(--text-primary);
    max-width: 300px;
}

.product-code {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 2px;
}

/* EAN cell */
.ean-value {
    font-family: 'SF Mono', 'Cascadia Code', Consolas, monospace;
    font-size: 0.85rem;
    color: var(--accent-light);
    font-weight: 500;
}

.ean-empty {
    color: var(--text-muted);
    font-style: italic;
    font-size: 0.8rem;
}

/* XML file cell */
.xml-cell {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: nowrap;
}

.xml-filename {
    font-family: 'SF Mono', 'Cascadia Code', Consolas, monospace;
    font-size: 0.78rem;
    color: var(--xml-color);
    font-weight: 500;
    word-break: break-all;
    max-width: 280px;
}

.btn-download {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 12px;
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.25);
    border-radius: 6px;
    color: var(--download-color);
    font-family: inherit;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
    text-decoration: none;
}

.btn-download:hover {
    background: rgba(16, 185, 129, 0.2);
    border-color: rgba(16, 185, 129, 0.4);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.15);
}

/* Supplier cell */
.supplier-name {
    font-weight: 500;
    color: var(--text-primary);
}

.supplier-fantasy {
    display: block;
    font-size: 0.75rem;
    color: var(--supplier-color);
    margin-top: 2px;
}

/* Nota cell */
.nota-info {
    white-space: nowrap;
}

.nota-numero {
    font-weight: 500;
}

.nota-data {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 2px;
}

/* Highlight */
.highlight {
    background: rgba(250, 204, 21, 0.2);
    color: #fbbf24;
    padding: 1px 3px;
    border-radius: 3px;
    font-weight: 600;
}

/* ============================================================
   Toast notification
   ============================================================ */

.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    padding: 14px 24px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.9rem;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    opacity: 0;
    transition: all 0.3s ease;
    pointer-events: none;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.toast.success {
    border-color: rgba(16, 185, 129, 0.3);
}

.toast.error {
    border-color: rgba(239, 68, 68, 0.3);
}

/* ============================================================
   Animations
   ============================================================ */

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(12px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.results-container {
    animation: fadeInUp 0.3s ease;
}

.stat-card {
    animation: fadeInUp 0.4s ease backwards;
}

.stat-card:nth-child(1) {
    animation-delay: 0.05s;
}

.stat-card:nth-child(2) {
    animation-delay: 0.1s;
}

.stat-card:nth-child(3) {
    animation-delay: 0.15s;
}

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 768px) {
    .header-content {
        flex-direction: column;
        gap: 12px;
        text-align: center;
    }

    .logo {
        justify-content: center;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .search-input {
        font-size: 1rem;
        padding: 16px 16px 16px 50px;
    }

    .results-table {
        font-size: 0.82rem;
    }

    .results-table th,
    .results-table td {
        padding: 10px 12px;
    }

    .xml-filename {
        max-width: 150px;
    }

    .xml-cell {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
    }
}

/* ============================================================
   Marcados (Bookmarks) UI
   ============================================================ */

/* Botão no Header */
.btn-bookmarks {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: rgba(245, 158, 11, 0.1);
    /* Laranja suave */
    color: var(--warning);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-bookmarks:hover {
    background: rgba(245, 158, 11, 0.15);
    border-color: rgba(245, 158, 11, 0.3);
    transform: translateY(-1px);
}

.bookmarks-badge {
    background: var(--warning);
    color: #fff;
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 10px;
    min-width: 20px;
    text-align: center;
}

/* Offcanvas */
.offcanvas-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 1040;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.offcanvas-overlay.show {
    opacity: 1;
    visibility: visible;
}

.offcanvas {
    position: fixed;
    top: 0;
    right: -400px;
    width: 400px;
    max-width: 100%;
    height: 100%;
    background: var(--bg-primary);
    border-left: 1px solid var(--border);
    box-shadow: -5px 0 25px rgba(0, 0, 0, 0.5);
    z-index: 1050;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
}

.offcanvas.show {
    transform: translateX(-100%);
}

.offcanvas-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    background: rgba(10, 14, 26, 0.95);
}

.offcanvas-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.btn-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: all var(--transition);
}

.btn-close:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.1);
}

.offcanvas-actions {
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    background: rgba(99, 102, 241, 0.05);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.offcanvas-actions p {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.btn-download-all {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 10px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-download-all:hover {
    background: var(--accent-light);
}

.offcanvas-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
}

.empty-bookmarks {
    text-align: center;
    padding: 40px 0;
    color: var(--text-muted);
}

.empty-bookmarks svg {
    opacity: 0.3;
    margin-bottom: 16px;
}

.empty-bookmarks p {
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.empty-bookmarks .hint {
    font-size: 0.8rem;
}

.bookmarks-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Bookmark Item (Sidebar) */
.bookmark-item {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px;
    transition: all var(--transition);
}

.bookmark-item:hover {
    border-color: var(--border-hover);
}

.bookmark-title {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-primary);
    margin-bottom: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.bookmark-ean {
    font-family: 'SF Mono', 'Cascadia Code', Consolas, monospace;
    font-size: 0.75rem;
    color: var(--accent-light);
    margin-bottom: 8px;
    display: block;
}

.bookmark-xml {
    font-size: 0.75rem;
    color: var(--text-muted);
    word-break: break-all;
    margin-bottom: 12px;
    display: block;
}

.bookmark-actions {
    display: flex;
    gap: 8px;
}

.btn-bookmark-remove {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 6px;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.2);
    border-radius: 4px;
    color: var(--danger);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-bookmark-remove:hover {
    background: rgba(239, 68, 68, 0.2);
}

.btn-bookmark-dl {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 6px;
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.2);
    border-radius: 4px;
    color: var(--download-color);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
}

.btn-bookmark-dl:hover {
    background: rgba(16, 185, 129, 0.2);
}

/* Tabela de Resultados: Botão de Marcar (Estrela) */
.btn-star {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}

.btn-star:hover {
    color: var(--warning);
    background: rgba(245, 158, 11, 0.1);
}

.btn-star.active {
    color: var(--warning);
    fill: var(--warning);
    /* Assume SVG com preenchimento quando ativo */
}

.btn-star.active svg {
    fill: currentColor;
}