/* Shared dashboard surfaces, independent of the Bootstrap theme build. */
.commune-page {
    --dashboard-surface: #fff;
    --dashboard-border: color-mix(in srgb, var(--mt-border-color) 80%, transparent);
    --commune-sidebar-width: 16rem;
}

[data-bs-theme="dark"] .commune-page {
    --dashboard-surface: var(--mt-secondary-bg);
}

.commune-content {
    min-width: 0;
    padding: clamp(1rem, 2vw, 2rem);
}

.commune-sidebar {
    background: var(--dashboard-surface);
    box-shadow: none;
}

.dashboard-page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem 1.5rem;
    margin-block: .75rem 2rem;
}

.dashboard-page-header h1 {
    flex: 1 1 16rem;
    min-width: 0;
    overflow-wrap: anywhere;
}

.dashboard-layout-controls {
    flex: 0 1 auto;
    min-width: 0;
}

.dashboard-layout-controls .dashboard-grid-toggle {
    display: flex;
    align-items: center;
    gap: .65rem;
    min-height: 2.75rem;
    padding: .5rem .85rem;
    border: 1px solid var(--dashboard-border);
    border-radius: .75rem;
    background: var(--dashboard-surface);
}

.dashboard-layout-controls .form-check-input {
    flex: 0 0 auto;
    float: none;
    margin: 0;
    cursor: pointer;
}

.dashboard-layout-controls .form-check-label {
    font-size: .875rem;
    font-weight: 600;
    cursor: pointer;
}

.dashboard-layout-controls__help {
    margin: .4rem 0 0;
    color: var(--mt-secondary-color);
    font-size: .75rem;
    line-height: 1.5;
}

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

.dashboard-section__header {
    gap: .5rem;
    margin-bottom: .75rem;
}

.dashboard-section__header h2 {
    font-size: clamp(1.15rem, 1.7vw, 1.5rem);
    font-weight: 650;
}

.dashboard-grid.grid-stack {
    margin-inline: -.5rem;
}

.dashboard-grid.grid-stack > .grid-stack-item > .grid-stack-item-content {
    display: flex;
    overflow: hidden !important;
    border-radius: 1rem;
}

.dashboard-grid .dashboard-card {
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    margin: 0;
    overflow: hidden;
    border: 1px solid var(--dashboard-border);
    border-top: 3px solid var(--dashboard-accent, var(--mt-grenat));
    border-radius: 1rem;
    background: var(--dashboard-surface);
    color: var(--mt-body-color);
    box-shadow: 0 3px 12px rgb(15 23 42 / 4%);
    transition: border-color .18s ease, box-shadow .18s ease;
}

.dashboard-grid .dashboard-card .card-body {
    display: flex;
    flex-direction: column;
    gap: .75rem;
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    padding: .875rem 1.125rem 1.125rem;
    overflow: hidden;
}

.dashboard-card__heading {
    gap: .35rem;
    min-width: 0;
    margin: 0;
}

.dashboard-card__toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    min-height: 2rem;
}

.dashboard-card__kind {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    color: var(--mt-secondary-color);
    font-size: .7rem;
    font-weight: 600;
    letter-spacing: .04em;
    text-transform: uppercase;
}

.dashboard-card__kind::before {
    width: .4rem;
    height: .4rem;
    border-radius: 50%;
    background: var(--dashboard-accent, var(--mt-grenat));
    content: "";
}

.dashboard-card__title {
    margin: 0;
    font-size: .95rem;
    font-weight: 600;
    line-height: 1.4;
    overflow-wrap: anywhere;
}

.dashboard-card--kpi .dashboard-card__title,
.dashboard-card--graph-leger .dashboard-card__title {
    min-height: 2.8em;
}

.dashboard-card__subtitle {
    margin: 0;
}

.dashboard-card__content {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    gap: .5rem;
    min-width: 0;
    min-height: 0;
}

.dashboard-card--kpi .dashboard-card__content {
    justify-content: center;
    align-items: flex-start;
}

.dashboard-card__value {
    max-width: 100%;
    margin: 0;
    font-size: clamp(1.65rem, 2.5vw, 2.25rem);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    letter-spacing: -.035em;
    line-height: 1.15;
    overflow-wrap: anywhere;
}

.dashboard-card__value--text {
    font-size: 1.35rem;
    letter-spacing: -.02em;
    line-height: 1.25;
}

.dashboard-card__unit {
    color: var(--mt-secondary-color);
    font-size: .55em;
    font-weight: 500;
    letter-spacing: 0;
    white-space: nowrap;
}

.dashboard-card__badge {
    padding: .2rem .5rem;
    border-radius: .4rem;
    background: var(--mt-tertiary-bg);
    color: var(--mt-secondary-color);
    font-size: .75rem;
    font-weight: 600;
}

.dashboard-card--graph-leger .dashboard-card__content {
    position: relative;
    justify-content: center;
}

.dashboard-card--graph-leger .dashboard-card__value {
    position: relative;
    align-self: flex-start;
    z-index: 1;
}

.dashboard-sparkline {
    position: absolute;
    inset: 0 0 0 35%;
    min-height: 0;
}

