:root {
    --glass-bg: rgba(235, 245, 255, 0.96);
    --glass-border: rgba(255, 255, 255, 0.6);
    --accent: #ff9919;
    --text-color: #183550;
}

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

/* Custom Scrollbar Styles */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb {
    background: rgba(24, 53, 80, 0.2);
    border-radius: 10px;
    transition: 0.3s;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(24, 53, 80, 0.4);
}

* {
    -webkit-tap-highlight-color: transparent;
}

html,
body {
    height: 100%;
    width: 100%;
    overflow: hidden;
    font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
    background-color: #d6eaf2;
}

#vanta-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    /* Static fallback; Vanta.BIRDS canvas draws on top */
    background: linear-gradient(180deg, #cde3ef 0%, #d6eaf2 50%, #e3f2f7 100%);
    overflow: hidden;
}

#mynetwork {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
    touch-action: none; /* Prevent browser scrolling while interacting with the graph on mobile */
}

.info-panel {
    position: absolute;
    top: 24px;
    left: 24px;
    z-index: 10;
    background: var(--glass-bg);
    will-change: transform, opacity;
    padding: 28px;
    border-radius: 24px;
    width: 340px;
    max-height: calc(100% - 48px);
    overflow-y: auto;
    color: var(--text-color);
    box-shadow: 
        0 4px 24px -1px rgba(0, 0, 0, 0.06),
        0 10px 40px -2px rgba(0, 0, 0, 0.1);
    border: 1px solid var(--glass-border);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease;
}

.info-panel::-webkit-scrollbar-track {
    margin-top: 18px;
    margin-bottom: 18px;
}

.info-panel:hover {
    box-shadow: 
        0 6px 30px -1px rgba(0, 0, 0, 0.08),
        0 12px 50px -2px rgba(0, 0, 0, 0.12);
}

h1 {
    font-size: 1.5em;
    margin-bottom: 12px;
    color: #183550;
    line-height: 1.25;
    font-weight: 800;
    letter-spacing: -0.02em;
    padding-top: 45px; /* Space for toggle button on desktop */
}

p {
    font-size: 0.95em;
    margin-bottom: 20px;
    color: #183550;
    line-height: 1.5;
}

