@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --secondary: #8b5cf6;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --dark: #0f172a;
    --dark-light: #1e293b;
    --dark-lighter: #334155;
    --light: #f8fafc;
    --border: #475569;
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --glass-bg: rgba(30, 41, 59, 0.7);
    --glass-border: rgba(148, 163, 184, 0.1);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
    --tree-line: rgba(99, 102, 241, 0.3);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #334155 100%);
    color: var(--text-primary);
    min-height: 100vh;
    padding: 2rem;
    line-height: 1.6;
}

.container {
    max-width: 1600px;
    margin: 0 auto;
}

/* Header Styles */
.header {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 2rem 2.5rem;
    margin-bottom: 2rem;
    box-shadow: var(--shadow-lg);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1.5rem;
}

.header-content h1 {
    font-size: 2.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.5rem;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1rem;
    font-weight: 400;
}

.header-actions {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

/* Button Styles */
.btn {
    padding: 0.875rem 1.75rem;
    border: none;
    border-radius: 12px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    box-shadow: var(--shadow-sm);
    font-family: 'Inter', sans-serif;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.btn:active {
    transform: translateY(0);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
}

.btn-secondary {
    background: linear-gradient(135deg, var(--secondary) 0%, #7c3aed 100%);
    color: white;
}

.btn-success {
    background: linear-gradient(135deg, var(--success) 0%, #059669 100%);
    color: white;
}

.icon {
    font-size: 1.1rem;
}

/* Stats Bar */
.stats-bar {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 1.25rem 2rem;
    margin-bottom: 2rem;
    display: flex;
    gap: 3rem;
    box-shadow: var(--shadow-sm);
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.stat-label {
    color: var(--text-secondary);
    font-size: 0.95rem;
    font-weight: 500;
}

.stat-value {
    color: var(--primary);
    font-size: 1.5rem;
    font-weight: 700;
}

/* Tree Container */
.tree-container {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    padding: 2rem;
    box-shadow: var(--shadow-md);
}

/* Tree Node Styles */
.tree-node {
    margin: 0;
    padding: 0;
    list-style: none;
}

.tree-node-content {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-radius: 10px;
    transition: all 0.2s ease;
    position: relative;
}

.tree-node-content:hover {
    background: rgba(99, 102, 241, 0.1);
}

/* Module Level (Root) */
.tree-node.module-level>.tree-node-content {
    background: rgba(99, 102, 241, 0.15);
    border-left: 4px solid var(--primary);
    margin-bottom: 0.5rem;
    padding: 1rem 1.25rem;
}

.tree-node.module-level>.tree-node-content:hover {
    background: rgba(99, 102, 241, 0.25);
}

/* Expand/Collapse Toggle */
.tree-toggle {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--primary);
    font-size: 1.2rem;
    font-weight: bold;
    transition: transform 0.3s ease;
    user-select: none;
    flex-shrink: 0;
}

.tree-toggle.expanded {
    transform: rotate(90deg);
}

.tree-toggle:hover {
    color: var(--secondary);
}

/* Checkbox Styles */
.tree-checkbox {
    width: 20px;
    height: 20px;
    cursor: pointer;
    accent-color: var(--primary);
    flex-shrink: 0;
}

.tree-node.module-level .tree-checkbox {
    width: 24px;
    height: 24px;
}

/* Node Label */
.tree-label {
    flex: 1;
    color: var(--text-secondary);
    font-size: 0.95rem;
    font-weight: 500;
    transition: color 0.2s ease;
    cursor: pointer;
    user-select: none;
}

.tree-node.module-level .tree-label {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
}

.tree-node-content:hover .tree-label {
    color: var(--text-primary);
}

/* Feature Count Badge */
.feature-count {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    padding: 0.35rem 0.85rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    flex-shrink: 0;
}

/* Screenshot Button */
.tree-screenshot-btn {
    background: rgba(99, 102, 241, 0.2);
    border: 1px solid rgba(99, 102, 241, 0.3);
    color: var(--primary);
    padding: 0.4rem 0.75rem;
    border-radius: 8px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 500;
    flex-shrink: 0;
}

.tree-screenshot-btn:hover {
    background: rgba(99, 102, 241, 0.3);
    border-color: rgba(99, 102, 241, 0.5);
    transform: scale(1.05);
}

/* Tree Children Container */
.tree-children {
    margin-left: 2.5rem;
    padding-left: 1.5rem;
    border-left: 2px solid var(--tree-line);
    margin-top: 0.5rem;
    overflow: hidden;
    transition: max-height 0.3s ease-out, opacity 0.3s ease-out;
}

.tree-children.collapsed {
    max-height: 0 !important;
    opacity: 0;
    margin-top: 0;
}

.tree-children.expanded {
    opacity: 1;
}

/* Feature Node */
.tree-node.feature-level {
    margin-bottom: 0.25rem;
}

.tree-node.feature-level>.tree-node-content {
    padding: 0.65rem 1rem;
}

/* Connection Lines */
.tree-node.feature-level>.tree-node-content::before {
    content: '';
    position: absolute;
    left: -1.5rem;
    top: 50%;
    width: 1rem;
    height: 2px;
    background: var(--tree-line);
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(8px);
}

.modal-content {
    position: relative;
    background: var(--dark-light);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 2rem;
    width: 1200px;
    height: 800px;
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    z-index: 1001;
}

.modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: rgba(239, 68, 68, 0.2);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: var(--danger);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 1.5rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.modal-close:hover {
    background: rgba(239, 68, 68, 0.3);
    transform: rotate(90deg);
}

.modal-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 1rem;
    color: var(--text-primary);
    flex-shrink: 0;
}

.modal-body {
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    flex: 1;
    overflow: hidden;
    /* Ensure image doesn't overflow container */
    margin: 0.5rem 0;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 0;
}

.modal-body img {
    max-width: 100%;
    max-height: 100%;
    border-radius: 0;
    box-shadow: var(--shadow-md);
    object-fit: contain;
    cursor: default;
    transition: transform 0.1s ease-out;
    /* Faster transition for dragging */
    user-select: none;
    transform-origin: center center;
}

.modal-body img.zoomed {
    cursor: grab;
    /* Transform will be handled by JS */
}

.modal-body img.zoomed:active {
    cursor: grabbing;
}

/* Modal Navigation Buttons */
.modal-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(99, 102, 241, 0.8);
    border: none;
    color: white;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    font-size: 2rem;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    backdrop-filter: blur(10px);
}

.modal-nav:hover {
    background: rgba(99, 102, 241, 1);
    transform: translateY(-50%) scale(1.1);
}

.modal-nav:active {
    transform: translateY(-50%) scale(0.95);
}

.modal-nav-left {
    left: 1rem;
}

.modal-nav-right {
    right: 1rem;
}

.modal-nav:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.modal-nav:disabled:hover {
    background: rgba(99, 102, 241, 0.8);
    transform: translateY(-50%);
}

/* Modal Footer */
.modal-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--glass-border);
    flex-shrink: 0;
}

