:root {
    /* Paleta Light Mode */
    --bg-app: #f8fafc;
    /* Fondo general */
    --bg-panel: #ffffff;
    /* Fondo de paneles */
    --bg-canvas: #e2e8f0;
    /* Fondo del área de trabajo (grisáceo) */
    --border: #e2e8f0;
    /* Color de bordes sutil */
    --text-main: #1e293b;
    /* Texto oscuro */
    --text-muted: #64748b;
    /* Texto secundario */

    --primary: #6366f1;
    /* Indigo */
    --primary-hover: #4f46e5;
    --danger: #ef4444;

    --radius: 12px;
    --header-height: 64px;
    --sidebar-width: 320px;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05);

    /* Dark Mode Defaults (can be toggled by body class) */
}

body.dark {
    --bg-app: #0f172a;
    --bg-panel: #1e293b;
    --bg-canvas: #334155;
    --border: #334155;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
}

body.dark .crop-overlay {
    background: rgba(2, 6, 23, 0.35);
}

body.dark .crop-selection {
    background: rgba(99, 102, 241, 0.22);
    box-shadow: inset 0 0 0 1px rgba(226, 232, 240, 0.35);
}

body.dark .crop-handle {
    background: #0f172a;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', system-ui, sans-serif;
}

body {
    background-color: var(--bg-app);
    color: var(--text-main);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* --- HEADER --- */
.editor-header {
    height: var(--header-height);
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    flex-shrink: 0;
    z-index: 10;
}

.brand {
    font-weight: 800;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-main);
    text-decoration: none;
}

.brand i {
    color: var(--primary);
    font-size: 1.4rem;
}

.brand-logo {
    height: 26px;
    width: auto;
    object-fit: contain;
}

.header-controls {
    display: flex;
    gap: 12px;
    align-items: center;
}

/* --- LAYOUT PRINCIPAL --- */
.editor-layout {
    flex: 1;
    display: flex;
    height: calc(100vh - var(--header-height));
}

/* --- SIDEBAR DE HERRAMIENTAS (Izquierda) --- */
.tools-sidebar {
    width: var(--sidebar-width);
    background: var(--bg-panel);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
    z-index: 5;
}

/* Tabs de Navegación */
.tabs-nav {
    display: flex;
    padding: 0 5px;
    border-bottom: 1px solid var(--border);
}

.tab-btn {
    flex: 1;
    background: transparent;
    border: none;
    padding: 16px 0;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.tab-btn:hover {
    color: var(--primary);
    background: rgba(99, 102, 241, 0.05);
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.tab-btn i {
    font-size: 1.1rem;
}

/* Contenido de Paneles */
.panels-wrapper {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

.tool-panel {
    display: none;
    animation: fadeIn 0.3s ease;
}

.tool-panel.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Grupos de Control */
.control-section {
    margin-bottom: 32px;
}

.section-title {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* UI Components */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 2px 5px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.btn-primary:disabled {
    background: var(--text-muted);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.btn-secondary {
    background: var(--bg-panel);
    border-color: var(--border);
    color: var(--text-main);
}

.btn-secondary:hover {
    border-color: #cbd5e1;
    background: var(--bg-app);
}

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    padding: 8px;
}

.btn-ghost:hover {
    color: var(--text-main);
    background: rgba(0, 0, 0, 0.05);
}

/* Grid de Botones Icono */
.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.icon-action {
    background: var(--bg-app);
    border: 1px solid var(--border);
    padding: 12px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: var(--text-main);
    font-weight: 500;
    font-size: 0.9rem;
    cursor: pointer;
    transition: 0.2s;
}

.icon-action:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--bg-panel);
}

/* Sliders */
.slider-group {
    margin-bottom: 20px;
}

.slider-label {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: 8px;
    color: var(--text-main);
}

.slider-val {
    font-family: monospace;
    color: var(--primary);
}

input[type=range] {
    width: 100%;
    height: 6px;
    background: #e2e8f0;
    border-radius: 4px;
    outline: none;
    -webkit-appearance: none;
    cursor: pointer;
}

input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    background: white;
    border: 2px solid var(--primary);
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: 0.2s;
}

input[type=range]::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

/* Filtros Grid */
.filters-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.filter-card {
    aspect-ratio: 1;
    border-radius: 8px;
    overflow: hidden;
    position: relative;
    border: 2px solid transparent;
    cursor: pointer;
    transition: 0.2s;
    background: #000;
}

.filter-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0.8;
    transition: 0.3s;
}

.filter-card:hover img {
    opacity: 1;
}

.filter-card span {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    font-size: 0.7rem;
    text-align: center;
    padding: 4px 0;
    font-weight: 600;
}

.filter-card.active {
    border-color: var(--primary);
    transform: scale(0.95);
}

.filter-card.active img {
    opacity: 1;
}

/* Inputs Text */
.input-row {
    display: flex;
    gap: 10px;
    align-items: center;
}

.input-wrapper {
    position: relative;
    flex: 1;
}

.input-wrapper input,
.input-wrapper select {
    width: 100%;
    padding: 10px 30px 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.9rem;
    outline: none;
    transition: 0.2s;
    background: var(--bg-panel);
    color: var(--text-main);
}

.input-wrapper input:focus,
.input-wrapper select:focus {
    border-color: var(--primary);
}

.input-wrapper span {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 0.8rem;
    pointer-events: none;
}

.chip-row {
    display: flex;
    gap: 8px;
}

