/* Estilos inspirados en jsonviewer.stack.hu */

/* Reset y base */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f5f5f5;
    color: #333;
    line-height: 1.4;
}

/* Contenedor principal */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* Paneles */
.panel {
    background: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.panel-header {
    background: #f8f9fa;
    border-bottom: 1px solid #ddd;
    padding: 10px 15px;
    font-weight: bold;
    color: #666;
}

/* Editor JSON */
#jsonInput {
    width: 100%;
    height: 400px;
    padding: 15px;
    border: none;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.4;
    resize: vertical;
    background: #f8f9fa;
    color: #333;
}

/* Controles */
.controls {
    padding: 10px 15px;
    background: #f8f9fa;
    border-bottom: 1px solid #ddd;
    display: flex;
    gap: 10px;
    align-items: center;
}

.btn {
    padding: 6px 12px;
    border: 1px solid #ccc;
    background: white;
    color: #333;
    border-radius: 3px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
}

.btn:hover {
    background: #e9ecef;
    border-color: #999;
}

.btn.primary {
    background: #007bff;
    color: white;
    border-color: #007bff;
}

.btn.primary:hover {
    background: #0056b3;
    border-color: #0056b3;
}

.btn.success {
    background: #28a745;
    color: white;
    border-color: #28a745;
}

.btn.success:hover {
    background: #1e7e34;
    border-color: #1e7e34;
}

/* Vista de árbol */
#treeView {
    height: 600px;
    overflow-y: auto;
    padding: 15px;
    background: white;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.4;
}

/* Estructura del árbol mejorada */
.json-tree {
    position: relative;
    font-size: 14px;
    line-height: 1.6;
    padding: 12px;
}

.json-node {
    position: relative;
    margin-left: 24px;
    padding: 6px 8px 6px 12px;
    min-height: 32px;
    display: flex;
    align-items: center;
    transition: all 0.2s ease;
    border-radius: 4px;
}

.json-node:hover {
    background: #f0f7ff;
    transform: translateX(2px);
}

