@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700&display=swap');

:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-light: #e0e7ff;
    --success: #10b981;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --bg-main: #f8fafc;
    --bg-card: #ffffff;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --radius-lg: 16px;
    --radius-md: 12px;
    --radius-sm: 8px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
    --font: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg-main: #0b0f19;
        --bg-card: #161e2e;
        --text-main: #f3f4f6;
        --text-muted: #9ca3af;
        --border-color: #243049;
        --primary-light: rgba(79, 70, 229, 0.15);
        --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.5);
        --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -2px rgba(0, 0, 0, 0.3);
        --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -4px rgba(0, 0, 0, 0.3);
    }
}

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

body {
    font-family: var(--font);
    background-color: var(--bg-main);
    color: var(--text-main);
    line-height: 1.5;
    padding: 2rem 1rem;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

.container {
    width: 100%;
    max-width: 960px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 0.5rem;
}

.logo-container {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 80px;
    height: 80px;
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    margin-bottom: 1rem;
    box-shadow: var(--shadow-md);
    overflow: hidden;
    padding: 8px;
}

.logo-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

header h1 {
    font-size: 2.25rem;
    font-weight: 700;
    letter-spacing: -0.025em;
    background: linear-gradient(135deg, var(--text-main), var(--text-muted));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 0.5rem;
}

header p {
    color: var(--text-muted);
    font-size: 1rem;
    max-width: 500px;
    margin: 0 auto;
}

/* Main Area */
.app-card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
    transition: var(--transition);
}

/* Dropzone */
.dropzone {
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-md);
    padding: 3rem 2rem;
    text-align: center;
    cursor: pointer;
    background-color: rgba(248, 250, 252, 0.02);
    transition: var(--transition);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    position: relative;
    overflow: hidden;
}

.dropzone:hover, .dropzone.dragover {
    border-color: var(--primary);
    background-color: var(--primary-light);
}

.dropzone-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background-color: var(--bg-main);
    border: 1px solid var(--border-color);
    color: var(--primary);
    transition: var(--transition);
}

.dropzone:hover .dropzone-icon, .dropzone.dragover .dropzone-icon {
    transform: scale(1.1);
    background-color: var(--primary);
    color: white;
    border-color: var(--primary);
    box-shadow: 0 8px 16px -4px rgba(79, 70, 229, 0.3);
}

.dropzone h3 {
    font-size: 1.25rem;
    font-weight: 600;
}

.dropzone p {
    color: var(--text-muted);
    font-size: 0.875rem;
}

.file-input {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

/* Actions Panel */
.actions-panel {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid var(--border-color);
}

.actions-panel.hidden {
    display: none !important;
}

.actions-left {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.file-count-badge {
    font-weight: 600;
    color: var(--primary);
    font-size: 1.125rem;
}

.actions-right {
    display: flex;
    gap: 0.75rem;
}

/* Buttons */
.btn {
    font-family: var(--font);
    font-weight: 600;
    font-size: 0.875rem;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: var(--transition);
}

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

.btn-secondary:hover {
    background-color: var(--bg-main);
    border-color: var(--text-muted);
}

.btn-danger {
    background-color: transparent;
    border-color: var(--border-color);
    color: var(--danger);
}

.btn-danger:hover {
    background-color: rgba(239, 68, 68, 0.08);
    border-color: var(--danger);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), #6366f1);
    color: white;
    box-shadow: 0 4px 10px -2px rgba(79, 70, 229, 0.3);
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--primary-hover), #4f46e5);
    box-shadow: 0 6px 14px -2px rgba(79, 70, 229, 0.4);
}

.btn-primary:disabled {
    background: var(--border-color);
    color: var(--text-muted);
    cursor: not-allowed;
    box-shadow: none;
}

/* PDF List Grid */
.pdf-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1.5rem;
    min-height: 100px;
    transition: var(--transition);
}

