/* ============================================================
   RESPONSIVO 100% — Complemento global
   ============================================================ */

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

html,
body {
    max-width: 100%;
    overflow-x: hidden;
}

img,
svg,
video,
canvas {
    max-width: 100%;
    height: auto;
}

.wrapper {
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
}

/* Utilitários responsivos */
@media (min-width: 768px) {
    .w-md-auto {
        width: auto !important;
    }
}

/* Evita zoom indesejado no iOS ao focar inputs */
@media (max-width: 767.98px) {
    input,
    select,
    textarea,
    .form-control,
    .form-select {
        font-size: 16px !important;
    }
}

/* Gráficos */
.chart-container {
    position: relative;
    width: 100%;
    min-height: 220px;
}

.chart-container-pie {
    min-height: 260px;
    max-width: 320px;
    margin: 0 auto;
}

/* Tabelas dentro de cards sem wrapper */
.card > .table {
    margin-bottom: 0;
}

/* Detalhes empilhados (ver documento) */
@media (max-width: 767.98px) {
    .table-detail-stack tbody tr {
        display: block;
        border-bottom: 1px solid var(--border-light);
        padding: 0.5rem 0;
    }

    .table-detail-stack tbody tr:last-child {
        border-bottom: none;
    }

    .table-detail-stack th,
    .table-detail-stack td {
        display: block;
        width: 100%;
        border: none;
        padding: 0.15rem 0.75rem;
    }

    .table-detail-stack th {
        color: var(--text-muted);
        font-size: 0.75rem;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        padding-top: 0.5rem;
    }

    .table-detail-stack td {
        padding-bottom: 0.5rem;
        word-break: break-word;
    }
}

/* Botões de formulário */
@media (max-width: 767.98px) {
    .form-actions-bar {
        flex-direction: column;
    }

    .form-actions-bar .btn {
        width: 100%;
    }

    .form-actions-bar .btn-lg {
        padding-top: 0.75rem;
        padding-bottom: 0.75rem;
    }
}

/* Filtros e pesquisas */
@media (max-width: 767.98px) {
    .table-filter-input {
        width: 100% !important;
        max-width: 100% !important;
    }

    .card-header .d-flex.gap-2 {
        flex-direction: column;
        align-items: stretch !important;
        width: 100%;
    }

    .card-header .d-flex.gap-2 .btn {
        width: 100%;
    }
}

/* Grupos de filtros */
@media (max-width: 767.98px) {
    .card-body .btn-group,
    .card-body .d-flex.flex-wrap .btn-group {
        display: flex;
        flex-wrap: wrap;
        width: 100%;
    }

    .card-body .btn-group .btn {
        flex: 1 1 auto;
        min-width: calc(50% - 0.25rem);
    }
}

/* Acções em tabelas admin */
@media (max-width: 575.98px) {
    .table-actions-cell {
        min-width: 0 !important;
    }

    .table-actions-cell .btn-sm {
        padding: 0.35rem 0.5rem;
    }
}

/* Modais em ecrã completo no telemóvel */
@media (max-width: 575.98px) {
    .modal-fullscreen-sm-down {
        width: 100vw;
        max-width: none;
        height: 100%;
        margin: 0;
    }

    .modal-fullscreen-sm-down .modal-content {
        min-height: 100%;
        border-radius: 0;
    }

    .modal.fade.show[style*="display:block"] {
        padding: 0 !important;
    }

    .modal.fade.show[style*="display:block"] .modal-dialog {
        margin: 0;
        max-width: 100%;
        min-height: 100dvh;
    }

    .modal.fade.show[style*="display:block"] .modal-content {
        min-height: 100dvh;
        border-radius: 0;
    }
}

/* Timeline */
@media (max-width: 767.98px) {
    .timeline {
        padding-left: 24px;
    }

    .timeline-item::before {
        left: -17px;
        width: 10px;
        height: 10px;
    }

    .timeline::before {
        left: 8px;
    }
}

/* Cabeçalho ver.php */
@media (max-width: 767.98px) {
    .page-header .d-flex.gap-2.no-print {
        width: 100%;
    }

    .page-header .d-flex.gap-2.no-print .btn,
    .page-header .d-flex.gap-2.no-print .badge {
        flex: 1 1 auto;
        text-align: center;
    }
}

/* List group anexos */
@media (max-width: 767.98px) {
    .list-group-item-action {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.35rem;
    }
}

/* Stat cards compactos */
@media (max-width: 575.98px) {
    .stat-card .card-body {
        padding: 0.75rem !important;
    }

    .stat-card .stat-icon {
        width: 38px !important;
        height: 38px !important;
        font-size: 1rem !important;
        margin-right: 0.5rem !important;
    }

    .stat-value {
        font-size: 1.25rem;
    }

    .stat-card .card-body.d-flex.justify-content-between {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.75rem;
    }

    .stat-card .card-body.d-flex.justify-content-between .btn {
        width: 100%;
    }
}

/* Scroll horizontal suave em tabelas */
.table-responsive {
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}

.table-responsive:focus {
    outline: 2px solid rgba(204, 9, 47, 0.25);
    outline-offset: -2px;
}

/* Configurações e perfil */
@media (max-width: 767.98px) {
    .row.g-4 > [class*="col-lg-"] {
        margin-bottom: 0.5rem;
    }
}

/* Notificações */
@media (max-width: 767.98px) {
    .list-group-item .d-flex {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.25rem;
    }
}

/* Impressão — mantém layout desktop */
@media print {
    html,
    body {
        overflow: visible !important;
    }

    .table-detail-stack th,
    .table-detail-stack td {
        display: table-cell !important;
    }

    .table-detail-stack tbody tr {
        display: table-row !important;
    }
}
