:root {
    --bg:        #000000;
    --line:      rgba(255,255,255,0.8);
    --text:      #ffffff;
    --font:      'Montserrat', sans-serif;
    --radius:    12px;
    --green:     #44ff44;
    --ui-h:      48px;
}

body, html {
    margin: 0; padding: 0;
    width: 100%; height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    overflow: hidden;
    user-select: none;
    touch-action: none;
}

/* ── HEADER ──────────────────────────────────────────────────────────────── */
#ui-layer {
    position: fixed;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 4px;
    z-index: 1000;
    flex-wrap: nowrap;
    white-space: nowrap;
    max-width: calc(100vw - 24px);
    background: rgba(0,0,0,0.72);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 14px;
    padding: 6px 8px;
}

.btn-group {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 0 4px;
}
.btn-group + .btn-group {
    border-left: 1px solid rgba(255,255,255,0.1);
}

/* Base de todos los botones del header */
#ui-layer button {
    display: flex;
    align-items: center;
    gap: 5px;
    background: transparent;
    color: rgba(255,255,255,0.7);
    border: 1px solid transparent;
    padding: clamp(5px, 0.7vw, 8px) clamp(7px, 0.9vw, 12px);
    font-family: var(--font);
    font-size: clamp(9px, 1.1vw, 11px);
    font-weight: 800;
    letter-spacing: 0.8px;
    text-transform: uppercase;
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    white-space: nowrap;
}

#ui-layer button svg {
    width: clamp(13px, 1.6vw, 17px);
    height: clamp(13px, 1.6vw, 17px);
    fill: currentColor;
    flex-shrink: 0;
}

#ui-layer button:hover:not(:disabled) {
    background: rgba(255,255,255,0.1);
    color: #fff;
    border-color: rgba(255,255,255,0.15);
}

#ui-layer button:disabled {
    opacity: 0.2;
    cursor: default;
}

/* Ocultar texto en pantallas muy estrechas, dejar solo icono */
@media (max-width: 680px) {
    #ui-layer button span { display: none; }
    #ui-layer button { padding: clamp(5px, 1.5vw, 8px); }
}

/* Botón acento (añadir tarjeta) */
#add-card-btn {
    color: #000 !important;
    background: var(--green) !important;
    border-color: transparent !important;
}
#add-card-btn:hover:not(:disabled) {
    filter: brightness(1.1);
    transform: scale(1.04);
}

/* Botón guardar — cambia color según estado */
#save-btn {
    color: var(--green) !important;
    border-color: rgba(68,255,68,0.3) !important;
}
#save-btn.unsaved {
    color: #fff !important;
    background: rgba(255,255,255,0.12) !important;
    border-color: rgba(255,255,255,0.35) !important;
}

/* ── MENÚ DROPDOWN ────────────────────────────────────────────────────────── */
#menu-wrapper { position: relative; }

#menu-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    background: #111;
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 10px;
    overflow: hidden;
    min-width: 140px;
    z-index: 3000;
    box-shadow: 0 12px 32px rgba(0,0,0,0.7);
}
#menu-dropdown.open { display: block; }

#menu-dropdown button {
    display: flex !important;
    align-items: center;
    gap: 8px;
    width: 100%;
    border-radius: 0 !important;
    border: none !important;
    padding: 11px 14px !important;
    color: rgba(255,255,255,0.85) !important;
    font-size: 11px !important;
}
#menu-dropdown button + button {
    border-top: 1px solid rgba(255,255,255,0.06) !important;
}
#menu-dropdown button:hover {
    background: rgba(255,255,255,0.07) !important;
    color: #fff !important;
}
#menu-dropdown button svg {
    width: 15px !important;
    height: 15px !important;
}

/* ── DOT WEBSOCKET ────────────────────────────────────────────────────────── */
#ws-status {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    margin-left: 4px;
    flex-shrink: 0;
    transition: background 0.4s;
}
#ws-status.connected    { background: var(--green); box-shadow: 0 0 5px var(--green); }
#ws-status.disconnected { background: #ff8844; }

/* ── CANVAS ──────────────────────────────────────────────────────────────── */
#canvas-container {
    width: 100vw; height: 100vh;
    cursor: grab;
    position: relative;
}
#canvas-container:active { cursor: grabbing; }
#viewport {
    position: absolute;
    transform-origin: 0 0;
    will-change: transform;
}

/* ── TARJETAS ────────────────────────────────────────────────────────────── */
.box {
    position: absolute;
    border: 1px solid var(--line);
    padding: 20px;
    min-width: 180px;
    max-width: 520px;
    display: inline-block;
    background: var(--bg);
    pointer-events: auto;
    user-select: text;
    z-index: 10;
    border-radius: var(--radius);
    box-shadow: 0 0 15px rgba(255,255,255,0.05);
    transition: box-shadow 0.3s, border-color 0.3s;
}