.dashboard-card__actions {
    display: flex;
    flex: 0 0 auto;
    gap: .25rem;
    visibility: hidden;
    pointer-events: none;
}

.dashboard-grid .dashboard-card__actions button {
    position: static;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    padding: .4rem;
    border: 1px solid var(--dashboard-border);
    border-radius: .5rem;
    background: var(--dashboard-surface);
    color: var(--mt-secondary-color);
    box-shadow: none;
    line-height: 1;
    z-index: auto;
}

.dashboard-card__actions svg {
    display: block;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.dashboard-grid-move-enabled .dashboard-card__actions {
    visibility: visible;
    pointer-events: auto;
}

.dashboard-grid-move-enabled .dashboard-grid .dashboard-card {
    border-color: color-mix(in srgb, var(--dashboard-accent) 40%, var(--dashboard-border));
    box-shadow: 0 3px 12px rgb(15 23 42 / 8%);
}

.dashboard-grid .dashboard-card__actions .dashboard-grid__drag-handle {
    cursor: grab;
    touch-action: none;
}

.dashboard-grid .ui-draggable-dragging .dashboard-grid__drag-handle {
    cursor: grabbing;
}

.dashboard-grid .dashboard-card__actions button:hover {
    background: var(--mt-tertiary-bg);
    color: var(--mt-body-color);
}

.dashboard-grid .dashboard-card__actions .dashboard-grid__remove:hover {
    color: var(--mt-tomate);
}

.dashboard-card__actions button:focus-visible {
    outline: 2px solid var(--dashboard-accent);
    outline-offset: 2px;
}

.dashboard-grid .grid-stack-placeholder > .placeholder-content {
    border: 2px dashed var(--mt-secondary-color);
    border-radius: 1rem;
    background: var(--mt-tertiary-bg);
}

.dashboard-grid .dashboard-apex,
.dashboard-grid .dashboard-leaflet {
    flex: 1 1 auto;
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    max-height: 100%;
}

.dashboard-grid .dashboard-grid__item--table .dashboard-card,
.dashboard-grid .dashboard-grid__item--table .dashboard-card .card-body {
    min-height: 0;
    overflow: hidden;
}

.dashboard-grid .dashboard-grid__item--table .table-responsive {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
}

.dashboard-table {
    margin: 0;
    font-size: .85rem;
}

.dashboard-table thead th {
    position: sticky;
    top: 0;
    padding: .65rem .5rem;
    border-bottom-width: 1px;
    background: var(--dashboard-surface);
    color: var(--mt-secondary-color);
    font-size: .75rem;
    font-weight: 600;
    white-space: nowrap;
    z-index: 1;
}

.dashboard-table td {
    padding: .65rem .5rem;
    vertical-align: top;
}

.dashboard-grid .dashboard-table-pagination {
    flex-wrap: wrap;
    justify-content: space-between;
    gap: .5rem;
    padding-top: .75rem;
    border-top: 1px solid var(--dashboard-border);
}

.dashboard-grid .dashboard-table-pagination .btn {
    min-height: 2rem;
    padding: .35rem .6rem;
    border-radius: .5rem;
    font-size: .75rem;
}

.dashboard-grid-restore {
    justify-content: flex-start;
    flex-wrap: wrap;
    margin: 0 0 .75rem;
    padding: .75rem;
    border: 1px dashed var(--dashboard-border);
    border-radius: .75rem;
}

.dashboard-grid-restore__list {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
}

.dashboard-grid-restore .btn {
    border-radius: .5rem;
}

.dashboard-grid-restore[hidden],
.dashboard-table-pagination[hidden],
.dashboard-grid .dashboard-grid__item--hidden {
    display: none !important;
}

@media (min-width: 992px) {
    .commune-sidebar-col,
    .commune-sidebar {
        width: var(--commune-sidebar-width);
    }

    .commune-content {
        flex: 0 0 auto;
        width: calc(100% - var(--commune-sidebar-width));
        margin-left: var(--commune-sidebar-width);
    }
}

@media (max-width: 991.98px) {
    .commune-page {
        padding-top: 4.5rem;
    }

    .commune-sidebar__header {
        top: 85px;
        justify-content: space-between;
        gap: .75rem;
        min-height: 4.5rem;
        margin-bottom: 0 !important;
        padding: .65rem 1rem;
        border-bottom: 1px solid var(--dashboard-border);
        background: var(--dashboard-surface);
    }

    .commune-sidebar__header > div {
        min-width: 0;
    }

    .commune-sidebar__header .h5 {
        overflow: hidden;
        font-size: 1rem;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .commune-sidebar__mobile-menu {
        display: inline-flex;
        flex: 0 0 auto;
        align-items: center;
        gap: .5rem;
        min-height: 2.75rem;
        border-radius: .6rem;
    }

    .dashboard-page-header {
        margin-bottom: 1.5rem;
    }
}

@media (max-width: 767.98px), (pointer: coarse) {
    .dashboard-grid .dashboard-card__actions button {
        width: 2.75rem;
        height: 2.75rem;
        padding: .65rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .dashboard-grid .dashboard-card,
    .dashboard-grid .grid-stack-item {
        transition: none !important;
    }
}
