:root {
    color-scheme: dark;
}

html,
body {
    min-height: 100%;
    min-height: calc(var(--app-vh, 1vh) * 100);
}

button,
a,
input,
select,
textarea {
    -webkit-tap-highlight-color: transparent;
}

[data-pwa-install][hidden] {
    display: none !important;
}

.pwa-install-link,
.pwa-floating-install {
    border: 1px solid rgba(211, 60, 47, 0.3);
    background: rgba(211, 60, 47, 0.12);
    color: #fff;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-weight: 700;
    min-height: 44px;
    padding: 10px 14px;
}

.pwa-install-link {
    width: 100%;
    margin-top: 14px;
}

.pwa-status-toast {
    position: fixed;
    left: 50%;
    bottom: max(18px, env(safe-area-inset-bottom));
    z-index: 3000;
    max-width: min(92vw, 360px);
    padding: 12px 16px;
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(10, 10, 12, 0.94);
    color: #fff;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.4);
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, 12px);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.pwa-status-toast.is-visible {
    opacity: 1;
    transform: translate(-50%, 0);
}

.pwa-status-toast[data-type="success"] {
    border-color: rgba(16, 185, 129, 0.3);
}

.pwa-status-toast[data-type="warning"] {
    border-color: rgba(245, 158, 11, 0.35);
}

@media (display-mode: standalone) {
    body {
        overscroll-behavior-y: contain;
    }
}