.image-counter {
    color: var(--primary);
    font-size: 1rem;
    font-weight: 600;
}

.image-name {
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    max-width: 60%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Responsive Design */
@media (max-width: 768px) {
    body {
        padding: 1rem;
    }

    .header {
        padding: 1.5rem;
        flex-direction: column;
        align-items: flex-start;
    }

    .header-content h1 {
        font-size: 1.75rem;
    }

    .header-actions {
        width: 100%;
        flex-direction: column;
    }

    .header-actions .btn {
        width: 100%;
        justify-content: center;
    }

    .stats-bar {
        flex-direction: column;
        gap: 1rem;
    }

    .tree-children {
        margin-left: 1.5rem;
        padding-left: 1rem;
    }

    .tree-node.module-level .tree-label {
        font-size: 1.1rem;
    }

    .modal-content {
        width: 95vw;
        height: 95vh;
    }
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.tree-node {
    animation: fadeIn 0.3s ease-out;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: var(--dark);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb {
    background: var(--dark-lighter);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--border);
}

/* Zoom Controls */
.zoom-controls {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.zoom-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--dark-lighter);
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 1.2rem;
}

.zoom-btn:hover {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
    transform: scale(1.1);
}

.zoom-btn:active {
    transform: scale(0.95);
}

.modal-footer {
    gap: 1rem;
}

.modal-body img {
    cursor: default;
}