.chip-btn {
    border: 1px solid var(--border);
    background: var(--bg-app);
    color: var(--text-main);
    font-size: 0.8rem;
    font-weight: 600;
    padding: 8px 10px;
    border-radius: 999px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.chip-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.chip-btn.active {
    background: rgba(99, 102, 241, 0.15);
    border-color: var(--primary);
    color: var(--primary);
}

/* Toggles / Checkbox estilo switch */
.switch-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    background: var(--bg-app);
    border-radius: 8px;
    border: 1px solid var(--border);
    margin-bottom: 12px;
    cursor: pointer;
}

.switch-label {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-main);
}

.toggle-switch {
    position: relative;
    width: 40px;
    height: 22px;
    background: #cbd5e1;
    border-radius: 20px;
    transition: 0.3s;
}

.toggle-switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    background: white;
    border-radius: 50%;
    transition: 0.3s;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

input:checked+.toggle-switch {
    background: var(--primary);
}

input:checked+.toggle-switch::after {
    transform: translateX(18px);
}


/* --- CANVAS --- */
.canvas-container {
    flex: 1;
    background-color: var(--bg-canvas);
    /* Patrón de transparencia */
    background-image:
        linear-gradient(45deg, #cbd5e1 25%, transparent 25%),
        linear-gradient(-45deg, #cbd5e1 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #cbd5e1 75%),
        linear-gradient(-45deg, transparent 75%, #cbd5e1 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    overflow: hidden;
    position: relative;
    user-select: none;
}

.image-wrapper {
    position: relative;
    overflow: hidden;
    box-shadow: 0 20px 50px -10px rgba(0, 0, 0, 0.15);
    line-height: 0;
    border-radius: 4px;
    max-width: 100%;
    max-height: 100%;
    transition: transform 0.3s ease;
    pointer-events: auto;
}

.target-img {
    max-width: 100%;
    max-height: 85vh;
    display: block;
    object-fit: contain;
    transition: filter 0.2s ease;
    pointer-events: none;
}

.crop-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.12);
    pointer-events: auto;
    cursor: crosshair;
}

.crop-selection {
    position: absolute;
    border: 2px solid var(--primary);
    background: rgba(99, 102, 241, 0.15);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.45);
    cursor: move;
    min-width: 24px;
    min-height: 24px;
}

.crop-handle {
    position: absolute;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #ffffff;
    border: 2px solid var(--primary);
    z-index: 2;
}

.handle-nw {
    top: -7px;
    left: -7px;
    cursor: nwse-resize;
}

.handle-ne {
    top: -7px;
    right: -7px;
    cursor: nesw-resize;
}

.handle-sw {
    bottom: -7px;
    left: -7px;
    cursor: nesw-resize;
}

.handle-se {
    bottom: -7px;
    right: -7px;
    cursor: nwse-resize;
}

/* Upload Overlay */
.landing-zone {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-app);
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
}

.landing-content {
    text-align: center;
}

.landing-icon {
    font-size: 4rem;
    color: var(--primary);
    margin-bottom: 20px;
}

.landing-logo {
    width: 92px;
    height: auto;
    object-fit: contain;
    margin-bottom: 18px;
}

.landing-title {
    font-size: 2rem;
    font-weight: 800;
    margin-bottom: 10px;
    color: var(--text-main);
}

.landing-desc {
    color: var(--text-muted);
    margin-bottom: 30px;
}

@media (max-width: 1100px) {
    :root {
        --sidebar-width: 300px;
    }

    .editor-header {
        padding: 0 16px;
    }

    .panels-wrapper {
        padding: 16px;
    }

    .canvas-container {
        padding: 24px;
    }
}

@media (max-width: 900px) {
    body {
        overflow: auto;
        height: auto;
        min-height: 100vh;
    }

    .editor-layout {
        flex-direction: column;
        height: auto;
        min-height: calc(100vh - var(--header-height));
    }

    .tools-sidebar {
        width: 100%;
        border-right: 0;
        border-bottom: 1px solid var(--border);
        box-shadow: none;
        max-height: 52vh;
    }

    .tabs-nav {
        position: sticky;
        top: 0;
        z-index: 6;
        background: var(--bg-panel);
    }

    .panels-wrapper {
        max-height: calc(52vh - 62px);
        padding: 12px;
    }

    .canvas-container {
        min-height: 50vh;
        padding: 14px;
    }

    .target-img {
        max-height: 55vh;
    }

    .filters-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

@media (max-width: 640px) {
    .editor-header {
        height: auto;
        padding: 10px 12px;
        flex-wrap: wrap;
        gap: 8px;
    }

    .brand {
        font-size: 1.1rem;
    }

    .brand-logo {
        height: 24px;
    }

    .header-controls {
        width: 100%;
        justify-content: flex-end;
    }

    .header-controls .btn {
        padding: 8px 10px;
        font-size: 0.84rem;
    }

    .tools-sidebar {
        max-height: 58vh;
    }

    .tab-btn {
        padding: 10px 0;
        font-size: 0.78rem;
        gap: 4px;
    }

    .tab-btn i {
        font-size: 1rem;
    }

    .grid-2 {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .filters-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 8px;
    }

    .canvas-container {
        padding: 10px;
        min-height: 42vh;
    }

    .target-img {
        max-height: 45vh;
    }

    .landing-logo {
        width: 76px;
    }

    .landing-title {
        font-size: 1.5rem;
    }

    .landing-desc {
        font-size: 0.95rem;
        margin-bottom: 18px;
        padding: 0 16px;
    }
}
