/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f8fafc;
    overflow: hidden;
    height: 100vh;
}

/* App Container */
.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
}

/* Header */
.header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-bottom: 1px solid #e2e8f0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    padding: 1.5rem 1rem;
    z-index: 100;
    position: relative;
    overflow: hidden;
}

.header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><defs><pattern id="grain" width="100" height="100" patternUnits="userSpaceOnUse"><circle cx="25" cy="25" r="1" fill="white" opacity="0.1"/><circle cx="75" cy="75" r="1" fill="white" opacity="0.1"/><circle cx="50" cy="10" r="0.5" fill="white" opacity="0.1"/><circle cx="10" cy="60" r="0.5" fill="white" opacity="0.1"/><circle cx="90" cy="40" r="0.5" fill="white" opacity="0.1"/></pattern></defs><rect width="100" height="100" fill="url(%23grain)"/></svg>');
    pointer-events: none;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1400px;
    margin: 0 auto;
    position: relative;
    z-index: 1;
}

.logo-section {
    display: flex;
    align-items: center;
}

.logo {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.logo-icon {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.logo-icon i {
    font-size: 1.75rem;
    color: white;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.logo-text {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.main-title {
    font-size: 1.75rem;
    font-weight: 700;
    color: white;
    margin: 0;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    letter-spacing: 0.5px;
}

.subtitle {
    font-size: 0.875rem;
    color: rgba(255, 255, 255, 0.9);
    margin: 0;
    font-weight: 400;
    letter-spacing: 0.5px;
}

.controls {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.control-group {
    display: flex;
    gap: 0.5rem;
    padding: 0.5rem;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.control-btn {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    padding: 0.75rem;
    cursor: pointer;
    transition: all 0.3s ease;
    color: white;
    font-size: 0.875rem;
    backdrop-filter: blur(10px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.control-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    border-color: rgba(255, 255, 255, 0.5);
}

.control-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Main Content */
.main {
    flex: 1;
    overflow: hidden;
    position: relative;
}

.tree-container {
    width: 100%;
    height: 100%;
    position: relative;
}

/* Tree Viewport - This is where dragging happens */
.tree-viewport {
    width: 100%;
    height: 100%;
    overflow: auto;
    cursor: grab;
    position: relative;
    background: #f8fafc;
    /* Essential for dragging */
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    /* Touch handling */
    touch-action: none;
    -webkit-overflow-scrolling: touch;
}

.tree-viewport:active {
    cursor: grabbing;
}

.tree-viewport.dragging {
    cursor: grabbing !important;
}

/* Tree Wrapper */
.tree-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 2rem;
    min-width: max-content;
    min-height: max-content;
    /* Ensure it can expand beyond viewport */
    width: max-content;
    height: max-content;
}

/* Tree Node Styles */
.tree-node {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 2rem;
    position: relative;
}

.node-card {
    background: white;
    border: 3px solid #2563eb;
    border-radius: 12px;
    padding: 1rem;
    width: 200px;
    min-height: 70px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    position: relative;
    z-index: 10;
    text-align: center;
}

.node-card:hover {
    border-color: #1d4ed8;
    box-shadow: 0 8px 15px rgba(0, 0, 0, 0.15);
    transform: translateY(-2px);
}

.node-card.expanded {
    border-color: #059669;
    background: #f0fdf4;
}

.node-card.collapsed {
    border-color: #f59e0b;
    background: #fffbeb;
}

.node-name {
    font-weight: 600;
    color: #1e293b;
    font-size: 0.875rem;
    line-height: 1.2;
}

.node-info {
    font-size: 0.75rem;
    color: #64748b;
    margin-top: 0.25rem;
}

/* Children Container */
.children-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: 1.5rem;
    position: relative;
    width: 100%;
}

/* Vertical connector from parent to children level */
.vertical-connector {
    width: 4px;
    height: 1.5rem;
    background: #2563eb;
    border-radius: 2px;
    margin-bottom: 0.5rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Children wrapper - horizontal layout */
.children-wrapper {
    display: flex;
    gap: 2rem;
    align-items: flex-start;
    justify-content: center;
    flex-wrap: wrap;
    position: relative;
    padding-top: 1.5rem;
    min-height: 80px;
    width: max-content;
    min-width: max-content;
}

/* Horizontal connector line connecting all children */
.children-wrapper::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: #2563eb;
    border-radius: 2px;
    z-index: 1;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Individual vertical connectors from horizontal line to each child */
.tree-node:not(:first-child)::before {
    content: '';
    position: absolute;
    top: -1.5rem;
    left: 50%;
    transform: translateX(-50%);
    width: 4px;
    height: 1.5rem;
    background: #2563eb;
    border-radius: 2px;
    z-index: 2;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Loading */
.loading {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(5px);
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #e2e8f0;
    border-top: 4px solid #2563eb;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Scrollbar Styling */
.tree-viewport::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

.tree-viewport::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 6px;
}

.tree-viewport::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 6px;
    border: 2px solid #f1f5f9;
}

.tree-viewport::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Responsive Design */
@media (max-width: 768px) {
    .header-content {
        flex-direction: column;
        gap: 1rem;
    }
    
    .logo {
        flex-direction: column;
        text-align: center;
        gap: 0.75rem;
    }
    
    .logo-icon {
        width: 50px;
        height: 50px;
    }
    
    .logo-icon i {
        font-size: 1.5rem;
    }
    
    .main-title {
        font-size: 1.5rem;
    }
    
    .subtitle {
        font-size: 0.8rem;
    }
    
    .controls {
        flex-wrap: wrap;
        justify-content: center;
        gap: 0.5rem;
    }
    
    .control-group {
        padding: 0.25rem;
    }
    
    .control-btn {
        padding: 0.5rem;
        font-size: 0.8rem;
    }
    
    .node-card {
        width: 160px;
        min-height: 60px;
        padding: 0.75rem;
    }
    
    .node-name {
        font-size: 0.8rem;
    }
    
    .children-wrapper {
        gap: 1rem;
    }
}

@media (max-width: 480px) {
    .node-card {
        width: 140px;
        min-height: 50px;
        padding: 0.5rem;
    }
    
    .node-name {
        font-size: 0.75rem;
    }
    
    .children-wrapper {
        gap: 0.75rem;
    }
}
