/* ══ GESTÃO TEVA — Celular ═══════════════════════════════════════════
   Carregado POR ÚLTIMO em todas as telas, depois dos <style> da página.
   Tudo aqui fica dentro de @media (max-width: 720px): no computador nada
   muda. Regra geral: nada de 7 colunas espremidas, nada de texto quebrando
   letra por letra, barras de botões e abas rolam de lado em vez de empilhar.
   ════════════════════════════════════════════════════════════════════ */

@media (max-width: 720px) {

  /* ── Base ───────────────────────────────────────────────────────── */
  html, body { overflow-x: hidden; }
  .page-content { padding: 12px 12px 28px; }

  /* Topo fixo: título à esquerda com reticências; botões secundários só
     com ícone (o texto está no title=), o principal mantém o nome. */
  .topbar {
    position: sticky; top: 0; z-index: 50;
    height: 54px; padding: 0 10px 0 6px; gap: 6px;
    padding-top: env(safe-area-inset-top);
  }
  .hamburger-btn { width: 40px; height: 40px; flex: none; }
  .topbar-title {
    flex: 1 1 auto; min-width: 0; text-align: left; font-size: 15px; font-weight: 800;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .topbar-actions { flex: none; display: flex; gap: 6px; align-items: center; }
  .topbar-actions .btn {
    height: 36px; padding: 0 12px; font-size: 12.5px; white-space: nowrap; border-radius: 10px;
  }
  .topbar-actions .btn-outline,
  .topbar-actions .btn-ghost {
    width: 36px; padding: 0; font-size: 0; gap: 0; justify-content: center;
  }
  .topbar-actions .btn svg { width: 17px; height: 17px; }

  /* Cabeçalho de página (título + descrição) mais enxuto */
  .page-header { margin-bottom: 14px; }
  .page-header h1, .page-title { font-size: 22px; }
  .page-header p, .page-subtitle { font-size: 12.5px; }

  /* Abas: uma linha só, rolando de lado */
  .tabs {
    flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; gap: 0;
    margin: 0 -12px 16px; padding: 0 12px;
    scrollbar-width: none; -webkit-overflow-scrolling: touch;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab-btn { flex: none; white-space: nowrap; padding: 11px 13px; font-size: 13px; }

  /* Tabela larga: rola dentro do card, não empurra a página */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Modais: folha que sobe de baixo, ocupando a largura */
  .modal-bg, .modal-overlay { align-items: flex-end; padding: 0; }
  .modal-bg .modal, .modal-overlay .modal {
    width: 100%; max-width: 100%; max-height: 92vh; margin: 0;
    border-radius: 16px 16px 0 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .modal-footer { position: sticky; bottom: 0; background: var(--white); z-index: 2; }
  .modal-footer .btn { flex: 1 1 auto; justify-content: center; }

  /* Campos com 16px: o iPhone não dá zoom ao tocar */
  :where(input[type=text], input[type=search], input[type=number], input[type=date],
  input[type=email], input[type=tel], input:not([type]), select, textarea):not(.xls *) { font-size: 16px; }

  /* ══ DASHBOARD ══════════════════════════════════════════════════ */

  .today-header { padding: 14px 16px; gap: 12px; align-items: center; margin-bottom: 12px; }
  .today-date { font-size: 17px; }
  .today-greeting { font-size: 12px; }
  #statObrasAtivas { font-size: 28px !important; }

  /* KPIs: faixa que rola de lado — os cinco números cabem num gesto, sem
     ocupar meia tela empilhados. */
  .kpi-row {
    display: flex; gap: 8px; overflow-x: auto; scroll-snap-type: x mandatory;
    margin: 0 -12px 14px; padding: 2px 12px 6px; scroll-padding: 0 12px;
    scrollbar-width: none; -webkit-overflow-scrolling: touch;
  }
  .kpi-row::-webkit-scrollbar { display: none; }
  .kpi-row > .kpi {
    flex: 0 0 auto; width: 46%; min-width: 150px; scroll-snap-align: start;
    padding: 11px 12px;
  }
  .kpi:hover { transform: none; }
  .kpi-label { font-size: 9.5px; margin-bottom: 4px; }
  .kpi-value { font-size: 17px; white-space: nowrap; }
  .kpi-sub { font-size: 10px; line-height: 1.35; }

  /* Agenda: toolbar em duas linhas organizadas */
  .ag-toolbar { padding: 12px 12px 10px; gap: 10px; }
  .ag-tb-left { width: 100%; justify-content: space-between; }
  .ag-tb-left h3 { font-size: 16px; }
  .ag-tb-right { width: 100%; gap: 6px; flex-wrap: wrap; }
  .ag-tb-right .ag-view-toggle { order: 0; }
  .ag-view-toggle button { padding: 7px 10px; }
  .ag-icon-btn { width: 36px; height: 36px; }
  .ag-text-btn { height: 36px; }
  .ag-tb-right .btn-primary { margin-left: auto; height: 36px; }

  /* Semana no celular (agenda.js › semanaCelular): um dia por bloco */
  .ag-mweek { display: flex; flex-direction: column; }
  .ag-mday { border-top: 1px solid var(--border); padding: 10px 12px 12px; }
  .ag-mday:first-child { border-top: none; }
  .ag-mday.is-today { background: #f3faf6; box-shadow: inset 3px 0 0 var(--accent-dark); }
  .ag-mday.is-past:not(.is-today) .ag-mday-num { color: var(--text-gray); }
  .ag-mday.is-vazio { padding-top: 8px; padding-bottom: 8px; }
  .ag-mday-head { display: flex; align-items: center; gap: 12px; }
  .ag-mday-data {
    flex: none; width: 40px; display: flex; flex-direction: column; align-items: center; line-height: 1;
  }
  .ag-mday-dow { font-size: 10px; font-weight: 800; letter-spacing: .06em; color: var(--text-gray); }
  .ag-mday-num { font-size: 20px; font-weight: 800; color: var(--text-dark); margin-top: 3px; }
  .ag-mday.is-today .ag-mday-num,
  .ag-mday.is-today .ag-mday-dow { color: var(--accent-dark); }
  .ag-mday-info { flex: 1; min-width: 0; font-size: 12.5px; color: var(--text-gray); font-weight: 600; }
  .ag-mday-info b { color: var(--accent-dark); font-weight: 800; }
  .ag-mday.is-vazio .ag-mday-info { font-weight: 500; opacity: .75; }
  .ag-mday-add {
    flex: none; width: 34px; height: 34px; border-radius: 10px; cursor: pointer;
    border: 1px dashed var(--border); background: var(--white); color: var(--text-gray);
    font-size: 18px; line-height: 1; font-family: inherit;
  }
  .ag-mday-body { display: flex; flex-direction: column; gap: 8px; margin: 10px 0 0; }
  .ag-mday .ag-col-pag {
    margin: 8px 0 0; padding: 0; border-top: none; min-height: 0;
    display: flex; flex-wrap: wrap; gap: 6px; text-align: left;
  }
  .ag-mday .ag-pag { margin: 0; font-size: 11.5px; padding: 3px 8px; border-radius: 20px; }
  .ag-mday .ag-pag-prev { margin: 0; align-self: center; font-size: 11px; }

  /* Card de empresa em largura cheia: letra de leitura, não de rodapé */
  .ag-mday .ag-gcard { padding: 9px 10px 8px; font-size: 13px; border-radius: 10px; }
  .ag-mday .ag-gcard-nome { font-size: 13.5px; }
  .ag-mday .ag-gcard-cont { font-size: 11px; padding: 1px 7px; }
  .ag-mday .ag-gcard-sub { font-size: 11px; gap: 6px; margin-top: 3px; }
  .ag-mday .ag-gcard-itens { gap: 4px; margin-top: 7px; }
  .ag-mday .ag-gitem { font-size: 13px; }

  /* Mês: células menores, sem valores cortados */
  .ag-month { font-size: 11px; }

  /* Clima: cinco dias rolando de lado se não couberem */
  .clima-card { padding: 12px; }
  .clima-now-temp { font-size: 26px; }
  .clima-dias { gap: 6px; }
  .clima-dia { padding: 9px 3px; }
  .clima-dia-icon svg { width: 20px; height: 20px; }
  .clima-dia-temp { font-size: 12px; }
}

@media (max-width: 380px) {
  .kpi-row > .kpi { width: 58%; }
  .topbar-actions .btn-primary { padding: 0 10px; font-size: 12px; }
}

/* ── Dashboard › Checklists por fornecedor: cards recolhidos ───────── */
@media (max-width: 720px) {
  .ckf-grid, #ckFxGrid { grid-template-columns: 1fr !important; gap: 8px !important; }
  .ckf-head { position: relative; cursor: pointer; padding: 12px 88px 11px 14px; -webkit-user-select: none; user-select: none; }
  .ckf-head::after {
    content: ''; position: absolute; right: 14px; top: 50%; width: 8px; height: 8px; margin-top: -6px;
    border-right: 2px solid var(--text-gray); border-bottom: 2px solid var(--text-gray);
    transform: rotate(45deg); transition: transform .15s;
  }
  .ckf-card:not(.fechado) .ckf-head::after { transform: rotate(-135deg); margin-top: -2px; }
  .ckf-card.fechado .ckf-head { border-bottom: none; }
  .ckf-card.fechado .ckf-itens,
  .ckf-card.fechado .ckf-feitas,
  .ckf-card.fechado .ckf-add { display: none; }
  .ckf-resumo {
    display: flex; flex-direction: column; align-items: flex-end; gap: 2px;
    position: absolute; right: 34px; top: 50%; transform: translateY(-50%);
    font-size: 17px; font-weight: 800; color: var(--text-dark); line-height: 1;
  }
  .ckf-resumo small { font-size: 10.5px; font-weight: 700; color: var(--text-gray); }
  .ckf-resumo small.late { color: #b91c1c; }
  .ckf-nome { font-size: 14px; }
  .ckf-add { flex-wrap: nowrap; }
  .ckf-add input[type=text] { flex: 1 1 auto; }
  .ckf-add input[type=date] { flex: 0 0 132px; }
}

/* ══ OBRAS / FINANCEIRO / FORNECEDORES ══════════════════════════════ */
@media (max-width: 720px) {

  /* Cards de obra (dashboard e lista): faixa de cor fina em vez de capa */
  .obra-card-cover { height: 8px; }
  .obras-grid { grid-template-columns: 1fr; gap: 10px; }

  /* Kanban de obras: coluna vazia não ocupa meia tela */
  .kanban { gap: 10px; }
  .kanban-col { min-height: 0; padding: 10px; gap: 8px; }
  .kanban-empty { padding: 6px 8px; font-size: 11px; }

  /* Faixa escura do topo (Financeiro e Obra): números em grade 2×2 */
  .caixa-hero { padding: 14px 16px; gap: 10px; }
  .caixa-hero .ch-value { font-size: 26px; }
  .caixa-hero .ch-side { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 0; }
  .caixa-hero .ch-side-item { padding: 0 10px; }
  .caixa-hero .ch-side-item:nth-child(odd) { border-left: none; padding-left: 0; }

  /* Cabeçalho de card com botões: quebra em duas linhas alinhadas */
  .gx-card-header { flex-wrap: wrap; gap: 8px; padding: 12px 14px; }
  .gx-card-header h3 { font-size: 14px; }
  .gx-card-body { padding: 12px; }
  #payCalTitle { min-width: 0 !important; font-size: 13px !important; }

  /* Calendário de pagamentos: só o número do dia e o total (cor = situação).
     Um toque no dia abre a lista completa (openDayPayments). */
  .paycal-grid { gap: 3px; }
  .paycal-dow { font-size: 9.5px; padding: 4px 0; letter-spacing: 0; }
  .paycal-day { height: 50px; min-height: 0; padding: 3px 2px; align-items: center; cursor: pointer; }
  .paycal-day .pcd-num { font-size: 12px; padding: 2px 0 0; align-self: center; }
  .paycal-day .pcd-num span { display: none; }
  .paycal-day .paycal-cards, .paycal-day .paycal-add { display: none !important; }
  .paycal-day.has-pay { background: var(--bg-light); }
  .pcd-tot {
    display: block; margin-top: auto; font-size: 10.5px; font-weight: 800; line-height: 1;
    padding: 3px 4px; border-radius: 5px; font-variant-numeric: tabular-nums; white-space: nowrap;
  }
  .pcd-tot.pago    { color: #15803d; background: #dcfce7; }
  .pcd-tot.apagar  { color: #92400e; background: #fef3c7; }
  .pcd-tot.vencido { color: #b91c1c; background: #fee2e2; }

  /* Planilhas (Fornecedores, Financeiro): rola de lado, linha baixa */
  .xls-toolbar { flex-direction: column; align-items: stretch; gap: 10px; padding: 12px; }
  .xls-toolbar .filters, .xls-toolbar .filters input { width: 100%; }
  .xls-toolbar > div:last-child {
    flex-wrap: nowrap !important; overflow-x: auto; scrollbar-width: none; gap: 6px !important;
  }
  .xls-toolbar > div:last-child::-webkit-scrollbar { display: none; }
  .xls-toolbar .btn-ghost, .xls-toolbar .btn { flex: none; white-space: nowrap; padding: 8px 11px; }
  .xls-toolbar .btn-primary { order: -1; }
  .xls-wrap { max-height: 70vh; border-radius: 0; border-left: none; border-right: none; }
  .xls { width: max-content; min-width: 100%; }
}

/* ══ OBRA (plataforma da obra) ═════════════════════════════════════ */
@media (max-width: 720px) {
  .obra-header { padding: 16px; gap: 14px; margin-bottom: 14px; }
  .obra-header > div:first-child { width: 100%; }
  .obra-header h1 { font-size: 21px; }
  .obra-header .oh-cliente { font-size: 12.5px; }
  .obra-header .oh-stats { width: 100%; display: grid; grid-template-columns: 1.25fr 1.25fr .7fr; gap: 8px; }
  .obra-header .oh-stat-value { font-size: 15px; white-space: nowrap; }
  .obra-header .oh-cad { grid-template-columns: 1fr 1fr; gap: 12px 14px; margin-top: 0; padding-top: 14px; }
  .obra-header .oh-cad-clima { grid-column: 1 / -1; }
  .obra-header .oh-cad-val { font-size: 12.5px; }
}

/* ══ DIÁRIO / MODAIS DA AGENDA ═════════════════════════════════════ */
@media (max-width: 720px) {
  .dgaleria { grid-template-columns: 1fr 1fr; gap: 10px; }
  /* Registro sem foto: faixa baixa com o ícone, não um quadro vazio de 4:3 */
  .dcard-capa:has(.dcard-sem-foto) { aspect-ratio: auto; height: 52px; }
  .dcard-sem-foto svg.lucide { width: 24px; height: 24px; }
  .dcard-body { padding: 10px 11px 11px; }

  /* Formulário de ação: Responsável em cima, Prioridade e Status lado a lado */
  .ag-form-row3.eq { grid-template-columns: 1fr 1fr !important; }
  .ag-form-row3.eq > .field:first-child { grid-column: 1 / -1; }
}
