/* 1. FLUID UNIVERSAL PROFILE SCHEMES */
:root[data-theme="light"] {
    --bg-main: #f8fafc;
    --bg-panel: #ffffff;
    --border: #e2e8f0;
    --contrast-button-boarder: #e2e8f0;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --accent: #2563eb;
    --hover: #f1f5f9;
}

:root[data-theme="dark"] {
    --bg-main: #090d16;
    --bg-panel: #111827;
    --border: #1f2937;
    --contrast-button-boarder: #9aa1ab;
    --text-primary: #f9fafb;
    --text-secondary: #9ca3af;
    --accent: #3b82f6;
    --hover: #1f2937;
}

body {
    margin: 0;
    padding: 0;
    display: flex;
    height: 100vh;
    font-family: "Calibri", "Arial", sans-serif;
    background-color: var(--bg-main);
    color: var(--text-primary);
    overflow: hidden;
    transition: background 0.2s, color 0.2s;
    -webkit-user-select: none;
    user-select: none;
}

/* 2. SIDEBAR PANEL LAYOUTS */
#sidebar {
    width: 280px;
    height: 100%;
    background-color: var(--bg-panel);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    /*transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);*/
    z-index: 100;
}

    /* 2. ADD a new class for when the user is actively clicking a toggle button */
    #sidebar.animate {
        transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    }

    #sidebar.collapsed {
        transform: translateX(-280px);
        margin-right: -280px;
    }

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
    font-weight: bold;
    text-transform: uppercase;
    font-size: 0.85rem;
    letter-spacing: 1px;
}

.image-list {
    flex: 1;
    overflow-y: auto;
    list-style: none;
    padding: 0;
    margin: 0;
    -webkit-overflow-scrolling: touch;
}

.image-list-item {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    font-size: 0.95rem;
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow:hidden;
}

    .image-list-item:hover {
        background-color: var(--hover);
    }

    .image-list-item.active {
        border-left: 4px solid var(--accent);
        background-color: var(--hover);
    }

    .image-list-item span {
        font-size: 0.75rem;
        color: var(--text-secondary);
    }

/* 3. CORE FRAMEWORK CONTAINERS */
#workspace {
    flex: 1;
    height: 100vh;
    max-height: 100vh;
    min-width: 0;
    position: relative;
    /* Forces an absolute 3-row layout structure */
    display: grid;
    grid-template-rows: auto 1fr auto;
    grid-template-columns: 100%;
}
/* Header locks to the top row automatically */
header {
    background-color: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    padding: 12px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    z-index: 10;
    flex-wrap: wrap; /* Allows wrap adjustments smoothly if text title grows too large */
}

.controls-cluster {
    display: flex;
    gap: 10px; /* Gives navigation chips slightly more breathing room */
    align-items: center;
    max-width: 100%;
}

.header-title {
    font-size: 1rem;
    font-weight: bold;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    /*max-width: 260px;*/ /* Safe truncation bounds mapping */
}

button {
    background-color: var(--bg-main);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 39px;
}

    button:hover {
        background-color: var(--hover);
    }


#contrast-button {
    background-color: var(--bg-main);
    border: 2px solid var(--contrast-button-boarder);
    color: var(--text-primary);
    padding: 8px 12px;
    margin-right:4px;
    margin-left:4px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
}

    #contrast-button:hover {
        background-color: var(--hover);
    }

/* 4. SEGMENTED TAB PANEL CHIPS */
.format-selector {
    display: inline-flex;
    background-color: var(--bg-main);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 2px;
    gap: 2px;
    min-height:38px;
}

.format-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 6px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.75rem;
    font-weight: 600;
    transition: all 0.15s ease;
    min-height: auto;
}

    .format-btn.active {
        background-color: var(--accent);
        color: #ffffff !important;
    }

/* 5. CANVAS CHANNELS */
main {
    background-color: var(--bg-main);
    position: relative;
    overflow: hidden;
    width: 100%;
    height: 100%;
}

#osd-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

footer {
    background-color: var(--bg-panel);
    border-top: 1px solid var(--border);
    padding: 12px 15px;
    font-family: monospace;
    font-size: 0.6rem;
    text-align: center;
    color: var(--text-secondary);
    line-height: 1.4;
    z-index: 10; /* Forces it to stay on top of the background canvas layers */
}
.node-counter {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

/* 6. METADATA DRAWER SLIDE SYSTEM */
#info-drawer {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 45%;
    background-color: var(--bg-panel);
    border-top: 1px solid var(--border);
    z-index: 85;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.15);
}

    #info-drawer.hidden {
        transform: translateY(100%);
    }

