* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-bg: #ffffff;
    --secondary-bg: #f5f5f5;
    --sidebar-bg: #fafafa;
    --border-color: #e0e0e0;
    --text-primary: #202124;
    --text-secondary: #5f6368;
    --accent-color: #1a73e8;
    --hover-color: #e8f0fe;
    --button-hover: #174ea6;
    --shadow: 0 1px 2px 0 rgba(60,64,67,0.3), 0 1px 3px 1px rgba(60,64,67,0.15);
}

body {
    font-family: 'Roboto', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--primary-bg);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
}

/* Header */
.header {
    height: 48px;
    background: #5f2c82;
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    z-index: 100;
}

.header h1 {
    font-size: 18px;
    font-weight: 500;
}

.header-links {
    display: flex;
    gap: 15px;
}

.nav-link {
    color: rgba(255,255,255,0.9);
    text-decoration: none;
    font-size: 14px;
    transition: color 0.2s;
}

.nav-link:hover {
    color: white;
}

/* Main Container */
.main-container {
    display: flex;
    height: calc(100vh - 48px);
    overflow: hidden;
}

/* Sidebars */
.left-sidebar,
.right-sidebar {
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    flex-shrink: 0;
}

.left-sidebar {
    width: 280px;
}

.right-sidebar {
    width: 320px;
    border-right: none;
    border-left: 1px solid var(--border-color);
}

.sidebar-section {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-section h3 {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 12px;
    letter-spacing: 0.5px;
}

/* Data Info */
.data-info {
    margin-bottom: 16px;
}

.info-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    font-size: 13px;
}

.info-label {
    color: var(--text-secondary);
}

/* Controls */
.control-group {
    margin-bottom: 16px;
}

.control-label {
    display: block;
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.control-select,
.dataset-select {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 13px;
    background: white;
    cursor: pointer;
}

.checkbox-group {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}

.checkbox-group input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.help-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--text-secondary);
    color: white;
    font-size: 11px;
    cursor: help;
    margin-left: auto;
}

/* Projection Tabs */
.projection-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.projection-tab {
    flex: 1;
    padding: 8px;
    border: 1px solid var(--border-color);
    background: white;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.projection-tab:hover {
    background: var(--hover-color);
}

.projection-tab.active {
    background: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}

/* Projection Controls */
.projection-controls {
    display: block;
}

.projection-controls.hidden {
    display: none;
}

.component-selectors {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.component-select {
    padding: 6px 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 12px;
    background: white;
}

.variance-info {
    margin-top: 8px;
    padding: 8px;
    background: #f0f4ff;
    border-radius: 4px;
}

.info-text {
    font-size: 12px;
    color: var(--text-secondary);
}

.slider {
    width: calc(100% - 50px);
    height: 4px;
    border-radius: 2px;
    outline: none;
    -webkit-appearance: none;
    background: #ddd;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent-color);
    cursor: pointer;
}

.slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent-color);
    cursor: pointer;
    border: none;
}

.value-display {
    display: inline-block;
    width: 40px;
    text-align: right;
    font-size: 13px;
    color: var(--text-secondary);
    margin-left: 8px;
}

.number-input {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 13px;
}

.run-button,
.action-button {
    width: 100%;
    padding: 10px;
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.run-button:hover,
.action-button:hover {
    background: var(--button-hover);
}

.action-button {
    margin-bottom: 8px;
}

.run-button:disabled,
.action-button:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.status-text {
    margin-top: 8px;
    font-size: 12px;
    color: var(--text-secondary);
    text-align: center;
}

/* Visualization Area */
.visualization-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    background: var(--secondary-bg);
}

.toolbar {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
    background: white;
    border-bottom: 1px solid var(--border-color);
}

.tool-button {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-color);
    background: white;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.tool-button:hover {
    background: var(--hover-color);
}

.tool-button.active {
    background: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}

.toolbar-divider {
    width: 1px;
    height: 24px;
    background: var(--border-color);
    margin: 0 4px;
}

.canvas-container {
    flex: 1;
    position: relative;
    overflow: hidden;
}

/* Word Labels */
.word-label {
    position: absolute;
    font-size: 12px;
    font-family: 'Roboto', Arial, sans-serif;
    color: #333;
    background: rgba(255, 255, 255, 0.9);
    padding: 2px 6px;
    border-radius: 3px;
    pointer-events: none;
    white-space: nowrap;
    transform: translate(-50%, -50%);
    z-index: 10;
    font-weight: 500;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.word-label.selected {
    font-size: 16px;
    font-weight: 700;
    color: #d94f5c;
    background: rgba(255, 255, 255, 0.95);
    padding: 4px 10px;
    box-shadow: 0 2px 6px rgba(217, 79, 92, 0.3);
    z-index: 20;
}

.word-label.neighbor {
    font-size: 13px;
    font-weight: 600;
    color: #8b6914;
    background: rgba(255, 255, 255, 0.92);
    z-index: 15;
}

.status-bar {
    padding: 6px 12px;
    background: white;
    border-top: 1px solid var(--border-color);
    font-size: 12px;
    color: var(--text-secondary);
}

/* Search */
.search-container {
    position: relative;
    margin-bottom: 12px;
}

.search-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 14px;
}

.search-input:focus {
    outline: none;
    border-color: var(--accent-color);
}

.search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    max-height: 200px;
    overflow-y: auto;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    margin-top: 4px;
    box-shadow: var(--shadow);
    z-index: 10;
    display: none;
}

.search-results.show {
    display: block;
}

.search-result-item {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 13px;
    transition: background 0.2s;
}

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

.search-info {
    margin-bottom: 12px;
}

/* Nearest Neighbors */
.metric-buttons {
    display: flex;
    gap: 8px;
}

.metric-button {
    flex: 1;
    padding: 6px 12px;
    border: 1px solid var(--border-color);
    background: white;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.metric-button:hover {
    background: var(--hover-color);
}

.metric-button.active {
    background: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}

.selected-word {
    padding: 12px;
    background: #f0f4ff;
    border-radius: 4px;
    margin-bottom: 12px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    text-align: center;
}

.neighbors-list {
    max-height: 400px;
    overflow-y: auto;
}

.neighbor-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    margin-bottom: 4px;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.neighbor-item:hover {
    background: var(--hover-color);
    border-color: var(--accent-color);
}

.neighbor-word {
    font-size: 13px;
    color: var(--accent-color);
    font-weight: 500;
}

.neighbor-distance {
    font-size: 12px;
    color: var(--text-secondary);
}

/* Bookmarks */
.bookmarks-list {
    max-height: 200px;
    overflow-y: auto;
}

.empty-state {
    padding: 20px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 13px;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loading-overlay.hidden {
    display: none;
}

.loading-content {
    text-align: center;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--border-color);
    border-top-color: var(--accent-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 16px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-text {
    font-size: 14px;
    color: var(--text-secondary);
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--secondary-bg);
}

::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #aaa;
}

/* Responsive */
@media (max-width: 1200px) {
    .left-sidebar {
        width: 240px;
    }

    .right-sidebar {
        width: 280px;
    }
}

@media (max-width: 900px) {
    .left-sidebar,
    .right-sidebar {
        position: absolute;
        top: 0;
        bottom: 0;
        z-index: 50;
        box-shadow: var(--shadow);
    }

    .left-sidebar {
        left: -280px;
        transition: left 0.3s;
    }

    .left-sidebar.open {
        left: 0;
    }

    .right-sidebar {
        right: -320px;
        transition: right 0.3s;
    }

    .right-sidebar.open {
        right: 0;
    }
}
