/* ==============================================
   Variables Globales y Reset
   ============================================== */
:root {
    --bg: #0f172a;
    --card: #1e293b;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --text: #f8fafc;
    --text-muted: #94a3b8;
    --border: #334155;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #eab308;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: system-ui, -apple-system, sans-serif;
}

body {
    background-color: var(--bg);
    color: var(--text);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ==============================================
   Header
   ============================================== */
header {
    padding: 1rem 2rem;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

header h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--accent);
}

/* ==============================================
   Main Content Layout
   ============================================== */
main {
    flex: 1;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

/* ==============================================
   Zona de Subida (Upload Section)
   ============================================== */
.drop-zone {
    border: 2px dashed var(--accent);
    border-radius: 1rem;
    padding: 2.5rem;
    text-align: center;
    background: rgba(59, 130, 246, 0.05);
    cursor: pointer;
    transition: all 0.2s;
}

.drop-zone.dragover {
    background: rgba(59, 130, 246, 0.2);
    border-color: var(--accent-hover);
    transform: scale(1.01);
}

/* ==============================================
   Cola de Espera (Pending Preview)
   ============================================== */
.pending-preview-container {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 1rem;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.pending-grid {
    display: flex;
    gap: 0.75rem;
    overflow-x: auto;
    padding: 0.25rem 0;
}

.pending-thumb {
    width: 90px;
    height: 90px;
    border-radius: 0.5rem;
    border: 1px solid var(--border);
    position: relative;
    flex-shrink: 0;
    background: var(--bg);
    overflow: hidden;
}

.pending-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.pending-thumb .remove-pending {
    position: absolute;
    top: 3px;
    right: 3px;
    background: rgba(239, 68, 68, 0.85);
    color: white;
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    z-index: 10;
}

.pending-thumb .remove-pending:hover {
    background: #dc2626;
}

/* ==============================================
   Panel de Configuración
   ============================================== */
.config-panel {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 1rem;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.options-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
}

.option-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 600;
    cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
    width: 1.2rem;
    height: 1.2rem;
    accent-color: var(--accent);
    cursor: pointer;
}

/* ==============================================
   Editor y Canvas
   ============================================== */
.editor-container {
    display: none;
    /* Se activa por JS */
    grid-template-columns: 1fr 320px;
    gap: 1.5rem;
}

.main-view {
    background: var(--card);
    border-radius: 1rem;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    align-items: center;
    justify-content: center;
    position: relative;
    border: 1px solid var(--border);
}

.canvas-wrapper {
    position: relative;
    max-width: 100%;
    max-height: 500px;
    overflow: hidden;
    border-radius: 0.5rem;
    /* Fondo ajedrezado para transparencia */
    background-image: linear-gradient(45deg, #334155 25%, transparent 25%), linear-gradient(-45deg, #334155 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #334155 75%), linear-gradient(-45deg, transparent 75%, #334155 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
    user-select: none;
}

canvas {
    display: block;
    max-width: 100%;
    max-height: 500px;
    object-fit: contain;
}

/* ==============================================
   Panel de Controles Laterales
   ============================================== */
.controls-panel {
    background: var(--card);
    border-radius: 1rem;
    padding: 1.25rem;
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

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

.control-group label {
    font-size: 0.875rem;
    color: var(--text-muted);
    display: flex;
    justify-content: space-between;
}

input[type="number"] {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.5rem;
    border-radius: 0.5rem;
    outline: none;
    width: 100%;
}

/* ==============================================
   Carrusel de Miniaturas
   ============================================== */
.carousel-container {
    display: flex;
    align-items: center;
    gap: 1rem;
    width: 100%;
    overflow-x: auto;
    padding: 0.5rem 0;
}

.thumb-list {
    display: flex;
    gap: 0.5rem;
}

.thumb {
    width: 80px;
    height: 80px;
    border-radius: 0.5rem;
    border: 2px solid var(--border);
    overflow: hidden;
    cursor: pointer;
    position: relative;
    flex-shrink: 0;
    transition: border-color 0.2s;
}

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

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

.thumb-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    border: none;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

/* ==============================================
   Botones Generales
   ============================================== */
.btn {
    background: var(--accent);
    color: white;
    border: none;
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    text-decoration: none;
    font-size: 1rem;
}

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

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

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

.btn-crop {
    background: var(--warning);
    color: #000;
}

.btn-crop:hover {
    background: #ca8a04;
}

.btn-crop.active {
    background: var(--danger);
    color: white;
}

/* ==============================================
   Overlay de Progreso (Cargando)
   ============================================== */
.progress-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(4px);
    display: none;
    /* Se activa por JS */
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.progress-card {
    background: var(--card);
    border: 1px solid var(--border);
    padding: 2rem;
    border-radius: 1rem;
    width: 90%;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    text-align: center;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
}

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

.progress-bar {
    height: 100%;
    width: 0%;
    /* Se anima por JS */
    background: var(--accent);
    transition: width 0.2s ease;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 4px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto;
}

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