/* PDF Card */
.pdf-card {
    background-color: var(--bg-main);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    position: relative;
    cursor: grab;
    user-select: none;
    transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.pdf-card:active {
    cursor: grabbing;
}

.pdf-card.dragging {
    opacity: 0.5;
    transform: scale(0.95);
    border-color: var(--primary);
    box-shadow: var(--shadow-sm);
}

.pdf-card.drag-over {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.pdf-card-preview {
    position: relative;
    aspect-ratio: 3/4;
    background-color: rgba(0, 0, 0, 0.05);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border-bottom: 1px solid var(--border-color);
}

.pdf-card-preview canvas, .pdf-card-preview img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Skeleton Loading for Canvas */
.preview-skeleton {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    color: var(--text-muted);
    background: linear-gradient(90deg, rgba(0,0,0,0.02) 25%, rgba(0,0,0,0.05) 50%, rgba(0,0,0,0.02) 75%);
    background-size: 200% 100%;
    animation: loading-shimmer 1.5s infinite;
}

@keyframes loading-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.pdf-card-details {
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex-grow: 1;
}

.pdf-card-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pdf-card-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.pdf-card-badge {
    background-color: var(--border-color);
    color: var(--text-main);
    padding: 0.125rem 0.5rem;
    border-radius: 9999px;
    font-weight: 500;
}

.pdf-card-actions {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    opacity: 0;
    transition: opacity 0.2s ease;
    z-index: 10;
    display: flex;
    gap: 0.375rem;
}

.pdf-card:hover .pdf-card-actions, .pdf-card:focus-within .pdf-card-actions {
    opacity: 1;
}

.btn-icon-delete {
    width: 32px;
    height: 32px;
    padding: 0;
    border-radius: 50%;
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
}

.btn-icon-delete:hover {
    background-color: var(--border-color);
    color: var(--text-main);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

.btn-icon-delete svg {
    width: 16px;
    height: 16px;
}

.btn-icon-rotate {
    width: 32px;
    height: 32px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background-color: #e11d48; /* Red rose color matching the image rotate button */
    color: white;
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
}

.btn-icon-rotate:hover {
    background-color: #be123c;
    transform: scale(1.05);
    box-shadow: 0 4px 8px rgba(225, 29, 72, 0.3);
}

.btn-icon-rotate svg {
    width: 16px;
    height: 16px;
}

/* Drag Handle */
.drag-handle {
    position: absolute;
    top: 0.5rem;
    left: 0.5rem;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.pdf-card:hover .drag-handle {
    opacity: 1;
}

.drag-handle svg {
    width: 16px;
    height: 16px;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.loading-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.loading-card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 2.5rem;
    text-align: center;
    max-width: 400px;
    width: 90%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border-color);
    border-top: 4px solid var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-text {
    font-weight: 600;
    font-size: 1.125rem;
}

.progress-bar-container {
    width: 100%;
    height: 6px;
    background-color: var(--border-color);
    border-radius: 9999px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    width: 0%;
    background-color: var(--primary);
    border-radius: 9999px;
    transition: width 0.2s ease;
}

/* Notification / Toast */
.toast-container {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    z-index: 1000;
}

.toast {
    background-color: var(--bg-card);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    padding: 1rem 1.5rem;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 500;
    font-size: 0.875rem;
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border-left: 4px solid var(--primary);
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

.toast.toast-error {
    border-left-color: var(--danger);
}

.toast.toast-success {
    border-left-color: var(--success);
}

.toast svg {
    width: 20px;
    height: 20px;
}

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

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

/* Footer / Privacidad */
footer {
    text-align: center;
    margin-top: 1rem;
    padding: 0 1rem;
}

.privacy-note {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    font-size: 0.825rem;
    color: var(--text-muted);
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 0.75rem 1.25rem;
    box-shadow: var(--shadow-sm);
    max-width: 720px;
    margin: 0 auto;
    text-align: left;
}

.privacy-note svg {
    width: 20px;
    height: 20px;
    color: var(--success);
    flex-shrink: 0;
}

@media (max-width: 600px) {
    .privacy-note {
        flex-direction: column;
        text-align: center;
        gap: 0.75rem;
    }
}

/* ==========================================
   PANEL DE SEGURIDAD Y RESTRICCIONES
   ========================================== */

.security-panel {
    background-color: var(--bg-main);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
    transition: var(--transition);
}

.security-panel.hidden {
    display: none !important;
}

.security-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem 1.5rem;
    cursor: pointer;
    background-color: rgba(0, 0, 0, 0.01);
    transition: var(--transition);
    user-select: none;
}

.security-header:hover {
    background-color: rgba(0, 0, 0, 0.03);
}

@media (prefers-color-scheme: dark) {
    .security-header:hover {
        background-color: rgba(255, 255, 255, 0.03);
    }
}

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

.security-title svg {
    width: 20px;
    height: 20px;
    color: var(--primary);
}

.security-toggle-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.security-toggle-icon svg {
    width: 18px;
    height: 18px;
}

/* Estado Expandido */
.security-panel:not(.collapsed-panel) .security-toggle-icon {
    transform: rotate(180deg);
}

.security-content {
    padding: 0 1.5rem 1.5rem 1.5rem;
    border-top: 1px solid transparent;
    opacity: 0;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1), 
                padding 0.3s cubic-bezier(0.4, 0, 0.2, 1), 
                opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.security-panel:not(.collapsed-panel) .security-content {
    border-top-color: var(--border-color);
    padding: 1.5rem;
    opacity: 1;
    max-height: 800px; /* Suficiente para acomodar el contenido expandido */
}

/* Grid de Inputs de Contraseña */
.security-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

@media (max-width: 600px) {
    .security-grid {
        grid-template-columns: 1fr;
        gap: 1.25rem;
    }
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.input-group label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-main);
}

.input-group input[type="password"] {
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background-color: var(--bg-card);
    color: var(--text-main);
    font-family: var(--font);
    transition: var(--transition);
}

.input-group input[type="password"]::placeholder {
    color: var(--text-muted);
    opacity: 0.7;
}

.input-group input[type="password"]:focus {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 3px var(--primary-light);
}

.input-help {
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1.4;
}

/* Sección de Restricciones */
.permissions-section {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px dashed var(--border-color);
}

.permissions-section h4 {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 0.25rem;
}

.permissions-note {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 1.25rem;
}

.permissions-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
}

@media (max-width: 600px) {
    .permissions-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
}

/* Personalización del Checkbox */
.permission-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-main);
    position: relative;
    user-select: none;
}