/* Líneas verticales del árbol - conectan nodos hermanos */
.json-node::before {
    content: '';
    position: absolute;
    left: -12px;
    top: -6px;
    bottom: 50%;
    width: 2px;
    background: linear-gradient(to bottom, #cbd5e1 0%, #94a3b8 100%);
    border-radius: 2px;
    opacity: 0.6;
}

/* Líneas horizontales del árbol - conectan padre con hijo */
.json-node::after {
    content: '';
    position: absolute;
    left: -12px;
    top: 50%;
    width: 12px;
    height: 2px;
    background: linear-gradient(to right, #94a3b8, rgba(148, 163, 184, 0.3));
    border-radius: 2px;
}

/* Primer nodo no tiene línea vertical superior */
.json-tree > .json-node:first-child::before {
    top: 50%;
}

/* Último hijo de cualquier nivel: línea vertical solo hasta su centro */
.json-node:last-child::before {
    bottom: 50%;
}

/* Estilo especial para nodos expandibles (con hijos) */
.json-node.expandable {
    font-weight: 500;
}

/* Línea vertical continua para nodos con hijos expandidos */
.json-node.expanded-parent {
    position: relative;
}

.json-node.expanded-parent::before {
    bottom: -6px;
    background: linear-gradient(to bottom, #cbd5e1 0%, #94a3b8 50%, #cbd5e1 100%);
    opacity: 0.7;
}

/* Nodos expandidos con borde lateral de color */
.json-node-expanded {
    background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
    border-left: 3px solid #3b82f6;
    padding-left: 12px;
    box-shadow: 0 1px 3px rgba(59, 130, 246, 0.1);
    margin-bottom: 4px;
}

/* Líneas del árbol */
.json-line {
    padding: 4px 0;
    display: flex;
    align-items: center;
    cursor: pointer;
    position: relative;
    min-height: 24px;
    transition: all 0.15s ease;
}

.json-line:hover {
    background: linear-gradient(to right, #f8fafc, transparent);
}

/* Iconos de expansión mejorados */
.toggle-icon {
    display: inline-block;
    width: 20px;
    height: 20px;
    text-align: center;
    margin-right: 6px;
    color: #3b82f6;
    font-size: 14px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    border-radius: 4px;
    line-height: 20px;
    background: transparent;
}

.toggle-icon:hover {
    background: #dbeafe;
    transform: scale(1.2);
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1);
}

.toggle-icon.expanded {
    transform: rotate(90deg);
    color: #2563eb;
}

.toggle-icon.expanded:hover {
    transform: rotate(90deg) scale(1.2);
    background: #dbeafe;
}

.toggle-icon.collapsed {
    transform: rotate(0deg);
}

/* Contenedor de hijos con animación */
.json-children {
    position: relative;
    overflow: hidden;
    animation: slideDown 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

/* Indicadores de nivel con colores por profundidad - Paleta extendida */
.json-node[data-depth="0"]::before {
    background: linear-gradient(to bottom, #fca5a5 0%, #ef4444 50%, #fca5a5 100%);
    width: 3px;
    opacity: 0.85;
}

.json-node[data-depth="0"]::after {
    background: linear-gradient(to right, #ef4444, rgba(239, 68, 68, 0.2));
    width: 14px;
}

.json-node[data-depth="1"]::before {
    background: linear-gradient(to bottom, #fcd34d 0%, #f59e0b 50%, #fcd34d 100%);
    width: 2.5px;
    opacity: 0.8;
}

.json-node[data-depth="1"]::after {
    background: linear-gradient(to right, #f59e0b, rgba(245, 158, 11, 0.2));
    width: 14px;
}

.json-node[data-depth="2"]::before {
    background: linear-gradient(to bottom, #86efac 0%, #22c55e 50%, #86efac 100%);
    width: 2.5px;
    opacity: 0.75;
}

.json-node[data-depth="2"]::after {
    background: linear-gradient(to right, #22c55e, rgba(34, 197, 94, 0.2));
    width: 13px;
}

.json-node[data-depth="3"]::before {
    background: linear-gradient(to bottom, #6ee7b7 0%, #14b8a6 50%, #6ee7b7 100%);
    width: 2.5px;
    opacity: 0.75;
}

.json-node[data-depth="3"]::after {
    background: linear-gradient(to right, #14b8a6, rgba(20, 184, 166, 0.2));
    width: 13px;
}

.json-node[data-depth="4"]::before {
    background: linear-gradient(to bottom, #7dd3fc 0%, #0ea5e9 50%, #7dd3fc 100%);
    width: 2.5px;
    opacity: 0.7;
}

.json-node[data-depth="4"]::after {
    background: linear-gradient(to right, #0ea5e9, rgba(14, 165, 233, 0.2));
    width: 13px;
}

.json-node[data-depth="5"]::before {
    background: linear-gradient(to bottom, #93c5fd 0%, #3b82f6 50%, #93c5fd 100%);
    width: 2.5px;
    opacity: 0.7;
}

.json-node[data-depth="5"]::after {
    background: linear-gradient(to right, #3b82f6, rgba(59, 130, 246, 0.2));
    width: 12px;
}

.json-node[data-depth="6"]::before {
    background: linear-gradient(to bottom, #a5b4fc 0%, #6366f1 50%, #a5b4fc 100%);
    width: 2px;
    opacity: 0.65;
}

.json-node[data-depth="6"]::after {
    background: linear-gradient(to right, #6366f1, rgba(99, 102, 241, 0.2));
    width: 12px;
}

.json-node[data-depth="7"]::before {
    background: linear-gradient(to bottom, #c4b5fd 0%, #8b5cf6 50%, #c4b5fd 100%);
    width: 2px;
    opacity: 0.65;
}

.json-node[data-depth="7"]::after {
    background: linear-gradient(to right, #8b5cf6, rgba(139, 92, 246, 0.2));
    width: 12px;
}

.json-node[data-depth="8"]::before {
    background: linear-gradient(to bottom, #d8b4fe 0%, #a855f7 50%, #d8b4fe 100%);
    width: 2px;
    opacity: 0.6;
}

.json-node[data-depth="8"]::after {
    background: linear-gradient(to right, #a855f7, rgba(168, 85, 247, 0.2));
    width: 12px;
}

.json-node[data-depth="9"]::before {
    background: linear-gradient(to bottom, #f0abfc 0%, #d946ef 50%, #f0abfc 100%);
    width: 2px;
    opacity: 0.6;
}

.json-node[data-depth="9"]::after {
    background: linear-gradient(to right, #d946ef, rgba(217, 70, 239, 0.2));
    width: 12px;
}

.json-node[data-depth="10"]::before {
    background: linear-gradient(to bottom, #f9a8d4 0%, #ec4899 50%, #f9a8d4 100%);
    width: 2px;
    opacity: 0.6;
}

.json-node[data-depth="10"]::after {
    background: linear-gradient(to right, #ec4899, rgba(236, 72, 153, 0.2));
    width: 12px;
}

.json-node[data-depth="11"]::before {
    background: linear-gradient(to bottom, #fda4af 0%, #f43f5e 50%, #fda4af 100%);
    width: 2px;
    opacity: 0.55;
}

.json-node[data-depth="11"]::after {
    background: linear-gradient(to right, #f43f5e, rgba(244, 63, 94, 0.2));
    width: 11px;
}

/* Nodos de mayor profundidad (12+) - ciclo de colores */
.json-node[data-depth]::before {
    opacity: 0.5;
    width: 2px;
}

.json-node[data-depth]::after {
    width: 11px;
}

/* Efecto arcoíris para niveles muy profundos (12+) */
.json-node:not([data-depth="0"]):not([data-depth="1"]):not([data-depth="2"]):not([data-depth="3"]):not([data-depth="4"]):not([data-depth="5"]):not([data-depth="6"]):not([data-depth="7"]):not([data-depth="8"]):not([data-depth="9"]):not([data-depth="10"]):not([data-depth="11"])::before {
    background: linear-gradient(to bottom, 
        #fb7185 0%, 
        #f97316 16.66%, 
        #eab308 33.33%, 
        #22c55e 50%, 
        #14b8a6 66.66%, 
        #3b82f6 83.33%, 
        #a855f7 100%
    );
    animation: rainbow-pulse 3s ease-in-out infinite;
}

@keyframes rainbow-pulse {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 0.7; }
}

/* Efecto de resplandor al hover sobre nodos expandibles */
.json-node:has(.toggle-icon):hover {
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.1);
}

/* Líneas horizontales más visibles en hover */
.json-node:hover::after {
    background: linear-gradient(to right, #3b82f6, transparent);
    height: 2px;
}

/* Animación suave para expansión de nodos */
.json-node.expanding {
    animation: expandNode 0.3s ease-out;
}

@keyframes expandNode {
    from {
        background: #dbeafe;
    }
    to {
        background: transparent;
    }
}

/* Resaltado de búsqueda */
.json-search-highlight {
    background-color: #ffeb3b !important;
    border-radius: 3px;
    padding: 2px 4px;
    margin: -2px -4px;
    box-shadow: 0 0 0 2px #fdd835;
    animation: highlight-pulse 0.3s ease-in-out;
}
/* Match activo (actual) */
.json-search-current {
    outline: 2px solid #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.35);
    border-radius: 6px;
}

@keyframes highlight-pulse {
    0% {
        background-color: #fff59d;
    }
    50% {
        background-color: #ffeb3b;
    }
    100% {
        background-color: #ffeb3b;
    }
}

/* Colores para valores JSON */
.json-key {
    color: #881391;
    font-weight: 500;
}

.json-index {
    color: #0066cc;
    font-weight: 600;
}

.json-colon {
    color: #666;
    margin: 0 4px;
}

.json-value {
    font-family: 'Courier New', monospace;
}

.json-string {
    color: #c41a16;
}

.json-number {
    color: #1c00cf;
}

.json-boolean {
    color: #0d22aa;
    font-weight: bold;
}

.json-null {
    color: #808080;
    font-style: italic;
}

.json-icon {
    margin-right: 6px;
    color: #666;
    font-size: 12px;
}

.json-meta {
    color: #999;
    font-size: 12px;
    margin-left: 4px;
}

.json-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 2px 6px;
    margin-right: 4px;
    color: #666;
    font-size: 10px;
    transition: color 0.2s;
}

.json-toggle:hover {
    color: #333;
}

/* Estadísticas JSON */
.stats-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    border-bottom: 1px solid #f0f0f0;
    transition: background-color 0.2s;
}

.stats-item:hover {
    background-color: #f8f9fa;
}

.stats-item:last-child {
    border-bottom: none;
}

.stats-label {
    font-weight: 500;
    color: #666;
    font-size: 13px;
}

.stats-value {
    font-weight: 600;
    color: #0066cc;
    font-size: 14px;
    font-family: 'Courier New', monospace;
}

/* Menú contextual */
.context-menu {
    user-select: none;
}

.context-menu-item {
    padding: 8px 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background-color 0.15s ease;
}

.context-menu-item:hover {
    background-color: #f0f8ff;
}

.context-menu-item i {
    width: 16px;
    text-align: center;
    color: #666;
}

.context-menu-separator {
    height: 1px;
    background-color: #eee;
    margin: 4px 0;
}

/* Contenedor de notificaciones apiladas (toasts) */
.notification-container {
    position: fixed;
    right: 20px;
    bottom: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 1000;
}

/* Notificaciones */
.notification {
    position: relative; /* ahora dentro del contenedor */
    padding: 12px 16px;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    max-width: 300px;
    font-size: 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    opacity: 1;
    transform: translateY(0);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.notification-info {
    background: #d1ecf1;
    color: #0c5460;
    border: 1px solid #bee5eb;
    opacity: 0.95;
}

.notification-success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
    opacity: 0.95;
}

.notification-warning {
    background: #fff3cd;
    color: #856404;
    border: 1px solid #ffeaa7;
    opacity: 0.98;
}

.notification-error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
    opacity: 1;
}

.notification-close {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    padding: 0;
    margin-left: 8px;
    color: inherit;
    opacity: 0.7;
}

.notification-close:hover {
    opacity: 1;
}

/* Animación de salida */
.notification-hide {
    opacity: 0;
    transform: translateY(8px);
}

/* Marca visual en el editor cuando hay error de JSON */
#json-editor.json-error {
    border-color: #e3342f !important; /* rojo */
    box-shadow: inset 0 0 0 2px rgba(227, 52, 47, 0.15);
    background-color: #fff5f5;
}

/* Modo fullscreen */
.app-container:fullscreen {
    background: white;
}

.app-container:fullscreen .editor-panel {
    display: none !important;
}

.app-container:fullscreen .tree-panel {
    flex: 1 !important;
    max-width: none !important;
}

.app-container:fullscreen .toolbar {
    position: fixed !important;
    top: 10px !important;
    right: 10px !important;
    z-index: 1001 !important;
    background: rgba(255, 255, 255, 0.95) !important;
    border-radius: 6px !important;
    padding: 8px !important;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15) !important;
}

/* Modales */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    backdrop-filter: blur(2px);
}

.modal {
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    max-width: 600px;
    width: 90%;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transform: scale(0.9);
    opacity: 0;
    transition: all 0.3s ease;
}

.modal.modal-show {
    transform: scale(1);
    opacity: 1;
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f8f9fa;
}

.modal-header h3 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
    color: #333;
}

.modal-close {
    background: none;
    border: none;
    font-size: 28px;
    cursor: pointer;
    color: #999;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s;
}

.modal-close:hover {
    color: #333;
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: 16px 20px;
    border-top: 1px solid #e0e0e0;
    background: #f8f9fa;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-actions {
    display: flex;
    gap: 10px;
}

/* Formularios en modales */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: #555;
    font-size: 14px;
}

.form-hint {
    display: block;
    margin-top: 6px;
    font-size: 12px;
    color: #888;
    font-style: italic;
}

.current-value {
    padding: 10px 12px;
    background: #f8f9fa;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    color: #0066cc;
    font-size: 14px;
    margin-bottom: 10px;
}

.form-input,
.form-textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    font-family: 'Courier New', monospace;
    transition: border-color 0.2s;
}

.form-input:focus,
.form-textarea:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
}

.form-input[type="text"],
.form-input[type="number"] {
    font-size: 16px;
    padding: 12px 14px;
}

.form-textarea {
    resize: vertical;
    min-height: 100px;
}

.value-input-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.value-type-selector {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    background: white;
    cursor: pointer;
}

.json-preview {
    background: #f5f5f5;
    padding: 12px;
    border-radius: 4px;
    margin-bottom: 16px;
    border: 1px solid #e0e0e0;
}

.json-preview pre {
    margin: 0;
    font-size: 12px;
    color: #333;
    overflow-x: auto;
}

/* Botones del modal */
.btn-primary {
    background: #007bff;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.2s;
}

.btn-primary:hover {
    background: #0056b3;
}

.btn-cancel {
    background: #6c757d;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.2s;
}

.btn-cancel:hover {
    background: #5a6268;
}

.btn-secondary {
    background: #dc3545;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.2s;
}

.btn-secondary:hover {
    background: #c82333;
}

/* Modo fullscreen del árbol */
.tree-panel.fullscreen-mode {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    z-index: 1000 !important;
    background: white !important;
    margin: 0 !important;
    max-width: none !important;
}

.tree-panel.fullscreen-mode #json-tree {
    height: calc(100vh - 100px);
    overflow-y: auto;
}

/* Responsive */
@media (max-width: 768px) {
    .container {
        padding: 10px;
    }

    .controls {
        flex-wrap: wrap;
    }

    .btn {
        padding: 8px 16px;
        font-size: 14px;
    }

    #jsonInput {
        height: 300px;
        font-size: 12px;
    }

    #treeView {
        height: 400px;
        font-size: 12px;
    }

    .modal {
        max-width: 95%;
    }

    .modal-header h3 {
        font-size: 18px;
    }

    .modal-footer {
        flex-direction: column;
        gap: 10px;
    }

    .modal-actions {
        width: 100%;
    }

    .modal-actions button {
        flex: 1;
    }
}
