/* ============================================
   DocScan Pro - Premium Dark Theme
   OTIMIZADO PARA MOBILE - TAMANHOS GRANDES
   ============================================ */

:root {
    --bg-primary: #0d0d14;
    --bg-secondary: #1a1a2e;
    --bg-tertiary: #252540;
    --bg-card: #16162a;
    --accent-primary: #6c5ce7;
    --accent-secondary: #a29bfe;
    --accent-gradient: linear-gradient(135deg, #6c5ce7 0%, #a29bfe 100%);
    --danger: #ff6b6b;
    --success: #00d9a5;
    --warning: #ffc107;
    --text-primary: #ffffff;
    --text-secondary: #b4b4c9;
    --text-muted: #6c6c8a;
    --border-color: #2a2a4a;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html,
body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

.hidden {
    display: none !important;
}

/* ============================================
   SPLASH SCREEN
   ============================================ */
.splash-screen {
    position: fixed;
    inset: 0;
    background: var(--bg-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.5s ease, visibility 0.5s ease;
}

.splash-screen.fade-out {
    opacity: 0;
    visibility: hidden;
}

.splash-content {
    text-align: center;
}

.splash-icon {
    font-size: 80px;
    margin-bottom: 20px;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.1);
    }
}

.splash-content h1 {
    font-size: 28px;
    font-weight: 600;
    margin-bottom: 24px;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

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

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

/* ============================================
   APP CONTAINER
   ============================================ */
.app {
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* ============================================
   HEADER - OTIMIZADO PARA MOBILE
   ============================================ */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
    min-height: 56px;
    gap: 6px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 1;
    min-width: 0;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.app-title {
    font-size: 16px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ============================================
   BOTÕES DE ÍCONE - TAMANHO OTIMIZADO (40px)
   ============================================ */
.icon-btn {
    min-width: 40px;
    width: 40px;
    height: 40px;
    border: none;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
    flex-shrink: 0;
    padding: 0;
}

.icon-btn svg {
    width: 22px;
    height: 22px;
    fill: var(--text-secondary);
    transition: var(--transition);
}

.icon-btn:hover,
.icon-btn:active {
    background: var(--accent-primary);
}

.icon-btn:hover svg,
.icon-btn:active svg {
    fill: white;
}

.icon-btn.primary {
    background: var(--accent-gradient);
}

.icon-btn.primary svg {
    fill: white;
}

.icon-btn.danger:hover,
.icon-btn.danger:active {
    background: var(--danger);
}

.icon-btn.danger:hover svg,
.icon-btn.danger:active svg {
    fill: white;
}

/* ============================================
   BARRA DE ORDENAÇÃO - COMPACTA
   ============================================ */
.sort-bar {
    display: flex;
    gap: 6px;
    padding: 8px 10px;
    background: var(--bg-secondary);
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    border-bottom: 1px solid var(--border-color);
}

.sort-bar::-webkit-scrollbar {
    display: none;
}

.sort-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    cursor: pointer;
    transition: var(--transition);
    flex-shrink: 0;
}

.sort-btn svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

.sort-btn.active {
    border-color: var(--accent-primary);
    background: var(--accent-primary);
    color: white;
}

/* ============================================
   BARRA DE SELEÇÃO - COMPACTA
   ============================================ */
.selection-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    background: var(--accent-primary);
    animation: slideDown 0.3s ease;
    min-height: 56px;
    gap: 8px;
}

@keyframes slideDown {
    from {
        transform: translateY(-100%);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.selection-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.selection-right {
    display: flex;
    align-items: center;
    gap: 4px;
}

.selection-bar .icon-btn {
    background: rgba(255, 255, 255, 0.25);
    width: 36px;
    height: 36px;
    min-width: 36px;
}

.selection-bar .icon-btn svg {
    fill: white;
    width: 20px;
    height: 20px;
}

#selectedCount {
    font-weight: 600;
    font-size: 14px;
}

/* ============================================
   BREADCRUMB - COMPACTO
   ============================================ */
.breadcrumb {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
    background: var(--bg-secondary);
    overflow-x: auto;
    scrollbar-width: none;
    border-bottom: 1px solid var(--border-color);
}

.breadcrumb::-webkit-scrollbar {
    display: none;
}

.breadcrumb-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border: none;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    flex-shrink: 0;
}

.breadcrumb-item svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

.breadcrumb-item.active {
    background: var(--accent-primary);
    color: white;
}

/* ============================================
   CONTEÚDO PRINCIPAL
   ============================================ */
.main-content {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    padding-bottom: 100px;
}

/* ============================================
   ESTADO VAZIO
   ============================================ */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    padding: 32px;
}

.empty-icon {
    font-size: 64px;
    margin-bottom: 16px;
    opacity: 0.6;
}

.empty-state h2 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 8px;
}

.empty-state p {
    font-size: 14px;
    color: var(--text-muted);
    max-width: 260px;
}

/* ============================================
   GRID DE DOCUMENTOS
   ============================================ */
.documents-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

@media (min-width: 400px) {
    .documents-grid {
        gap: 12px;
    }
}

@media (min-width: 500px) {
    .documents-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (min-width: 768px) {
    .documents-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 16px;
    }
}

.doc-item {
    position: relative;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    overflow: hidden;
    cursor: pointer;
    transition: var(--transition);
    border: 2px solid transparent;
}

.doc-item:active {
    transform: scale(0.98);
}

.doc-item.selected {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px var(--accent-secondary);
}

/* PASTA */
.doc-item.folder {
    aspect-ratio: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 16px 12px;
}

