/* Global Styles */
:root {
    --navbar-height: 70px;
    --footer-height: 70px;
    --mobile-touch-target: 44px;
}

body {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

.navbar {
    min-height: var(--navbar-height);
}

.app-shell {
    padding-inline: clamp(1rem, 3vw, 2rem);
}

.skip-link {
    position: fixed;
    top: .5rem;
    left: .5rem;
    z-index: 1100;
    padding: .75rem 1rem;
    border-radius: .5rem;
    background: var(--bs-primary);
    color: #fff;
}

.main-content {
    flex: 1;
    min-width: 0;
    margin-top: 1.5rem;
}

.mobile-stack-header {
    align-items: center;
}

.mobile-stack-header.is-align-start {
    align-items: flex-start;
}

.mobile-form-actions {
    display: flex;
}

.table.mobile-card-table > tbody > tr > td.mobile-table-actions,
.table.mobile-card-table > tbody > tr > td.mobile-table-end {
    text-align: end;
}

.table.mobile-card-table > tbody > tr > td.mobile-table-actions {
    padding-right: 1.5rem;
}

.table.mobile-card-table > tbody > tr > td.mobile-table-empty {
    padding-top: 1.5rem;
    padding-bottom: 1.5rem;
    text-align: center;
}

.mobile-card-table tr.mobile-table-detail .mobile-detail-body {
    padding: 1rem 1.5rem;
}

/* Closed detail rows sit in the table on desktop. Zero the cell box so
   Bootstrap's table padding and bottom border do not draw an empty band. */
.table.mobile-card-table > tbody > tr.mobile-table-detail > td {
    padding: 0;
    border: 0;
}

.mobile-only {
    display: none;
}

.card-kpi { border-top: 4px solid #4e73df; }
.card-kpi.success { border-top-color: #1cc88a; }
.card-kpi.info { border-top-color: #36b9cc; }
.card-kpi.warning { border-top-color: #f6c23e; }
.card-kpi.danger { border-top-color: #e74a3b; }
.card-kpi.dark { border-top-color: #5a5c69; }
.card-kpi.secondary { border-top-color: #858796; }

.text-gray-300 {
    color: #dddfeb !important;
}

footer {
    min-height: var(--footer-height);
    display: flex;
    align-items: center;
    margin-top: auto;
}

/* Dark Mode Adjustments */
[data-bs-theme="dark"] {
    --bs-body-bg: #1a1d20;
    --bs-body-color: #adb5bd;
    --bs-secondary-color: #868e96;
    --bs-tertiary-bg: #212529;
    --bs-border-color: #2c3034;
}

[data-bs-theme="dark"] .card {
    background-color: #212529;
    border-color: #2c3034;
    box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.2) !important;
}

[data-bs-theme="dark"] .text-muted {
    color: #868e96 !important;
}

[data-bs-theme="dark"] .table-dark {
    --bs-table-bg: #1a1d20;
}

[data-bs-theme="dark"] .card-header {
    background-color: rgba(255, 255, 255, 0.02);
    border-bottom: 1px solid #2c3034;
}

/* Softer Subtle Backgrounds for Dark Mode */
[data-bs-theme="dark"] .bg-primary-subtle {
    background-color: rgba(13, 110, 253, 0.1) !important;
    color: #4ea2ff !important;
    border: 1px solid rgba(13, 110, 253, 0.15) !important;
}

[data-bs-theme="dark"] .bg-success-subtle {
    background-color: rgba(25, 135, 84, 0.1) !important;
    color: #47c385 !important;
    border: 1px solid rgba(25, 135, 84, 0.15) !important;
}

[data-bs-theme="dark"] .bg-warning-subtle {
    background-color: rgba(255, 193, 7, 0.1) !important;
    color: #ffd33d !important;
    border: 1px solid rgba(255, 193, 7, 0.15) !important;
}

[data-bs-theme="dark"] .bg-info-subtle {
    background-color: rgba(13, 202, 240, 0.1) !important;
    color: #58d9f1 !important;
    border: 1px solid rgba(13, 202, 240, 0.15) !important;
}

[data-bs-theme="dark"] .bg-secondary-subtle {
    background-color: rgba(108, 117, 125, 0.1) !important;
    color: #adb5bd !important;
    border: 1px solid rgba(108, 117, 125, 0.15) !important;
}

[data-bs-theme="dark"] .list-group-item {
    background-color: transparent;
    border-color: #2c3034;
    color: #adb5bd;
}

[data-bs-theme="dark"] .badge.bg-success-subtle {
    background-color: rgba(25, 135, 84, 0.2) !important;
}

[data-bs-theme="dark"] .navbar {
    border-bottom: 1px solid #2c3034;
}

[data-bs-theme="dark"] .card-kpi .text-dark {
    color: #f8f9fa !important;
}

[data-bs-theme="dark"] .card-kpi .text-secondary {
    color: #ced4da !important;
}

[data-bs-theme="dark"] .card-kpi .text-body {
    color: #ffffff !important;
}

/* Google Sign-in Button */
.btn-google {
    background-color: #ffffff;
    color: #3c4043;
    border: 1px solid #dadce0;
}

.btn-google:hover {
    background-color: #f8f9fa;
    color: #3c4043;
    border-color: #dadce0;
}

[data-bs-theme="dark"] .btn-google {
    background-color: #2b3035;
    color: #f8f9fa;
    border: 1px solid #adb5bd;
}

[data-bs-theme="dark"] .btn-google:hover {
    background-color: #343a40;
    color: #ffffff;
    border-color: #ced4da;
}

@media (max-width: 991.98px) {
    .navbar {
        position: sticky;
        top: 0;
        z-index: 1030;
        min-height: 60px;
        padding-block: .65rem;
    }

    .navbar-brand {
        max-width: calc(100vw - 6rem);
        font-size: 1rem;
    }

    .navbar-toggler {
        min-width: var(--mobile-touch-target);
        min-height: var(--mobile-touch-target);
    }

    .navbar-collapse {
        max-height: calc(100dvh - 76px);
        overflow-y: auto;
        overscroll-behavior: contain;
        padding: .75rem 0 calc(.75rem + env(safe-area-inset-bottom));
    }

    .navbar .nav-link,
    .navbar .dropdown-item {
        display: flex;
        align-items: center;
        min-height: var(--mobile-touch-target);
        gap: .35rem;
    }

    .navbar button.nav-link {
        min-width: var(--mobile-touch-target);
        justify-content: center;
    }

    .navbar .dropdown-menu {
        margin-bottom: .5rem;
    }

    .main-content {
        width: 100%;
        max-width: none;
        margin-top: 1rem;
        padding-inline: 1rem;
    }

    footer {
        min-height: auto;
        padding-bottom: env(safe-area-inset-bottom);
    }
}

@media (max-width: 767.98px) {
    h1.h3 {
        font-size: 1.35rem;
    }

    .card {
        border-radius: .85rem;
    }

    .card-body {
        padding: 1rem;
    }

    .btn:not(.btn-close),
    .form-control,
    .form-select {
        min-height: var(--mobile-touch-target);
    }

    .btn-sm,
    .form-control-sm,
    .form-select-sm {
        min-height: 40px;
    }

    .form-check-input {
        min-width: 1.25rem;
        min-height: 1.25rem;
    }

    .breadcrumb {
        flex-wrap: nowrap;
        overflow-x: auto;
        padding-bottom: .25rem;
        white-space: nowrap;
        scrollbar-width: none;
    }

    .breadcrumb::-webkit-scrollbar {
        display: none;
    }

    .mobile-only {
        display: initial;
    }

    .mobile-stack-header,
    .mobile-stack-header.is-align-start {
        align-items: stretch;
        flex-direction: column;
    }

    .mobile-stack-header > .btn,
    .mobile-stack-header > .d-flex > .btn {
        width: 100%;
    }

    .mobile-full-width {
        width: 100%;
    }

    .mobile-form-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }

    .mobile-form-actions > .btn {
        width: 100%;
    }

    .mobile-form-actions > :only-child {
        grid-column: 1 / -1;
    }

    .mobile-scroll-actions {
        width: 100%;
        overflow-x: auto;
        padding-bottom: .25rem;
        scrollbar-width: none;
    }

    .mobile-scroll-actions::-webkit-scrollbar {
        display: none;
    }

    .mobile-scroll-actions .btn-group,
    .mobile-scroll-actions.btn-group {
        flex-wrap: nowrap;
        width: max-content;
    }

    .mobile-card-table {
        --mobile-table-gap: .65rem;
    }

    .mobile-card-table,
    .mobile-card-table tbody {
        display: block;
    }

    .mobile-card-table thead {
        display: none;
    }

    .mobile-card-table tr {
        display: grid;
        gap: var(--mobile-table-gap);
        margin: .75rem;
        padding: 1rem;
        border: 1px solid var(--bs-border-color);
        border-radius: .75rem;
        background: var(--bs-table-bg, var(--bs-body-bg));
        box-shadow: var(--bs-box-shadow-sm);
    }

    .table.mobile-card-table > tbody > tr > td {
        display: grid;
        grid-template-columns: minmax(6.5rem, 38%) minmax(0, 1fr);
        gap: .75rem;
        align-items: start;
        width: 100%;
        padding: 0;
        border: 0;
        text-align: end;
        overflow-wrap: anywhere;
    }

    .table.mobile-card-table > tbody > tr > td::before {
        content: attr(data-label);
        color: var(--bs-secondary-color);
        font-size: .78rem;
        font-weight: 600;
        text-align: start;
    }

    .table.mobile-card-table > tbody > tr > td[data-label=""] {
        display: block;
        text-align: start;
    }

    .table.mobile-card-table > tbody > tr > td[data-label=""]::before,
    .table.mobile-card-table > tbody > tr > td[colspan]::before {
        content: none;
    }

    .table.mobile-card-table > tbody > tr > td.mobile-table-empty,
    .table.mobile-card-table > tbody > tr > td[colspan] {
        display: block;
        padding-block: 1rem;
        text-align: center;
    }

    .table.mobile-card-table > tbody > tr > td.mobile-table-primary {
        display: block;
        padding-bottom: .65rem;
        border-bottom: 1px solid var(--bs-border-color);
        text-align: start;
    }

    .table.mobile-card-table > tbody > tr > td.mobile-table-primary::before {
        content: none;
    }

    .table.mobile-card-table > tbody > tr > td.mobile-table-actions {
        display: block;
        padding: .35rem 0 0;
        text-align: start;
    }

    .table.mobile-card-table > tbody > tr > td.mobile-table-actions::before {
        display: block;
        margin-bottom: .4rem;
    }

    .mobile-card-table .mobile-table-actions .btn,
    .mobile-card-table .mobile-table-actions form {
        min-width: var(--mobile-touch-target);
    }

    .table.mobile-card-table > tbody > tr > td.mobile-table-actions > form,
    .table.mobile-card-table > tbody > tr > td.mobile-table-actions > .btn {
        display: inline-block;
        margin: 0 .25rem .25rem 0;
    }

    .mobile-card-table tr.mobile-table-detail {
        display: block;
        margin-top: -.75rem;
        padding: 0;
        border: 0;
        box-shadow: none;
    }

    .table.mobile-card-table > tbody > tr.mobile-table-detail > td {
        display: block;
        padding: 0;
        border: 0;
        text-align: start;
    }

    .mobile-card-table tr.mobile-table-detail .mobile-detail-body {
        padding: 1rem;
        border: 1px solid var(--bs-border-color);
        border-radius: 0 0 .75rem .75rem;
    }

    .table-responsive:has(.mobile-card-table) {
        overflow: visible;
    }
}

@media (max-width: 359.98px) {
    .main-content {
        padding-inline: .75rem;
    }

    .mobile-card-table tr {
        margin-inline: .5rem;
        padding: .85rem;
    }

    .table.mobile-card-table > tbody > tr > td,
    .table.mobile-card-table > tbody > tr > td.mobile-table-end {
        grid-template-columns: 1fr;
        gap: .2rem;
        text-align: start;
    }
}
