/* ============================================
   VARIABLES CSS Y CONFIGURACIÓN GLOBAL
   ============================================ */

:root {
    /* Layout dimensions */
    --panel-left-width: 350px;
    --panel-right-width: 90px;
    --panel-tabs-width: 35px;
    --symbol-size: 60px;
    --toolbar-height: 50px;
    --top-offset: 0px;
    
    /* Colors - Light theme */
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-gradient: linear-gradient(to bottom, #ffffff, #f8f9fa);
    --bg-accent: linear-gradient(to bottom, #556ee6, #4a5fc7);
    --border-color: #d0d5dd;
    --border-light: #dee2e6;
    --border-item: #e3e6ea;
    --text-primary: #495057;
    --text-secondary: #6c757d;
    --text-heading: #2c3e50;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 12px rgba(85, 110, 230, 0.15);
    --shadow-panel: 2px 0 8px rgba(0, 0, 0, 0.05);
    
    /* Selection colors */
    --selection-color: #007bff;
    --selection-shadow: 0 0 10px rgba(0, 123, 255, 0.5);

    /* Drag handle colors */
    --drag-handle-color: #9b59b6;
    --drag-handle-shadow: 0 0 10px rgba(155, 89, 182, 0.5);
}

/* Colors - Dark theme */
[data-bs-theme="dark"] {
    --bg-primary: #262b3c;
    --bg-secondary: #1e2230;
    --bg-gradient: linear-gradient(to bottom, #262b3c, #1e2230);
    --border-color: #3a4157;
    --border-light: #3a4157;
    --border-item: #3a4157;
    --text-primary: #a6b0cf;
    --text-secondary: #a6b0cf;
    --text-heading: #a6b0cf;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 12px rgba(85, 110, 230, 0.3);
    --shadow-panel: 2px 0 8px rgba(0, 0, 0, 0.3);
}

html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: auto;
}

#watermark-footer {
    position: fixed;
    right: calc(var(--panel-right-width) + 12px);
    bottom: 12px;
    z-index: 999;
    color: #888;
    font-size: 12px;
    background: rgba(255,255,255,0.7);
    padding: 6px 8px;
    border-radius: 8px;
    pointer-events: none; /* Para que no interfiera con clics */
}

/* ============================================
   TOOLBAR
   ============================================ */

.toolbar {
    position: fixed;
    top: var(--top-offset);
    left: var(--panel-left-width);
    right: 0;
    height: var(--toolbar-height);
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-light);
    color: var(--text-primary);
    padding: 8px 15px;
    z-index: 999;
    display: flex;
    align-items: center;
    gap: 5px;
    transition: left 0.3s ease;
    overflow-x: auto;
    overflow-y: hidden;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x;
    overscroll-behavior-x: contain;
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.toolbar::-webkit-scrollbar {
    display: none;
}

/* Toolbar - Estados de visibilidad de paneles */
#panelGallerySymbols.hidden ~ * .toolbar,
body:has(#panelGallerySymbols.hidden) .toolbar {
    left: var(--panel-tabs-width);
}

/* Toolbar buttons */
.toolbar-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 14px;
    border-radius: 9999px;
    touch-action: pan-x;
    overflow: hidden;
}

.toolbar-btn .btn-icon {
    font-size: 16px;
}

.toolbar-btn .btn-text {
    font-size: 12px;
}

/* Toolbar dropdown */
.toolbar-dropdown {
    display: none;
    position: fixed;
    min-width: 180px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    z-index: 1101;
    overflow: hidden;
}

.toolbar-dropdown.show {
    display: block;
}

.toolbar-dropdown-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    font-size: 13px;
    color: var(--text-primary);
    text-decoration: none;
    cursor: pointer;
    transition: background 0.2s ease;
    white-space: nowrap;
}

.toolbar-dropdown-item:hover {
    background: var(--bg-secondary);
    color: #556ee6;
    text-decoration: none;
}

.toolbar-dropdown-item span.bx {
    font-size: 16px;
}

