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

:root {
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --secondary-color: #64748b;
    --accent-color: #f59e0b;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --background-color: #f8fafc;
    --surface-color: #ffffff;
    --border-color: #e2e8f0;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --border-radius: 8px;
    --transition: all 0.2s ease-in-out;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
    min-height: 100vh;
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden;
}

/* Container Layout */
.container {
    display: flex;
    height: 100vh;
    width: 100vw;
    background: var(--surface-color);
    box-shadow: none;
    border-radius: 0;
    margin: 0;
    padding: 0;
    overflow: hidden;
    position: relative;
}

/* Sidebar Styles */
.sidebar {
    width: 350px;
    background: var(--surface-color);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: var(--transition);
    position: relative;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
    color: white;
}

.sidebar-header h1 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.sidebar-header p {
    font-size: 0.875rem;
    opacity: 0.9;
}

.search-container {
    padding: 1rem;
    position: relative;
}

#searchBox {
    width: 100%;
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    background: var(--surface-color);
    transition: var(--transition);
    box-shadow: var(--shadow-sm);
}

#searchBox:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgb(59 130 246 / 0.1);
}

#searchResults {
    position: absolute;
    top: 100%;
    left: 1rem;
    right: 1rem;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    max-height: 300px;
    overflow-y: auto;
    z-index: 1000;
    box-shadow: var(--shadow-lg);
    display: none;
}

.search-result {
    padding: 0.75rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    transition: var(--transition);
}

.search-result:hover {
    background: var(--background-color);
}

.search-result:last-child {
    border-bottom: none;
}

/* Controls Section */
.controls {
    padding: 1rem;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

.controls button {
    padding: 0.5rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    background: var(--surface-color);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
}

.controls button:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.controls button:active {
    transform: translateY(0);
}

/* Tree Styles */
.tree {
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
}

.tree-item {
    margin: 0.25rem 0;
}

.tree-item-content {
    cursor: pointer;
    padding: 0.5rem 0.75rem;
    border-radius: var(--border-radius);
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
}

.tree-item-content:hover {
    background: var(--background-color);
    transform: translateX(4px);
}

.tree-item-content.selected {
    background: var(--primary-color);
    color: white;
    box-shadow: var(--shadow-md);
}

.tree-item-content.selected .tree-toggle {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.tree-item-content.selected .tree-toggle:hover {
    background: rgba(255, 255, 255, 0.3);
}

.tree-item-content.highlighted {
    background: var(--accent-color);
    color: white;
    animation: pulse 2s infinite;
}

.tree-item-content.highlighted .tree-toggle {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.8; }
}

.tree-toggle {
    cursor: pointer;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: var(--transition);
    background: var(--background-color);
    color: var(--text-primary);
}

.tree-toggle:hover {
    background: var(--border-color);
}

.tree-toggle::before {
    content: '▶';
    font-size: 0.75rem;
    transition: var(--transition);
}

.tree-toggle.expanded::before {
    transform: rotate(90deg);
}

.tree-children {
    display: none;
    padding-left: 1.5rem;
    border-left: 2px solid var(--border-color);
    margin-left: 0.5rem;
}

.tree-children.expanded {
    display: block;
    animation: slideDown 0.3s ease-out;
}

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

/* Info Panel */
.info-panel {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
    background: var(--surface-color);
    position: relative;
    min-width: 0;
}

.info-panel h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.info-panel h3 {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 1.5rem 0 1rem;
    color: var(--text-primary);
    border-bottom: 2px solid var(--primary-color);
    padding-bottom: 0.5rem;
}

.info-panel p {
    margin: 1rem 0;
    line-height: 1.7;
    color: var(--text-secondary);
}

.info-panel ul {
    margin: 1rem 0;
    padding-left: 1.5rem;
}

.info-panel li {
    margin: 0.5rem 0;
    color: var(--text-secondary);
}

/* Login Modal */
.login-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: url('images/bg.jpg');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    padding: 1rem;
}

.login-form {
    background: var(--surface-color);
    padding: 2rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 400px;
    text-align: center;
    animation: slideUp 0.3s ease-out;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.login-form h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    color: var(--text-primary);
}