.lang-selector,
.filter-selector {
    display: flex;
    gap: 8px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.lang-btn {
    background: rgba(255, 255, 255, 0.3);
    border: 1px solid rgba(24, 53, 80, 0.2);
    color: #183550;
    padding: 6px 10px;
    border-radius: 12px;
    cursor: pointer;
    font-size: 0.85em;
    font-weight: 600;
    -webkit-user-select: none;
    user-select: none;
    transition: opacity 0.3s ease, transform 0.3s ease, background 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

.lang-btn:hover,
.lang-btn.active {
    background: #183550;
    color: white;
    border-color: #183550;
    transform: translateY(-2px);
}

.lang-btn.saving {
    background: #ff9919 !important;
    color: white !important;
    cursor: wait;
}

.lang-btn.saved {
    background: #2e7d32 !important;
    color: white !important;
}

.custom-select {
    position: relative;
    width: 100%;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

.select-trigger {
    background: rgba(215, 233, 252, 0.98);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: #183550;
    padding: 12px 18px;
    border-radius: 15px;
    cursor: pointer;
    font-size: 0.95em;
    font-weight: 600;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: transform 0.3s ease, background 0.3s ease, border-color 0.3s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
}

.select-trigger:hover {
    background: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 0.5);
}

.select-trigger .arrow {
    font-size: 0.8em;
    transition: transform 0.3s ease;
    opacity: 0.6;
}

.custom-select.open .select-trigger .arrow {
    transform: rotate(180deg);
}

.select-options {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    background: rgba(228, 241, 255, 0.99);
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 18px;
    z-index: 1000;
    overflow: hidden;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.12);
    opacity: 0;
    transform: translateY(-10px);
    pointer-events: none;
    transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1), transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.custom-select.open .select-options {
    opacity: 1;
    transform: translateY(0);
    pointer-events: all;
}

.select-option {
    padding: 12px 18px;
    cursor: pointer;
    transition: background 0.2s ease, padding-left 0.2s ease, color 0.2s ease;
    color: #183550;
    font-weight: 500;
    font-size: 0.95em;
}

.select-option:hover {
    background: rgba(255, 255, 255, 0.4);
    padding-left: 22px;
}

.select-option.selected {
    background: rgba(24, 53, 80, 0.9);
    color: white;
}

.hint {
    font-style: italic;
    font-size: 0.85em;
    opacity: 0.8;
    margin-top: 10px;
    border-top: 1px solid rgba(24, 53, 80, 0.1);
    padding-top: 10px;
}

.hint+.hint {
    border-top: none;
    padding-top: 0;
    margin-top: 5px;
}

/* Layout Controls */
.layout-controls {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid rgba(24, 53, 80, 0.1);
}

.layout-controls h3 {
    font-size: 0.9em;
    font-weight: 700;
    color: #183550;
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.8;
}

.layout-buttons {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.layout-btn {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 12px;
    padding: 8px 4px;
    color: #183550;
    font-family: inherit;
    font-size: 0.8em;
    font-weight: 600;
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    text-align: center;
}

.layout-btn:hover {
    background: rgba(255, 255, 255, 0.4);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    border-color: rgba(255, 255, 255, 0.5);
}

.layout-btn:active,
.layout-btn.active {
    background: var(--text-color);
    color: white;
    transform: translateY(0);
    border-color: var(--text-color);
}

.layout-btn span {
    font-size: 0.85em;
    white-space: nowrap;
}

.admin-link-container {
    border-top: 1px solid rgba(24, 53, 80, 0.1);
    margin-top: 15px;
    padding-top: 10px;
}

.admin-link {
    color: #183550;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.9em;
    display: flex;
    align-items: center;
    gap: 5px;
    transition: all 0.3s ease;
}

.admin-link:hover {
    color: #ff9919;
    transform: translateX(5px);
}

.detail-panel {
    position: absolute;
    top: 50%;
    right: 24px;
    transform: translateY(-50%) translateX(440px);
    z-index: 100;
    background: var(--glass-bg);
    will-change: transform, opacity;
    padding: 35px;
    border-radius: 32px;
    width: 400px;
    max-height: 85vh;
    overflow-y: auto;
    color: var(--text-color);
    box-shadow: 
        0 20px 50px -10px rgba(0, 0, 0, 0.15),
        0 10px 30px -5px rgba(0, 0, 0, 0.1);
    border: 1px solid var(--glass-border);
    transition: opacity 0.5s cubic-bezier(0.16, 1, 0.3, 1), transform 0.5s cubic-bezier(0.16, 1, 0.3, 1);
    opacity: 0;
    pointer-events: none;
    overscroll-behavior: contain;
}

.detail-panel::-webkit-scrollbar {
    width: 6px;
}

.detail-panel::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    margin-top: 24px;
    margin-bottom: 24px;
}

.detail-panel::-webkit-scrollbar-thumb {
    background: rgba(24, 53, 80, 0.2);
    border-radius: 10px;
}

.toggle-container {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 15px;
    background: rgba(255, 255, 255, 0.2);
    padding: 8px 15px;
    border-radius: 12px;
    cursor: pointer;
    transition: 0.3s;
}

.toggle-container:hover {
    background: rgba(255, 255, 255, 0.3);
}

.toggle-switch {
    width: 34px;
    height: 18px;
    background: rgba(24, 53, 80, 0.3);
    border-radius: 9px;
    position: relative;
    transition: 0.3s;
}

.toggle-switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 14px;
    height: 14px;
    background: white;
    border-radius: 50%;
    transition: 0.3s;
}

.toggle-container.active .toggle-switch {
    background: #ff9919;
}

.toggle-container.active .toggle-switch::after {
    transform: translateX(16px);
}

.toggle-label {
    font-size: 0.85em;
    font-weight: 600;
}

.detail-panel.active {
    opacity: 1;
    transform: translateY(-50%) translateX(0);
    pointer-events: all;
}

.detail-header {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-bottom: 25px;
}

.detail-avatar {
    width: 90px;
    height: 90px;
    border-radius: 22px;
    border: 4px solid #fff;
    object-fit: cover;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
    background: #fff;
}

.detail-name {
    font-size: 1.7em;
    font-weight: 800;
    margin-bottom: 4px;
    color: #183550;
    line-height: 1.2;
    letter-spacing: -0.01em;
}

.detail-connection-title {
    font-size: 0.75em;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: #ff9919;
    margin-bottom: 15px;
    font-weight: 800;
}

.detail-description {
    font-size: 1.05em;
    line-height: 1.7;
    color: #2c3e50;
    background: rgba(255, 255, 255, 0.4);
    padding: 20px;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.5);
}

.detail-section {
    margin-top: 25px;
    border-top: 1px solid rgba(255, 255, 255, 0.2);
    padding-top: 20px;
}

