:root {
    --bg-primary: #f8fafc; /* Very light cool gray */
    --bg-secondary: #ffffff;
    --bg-hover: #e2e8f0;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --border-color: #cbd5e1;
    --accent-color: #2563eb; /* Modern blue */
    --accent-light: #eff6ff;
    --sidebar-width: 280px;
    --sidebar-collapsed-width: 0px;
    --header-height: 64px;
    --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);
    --transition-speed: 0.3s;
}

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

body {
    font-family: 'Inter', sans-serif;
    color: var(--text-primary);
    background-color: var(--bg-primary);
    overflow: hidden; /* Prevent body scroll, layout handles it */
}

/* Base Layout Container */
.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* Sidebar styling */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: width var(--transition-speed) ease;
    overflow-x: hidden;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
    z-index: 10;
}

.sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
}

.sidebar-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    border-bottom: 1px solid var(--border-color);
    min-width: var(--sidebar-width);
}

.sidebar-header h2 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 0.375rem;
    padding: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.icon-btn:hover {
    background-color: var(--bg-hover);
    color: var(--text-primary);
}

/* Sidebar Navigation */
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem 0;
    min-width: var(--sidebar-width);
}

/* Sidebar Top Tabs */
.sidebar-footer {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    background-color: var(--bg-secondary);
    min-width: var(--sidebar-width);
}

.footer-tab {
    flex: 1;
    padding: 1rem 0;
    text-align: center;
    background: transparent;
    border: none;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    border-bottom: 2px solid transparent;
}

.footer-tab:hover {
    color: var(--text-primary);
    background-color: var(--bg-hover);
}

.footer-tab.active {
    color: var(--accent-color);
    border-bottom: 2px solid var(--accent-color);
    background-color: var(--accent-light);
}

/* Custom Scrollbar for Sidebar */
.sidebar-nav::-webkit-scrollbar {
    width: 6px;
}
.sidebar-nav::-webkit-scrollbar-track {
    background: transparent;
}
.sidebar-nav::-webkit-scrollbar-thumb {
    background-color: #cbd5e1;
    border-radius: 10px;
}
.sidebar-nav:hover::-webkit-scrollbar-thumb {
    background-color: #94a3b8;
}

.nav-category {
    margin-bottom: 1.5rem;
}

.nav-category-header {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 700;
    color: var(--text-secondary);
    padding: 0.5rem 1.5rem;
    cursor: pointer;
    list-style: none; /* Hide default arrow */
    display: flex;
    align-items: center;
}

.nav-category-header::-webkit-details-marker {
    display: none;
}

/* Custom dropdown arrow */
.nav-category-header::before {
    content: "▼";
    font-size: 0.6rem;
    margin-right: 0.5rem;
    transform: rotate(-90deg);
    transition: transform 0.2s ease;
}

.nav-category[open] .nav-category-header::before {
    transform: rotate(0);
}

.nav-list {
    list-style: none;
    margin-top: 0.5rem;
}

.nav-item {
    padding: 0.75rem 1.5rem 0.75rem 2.5rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    user-select: none;
    position: relative;
}

.nav-item:hover {
    background-color: var(--bg-hover);
    color: var(--text-primary);
}

.nav-item.active {
    background-color: var(--accent-light);
    color: var(--accent-color);
    font-weight: 500;
}

.nav-item.active::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background-color: var(--accent-color);
}

/* Main Content Area */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    position: relative;
    background-color: var(--bg-primary);
}

/* Global Toggle Sidebar Button (Used when sidebar is collapsed) */
.global-toggle {
    position: absolute;
    top: 0.75rem;
    left: 1rem;
    z-index: 20;
    background-color: var(--bg-secondary);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    display: none;
}

.sidebar.collapsed ~ .main-content .global-toggle {
    display: flex;
}

.top-header {
    height: var(--header-height);
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    box-shadow: var(--shadow-sm);
    z-index: 5;
    transition: padding-left var(--transition-speed) ease;
}

.sidebar.collapsed ~ .main-content .top-header {
    padding-left: 4rem; /* Room for global toggle button */
}

.top-header h1 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.header-actions {
    display: flex;
    align-items: center;
}

/* Tooltip implementation */
.tooltip-container {
    position: relative;
    display: inline-block;
}

