/* ==========================================================================
   NGHENA — responsive.css  v1.0
   Sistema de Gestão de Apólices · by Carlyle Partners

   Apenas @media queries e correcções de layout.
   Não altera cores, tipografia base nem lógica de negócio.

   Breakpoints (Bootstrap 5 / Dashmix):
     xs  < 576px    telemóvel pequeno
     sm  576–767px  telemóvel grande
     md  768–991px  tablet / iPad portrait
     lg  992–1199px iPad landscape / laptop
     xl  ≥ 1200px   desktop (sem @media — default)

   Prioridade: mobile-first.
   ========================================================================== */


/* ══════════════════════════════════════════════════════════════
   0. FUNDAÇÃO GLOBAL
   ══════════════════════════════════════════════════════════════ */
html, body {
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

img, video, iframe { max-width: 100%; height: auto; }

/* Alvos tácteis mínimos 44px (WCAG 2.1) */
.btn, .nav-main-link, .dropdown-item,
.form-control, .form-select, .page-link {
  min-height: 44px;
}
.btn-xs  { min-height: 32px; }
.btn-sm  { min-height: 38px; }
.btn-lg  { min-height: 52px; }


/* ══════════════════════════════════════════════════════════════
   1. TABELAS — scroll horizontal universal
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 991px) {
  /* Forçar scroll em todas as tabelas em blocos */
  .block-content .table,
  .block-content > table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
    border-radius: 0;
  }

  .table thead th,
  .table tbody td {
    padding: 9px 12px !important;
    font-size: 12.5px;
    white-space: nowrap;
  }
}

@media (max-width: 575px) {
  .table thead th,
  .table tbody td {
    padding: 8px 10px !important;
    font-size: 12px;
  }

  /* Ocultar colunas secundárias em mobile (marcar com .d-none-xs) */
  .table .d-none-xs { display: none !important; }
}


/* ══════════════════════════════════════════════════════════════
   2. LAYOUT PRINCIPAL — sidebar, topbar, main
   ══════════════════════════════════════════════════════════════ */

/* Desktop ≥992px: layout já tratado pelo Dashmix */
@media (min-width: 992px) {
  /* Garantir sidebar não sobrepõe conteúdo */
  #page-container.sidebar-o #sidebar { transform: none !important; }
}

/* Tablet + Mobile: sidebar como drawer overlay */
@media (max-width: 991px) {
  #sidebar {
    position: fixed !important;
    top: 0; left: 0; height: 100% !important;
    z-index: 1031;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    transition: transform .28s cubic-bezier(.4,0,.2,1) !important;
  }

  /* Sidebar fechada por defeito no mobile */
  #page-container:not(.sidebar-o-xs) #sidebar {
    transform: translateX(-100%) !important;
  }

  /* Sidebar aberta */
  #page-container.sidebar-o-xs #sidebar {
    transform: translateX(0) !important;
  }

  /* Overlay quando sidebar aberta */
  #page-container.sidebar-o-xs #page-overlay {
    display: block !important;
    opacity: 1 !important;
  }

  /* Main sem margem lateral */
  #main-container,
  #page-header {
    margin-left: 0 !important;
    padding-left: 0 !important;
  }

  .content { padding: 16px !important; }
  .content-heading {
    font-size: .95rem !important;
    padding: 14px 16px 8px !important;
    margin-bottom: 0 !important;
  }
}

@media (max-width: 575px) {
  .content { padding: 12px !important; }
  .content-heading {
    font-size: .9rem !important;
    padding: 10px 12px 6px !important;
  }
}


/* ══════════════════════════════════════════════════════════════
   3. TOPBAR / PAGE HEADER
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 991px) {
  #page-header .content-header {
    padding: 0 12px !important;
    min-height: 56px !important;
  }

  /* Input de pesquisa: limitado em tablet */
  #page-header .input-group {
    max-width: 220px;
  }
}

@media (max-width: 575px) {
  #page-header .content-header {
    padding: 0 10px !important;
    min-height: 52px !important;
  }
}