.doc-item.folder .folder-icon {
    font-size: 48px;
    margin-bottom: 8px;
}

.doc-item.folder .folder-name {
    font-size: 13px;
    font-weight: 600;
    text-align: center;
    word-break: break-word;
    line-height: 1.3;
}

/* MINIATURA DE DOCUMENTO */
.doc-thumbnail {
    width: 100%;
    aspect-ratio: 3/4;
    object-fit: cover;
    background: var(--bg-tertiary);
}

.doc-info {
    padding: 10px 8px;
}

.doc-name {
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 4px;
}

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

/* CHECKBOX DE SELEÇÃO */
.doc-checkbox {
    position: absolute;
    top: 6px;
    left: 6px;
    width: 22px;
    height: 22px;
    border: 2px solid white;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 5;
}

.doc-checkbox svg {
    width: 14px;
    height: 14px;
    fill: white;
    opacity: 0;
}

.doc-item.selected .doc-checkbox {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
}

.doc-item.selected .doc-checkbox svg {
    opacity: 1;
}

.select-mode .doc-checkbox {
    display: flex;
}

/* BOTÃO DE MENU DO DOCUMENTO */
.doc-menu-btn {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 28px;
    height: 28px;
    border: none;
    background: rgba(0, 0, 0, 0.7);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 5;
}

.doc-menu-btn svg {
    width: 16px;
    height: 16px;
    fill: white;
}

/* ESTRELA DE FAVORITO */
.doc-favorite {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 24px;
    height: 24px;
    background: rgba(255, 215, 0, 0.95);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5;
}

.doc-favorite svg {
    width: 14px;
    height: 14px;
    fill: #000;
}

/* ============================================
   FAB - BOTÃO FLUTUANTE
   ============================================ */
.fab {
    position: fixed;
    bottom: 24px;
    right: 16px;
    width: 60px;
    height: 60px;
    border: none;
    background: var(--accent-gradient);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 6px 24px rgba(108, 92, 231, 0.5);
    transition: var(--transition);
    z-index: 50;
}

.fab svg {
    width: 28px;
    height: 28px;
    fill: white;
}

.fab:active {
    transform: scale(0.92);
}

/* FAB SECUNDÁRIO */
.fab-secondary {
    position: fixed;
    bottom: 96px;
    right: 20px;
    width: 48px;
    height: 48px;
    border: none;
    background: var(--bg-tertiary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--shadow-lg);
    transition: var(--transition);
    z-index: 50;
    border: 2px solid var(--border-color);
}

.fab-secondary svg {
    width: 24px;
    height: 24px;
    fill: var(--accent-secondary);
}

/* ============================================
   MENU LATERAL
   ============================================ */
.side-menu {
    position: fixed;
    inset: 0;
    z-index: 200;
    pointer-events: none;
}

.side-menu.open {
    pointer-events: auto;
}

.side-menu-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.side-menu.open .side-menu-overlay {
    opacity: 1;
}

.side-menu-content {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 280px;
    max-width: 85%;
    background: var(--bg-secondary);
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
}

.side-menu.open .side-menu-content {
    transform: translateX(0);
}

.side-menu-header {
    padding: 24px 16px;
    background: var(--accent-gradient);
    text-align: center;
}

.user-avatar {
    font-size: 40px;
    margin-bottom: 8px;
}

.side-menu-header h2 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 4px;
}