@media (max-width: 768px) {
    body.mobile-menu-open {
        overflow: hidden;
        touch-action: none;
    }

    .sidebar {
        width: min(86vw, 320px) !important;
        height: 100dvh !important;
        padding: max(18px, env(safe-area-inset-top)) 16px max(18px, env(safe-area-inset-bottom)) !important;
        overflow-y: auto;
        box-shadow: 24px 0 60px rgba(0, 0, 0, 0.45);
    }

    .mobile-overlay {
        background: rgba(0, 0, 0, 0.62) !important;
    }

    .main-content {
        width: 100%;
        padding: max(14px, env(safe-area-inset-top)) 12px max(22px, env(safe-area-inset-bottom)) !important;
    }

    .main-content > div:first-child,
    .top-bar {
        position: sticky;
        top: 0;
        z-index: 850;
        margin: -14px -12px 18px !important;
        padding: max(12px, env(safe-area-inset-top)) 12px 12px;
        background: rgba(10, 10, 12, 0.92);
        border-bottom: 1px solid rgba(255, 255, 255, 0.07);
        backdrop-filter: blur(14px);
        -webkit-backdrop-filter: blur(14px);
    }

    .top-bar {
        align-items: stretch !important;
    }

    .top-bar > div:first-child {
        width: 100%;
    }

    .top-icons {
        width: 100%;
        display: grid !important;
        grid-template-columns: repeat(5, minmax(42px, 1fr));
        gap: 8px !important;
    }

    .mobile-menu-btn,
    .icon-btn,
    .action-btn {
        min-width: 42px;
        min-height: 42px;
    }

    .mobile-menu-btn {
        margin-right: 10px !important;
        border-radius: 10px !important;
    }

    .search-box {
        min-height: 44px;
        border-radius: 12px !important;
        padding: 10px 12px !important;
    }

    h4,
    .main-content h4 {
        font-size: clamp(1.05rem, 5vw, 1.35rem);
        line-height: 1.25;
    }

    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 10px !important;
        margin-bottom: 18px !important;
    }

    .stat-card {
        border-radius: 16px !important;
        padding: 14px 10px !important;
        min-height: 94px;
    }

    .stat-card h3 {
        font-size: clamp(1.15rem, 7vw, 1.65rem) !important;
        line-height: 1.1;
        overflow-wrap: anywhere;
    }

    .stat-card p {
        font-size: 0.66rem !important;
        line-height: 1.25;
        letter-spacing: 0.04em !important;
    }

    .content-card {
        border-radius: 16px !important;
        overflow: hidden !important;
    }

    .card-header {
        padding: 16px !important;
        gap: 12px;
        align-items: stretch !important;
    }

    .card-header .btn,
    .card-header button,
    .card-header a {
        min-height: 42px;
    }

    .card-body {
        padding: 16px !important;
    }

    .mobile-card-table {
        overflow: visible !important;
    }

    .mobile-card-table table,
    .mobile-card-table thead,
    .mobile-card-table tbody,
    .mobile-card-table tr,
    .mobile-card-table td {
        display: block;
        width: 100%;
    }

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

    .mobile-card-table tbody {
        display: grid;
        gap: 12px;
        padding: 12px;
    }

    .mobile-card-table tbody tr {
        border: 1px solid rgba(255, 255, 255, 0.08);
        border-radius: 14px;
        background: rgba(255, 255, 255, 0.025);
        padding: 10px 12px;
    }

    .mobile-card-table tbody tr[style*="display: none"] {
        display: none !important;
    }

    .mobile-card-table tbody td {
        min-height: 38px;
        display: flex !important;
        align-items: center;
        justify-content: space-between;
        gap: 14px;
        padding: 10px 0 !important;
        border-bottom: 1px solid rgba(255, 255, 255, 0.06) !important;
        text-align: right;
        overflow-wrap: anywhere;
    }

    .mobile-card-table tbody td:last-child {
        border-bottom: 0 !important;
    }

    .mobile-card-table tbody td[colspan] {
        display: block !important;
        text-align: center;
    }

    .mobile-card-table tbody td[colspan]::before {
        display: none;
    }

    .mobile-card-table tbody td::before {
        content: attr(data-label);
        flex: 0 0 auto;
        max-width: 42%;
        color: var(--text-muted, #9ca3af);
        font-size: 0.68rem;
        font-weight: 800;
        letter-spacing: 0.05em;
        line-height: 1.25;
        text-align: left;
        text-transform: uppercase;
    }

    .mobile-card-table tbody td[data-label="Ação"],
    .mobile-card-table tbody td[data-label="Ações"] {
        display: block !important;
        text-align: left;
    }

    .mobile-card-table tbody td[data-label="Ação"]::before,
    .mobile-card-table tbody td[data-label="Ações"]::before {
        display: block;
        max-width: none;
        margin-bottom: 10px;
    }

    .action-btns {
        flex-wrap: wrap;
        gap: 10px !important;
    }

    .action-btn {
        width: 42px !important;
        height: 42px !important;
        border-radius: 10px !important;
        font-size: 16px !important;
    }

    .btn,
    .form-control,
    .form-select,
    input,
    select,
    textarea {
        font-size: 16px !important;
    }

    .btn,
    .btn-save,
    .btn-login {
        min-height: 44px;
    }

    .modal {
        padding-left: 0 !important;
        padding-right: 0 !important;
    }

    .modal-dialog {
        width: auto !important;
        max-width: calc(100vw - 18px) !important;
        margin: 9px auto max(9px, env(safe-area-inset-bottom)) !important;
    }

    .modal-content {
        border-radius: 18px !important;
        max-height: calc(100dvh - 18px);
        overflow: hidden;
    }

    .modal-header,
    .modal-footer {
        padding: 16px !important;
    }

    .modal-body {
        padding: 16px !important;
        overflow-y: auto;
        max-height: calc(100dvh - 150px);
    }

    .modal-footer {
        display: grid !important;
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .modal-footer .btn {
        width: 100%;
        margin: 0 !important;
    }

    .upload-area {
        align-items: flex-start !important;
        flex-direction: column;
    }

    .upload-btn,
    .btn-save {
        width: 100%;
        justify-content: center;
    }

    .btn-save-wrap {
        justify-content: stretch !important;
    }

    .pwa-status-toast {
        bottom: max(14px, env(safe-area-inset-bottom));
    }
}

@media (max-width: 420px) {
    .stats-grid {
        grid-template-columns: 1fr !important;
    }

    .mobile-card-table tbody td {
        align-items: flex-start;
        flex-direction: column;
        text-align: left;
    }

    .mobile-card-table tbody td::before {
        max-width: 100%;
    }
}