/* ══════════════════════════════════════════════════════════════
   4. BLOCKS / CARDS
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 991px) {
  .block, .block-rounded {
    border-radius: 10px !important;
    margin-bottom: 12px !important;
  }
  .block-content { padding: 16px !important; }
  .block-header  { padding: 12px 16px !important; }
  .block-title   { font-size: .88rem !important; }
}

@media (max-width: 575px) {
  .block, .block-rounded { border-radius: 8px !important; }
  .block-content { padding: 14px !important; }
  .block-header  { padding: 10px 14px !important; }
}


/* ══════════════════════════════════════════════════════════════
   5. KPI / STATS CARDS (Dashboard — col-md-6 col-xl-3)
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 575px) {
  /* 2 colunas em mobile */
  .row > .col-md-6.col-xl-3,
  .row > .col-md-6.col-lg-3,
  .row > .col-sm-6.col-xl-3 {
    flex: 0 0 50%;
    max-width: 50%;
  }

  .col-md-6.col-xl-3 .block-content { padding: 12px !important; }
  .col-md-6.col-xl-3 .fs-2 { font-size: 1.5rem !important; }
  .col-md-6.col-xl-3 .fs-sm { font-size: .68rem !important; }
}

@media (max-width: 360px) {
  /* 1 coluna em ecrãs muito pequenos */
  .row > .col-md-6.col-xl-3,
  .row > .col-md-6.col-lg-3 {
    flex: 0 0 100%;
    max-width: 100%;
  }
}


/* ══════════════════════════════════════════════════════════════
   6. FORMULÁRIOS
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 991px) {
  .form-label, .col-form-label {
    font-size: .85rem;
    margin-bottom: 4px;
  }

  .form-control, .form-select {
    font-size: .9rem !important;
    padding: 10px 12px !important;
    min-height: 44px;
    height: auto !important;
  }

  .form-control-sm, .form-select-sm {
    font-size: .82rem !important;
    padding: 7px 10px !important;
    min-height: 38px;
  }

  textarea.form-control { min-height: 90px; }

  /* Select2 */
  .select2-container--default .select2-selection--single {
    min-height: 44px !important;
    padding: 9px 12px !important;
    line-height: 1.5 !important;
  }
  .select2-container--default .select2-selection--single
    .select2-selection__arrow { height: 44px !important; }
}

@media (max-width: 575px) {
  /* Colunas de form: sempre 100% em mobile */
  .row > .col-sm-6,
  .row > .col-md-6,
  .row > .col-lg-4,
  .row > .col-lg-6,
  .row > .col-xl-4,
  .row > .col-xl-6 {
    flex: 0 0 100%;
    max-width: 100%;
  }
}


/* ══════════════════════════════════════════════════════════════
   7. BOTÕES
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 575px) {
  /* Grupos de botões: scroll horizontal em vez de quebrar */
  .d-flex.gap-2.flex-wrap { flex-wrap: wrap !important; }

  .btn-sm {
    padding: 8px 13px !important;
    font-size: 12.5px !important;
  }

  /* Botões de acção em full-width quando sozinhos */
  .btn.w-100-mobile { width: 100% !important; }
}


/* ══════════════════════════════════════════════════════════════
   8. MODAIS — fullscreen em mobile
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 575px) {
  .modal-dialog {
    margin: 0 !important;
    max-width: 100% !important;
    width: 100% !important;
    height: 100%;
  }

  .modal-content {
    border-radius: 0 !important;
    border: none !important;
    min-height: 100dvh;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
  }

  .modal-header {
    padding: 14px 16px !important;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--ng-surface);
  }

  .modal-body {
    padding: 16px !important;
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .modal-footer {
    padding: 12px 16px !important;
    flex-shrink: 0;
    position: sticky;
    bottom: 0;
    background: var(--ng-surface);
    border-top: 1px solid var(--ng-border);
  }

  .modal-footer .btn { flex: 1; }
}

@media (min-width: 576px) and (max-width: 767px) {
  .modal-dialog {
    margin: 20px auto !important;
    max-width: calc(100% - 32px) !important;
  }
  .modal-content { border-radius: 14px !important; }
}


/* ══════════════════════════════════════════════════════════════
   9. FICHA DO MEMBRO / DETALHES (colunas col-lg-4 / col-lg-8)
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 991px) {
  .row > .col-lg-4,
  .row > .col-xl-4 {
    flex: 0 0 100%; max-width: 100%;
    margin-bottom: 12px;
  }
  .row > .col-lg-8,
  .row > .col-xl-8 {
    flex: 0 0 100%; max-width: 100%;
  }

  dl.row > dt,
  dl.row > dd {
    font-size: .85rem !important;
    padding: 7px 10px !important;
  }
}

@media (max-width: 575px) {
  /* dl empilhados verticalmente */
  dl.row { display: block !important; }

  dl.row > dt {
    font-size: .72rem !important;
    font-weight: 700;
    color: var(--ng-text-soft);
    padding: 8px 0 2px !important;
    border: none !important;
    background: transparent !important;
  }

  dl.row > dd {
    font-size: .88rem !important;
    padding: 0 0 10px !important;
    border-bottom: 1px solid var(--ng-border) !important;
    margin-left: 0 !important;
  }

  dl.row > dd:last-child { border-bottom: none !important; }

  .badge {
    font-size: .72rem !important;
    padding: 4px 9px !important;
  }
}


