:root {
    --footer-height: 45px;      /* actual footer height */
    --scrollbar-height: 18px;   /* horizontal scrollbar */
}

html,
body {
    height: 100%;
    margin: 0;
    overflow: hidden;
}
.read-paper-btn {
    padding: 2px !important;
    margin: 0 !important;
    line-height: 1.2;
    text-decoration: none;
    color: inherit;
}


/* Scrollable main application area */
.app-scroll {
    height: calc(100vh - var(--footer-height) - var(--scrollbar-height)); /* reserve footer height and scrollbar */
    overflow: auto;
    padding-bottom: 50px;
    min-width: 0; /* Prevent children from shrinking below their content width */
    /* keep content above footer */
    padding-bottom: calc(var(--footer-height) + 10px);
    box-sizing: border-box;
}

/* Allow wide tab content/plots to create horizontal scroll */
.app-scroll > * {
    min-width: max-content;
}

.app-scroll .container,
.app-scroll .container-fluid,
.app-scroll .row {
    min-width: max-content;
}

.app-scroll .shiny-plot-output,
.app-scroll .plotly,
.app-scroll .html-widget {
    min-width: 600px;
}

/* Fixed footer */
.app-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: var(--footer-height);

    background: white;
    color: #6c757d;

    font-size: 0.9rem;
    border-top: 1px solid #dee2e6;

    padding: 8px 15px;

    z-index: 9999;
}

.navbar-title {
    font-size: 20px;
    font-weight: bold;
    text-decoration: none;
    color: inherit;
}

.navbar-title:hover {
    text-decoration: none;
    color: inherit;
}

.navbar-logo-link {
    display: flex;
    align-items: center;
    height: 45px;
    padding: 0 !important;
    margin: 0 !important;
    line-height: 0;
}

.navbar-logo {
    height: 45px;
    width: auto;
    display: block;
    object-fit: contain;
    margin: 0;
    padding: 0;
}

.navbar .nav-item {
    display: flex;
    align-items: center;
}

.help-icon {
    width: 45px;
    height: 45px;
    object-fit: contain;
    cursor: pointer;
}

#plot_help {
    box-shadow: none !important;
}

#plot_help:focus {
    box-shadow: none !important;
}

.popover {
    max-width: 420px;
}

/* Full application container */
.app-wrapper {
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}


.footer-content {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;  
}

.footer-left {
    margin: 0;
    text-align: left;
    font-weight: 1000;
    flex: 1;
}
.footer-left p {
    margin: 2px 0;   /* top/bottom left/right */
    line-height: 1.1;
}

.footer-right {
    margin: 0;
    text-align: right;
    white-space: nowrap;       /* Prevent wrapping */
}

.footer-right a {
    color: inherit;
    text-decoration: none;
    font-weight: 500;
}

.footer-right a:hover {
    text-decoration: underline;
}

#app-container {
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
}

.panel-row {
    display: flex;
    flex: 1;
    min-height: 0;
}

/* ==========================
   LEFT PANEL
   ========================== */

.left-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 5px;
    min-height: 0;
}

.left-panel .card {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* ==========================
   Plot PANEL
   ========================== */

.plot-panel {
    flex: 5;
    display: flex;
    flex-direction: column;
    padding: 5px;
    min-height: 0;
}

.plot-panel .card {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* ==========================
   RIGHT PANEL
   ========================== */

.stats-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 5px;
    min-height: 0;
    height: 80vh;   /* fill viewport height */
    gap: 10px;
}

/* Each info panel gets half the available height */
.stats-panel > .card {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.card-fill {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding: 10px;
}


/* Input row layout */
.input-row {
    display: flex;
    align-items: flex-start;
    padding-left: 10px;
    padding-right: 10px;
    padding-top: 2px;
    padding-bottom: 2px;
}

/* Make inputs take equal width */
.input-row > div {
    flex: 1;
}
.selectize-control {
    max-width: 270px;
}

.stats-panel > .display-card {
    flex: 0.5 !important;
    height: auto;
}

.plot-box {
    flex: 1;
    min-height: 0;
    display: flex;
}

.plot-box > div,
.plot-box iframe {
    width: 100% !important;
    height: 100% !important;
}

/* ==========================
   RIGHT PANEL
   ========================== */

.right-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 5px;
    min-height: 0;
}

.right-panel .card {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* Remove Bootstrap spacing */
.navbar {
    margin-bottom: 0;
}

.tab-content {
    padding-top: 0;
    height: 100%;
    overflow: visible;
}

.tab-pane.active,
.tab-pane {
    height: 100%;
}

.card-body {
    padding: 0;
    display:flex;
    flex-direction:column;
}

.card {
    margin-top: 0;
    margin-bottom: 0;
}

.card > .bslib-gap-spacing {
    margin-top: 0 !important;
    margin-bottom: 0 !important;
    padding: 10px !important;
    gap: 0 !important;
}

/* Main three-column layout */
.gene-panel-row {
    display: flex;
    width: 100%;
    height: calc(100vh - var(--footer-height) - var(--scrollbar-height));
    gap: 10px;
}


/* Left input column */
.gene-input-panel {
    width: 20%;
    min-width: 200px;
    height: 80vh;
    display: flex;
    flex-direction: column;
}


/* Card fills entire input panel */
.gene-input-panel .card {
    height:100%;
}


/* Input controls stacked vertically */
.gene-input-column {
    display: flex;
    flex-direction: column;
    gap: 15px;
    height:100%;
    overflow-y: auto;
}


/* Middle plot column */
.gene-plot-panel {
    width: 50%;
    min-width: 600px;
    min-height: 600px;
}


/* Right statistics column */
.gene-stats-panel {
    width: 25%;
    min-width: 300px;
    height: 80vh;

    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Plot fills available space */
.plot-box {
    height: 100%;
    width: 100%;
}


/* Right side split */
.stats-summary {
    flex: 1;
    overflow: auto;
}


.expression-legend {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}


.legend-img {
    flex: 1;

    display: flex;
    justify-content: center;  /* horizontal center */
    align-items: center;      /* vertical center */

    width: 100%;
    height: 100%;
}


.legend-img .js-plotly-plot,
.legend-img .plotly {
    max-width: 100%;
    max-height: 100%;
}

/* Allow the plot card to use the available viewport height */
.plot-panel .card {
    height: 100%;
    min-height: 0;
    overflow: hidden;
}

/* Scroll vertically when multiple gene subplots make the figure taller */
.plot-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: auto;
    position: relative;
}

/* Important: do not force Plotly to shrink its dynamically assigned height */
.plot-scroll .html-widget,
.plot-scroll .plotly,
.plot-scroll .js-plotly-plot {
    min-height: 100%;
}