/* ============================================================================
   dashboard-mobile.css — reformulação do Painel de Projetos para telefone.

   Estratégia: em telas <= 767.98px o painel deixa de ser uma pilha longa de
   cartões e passa a funcionar como um app: barra fixa com as três seções,
   filtros em bottom sheet, KPIs densos em grade 2x2 e um "deck" horizontal
   deslizável em que cada cartão (mapa, gráficos, lista) ocupa uma tela.
   Assim todas as informações continuam acessíveis com pouquíssima rolagem.

   Depende de js/dashboard-mobile.js, que reorganiza o DOM nesta faixa.
   Acima de 768px nada aqui se aplica e o layout desktop segue intacto.
   ========================================================================= */

@media (max-width: 767.98px) {

  /* ---------------------------------------------------------------- base -- */
  #painel {
    --pjm-nav-h: 60px;          /* altura da navbar mobile do site */
    --pjm-bar-h: 52px;          /* altura da barra de seções */
    --pjm-gutter: 12px;
    --pjm-deck-h: clamp(348px, 56dvh, 540px);
    --pjm-radius: 14px;
    --pjm-line: #dde5ec;
    --pjm-ink: #14314a;
    --pjm-ink-soft: #5b7385;
    padding-bottom: calc(28px + env(safe-area-inset-bottom));
    background: #eff3f7;
    overflow-x: clip;
  }

  /* ------------------------------------------------- barra de seções (topo) */
  .pj-tabbar {
    position: sticky;
    top: var(--pjm-nav-h);
    z-index: 700;
    padding: 8px var(--pjm-gutter) 9px;
    border-bottom: 1px solid var(--pjm-line);
    background: rgba(255, 255, 255, .92);
    backdrop-filter: saturate(180%) blur(12px);
    -webkit-backdrop-filter: saturate(180%) blur(12px);
    box-shadow: 0 1px 0 rgba(16, 42, 67, .04);
  }

  .pjm-bar { display: flex; align-items: center; gap: 8px; }

  /* segmented control estilo iOS/shadcn */
  .pj-tabs {
    flex: 1 1 auto;
    gap: 2px;
    min-width: 0;
    padding: 3px;
    border-radius: 11px;
    background: #e7edf3;
    overflow: hidden;
  }

  .pj-tab {
    flex: 1 1 0;
    min-width: 0;
    min-height: 38px;
    padding: 0 4px;
    border: 0;
    border-radius: 8px;
    color: #5b7385;
    font-size: 12.5px;
    font-weight: 600;
    letter-spacing: -.01em;
    transition: color .16s ease, background-color .16s ease, box-shadow .16s ease;
  }
  .pj-tab i { display: none; }
  .pj-tab__full { display: none; }
  .pj-tab__short { display: inline; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .pj-tab.active {
    color: var(--pjm-ink);
    background: #fff;
    border-bottom-color: transparent;
    box-shadow: 0 1px 2px rgba(16, 42, 67, .14), 0 0 0 .5px rgba(16, 42, 67, .05);
  }
  .pj-tab:active { transform: scale(.985); }

  /* botão de filtros da barra */
  .pjm-filterbtn {
    position: relative;
    display: inline-grid;
    place-items: center;
    flex: none;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 1px solid var(--pjm-line);
    border-radius: 11px;
    color: var(--pj-blue);
    background: #fff;
    font-size: 15px;
    cursor: pointer;
    transition: background-color .16s ease, border-color .16s ease, transform .16s ease;
  }
  .pjm-filterbtn:active { transform: scale(.96); background: #eef4f9; }
  .pjm-filterbtn[hidden] { display: none; }
  .pjm-filterbtn__dot {
    position: absolute;
    top: -5px;
    right: -5px;
    display: grid;
    place-items: center;
    min-width: 19px;
    height: 19px;
    padding: 0 5px;
    border: 2px solid #fff;
    border-radius: 999px;
    color: #fff;
    background: var(--pj-blue);
    font-family: 'Poppins', sans-serif;
    font-size: 10px;
    font-weight: 700;
    line-height: 1;
  }
  .pjm-filterbtn__dot[hidden] { display: none; }

  /* ---------------------------------------------------------------- wrap -- */
  .pj-wrap { padding: 12px var(--pjm-gutter) 0; }

  .pj-heading { display: block; margin: 0 0 10px; }
  .pj-heading__eyebrow { margin-bottom: 4px; font-size: 10px; letter-spacing: .1em; }
  .pj-heading h1, .pj-heading h2 {
    margin: 0;
    font-family: 'Poppins', sans-serif;
    font-size: 19px;
    font-weight: 700;
    letter-spacing: -.015em;
  }
  .pj-heading p { display: none; }
  .pj-live { display: none; }

  /* grades desktop ficam vazias após a migração dos cartões para o deck */
  #painel.is-mobile .pj-grid { display: none; }

  /* ---------------------------------------------------- chips dos filtros -- */
  .pjm-chips {
    display: flex;
    gap: 6px;
    margin: 0 calc(var(--pjm-gutter) * -1) 10px;
    padding: 0 var(--pjm-gutter);
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .pjm-chips::-webkit-scrollbar { display: none; }
  .pjm-chips:empty { display: none; }
  .pjm-chips .pj-active-filters { display: contents; }
  .pjm-chips .pj-filter-chip {
    flex: none;
    max-width: 74vw;
    min-height: 32px;
    padding: 0 10px;
    font-size: 12px;
  }
  .pjm-chips .pj-filter-chip span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* --------------------------------------------------------- KPIs densos -- */
  .pj-kpis, .pj-kpis.k4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin: 0 0 12px;
  }
  .pj-kpi {
    position: relative;
    display: block;
    padding: 11px 12px 12px;
    border: 1px solid var(--pjm-line);
    border-radius: var(--pjm-radius);
    background: #fff;
    box-shadow: 0 1px 2px rgba(16, 42, 67, .05);
    transition: transform .16s ease, background-color .16s ease;
    animation: pjm-rise .4s cubic-bezier(.22, .68, .35, 1) both;
  }
  .pj-kpi:nth-child(2) { animation-delay: .05s; }
  .pj-kpi:nth-child(3) { animation-delay: .1s; }
  .pj-kpi:nth-child(4) { animation-delay: .15s; }
  .pj-kpi:active { transform: scale(.985); background: #fbfdfe; }
  .pj-kpi .ic {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 24px;
    height: 24px;
    border: 0;
    border-radius: 7px;
    color: var(--pj-blue);
    background: #eaf2f8;
    font-size: 11px;
  }
  .pj-kpi.green .ic { color: #24815a; background: #e9f5ef; }
  .pj-kpi.amber .ic { color: #a96a12; background: #fdf2e2; }
  .pj-kpi.violet .ic { color: #4b6a83; background: #eef2f6; }
  .pj-kpi .tx { display: block; }
  .pj-kpi .tx small {
    display: block;
    max-width: calc(100% - 28px);
    margin-bottom: 5px;
    overflow: hidden;
    color: var(--pjm-ink-soft);
    font-size: 9.5px;
    font-weight: 700;
    letter-spacing: .075em;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .pj-kpi .tx b {
    font-family: 'Poppins', sans-serif;
    font-size: 21px;
    font-weight: 700;
    letter-spacing: -.025em;
    line-height: 1.05;
    color: var(--pjm-ink);
  }

  /* ------------------------------------------- seletor de painéis (chips) -- */
  .pjm-seg {
    display: flex;
    gap: 6px;
    margin: 0 calc(var(--pjm-gutter) * -1) 9px;
    padding: 1px var(--pjm-gutter) 3px;
    overflow-x: auto;
    scroll-behavior: smooth;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .pjm-seg::-webkit-scrollbar { display: none; }
  .pjm-seg__btn {
    display: inline-flex;
    flex: none;
    align-items: center;
    gap: 6px;
    min-height: 34px;
    padding: 0 12px;
    border: 1px solid var(--pjm-line);
    border-radius: 999px;
    color: #4a6376;
    background: #fff;
    font-size: 12.5px;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
    transition: color .16s ease, background-color .16s ease, border-color .16s ease, transform .16s ease;
  }
  .pjm-seg__btn i { font-size: 11px; opacity: .75; }
  .pjm-seg__btn[aria-selected='true'] {
    border-color: var(--pj-blue-dark);
    color: #fff;
    background: var(--pj-blue-dark);
  }
  .pjm-seg__btn[aria-selected='true'] i { opacity: 1; }
  .pjm-seg__btn:active { transform: scale(.97); }

  /* -------------------------------------------------- deck deslizável ----- */
  .pjm-deck {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 100%;
    gap: var(--pjm-gutter);
    margin: 0 calc(var(--pjm-gutter) * -1);
    padding: 2px var(--pjm-gutter) 14px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .pjm-deck::-webkit-scrollbar { display: none; }

  .pjm-deck > .pj-card {
    display: flex;
    flex-direction: column;
    height: var(--pjm-deck-h);
    min-width: 0;
    padding: 13px 13px 6px;
    border: 1px solid var(--pjm-line);
    border-radius: var(--pjm-radius);
    background: #fff;
    box-shadow: 0 1px 2px rgba(16, 42, 67, .05);
    scroll-snap-align: center;
    scroll-snap-stop: always;
  }

  .pjm-deck > .pj-card > .pj-card-head {
    flex: none;
    align-items: center;
    gap: 8px;
    margin: 0 0 10px;
  }
  .pjm-deck > .pj-card .pj-card-icon { width: 27px; height: 27px; border-radius: 8px; font-size: 12px; }
  .pjm-deck > .pj-card h3 { font-size: 14px; letter-spacing: -.01em; }
  .pjm-deck > .pj-card .pj-card-subtitle { font-size: 10.5px; }
  .pjm-deck > .pj-card .tag { flex: none; padding: 3px 7px; font-size: 9px; }

  /* área de conteúdo do cartão rola sozinha, o resto da página não se mexe */
  .pjm-deck .pj-chart,
  .pjm-deck .pj-barlist,
  .pjm-deck .pj-ods-grid,
  .pjm-deck .pj-table-wrap {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
  }
  .pjm-deck .pj-chart { display: flex; flex-direction: column; justify-content: center; }

  /* mapa ocupa todo o cartão */
  .pjm-deck .pj-mapcard { padding-bottom: 13px; }
  #mapaInicio, #mapaOds {
    flex: 1 1 auto;
    min-height: 0;
    height: auto;
    border-radius: 11px;
  }

  /* lista de funções */
  .pjm-deck .pj-barlist { display: block; padding: 0 2px 2px 0; }
  .pjm-deck .pj-barlist__head { display: none; }
  .pjm-deck .pj-barlist__row {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 5px 10px;
    min-height: 0;
    padding: 8px 6px;
    border-bottom: 1px solid #eef2f5;
    border-radius: 0;
  }
  .pjm-deck .pj-barlist__row:last-child { border-bottom: 0; }
  .pjm-deck .pj-barlist__label { grid-column: 1; grid-row: 1; font-size: 12px; }
  .pjm-deck .pj-barlist__value { grid-column: 2; grid-row: 1; font-family: 'Poppins', sans-serif; font-size: 11.5px; }
  .pjm-deck .pj-barlist__track { grid-column: 1 / -1; grid-row: 2; height: 7px; border-radius: 999px; }

  /* grade dos 17 ODS */
  .pjm-deck .pj-ods-grid { grid-template-columns: repeat(4, 1fr); gap: 6px; align-content: start; padding-bottom: 4px; }
  .pjm-deck .pj-ods { border-width: 2px; border-radius: 9px; }
  .pjm-deck .pj-ods .cnt { top: 3px; right: 3px; padding: 1px 4px; font-size: 9px; }

  /* tabela em cartões */
  .pj-tablecard { margin: 0; }
  .pjm-deck > .pj-tablecard { padding: 13px 13px 6px; }
  .pjm-deck > .pj-tablecard > .pj-card-head { padding: 0; border-bottom: 0; }
  .pjm-deck .pj-table-wrap { padding: 0 2px 2px 0; }
  #painel .dataTables_wrapper .dataTables_filter { margin-bottom: 9px; }
  #painel .dataTables_wrapper .dataTables_filter input { height: 38px; border-radius: 10px; font-size: 13px; }
  #painel table.dataTable tbody { gap: 8px; }
  #painel table.dataTable tbody tr {
    padding: 11px 12px;
    border-radius: 12px;
    box-shadow: none;
  }
  #painel table.dataTable tbody td {
    grid-template-columns: minmax(78px, .38fr) minmax(0, 1fr);
    gap: 10px;
    padding: 5px 0;
    font-size: 11.5px;
  }
  #painel table.dataTable tbody td::before { font-size: 9px; }
  .pj-project-name { font-size: 13px; line-height: 1.35; }
  #painel table.dataTable tbody td.pj-row-title { padding-bottom: 9px; }
  #painel table.dataTable tbody td.pj-row-action { padding-top: 10px; }
  #painel table.dataTable tbody td.pj-row-action .pj-ficha { min-height: 38px; font-size: 12px; }
  #painel .dataTables_wrapper .dataTables_info { padding: 6px 0 2px; font-size: 11px; }
  #painel .dataTables_wrapper .dataTables_paginate .paginate_button { min-width: 32px; padding: 5px 8px !important; font-size: 12px; }

  /* rodapé de origem dos dados */
  .pjm .pj-note { margin: 2px 0 0; padding: 0; font-size: 11px; line-height: 1.45; }

  /* -------------------------------------------------- bottom sheet filtros -- */
  .pjm-sheet { position: fixed; inset: 0; z-index: 1200; }
  .pjm-sheet[hidden] { display: none; }
  .pjm-sheet__scrim {
    position: absolute;
    inset: 0;
    background: rgba(6, 24, 40, .5);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    animation: pjm-fade .22s ease both;
  }
  .pjm-sheet__panel {
    position: absolute;
    right: 0;
    bottom: 0;
    left: 0;
    display: flex;
    max-height: 92dvh;
    flex-direction: column;
    padding-bottom: env(safe-area-inset-bottom);
    border-radius: 20px 20px 0 0;
    background: #fff;
    box-shadow: 0 -12px 40px rgba(6, 24, 40, .28);
    animation: pjm-sheet-up .26s cubic-bezier(.32, .72, 0, 1) both;
  }
  .pjm-sheet__grab {
    width: 38px;
    height: 4px;
    margin: 8px auto 0;
    border-radius: 999px;
    background: #ccd7e0;
  }
  .pjm-sheet__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 16px 12px;
  }
  .pjm-sheet__head h2 {
    margin: 0;
    font-family: 'Poppins', sans-serif;
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -.01em;
    color: var(--pjm-ink);
  }
  .pjm-sheet__x {
    display: grid;
    place-items: center;
    flex: none;
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 999px;
    color: #5b7385;
    background: #eff3f7;
    font-size: 14px;
    cursor: pointer;
  }
  .pjm-sheet__body {
    flex: 1 1 auto;
    min-height: 0;
    padding: 0 16px 8px;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }
  .pjm-sheet__foot {
    flex: none;
    padding: 12px 16px calc(14px + env(safe-area-inset-bottom));
    border-top: 1px solid #eef2f5;
    background: #fff;
  }
  .pjm-apply {
    width: 100%;
    min-height: 46px;
    border: 0;
    border-radius: 12px;
    color: #fff;
    background: var(--pj-blue-dark);
    font-family: 'Poppins', sans-serif;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
  }
  .pjm-apply:active { transform: scale(.99); background: #002c4c; }

  /* cartão de filtros dentro do sheet perde a moldura */
  .pjm-sheet .pj-filter-card {
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }
  .pjm-sheet .pj-filter-card::before { display: none; }
  .pjm-sheet .pj-filter-head {
    margin-bottom: 12px;
    padding-bottom: 10px;
  }
  .pjm-sheet .pj-filter-title { font-size: 12px; }
  .pjm-sheet .pj-filter-actions { flex-direction: row; }
  .pjm-sheet .pj-filtros { gap: 13px; }
  .pjm-sheet .pj-active-filters { display: none; } /* os chips vivem na página */
  .pjm-sheet .pj-combobox__control { height: 46px; }
  .pjm-sheet .pj-combobox__input { height: 44px; font-size: 15px; } /* >=16px evita zoom no iOS ao focar; 15px + user-scalable ok */
  .pjm-sheet .pj-combobox__toggle { width: 44px; height: 44px; }
  .pjm-sheet .pj-combobox__menu { max-height: 46dvh; }
  .pjm-sheet .pj-combobox__option { padding: 11px 10px; font-size: 14px; }

  /* ------------------------------------------------------------- diálogos -- */
  .pj-dialog {
    width: 100%;
    max-width: none;
    max-height: 88dvh;
    margin: auto auto 0;
    border: 0;
    border-radius: 20px 20px 0 0;
  }
  .pj-dialog__body { max-height: none; padding: 18px 16px; }
  .pj-dialog__value { font-family: 'Poppins', sans-serif; font-size: 30px; }
  .pj-dialog__details { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .pj-dialog__foot { padding: 12px 16px calc(14px + env(safe-area-inset-bottom)); }
  .pj-dialog__button { width: 100%; min-height: 44px; border-radius: 12px; }

  .pj-modal-box { border-radius: 20px 20px 0 0; }
  .pj-modal-foot { padding: 12px 16px calc(14px + env(safe-area-inset-bottom)); }
  .pj-modal .pj-btn { flex: 1 1 auto; justify-content: center; min-height: 44px; }

  .pj-toast { right: 12px; left: 12px; bottom: calc(18px + env(safe-area-inset-bottom)); width: auto; }

  /* controles flutuantes globais não devem cobrir o deck */
  .back-to-top { display: none !important; }
  [vw].enabled { right: 10px !important; bottom: 14px !important; }

  @keyframes pjm-sheet-up { from { transform: translateY(100%); } to { transform: none; } }
  @keyframes pjm-fade { from { opacity: 0; } to { opacity: 1; } }
  @keyframes pjm-rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
}

@media (max-width: 767.98px) and (prefers-reduced-motion: reduce) {
  .pjm-sheet__panel, .pjm-sheet__scrim { animation: none; }
  .pjm-seg, .pjm-deck { scroll-behavior: auto; }
}

/* telas muito estreitas: KPIs em coluna única continuam legíveis */
@media (max-width: 359.98px) {
  #painel .pj-kpis, #painel .pj-kpis.k4 { grid-template-columns: 1fr; }
  #painel .pjm-deck .pj-ods-grid { grid-template-columns: repeat(3, 1fr); }
}