/* ══════════════════════════════════════════════════════════════
   10. CABEÇALHOS DE ACÇÃO (action bars, filtros)
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 767px) {
  /* Pares título + botão: stack vertical */
  .d-flex.justify-content-between.align-items-center.mb-3,
  .d-flex.justify-content-between.align-items-center.mb-4 {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 10px !important;
  }

  .d-flex.justify-content-between.align-items-center > .btn,
  .d-flex.justify-content-between.align-items-center > .d-flex {
    width: 100%;
  }

  /* Barra de filtros: scroll horizontal */
  .filter-bar {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
    padding-bottom: 4px;
  }

  .input-group { width: 100% !important; }
}


/* ══════════════════════════════════════════════════════════════
   11. ALERTAS
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 575px) {
  .alert {
    font-size: .85rem !important;
    padding: 12px 14px !important;
    border-radius: 10px !important;
  }
}


/* ══════════════════════════════════════════════════════════════
   12. PAGINAÇÃO
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 575px) {
  .pagination {
    flex-wrap: wrap;
    justify-content: center;
    gap: 4px;
  }

  .page-link {
    padding: 8px 11px !important;
    font-size: .82rem !important;
    min-height: 38px;
    min-width: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
}


/* ══════════════════════════════════════════════════════════════
   13. DATATABLES
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 767px) {
  .dataTables_wrapper .dataTables_length,
  .dataTables_wrapper .dataTables_filter {
    float: none !important;
    text-align: left !important;
    margin-bottom: 10px;
    display: block;
    width: 100%;
  }

  .dataTables_wrapper .dataTables_filter input {
    width: 100% !important;
    display: block !important;
    min-height: 44px;
    padding: 8px 12px;
    margin-left: 0 !important;
  }

  .dataTables_wrapper .dataTables_info,
  .dataTables_wrapper .dataTables_paginate {
    float: none !important;
    text-align: center !important;
    margin-top: 10px;
  }

  .dataTables_wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }
}


/* ══════════════════════════════════════════════════════════════
   14. PORTAL CLIENTE — BOTTOM NAVIGATION (mobile only)
   ══════════════════════════════════════════════════════════════ */

/* Esconder sidebar em mobile — substituída pela bottom nav */
@media (max-width: 767px) {
  /* Sidebar visível apenas quando toggle activo */
  #page-container:not(.sidebar-o-xs) #sidebar {
    display: none !important;
  }

  /* Reservar espaço para bottom nav */
  #main-container { padding-bottom: 68px !important; }

  /* Bottom Nav */
  .ng-bottom-nav {
    display: flex !important;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: 60px;
    background: #fff;
    border-top: 1px solid rgba(14,124,123,.14);
    box-shadow: 0 -4px 20px rgba(14,124,123,.1);
    z-index: 1035;
    align-items: stretch;
    /* Safe area iOS */
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .ng-bottom-nav a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    text-decoration: none;
    color: #6e8887;
    font-size: .56rem;
    font-weight: 600;
    letter-spacing: .3px;
    text-transform: uppercase;
    padding: 6px 2px;
    position: relative;
    -webkit-tap-highlight-color: transparent;
    transition: color .15s;
  }

  .ng-bottom-nav a i {
    font-size: 1.05rem;
    line-height: 1;
    transition: color .15s, transform .15s;
  }

  .ng-bottom-nav a.active { color: #0E7C7B; }
  .ng-bottom-nav a.active i {
    color: #0E7C7B;
    transform: scale(1.08);
  }

  /* Indicator line */
  .ng-bottom-nav a.active::after {
    content: '';
    position: absolute;
    top: 0; left: 50%;
    transform: translateX(-50%);
    width: 28px; height: 2px;
    background: #0E7C7B;
    border-radius: 0 0 4px 4px;
  }
}

