/* =====================================================================
   VERSÃO CELULAR do WhatStatus (telas de até 768px).
   No computador nada daqui aparece: os elementos .m-only ficam escondidos
   e todas as regras de layout estão dentro do @media abaixo.
   ===================================================================== */

.m-only { display: none !important; }
.m-date-label { display: none; }

@media (max-width: 768px) {
  :root {
    --m-nav-h: 64px;
    --m-safe-b: env(safe-area-inset-bottom, 0px);
  }

  html, body { -webkit-tap-highlight-color: transparent; }
  body { background-attachment: scroll; overscroll-behavior-y: contain; }

  /* ---------- Estrutura: sem menu lateral, rolagem natural da página ---------- */
  .app-layout { display: block; height: auto; overflow: visible; }
  .app-layout > .sidebar { display: none !important; }
  .app-container {
    max-width: none;
    padding: 0.75rem 0.85rem calc(var(--m-nav-h) + var(--m-safe-b) + 1.25rem);
    overflow: visible;
  }

  /* ---------- Barra do topo ---------- */
  #m-topbar {
    display: flex !important; flex-direction: column;
    position: sticky; top: 0; z-index: 950;
    padding: 0 0.85rem;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: saturate(180%) blur(12px);
    -webkit-backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid var(--border-light);
  }
  .m-top-row { display: flex; align-items: center; justify-content: space-between; height: 56px; }
  #m-trialbar {
    display: flex; align-items: center; gap: 0.45rem; width: 100%;
    margin: 0 0 0.55rem; padding: 0.5rem 0.75rem; border-radius: 12px;
    background: #FACC15; color: #422006; border: 1.5px solid #EAB308;
    font-size: 0.82rem; font-weight: 700; text-align: left;
    box-shadow: 0 2px 10px rgba(234, 179, 8, 0.35);
    animation: trialPulse 1.6s ease-in-out infinite;
  }
  #m-trialbar.hidden { display: none !important; }
  #m-trialbar > i { font-size: 1.1rem; flex-shrink: 0; }
  #m-trialbar .m-trial-text { flex: 1; white-space: nowrap; }
  #m-trialbar strong { font-size: 0.95rem; font-variant-numeric: tabular-nums; }
  #m-trialbar .m-trial-offer { display: inline-flex; align-items: center; gap: 0.15rem; background: #FFFFFF; color: #854D0E; border-radius: 9999px; padding: 0.2rem 0.55rem; font-size: 0.74rem; white-space: nowrap; }
  #trial-countdown-wrap { display: none !important; }
  #m-topbar .m-logo { display: block; position: relative; width: 64px; height: 44px; overflow: hidden; }
  #m-topbar .m-logo img { position: absolute; left: -8.3px; top: -13.3px; width: 80px; height: auto; max-width: none; }
  .m-top-actions { display: flex; align-items: center; gap: 0.5rem; }
  .m-chip {
    display: inline-flex; align-items: center; gap: 0.35rem;
    height: 34px; padding: 0 0.75rem; border-radius: 9999px;
    background: rgba(37, 211, 102, 0.12); border: 1px solid rgba(37, 211, 102, 0.3);
    color: #008069; font-size: 0.82rem; font-weight: 700;
  }
  .m-chip i { font-size: 1.05rem; }
  .m-chip.off { background: var(--bg-primary); border-color: var(--border-light); color: var(--text-secondary); }
  .m-avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: linear-gradient(135deg, #25D366, #128C7E); color: #FFFFFF;
    font-weight: 800; font-size: 0.95rem; display: inline-flex; align-items: center; justify-content: center;
    box-shadow: 0 2px 8px rgba(18, 140, 126, 0.3);
  }

  /* ---------- Cabeçalho da página: só o cronômetro do teste e o selo do plano ---------- */
  .app-header {
    flex-direction: column; align-items: stretch; gap: 0.5rem;
    margin-bottom: 0.75rem; padding-bottom: 0; border-bottom: none;
  }
  .app-header .header-left { display: none; }
  .app-header .header-right { gap: 0.5rem !important; justify-content: center; }
  .app-header .header-right > div:not(#header-trial-badge),
  #status-toggles-container,
  #btn-open-conexoes { display: none !important; }
  #header-trial-badge { width: 100%; justify-content: center; font-size: 0.8rem; }

  /* ---------- Painel principal: Agenda e Mídias são telas separadas ---------- */
  .dashboard-grid { display: block; }
  .dashboard-grid > .section-card { margin-bottom: 0.85rem; }
  .section-card { padding: 1rem; border-radius: 16px; }
  body[data-mview="agenda"] .media-gallery-sidebar { display: none !important; }
  body[data-mview="midias"] .calendar-section,
  body[data-mview="midias"] #m-upcoming { display: none !important; }
  #m-upcoming { display: block !important; }

  /* ---------- Calendário compacto ---------- */
  .calendar-header { margin-bottom: 0.6rem; }
  .calendar-header h2 { font-size: 1.1rem; }
  .calendar-header .btn-icon { width: 40px; height: 40px; }
  .calendar-grid-header { font-size: 0.66rem; margin-bottom: 0.3rem; letter-spacing: 0.02em; }
  .calendar-grid-days { gap: 4px; }
  .calendar-day {
    min-height: 46px; padding: 4px 2px; border-radius: 10px;
    align-items: center; justify-content: flex-start; box-shadow: none;
  }
  .calendar-day:hover { transform: none; }
  .calendar-day .day-number { font-size: 0.9rem; margin: 0; width: 100%; text-align: center; align-self: center; }
  .calendar-day .day-indicators { justify-content: center; gap: 2px; margin-top: 3px; flex-wrap: wrap; max-width: 100%; }
  .calendar-day .day-indicator { width: 6px; height: 6px; }
  .calendar-day.m-selected { border: 2px solid var(--accent-primary); background: rgba(37, 211, 102, 0.08); }
  .m-cal-hint { display: block !important; margin: 0.65rem 0 0; font-size: 0.74rem; color: var(--text-muted); text-align: center; }

  /* ---------- Próximos status ---------- */
  .m-section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.6rem; }
  .m-section-head h2 { margin: 0; font-size: 1.05rem; }
  .m-link-btn { display: inline-flex; align-items: center; gap: 0.3rem; color: #008069; font-weight: 700; font-size: 0.85rem; padding: 0.35rem 0.6rem; border-radius: 9999px; background: rgba(37, 211, 102, 0.1); }
  .m-empty { text-align: center; color: var(--text-muted); font-size: 0.85rem; padding: 1.1rem 0.5rem; }
  .m-empty .submit-btn { width: auto; margin-top: 0.75rem; padding: 0.6rem 1.1rem; }
  .m-day-group { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); margin: 0.75rem 0 0.35rem; }
  .m-day-group:first-child { margin-top: 0; }
  .m-post-row {
    display: flex; align-items: center; gap: 0.7rem; width: 100%; text-align: left;
    padding: 0.55rem; border: 1px solid var(--border-light); border-radius: 12px; background: #FFFFFF;
    margin-bottom: 0.45rem;
  }
  .m-post-row:active { background: var(--bg-primary); }
  .m-post-thumb {
    flex-shrink: 0; width: 46px; height: 46px; border-radius: 10px; overflow: hidden;
    background: var(--bg-primary); display: flex; align-items: center; justify-content: center;
    color: var(--text-muted); font-size: 1.3rem;
  }
  .m-post-thumb img, .m-post-thumb video { width: 100%; height: 100%; object-fit: cover; }
  .m-post-thumb.text { background: linear-gradient(135deg, #25D366, #128C7E); color: #FFFFFF; font-size: 1.1rem; }
  .m-post-main { flex: 1; min-width: 0; }
  .m-post-time { font-weight: 800; font-size: 0.95rem; color: var(--text-primary); }
  .m-post-text { font-size: 0.8rem; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .m-post-row .badge { flex-shrink: 0; }
  .m-post-row > i { color: var(--text-muted); flex-shrink: 0; }

  /* ---------- Mídias ---------- */
  .gallery-header { gap: 0.5rem; }
  .gallery-header h2 { font-size: 1.05rem; margin: 0; }
  .gallery-header .add-media-btn { padding: 0.55rem 0.9rem; font-weight: 700; background: rgba(37, 211, 102, 0.1); border-color: rgba(37, 211, 102, 0.35); color: #008069; }
  .media-gallery-sidebar .gallery-instructions { display: none; }
  .gallery-grid { grid-template-columns: repeat(3, 1fr) !important; max-height: none !important; overflow: visible !important; gap: 6px !important; }
  .gallery-grid > p { grid-column: 1 / -1 !important; }
  .gallery-item { cursor: pointer; }
  .gallery-item-delete { width: 26px !important; height: 26px !important; font-size: 1rem !important; opacity: 1 !important; }
  .m-gallery-tip { display: block !important; font-size: 0.76rem; color: #008069; background: rgba(37, 211, 102, 0.08); border-radius: 10px; padding: 0.5rem 0.7rem; margin: 0.6rem 0; }

  /* ---------- Barra de navegação de baixo ---------- */
  #m-bottomnav {
    display: grid !important; grid-template-columns: repeat(5, 1fr); align-items: end;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 960;
    height: calc(var(--m-nav-h) + var(--m-safe-b)); padding: 0 0.25rem var(--m-safe-b);
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: saturate(180%) blur(12px);
    -webkit-backdrop-filter: saturate(180%) blur(12px);
    border-top: 1px solid var(--border-light);
    box-shadow: 0 -4px 18px rgba(11, 20, 26, 0.06);
  }
  #m-bottomnav button {
    height: var(--m-nav-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    color: var(--text-muted); font-size: 0.68rem; font-weight: 600;
  }
  #m-bottomnav button i { font-size: 1.45rem; }
  #m-bottomnav button.active { color: #008069; }
  #m-bottomnav button.active i { font-weight: bold; }
  #m-bottomnav .m-fab { justify-content: flex-start; }
  #m-bottomnav .m-fab i {
    width: 54px; height: 54px; margin-top: -18px; border-radius: 50%;
    background: linear-gradient(135deg, #25D366, #128C7E); color: #FFFFFF; font-size: 1.6rem;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 6px 16px rgba(18, 140, 126, 0.45); border: 4px solid #FFFFFF;
  }
  #support-fab { display: none !important; }

  /* ---------- Janelas viram "folhas" que sobem de baixo ---------- */
  .modal-overlay:not(#modal-login):not(#modal-dialog):not(#modal-image-preview) { align-items: flex-end !important; padding: 0 !important; }
  .modal-overlay:not(#modal-login):not(#modal-dialog):not(#modal-image-preview) > .modal-content {
    width: 100% !important; max-width: 100% !important;
    max-height: calc(94 * var(--vh)) !important;
    border-radius: 20px 20px 0 0 !important;
    border-left: none !important; border-right: none !important; border-bottom: none !important;
    padding-bottom: var(--m-safe-b);
    animation: m-sheet-up 0.22s ease-out;
    overflow-y: auto;
  }
  .modal-overlay:not(#modal-login):not(#modal-dialog):not(#modal-image-preview) > .modal-content::before {
    content: ''; display: block; flex-shrink: 0; width: 40px; height: 4px; border-radius: 4px;
    background: var(--border-strong); margin: 8px auto 0;
  }
  .modal-header { padding: 0.75rem 1rem; position: sticky; top: 0; background: #FFFFFF; z-index: 2; }
  .modal-header h2 { font-size: 1.05rem; }
  .modal-body { padding: 1rem; }
  .close-modal-btn { font-size: 1.7rem; min-width: 40px; min-height: 40px; }
  #modal-dialog > .modal-content { width: calc(100% - 2rem) !important; max-width: 420px !important; }
  #modal-image-preview > .modal-content, #modal-image-preview img, #modal-image-preview video { max-width: 100% !important; }

  /* campos e botões no tamanho do dedo (16px evita o zoom automático do iPhone) */
  input[type="text"], input[type="email"], input[type="password"], input[type="tel"], input[type="time"], input[type="date"], input[type="number"], textarea, select { font-size: 16px !important; }
  .submit-btn { min-height: 48px; }

  /* formulário de novo status */
  #modal-add-post .m-date-label { display: block; font-size: 0.8rem; font-weight: 600; color: #008069; margin-top: 0.1rem; text-transform: capitalize; }
  #modal-add-post .type-toggle-container .toggle-btn { padding: 0.65rem 0.4rem; font-size: 0.9rem; }
  #modal-add-post textarea { min-height: 110px; }
  #modal-add-post #submit-btn { position: sticky; bottom: 0; }

  /* janela do dia */
  #modal-day .day-action-bar .submit-btn { margin-top: 0; }
  .queue-card { padding: 0.85rem; border-radius: 14px; }
  .card-bottom { flex-wrap: wrap; }
  .card-bottom button { flex: 1 1 45%; min-height: 40px; justify-content: center; }

  /* conexões */
  #modal-conexoes > .modal-content { padding: 1rem !important; }
  #modal-conexoes .modal-body { padding: 0 !important; }
  #modal-conexoes .modal-body > div:first-child { flex-wrap: wrap; }
  #connections-grid { grid-template-columns: 1fr !important; gap: 0.85rem !important; }
  #modal-connection-details > .modal-content { padding: 1rem !important; }
  #modal-connection-details .modal-body > div { grid-template-columns: 1fr !important; }
  #modal-connection-details section.section-card { min-height: 0 !important; }
  #modal-connection-details .modal-body > div:nth-child(2) > div:last-child { order: -1; }
  #modal-con-qr-wrapper > p { display: none; }
  #modal-con-pair-box { order: -1; max-width: 100% !important; background: rgba(37, 211, 102, 0.07); border: 1px solid rgba(37, 211, 102, 0.3); border-radius: 14px; padding: 0.85rem; }
  #modal-con-pair-toggle { display: none; }
  #modal-con-pair-box::before { content: 'Conectar pelo código (recomendado)'; font-size: 0.9rem; font-weight: 800; color: #008069; }
  #modal-con-pair-go { min-height: 46px; font-size: 0.95rem !important; }
  #modal-con-qr-box { width: min(220px, 70%) !important; }
  #modal-con-qr-box::after { content: 'Ou leia este QR Code em outro aparelho'; position: absolute; bottom: -1.6rem; left: 0; right: 0; font-size: 0.72rem; color: var(--text-muted); }
  #modal-con-qr-wrapper { gap: 1.6rem !important; }

  /* planos */
  #modal-upgrade > .modal-content { padding: 0.9rem 0.85rem 1rem !important; }

  /* ---------- Folha de escolhas do celular (conta, dia, mídia) ---------- */
  .m-sheet-overlay {
    position: fixed; inset: 0; z-index: 9990;
    background: rgba(11, 20, 26, 0.45);
    display: flex; align-items: flex-end;
  }
  .m-sheet-overlay.hidden { display: none !important; }
  .m-sheet {
    width: 100%; max-height: calc(88 * var(--vh)); overflow-y: auto;
    background: #FFFFFF; border-radius: 20px 20px 0 0;
    padding: 0 1rem calc(1rem + var(--m-safe-b));
    animation: m-sheet-up 0.22s ease-out;
  }
  .m-sheet-grip { width: 40px; height: 4px; border-radius: 4px; background: var(--border-strong); margin: 8px auto 0; }
  .m-sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 0.6rem 0 0.5rem; }
  .m-sheet-head h3 { margin: 0; font-size: 1.05rem; }
  .m-sheet-close { font-size: 1.7rem; color: var(--text-secondary); min-width: 40px; min-height: 40px; }
  .m-sheet-list { display: flex; flex-direction: column; gap: 0.45rem; }
  .m-sheet-item {
    display: flex; align-items: center; gap: 0.8rem; width: 100%; text-align: left;
    padding: 0.85rem 0.9rem; border-radius: 14px; border: 1px solid var(--border-light); background: #FFFFFF;
    font-size: 0.95rem; font-weight: 600; color: var(--text-primary); text-decoration: none;
  }
  .m-sheet-item:active { background: var(--bg-primary); }
  .m-sheet-item i { font-size: 1.35rem; color: #008069; flex-shrink: 0; }
  .m-sheet-item small { display: block; font-size: 0.75rem; font-weight: 500; color: var(--text-secondary); }
  .m-sheet-item.danger, .m-sheet-item.danger i { color: #DC2626; }
  .m-sheet-item.primary { background: linear-gradient(135deg, #25D366, #128C7E); border: none; color: #FFFFFF; }
  .m-sheet-item.primary i, .m-sheet-item.primary small { color: #FFFFFF; }
  .m-account-card { display: flex; align-items: center; gap: 0.8rem; padding: 0.85rem; border-radius: 14px; background: var(--bg-primary); margin-bottom: 0.75rem; }
  .m-account-card .m-avatar { width: 46px; height: 46px; font-size: 1.15rem; flex-shrink: 0; }
  .m-account-name { font-weight: 800; font-size: 1rem; }
  .m-account-plan { font-size: 0.8rem; color: #008069; font-weight: 600; }
  .m-account-email { font-size: 0.78rem; color: var(--text-secondary); word-break: break-all; }
  .m-sheet-sep { font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); margin: 0.6rem 0 0.1rem 0.2rem; }
  .m-day-chips { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; margin-bottom: 0.75rem; }
  .m-day-chip { padding: 0.85rem 0.5rem; border-radius: 14px; border: 1.5px solid var(--border-light); background: #FFFFFF; font-weight: 700; color: var(--text-primary); }
  .m-day-chip small { display: block; font-size: 0.74rem; font-weight: 500; color: var(--text-secondary); }
  .m-day-chip:active, .m-day-chip.on { border-color: var(--accent-primary); background: rgba(37, 211, 102, 0.08); }
  .m-date-row { display: flex; gap: 0.5rem; align-items: stretch; }
  .m-date-row input { flex: 1; min-height: 48px; border-radius: 12px; border: 1px solid var(--border-strong); padding: 0 0.75rem; background: #FFFFFF; }
  .m-date-row button { width: auto; margin: 0; padding: 0 1.1rem; }
  .m-media-preview { width: 100%; max-height: 38vh; object-fit: contain; border-radius: 14px; background: #000; margin-bottom: 0.75rem; display: block; }

  @keyframes m-sheet-up { from { transform: translateY(24px); opacity: 0.6; } to { transform: translateY(0); opacity: 1; } }
  @media (prefers-reduced-motion: reduce) {
    .m-sheet, .modal-overlay > .modal-content, #m-trialbar { animation: none !important; }
  }
}

/* ---------- Telas do dono (Painel, Financeiro, Conexões dos Clientes, Evolution) no celular ---------- */
@media (max-width: 768px) {
  .m-page-title { display: block !important; font-size: 1.15rem; margin: 0.15rem 0 0.75rem; }
  /* tabelas largas: deslizam para o lado com o dedo, sem cortar colunas */
  .app-container table { display: block; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; border-collapse: collapse; }
  .app-container table th, .app-container table td { white-space: nowrap; }
  .m-swipe-hint { display: block !important; font-size: 0.72rem; color: var(--text-muted); margin: 0.35rem 0; }
  /* contadores do Painel do Dono: dois por linha */
  #page-admin > div:first-of-type { grid-template-columns: 1fr 1fr !important; gap: 0.6rem !important; }
  #page-admin > div:first-of-type > .section-card { padding: 0.8rem !important; gap: 0.55rem !important; flex-direction: column; align-items: flex-start !important; }
  #page-admin > div:first-of-type > .section-card > div:first-child { width: 36px !important; height: 36px !important; font-size: 1.2rem !important; }
  #page-admin > div:first-of-type [id^="adm-metric-"] { font-size: 1.35rem !important; }
}

/* Botão do cupom no celular: acima da barra de baixo */
@media (max-width: 768px) {
  #coupon-fab { right: 16px !important; bottom: calc(var(--m-nav-h) + var(--m-safe-b) + 14px) !important; width: 48px; height: 48px; }
  #coupon-fab .coupon-fab-btn { width: 48px; height: 48px; font-size: 1.45rem; }
  #coupon-fab .coupon-fab-label { display: none; }
}

/* Sair da conta: espaço entre o tracinho da janela e o ícone */
@media (max-width: 768px) {
  #modal-logout .lo-icon, #modal-need-conn .lo-icon, #modal-ws-notice .lo-icon { margin-top: 0.9rem; }
}

/* Botão de sugestões no celular: acima do cupom */
@media (max-width: 768px) {
  #feedback-fab { right: 16px !important; bottom: calc(var(--m-nav-h) + var(--m-safe-b) + 74px) !important; width: 48px; height: 48px; }
  #coupon-fab[hidden] ~ #feedback-fab { bottom: calc(var(--m-nav-h) + var(--m-safe-b) + 14px) !important; }
  #feedback-fab .feedback-fab-btn { width: 48px; height: 48px; font-size: 1.4rem; }
  #feedback-fab .feedback-fab-label { display: none; }
  .fb-kinds { grid-template-columns: 1fr; }
  .fb-card-date { margin-left: 0; width: 100%; }
}