/* ============================================
   CANVAS WRAPPER Y CONTAINER
   ============================================ */

#canvasWrapper {
    position: fixed;
    top: calc(var(--top-offset) + var(--toolbar-height));
    bottom: 0;
    left: var(--panel-left-width);
    right: var(--panel-right-width);
    overflow: auto;
    transition: left 0.3s ease, right 0.3s ease;
    touch-action: none;
}

#canvasWrapper.panel-hidden {
    left: var(--panel-tabs-width);
}

#drawingCanvas {
    position: relative;
    transform-origin: 0 0;
    min-width: 100%;
    min-height: 100%;
}

/* ============================================
   SYMBOLS Y ELEMENTOS DEL CANVAS
   ============================================ */

.symbol {
    position: absolute;
    touch-action: none;
    cursor: move;
    user-select: none;
    -webkit-user-drag: none;
    transition: transform 0.3s ease;
}

.symbol.action-target {
    cursor: pointer;
}

.action-indicator {
    position: absolute;
    background-color: rgba(128, 128, 128, 0.4);
    border-radius: 50%;
    pointer-events: auto;
    cursor: pointer;
    z-index: 10;
    transition: background-color 0.2s ease;
}

.action-indicator:hover {
    background-color: rgba(220, 53, 69, 0.6);
}

.copy-indicator {
    position: absolute;
    background: #28a745;
    color: white;
    font-size: 24px;
    font-weight: bold;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    z-index: 10000;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    line-height: 1;
}

/* ============================================
   DEBUG - ÁREA DE ARRASTRE (HANDLE)
   ============================================ */

.drag-handle-overlay {
    position: absolute;
    pointer-events: none;
    z-index: 9999;
    border: 2px dashed var(--drag-handle-color);
    box-shadow: var(--drag-handle-shadow);
    border-radius: 4px;
    display: none;
}

.symbol-ghost {
    position: fixed;
    pointer-events: none;
    z-index: 10000;
    opacity: 0.7;
    background: white;
    border: 2px solid var(--drag-handle-color);
    border-radius: 5px;
    padding: 5px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* Highlight source item while touch-dragging from gallery */
.symbol-item.touch-dragging {
    opacity: 0.4;
    outline: 2px dashed var(--drag-handle-color);
    outline-offset: 2px;
}

/* Highlight canvas wrapper when a touch-dragged symbol hovers over it */
#canvasWrapper.drop-target-active {
    outline: 3px dashed var(--drag-handle-color);
    outline-offset: -3px;
}

/* ============================================
   PANEL IZQUIERDO - GALERÍA DE SÍMBOLOS
   ============================================ */

#panelGallerySymbols {
    position: fixed;
    left: 0;
    top: var(--top-offset);
    width: var(--panel-left-width);
    height: calc(100vh - var(--top-offset));
    background: var(--bg-gradient);
    border-right: 1px solid var(--border-color);
    display: flex;
    z-index: 1000;
    transition: width 0.3s ease;
    box-shadow: var(--shadow-panel);
}

#panelGallerySymbols.hidden {
    width: var(--panel-tabs-width);
}

/* Tabs container */
.tabs-container {
    width: var(--panel-tabs-width);
    background: var(--bg-accent);
    border-right: 1px solid #4a5fc7;
    display: flex;
    flex-direction: column;
    box-shadow: 1px 0 4px rgba(0, 0, 0, 0.1);
}

.tab {
    width: var(--panel-tabs-width);
    height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    font-size: 11px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.7);
    text-align: center;
    word-wrap: break-word;
    padding: 5px;
    transition: all 0.3s ease;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    transform: rotate(180deg);
    letter-spacing: 0.5px;
}

.tab:hover {
    background: rgba(255, 255, 255, 0.15);
    color: rgba(255, 255, 255, 0.95);
}

.tab.active {
    background: rgba(255, 255, 255, 0.25);
    color: white;
    font-weight: 700;
    box-shadow: inset 3px 0 0 #ffffff;
}