/* Desktop/tablet: esconder bottom nav */
@media (min-width: 768px) {
  .ng-bottom-nav { display: none !important; }
}


/* ══════════════════════════════════════════════════════════════
   15. PORTAL ADMIN — SIDEBAR MOBILE TOGGLE
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 991px) {
  /* Overlay escuro quando sidebar aberta */
  .ng-sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 1030;
    backdrop-filter: blur(1px);
    -webkit-backdrop-filter: blur(1px);
  }
  .ng-sidebar-overlay.active { display: block; }
}


/* ══════════════════════════════════════════════════════════════
   16. TIPOGRAFIA ADAPTATIVA
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 991px) {
  h2, .h2 { font-size: 1.2rem !important; }
  h3, .h3 { font-size: 1.05rem !important; }
  h4, .h4 { font-size: .95rem !important; }
  .fs-1    { font-size: 1.8rem !important; }
  .fs-2    { font-size: 1.4rem !important; }
  .fs-3    { font-size: 1.15rem !important; }
}

@media (max-width: 575px) {
  body, #page-container {
    font-size: 13px !important;
    line-height: 1.5;
  }
  h2, .h2 { font-size: 1.1rem !important; }
  .fs-2    { font-size: 1.3rem !important; }
  .fs-sm   { font-size: .7rem !important; }
}


/* ══════════════════════════════════════════════════════════════
   17. REVENDEDOR PORTAL (revendedor/)
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  /* Sidebar do revendedor: drawer */
  .sidebar {
    position: fixed !important;
    top: 0; left: 0; height: 100% !important;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform .3s cubic-bezier(.4,0,.2,1) !important;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .sidebar.open { transform: translateX(0) !important; }

  .main-content {
    margin-left: 0 !important;
    padding: 14px !important;
  }

  .topbar {
    left: 0 !important;
  }
}

@media (max-width: 575px) {
  .main-content { padding: 10px !important; }
}


/* ══════════════════════════════════════════════════════════════
   18. FORMULÁRIOS PÚBLICOS (public/)
   ══════════════════════════════════════════════════════════════ */

/* Sinistro, Adesão, Registo Revendedor */
@media (max-width: 575px) {
  /* Container principal estreito */
  .container, .container-fluid { padding-left: 12px !important; padding-right: 12px !important; }

  /* Upload zones: mais compactas */
  .upload-zone { padding: 16px !important; }

  /* Dropzone mobile */
  .dropzone { min-height: 100px !important; padding: 16px !important; }
}


/* ══════════════════════════════════════════════════════════════
   19. PRINTS
   ══════════════════════════════════════════════════════════════ */
@media print {
  #sidebar, #page-header, .ng-bottom-nav,
  .btn:not(.btn-print), .modal-backdrop,
  .ng-sidebar-overlay { display: none !important; }

  #main-container { margin: 0 !important; padding: 0 !important; }
  .block { box-shadow: none !important; border: 1px solid #ddd !important; }
  .table { white-space: normal !important; overflow: visible !important; display: table !important; }
}


/* ══════════════════════════════════════════════════════════════
   20. UTILITÁRIOS
   ══════════════════════════════════════════════════════════════ */

/* Scroll horizontal para listas de pills */
.pills-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  white-space: nowrap;
  scrollbar-width: none;
}
.pills-scroll::-webkit-scrollbar { display: none; }

/* Texto truncado em mobile */
@media (max-width: 575px) {
  .text-truncate-sm {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 140px;
    display: inline-block;
    vertical-align: bottom;
  }
}