.box.locked {
    border: 2px solid rgba(255,255,255,0.2);
    box-shadow: 0 0 10px rgba(0,0,0,0.5);
}
.box.locked:hover { border-color: rgba(255,255,255,0.4); }
.box.locked .drag-handle,
.box.locked .dot-handle,
.box.locked .delete-btn { display: none !important; }
.box.locked .box-header,
.box.locked .content { cursor: default !important; }
.box.locked::after {
    content: '🔒 CORE';
    position: absolute; top: -10px; right: 10px;
    background: #000; color: #fff;
    font-size: 8px; font-weight: 900;
    padding: 2px 6px; border-radius: 4px;
    border: 1px solid rgba(255,255,255,0.2);
}

.box-header {
    font-size: 10px; font-weight: 900;
    text-transform: uppercase; margin-bottom: 12px;
    opacity: 0.6; border-bottom: 1px solid rgba(255,255,255,0.15);
    padding-bottom: 8px; letter-spacing: 2px;
    padding-right: 58px;
    outline: none;
}
.box-header:focus { opacity: 1; border-bottom-color: var(--green); }

/* ── BOTÓN BORRAR (al lado del drag handle) ─────────────────────────────── */
.delete-btn {
    position: absolute; top: 12px; right: 32px;
    width: 14px; height: 14px;
    background: rgba(200,40,40,0.8);
    color: #fff; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 10px; font-weight: 900; line-height: 1;
    cursor: pointer; opacity: 0; user-select: none;
    transition: opacity 0.2s, transform 0.15s, background 0.15s;
    z-index: 30;
}
.box:hover .delete-btn { opacity: 0.5; }
.delete-btn:hover { opacity: 1 !important; background: #cc2222; transform: scale(1.2); }

/* ── DRAG HANDLE ─────────────────────────────────────────────────────────── */
.drag-handle {
    position: absolute; top: 12px; right: 12px;
    width: 14px; height: 14px;
    background: #fff; border-radius: 50%;
    cursor: move; opacity: 0.15;
    transition: opacity 0.2s; z-index: 20;
}
.box:hover .drag-handle { opacity: 1; }
.drag-handle:active { background: var(--green); transform: scale(1.2); }

/* ── PUNTOS DE CONEXIÓN ──────────────────────────────────────────────────── */
.dot-handle {
    position: absolute;
    width: 8px; height: 8px;
    background: #fff; border-radius: 50%;
    cursor: crosshair; opacity: 0;
    transition: opacity 0.2s, transform 0.2s;
    z-index: 25;
}
.dot-top    { top: -4px;    left: 50%; transform: translateX(-50%); }
.dot-bottom { bottom: -4px; left: 50%; transform: translateX(-50%); }
.dot-left   { left: -4px;   top: 50%;  transform: translateY(-50%); }
.dot-right  { right: -4px;  top: 50%;  transform: translateY(-50%); }
.dot-handle:hover {
    transform: translate(var(--tw-translate-x, -50%), var(--tw-translate-y, -50%)) scale(1.5);
    background: var(--green);
}
.box:hover .dot-handle { opacity: 0.3; }
.dot-handle:hover { opacity: 1 !important; }

.content {
    outline: none; white-space: pre-wrap;
    line-height: 1.6; font-size: 14px; font-weight: 400;
    color: rgba(255,255,255,0.9);
    font-family: 'Courier New', Courier, monospace;
    cursor: text;
}
.content-normal { font-family: var(--font); }

/* ── CABLES SVG ──────────────────────────────────────────────────────────── */
.cable {
    fill: none;
    stroke: rgba(255,255,255,0.25);
    stroke-width: 2; stroke-linecap: round;
    transition: stroke 0.2s, stroke-width 0.2s;
}
.cable-group:hover .cable {
    stroke: rgba(255,255,255,0.55);
    stroke-width: 2.5;
}
.cable-delete-btn { opacity: 0; transition: opacity 0.15s; cursor: pointer; }
.cable-group:hover .cable-delete-btn { opacity: 1; }
.cable-delete-btn:hover circle { fill: #cc2222; stroke: rgba(255,255,255,0.7); }
.cable-delete-btn:hover text { fill: #fff; }
.cable-preview {
    fill: none;
    stroke: rgba(68,255,68,0.3);
    stroke-width: 1.5;
}
.separator-cable {
    fill: none;
    stroke: rgba(255,255,255,0.05);
    stroke-width: 4; stroke-linecap: round;
}
.line-handle { display: none !important; }

/* ── FONDO ───────────────────────────────────────────────────────────────── */
#grid-bg {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background-image: radial-gradient(circle, rgba(255,255,255,0.025) 1px, transparent 1px);
    background-size: 28px 28px;
    z-index: -1;
}

.section-title {
    position: absolute;
    font-weight: 900; font-size: 120px;
    color: rgba(255,255,255,0.04);
    pointer-events: none; letter-spacing: -2px;
    text-transform: uppercase; text-align: center;
    width: 800px;
}

/* ── MÓVIL ───────────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
    #ui-layer { top: 8px; padding: 4px 6px; gap: 2px; }
    .btn-group { padding: 0 2px; }
    #ws-status { display: none; }
}