.credits-display {
    background: rgba(0, 0, 0, 0.2);
    padding: 6px 16px;
    border-radius: 20px;
    display: inline-block;
    margin: 8px 0;
    font-size: 14px;
    font-weight: 600;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.side-menu-header p {
    font-size: 12px;
    opacity: 0.85;
}

.side-menu-nav {
    flex: 1;
    padding: 12px;
    overflow-y: auto;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 12px 14px;
    border: none;
    background: transparent;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 14px;
    cursor: pointer;
    transition: var(--transition);
    text-align: left;
}

.menu-item svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.menu-item:hover,
.menu-item.active {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.menu-item.active {
    color: var(--accent-secondary);
}

.menu-item.highlight {
    background: var(--accent-gradient);
    color: white;
    font-weight: 600;
    margin-bottom: 8px;
    box-shadow: 0 4px 12px rgba(108, 92, 231, 0.3);
}

.menu-item.highlight svg {
    fill: white;
}

.menu-divider {
    height: 1px;
    background: var(--border-color);
    margin: 10px 0;
}

.badge {
    margin-left: auto;
    padding: 2px 8px;
    background: var(--danger);
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
}

.side-menu-footer {
    padding: 12px;
    text-align: center;
    border-top: 1px solid var(--border-color);
}

.side-menu-footer p {
    font-size: 11px;
    color: var(--text-muted);
}

/* ============================================
   MODAIS
   ============================================ */
.modal {
    position: fixed;
    inset: 0;
    z-index: 300;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    background: rgba(0, 0, 0, 0.7);
}

.modal.open {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    width: 100%;
    max-height: 92vh;
    background: var(--bg-secondary);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    transform: translateY(100%);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal.open .modal-content {
    transform: translateY(0);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    gap: 10px;
    min-height: 56px;
}

.modal-header h2 {
    font-size: 16px;
    font-weight: 600;
    flex: 1;
    text-align: center;
}

/* ============================================
   MODAL DE CAPTURA
   ============================================ */
.capture-options {
    display: flex;
    gap: 20px;
    padding: 32px 24px;
}

.capture-option {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 40px 24px;
    border: 3px dashed var(--border-color);
    background: var(--bg-tertiary);
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: var(--transition);
}

.capture-option:active {
    border-color: var(--accent-primary);
    background: var(--bg-card);
}

.capture-icon {
    font-size: 64px;
}

.capture-option span {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

/* ============================================
   MODAL DO EDITOR
   ============================================ */
.editor-modal {
    max-height: 100vh;
    max-height: 100dvh;
    height: 100vh;
    height: 100dvh;
    border-radius: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal:has(.editor-modal) {
    align-items: stretch;
}

.modal.open .modal-content.editor-modal {
    transform: translateY(0);
}

.editor-tabs {
    display: flex;
    padding: 8px;
    gap: 8px;
    background: var(--bg-primary);
    flex-shrink: 0;
}

.editor-tab {
    flex: 1;
    padding: 10px 8px;
    border: none;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.editor-tab.active {
    background: var(--accent-primary);
    color: white;
}

.editor-canvas-container {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
    overflow: hidden;
    min-height: 80px;
    /* canvas pode encolher, mas mantém mínimo utilizável */
}

#editorCanvas {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* Crop Overlay */
.crop-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 5;
    overflow: visible;
}

.crop-area {
    position: absolute;
    border: 3px solid var(--accent-primary);
    background: rgba(108, 92, 231, 0.1);
    pointer-events: auto;
    touch-action: none;
}

.crop-handle {
    position: absolute;
    width: 44px;
    height: 44px;
    background: var(--accent-primary);
    border: 3px solid white;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    cursor: grab;
    touch-action: none;
    z-index: 20;
    pointer-events: auto;
    box-shadow: 0 2px 12px rgba(108, 92, 231, 0.7), 0 0 0 2px rgba(255, 255, 255, 0.3);
    transition: transform 0.08s ease, box-shadow 0.08s ease;
}

/* Large invisible touch target */
.crop-handle::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 72px;
    height: 72px;
    border-radius: 50%;
}

.crop-handle:active {
    transform: translate(-50%, -50%) scale(1.3);
    box-shadow: 0 4px 20px rgba(108, 92, 231, 0.9), 0 0 0 4px rgba(255, 255, 255, 0.5);
    cursor: grabbing;
}

/* Remove static corner positioning — JS controls left/top now */

.crop-grid {
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(var(--accent-secondary) 1px, transparent 1px),
        linear-gradient(90deg, var(--accent-secondary) 1px, transparent 1px);
    background-size: 33.33% 33.33%;
    opacity: 0.3;
}

/* Editor Tools — sempre visível na base, scroll interno se conteúdo muito alto */
.editor-tools {
    padding: 12px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
    /* nunca encolhe — o canvas que cede espaço */
    overflow-y: auto;
    /* scroll interno se o conteúdo passar do max-height */
    max-height: 47vh;
    /* no máximo ~metade da tela para ferramentas */
    -webkit-overflow-scrolling: touch;
}

.tool-group {
    margin-bottom: 12px;
}

.tool-label {
    display: block;
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.ratio-buttons {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.ratio-btn {
    flex: 1;
    min-width: 60px;
    padding: 10px 8px;
    border: 2px solid var(--border-color);
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    text-align: center;
}

.ratio-btn.active {
    border-color: var(--accent-primary);
    background: var(--accent-primary);
    color: white;
}

.tool-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.tool-btn {
    flex: 1;
    min-width: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 10px;
    border: 2px solid var(--border-color);
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.tool-btn svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
}

/* Filter Tools */
.filter-section {
    margin-bottom: 24px;
}

.filter-section h4 {
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 14px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.filter-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
}

.filter-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 10px;
    border: 3px solid transparent;
    background: transparent;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
}

.filter-btn.active {
    border-color: var(--accent-primary);
}

.filter-preview {
    width: 60px;
    height: 60px;
    border-radius: var(--radius-sm);
    background: var(--bg-tertiary);
}

.filter-preview.grayscale {
    filter: grayscale(1);
    background: linear-gradient(135deg, #888, #444);
}

.filter-preview.contrast {
    filter: contrast(1.5);
    background: linear-gradient(135deg, #000, #fff);
}

.filter-preview.brightness {
    filter: brightness(1.3);
    background: linear-gradient(135deg, #fff, #aaa);
}

.filter-preview.document {
    background: linear-gradient(135deg, #fff, #f0f0f0);
}

.filter-preview.whiteboard {
    background: linear-gradient(135deg, #f8f8ff, #e8e8f0);
}

.filter-preview.magic {
    background: linear-gradient(135deg, #fff, #4a90e2, #000);
}

.filter-preview.autoclean {
    background: linear-gradient(135deg, #fafafa, #eee);
}

.filter-btn span {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}

.filter-btn.active span {
    color: var(--accent-secondary);
}

/* Adjust Tools */
.adjust-buttons {
    display: flex;
    gap: 16px;
}

.adjust-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 14px 12px;
    border: 2px solid var(--border-color);
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.adjust-btn svg {
    width: 28px;
    height: 28px;
    fill: var(--accent-secondary);
}

/* Extra compact for very short screens (e.g. small phones in landscape or short portrait) */
@media (max-height: 650px) {
    .editor-tabs {
        padding: 5px 8px;
        gap: 6px;
    }

    .editor-tab {
        padding: 7px 6px;
        font-size: 13px;
    }

    .editor-tools {
        padding: 8px;
    }

    .tool-group {
        margin-bottom: 8px;
    }

    .ratio-btn {
        padding: 7px 6px;
        font-size: 12px;
    }

    .tool-btn {
        padding: 7px 8px;
        font-size: 13px;
    }

    .adjust-btn {
        padding: 10px 8px;
        gap: 6px;
        font-size: 13px;
    }

    .adjust-btn svg {
        width: 24px;
        height: 24px;
    }

    .tool-btn svg {
        width: 20px;
        height: 20px;
    }

    /* Em telas curtas, limitar ainda mais as tools para ceder espaço ao canvas */
    .editor-tools {
        max-height: 42vh;
    }
}

/* ============================================
   MODAL MULTI-PÁGINA
   ============================================ */
.multipage-modal {
    max-height: 85vh;
}

.pages-grid {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
    padding: 18px;
    overflow-y: auto;
}

.page-item {
    position: relative;
    aspect-ratio: 3/4;
    border-radius: var(--radius-md);
    overflow: hidden;
    background: var(--bg-tertiary);
}

.page-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.page-number {
    position: absolute;
    bottom: 10px;
    left: 10px;
    padding: 6px 12px;
    background: rgba(0, 0, 0, 0.8);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 700;
}

.page-remove {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 32px;
    height: 32px;
    border: none;
    background: var(--danger);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.page-remove svg {
    width: 20px;
    height: 20px;
    fill: white;
}

.multipage-actions {
    padding: 18px;
    border-top: 1px solid var(--border-color);
}

.action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    width: 100%;
    padding: 18px;
    border: 3px dashed var(--border-color);
    background: transparent;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.action-btn svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
}

/* ============================================
   MODAL DE SALVAR
   ============================================ */
.save-options {
    padding: 24px;
}

.form-group {
    margin-bottom: 24px;
}

.form-group label {
    display: block;
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 10px;
    font-weight: 500;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 16px 18px;
    border: 2px solid var(--border-color);
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 17px;
    outline: none;
    transition: var(--transition);
}

.form-group input:focus,
.form-group select:focus {
    border-color: var(--accent-primary);
}

.format-buttons {
    display: flex;
    gap: 14px;
}

.format-btn {
    flex: 1;
    padding: 18px;
    border: 2px solid var(--border-color);
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 18px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.format-btn.active {
    border-color: var(--accent-primary);
    background: var(--accent-primary);
    color: white;
}

.save-actions {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin-top: 28px;
}

.save-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 18px;
    border: none;
    border-radius: var(--radius-md);
    font-size: 17px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.save-btn svg {
    width: 26px;
    height: 26px;
    fill: currentColor;
}

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

.save-btn:not(.primary):not(.secondary) {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 2px solid var(--border-color);
}

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

/* ============================================
   MODAL DE PASTA
   ============================================ */
.folder-form {
    padding: 24px;
}

/* ============================================
   MENU DE CONTEXTO
   ============================================ */
.context-menu {
    position: fixed;
    z-index: 400;
    min-width: 220px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.context-item {
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
    padding: 16px 18px;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 16px;
    cursor: pointer;
    transition: var(--transition);
    text-align: left;
}

.context-item svg {
    width: 24px;
    height: 24px;
    fill: var(--text-secondary);
}

.context-item:active {
    background: var(--bg-tertiary);
}

.context-item.danger {
    color: var(--danger);
}

.context-item.danger svg {
    fill: var(--danger);
}

.context-divider {
    height: 1px;
    background: var(--border-color);
}

/* ============================================
   MODAL DE MOVER
   ============================================ */
.folders-list {
    padding: 18px;
    max-height: 60vh;
    overflow-y: auto;
}

.folder-list-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 18px;
    border: 2px solid var(--border-color);
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    margin-bottom: 10px;
    cursor: pointer;
    transition: var(--transition);
}

.folder-list-item:active {
    border-color: var(--accent-primary);
}

.folder-list-item .folder-icon {
    font-size: 28px;
}

/* ============================================
   MODAL DO VIEWER - CORRIGIDO
   ============================================ */
.viewer-modal-container {
    align-items: flex-start !important;
}

.viewer-modal-container.open .viewer-modal {
    transform: translateY(0) !important;
}

.viewer-modal {
    height: 100% !important;
    max-height: 100% !important;
    border-radius: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    transform: translateY(0) !important;
}

/* Header do viewer */
.viewer-header {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    justify-content: space-between !important;
    width: 100% !important;
    padding: 14px 18px !important;
    padding-top: max(14px, env(safe-area-inset-top, 0px)) !important;
    background: var(--bg-secondary) !important;
    border-bottom: 1px solid var(--border-color) !important;
    flex-shrink: 0 !important;
    gap: 14px !important;
    min-height: 72px !important;
}

.viewer-title {
    flex: 1 !important;
    font-size: 17px !important;
    font-weight: 600 !important;
    color: var(--text-primary) !important;
    text-align: center !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
    margin: 0 !important;
    padding: 0 10px !important;
}

.viewer-header-actions {
    display: flex !important;
    flex-direction: row !important;
    gap: 10px !important;
    flex-shrink: 0 !important;
}

.viewer-btn {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    border: none !important;
    border-radius: 12px !important;
    cursor: pointer !important;
    transition: all 0.2s ease !important;
    padding: 0 !important;
    flex-shrink: 0 !important;
}

.viewer-btn-close {
    width: 52px !important;
    height: 52px !important;
    min-width: 52px !important;
    background: var(--danger) !important;
    color: white !important;
}

.viewer-btn-close svg {
    width: 30px !important;
    height: 30px !important;
}

.viewer-btn-action {
    width: 48px !important;
    height: 48px !important;
    min-width: 48px !important;
    background: var(--accent-primary) !important;
    color: white !important;
}

.viewer-btn-action svg {
    width: 26px !important;
    height: 26px !important;
}

.viewer-modal .viewer-content {
    flex: 1 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    background: var(--bg-primary) !important;
    overflow: auto !important;
    min-height: 0 !important;
}

.viewer-modal .viewer-content img {
    max-width: 100% !important;
    max-height: 100% !important;
    object-fit: contain !important;
}

/* ============================================
   BARRA DE BUSCA
   ============================================ */
.search-bar {
    background: var(--bg-secondary);
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
}

.search-input-container {
    position: relative;
    display: flex;
    align-items: center;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    padding: 0 14px;
}

.search-icon {
    width: 24px;
    height: 24px;
    fill: var(--text-muted);
    margin-right: 10px;
}

#searchInput {
    flex: 1;
    background: transparent;
    border: none;
    padding: 16px 10px;
    color: var(--text-primary);
    font-size: 17px;
    outline: none;
}

#searchInput::placeholder {
    color: var(--text-muted);
}

.icon-btn-small {
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.icon-btn-small svg {
    width: 24px;
    height: 24px;
    fill: var(--text-secondary);
}

/* ============================================
   TOAST
   ============================================ */
.toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    padding: 16px 24px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    z-index: 500;
    animation: slideUp 0.3s ease;
    max-width: 90%;
    text-align: center;
    font-size: 16px;
    font-weight: 500;
}

@keyframes slideUp {
    from {
        transform: translateX(-50%) translateY(100%);
        opacity: 0;
    }

    to {
        transform: translateX(-50%) translateY(0);
        opacity: 1;
    }
}

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

.toast.error {
    background: var(--danger);
    color: white;
}

/* ============================================
   LOADING
   ============================================ */
.loading {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 600;
}

.loading-spinner {
    width: 56px;
    height: 56px;
    border: 5px solid var(--bg-tertiary);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

#loadingText {
    color: var(--text-secondary);
    font-size: 16px;
}

/* ============================================
   iOS SAFE AREAS
   ============================================ */
@supports (padding-top: env(safe-area-inset-top)) {
    .header {
        padding-top: calc(12px + env(safe-area-inset-top));
        min-height: calc(70px + env(safe-area-inset-top));
    }

    .fab {
        bottom: calc(28px + env(safe-area-inset-bottom));
        right: calc(20px + env(safe-area-inset-right));
    }

    .fab-secondary {
        bottom: calc(112px + env(safe-area-inset-bottom));
    }

    .main-content {
        padding-bottom: calc(120px + env(safe-area-inset-bottom));
    }

    .toast {
        bottom: calc(100px + env(safe-area-inset-bottom));
    }
}

/* ============================================
   ANIMAÇÕES
   ============================================ */
.doc-item {
    animation: fadeInUp 0.3s ease backwards;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============================================
   CONFIGURAÇÕES
   ============================================ */
.settings-modal {
    max-height: 85vh;
}

.settings-content {
    padding: 20px;
    overflow-y: auto;
}

.setting-group {
    margin-bottom: 28px;
}

.setting-group h3 {
    font-size: 15px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 14px;
}

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

.setting-item label {
    font-size: 16px;
    color: var(--text-primary);
}

.theme-buttons {
    display: flex;
    gap: 10px;
    width: 100%;
    margin-top: 14px;
}

.theme-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 18px 14px;
    border: 2px solid var(--border-color);
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.theme-btn svg {
    width: 30px;
    height: 30px;
    fill: currentColor;
}

.theme-btn.active {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

.switch {
    position: relative;
    display: inline-block;
    width: 56px;
    height: 32px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--bg-tertiary);
    border-radius: 32px;
    transition: var(--transition);
}

.slider:before {
    position: absolute;
    content: "";
    height: 24px;
    width: 24px;
    left: 4px;
    bottom: 4px;
    background: white;
    border-radius: 50%;
    transition: var(--transition);
}

input:checked+.slider {
    background: var(--accent-primary);
}

input:checked+.slider:before {
    transform: translateX(24px);
}

/* ============================================
   ESTATÍSTICAS
   ============================================ */
.stats-modal {
    max-height: 85vh;
}

.stats-content {
    padding: 20px;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
}

.stat-card {
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    padding: 22px;
    display: flex;
    align-items: center;
    gap: 16px;
    border: 1px solid var(--border-color);
}

.stat-card.full-width {
    grid-column: 1 / -1;
}

.stat-icon {
    font-size: 44px;
}

.stat-value {
    font-size: 30px;
    font-weight: 700;
    color: var(--accent-secondary);
    margin-bottom: 4px;
}

.stat-label {
    font-size: 14px;
    color: var(--text-muted);
    text-transform: uppercase;
}

/* ============================================
   TUTORIAL
   ============================================ */
.tutorial-modal {
    max-height: 90vh;
}

.tutorial-slides {
    position: relative;
    min-height: 420px;
    padding: 44px 24px;
}

.tutorial-slide {
    position: absolute;
    inset: 44px 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    opacity: 0;
    visibility: hidden;
    transform: translateX(100%);
    transition: all 0.4s ease;
}

.tutorial-slide.active {
    opacity: 1;
    visibility: visible;
    transform: translateX(0);
    position: relative;
    inset: auto;
}

.tutorial-icon {
    font-size: 90px;
    margin-bottom: 28px;
}

.tutorial-slide h3 {
    font-size: 26px;
    font-weight: 600;
    margin-bottom: 14px;
}

.tutorial-slide p {
    font-size: 17px;
    color: var(--text-secondary);
    max-width: 320px;
    line-height: 1.6;
}

.tutorial-navigation {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 22px;
    border-top: 1px solid var(--border-color);
}

.tutorial-dots {
    display: flex;
    gap: 10px;
}

.dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--bg-tertiary);
    transition: var(--transition);
}

.dot.active {
    background: var(--accent-primary);
    width: 28px;
    border-radius: 5px;
}

.tutorial-btn-primary,
.tutorial-btn-secondary {
    padding: 14px 28px;
    border: none;
    border-radius: var(--radius-md);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
}

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

.tutorial-btn-secondary {
    background: transparent;
    color: var(--text-secondary);
}

/* ============================================
   OCR
   ============================================ */
.ocr-modal {
    max-height: 75vh;
}

.ocr-content {
    padding: 20px;
    flex: 1;
    overflow: hidden;
}

#ocrText {
    width: 100%;
    height: 100%;
    min-height: 320px;
    padding: 18px;
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    font-size: 16px;
    line-height: 1.7;
    resize: vertical;
}

/* ============================================
   MODO LISTA
   ============================================ */
.documents-grid.list-view {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.documents-grid.list-view .doc-item {
    display: flex;
    flex-direction: row;
    aspect-ratio: auto;
}

.documents-grid.list-view .doc-item.folder {
    aspect-ratio: auto;
    flex-direction: row;
    justify-content: flex-start;
    padding: 18px;
}

.documents-grid.list-view .doc-thumbnail {
    width: 90px;
    height: 110px;
    aspect-ratio: auto;
    flex-shrink: 0;
}

.documents-grid.list-view .doc-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.documents-grid.list-view .folder-icon {
    font-size: 36px;
    margin: 0;
    margin-right: 14px;
}

/* ============================================
   TEMA CLARO
   ============================================ */
body.theme-light {
    --bg-primary: #f5f5f5;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f0f0f0;
    --bg-card: #fafafa;
    --text-primary: #1a1a1a;
    --text-secondary: #4a4a4a;
    --text-muted: #888888;
    --border-color: #e0e0e0;
}

/* ============================================
   PRINT
   ============================================ */
@media print {

    .header,
    .fab,
    .fab-secondary,
    .side-menu,
    .modal {
        display: none !important;
    }

    .main-content {
        padding: 0;
    }
}

/* ============================================
   LOADING COM PROGRESSO (OCR)
   ============================================ */
.loading-progress {
    margin-top: 20px;
    width: 80%;
    max-width: 300px;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 10px;
}

.progress-fill {
    height: 100%;
    background: var(--accent-gradient);
    border-radius: 4px;
    transition: width 0.3s ease;
    width: 0%;
}

#progressText {
    color: var(--text-secondary);
    font-size: 14px;
}

/* ============================================
   QR CODE SCANNER
   ============================================ */
.qr-modal {
    max-height: 95vh;
    height: 95vh;
}

.qr-scanner-container {
    flex: 1;
    position: relative;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    min-height: 300px;
}

#qrReader {
    width: 100% !important;
    height: 100% !important;
}

#qrReader video {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
}

#qrReader img {
    display: none;
}

.qr-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.qr-frame {
    width: 250px;
    height: 250px;
    border: 3px solid var(--accent-primary);
    border-radius: 20px;
    position: relative;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5);
}

.qr-frame::before,
.qr-frame::after {
    content: '';
    position: absolute;
    width: 30px;
    height: 30px;
    border: 4px solid var(--accent-secondary);
}

.qr-frame::before {
    top: -3px;
    left: -3px;
    border-right: none;
    border-bottom: none;
    border-radius: 15px 0 0 0;
}

.qr-frame::after {
    bottom: -3px;
    right: -3px;
    border-left: none;
    border-top: none;
    border-radius: 0 0 15px 0;
}

/* Animação de scan */
.qr-frame .scan-line {
    position: absolute;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--accent-primary);
    box-shadow: 0 0 10px var(--accent-primary);
    animation: scanMove 2s linear infinite;
}

@keyframes scanMove {
    0% {
        top: 0;
    }

    50% {
        top: calc(100% - 3px);
    }

    100% {
        top: 0;
    }
}

.qr-instructions {
    padding: 16px;
    text-align: center;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
}

.qr-instructions p {
    color: var(--text-secondary);
    font-size: 15px;
}

/* QR Result */
.qr-result {
    padding: 24px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
}

.qr-result-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.qr-result-header span {
    font-size: 18px;
    font-weight: 600;
    color: var(--success);
}

.qr-result-content {
    background: var(--bg-tertiary);
    padding: 16px;
    border-radius: var(--radius-md);
    margin-bottom: 20px;
    word-break: break-all;
    font-family: monospace;
    font-size: 14px;
    color: var(--text-primary);
    max-height: 150px;
    overflow-y: auto;
}

.qr-result-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.qr-action-btn {
    flex: 1;
    min-width: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 18px;
    border: 2px solid var(--border-color);
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.qr-action-btn svg {
    width: 22px;
    height: 22px;
    fill: currentColor;
}

.qr-action-btn.primary {
    background: var(--accent-gradient);
    border-color: var(--accent-primary);
    color: white;
}

.qr-action-btn:active {
    transform: scale(0.98);
}

/* OCR Modal melhorado */
.ocr-modal {
    max-height: 90vh;
}

.ocr-content {
    padding: 20px;
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#ocrText {
    width: 100%;
    flex: 1;
    min-height: 250px;
    padding: 18px;
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    font-size: 16px;
    line-height: 1.7;
    resize: none;
}

.ocr-actions {
    display: flex;
    gap: 12px;
    margin-top: 16px;
}

.ocr-action-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 16px;
    border: none;
    border-radius: var(--radius-md);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.ocr-action-btn.primary {
    background: var(--accent-gradient);
    color: white;
}

.ocr-action-btn.secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 2px solid var(--border-color);
}

.ocr-action-btn svg {
    width: 22px;
    height: 22px;
    fill: currentColor;
}

/* Melhorar aparência quando editável */
#ocrText:not([readonly]) {
    border-color: var(--accent-primary);
    background: var(--bg-card);
}

/* ============================================
   DIALOG MULTI-PÁGINA
   ============================================ */
.multipage-dialog-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 2000;
    display: flex;
    align-items: flex-end;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.multipage-dialog-overlay.open {
    opacity: 1;
}

.multipage-dialog {
    background: var(--bg-secondary);
    border-radius: 24px 24px 0 0;
    padding: 24px 20px 36px;
    width: 100%;
    text-align: center;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.multipage-dialog-overlay.open .multipage-dialog {
    transform: translateY(0);
}

.multipage-dialog-preview {
    width: 80px;
    height: 100px;
    margin: 0 auto 16px;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

.multipage-dialog-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.multipage-dialog h3 {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.multipage-dialog p {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 20px;
}

.multipage-dialog-actions {
    display: flex;
    gap: 12px;
}

.mpdialog-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 16px 12px;
    border: 2px solid var(--border-color);
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.mpdialog-btn svg {
    width: 28px;
    height: 28px;
    fill: var(--text-secondary);
}

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

.mpdialog-btn.primary svg {
    fill: white;
}

.mpdialog-btn:active {
    transform: scale(0.96);
}

/* ============================================
   ANIMAÇÃO DE SUCESSO AO SALVAR
   ============================================ */
.save-success-anim {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 3000;
    pointer-events: none;
    opacity: 0;
    transform: scale(0.7);
    transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.save-success-anim.show {
    opacity: 1;
    transform: scale(1);
}

.save-success-circle {
    width: 80px;
    height: 80px;
    background: var(--accent-primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 0 0 rgba(108, 92, 231, 0.4);
    animation: pulse-ring 1.5s ease-out infinite;
}

.save-success-circle svg {
    width: 52px;
    height: 52px;
}

.save-success-circle svg circle {
    stroke: white;
    stroke-width: 3;
    stroke-dasharray: 157;
    stroke-dashoffset: 157;
    animation: draw-circle 0.5s ease forwards;
}

.save-success-circle svg path {
    stroke: white;
    stroke-width: 3;
    stroke-dasharray: 40;
    stroke-dashoffset: 40;
    animation: draw-check 0.4s ease 0.4s forwards;
}

@keyframes draw-circle {
    to {
        stroke-dashoffset: 0;
    }
}

@keyframes draw-check {
    to {
        stroke-dashoffset: 0;
    }
}

@keyframes pulse-ring {
    0% {
        box-shadow: 0 0 0 0 rgba(108, 92, 231, 0.4);
    }

    70% {
        box-shadow: 0 0 0 20px rgba(108, 92, 231, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(108, 92, 231, 0);
    }
}

.save-success-anim span {
    margin-top: 16px;
    font-size: 20px;
    font-weight: 700;
    color: white;
    text-shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
}

/* ============================================
   SLIDERS DE AJUSTE
   ============================================ */
.adjust-sliders {
    margin-top: 16px;
}

.slider-row {
    margin-bottom: 14px;
}

.slider-row label {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 6px;
    font-weight: 500;
}

.slider-row input[type="range"] {
    width: 100%;
    -webkit-appearance: none;
    appearance: none;
    height: 4px;
    border-radius: 2px;
    background: linear-gradient(to right, var(--accent-primary) 0%, var(--accent-primary) 50%, var(--border-color) 50%);
    outline: none;
    cursor: pointer;
}

.slider-row input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--accent-primary);
    border: 3px solid white;
    box-shadow: 0 2px 8px rgba(108, 92, 231, 0.5);
    cursor: grab;
}

.slider-row input[type="range"]::-webkit-slider-thumb:active {
    cursor: grabbing;
    transform: scale(1.2);
}

/* ============================================
   SWIPE TO DELETE
   ============================================ */
.doc-item {
    overflow: hidden;
    position: relative;
}

.swipe-delete-btn {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 72px;
    background: #e74c3c;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transform: translateX(100%);
    transition: transform 0.25s ease;
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
    z-index: 5;
}

.swipe-delete-btn svg {
    width: 26px;
    height: 26px;
    fill: white;
}

.doc-item.swipe-open .swipe-delete-btn {
    transform: translateX(0);
}

.doc-item.swipe-open {
    transform: translateX(-72px);
    transition: transform 0.25s ease;
}

/* ============================================
   CANVAS ZOOM / PAN
   ============================================ */
#editorCanvas {
    transition: transform 0.05s linear;
    will-change: transform;
}

/* ============================================
   SW CACHE — v5
   ============================================ */

/* ============================================
   PERSPECTIVA — Overlay e Handles
   ============================================ */
.persp-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 20;
}

.persp-overlay.hidden {
    display: none;
}

.persp-lines {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.persp-handle {
    position: absolute;
    width: 40px;
    height: 40px;
    background: var(--accent-primary);
    border: 3px solid white;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    cursor: grab;
    touch-action: none;
    pointer-events: all;
    z-index: 25;
    box-shadow: 0 2px 14px rgba(108, 92, 231, 0.7), 0 0 0 2px rgba(255, 255, 255, 0.3);
    transition: transform 0.1s, box-shadow 0.1s;
}

.persp-handle::before {
    content: '';
    position: absolute;
    inset: -20px;
    border-radius: 50%;
}

.persp-handle:active {
    cursor: grabbing;
    transform: translate(-50%, -50%) scale(1.3);
    box-shadow: 0 4px 24px rgba(108, 92, 231, 0.9);
}

.persp-instructions {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.5;
}

.persp-instructions strong {
    color: var(--text-primary);
}

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

.tool-btn.primary svg {
    fill: white;
}

/* ============================================
   DRAG-AND-DROP DE PÁGINAS
   ============================================ */
.page-item {
    position: relative;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.page-item.drag-source {
    opacity: 0.35;
    transform: scale(0.96);
}

.page-item.drag-over {
    outline: 2.5px dashed var(--accent-primary);
    outline-offset: 2px;
    transform: scale(1.03);
}

.page-drag-handle {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.45);
    border-radius: 6px;
    z-index: 10;
    cursor: grab;
    touch-action: none;
}

.page-drag-handle svg {
    width: 18px;
    height: 18px;
    fill: white;
    pointer-events: none;
}

.page-drag-handle:active {
    cursor: grabbing;
}

/* ============================================
   PAYMENT MODAL
   ============================================ */
.payment-modal {
    max-width: 500px;
    height: auto !important;
    max-height: 90vh;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
}

.payment-body {
    padding: 24px;
}

.payment-intro {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 24px;
    text-align: center;
}

.package-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.package-card {
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.package-card:hover,
.package-card:active {
    border-color: var(--accent-primary);
    background: var(--bg-card);
}

.package-card.featured {
    border-color: var(--accent-primary);
    background: rgba(108, 92, 231, 0.1);
}

.package-badge {
    position: absolute;
    top: 0;
    right: 0;
    background: var(--accent-primary);
    color: white;
    font-size: 10px;
    font-weight: 800;
    padding: 4px 12px;
    border-bottom-left-radius: 12px;
}

.package-credits {
    font-size: 32px;
    font-weight: 800;
    color: var(--accent-secondary);
    line-height: 1;
}

.package-label {
    flex: 1;
    font-size: 16px;
    font-weight: 600;
}

.package-price {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
}

/* PIX PAYMENT */
.pix-qr-container {
    text-align: center;
    margin-bottom: 24px;
}

#pixQrImg {
    width: 200px;
    height: 200px;
    background: white;
    padding: 10px;
    border-radius: var(--radius-md);
    margin-bottom: 12px;
}

.pix-timer {
    font-size: 13px;
    color: var(--text-muted);
}

#pixCountdown {
    color: var(--danger);
    font-weight: 700;
}

.pix-copy-paste {
    margin-bottom: 20px;
}

.pix-copy-paste label {
    display: block;
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 6px;
}

#pixCode {
    width: 100%;
    height: 60px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 12px;
    padding: 10px;
    margin-bottom: 12px;
    resize: none;
    font-family: monospace;
}

.success-icon {
    font-size: 64px;
    text-align: center;
    margin-bottom: 16px;
}

#paymentSuccess h3 {
    text-align: center;
    margin-bottom: 12px;
}

#paymentSuccess p {
    text-align: center;
    color: var(--text-secondary);
    margin-bottom: 24px;
}

.action-btn {
    width: 100%;
    padding: 14px;
    border-radius: var(--radius-md);
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

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

.text-btn {
    width: 100%;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 14px;
    margin-top: 16px;
    cursor: pointer;
}

/* ============================================
   LASER SCAN ANIMATION
   ============================================ */
.laser-scan-container {
    position: relative;
    overflow: hidden;
    width: 100%;
    height: 100%;
}

.laser-scan-line {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 4px;
    background: linear-gradient(180deg, transparent, var(--accent-secondary), var(--accent-primary), transparent);
    box-shadow: 0 0 15px var(--accent-primary);
    z-index: 100;
    pointer-events: none;
    opacity: 0;
}

.laser-scan-line.animating {
    animation: laserScanAnim 2s ease-in-out;
    opacity: 1;
}

@keyframes laserScanAnim {
    0% {
        top: 0;
        opacity: 1;
    }

    50% {
        top: 100%;
        opacity: 1;
    }

    100% {
        top: 0;
        opacity: 0;
    }
}

/* ============================================
   PROTECTED FOLDERS & PIN MODAL
   ============================================ */
.doc-item.folder.locked .folder-icon::after {
    content: '🔒';
    position: absolute;
    top: -5px;
    right: -5px;
    font-size: 14px;
    background: var(--bg-primary);
    padding: 2px;
    border-radius: 50%;
    box-shadow: var(--shadow-sm);
}

.pin-modal {
    padding: 24px;
    max-width: 320px;
    margin: 30% auto;
    border-radius: var(--radius-xl);
    background: var(--bg-secondary);
}

.pin-display {
    margin: 20px 0;
    text-align: center;
}

.pin-display input {
    width: 100%;
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 15px;
    color: var(--text-primary);
    font-size: 24px;
    text-align: center;
    letter-spacing: 10px;
}

.pin-keypad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

.pin-keypad button {
    aspect-ratio: 1;
    border: none;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 20px;
    font-weight: 600;
    border-radius: 50%;
    cursor: pointer;
    transition: var(--transition);
}

.pin-keypad button:active {
    background: var(--accent-primary);
    transform: scale(0.9);
}

.pin-keypad button.clear {
    color: var(--danger);
}

.pin-keypad button.confirm {
    background: var(--accent-gradient);
    color: white;
}