:root {
    --bg-main: #0a0e17;
    --bg-card: #111827;
    --bg-card-hover: #1f293d;
    --bg-active: #0c4a6e;
    --border-color: #1e293b;
    --border-light: #334155;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --text-dim: #64748b;
    --primary: #06b6d4;
    --primary-hover: #0891b2;
    --accent: #10b981;
    --danger: #ef4444;
    --font-family: 'Inter', system-ui, -apple-system, sans-serif;
    --header-height: 56px;
    --footer-height: 38px;
    --sidebar-width: 280px;
}

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

html, body {
    width: 100%;
    height: 100%;
    font-family: var(--font-family);
    background-color: var(--bg-main);
    color: var(--text-main);
    overflow: hidden;
    user-select: none;
    -webkit-font-smoothing: antialiased;
}

/* Contenedor Principal */
.viewer-container {
    display: flex;
    flex-direction: column;
    width: 100vw;
    height: 100vh;
    background: radial-gradient(circle at 50% 0%, #172554 0%, var(--bg-main) 70%);
}

/* Header */
.viewer-header {
    height: var(--header-height);
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 20;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 20px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand-icon {
    width: 34px;
    height: 34px;
    background: linear-gradient(135deg, rgba(6, 182, 212, 0.2), rgba(16, 185, 129, 0.2));
    border: 1px solid rgba(6, 182, 212, 0.4);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
}

.brand-title {
    display: flex;
    flex-direction: column;
}

.title-main {
    font-size: 14px;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: #fff;
}

.title-sub {
    font-size: 11px;
    color: var(--text-muted);
}

.title-sub strong {
    color: var(--primary);
}

/* Filtros */
.filters-group {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(30, 41, 59, 0.6);
    padding: 4px 10px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.filter-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.filter-item label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-dim);
}

.custom-select {
    background: #0f172a;
    border: 1px solid var(--border-color);
    color: var(--text-main);
    font-size: 12px;
    padding: 4px 8px;
    border-radius: 6px;
    outline: none;
    cursor: pointer;
    transition: all 0.2s;
}

.custom-select:hover, .custom-select:focus {
    border-color: var(--primary);
}

/* Acciones y Botones */
.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.btn-group {
    display: flex;
    align-items: center;
    gap: 4px;
    background: rgba(30, 41, 59, 0.6);
    padding: 4px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.zoom-text {
    font-size: 12px;
    font-weight: 600;
    min-width: 44px;
    text-align: center;
    color: var(--text-muted);
}

.btn {
    border: none;
    background: transparent;
    color: var(--text-muted);
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.btn-icon {
    width: 32px;
    height: 32px;
}

.btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.btn-highlight {
    background: rgba(6, 182, 212, 0.15);
    color: var(--primary);
}

.btn-highlight:hover {
    background: var(--primary);
    color: #fff;
}

/* Cuerpo del Visor */
.viewer-body {
    flex: 1;
    display: flex;
    height: calc(100vh - var(--header-height));
    position: relative;
    overflow: hidden;
}

/* Sidebar de Facturas */
.invoices-sidebar {
    width: var(--sidebar-width);
    background: rgba(15, 23, 42, 0.7);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    z-index: 10;
}

.sidebar-header {
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-title {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.badge {
    background: rgba(6, 182, 212, 0.15);
    color: var(--primary);
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
}

.invoices-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Scrollbars estilizados */
.invoices-list::-webkit-scrollbar {
    width: 6px;
}

.invoices-list::-webkit-scrollbar-track {
    background: transparent;
}

.invoices-list::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.invoices-list::-webkit-scrollbar-thumb:hover {
    background: var(--border-light);
}

/* Tarjeta de Factura en Lista */
.invoice-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.invoice-card:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-light);
    transform: translateY(-1px);
}

.invoice-card.active {
    background: linear-gradient(135deg, rgba(6, 182, 212, 0.15), rgba(15, 23, 42, 0.9));
    border-color: var(--primary);
    box-shadow: 0 0 15px rgba(6, 182, 212, 0.2);
}

.card-icon {
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-dim);
    flex-shrink: 0;
}

.invoice-card.active .card-icon {
    color: var(--primary);
    background: rgba(6, 182, 212, 0.2);
}

.card-info {
    flex: 1;
    min-width: 0;
}

.card-date {
    font-size: 13px;
    font-weight: 600;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-meta {
    font-size: 11px;
    color: var(--text-dim);
    margin-top: 2px;
}

/* Viewport de Imagen */
.viewport-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    background: radial-gradient(circle at center, #1e293b 0%, #090d16 100%);
    overflow: hidden;
}

.canvas-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
    cursor: grab;
}

.canvas-container.grabbing {
    cursor: grabbing;
}

.canvas-wrapper {
    position: absolute;
    transform-origin: center center;
    transition: transform 0.05s ease-out;
    display: flex;
    align-items: center;
    justify-content: center;
    will-change: transform;
}

.invoice-img {
    max-width: none;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    background-color: #fff;
    display: block;
    user-select: none;
    -webkit-user-drag: none;
}

/* Pie de Metadatos */
.viewport-footer {
    height: var(--footer-height);
    background: rgba(15, 23, 42, 0.9);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 24px;
    font-size: 11px;
    color: var(--text-muted);
    z-index: 10;
}

.meta-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.meta-label {
    color: var(--text-dim);
    font-weight: 500;
}

.meta-val {
    color: var(--text-main);
    font-weight: 600;
}

.meta-item.hints {
    margin-left: auto;
    color: var(--text-dim);
    font-size: 10px;
}

/* Estado Vacío */
.empty-state {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 40px;
    max-width: 400px;
    background: rgba(15, 23, 42, 0.8);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    backdrop-filter: blur(8px);
}

.empty-icon {
    width: 72px;
    height: 72px;
    background: rgba(6, 182, 212, 0.1);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
    margin-bottom: 16px;
}

.empty-state h3 {
    font-size: 16px;
    font-weight: 600;
    color: #fff;
    margin-bottom: 6px;
}

.empty-state p {
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.5;
}

/* Spinner de carga */
.loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 0;
    gap: 12px;
    color: var(--text-muted);
    font-size: 12px;
}

.spinner {
    width: 24px;
    height: 24px;
    border: 2px solid rgba(6, 182, 212, 0.2);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Mobile Drawer Controls & Backdrop */
.btn-toggle-drawer {
    display: none;
    background: rgba(6, 182, 212, 0.15);
    color: var(--primary);
    border: 1px solid rgba(6, 182, 212, 0.35);
    padding: 6px;
    border-radius: 8px;
    cursor: pointer;
}

.btn-close-drawer {
    display: none;
    background: transparent;
    border: none;
    color: #94a3b8;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    padding: 4px;
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 40;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-backdrop.active {
    display: block;
    opacity: 1;
}

.canvas-container {
    touch-action: none;
}

/* Responsive Media Queries */
@media (max-width: 850px) {
    .btn-toggle-drawer {
        display: inline-flex;
    }

    .btn-close-drawer {
        display: block;
    }

    .invoices-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 85%;
        max-width: 320px;
        z-index: 50;
        background: #0f172a;
        box-shadow: 0 0 40px rgba(0, 0, 0, 0.8);
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .invoices-sidebar.open {
        transform: translateX(0);
    }

    .viewer-header {
        height: auto;
        min-height: 52px;
        padding: 8px 12px;
        flex-wrap: wrap;
        gap: 8px;
    }

    .header-left {
        gap: 10px;
        flex-wrap: wrap;
    }

    .filters-group {
        gap: 6px;
        padding: 3px 6px;
    }

    .filter-item label {
        display: none;
    }

    .custom-select {
        padding: 4px 6px;
        font-size: 11px;
    }

    .viewport-footer {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
        gap: 12px;
        padding: 0 12px;
    }

    .meta-item.hints {
        display: none;
    }
}

@media (max-width: 540px) {
    .brand-title {
        display: none;
    }

    .zoom-text {
        min-width: 36px;
        font-size: 11px;
    }

    .header-actions {
        gap: 6px;
    }

    .btn-group {
        padding: 2px;
        gap: 2px;
    }
}

/* Impresión */
@media print {
    body, html {
        background: #fff !important;
        overflow: visible !important;
    }
    .viewer-header, .invoices-sidebar, .viewport-footer, .empty-state, .btn-toggle-drawer, .sidebar-backdrop {
        display: none !important;
    }
    .viewer-container, .viewer-body, .viewport-area, .canvas-container, .canvas-wrapper {
        position: static !important;
        width: 100% !important;
        height: auto !important;
        transform: none !important;
        background: transparent !important;
    }
    .invoice-img {
        max-width: 100% !important;
        box-shadow: none !important;
        border: none !important;
    }
}
