/* ==========================================
   Swiss Design / Dashboard Layout CSS
   ========================================== */

:root {
    /* Paleta Suiza / Dark Mode Elegante */
    --bg-app: #0f0f12;
    /* Fondo principal casi negro */
    --bg-panel: #18181b;
    /* Paneles laterales */
    --bg-surface: #27272a;
    /* Inputs y elementos UI */

    --primary: #6366f1;
    /* Acento principal (Indigo) */
    --primary-hover: #4f46e5;

    --text-main: #ffffff;
    --text-muted: #a1a1aa;
    --text-dim: #52525b;

    --border-subtle: #27272a;
    /* Bordes separadores */
    --border-focus: #6366f1;

    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 20px;

    --shadow-soft: 0 4px 20px rgba(0, 0, 0, 0.2);

    /* Layout */
    --navbar-height: 60px;
    --sidebar-width: 400px;
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-app);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
    /* App-like feel */
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}

/* ==========================================
   Navbar
   ========================================== */
.navbar {
    height: var(--navbar-height);
    background-color: var(--bg-app);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 100;
}

.navbar-left .brand {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    color: var(--text-main);
}

.logo-box {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--primary), #818cf8);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: white;
}

.brand-info {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.brand-name {
    font-weight: 600;
    font-size: 15px;
}

.brand-desc {
    font-size: 11px;
    color: var(--text-muted);
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.navbar-right .btn-text {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    transition: color 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
}

.navbar-right .btn-text:hover {
    color: var(--text-main);
}

/* ==========================================
   App Layout
   ========================================== */
.app-layout {
    display: flex;
    height: calc(100vh - var(--navbar-height));
    margin-top: var(--navbar-height);
    width: 100%;
}

/* Sidebar (Config) */
.config-sidebar {
    width: var(--sidebar-width);
    max-width: 100%;
    background-color: var(--bg-panel);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow-y: auto;
    overflow-x: hidden;
    /* Evitar scroll horizontal */
}

.sidebar-header {
    padding: 32px 32px 16px;
}

.sidebar-header h2 {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.5px;
    margin-bottom: 4px;
}

.sidebar-header p {
    color: var(--text-muted);
    font-size: 14px;
}

.sidebar-content {
    padding: 0 32px 40px;
}

/* Sections */
.config-section {
    margin-bottom: 24px;
}

.section-title {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 20px;
}

/* Collapsible Sections */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    padding: 12px 0;
    margin-bottom: 0;
    border-radius: var(--radius-sm);
    transition: color 0.2s;
}

.section-header:hover {
    color: var(--primary);
}

.section-header .section-title {
    margin-bottom: 0;
}

.section-header i {
    font-size: 12px;
    color: var(--text-dim);
    transition: transform 0.3s ease;
}

.section-header.expanded i {
    transform: rotate(180deg);
}

.section-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s ease, padding 0.3s ease;
    padding-top: 0;
}

.section-content.expanded {
    max-height: 2000px;
    /* Suficiente para cualquier contenido */
    padding-top: 16px;
}

.divider {
    border: 0;
    height: 1px;
    background: var(--border-subtle);
    margin: 24px 0;
}

/* Inputs */
.input-group {
    margin-bottom: 16px;
}

.toggle-row+.input-group {
    margin-top: 24px;
}

.input-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 8px;
    color: var(--text-main);
}

.form-input,
.form-select {
    width: 100%;
    background-color: var(--bg-surface);
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    color: var(--text-main);
    font-family: inherit;
    font-size: 14px;
    transition: all 0.2s;
}

.form-input:focus,
.form-select:focus {
    outline: none;
    background-color: var(--bg-app);
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

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

/* Colors Presets */
.color-presets-grid {
    display: flex;
    gap: 10px;
}

.color-preset {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid transparent;
    background: var(--c);
    cursor: pointer;
    transition: transform 0.2s;
}

.color-preset:hover {
    transform: scale(1.1);
}

.color-preset.active {
    border-color: white;
    box-shadow: 0 0 0 2px var(--bg-panel), 0 0 0 4px var(--c);
}

.advanced-colors-toggle {
    font-size: 12px;
    color: var(--primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
    margin-top: 10px;
}

.advanced-colors-panel {
    margin-top: 10px;
    background: var(--bg-surface);
    padding: 12px;
    border-radius: var(--radius-sm);
}

/* Fix para evitar desbordamiento en colores avanzados */
.advanced-colors-panel .grid-2 {
    grid-template-columns: 1fr;
    /* Una sola columna para que quepan bien */
    gap: 12px;
}

.color-input-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
}

.color-input-wrapper input[type="color"] {
    width: 44px;
    height: 38px;
    border: none;
    background: var(--bg-surface);
    cursor: pointer;
    border-radius: var(--radius-sm);
    padding: 4px;
}

.color-input-wrapper input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 2px;
}

.color-input-wrapper input[type="color"]::-webkit-color-swatch {
    border-radius: 4px;
    border: none;
}

