/**
 * FGSC Portal — CSS Responsivo Mobile
 * Ficheiro: /public_html/assets/responsive.css
 *
 * Incluir em TODAS as páginas do portal e admin:
 * <link rel="stylesheet" href="/assets/responsive.css">
 *
 * Breakpoints:
 *   Mobile  : ≤ 640px
 *   Tablet  : 641px – 900px
 *   Desktop : ≥ 901px (estilos base nas páginas PHP)
 */

/* ═══════════════════════════════════════════════════════════════
   UTILITÁRIOS GLOBAIS
   ═══════════════════════════════════════════════════════════════ */

* { box-sizing: border-box; }

/* Scrollbar fina em todas as áreas */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #E2E8F0; border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: #CBD5E1; }

/* ═══════════════════════════════════════════════════════════════
   TABLET  (641px – 900px)
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 900px) {

  /* SIDEBAR — colapsa para 56px com apenas ícones */
  .sb, .sidebar {
    width: 56px !important;
    min-width: 56px !important;
    overflow: visible;
    position: relative;
    z-index: 100;
  }

  /* Esconder texto e pills na sidebar */
  .sb-brand-text,
  .sb-admin-tag span,
  .sb-user-name, .sb-nm,
  .sb-user-code, .sb-cd, .sb-role,
  .sb-gl,
  .sb-a span,
  .sb-a .sb-pill,
  .sb-a .sb-pill.am,
  .sb-a .sb-pill.bl,
  .sb-out span,
  .sidebar .nav-label,
  .sidebar .nav-item span,
  .sidebar .nav-badge {
    display: none !important;
  }

  /* Logo — mostrar só ícone */
  .sb-brand, .sb-logo { justify-content: center; padding: 16px 0; }
  .sb-brand svg { margin: 0 auto; }

  /* User avatar centrado */
  .sb-user, .sidebar .client-avatar-wrap {
    justify-content: center;
    padding: 8px 0;
    background: transparent !important;
    border: none !important;
  }
  .sb-av { margin: 0 auto; }

  /* Links sidebar — centrar ícones */
  .sb-a, .sidebar .nav-item {
    justify-content: center;
    padding: 10px 0 !important;
  }
  .sb-a i, .sidebar .nav-item i { margin: 0 auto; font-size: 18px !important; }

  /* Logout */
  .sb-ft { padding: 10px 0; display: flex; justify-content: center; }
  .sb-out { justify-content: center; }

  /* KPI grids: 2 colunas em vez de 4 */
  .kpis, .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  /* Grids de 2 colunas: empilhar */
  .g2, .bg2, .grid2, .two-col, .body-grid {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  /* Pipeline Kanban: 2 colunas */
  .pipeline {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  /* Hero financeiro: 2 colunas */
  .fin-hero, .score-bar {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 8px;
  }
  .fin-hero .fh-s:nth-child(2),
  .fin-hero .fh-stat:nth-child(2) { border-right: none !important; }
  .fin-hero .fh-s:nth-child(3),
  .fin-hero .fh-stat:nth-child(3) { border-left: none !important; }
  .sb2-div { display: none !important; }
  .prog-wrap, .pw { grid-column: 1 / -1; }

  /* Tabelas — esconder colunas menos críticas */
  .cl-table th:nth-child(4),
  .cl-table td:nth-child(4),
  .ob-table th:nth-child(5),
  .ob-table td:nth-child(5),
  .fact-table th:nth-child(4),
  .fact-table td:nth-child(4) { display: none; }
}

/* ═══════════════════════════════════════════════════════════════
   MOBILE  (≤ 640px)
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 640px) {

  /* ── LAYOUT PRINCIPAL ─────────────────────────────────────── */

  /* Portal usa flex coluna: topbar + conteúdo + nav bottom */
  .portal, .portal-wrap {
    flex-direction: column !important;
    height: 100dvh;
    overflow: hidden;
  }

  /* Sidebar desktop escondida */
  .sb, .sidebar {
    display: none !important;
  }

  /* Main ocupa tudo */
  .main, .main-area {
    flex: 1;
    overflow: hidden;
    min-width: 0;
  }

  /* Topbar compacta */
  .topbar {
    height: 48px !important;
    padding: 0 14px !important;
  }
  .tb-l h1, .topbar-title { font-size: 13px !important; }
  .tb-l span, .topbar .breadcrumb { display: none !important; }
  .tb-date { display: none !important; }

  /* Conteúdo com padding reduzido */
  .ct, .content, .ct { padding: 12px 14px !important; }

  /* ── NAVEGAÇÃO BOTTOM ─────────────────────────────────────── */

  /* Barra de navegação inferior para mobile */
  .mobile-nav {
    display: flex !important;
    align-items: center;
    justify-content: space-around;
    height: 56px;
    background: #fff;
    border-top: 1px solid #E2E8F0;
    flex-shrink: 0;
    padding: 0 8px;
    position: relative;
    z-index: 50;
  }
  .mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 6px 10px;
    text-decoration: none;
    border-radius: 8px;
    position: relative;
    transition: background .15s;
  }
  .mobile-nav-item i { font-size: 20px; color: #94A3B8; }
  .mobile-nav-item span { font-size: 9px; color: #94A3B8; font-family: 'Century Gothic', sans-serif; }
  .mobile-nav-item.on i, .mobile-nav-item.on span { color: #1EA7E1; }
  .mobile-nav-item .m-pill {
    position: absolute;
    top: 4px;
    right: 6px;
    width: 16px;
    height: 16px;
    background: #E8563A;
    border-radius: 50%;
    font-size: 8px;
    font-weight: 700;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1.5px solid #fff;
  }

  /* ── HERO / SCORE ─────────────────────────────────────────── */

  .hero, .score-card, .fin-hero {
    padding: 14px 14px !important;
    border-radius: 10px !important;
    margin-bottom: 12px !important;
  }

  /* Hero portal — empilhar score + info */
  .hero { flex-direction: column !important; gap: 10px !important; }
  .hero-rt, .hero-right {
    border-left: none !important;
    border-top: 1px solid rgba(255,255,255,0.08) !important;
    margin-left: 0 !important;
    padding-left: 0 !important;
    padding-top: 10px !important;
    text-align: left !important;
    display: flex;
    gap: 20px;
  }
  .hero-inf, .hero-info { min-width: 0; }

  /* Score bar admin */
  .score-bar {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px !important;
  }
  .sb2-d, .sb2-div { display: none !important; }
  .pw, .prog-wrap { grid-column: 1 / -1; }

  /* Hero financeiro */
  .fin-hero {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
  .fin-hero .fh-s, .fin-hero .fh-stat {
    border-right: none !important;
    padding: 0 !important;
  }

  /* ── KPI GRID ─────────────────────────────────────────────── */

  .kpis, .kpi-grid, .kpi-row {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 8px !important;
    margin-bottom: 12px !important;
  }
  .kpi, .kpi-card {
    padding: 11px 12px !important;
    border-radius: 8px !important;
  }
  .kpi-v, .kpi-val, .kpi-num { font-size: 18px !important; }
  .kpi-n, .kpi-lbl, .kpi-name { font-size: 9px !important; }

  /* ── GRIDS ────────────────────────────────────────────────── */

  .g2, .bg2, .grid2, .two-col, .body-grid,
  .top-grid, .pipeline {
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 10px !important;
  }

  /* ── SECTION CARDS ────────────────────────────────────────── */

  .sc, .card, .section-card,
  .fact-table, .ob-table, .doc-table, .cl-table-wrap {
    border-radius: 8px !important;
    margin-bottom: 10px !important;
  }
  .sc-h, .card-header, .section-header {
    padding: 10px 12px !important;
  }
  .sc-h h3, .card-header h3 { font-size: 11px !important; }

  /* ── TABELAS → CARDS MOBILE ───────────────────────────────── */

  /* Esconder cabeçalhos de tabela */
  .ob-table .ot-head,
  .cl-table thead,
  .fact-table .ft-head,
  .doc-table .dt-head {
    display: none !important;
  }

  /* Converter linhas de tabela em cards */
  .ob-table .ot-row,
  .cl-table tbody tr,
  .fact-table .ft-row,
  .doc-table .dt-row {
    display: flex !important;
    flex-direction: column !important;
    gap: 6px !important;
    padding: 12px !important;
    border-bottom: 1px solid #F1F5F9 !important;
    border-radius: 0 !important;
  }

  /* Acções ficam numa linha */
  .ot-acts, .cl-acts, .ft-acts, .doc-acts {
    flex-direction: row !important;
    justify-content: flex-start !important;
    flex-wrap: wrap !important;
    gap: 6px !important;
    margin-top: 4px !important;
  }

  /* Esconder colunas menos críticas em mobile */
  .ot-row .ot-cell:nth-child(3),
  .ft-row .ft-date:first-of-type { display: none !important; }

  /* ── FILTROS ──────────────────────────────────────────────── */

  .filters { gap: 6px !important; }
  .filter-tabs, .f-tabs {
    overflow-x: auto;
    flex-wrap: nowrap !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    width: 100%;
  }
  .filter-tabs::-webkit-scrollbar { display: none; }
  .f-tab { font-size: 9px !important; padding: 4px 10px !important; white-space: nowrap; }
  .f-sel { font-size: 10px !important; padding: 6px 8px !important; height: 32px !important; }
  .f-right, .filter-right { display: none !important; }
  .search-wrap { max-width: 100% !important; width: 100% !important; }
  .sp-note { display: none !important; }

  /* ── OBRIGAÇÕES TABELA MOBILE ─────────────────────────────── */

  .ob-table { overflow: hidden; }
  .month-block { border-radius: 8px !important; margin-bottom: 10px !important; }
  .month-hd { padding: 10px 12px !important; flex-wrap: wrap; gap: 6px; }
  .month-title { font-size: 11px !important; }
  .ob-table th { font-size: 8px !important; padding: 6px 10px !important; }
  .ob-table td { padding: 8px 10px !important; }
  .ob-table th:nth-child(4),
  .ob-table td:nth-child(4),
  .ob-table th:nth-child(6),
  .ob-table td:nth-child(6) { display: none !important; }

  /* ── CHAT / MENSAGENS ─────────────────────────────────────── */

  .chat-wrap { flex-direction: column !important; }

  /* Lista de conversas: painel deslizante (esconde em mobile por defeito) */
  .conv-list {
    width: 100% !important;
    min-width: 100% !important;
    height: 100% !important;
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 10;
    transform: translateX(-100%);
    transition: transform .25s ease;
  }
  .conv-list.open {
    transform: translateX(0);
  }

  /* Chat area ocupa tudo */
  .chat-area {
    width: 100% !important;
    min-width: 100% !important;
  }

  /* Botão para abrir lista de conversas */
  .btn-back-convs {
    display: flex !important;
  }

  /* Mensagens */
  .msg-in, .msg-out { max-width: 88% !important; }
  .msgs { padding: 12px 14px !important; }
  .chat-input { padding: 10px 14px !important; }
  .chat-hd { padding: 10px 14px !important; }
  .chat-hd-name { font-size: 12px !important; }
  .ctx-badges { display: none !important; }

  /* ── UPLOAD ZONE ──────────────────────────────────────────── */

  .upload-zone {
    padding: 20px 14px !important;
    border-radius: 8px !important;
  }
  .upload-icon { width: 40px !important; height: 40px !important; }
  .upload-title { font-size: 12px !important; }
  .upload-sub { font-size: 10px !important; }

  /* ── DOCS / CHECKLIST ─────────────────────────────────────── */

  .cl-card { border-radius: 8px !important; }
  .cl-row { padding: 8px 12px !important; }
  .cl-nm { font-size: 10px !important; }

  /* ── FACTURAS PORTAL ──────────────────────────────────────── */

  .fact-table .ft-head { display: none !important; }
  .fact-table .ft-row {
    display: flex !important;
    flex-direction: column !important;
    gap: 5px !important;
    padding: 12px !important;
  }
  .ft-num { font-size: 12px !important; }
  .fact-actions { justify-content: flex-start !important; margin-top: 4px !important; }

  /* ── CONSULTOR CARD ───────────────────────────────────────── */

  .consultor-card, .cons { padding: 12px !important; margin-bottom: 10px !important; }
  .cons-nm, .cons-name { font-size: 12px !important; }

  /* ── MODAL RESPONSIVO ─────────────────────────────────────── */

  .modal-card {
    width: 100% !important;
    max-width: 100% !important;
    border-radius: 16px 16px 0 0 !important;
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    max-height: 90dvh !important;
    overflow-y: auto !important;
  }
  .modal-ov {
    align-items: flex-end !important;
    padding: 0 !important;
  }
  .modal-acts { flex-direction: column-reverse !important; }
  .modal-acts button { width: 100% !important; }

  /* ── PIPELINE KANBAN ──────────────────────────────────────── */

  .pipeline {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 8px !important;
  }
  .pipe-col { border-radius: 8px !important; }
  .pipe-hd { padding: 8px 10px !important; }
  .pipe-hd h3 { font-size: 10px !important; }
  .pipe-card { padding: 7px 8px !important; }
  .pc-emp { font-size: 9px !important; }
  .pc-file { font-size: 8px !important; }

  /* ── TOPBAR BOTÕES ────────────────────────────────────────── */

  .btn-criar, .btn-emitir, .btn-broadcast {
    font-size: 9px !important;
    padding: 5px 10px !important;
    gap: 4px !important;
  }
  .btn-criar span, .btn-emitir span { display: none; }

  /* ── ADMIN DASHBOARD ──────────────────────────────────────── */

  .sb-admin-tag { display: none !important; }

  /* ── TABELA CLIENTES ADMIN → CARDS ────────────────────────── */

  .cl-table-wrap .cl-table thead { display: none !important; }
  .cl-table-wrap .cl-table tbody tr {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 6px !important;
    padding: 12px 14px !important;
    border-bottom: 1px solid #F1F5F9;
    align-items: center !important;
  }
  .cl-table-wrap .cl-table tbody tr td:nth-child(3),
  .cl-table-wrap .cl-table tbody tr td:nth-child(4) {
    display: none !important;
  }

  /* ── MISC ─────────────────────────────────────────────────── */

  .empty-state { padding: 30px 14px !important; }
  .empty-state i { font-size: 32px !important; }

  /* Score bar portal cliente */
  .score-bar.adm {
    flex-wrap: wrap !important;
    gap: 10px !important;
  }

}

/* ═══════════════════════════════════════════════════════════════
   MOBILE NAV — escondido em desktop, visível em mobile
   ═══════════════════════════════════════════════════════════════ */

.mobile-nav { display: none; }

@media (max-width: 640px) {
  .mobile-nav { display: flex; }
  .btn-back-convs { display: flex; }
}

/* Botão de voltar às conversas (chat mobile) */
.btn-back-convs {
  display: none;
  align-items: center;
  gap: 6px;
  font-family: 'Century Gothic', sans-serif;
  font-size: 11px;
  font-weight: 700;
  color: #1EA7E1;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  flex-shrink: 0;
}
.btn-back-convs i { font-size: 16px; }
.btn-back-convs:hover { background: rgba(30,167,225,0.08); }