.login-form label {
    display: block;
    margin: 1rem 0 0.5rem;
    text-align: left;
    font-weight: 500;
    color: var(--text-primary);
}

.login-form input {
    width: 100%;
    padding: 0.75rem;
    margin-bottom: 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 0.875rem;
    transition: var(--transition);
}

.login-form input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgb(59 130 246 / 0.1);
}

.login-form button {
    width: 100%;
    padding: 0.75rem;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: var(--border-radius);
    transition: var(--transition);
}

.login-form button:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

#login-error {
    display: none;
    color: var(--danger-color);
    font-size: 0.875rem;
    margin-top: 1rem;
    padding: 0.5rem;
    background: rgb(239 68 68 / 0.1);
    border-radius: var(--border-radius);
}

/* Image Styles */
.image-thumbnails {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.thumbnail {
    width: 100%;
    height: 120px;
    object-fit: cover;
    cursor: pointer;
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    transition: var(--transition);
}

.thumbnail:hover {
    border-color: var(--primary-color);
    transform: scale(1.05);
    box-shadow: var(--shadow-md);
}

#image-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(4px);
    justify-content: center;
    align-items: center;
    z-index: 1000;
    padding: 1rem;
}

.modal-image {
    max-width: 90%;
    max-height: 90%;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    animation: zoomIn 0.3s ease-out;
}

@keyframes zoomIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Mobile Responsive Design */
@media (max-width: 768px) {
    .container {
        flex-direction: column;
        margin: 0;
        padding: 0;
        height: 100vh;
        width: 100vw;
        border-radius: 0;
    }

    .sidebar {
        width: 100%;
        height: 50vh;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        flex-shrink: 0;
    }

    .sidebar-header {
        padding: 1rem;
    }

    .sidebar-header h1 {
        font-size: 1.125rem;
    }

    .controls {
        grid-template-columns: repeat(3, 1fr);
        padding: 0.75rem;
    }

    .controls button {
        font-size: 0.7rem;
        padding: 0.5rem;
    }

    .info-panel {
        height: 50vh;
        padding: 1rem;
        flex: 1;
        min-width: 0;
    }

    .info-panel h2 {
        font-size: 1.25rem;
        margin-bottom: 1rem;
    }

    .info-panel h3 {
        font-size: 1.125rem;
        margin: 1rem 0 0.75rem;
    }

    .login-form {
        margin: 1rem;
        padding: 1.5rem;
    }

    .image-thumbnails {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: 0.75rem;
    }

    .thumbnail {
        height: 100px;
    }
}

@media (max-width: 480px) {
    .container {
        margin: 0;
        padding: 0;
        width: 100vw;
        height: 100vh;
    }

    .controls {
        grid-template-columns: repeat(2, 1fr);
    }

    .controls button {
        font-size: 0.65rem;
        padding: 0.4rem;
    }

    .tree-item-content {
        font-size: 0.8rem;
        padding: 0.4rem 0.6rem;
    }

    .info-panel {
        padding: 0.75rem;
    }

    .info-panel h2 {
        font-size: 1.125rem;
    }

    .info-panel h3 {
        font-size: 1rem;
    }

    .image-thumbnails {
        grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
        gap: 0.5rem;
    }

    .thumbnail {
        height: 80px;
    }
}

/* Tablet Responsive Design */
@media (min-width: 769px) and (max-width: 1024px) {
    .container {
        margin: 0;
        padding: 0;
        width: 100vw;
        height: 100vh;
    }

    .sidebar {
        width: 300px;
    }

    .controls {
        grid-template-columns: repeat(2, 1fr);
    }

    .info-panel {
        padding: 1.5rem;
    }
}

/* Large Screen Enhancements */
@media (min-width: 1025px) {
    .container {
        max-width: none;
        margin: 0;
        padding: 0;
        width: 100vw;
        height: 100vh;
    }

    .sidebar {
        width: 400px;
    }

    .controls {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* Accessibility Improvements */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus Styles for Keyboard Navigation */
button:focus,
input:focus,
.tree-item-content:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Loading States */
.loading {
    opacity: 0.6;
    pointer-events: none;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid var(--border-color);
    border-top: 2px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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