.info-drawer-header {
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

    .info-drawer-header h3 {
        margin: 0;
        font-size: 1rem;
        text-transform: uppercase;
        letter-spacing: 0.5px;
        color: var(--accent);
    }

.info-drawer-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
    line-height: 1.5;
    font-size: 0.95rem;
    -webkit-overflow-scrolling: touch;
}

    .info-drawer-body h4 {
        margin: 15px 0 5px 0;
        font-size: 0.85rem;
        text-transform: uppercase;
        color: var(--text-secondary);
    }

    .info-drawer-body p {
        margin: 0 0 10px 0;
    }

    .info-drawer-body code {
        background-color: var(--bg-main);
        padding: 3px 6px;
        border-radius: 4px;
        font-family: monospace;
        border: 1px solid var(--border);
    }

/* 7. GLASS BACKDROP SHEET LAYER OVERLAYS */
#mobile-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(2px);
    z-index: 90;
}

/* 8. MOBILE VIEW DISPLAY TUNING RESPONSIVE LAYOUTS */
@media (max-width: 768px) {
    #sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        transform: translateX(0);
        margin-right: 0;
        box-shadow: 10px 0 30px rgba(0,0,0,0.25);
    }

        #sidebar.collapsed {
            transform: translateX(-280px);
        }

        #sidebar:not(.collapsed) ~ #mobile-overlay {
            display: block;
        }

    #info-drawer {
        height: 60%;
    }

    header {
        flex-direction: column;
        align-items: stretch;
        padding: 10px;
        gap: 8px;
    }

    .header-title {
        max-width: 100%;
        font-size: 0.95rem;
    }

    .controls-cluster {
        justify-content: space-between;
        width: 100%;
    }

    .format-selector {
        flex: 1;
    }

    .format-btn {
        flex: 1;
        text-align: center;
        padding: 8px 4px;
    }

    .node-counter {
        font-size: 0.8rem;
    }

    footer {
        font-size: 0.3rem;
        padding: 8px;
    }
}


/* ==========================================================================
   LISTING VIEW CARD MODULES (FIXED STRUCTURE BUILD)
   ========================================================================== */

.catalog-grid {
    display: grid;
    /* Changed auto-fill to auto-fit to preserve column layout structures */
    grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
    gap: 24px;
    margin-bottom: 40px;
    width: 100%;
    /* Keep everything neatly aligned to the left edge of your page space */
    justify-content: start;
    justify-items: start;
}

.catalog-card {
    background-color: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    cursor: pointer;
    transition: transform 0.2s, border-color 0.2s;
    min-height: 280px; /*Hani:340px;*/
    height: 100%;
    width: 100%;
    /* FIX: Prevents a single card from stretching across the entire width */
    max-width: 320px;
}

    .catalog-card:hover {
        transform: translateY(-4px);
        border-color: var(--accent);
    }

.thumbnail-space {
    width: 100%;
    height: 160px; /* Locked fixed height layout */
    background-color: var(--bg-main);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border-bottom: 1px solid var(--border);
    /* FIX: Absolutely blocks text panels from squashing or flattening this area */
    flex-shrink: 0;
}

    .thumbnail-space img {
        width: 100%;
        height: 100%;
        object-fit: cover;
        opacity: 0.85;
    }

.card-meta {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    /* FIX: Instructs this text cell container to stretch down dynamically */
    flex: 1 1 auto;
    min-height: 160px;
    background-color: var(--bg-panel);
    box-sizing: border-box;
}

    .card-meta strong {
        font-size: 0.95rem;
        color: var(--text-primary);
        line-height: 1.4;
        font-weight: 700;
        /* FIX: Force wrapping controls */
        white-space: normal !important;
        word-break: break-word !important;
        overflow-wrap: break-word;
    }

    .card-meta span {
        font-size: 0.75rem;
        color: var(--text-secondary);
        font-family: monospace;
        line-height: 1.4;
        margin-top: auto; /* Aligns dataset id string to the absolute bottom of the container */
        /* FIX: Force long string codes with zero spaces to break gracefully on borders */
        white-space: normal !important;
        word-break: break-all !important;
        overflow-wrap: break-word;
    }