.tooltip {
    visibility: hidden;
    width: 200px;
    background-color: #1e293b;
    color: #fff;
    text-align: center;
    border-radius: 0.375rem;
    padding: 0.75rem;
    position: absolute;
    z-index: 100;
    top: 125%;
    right: 0;
    opacity: 0;
    transition: opacity 0.3s;
    font-size: 0.75rem;
    line-height: 1.4;
    box-shadow: var(--shadow-md);
}

.tooltip::after {
    content: "";
    position: absolute;
    bottom: 100%;
    right: 1.5rem;
    margin-left: -5px;
    border-width: 5px;
    border-style: solid;
    border-color: transparent transparent #1e293b transparent;
}

.tooltip-container:hover .tooltip {
    visibility: visible;
    opacity: 1;
}

/* Viewer Area */
.viewer-area {
    flex: 1;
    display: flex;
    flex-direction: row;
    position: relative;
    background-color: var(--bg-primary);
    overflow: hidden;
}

.pan-wrapper {
    flex: 1;
    position: relative;
    overflow: hidden;
    /* Pattern background representing canvas */
    background-image: radial-gradient(var(--border-color) 1px, transparent 1px);
    background-size: 20px 20px;
}

.viewer-controls {
    position: absolute;
    bottom: 2rem;
    right: 2rem;
    background-color: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(4px);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    box-shadow: var(--shadow-md);
    z-index: 20;
}

.control-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: 0.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.control-btn:hover {
    background-color: var(--bg-hover);
    color: var(--text-primary);
}

/* Pan Container & Image */
.pan-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    cursor: grab;
    display: flex;
    align-items: center;
    justify-content: center;
    transform-origin: 0 0;
    will-change: transform;
}

.pan-container:active {
    cursor: grabbing;
}

#flowchart-image {
    max-width: none;
    max-height: none;
    transition: opacity 0.3s ease;
    box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
    background: white;
    border-radius: 0.5rem;
    pointer-events: none; /* Prevent browser default image drag */
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .sidebar {
        position: absolute;
        height: 100%;
        left: 0;
        top: 0;
        transform: translateX(0);
        width: var(--sidebar-width);
    }
    
    .sidebar.collapsed {
        transform: translateX(-100%);
        width: var(--sidebar-width); /* keep width but move offscreen */
    }
    
    .sidebar.collapsed ~ .main-content .top-header {
        padding-left: 4rem;
    }

    .top-header {
        padding: 0 1rem;
    }

    .top-header h1 {
        font-size: 1.1rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 60%;
    }

    .header-actions .tooltip {
        display: none;
    }

    .viewer-area {
        flex-direction: column;
    }

    .pan-wrapper {
        flex: 1;
        min-height: 50vh;
    }

    .flow-description {
        flex: none;
        width: 100%;
        height: auto;
        max-height: 50vh;
        border-left: none;
        border-top: 1px solid var(--border-color);
        padding: 1.5rem 1rem;
    }

    .viewer-controls {
        bottom: 1rem;
        right: 1rem;
        flex-direction: row;
    }
}

/* Description Panel */
.flow-description {
    flex: 0 0 400px;
    background-color: var(--bg-secondary);
    border-left: 1px solid var(--border-color);
    padding: 2.5rem 2rem;
    overflow-y: auto;
    box-shadow: -4px 0 15px rgba(0,0,0,0.03);
    z-index: 10;
}

.flow-description h3 {
    margin-bottom: 0.5rem;
    color: var(--text-primary);
    font-size: 1rem;
}

.flow-description h4 {
    margin-top: 1.25rem;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
    font-size: 0.9rem;
}

.flow-description h5 {
    margin-top: 1rem;
    margin-bottom: 0.25rem;
    color: var(--text-primary);
    font-size: 0.85rem;
}

.flow-description p, .flow-description ul {
    font-size: 0.875rem;
    color: var(--text-secondary);
    line-height: 1.5;
    margin-bottom: 0.5rem;
}

.flow-description ul {
    padding-left: 1.5rem;
}

.flow-description li {
    margin-bottom: 0.5rem;
}

/* In-description Tabs */
.module-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
    flex-wrap: wrap;
}

.module-tab {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 0.25rem;
    padding: 0.5rem 1rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}

.module-tab:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.module-tab.active {
    background: var(--accent-light);
    color: var(--accent-color);
    border-color: var(--accent-color);
}

.module-tab-content {
    display: none;
}

.module-tab-content.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

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