:root {
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --text-main: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --danger-color: #ef4444;
    --success-color: #22c55e;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --radius: 12px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    display: flex;
    justify-content: center;
    min-height: 100vh;
    padding: 2rem;
}

.app-container {
    width: 100%;
    max-width: 800px;
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    padding: 2.5rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
    height: fit-content;
}

/* Header */
.app-header {
    text-align: center;
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}

.logo i {
    font-size: 1.8rem;
}

.logo h1 {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--text-main);
}

.app-header p {
    color: var(--text-secondary);
}

/* Drop Zone */
.drop-zone {
    border: 2px dashed var(--border-color);
    border-radius: var(--radius);
    padding: 3rem 2rem;
    text-align: center;
    transition: all 0.3s ease;
    background-color: #f8fafc;
    cursor: pointer;
}

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

.drop-zone-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    pointer-events: none;
}

.drop-zone-content input,
.drop-zone-content label {
    pointer-events: auto;
}

.cloud-icon {
    font-size: 3.5rem;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}

.drop-zone h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

.file-btn {
    background-color: var(--primary-color);
    color: white;
    padding: 0.75rem 1.5rem;
    border-radius: 50px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s;
    display: inline-block;
    border: none;
}

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

/* File List */
.file-list-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.file-list-container.hidden {
    display: none;
}

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

.list-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

.text-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    transition: background 0.2s;
}

.text-btn:hover {
    background-color: #f1f5f9;
}

.text-btn.danger {
    color: var(--danger-color);
}

.text-btn.danger:hover {
    background-color: #fee2e2;
}

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

.text-btn.primary-text:hover {
    background-color: #eff6ff;
}

.header-actions {
    display: flex;
    gap: 0.5rem;
}

.file-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    max-height: 400px;
    overflow-y: auto;
    padding-right: 0.5rem;
}

.file-item {
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.75rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
    position: relative;
    overflow: hidden;
}

.file-item:hover {
    box-shadow: var(--shadow-sm);
    border-color: #cbd5e1;
}

.file-item.dragging {
    opacity: 0.5;
    background: #f1f5f9;
    border: 2px dashed var(--primary-color);
}

.file-handle {
    color: var(--text-secondary);
    cursor: grab;
    padding: 0.5rem;
    display: flex;
    align-items: center;
}

.file-handle:active {
    cursor: grabbing;
}

.file-thumbnail {
    width: 60px;
    height: 85px;
    /* Aspecto ~A4 */
    background-color: #e2e8f0;
    border-radius: 4px;
    overflow: hidden;
    flex-shrink: 0;
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
}

.file-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    /* Ajustar imagen dentro */
    background: white;
}

.file-thumbnail i {
    font-size: 1.5rem;
    color: var(--text-secondary);
}

.file-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    overflow: hidden;
}

.file-name {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-size {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.actions {
    display: flex;
    gap: 0.5rem;
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 6px;
    transition: all 0.2s;
    font-size: 1rem;
}

.icon-btn:hover {
    background-color: #f1f5f9;
    color: var(--primary-color);
}

.icon-btn.remove:hover {
    background-color: #fee2e2;
    color: var(--danger-color);
}

/* Footer Action */
.app-footer {
    display: flex;
    justify-content: center;
    border-top: 1px solid var(--border-color);
    padding-top: 2rem;
}

.action-btn {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 1rem 2.5rem;
    border-radius: 50px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    transition: all 0.2s;
    box-shadow: 0 4px 6px -1px rgba(59, 130, 246, 0.3);
}

.action-btn:hover:not(:disabled) {
    background-color: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 8px -1px rgba(59, 130, 246, 0.4);
}

.action-btn:disabled {
    background-color: #cbd5e1;
    box-shadow: none;
    cursor: not-allowed;
    transform: none;
}

/* Editor Modal */
.editor-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: #e2e8f0;
    z-index: 500;
    display: flex;
    flex-direction: column;
}

.editor-modal.hidden {
    display: none;
}

.editor-header {
    background: white;
    padding: 0.75rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-sm);
    z-index: 10;
}

.editor-title {
    font-weight: 600;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-main);
}

.editor-tools {
    display: flex;
    gap: 0.5rem;
    background: #f1f5f9;
    padding: 0.25rem;
    border-radius: 8px;
}

.separator {
    width: 1px;
    background: #cbd5e1;
    margin: 0 0.25rem;
}

.tool-btn {
    border: none;
    background: transparent;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.tool-btn:hover {
    background: #e2e8f0;
    color: var(--text-main);
}

.tool-btn.active {
    background: white;
    color: var(--primary-color);
    box-shadow: var(--shadow-sm);
    font-weight: 500;
}

.tool-btn.danger:hover {
    color: var(--danger-color);
    background: #fee2e2;
}

.tool-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

.editor-body {
    flex: 1;
    display: flex;
    overflow: hidden;
}

.editor-sidebar {
    width: 200px;
    background: white;
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.thumbnails-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.thumbnail-item {
    cursor: pointer;
    border: 2px solid transparent;
    border-radius: 4px;
    padding: 4px;
    transition: all 0.2s;
    opacity: 0.8;
}

.thumbnail-item:hover {
    background: #f1f5f9;
    opacity: 1;
}

.thumbnail-item.active {
    border-color: var(--primary-color);
    background: #eff6ff;
    opacity: 1;
}

.thumbnail-item.dragging {
    opacity: 0.4;
    transform: scale(0.95);
}

.thumbnail-item.over {
    border-top: 4px solid var(--primary-color);
}

.thumbnail-item canvas {
    width: 100%;
    height: auto;
    border: 1px solid #e2e8f0;
    background: white;
    display: block;
}

.thumbnail-number {
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

.source-label {
    position: absolute;
    top: 4px;
    right: 4px;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    font-size: 9px;
    padding: 2px 5px;
    border-radius: 4px;
    pointer-events: none;
    backdrop-filter: blur(2px);
    z-index: 5;
}

.editor-main-view {
    flex: 1;
    background: #cbd5e1;
    overflow: auto;
    display: flex;
    justify-content: center;
    padding: 2rem;
    position: relative;
}

.canvas-wrapper {
    position: relative;
    box-shadow: var(--shadow-md);
    background: white;
}

.annotations-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: auto;
    /* Permitir interacción */
}

/* Elementos de anotación */
.annotation-input {
    position: absolute;
    background: transparent;
    border: 1px dashed var(--primary-color);
    font-family: Helvetica, sans-serif;
    /* Standard PDF font */
    color: black;
    padding: 2px;
    outline: none;
    z-index: 10;
    /* font-size dinámico vía JS */
}

.annotation-rect {
    position: absolute;
    background-color: white;
    border: 1px solid #eee;
    z-index: 5;
    cursor: grab;
}

/* Interactividad Anotaciones */
.annotation-item {
    cursor: grab;
    transition: box-shadow 0.2s;
    user-select: none;
    /* Evitar selección de texto nativo al arrastrar */
}

.annotation-item:hover {
    box-shadow: 0 0 0 1px var(--primary-color);
}

.annotation-item:active {
    cursor: grabbing;
}


/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

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

.loader {
    width: 48px;
    height: 48px;
    border: 5px solid var(--primary-color);
    border-bottom-color: transparent;
    border-radius: 50%;
    display: inline-block;
    box-sizing: border-box;
    animation: rotation 1s linear infinite;
    margin-bottom: 1rem;
}

@keyframes rotation {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* Scrollbar bonito */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background-color: #cbd5e1;
    border-radius: 20px;
}