/* ============================================================
   CuadroBuilder Pro — styles.css (Versión FINAL limpia)
   ============================================================ */

:root {
    --bg-base:        #1a1f2e;
    --bg-surface:     #222839;
    --bg-raised:      #2a3045;
    --bg-input:       #1e2333;
    --border-subtle:  #343c52;
    --border-strong:  #4a5270;
    --text-primary:   #dde3f0;
    --text-secondary: #8e97b0;
    --text-muted:     #5c657d;
    --accent:         #4ec9e0;
    --accent-dim:     rgba(78,201,224,.12);
    --accent-hover:   #38b4cc;
    --armario-bg:     #c8cdd8;
    --armario-border: #9aa0b0;
    --carril-bg:      #dde1ea;
    --carril-inner:   #e8ecf4;
    --label-bg:       #fdf9e8;
    --toast-ok:       #2d6a4f;
    --toast-err:      #6b2333;
    --radius:         10px;
    --radius-sm:      6px;
    --transition:     180ms ease;
    --font-mono:      'JetBrains Mono', monospace;
    --font-ui:        'Inter', system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 13px; }

body {
    font-family: var(--font-ui);
    background: var(--bg-base);
    color: var(--text-primary);
    min-height: 100vh;
    overflow: hidden;
    margin: 0;
}

/* LAYOUT PRINCIPAL */
.app-wrapper {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 16px;
    height: 100vh;
    padding: 16px;
    overflow: hidden;
}

/* PANEL IZQUIERDO */
.panel-control {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    padding: 18px 16px;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    height: calc(100vh - 32px);
    box-shadow: 0 4px 24px rgba(0,0,0,.4);
}

.panel-header { margin-bottom: 14px; }
.logo-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.logo-icon { font-size: 22px; }
.logo-title { font-family: var(--font-mono); font-size: 15px; font-weight: 800; letter-spacing: -0.5px; }
.logo-accent { color: var(--accent); }
.logo-sub { font-size: 10px; color: var(--text-muted); margin-top: 1px; }

.badge-autosave {
    display: inline-block;
    font-size: 9.5px;
    font-family: var(--font-mono);
    padding: 3px 8px;
    border-radius: 20px;
    background: rgba(74,184,138,.10);
    border: 1px solid rgba(74,184,138,.25);
    color: #4ab88a;
}

.tip-box {
    display: flex; gap: 8px;
    background: var(--bg-raised);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    margin-bottom: 14px;
    font-size: 11px;
    color: var(--text-secondary);
}
.tip-icon { flex-shrink: 0; font-size: 13px; }

.section-divider {
    border: none;
    border-top: 1px solid var(--border-subtle);
    margin: 12px 0;
}
.section-title {
    font-size: 10px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .8px;
    margin-bottom: 8px;
}

/* Toggle */
.toggle-row {
    display: flex; align-items: center; gap: 10px;
    cursor: pointer; user-select: none; margin-bottom: 4px;
}
.toggle-row input { display: none; }
.toggle-track {
    width: 32px; height: 18px;
    background: var(--bg-input);
    border: 1px solid var(--border-strong);
    border-radius: 20px;
    position: relative;
    flex-shrink: 0;
}
.toggle-thumb {
    position: absolute; top: 2px; left: 2px;
    width: 12px; height: 12px;
    border-radius: 50%;
    background: var(--text-muted);
    transition: all var(--transition);
}
.toggle-row input:checked ~ .toggle-track { background: var(--accent-dim); border-color: var(--accent); }
.toggle-row input:checked ~ .toggle-track .toggle-thumb { transform: translateX(14px); background: var(--accent); }
.toggle-label { font-size: 11px; color: var(--text-secondary); }

/* Campos y select */
.field-label { 
    display: block; font-size: 10.5px; font-weight: 600; 
    color: var(--text-muted); margin-bottom: 5px; 
    text-transform: uppercase; letter-spacing: .5px; 
}