.color-input-wrapper input[type="text"],
.color-text-input {
    flex: 1;
    min-width: 0;
    /* Evitar desbordamiento en flex */
    max-width: 100%;
    background-color: var(--bg-surface);
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    color: var(--text-main);
    font-family: 'Monaco', 'Consolas', monospace;
    font-size: 13px;
    transition: all 0.2s;
}

.color-input-wrapper input[type="text"]:focus,
.color-text-input:focus {
    outline: none;
    background-color: var(--bg-app);
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

input[type="color"] {
    width: 30px;
    height: 36px;
    border: none;
    background: none;
    cursor: pointer;
}

/* Volume Slider */
.volume-slider {
    width: 100%;
    height: 8px;
    background: var(--bg-surface);
    border-radius: 4px;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    margin-top: 8px;
}

.volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    background: var(--primary);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(99, 102, 241, 0.4);
    transition: transform 0.2s;
}

.volume-slider::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

.volume-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: var(--primary);
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

/* Switch */
.toggle-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 16px;
    font-size: 13px;
    font-weight: 500;
}

.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

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

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--bg-surface);
    transition: .3s;
    border-radius: 34px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .3s;
    border-radius: 50%;
}

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

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

/* Button */
.btn-primary {
    width: 100%;
    background-color: var(--primary);
    color: white;
    border: none;
    padding: 14px;
    border-radius: var(--radius-md);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    margin-top: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

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

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

/* ==========================================
   Preview Area
   ========================================== */
.preview-area {
    flex: 1;
    background-color: #0d0d10;
    /* Fondo oscuro sólido o patrón suave */
    background-image: radial-gradient(circle at center, #1a1a1e 1px, transparent 1px);
    background-size: 24px 24px;
    display: flex;
    flex-direction: column;
    padding: 0;
    /* Sin padding para usar todo el espacio */
    position: relative;
    overflow: hidden;
}

.preview-wrapper {
    width: 100%;
    height: 100%;
    /* Ocupar toda la altura */
    max-width: none;
    /* Sin límite de ancho */
    background: var(--bg-panel);
    border-radius: 0;
    /* Sin bordes redondeados */
    box-shadow: none;
    border: none;
    display: flex;
    flex-direction: column;
}

.preview-header {
    padding: 12px 20px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    /* No encoger header */
}

.preview-header h3 {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
}

.device-indicators {
    display: flex;
    gap: 6px;
}

.dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.red {
    background: #ef4444;
}

.yellow {
    background: #f59e0b;
}

.green {
    background: #10b981;
}

.preview-stage {
    flex: 1;
    /* Ocupar todo el espacio restante vertical */
    width: 100%;
    padding: 0;
    background: black;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.preview-stage iframe {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
}

.empty-state {
    text-align: center;
    color: var(--text-muted);
}

.empty-state i {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.3;
}

/* Output Code Tabs */
.output-panel {
    border-top: 1px solid var(--border-subtle);
    background: var(--bg-panel);
}

.output-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-subtle);
}

.tab-btn {
    flex: 1;
    background: none;
    border: none;
    padding: 12px;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border-bottom: 2px solid transparent;
}

.tab-btn.active {
    color: var(--text-main);
    border-bottom-color: var(--primary);
    background: rgba(99, 102, 241, 0.05);
}

.tab-content {
    padding: 0;
}

.code-block {
    position: relative;
    background: #09090b;
    padding: 20px;
}

code {
    font-family: 'Monaco', 'Consolas', monospace;
    font-size: 13px;
    color: #a5b4fc;
    word-break: break-all;
    display: block;
    max-height: 100px;
    overflow-y: auto;
}

.copy-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    color: var(--text-main);
    width: 32px;
    height: 32px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

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

/* Mobile Toggle */
.mobile-preview-toggle {
    display: none;
}

/* ==========================================
   Responsive
   ========================================== */
@media (max-width: 900px) {
    .app-layout {
        flex-direction: column;
        height: auto;
        overflow: auto;
    }

    body {
        overflow: auto;
    }

    .config-sidebar {
        width: 100%;
        height: auto;
        border-right: none;
        overflow: visible;
    }

    .preview-area {
        padding: 0;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        height: auto;
        background: transparent;
        z-index: 200;
        pointer-events: none;
        /* Dejar clickear abajo si está colapsado */
    }

    .mobile-preview-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 100%;
        padding: 14px;
        background: var(--primary);
        color: white;
        border: none;
        font-weight: 600;
        pointer-events: auto;
        gap: 8px;
        box-shadow: 0 -4px 10px rgba(0, 0, 0, 0.2);
    }

    .preview-wrapper {
        border-radius: 0;
        transform: translateY(100%);
        transition: transform 0.3s ease;
        background: var(--bg-panel);
        pointer-events: auto;
        height: 80vh;
        /* Altura máxima en móvil */
        display: none;
    }

    .preview-wrapper.visible {
        transform: translateY(0);
        display: flex;
    }
}

/* ==========================================
   Toast Notifications
   ========================================== */
@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOutRight {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

/* Button disabled state */
.btn-primary:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
}

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