* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
:root {
    /* Paleta Oscura (Slate/Dark Mode) */
    --bg-body: #0b1329;        /* Fondo principal muy oscuro */
    --bg-card: #0f172a;        /* Fondo para canvas-wrapper y sidebar (Slate 900) */
    --bg-canvas: #020617;      /* Lienzo del simulador (Slate 950) */
    
    --text-primary: #f8fafc;    /* Texto principal de alto contraste */
    --text-secondary: #94a3b8;  /* Texto secundario y etiquetas */
    --border-light: #1e293b;    /* Bordes sutiles para tarjetas e inputs */
    
    --shadow-card: 0 20px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.5);
    --radius-card: 28px;
    --radius-btn: 40px;
    
    --gold: #d97706;
    --blue-accent: #3b82f6;
    --blue-hover: #2563eb;
    --green-accent: #10b981;
    --green-hover: #059669;
    
    --font: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
}

body {
    font-family: var(--font);
    background: var(--bg-body);
    color: var(--text-primary);
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    margin: 0;
}

/* ===== MATERIAL ICONS CENTRADO ===== */
.material-icons {
    font-size: 1.2em;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    vertical-align: middle;
    line-height: 1;
}

.nav-logo {
    display: flex;
    align-items: center;
    gap: 10px;
}
.nav-logo svg {
    color: var(--gold);
    flex-shrink: 0;
}
.nav-logo span {
    color: #0d0000;
    font-weight: 700;
    font-size: 17px;
    letter-spacing: -0.02em;
}

/* ===== BOTÓN REGRESAR ===== */
.btn-back {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.8rem;
    font-weight: 600;
    padding: 6px 14px;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-btn);
    background: #1e293b;
    transition: all 0.2s ease;
}
.btn-back:hover {
    background: #334155;
    color: var(--f8fafc);
    border-color: #475569;
    transform: translateX(-2px);
}

/* ===== LAYOUT PRINCIPAL ===== */
#app {
    display: flex;
    gap: 24px;
    max-width: 1440px;
    width: 100%;
    height: 92vh;
    max-height: 820px;
    background: transparent;
}
/* === COLUMNA IZQUIERDA (LIENZO) === */
#canvas-wrapper {
    flex: 2.2;
    background: var(--bg-card);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-card);
    padding: 24px;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}
#canvas-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    gap: 12px;
    flex-wrap: wrap;
}
.canvas-title-group {
    display: flex;
    align-items: center;
    gap: 12px;
}
#canvas-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
    letter-spacing: -0.3px;
    display: flex;
    align-items: center;
    gap: 8px;
}
#canvas-header h2 span.badge-pilar {
    background: rgba(59, 130, 246, 0.15);;
    color: #60a5fa;
    font-size: 0.7rem;
    padding: 2px 10px;
    border-radius: 40px;
    font-weight: 600;
    border: 1px solid rgba(96, 165, 250, 0.2);
}
#template-selector {
    display: flex;
    gap: 8px;
}
.template-chip {
   padding: 6px 16px;
    border-radius: 40px;
    border: 1px solid var(--border-light);
    background: #1e293b;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
}
.template-chip:hover {
    border-color: var(--blue-accent);
    color: var(--text-primary);
    background: #334155;
}
.template-chip.active {
    background: var(--blue-accent);
    color: white;
    border-color: var(--blue-accent);
}

#canvas-container {
    position: relative;
    flex: 1;
    background: var(--bg-canvas);
    border-radius: 18px;
    overflow: hidden;
    cursor: grab;
    touch-action: none;
}
#canvas-container:active {
    cursor: grabbing;
}
#floorPlan {
    display: block;
    width: 100%;
    height: 100%;
    background: #090d16;
    border-radius: 18px;
}
/* Badge de APs en el canvas */
.ap-count-badge {
    position: absolute;
    bottom: 16px;
    left: 16px;
    background: rgba(11, 26, 51, 0.85);
    backdrop-filter: blur(6px);
    color: white;
    padding: 6px 14px;
    border-radius: 40px;
    font-size: 0.7rem;
    font-weight: 500;
    pointer-events: none;
    letter-spacing: 0.3px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.canvas-footer-banner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.72rem;
    color: var(--text-secondary);
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid var(--border-light);
}

/* === COLUMNA DERECHA (SIDEBAR) === */
#sidebar {
    flex: 1;
    min-width: 290px;
    background: var(--bg-card);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-card);
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}
#sidebar .brand {
    background: rgba(59, 130, 246, 0.15); /* Azul semitransparente sobre fondo oscuro */
    color: #60a5fa;
    font-size: 0.7rem;
    padding: 2px 10px;
    border-radius: 40px;
    font-weight: 600;
    border: 1px solid rgba(96, 165, 250, 0.2);
    display: flex;
    flex-direction: column;
    gap: 4px;
    border-bottom: 1px solid var(--border-light);
    padding-bottom: 12px;
}
#sidebar .brand-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
#sidebar .brand h1 {
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: -0.5px;
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-primary);
}
#sidebar .brand small {
    color: var(--blue-accent);
    font-weight: 600;
    font-size: 0.7rem;
    background: #dbeafe;
    padding: 2px 10px;
    border-radius: 40px;
}
#sidebar .brand p {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

