/* ============================================================
   IntGest PDF Viewer — Styles
   ============================================================ */

/* Utility: ocultar elementos via classe */
.ipv-hidden {
    display: none !important;
}

.intgest-pdf-viewer {
    position: relative;
    width: 100%;
    height: 100%;
    min-height: 500px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.intgest-pdf-viewer:fullscreen {
    background: var(--ipv-bg);
}

/* ---- Theme tokens ---- */
.ipv-wrapper[data-theme="light"] {
    --ipv-bg: #f3f4f6;
    --ipv-toolbar-bg: #ffffff;
    --ipv-toolbar-border: #e5e7eb;
    --ipv-text: #1f2937;
    --ipv-text-muted: #6b7280;
    --ipv-btn-hover: #f3f4f6;
    --ipv-btn-active: #e5e7eb;
    --ipv-thumb-bg: #ffffff;
    --ipv-thumb-border: #d1d5db;
    --ipv-thumb-active-border: #3b82f6;
    --ipv-input-bg: #f9fafb;
    --ipv-input-border: #d1d5db;
    --ipv-page-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.08);
    --ipv-search-match: rgba(253, 224, 71, 0.5);
    --ipv-accent: #3b82f6;
    --ipv-accent-hover: #2563eb;
    --ipv-canvas-filter: none;
    --ipv-sidebar-bg: #ffffff;
}

.ipv-wrapper[data-theme="dark"] {
    --ipv-bg: #111827;
    --ipv-toolbar-bg: #1f2937;
    --ipv-toolbar-border: #374151;
    --ipv-text: #f9fafb;
    --ipv-text-muted: #9ca3af;
    --ipv-btn-hover: #374151;
    --ipv-btn-active: #4b5563;
    --ipv-thumb-bg: #1f2937;
    --ipv-thumb-border: #374151;
    --ipv-thumb-active-border: #3b82f6;
    --ipv-input-bg: #374151;
    --ipv-input-border: #4b5563;
    --ipv-page-shadow: 0 1px 3px rgba(0,0,0,0.4);
    --ipv-search-match: rgba(234, 179, 8, 0.4);
    --ipv-accent: #3b82f6;
    --ipv-accent-hover: #60a5fa;
    --ipv-canvas-filter: invert(0.88) hue-rotate(180deg);
    --ipv-sidebar-bg: #1f2937;
}

/* ---- Wrapper ---- */
.ipv-wrapper {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: var(--ipv-bg);
    color: var(--ipv-text);
    border-radius: 0.75rem;
    overflow: hidden;
    border: 1px solid var(--ipv-toolbar-border);
}

/* ---- Toolbar ---- */
.ipv-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 12px;
    background: var(--ipv-toolbar-bg);
    border-bottom: 1px solid var(--ipv-toolbar-border);
    gap: 8px;
    flex-shrink: 0;
    z-index: 10;
}

.ipv-toolbar-left,
.ipv-toolbar-center,
.ipv-toolbar-right {
    display: flex;
    align-items: center;
    gap: 4px;
}

@media (max-width: 768px) {
    .ipv-toolbar-center {
        display: none;
    }
    .ipv-toolbar-right {
        gap: 2px;
    }
}

.ipv-separator {
    width: 1px;
    height: 20px;
    background: var(--ipv-toolbar-border);
    margin: 0 4px;
}

/* ---- Buttons ---- */
.ipv-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--ipv-text);
    cursor: pointer;
    border-radius: 6px;
    transition: background-color 0.15s, color 0.15s;
    font-size: 13px;
    line-height: 1;
}

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

.ipv-btn:active {
    background: var(--ipv-btn-active);
}

.ipv-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.ipv-btn:disabled:hover {
    background: transparent;
}

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

.ipv-btn-sm {
    width: 26px;
    height: 26px;
}

.ipv-btn-primary {
    background: var(--ipv-accent);
    color: #fff;
    padding: 8px 16px;
    font-weight: 500;
}

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

/* ---- Page info ---- */
.ipv-page-info {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
    color: var(--ipv-text-muted);
}

.ipv-page-input {
    width: 42px;
    height: 28px;
    text-align: center;
    border: 1px solid var(--ipv-input-border);
    border-radius: 6px;
    background: var(--ipv-input-bg);
    color: var(--ipv-text);
    font-size: 13px;
    -moz-appearance: textfield;
    outline: none;
}

.ipv-page-input::-webkit-inner-spin-button,
.ipv-page-input::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.ipv-page-input:focus {
    border-color: var(--ipv-accent);
    box-shadow: 0 0 0 2px rgba(59,130,246,0.2);
}

/* ---- Zoom display ---- */
.ipv-zoom-display {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 52px;
    height: 28px;
    padding: 0 8px;
    font-size: 12px;
    font-weight: 500;
    color: var(--ipv-text-muted);
    border-radius: 6px;
    cursor: pointer;
    user-select: none;
    transition: background 0.15s;
}

.ipv-zoom-display:hover {
    background: var(--ipv-btn-hover);
}

/* ---- Search bar ---- */
.ipv-search-bar {
    padding: 8px 12px;
    background: var(--ipv-toolbar-bg);
    border-bottom: 1px solid var(--ipv-toolbar-border);
    flex-shrink: 0;
}

.ipv-search-bar.hidden {
    display: none;
}

