/* ==========================================================================
   Merwa — mobile / tablet / desktop layer (loaded on resident, admin and public pages)
   Makes every page behave like a phone app on small screens.
   ========================================================================== */
html { -webkit-text-size-adjust: 100%; }
html, body { max-width: 100%; overflow-x: hidden; }
img, video, iframe, canvas, svg { max-width: 100%; }
img { height: auto; }
.table-responsive, .tbl-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
.table-responsive > table, .tbl-scroll > table { min-width: 560px; }
table { max-width: 100%; }
pre, code { word-break: break-word; }

/* safe areas (notch / gesture bar) */
body { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }

/* ---- resident: message bell ---- */
.msg-bell { position: relative; margin-left: auto; width: 40px; height: 40px; border-radius: 12px; display: inline-flex; align-items: center; justify-content: center; background: #f1f5f9; color: #334155; font-size: 17px; flex-shrink: 0; }
.msg-bell.ringing i { animation: msgRing .6s ease-in-out infinite; transform-origin: 50% 0; }
@keyframes msgRing { 0%,100% { transform: rotate(0); } 20% { transform: rotate(18deg); } 40% { transform: rotate(-16deg); } 60% { transform: rotate(10deg); } 80% { transform: rotate(-8deg); } }
.msg-badge { position: absolute; top: -5px; right: -5px; min-width: 19px; height: 19px; padding: 0 5px; border-radius: 10px; background: #ef4444; color: #fff; font-size: 11px; font-weight: 700; line-height: 19px; text-align: center; }

/* ---- resident: popup toasts ---- */
#userPopupHost { position: fixed; top: 12px; right: 12px; left: 12px; z-index: 9999; display: flex; flex-direction: column; gap: 10px; align-items: flex-end; pointer-events: none; padding-top: env(safe-area-inset-top); }
.user-popup { pointer-events: auto; width: 100%; max-width: 380px; background: #fff; border-radius: 14px; border-left: 5px solid #0d9488; box-shadow: 0 12px 40px rgba(15,23,42,.25); padding: 14px 16px; position: relative; animation: upIn .25s ease; }
.user-popup.warn { border-left-color: #ef4444; }
.user-popup .up-title { font-weight: 700; font-size: 14.5px; padding-right: 22px; }
.user-popup .up-body { font-size: 13.5px; color: #475569; margin: 6px 0 10px; line-height: 1.5; max-height: 140px; overflow: auto; }
.user-popup .up-link { display: inline-block; background: #0d9488; color: #fff; padding: 6px 14px; border-radius: 8px; font-size: 12.5px; font-weight: 600; }
.user-popup .up-x { position: absolute; top: 6px; right: 8px; border: 0; background: none; font-size: 22px; line-height: 1; cursor: pointer; color: #94a3b8; }
@keyframes upIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: none; } }
#soundBanner { position: fixed; left: 50%; bottom: calc(76px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: #0f172a; color: #fff; padding: 10px 20px; border-radius: 30px; font-size: 13px; cursor: pointer; z-index: 9998; display: none; box-shadow: 0 8px 24px rgba(0,0,0,.3); white-space: nowrap; }

/* ---- overlay behind slide-in menus ---- */
.nav-overlay { position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 900; opacity: 0; visibility: hidden; transition: opacity .25s; }
.nav-overlay.show { opacity: 1; visibility: visible; }

/* ---- bottom app bar (phones & small tablets) ---- */
.bottom-nav, .admin-bottom-nav { display: none; }
@media (max-width: 992px) {
    .bottom-nav, .admin-bottom-nav {
        display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 800;
        background: #fff; border-top: 1px solid #e2e8f0; box-shadow: 0 -6px 24px rgba(15,23,42,.08);
        padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    }
    .bottom-nav a, .admin-bottom-nav a {
        flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 2px;
        font-size: 11px; font-weight: 600; color: #64748b; border-radius: 10px; min-width: 0;
    }
    .bottom-nav a i, .admin-bottom-nav a i { font-size: 18px; }
    .bottom-nav a.active, .admin-bottom-nav a.active { color: #0d9488; background: #f0fdfa; }
    .main-content, .admin-main { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
    .sidebar, .admin-sidebar { max-width: 86vw; z-index: 1001 !important; padding-bottom: env(safe-area-inset-bottom); }
    .close-sidebar { display: block; }
    .topbar, .admin-topbar { padding-top: calc(10px + env(safe-area-inset-top)); }
}

/* ---- tablets / phones: layout ---- */
@media (max-width: 768px) {
    body { font-size: 15px; }
    .content-wrapper, .admin-content { padding: 14px 12px 28px !important; }
    .card-header { flex-wrap: wrap; gap: 8px; }
    .card-header h2 { font-size: 1.02rem; }
    .grid-2, .grid-3, .form-row, .grid2 { grid-template-columns: minmax(0, 1fr) !important; }
    .stats-grid, .stat-grid-admin { grid-template-columns: 1fr 1fr !important; gap: 10px !important; }
    .stat-card { padding: 12px !important; gap: 10px !important; }
    .stat-icon { width: 38px; height: 38px; font-size: 16px; }
    /* inline two-column layouts built with style="grid-template-columns:..." stack on phones */
    [style*="grid-template-columns"]:not([style*="auto-fill"]):not([style*="auto-fit"]):not([style*="1fr 1fr 1fr"]) { grid-template-columns: minmax(0, 1fr) !important; }
    /* touch friendly controls; 16px stops iOS from zooming into inputs */
    .form-control, input[type=text], input[type=email], input[type=password], input[type=number], input[type=tel], input[type=date], input[type=search], select, textarea { font-size: 16px !important; min-height: 44px; }
    textarea.form-control, textarea { min-height: 90px; }
    .btn { min-height: 42px; }
    .btn-sm { min-height: 36px; padding-left: 12px; padding-right: 12px; }
    .table-responsive > table, .tbl-scroll > table { min-width: 520px; }
    th, td { padding: 9px 10px !important; font-size: 13px; }
    /* modals */
    [id$="Modal"] > div { width: 94% !important; max-width: 94% !important; max-height: 92vh; overflow-y: auto; }
    .alert, .alert-popup { max-width: 100% !important; }
    #alertPopupHost { left: 10px !important; right: 10px !important; }
    .alert-popup { min-width: 0 !important; width: 100% !important; }
    .notif-panel { position: fixed !important; left: 8px !important; right: 8px !important; top: 60px !important; width: auto !important; max-width: none !important; }
    .pay-toolbar { flex-direction: column; align-items: stretch !important; }
    .pay-toolbar .form-control { max-width: none !important; width: 100%; }
    .invoice-box { padding: 16px !important; }
}
@media (max-width: 420px) {
    .topbar .page-title { font-size: 15px; }
}
/* printing keeps desktop look */
@media print { .bottom-nav, .admin-bottom-nav, .msg-bell, #userPopupHost, #soundBanner, .nav-overlay { display: none !important; } }

/* ---- page-specific two-column layouts that must stack on tablets / phones ---- */
@media (max-width: 900px) {
    .admin-content .layout, .gm-grid, .team-admin-grid, .vid-layout, .about-split, .contact-grid { grid-template-columns: minmax(0, 1fr) !important; }
}
/* grid / flex children may shrink below their content width (stops tables & long text pushing the page wider than the screen) */
.admin-content > *, .content-wrapper > *, .main-content, .admin-main { min-width: 0; max-width: 100%; }
@media (max-width: 992px) {
    [class*="grid"] > *, [style*="display:grid"] > *, .layout > * { min-width: 0; }
    .admin-content form, .content-wrapper form { max-width: 100%; }
    .admin-content select, .content-wrapper select { max-width: 100%; }
    /* filter bars made of inline-sized inputs */
    form[style*="flex-wrap"] > .form-control, form[style*="flex-wrap"] > select, form[style*="flex-wrap"] > input { max-width: 100% !important; flex: 1 1 140px; }
}
/* public home: vendor verification box */
@media (max-width: 640px) {
    .vendor-verify-home form { justify-content: stretch !important; min-width: 0 !important; width: 100%; }
    .vendor-verify-home form input { max-width: none !important; flex: 1 1 100%; }
    .vendor-verify-home form button { flex: 1 1 100%; justify-content: center; }
    .section { padding-left: 16px; padding-right: 16px; }
}
/* long words / emails never push the layout */
td, th, p, h1, h2, h3, h4, .card-body { overflow-wrap: anywhere; }
table td, table th { overflow-wrap: break-word; }

/* ---- tables that turn into cards on phones (add class "stack-mobile") ---- */
@media (max-width: 640px) {
    .table-responsive > table.stack-mobile, table.stack-mobile { min-width: 0 !important; display: block; width: 100%; }
    table.stack-mobile thead { display: none; }
    table.stack-mobile tbody, table.stack-mobile tr { display: block; width: 100%; }
    table.stack-mobile tr { border: 1px solid #e2e8f0; border-radius: 14px; margin-bottom: 12px; padding: 6px 14px; background: #fff; box-shadow: 0 2px 10px rgba(15,23,42,.04); }
    table.stack-mobile td { display: flex !important; justify-content: space-between; align-items: center; gap: 14px; padding: 8px 0 !important; border: 0 !important; border-bottom: 1px dashed #f1f5f9 !important; text-align: right; font-size: 13.5px; }
    table.stack-mobile td:last-child { border-bottom: 0 !important; }
    table.stack-mobile td::before { content: attr(data-label); font-weight: 600; color: #64748b; text-align: left; flex-shrink: 0; font-size: 12.5px; }
    table.stack-mobile td:not([data-label])::before, table.stack-mobile td[data-label=""]::before { display: none; }
    .stats-grid, .stat-grid-admin { grid-template-columns: 1fr 1fr !important; }
}
@media (max-width: 420px) {
    .stats-grid, .stat-grid-admin { grid-template-columns: 1fr 1fr !important; gap: 8px !important; }
    .stat-card { padding: 10px !important; gap: 8px !important; flex-direction: row; }
    .stat-card h3, .stat-card .stat-value { font-size: 1.15rem !important; }
    .stat-card p, .stat-card .stat-label { font-size: 11.5px !important; }
}

/* sound prompt sits above the bottom app bar on phones */
@media (max-width: 992px) { #soundBanner { bottom: calc(78px + env(safe-area-inset-bottom)) !important; } }

/* rows of avatar + text + several action buttons wrap instead of overflowing */
@media (max-width: 640px) {
    .member-row, .ev-row, .sh-item { flex-wrap: wrap; }
    .member-row > div[style*="flex:1"] { flex: 1 1 150px; min-width: 0; }
}