#sidebar .brand span {
    color: var(--text-secondary);
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.control-row {
    display: flex;
    gap: 8px;
}
.btn {
    padding: 12px 16px;
    border: none;
    border-radius: var(--radius-btn);
    font-family: var(--font);
    font-weight: 600;
    font-size: 0.88rem;
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex: 1;
}
.btn-primary {
    background: var(--blue-accent);
    color: white;
}
.btn-primary:hover {
    background: var(--blue-hover);
    transform: translateY(-1px);
    box-shadow: 0 8px 20px -8px rgba(37, 99, 235, 0.4);
}
.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.btn-success {
    background: var(--green-accent);
    color: white;
}
.btn-success:hover {
    background: var(--green-hover);
    transform: translateY(-1px);
    box-shadow: 0 8px 20px -8px rgba(16, 185, 129, 0.4);
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border-light);
    color: var(--text-secondary);
}
.btn-outline:hover {
    background: #f8fafc;
    border-color: #94a3b8;
}
.btn-sm {
    padding: 8px 12px;
    font-size: 0.78rem;
    flex: 1;
}

/* Métricas */
.metrics-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    background: #1e293b; /* Ajustado al fondo secundario del sidebar */
    padding: 14px;
    border-radius: 18px;
    margin: 2px 0;
    border: 1px solid rgba(255, 255, 255, 0.05);
}
.metric-item {
    text-align: center;
}
.metric-item .value {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: -0.5px;
}
.metric-item .label {
    font-size: 0.68rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}
.metric-item .value.green {
    color: var(--green-accent);
}
.metric-item .value.red {
    color: #ef4444;
}
.metric-item .value.blue {
    color: var(--blue-accent);
}

.legend-bar {
    display: flex;
    height: 6px;
    border-radius: 8px;
    overflow: hidden;
    margin-top: 4px;
}
.legend-bar div {
    flex: 1;
}

.trust-box {
    background: #1e293b;
    padding: 10px 12px;
    border-radius: 14px;
    font-size: 0.72rem;
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    gap: 4px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}
.trust-box-title {
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 4px;
}

/* ===== MODAL LEAD ===== */
#leadModal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(11, 26, 51, 0.6);
    backdrop-filter: blur(8px);
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 20px;
}
#leadModal.open {
    display: flex;
}
.modal-box {
    background: #0f172a;
    max-width: 460px;
    width: 100%;
    padding: 32px;
    border-radius: 28px;
    border: 1px solid #1e293b;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.7);
    animation: modalFadeIn 0.25s ease;
}
@keyframes modalFadeIn {
    from {
        opacity: 0;
        transform: scale(0.96) translateY(10px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}
.modal-box h3 {
    font-size: 1.35rem;
    font-weight: 700;
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-primary);
}
.modal-box p {
    color: var(--text-secondary);
    margin-bottom: 16px;
    font-size: 0.88rem;
    line-height: 1.4;
}
.modal-box input,
.modal-box select {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border-light);
    border-radius: 12px;
    font-family: var(--font);
    font-size: 0.88rem;
    margin-bottom: 10px;
    background: #1e293b;
    color: var(--text-primary);
    transition: border 0.15s;
}
.modal-box input:focus,
.modal-box select:focus {
    outline: none;
    border-color: var(--blue-accent);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}
.modal-box .btn {
    width: 100%;
    padding: 14px;
    font-size: 0.95rem;
}
.modal-close {
    float: right;
    background: none;
    border: none;
    font-size: 1.5rem;
    color: #94a3b8;
    cursor: pointer;
    margin-top: -6px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal-close:hover {
    color: #475569;
}

/* Spinner */
.spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 0.6s linear infinite;
}
@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Responsive */
@media (max-width: 1024px) {
    body {
        height: auto;
        min-height: 100dvh;
        align-items: flex-start;
        justify-content: flex-start;
        padding-top: max(16px, env(safe-area-inset-top));
    }
    #app {
        flex-direction: column;
        height: auto;
        max-height: none;
    }
    #canvas-wrapper {
        min-height: auto;
    }
    #sidebar {
        min-width: unset;
    }
}

@media (max-width: 600px) {
    body {
        padding: max(12px, env(safe-area-inset-top)) 12px 12px 12px;
    }
    #canvas-wrapper {
        padding: 14px;
    }
    #sidebar {
        padding: 18px;
    }
    .metrics-grid {
        grid-template-columns: 1fr 1fr;
    }
    #template-selector {
        flex-wrap: wrap;
    }
    .canvas-title-group {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
    }
}

/* --- Estilos base del modal --- */
.swal2-popup {
    background-color: var(--bg-card) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border-light) !important;
    border-radius: var(--radius-card) !important;
    box-shadow: var(--shadow-card) !important;
    font-family: var(--font) !important;
}

.swal2-title {
    color: var(--text-primary) !important;
    font-size: 1.2rem !important;
    font-weight: 600 !important;
}

.swal2-html-container {
    color: var(--text-secondary) !important;
    font-size: 0.88rem !important;
}

/* --- Botones --- */
.swal2-styled.swal2-confirm {
    border-radius: var(--radius-btn) !important;
    font-size: 0.85rem !important;
    font-weight: 600 !important;
    padding: 10px 24px !important;
    box-shadow: none !important;
}

/* --- Iconos (Error, Success, Warning, Info) --- */
.swal2-icon.swal2-error {
    border-color: #ef4444 !important;
    color: #ef4444 !important;
}

.swal2-icon.swal2-error [class^='swal2-x-mark-line'] {
    background-color: #ef4444 !important;
}

.swal2-icon.swal2-success {
    border-color: var(--green-accent) !important;
    color: var(--green-accent) !important;
}

.swal2-icon.swal2-success [class^='swal2-success-line'] {
    background-color: var(--green-accent) !important;
}

.swal2-icon.swal2-success .swal2-success-ring {
    border-color: rgba(16, 185, 129, 0.3) !important;
}

/* --- Backdrop --- */
.swal2-container {
    backdrop-filter: blur(4px);
    background: rgba(2, 6, 23, 0.75) !important;
}