.ipv-search-inner {
    display: flex;
    align-items: center;
    gap: 6px;
    max-width: 480px;
    background: var(--ipv-input-bg);
    border: 1px solid var(--ipv-input-border);
    border-radius: 8px;
    padding: 4px 8px;
}

.ipv-search-inner:focus-within {
    border-color: var(--ipv-accent);
    box-shadow: 0 0 0 2px rgba(59,130,246,0.2);
}

.ipv-search-icon {
    flex-shrink: 0;
    color: var(--ipv-text-muted);
}

.ipv-search-input {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--ipv-text);
    font-size: 13px;
    outline: none;
    min-width: 0;
}

.ipv-search-input::placeholder {
    color: var(--ipv-text-muted);
}

.ipv-search-count {
    font-size: 11px;
    color: var(--ipv-text-muted);
    white-space: nowrap;
    padding: 0 4px;
}

/* ---- Main body ---- */
.ipv-body {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
}

/* ---- Thumbnails sidebar ---- */
.ipv-thumbnails {
    width: 180px;
    min-width: 180px;
    background: var(--ipv-sidebar-bg);
    border-right: 1px solid var(--ipv-toolbar-border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
}

.ipv-thumbnails.hidden {
    display: none;
}

.ipv-thumbnails-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border-bottom: 1px solid var(--ipv-toolbar-border);
}

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

.ipv-thumbnails-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
}

.ipv-thumb {
    cursor: pointer;
    border: 2px solid var(--ipv-thumb-border);
    border-radius: 6px;
    overflow: hidden;
    transition: border-color 0.2s, box-shadow 0.2s;
    position: relative;
    background: var(--ipv-thumb-bg);
}

.ipv-thumb canvas {
    display: block;
    width: 100%;
    height: auto;
}

.ipv-thumb:hover {
    border-color: var(--ipv-accent);
}

.ipv-thumb-active {
    border-color: var(--ipv-thumb-active-border) !important;
    box-shadow: 0 0 0 2px rgba(59,130,246,0.25);
}

.ipv-thumb-num {
    position: absolute;
    bottom: 4px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.65);
    color: #fff;
    font-size: 10px;
    font-weight: 600;
    padding: 1px 8px;
    border-radius: 10px;
}

/* ---- Pages container ---- */
.ipv-pages-container {
    flex: 1;
    overflow: auto;
    position: relative;
    background: var(--ipv-bg);
}

.ipv-pages-scroll {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 24px;
    gap: 16px;
    min-height: 100%;
}

/* ---- Page ---- */
.ipv-page {
    position: relative;
    background: #fff;
    box-shadow: var(--ipv-page-shadow);
    border-radius: 2px;
    overflow: hidden;
    flex-shrink: 0;
}

.ipv-page-canvas {
    display: block;
    filter: var(--ipv-canvas-filter);
}

.ipv-page-label {
    position: absolute;
    bottom: -24px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 11px;
    color: var(--ipv-text-muted);
    white-space: nowrap;
}

.ipv-text-layer {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    opacity: 0;
}

/* Search match highlight on page */
.ipv-page.ipv-search-match {
    outline: 3px solid var(--ipv-accent);
    outline-offset: 2px;
}

/* ---- Loading ---- */
.ipv-loading {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--ipv-bg);
    z-index: 5;
}

.ipv-loading-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    color: var(--ipv-text-muted);
    font-size: 14px;
}

.ipv-loading-inner.ipv-error {
    color: #ef4444;
}

.ipv-spinner {
    width: 40px;
    height: 40px;
    color: var(--ipv-accent);
    animation: ipv-spin 1s linear infinite;
}

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

/* ---- Mobile bottom bar ---- */
.ipv-mobile-bar {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--ipv-toolbar-bg);
    border-top: 1px solid var(--ipv-toolbar-border);
}

.ipv-mobile-separator {
    width: 1px;
    height: 20px;
    background: var(--ipv-toolbar-border);
    margin: 0 4px;
}

.ipv-mobile-page-info {
    font-size: 13px;
    color: var(--ipv-text-muted);
    min-width: 50px;
    text-align: center;
}

@media (max-width: 768px) {
    .ipv-mobile-bar {
        display: flex;
    }
    
    .ipv-pages-scroll {
        padding: 12px;
        gap: 12px;
    }

    .ipv-thumbnails {
        width: 130px;
        min-width: 130px;
    }
}

/* ---- Scrollbar styling ---- */
.ipv-pages-container::-webkit-scrollbar,
.ipv-thumbnails-list::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.ipv-pages-container::-webkit-scrollbar-track,
.ipv-thumbnails-list::-webkit-scrollbar-track {
    background: transparent;
}

.ipv-pages-container::-webkit-scrollbar-thumb,
.ipv-thumbnails-list::-webkit-scrollbar-thumb {
    background: var(--ipv-toolbar-border);
    border-radius: 4px;
}

.ipv-pages-container::-webkit-scrollbar-thumb:hover,
.ipv-thumbnails-list::-webkit-scrollbar-thumb:hover {
    background: var(--ipv-text-muted);
}

/* ---- Print styles ---- */
@media print {
    .ipv-toolbar,
    .ipv-search-bar,
    .ipv-thumbnails,
    .ipv-mobile-bar,
    .ipv-page-label {
        display: none !important;
    }
    
    .ipv-wrapper {
        border: none;
    }
    
    .ipv-page {
        box-shadow: none;
        break-inside: avoid;
        page-break-inside: avoid;
    }
}