.detail-section-title {
    font-size: 0.8em;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: #ff9919;
    margin-bottom: 12px;
    font-weight: 800;
}

.connections-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.connection-item {
    background: rgba(255, 255, 255, 0.4);
    padding: 12px 15px;
    border-radius: 15px;
    border: 1px solid rgba(255, 255, 255, 0.5);
}

.connection-with {
    font-size: 0.95em;
    color: #183550;
    margin-bottom: 4px;
}

.connection-desc {
    font-size: 0.9em;
    line-height: 1.5;
    color: #2c3e50;
}

.no-connections {
    font-style: italic;
    color: rgba(24, 53, 80, 0.5);
    font-size: 0.9em;
}

.admin-only {
    display: none !important;
}

.close-detail {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border: none;
    color: #183550;
    font-size: 20px;
    transition: background 0.3s ease, color 0.3s ease, transform 0.3s ease;
}

.close-detail:hover {
    background: #183550;
    color: white;
    transform: rotate(90deg);
}

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

#node-search {
    width: 100%;
    padding: 12px 80px 12px 18px;
    /* Increased right padding for icons */
    border-radius: 15px;
    border: 1px solid rgba(255, 255, 255, 0.5);
    background: rgba(215, 233, 252, 0.98);
    color: #183550;
    font-family: inherit;
    font-size: 0.95em;
    outline: none;
    transition: all 0.3s ease;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.03);
}

#node-search:focus {
    background: rgba(200, 225, 252, 1);
    border-color: #ff9919;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
}

.search-icon {
    position: absolute;
    right: 18px;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0.4;
    pointer-events: none;
    font-size: 1.1em;
}

.search-clear {
    position: absolute;
    right: 42px;
    top: 50%;
    transform: translateY(-50%);
    width: 22px;
    height: 22px;
    background: rgba(24, 53, 80, 0.08);
    border-radius: 50%;
    color: #183550;
    cursor: pointer;
    font-size: 14px;
    display: none;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    z-index: 10;
    line-height: 1;
    padding-bottom: 2px;
}

.search-clear:hover {
    background: rgba(24, 53, 80, 0.2);
    transform: translateY(-50%) scale(1.1);
}

.search-clear.visible {
    display: flex !important;
}

/* Utility Classes */
.flex-gap-10-mt10 {
    display: flex;
    gap: 8px;
    margin-top: 15px;
    flex-wrap: wrap;
}

.flex-1-rounded-p10 {
    flex: 1 1 auto;
    min-width: 80px;
    border-radius: 12px;
    padding: 10px 5px;
    font-size: 0.72em;
    white-space: normal;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    line-height: 1.1;
    min-height: 38px;
}

/* Help Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(24, 53, 80, 0.6);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.modal-content {
    background: rgba(240, 247, 255, 0.99);
    padding: 30px 45px 35px 35px;
    /* Increased right padding for scrollbar comfort */
    border-radius: 25px;
    width: 90%;
    max-width: 550px;
    max-height: 85vh;
    overflow-y: auto;
    overflow-x: hidden;
    direction: ltr;
    /* Force LTR to ensure scrollbar stays on the right */
    /* Reserve space for scrollbar to prevent content shifting */
    overscroll-behavior: contain;
    position: relative;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.4);
    transform: scale(0.9);
    transition: opacity 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275), transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    word-break: break-word;
    /* Prevent long words from overflowing */
}

/* Custom Scrollbar */
.modal-content::-webkit-scrollbar,
.detail-description::-webkit-scrollbar {
    width: 8px;
}

.modal-content::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
    border-radius: 10px;
    margin-top: 18px;
    margin-bottom: 18px;
}

.detail-description::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
    border-radius: 10px;
    margin-top: 14px;
    margin-bottom: 14px;
}

.modal-content::-webkit-scrollbar-thumb,
.detail-description::-webkit-scrollbar-thumb {
    background: rgba(24, 53, 80, 0.2);
    border-radius: 10px;
}

.modal-content::-webkit-scrollbar-thumb:hover,
.detail-description::-webkit-scrollbar-thumb:hover,
.detail-panel::-webkit-scrollbar-thumb:hover {
    background: rgba(24, 53, 80, 0.4);
}

.modal-overlay.active .modal-content {
    transform: scale(1);
}

.close-modal {
    position: absolute;
    top: 15px;
    right: 15px;
    background: none;
    border: none;
    font-size: 28px;
    cursor: pointer;
    color: #183550;
    opacity: 0.5;
    transition: 0.3s;
}