.symbols-container {
    flex: 1;
    padding: 6px;
    overflow-y: auto;
    transition: opacity 0.3s ease, width 0.3s ease;
    opacity: 1;
    width: 350px;
    background: transparent;
}

#panelGallerySymbols.hidden .symbols-container {
    opacity: 0;
    width: 0;
    padding: 0;
    overflow: hidden;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
}

/* Symbol items */
.symbol-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 4px;
    background: var(--bg-primary);
    border: 1px solid var(--border-item);
    border-radius: 8px;
    cursor: grab;
    transition: all 0.3s ease;
    max-width: 100%;
    touch-action: auto;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    box-shadow: var(--shadow-sm);
}

.text-element {
    background-color: rgba(155, 212, 238, 0.4);
    font-family: inherit; 
}

/* En pantallas grandes (escritorio), bloquear touch para permitir drag */
@media (min-width: 992px) {
    .symbol-item {
        touch-action: none;
    }
}

.symbol-item:hover {
    background: var(--bg-secondary);
    border-color: #556ee6;
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.symbol-item:active {
    cursor: grabbing;
    transform: translateY(0);
    box-shadow: 0 2px 6px rgba(85, 110, 230, 0.2);
}

.symbol-thumbnail {
    width: var(--symbol-size);
    height: var(--symbol-size);
    object-fit: contain;
    margin-bottom: 5px;
    -webkit-touch-callout: none;
    pointer-events: none;
}

.symbol-name {
    font-size: 9px;
    text-align: center;
    color: var(--text-secondary);
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
    white-space: normal;
    width: 100%;
    max-width: 100%;
    line-height: 1.3;
    font-weight: 500;
    margin-top: 2px;
    padding-left: 4px;
    padding-right: 4px; 
}

/* ============================================
   PANEL DERECHO - ACCIONES
   ============================================ */

#panelActions {
    position: fixed;
    right: 0;
    top: calc(var(--top-offset) + var(--toolbar-height));
    width: var(--panel-right-width);
    height: calc(100vh - var(--top-offset) - var(--toolbar-height));
    background: var(--bg-gradient);
    border-left: 1px solid var(--border-color);
    padding: 10px;
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 1000;
    box-shadow: calc(-1 * var(--shadow-panel));
    touch-action: pan-y;
    overscroll-behavior: contain;
    transition: transform 0.3s ease-in-out;
}

#panelActions h3 {
    margin: 0 0 10px 0;
    font-size: 10px;
    font-weight: 700;
    color: var(--text-heading);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid #556ee6;
    padding-bottom: 10px;
}

/* Action buttons */
.action-btn {
    width: 100%;
    padding: 8px 10px;
    margin-bottom: 6px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    font-size: 18px;
    font-weight: 500;
    color: var(--text-primary);
    transition: all 0.3s ease;
    box-shadow: var(--shadow-sm);
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: visible;
}

.action-btn .btn-icon {
    font-size: 20px;
    display: inline-block;
}

.action-btn .btn-text {
    display: none;
    margin-left: 6px;
    font-size: 12px;
}

.action-btn:not(:hover) {
    width: 100%;
}

.action-btn.active {
    background: var(--bg-accent);
    color: white;
    border-color: #556ee6;
    box-shadow: 0 3px 8px rgba(85, 110, 230, 0.3);
}

.action-btn:focus,
.action-btn:active {
    outline: none;
}

#zoomIn:focus,
#zoomOut:focus,
#zoomReset:focus,
#editText:focus,
#showAllBtn:focus {
    background: var(--bg-primary);
    color: var(--text-primary);
    border-color: var(--border-color);
}

/* Mobile tooltip */
.mobile-tooltip {
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 11px;
    line-height: 1.4;
    z-index: 1000;
    pointer-events: none;
    animation: fadeInTooltip 0.2s ease;
    word-wrap: break-word;
    white-space: normal;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    text-align: center;
}

@keyframes fadeInTooltip {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Action categories */
.action-category {
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-light);
}

.action-category:last-child {
    border-bottom: none;
}

.action-category h4 {
    font-size: 8px;
    margin: 0 0 12px 0;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 0.8px;
}

