/* ================= DASHBOARD GRID ================= */

.dashboard-grid {
    display: grid;
    gap: 1rem;
    grid-auto-flow: row;
    grid-template-columns: 1fr;
    align-items: start;
    /* prevent content being hidden behind fixed tray */
    padding-bottom: 40px;
}


.dashboard-item {
    min-width: 0;
}

/* Tablet */
@media (min-width:768px) {
    .dashboard-grid {
        grid-template-columns: repeat(2, minmax(0,1fr));
    }
}

/* Desktop (3 columns, wide centre) */
@media (min-width:1200px) {
    .dashboard-grid {
        grid-template-columns: minmax(0,1fr) minmax(0,1.5fr) minmax(0,1fr);
    }
}

/* ================= WIDTH STATES ================= */

/* +1 column (desktop only) */
@media (min-width:1200px) {
    .dashboard-item.is-wide {
        grid-column: span 2;
    }
}

/* Full width (tablet+) */
@media (min-width:768px) {
    .dashboard-item.is-full {
        grid-column: 1 / -1;
    }
}

/* ================= CONTROLS (ALWAYS VISIBLE) ================= */

.dashboard-drag-handle,
.dashboard-expand-toggle,
.dashboard-minimise {
    opacity: 1;
    pointer-events: auto;
}

.dashboard-drag-handle {
    cursor: grab;
}

    .dashboard-drag-handle:active {
        cursor: grabbing;
    }

/* ================= SORTABLE STATES ================= */

.sortable-chosen {
    opacity: .9;
}

.sortable-ghost {
    opacity: .5;
}

/* ================= CARD HEIGHT SYSTEM ================= */

.dashboard-item {
    --pane-h: 420px;
    height: var(--pane-h);
    transition: height .2s ease;
}

    .dashboard-item[data-h="sm"] {
        --pane-h: 320px;
    }

    .dashboard-item[data-h="md"] {
        --pane-h: 420px;
    }

    .dashboard-item[data-h="lg"] {
        --pane-h: 560px;
    }

    .dashboard-item[data-h="xl"] {
        --pane-h: 720px;
    }

    .dashboard-item.is-tall {
        height: calc(var(--pane-h) * 2);
    }

@media (min-height: 700px) {
    .dashboard-item.is-tall {
        max-height: 80vh;
    }
}

/* Card layout */
.dashboard-item .card {
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* Scrollable content */
.dashboard-item .dash-body {
    flex: 1 1 auto;
    overflow-y: auto;
    min-height: 0;
}

    /* Sticky table headers */
    .dashboard-item .dash-body thead th {
        position: sticky;
        top: 0;
        background: #fff;
        z-index: 1;
    }

/* Calendar fix (valid CSS now) */
[data-widget-id='calendar'] .card-body {
    height: 100%;
    overflow-y: auto;
}

/* ================= MINIMISED STATE ================= */

.dashboard-item.is-minimized {
    display: none !important;
}

/* ================= TRAY (IN CONTROL BAR) ================= */

.dashboard-controls {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: 3px 10px;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 30px;
    line-height: 30px;
    background: rgba(0,0,0,0.75);
    z-index: 9999;
}

/* Tray container */
#dashboardTrayList,
.dashboard-tray {
    display: flex;
    align-items: center;
    gap: .4rem;
}

    /* Hide tray completely when empty */
    #dashboardTrayList:empty {
        display: none;
    }

/* Tray buttons */
.dashboard-tray-btn {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    padding: .2rem .5rem;
    font-size: .75rem;
    line-height: 1;
    border-radius: .3rem;
    border: 1px solid rgba(255,255,255,0.25);
    background: rgba(255,255,255,0.9);
    color: #212529;
    cursor: pointer;
    white-space: nowrap;
}

    .dashboard-tray-btn i {
        font-size: .7rem;
        opacity: .8;
    }

    .dashboard-tray-btn:hover {
        background: #fff;
        border-color: rgba(255,255,255,0.5);
    }

/* ================= FOOTER (STAYS BELOW CONTENT) ================= */

html, body {
    height: 100%;
}

    body.app-shell {
        min-height: 100vh;
        display: flex;
        flex-direction: column;
    }

        body.app-shell > .app-main {
            flex: 1 1 auto;
            min-height: 0;
        }

footer.footer {
    flex: 0 0 auto;
    height: 30px;
    line-height: 30px;
    padding-left: 10px;
}

/* Mobile: one widget per screen, horizontal swipe */
@media (max-width: 767.98px) {
    .dashboard-grid {
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        scroll-snap-type: x mandatory;
        -webkit-overflow-scrolling: touch;
        gap: 0;
        padding-bottom: 40px;
        margin:0 -12px 0 -12px;
        height:calc(100vh - 49px);
    }
    .dashboard-item{
        height:100%;
    }
    .dash-panel-ctrls button, .dash-panel-ctrls .filter-button{
        display:none;
    }

    .dashboard-grid .card{
        margin:0!important;
    }

    .dashboard-grid .dash-panel-ctrls{
        display:none;
    }

        .dashboard-grid::-webkit-scrollbar {
            display: none;
        }

    .dashboard-item {
        flex: 0 0 100%;
        width: 100%;
        scroll-snap-align: start;
        padding-right: 0;
    }

        .dashboard-item.is-wide,
        .dashboard-item.is-full {
            width: 100%;
            flex-basis: 100%;
        }
}

.dashboard-mobile-nav {
    display: none;
}

@media (max-width: 767.98px) {
    .dashboard-mobile-nav {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: .75rem;
        margin-bottom: .5rem;
    }
}

.card .card-header{
    background: #888;
    font-size: 1.2rem;
    font-weight: 500;
    padding-left: 1rem;
    padding-right: 1rem;
}

.card button.btn{
    background-color:#00000035;
    color:white;
    font-size:0.7rem;
}

/* While sorting, flatten complex grid behaviour so Sortable can calculate insertion reliably */
.dashboard-grid.is-sorting {
    grid-auto-flow: row;
}

.dashboard-grid.is-sorting .dashboard-item {
    grid-column: auto !important;
    height: var(--pane-h) !important;
}

.dashboard-grid.is-sorting .dashboard-item.is-full,
.dashboard-grid.is-sorting .dashboard-item.is-wide,
.dashboard-grid.is-sorting .dashboard-item.is-tall {
    grid-column: auto !important;
    height: var(--pane-h) !important;
}