.close-modal:hover {
    opacity: 1;
    transform: rotate(90deg);
}

.help-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-top: 20px;
}

.help-list div {
    font-size: 1.02em;
    line-height: 1.4;
    color: #183550;
    padding: 2px 10px 2px 15px;
    border-left: 3px solid #ff9919;
}

/* Info Panel Toggle (Always Available) */
#info-panel-toggle {
    display: flex !important;
    position: fixed;
    top: 30px;
    left: 30px;
    z-index: 1001;
    width: 36px !important;
    height: 36px !important;
    background: rgba(228, 240, 253, 0.96) !important;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    cursor: pointer;
    justify-content: center;
    align-items: center;
    font-size: 18px;
    color: #183550;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    padding-bottom: 2px;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

#info-panel-toggle:hover {
    background: rgba(24, 53, 80, 0.2) !important;
    transform: scale(1.05);
}

.info-panel.collapsed {
    transform: translateX(-120%);
    opacity: 0;
    pointer-events: none;
}

@media (max-width: 600px) {
    #info-panel-toggle {
        top: 20px;
        left: 20px;
    }

    .info-panel {
        width: calc(100% - 32px);
        top: 75px; /* Spacing for toggle button */
        left: 16px;
        padding: 20px;
        max-height: calc(100% - 100px);
        overflow-y: auto;
        z-index: 1000;
        transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.4s ease;
    }

    .info-panel.collapsed {
        transform: translateX(-120%);
        opacity: 0;
        pointer-events: none;
    }

    h1 {
        font-size: 1.3em;
        padding-top: 0; /* Reset desktop padding on mobile */
    }

    .filter-selector {
        gap: 8px;
    }

    .detail-panel {
        width: 100%;
        bottom: 0;
        right: 0;
        left: 0;
        top: auto;
        transform: translateY(100%);
        border-radius: 32px 32px 0 0;
        max-height: 80vh;
        padding: 25px 20px 60px 20px; /* Added more bottom padding for mobile touch safety */
        box-shadow: 0 -10px 40px rgba(0,0,0,0.15);
        border-left: none;
        border-right: none;
        border-bottom: none;
    }

    .detail-panel.active {
        transform: translateY(0);
    }

    .detail-avatar {
        width: 70px;
        height: 70px;
        border-radius: 18px;
    }

    .detail-name {
        font-size: 1.4em;
    }

    .flex-gap-10-mt10 {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .flex-1-rounded-p10 {
        padding: 12px 6px;
        font-size: 0.8em;
    }

    .admin-only {
        grid-column: span 2;
    }

    #node-search {
        padding: 10px 70px 10px 15px;
        font-size: 0.88em;
    }

    .search-clear {
        right: 38px;
        width: 22px;
        height: 22px;
        font-size: 14px;
    }

    .search-icon {
        right: 15px;
        font-size: 1em;
    }
}


/* Height-based adjustments for 1024x768 and similar */
@media (max-height: 780px) {
    .modal-content {
        padding: 20px 30px;
        max-height: 90vh;
    }

    .help-list {
        gap: 10px;
        margin-top: 15px;
    }

    .help-list div {
        font-size: 0.95em;
        padding: 2px 8px 2px 12px;
    }
}

@media (max-width: 1024px) {
    .modal-content {
        width: 95%;
        padding: 25px 30px;
    }
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(235, 245, 255, 0.95);
    z-index: 3000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: opacity 0.5s ease;
}

.loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 5px solid rgba(24, 53, 80, 0.1);
    border-top: 5px solid #ff9919;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

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

.loading-text {
    font-weight: 600;
    color: #183550;
    letter-spacing: 0.05em;
}

/* Fallback for browsers that do not support custom webkit scrollbars (like Firefox) */
@supports not selector(::-webkit-scrollbar) {
    .info-panel,
    .detail-panel {
        scrollbar-width: thin;
        scrollbar-color: rgba(24, 53, 80, 0.2) transparent;
    }
    .modal-content {
        scrollbar-width: thin;
    }
}

/* Color Scheme Legend Styles */
.color-legend {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 20px;
    padding: 14px;
    background: rgba(255, 255, 255, 0.45);
    border: 1px solid rgba(24, 53, 80, 0.15);
    border-radius: 16px;
    /* backdrop-filter removed for performance — saves GPU recompositing on every frame */
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.88em;
    font-weight: 550;
    color: #244360;
}

.legend-color {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.legend-red {
    background-color: #F44336;
}

.legend-green {
    background-color: #4CAF50;
}

.legend-blue {
    background-color: #2196F3;
}