.select-field, .text-field {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 7px 10px;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 600;
}
.select-field:focus, .text-field:focus { border-color: var(--accent); }
.text-field { text-transform: uppercase; }

/* Botones de dispositivos */
.device-list { display: flex; flex-direction: column; gap: 5px; }
.btn-device {
    display: flex; justify-content: space-between; align-items: center;
    width: 100%; padding: 7px 10px;
    background: var(--bg-raised);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 11.5px; font-weight: 500;
    color: var(--text-secondary);
}
.btn-device:hover { background: var(--bg-input); border-color: var(--border-strong); color: var(--text-primary); }

.btn-device.btn-amber  { border-color: rgba(212,168,67,.3); color: #d4a843; }
.btn-device.btn-emerald{ border-color: rgba(74,184,138,.3); color: #4ab88a; }
.btn-device.btn-sky    { border-color: rgba(79,168,212,.3); color: #4fa8d4; }
.btn-device.btn-indigo { border-color: rgba(123,143,224,.3); color: #7b8fe0; }
.btn-device.btn-purple { border-color: rgba(160,123,204,.3); color: #a07bcc; }
.btn-device.btn-reserva{ border-color: rgba(180,185,200,.3); color: #a0a8bc; }

/* Botones danger y print */
.danger-zone { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 10px; }
.btn {
    padding: 7px 10px; border-radius: var(--radius-sm); 
    border: 1px solid transparent; cursor: pointer; 
    font-size: 11.5px; font-weight: 600; text-align: center;
}
.btn-danger-soft { background: rgba(180,50,60,.15); border-color: rgba(180,50,60,.3); color: #e07080; }
.btn-danger-ghost { background: transparent; border-color: var(--border-subtle); color: var(--text-muted); }
.btn-print { background: #2858a0; border: 1px solid #3a6bbf; color: #c8daff; font-weight: 700; }

/* Planos */
.planos-actions { display: flex; flex-direction: column; gap: 6px; }
.btn-save-plan, .btn-load-plan {
    display: flex; align-items: center; justify-content: center; gap: 7px;
    padding: 8px 12px; border-radius: var(--radius-sm); font-weight: 600;
}
.btn-save-plan { background: rgba(74,184,138,.12); border: 1px solid rgba(74,184,138,.35); color: #4ab88a; }
.btn-load-plan { background: rgba(79,168,212,.12); border: 1px solid rgba(79,168,212,.35); color: #4fa8d4; }

/* ZOOM TOOLBAR */
.zoom-toolbar {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    padding: 8px 12px;
    display: flex; align-items: center; gap: 8px;
    margin-bottom: 12px; flex-shrink: 0;
}
.zoom-toolbar button {
    padding: 6px 12px;
    background: var(--bg-raised);
    border: 1px solid var(--border-strong);
    color: var(--text-primary);
    border-radius: 6px;
    cursor: pointer;
    font-size: 12.5px;
    font-weight: 600;
}
.zoom-toolbar button:hover { background: var(--accent-dim); border-color: var(--accent); }

/* ARMARIO */
.armario-wrapper {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 32px);
    overflow: hidden;
    background: #1a1f2e;
    border-radius: var(--radius);
    gap: 0;
}

/* Scroll area: the viewport that clips the scaled board */
.scroll-area {
    flex: 1;
    overflow: auto;
    position: relative;
    min-height: 0;
    /* Hide native scrollbar — we use our custom one below */
    scrollbar-width: none;
}
.scroll-area::-webkit-scrollbar { display: none; }

/* Scroll content: sized to match scaled board dimensions */
.scroll-content {
    position: relative;
    /* width/height set dynamically by JS */
    min-width: 100%;
    min-height: 100%;
}

/* The board itself sits at top-left, scaled by transform */
.armario {
    position: absolute;
    top: 0;
    left: 0;
    transform-origin: top left;

    background: var(--armario-bg);
    border: 10px solid var(--armario-border);
    border-radius: 18px;
    padding: 20px 20px 24px;
    box-shadow: 0 8px 40px rgba(0,0,0,.6), inset 0 2px 0 rgba(255,255,255,.3);
    color: #1a2035;
    /* Do NOT set overflow: auto here — scroll is handled by .scroll-area */
}

/* ── HORIZONTAL SCROLLBAR ────────────────────────────── */
.h-scrollbar {
    height: 14px;
    overflow-x: auto;
    overflow-y: hidden;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-subtle);
    border-radius: 0 0 var(--radius) var(--radius);
    flex-shrink: 0;
    /* Custom scrollbar styling */
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
}
.h-scrollbar::-webkit-scrollbar { height: 8px; }
.h-scrollbar::-webkit-scrollbar-track { background: var(--bg-surface); border-radius: 4px; }
.h-scrollbar::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }
.h-scrollbar::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* This inner div's width is synced with scroll-content width by JS */
.h-scrollbar-inner {
    height: 1px; /* Just needs to create scroll range */
    min-width: 100%;
}

/* Estilos del tablero */
.armario-header {
    border: 3px solid #0f2c59;
    background: #c5dcf0;
    text-align: center;
    padding: 10px 16px;
    margin-bottom: 18px;
    border-radius: 8px;
    box-shadow: 0 2px 6px rgba(0,0,0,.15);
}
.armario-header h1 {
    font-family: var(--font-mono);
    font-size: 13px;
    font-weight: 800;
    color: #0f2c59;
    letter-spacing: 2px;
    text-transform: uppercase;
    outline: none;
    cursor: text;
}


/* Carriles y módulos */
.contenedor-cuadro { display: flex; flex-direction: column; gap: 12px; }

.carril-row {
    background: var(--carril-bg);
    border: 2px solid #b0b6c2;
    border-radius: 10px;
    padding: 8px;
    box-shadow: 0 2px 6px rgba(0,0,0,.1);
}

.carril-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--label-bg);
    border: 1px solid #d4c870;
    border-radius: 5px;
    padding: 4px 10px;
    margin-bottom: 6px;
}
.carril-num { font-size: 9px; font-weight: 700; color: #1a3a70; font-family: var(--font-mono); }
.carril-label-edit {
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 800;
    color: #1a2035;
    text-transform: uppercase;
    letter-spacing: .5px;
    outline: none;
    cursor: text;
    flex: 1;
    text-align: right;
}

.carril-din {
    min-height: 140px;
    display: flex;
    align-items: flex-end;
    background: var(--carril-inner);
    border: 1px solid #b8bece;
    border-radius: 6px;
    padding: 6px;
    padding-bottom: 10px; /* extra space so scrollbar doesn't overlap modules */
    overflow-x: auto;
    overflow-y: hidden;
    gap: 4px;

    /* Scrollbar always visible so users know they can scroll */
    scrollbar-width: thin;
    scrollbar-color: #9aa0b8 #d0d4df;
}

/* Webkit browsers */
.carril-din::-webkit-scrollbar {
    height: 7px;
}
.carril-din::-webkit-scrollbar-track {
    background: #d0d4df;
    border-radius: 0 0 5px 5px;
}
.carril-din::-webkit-scrollbar-thumb {
    background: #9aa0b8;
    border-radius: 4px;
    border: 1px solid #c0c4cf;
}
.carril-din::-webkit-scrollbar-thumb:hover {
    background: #6a7490;
}

.modulo {
    display: flex; flex-direction: column; align-items: center;
    flex-shrink: 0;
    position: relative;
    animation: modulo-enter 300ms cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes modulo-enter {
    0%   { opacity: 0; transform: translateY(18px) scale(0.85); }
    100% { opacity: 1; transform: translateY(0) scale(1); }
}

.modulo-label {
    font-size: 7.5px;
    font-weight: 800;
    text-align: center;
    color: #1a2035;
    background: #fff;
    border: 1px solid #b0b6c4;
    border-radius: 3px;
    padding: 2px 3px;
    margin-bottom: 3px;
}

.modulo img {
    height: 112px;
    border-radius: 3px;
    border: 1px solid #9aa0b0;
}

.modulo-delete {
    position: absolute;
    top: 18px; right: -4px;
    width: 16px; height: 16px;
    background: #c0303a;
    color: #fff;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    opacity: 0;
    transition: opacity var(--transition);
}
.modulo:hover .modulo-delete { opacity: 1; }

/* Toast */
#toast-container {
    position: fixed;
    bottom: 24px; right: 24px;
    display: flex; flex-direction: column-reverse;
    gap: 8px;
    z-index: 9999;
}

.toast {
    display: flex; align-items: center; gap: 10px;
    padding: 11px 16px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    box-shadow: 0 4px 20px rgba(0,0,0,.5);
}

.toast-ok  { background: var(--toast-ok); color: #95e6c3; }
.toast-err { background: var(--toast-err); color: #f4a7b4; }
.toast-warn { background: #5a4a1a; color: #e8c870; }

/* Print */
@media print {
    body { background: white; }
    .panel-control, .zoom-toolbar, #toast-container { display: none !important; }
    .armario { border: 8px solid #888; box-shadow: none; }
    .carril-delete-btn, .modulo-delete { display: none !important; }
}

@media (max-width: 900px) {
    .app-wrapper { grid-template-columns: 1fr; }
    .panel-control { height: auto; }
}
/* ── ANALIZADORES CIRCUTOR ─────────────────────────────── */
.bloque-analizadores {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    border: 2px solid #b0b6c2;
    background: #d8dce6;
    padding: 12px;
    border-radius: 10px;
    margin-bottom: 16px;
    box-shadow: inset 0 2px 4px rgba(0,0,0,.08);
}

.analizador-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: #fff;
    border: 1px solid #c8ccda;
    border-radius: 10px;
    padding: 8px;
    box-shadow: 0 1px 4px rgba(0,0,0,.08);
}

.analizador-label {
    font-size: 9.5px;
    font-weight: 800;
    color: #3a4260;
    text-transform: uppercase;
    margin-bottom: 6px;
    letter-spacing: .4px;
    text-align: center;
}

.analizador-body {
    width: 96px;
    height: 96px;
    background: #212529;
    border: 5px solid #5a626a;
    border-radius: 10px;
    padding: 6px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    box-shadow: 0 2px 8px rgba(0,0,0,.5);
}

.analizador-brand {
    font-size: 6.5px;
    color: #5a626a;
    font-family: var(--font-mono);
    text-align: center;
    letter-spacing: 2px;
    border-bottom: 1px solid #333;
    padding-bottom: 3px;
}

.analizador-display {
    background: #1565c0;
    border: 1px solid #0d47a1;
    border-radius: 4px;
    padding: 4px 5px;
    flex: 1;
    margin: 4px 0;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
}

.analizador-row {
    display: flex;
    justify-content: space-between;
    font-size: 8px;
    font-family: var(--font-mono);
    color: #e3f2fd;
}

.analizador-model {
    font-size: 6px;
    color: #5a626a;
    font-family: var(--font-mono);
    letter-spacing: 1px;
    text-align: center;
}
/* ── TAPAS OBTURADORAS / RESERVAS ──────────────────────── */
.tapa-obturadora {
    width: 36px; /* Alineado a 1 módulo estándar en tu diseño */
    height: 112px; /* Mismo alto que las imágenes de los dispositivos */
    background: #d1d5db; /* Gris plástico */
    border: 1px solid #9aa0b0;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: inset 0 2px 4px rgba(255,255,255,0.6), inset 0 -2px 4px rgba(0,0,0,0.1);
}

.tapa-text {
    writing-mode: vertical-rl;
    text-orientation: mixed;
    font-size: 11px;
    font-weight: 800;
    color: #6b7280;
    letter-spacing: 3px;
    text-transform: uppercase;
    transform: rotate(180deg); /* Opcional: para que se lea de abajo hacia arriba */
}