/**
 * Native-like PWA shell: no page zoom, no horizontal shake, contained scroll.
 */

html {
    height: 100%;
    height: 100dvh;
    overflow-x: hidden;
    overscroll-behavior: none;
    touch-action: manipulation;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    margin: 0;
    width: 100%;
    overflow-x: hidden;
    overscroll-behavior: none;
    touch-action: manipulation;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

/* Dashboard / app shell only — fixed viewport, contained scroll */
body.app-shell {
    height: 100%;
    height: 100dvh;
    overflow: hidden;
    -webkit-overflow-scrolling: touch;
    position: fixed;
    inset: 0;
}

body.app-shell .main {
    display: flex;
    flex-direction: column;
    height: 100%;
    height: 100dvh;
    width: 100%;
    max-width: 100vw;
    overflow: hidden;
}

body.app-shell .app-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding-bottom: env(safe-area-inset-bottom);
}

.topbar {
    flex-shrink: 0;
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.header {
    flex-shrink: 0;
    width: 100%;
    max-width: 100vw;
    overflow: hidden;
    background: #fff;
    padding: 0.55rem max(0.65rem, env(safe-area-inset-left)) 0.7rem max(0.65rem, env(safe-area-inset-right));
    border-bottom: 1px solid rgba(15, 23, 42, 0.08);
}

.app-header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.55rem;
}

.app-header-logo {
    display: flex;
    align-items: center;
    line-height: 0;
    text-decoration: none;
    min-width: 0;
}

.header .branding {
    height: 34px !important;
    width: auto !important;
    max-width: 150px !important;
}

.app-header-refresh {
    flex-shrink: 0;
    width: 38px;
    height: 38px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: #546E7A;
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
}

.app-header-refresh:active {
    filter: brightness(0.9);
}

/* Action pills — 4 in one row (regular users) */
.app-header-actions {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.4rem;
    width: 100%;
    overflow: hidden;
}

/* Admin: 5 buttons → 3 top, 2 bottom */
.app-header-actions--5 {
    grid-template-columns: repeat(6, minmax(0, 1fr));
}

.header .app-header-actions .app-header-btn {
    display: inline-flex !important;
    flex-direction: row !important;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    min-width: 0;
    padding: 0.52rem 0.2rem;
    border: none !important;
    border-radius: 999px;
    font-size: clamp(0.62rem, 2.5vw, 0.75rem);
    font-weight: 600;
    line-height: 1.1;
    color: #fff !important;
    text-decoration: none !important;
    white-space: nowrap;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12);
    -webkit-tap-highlight-color: transparent;
    cursor: pointer;
    box-sizing: border-box;
    -webkit-appearance: none;
    appearance: none;
}

.app-header-actions--5 .app-header-btn {
    grid-column: span 2;
}

.app-header-actions--5 .app-header-btn:nth-child(4) {
    grid-column: 2 / 4;
}

.app-header-actions--5 .app-header-btn:nth-child(5) {
    grid-column: 4 / 6;
}

.header .app-header-actions .app-header-btn i {
    font-size: 0.75rem;
    flex-shrink: 0;
    color: #fff;
}

.header .app-header-actions .app-header-btn span {
    overflow: hidden;
    text-overflow: ellipsis;
}

.header .app-header-actions .app-header-btn--support { background: #0F9CBD !important; }
.header .app-header-actions .app-header-btn--profile { background: #70A538 !important; }
.header .app-header-actions .app-header-btn--tracking { background: #9C27B0 !important; }
.header .app-header-actions .app-header-btn--security { background: #5C6BC0 !important; }
.header .app-header-actions .app-header-btn--logout { background: #E97723 !important; }

.header .app-header-actions .app-header-btn:active {
    filter: brightness(0.92);
}

@media (min-width: 992px) {
    .header {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        justify-content: space-between;
        gap: 0.75rem;
        padding: 0.65rem max(1rem, env(safe-area-inset-left)) 0.65rem max(1rem, env(safe-area-inset-right));
    }

    .app-header-top {
        margin-bottom: 0;
        flex: 0 0 auto;
    }

    .header .branding {
        height: 38px !important;
        max-width: 170px !important;
    }

    .app-header-actions {
        display: flex;
        flex-wrap: wrap;
        justify-content: flex-end;
        gap: 0.5rem;
        width: auto;
        flex: 1 1 auto;
        min-width: 0;
    }

    .app-header-actions--5 .app-header-btn {
        grid-column: auto;
    }

    .app-header-actions--5 .app-header-btn:nth-child(4),
    .app-header-actions--5 .app-header-btn:nth-child(5) {
        grid-column: auto;
    }

    .header .app-header-actions .app-header-btn {
        flex: 0 0 auto;
        padding: 0.5rem 1rem;
        font-size: 0.82rem;
    }
}

.app-member-card {
    border: 1px solid rgba(15, 23, 42, 0.08);
    border-radius: 10px;
    background: #fff;
}

.app-member-card + .app-member-card {
    margin-top: 0.65rem;
}

.app-detail-row {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.35rem 0;
    font-size: 0.875rem;
}

.app-detail-row span:first-child {
    color: #64748b;
    flex-shrink: 0;
}

.app-detail-row span:last-child {
    text-align: right;
    word-break: break-word;
}

.list-group-item.app-detail-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.75rem;
}

.app-page {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    padding-left: max(0.75rem, env(safe-area-inset-left));
    padding-right: max(0.75rem, env(safe-area-inset-right));
}

.app-page .row {
    margin-left: 0;
    margin-right: 0;
    max-width: 100%;
}

.app-page .row > [class*="col-"] {
    padding-left: 0.5rem;
    padding-right: 0.5rem;
    max-width: 100%;
}

.recent-intakes {
    padding: 0.75rem 0;
}

.recent-intakes .card,
.recent-intakes .accordion {
    max-width: 100%;
}

.recent-intakes .container,
.recent-intakes .container-fluid {
    max-width: 100%;
    padding-left: 0;
    padding-right: 0;
}

.recent-intakes .table-responsive {
    overflow-x: visible;
}

.recent-intakes img {
    max-width: 100%;
    height: auto !important;
}

.table-responsive {
    overflow-x: visible;
}

#loadingMessage,
#loadingMessage1 {
    width: min(90vw, 360px) !important;
}

.support-float {
    padding-bottom: env(safe-area-inset-bottom);
    padding-right: env(safe-area-inset-right);
}

@media (max-width: 576px) {
    .recent-intakes h4,
    .recent-intakes h5 {
        font-size: 1.1rem;
    }
}
