/* ============================================
   MOBILE CSS - Painel CMS Plano D
   Todas as regras dentro de @media (max-width: 768px)
   Não afeta desktop.
   ============================================ */

/* === ESCONDER ELEMENTOS MOBILE NO DESKTOP === */
.mobile-header {
  display: none;
}

.mobile-bottom-nav {
  display: none;
}

/* === MEDIA QUERY MOBILE === */
@media (max-width: 768px) {

  /* ------------------------------------------
     1. BASE - Sem scroll horizontal
     ------------------------------------------ */
  html,
  body {
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: hidden !important;
  }

  * {
    box-sizing: border-box;
  }

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

  /* ------------------------------------------
     2. SIDEBAR - Esconder completamente
     ------------------------------------------ */
  .sidebar {
    display: none !important;
  }

  /* ------------------------------------------
     3. LAYOUT PRINCIPAL - Bloco unico
     ------------------------------------------ */
  .app-layout {
    display: block !important;
  }

  .main-content {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    margin-left: 0 !important;
  }

  .top-header {
    padding: 1rem 16px !important;
  }

  .top-header h1 {
    font-size: 1.25rem !important;
    line-height: 1.3 !important;
  }

  .content-wrapper {
    padding: 16px !important;
    max-width: 100% !important;
    width: 100% !important;
    margin: 0 !important;
    padding-bottom: calc(96px + env(safe-area-inset-bottom)) !important;
  }

  /* ------------------------------------------
     4. HEADER MOBILE
     ------------------------------------------ */
  .mobile-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 56px;
    padding: 0 16px;
    background: #ffffff;
    border-bottom: 1px solid #e5e7eb;
    position: sticky;
    top: 0;
    z-index: 80;
  }

  .mobile-header-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 18px;
    font-weight: 700;
    color: #0f172a;
  }

  .mobile-header-brand span {
    font-size: 12px;
    font-weight: 700;
    color: #64748b;
    background: #f1f5f9;
    border-radius: 999px;
    padding: 4px 8px;
  }

  /* ------------------------------------------
     5. BARRA DE NAVEGACAO INFERIOR
     ------------------------------------------ */
  .mobile-bottom-nav {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 100;
    background: #ffffff;
    border-top: 1px solid #e5e7eb;
    padding: 8px 6px calc(8px + env(safe-area-inset-bottom));
    box-shadow: 0 -8px 24px rgba(15, 23, 42, 0.06);
  }

  .mobile-bottom-nav a {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 6px 4px;
    text-decoration: none;
    font-size: 11px;
    line-height: 1.1;
    font-weight: 700;
    color: #64748b;
    border-radius: 12px;
    white-space: nowrap;
    transition: background 0.15s, color 0.15s;
  }

  .mobile-bottom-nav a:hover,
  .mobile-bottom-nav a:active,
  .mobile-bottom-nav a.is-active {
    background: #f1f5f9;
    color: #0f172a;
  }

  /* ------------------------------------------
     6. TITULOS
     ------------------------------------------ */
  h1 {
    font-size: 24px !important;
    line-height: 1.15 !important;
    margin-bottom: 14px !important;
    word-break: break-word;
  }

  h2 {
    font-size: 20px !important;
    line-height: 1.2 !important;
    word-break: break-word;
  }

  h3 {
    font-size: 17px !important;
    line-height: 1.25 !important;
  }

  h4 {
    font-size: 16px !important;
    line-height: 1.3 !important;
  }

  /* ------------------------------------------
     7. CARDS
     ------------------------------------------ */
  .card {
    border-radius: 12px !important;
    margin-bottom: 1rem !important;
  }

  .card-header {
    padding: 1rem !important;
  }

  .card-header.d-flex {
    flex-direction: column !important;
    gap: 10px !important;
    align-items: flex-start !important;
  }

  .card-body {
    padding: 1rem !important;
  }

  /* ------------------------------------------
     8. DASHBOARD - Cards de estatisticas em coluna
     ------------------------------------------ */
  .dashboard-stats {
    flex-direction: column !important;
    gap: 12px !important;
  }

  .dashboard-stats .card {
    flex: unset !important;
    width: 100% !important;
  }

  .card-body.text-center h2 {
    font-size: 28px !important;
  }

  .card-body.text-center h3 {
    font-size: 13px !important;
  }

  /* ------------------------------------------
     9. TABELAS - Transformar em cards
     ------------------------------------------ */
  .table-responsive {
    overflow-x: visible !important;
    margin: 0;
    padding: 0;
  }

  table,
  table thead,
  table tbody,
  table tr,
  table th,
  table td {
    display: block !important;
    width: 100% !important;
  }

  /* Esconder cabeçalho */
  table thead {
    display: none !important;
  }

  /* Cada linha vira um card */
  table tbody tr {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 14px;
    margin-bottom: 12px;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
  }

  table tbody tr:last-child td {
    border-bottom: none !important;
  }

  /* Cada celula exibe o label antes do conteudo */
  table td {
    padding: 6px 0 !important;
    border-bottom: none !important;
    font-size: 14px !important;
    display: flex !important;
    align-items: flex-start;
    gap: 8px;
    word-break: break-word;
  }

  table td::before {
    content: attr(data-label);
    font-weight: 700;
    font-size: 12px;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    min-width: 90px;
    flex-shrink: 0;
    padding-top: 2px;
  }

  /* Celula vazia (mensagem "nenhum encontrado") */
  table td[data-label=""]::before {
    display: none;
  }

  table td[data-label=""]  {
    justify-content: center;
    text-align: center;
  }

  /* Primeira celula (titulo) - destaque */
  table td:first-child {
    font-weight: 600;
    font-size: 15px !important;
    color: #0f172a;
    padding-bottom: 8px !important;
    border-bottom: 1px solid #f1f5f9 !important;
    margin-bottom: 4px;
  }

  /* Celula de acoes */
  table td[data-label="A\e7\f5es"] {
    padding-top: 10px !important;
    border-top: 1px solid #f1f5f9 !important;
    margin-top: 4px;
  }

  table td[data-label="A\e7\f5es"] .btn {
    min-height: 40px;
    font-size: 13px !important;
  }

  table td[data-label="A\e7\f5es"] .d-flex {
    flex-direction: column;
    width: 100%;
    gap: 8px !important;
  }

  table td[data-label="A\e7\f5es"] .d-flex .btn,
  table td[data-label="A\e7\f5es"] .d-flex form {
    width: 100%;
  }

  table td[data-label="A\e7\f5es"] .d-flex form .btn {
    width: 100%;
  }

  /* ------------------------------------------
     10. FORMULARIOS
     ------------------------------------------ */
  .form-group {
    margin-bottom: 1rem !important;
  }

  .form-group label {
    font-size: 14px !important;
    font-weight: 600 !important;
    margin-bottom: 6px !important;
    color: #334155;
  }

  .form-control,
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="url"],
  input[type="file"],
  select,
  textarea {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    min-height: 44px;
    font-size: 16px !important;
    line-height: 1.4;
    padding: 10px 12px !important;
  }

  textarea.form-control {
    min-height: 120px;
    resize: vertical;
  }

  /* Conteudo HTML - textarea maior */
  textarea[name="conteudo"] {
    min-height: 300px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 14px !important;
  }

  /* ------------------------------------------
     11. EDITAR ARTIGO - Colunas empilhadas
     ------------------------------------------ */
  .editor-columns {
    flex-direction: column !important;
    gap: 1rem !important;
  }

  .editor-main {
    flex: unset !important;
    width: 100% !important;
  }

  .editor-sidebar {
    flex: unset !important;
    width: 100% !important;
    padding: 1rem !important;
    border-radius: 12px !important;
  }

  /* Botoes finais do editor */
  .editor-actions {
    flex-direction: column !important;
    gap: 10px !important;
  }

  .editor-actions .d-flex {
    flex-direction: column !important;
    gap: 10px !important;
    width: 100%;
  }

  .editor-actions .btn,
  .editor-actions button,
  .editor-actions a {
    width: 100% !important;
    min-height: 46px !important;
    justify-content: center;
  }

  /* Card header do editor - titulo + status */
  .card-header h2 .status {
    display: block;
    margin-left: 0 !important;
    margin-top: 6px;
  }

  /* ------------------------------------------
     12. SECAO IA
     ------------------------------------------ */
  #ia_texto_bruto {
    min-height: 200px !important;
  }

  #ia_observacoes {
    min-height: 80px !important;
  }

  #btnIaPreparar {
    width: 100% !important;
    min-height: 46px !important;
  }

  #ia_status {
    display: block !important;
    margin-top: 10px;
    word-break: break-word;
  }

  /* ------------------------------------------
     13. UPLOAD DE IMAGEM
     ------------------------------------------ */
  #previewImagemContainer img,
  .image-preview img,
  .upload-preview img {
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    border-radius: 8px;
  }

  #inputFileUpload {
    font-size: 14px !important;
  }

  #btnUploadImagem {
    width: 100% !important;
    min-height: 44px !important;
  }

  /* URLs longas */
  input[name="imagem"] {
    word-break: break-word;
    overflow-wrap: anywhere;
  }

  /* ------------------------------------------
     14. BOTOES - Todos tocaveis
     ------------------------------------------ */
  .btn,
  button,
  input[type="submit"] {
    min-height: 44px;
    font-size: 15px !important;
  }

  .btn-sm {
    min-height: 38px !important;
    font-size: 13px !important;
    padding: 6px 12px !important;
  }

  /* Flex com justify-between em forms - empilhar */
  .d-flex.justify-between {
    flex-direction: column !important;
    gap: 10px !important;
  }

  /* ------------------------------------------
     15. LOGIN
     ------------------------------------------ */
  .auth-layout {
    padding: 16px !important;
    align-items: flex-start !important;
    padding-top: 60px !important;
  }

  .auth-box {
    width: 100% !important;
    max-width: 420px !important;
    margin: 0 auto !important;
    padding: 24px !important;
  }

  .auth-box h1 {
    font-size: 1.5rem !important;
  }

  /* ------------------------------------------
     16. ALERTAS
     ------------------------------------------ */
  .alert {
    font-size: 0.8rem !important;
    padding: 0.75rem !important;
    word-break: break-word;
  }

  /* ------------------------------------------
     17. CARDS DE FORMULARIO COM MAX-WIDTH
     ------------------------------------------ */
  .card[style*="max-width"] {
    max-width: 100% !important;
    margin: 0 !important;
  }

  /* ------------------------------------------
     18. BADGES E STATUS
     ------------------------------------------ */
  .badge {
    font-size: 0.7rem !important;
    padding: 2px 6px !important;
  }

  .status {
    font-size: 0.7rem !important;
  }

  /* ------------------------------------------
     19. UTILITARIOS D-FLEX NO MOBILE
     ------------------------------------------ */
  .d-flex.align-center.gap-2 {
    flex-wrap: wrap;
    gap: 6px !important;
  }

  /* ------------------------------------------
     20. SMALL TEXTS
     ------------------------------------------ */
  small,
  .text-muted {
    word-break: break-word;
    overflow-wrap: anywhere;
  }

  /* Link de URL publicada */
  a[target="_blank"] {
    word-break: break-word;
    overflow-wrap: anywhere;
  }

} /* FIM DA MEDIA QUERY */