/* Ocultar checkbox por defecto */
.permission-item input {
    position: absolute;
    opacity: 0;
    cursor: pointer;
    height: 0;
    width: 0;
}

.checkbox-custom {
    position: relative;
    height: 20px;
    width: 20px;
    background-color: var(--bg-card);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

/* Al pasar el ratón */
.permission-item:hover input:not(:disabled) ~ .checkbox-custom {
    border-color: var(--primary);
}

/* Cuando está checked */
.permission-item input:checked ~ .checkbox-custom {
    background-color: var(--primary);
    border-color: var(--primary);
}

/* Marca de verificación interna */
.checkbox-custom:after {
    content: "";
    position: absolute;
    display: none;
    left: 6px;
    top: 2px;
    width: 5px;
    height: 9px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.permission-item input:checked ~ .checkbox-custom:after {
    display: block;
}

/* Estado deshabilitado */
.permission-item input:disabled ~ .checkbox-custom {
    background-color: rgba(0, 0, 0, 0.05);
    border-color: var(--border-color);
    cursor: not-allowed;
}

@media (prefers-color-scheme: dark) {
    .permission-item input:disabled ~ .checkbox-custom {
        background-color: rgba(255, 255, 255, 0.05);
    }
}

.permission-item input:disabled ~ .permission-label-text {
    color: var(--text-muted);
    opacity: 0.6;
    cursor: not-allowed;
}

.permission-item input:disabled ~ .checkbox-custom:after {
    border-color: var(--text-muted);
}

.permission-item input:disabled {
    cursor: not-allowed;
}