.action-category [style*="grid-template-columns"] .action-btn {
    min-width: 40px;
    padding: 8px 5px;
}

.action-category [style*="grid-template-columns"] .action-btn .btn-icon {
    font-size: 14px;
}

/* ============================================
   HOVER STATES (Desktop only)
   ============================================ */

@media (hover: hover) {
    .action-btn:hover .btn-text {
        display: inline-block;
    }
    
    .action-btn:hover {
        background: var(--bg-accent);
        border-color: #556ee6;
        color: white;
        box-shadow: 0 3px 8px rgba(85, 110, 230, 0.25);
        transform: translateY(-1px);
        width: 100%;
        z-index: 10;
    }
}

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */

/* Desktop: Mostrar texto en toolbar buttons */
@media (min-width: 992px) {
    .toolbar-btn .btn-text {
        display: inline-block;
    }
}

/* Tablets y móviles */
@media (max-width: 991px) {
    :root {
        --panel-left-width: 240px;
        --panel-right-width: 70px;
        --symbol-size: 40px;
        --toolbar-height: 50px;
    }

    /* Toolbar ajustes para evitar recortes */
    .toolbar {
        padding: 6px 10px;
        height: var(--toolbar-height);
        left: var(--panel-left-width);
    }

    /* Toolbar buttons: solo iconos */
    .toolbar-btn {
        padding: 6px 10px;
        min-width: 40px;
        justify-content: center;
        height: 38px;
    }
    
    .toolbar-btn .btn-text {
        display: none;
    }
    
    .toolbar-btn .btn-icon {
        font-size: 18px;
        line-height: 1;
    }

    /* Panel izquierdo pegado a la izquierda */
    #panelGallerySymbols {
        left: 0;
    }
    
    #panelGallerySymbols.hidden {
        width: var(--panel-tabs-width);
    }
    
    /* Canvas ajustado */
    #canvasWrapper {
        left: var(--panel-left-width);
        right: var(--panel-right-width);
    }
    
    #canvasWrapper.panel-hidden {
        left: var(--panel-tabs-width);
        right: var(--panel-right-width);
    }
    
    body:has(#panelGallerySymbols.hidden) .toolbar {
        left: var(--panel-tabs-width);
    }
}

/* Móviles pequeños */
@media (max-width: 767px) {
    :root {
        --panel-left-width: 120px;
        --panel-tabs-width: 26px;
        --symbol-size: 35px;
    }

    .tabs-container {
        width: var(--panel-tabs-width);
    }
    
    .tab {
        width: var(--panel-tabs-width);
        height: 94px;
        font-size: 10px;
        padding: 4px;
    }
    
    .tab-content.active {
        grid-template-columns: 1fr;
        gap: 8px;
    }
    
    .symbols-container {
        width: var(--panel-left-width);
        padding: 8px;
    }
    
    .symbol-item {
        padding: 1px;
        min-height: calc(1.3 * var(--symbol-size) + 0px);
    }
    
    .symbol-thumbnail {
        width: calc(1.3 * var(--symbol-size));
        height: calc(1.3 * var(--symbol-size));        
        margin-bottom: 1px;
    }

    .symbol-name {
        font-size: 7px;
        padding-left: 2px;
        padding-right: 2px;        
    }
    
    #panelGallerySymbols.hidden {
        width: var(--panel-tabs-width);
    }
    
    #canvasWrapper.panel-hidden {
        left: var(--panel-tabs-width);
    }
    
    body:has(#panelGallerySymbols.hidden) .toolbar {
        left: var(--panel-tabs-width);
    }

    #panelActions {
        padding: 6px;
    }

    #watermark-footer {
        position: fixed;
        right: calc(var(--panel-right-width));
        bottom: 2px;
        z-index: 999;
        color: #888;
        font-size: 11px;
        background: rgba(255,255,255,0.7);
        padding: 6px 6px;
        border-radius: 8px;
        pointer-events: none; /* Para que no interfiera con clics */
    }    
}