/* ========================================
   MELHORIAS MOBILE - Portal UrbIA
   Ajustes específicos para dispositivos móveis
   ======================================== */

/* ===== VARIÁVEIS MOBILE ===== */
@media (max-width: 639px) {
  :root {
    --mobile-padding: 1rem;
    --mobile-gap: 0.75rem;
    --mobile-font-size: 0.875rem;
  }
}

/* ===== NAVEGAÇÃO MOBILE APRIMORADA ===== */
@media (max-width: 639px) {
  .navbar {
    padding: 0.5rem 0;
  }

  .navbar-container {
    padding: 0 var(--mobile-padding);
  }

  /* Logo ajustado para mobile */
  .navbar-logo img {
    height: 2rem;
  }

  .navbar-logo span {
    font-size: 1rem;
  }

  /* Menu mobile melhorado */
  .navbar-menu.active {
    position: fixed;
    top: 4rem;
    left: 0;
    right: 0;
    bottom: 0;
    background: white;
    padding: var(--mobile-padding);
    overflow-y: auto;
    animation: slideDown 0.3s ease-out;
  }

  @keyframes slideDown {
    from {
      opacity: 0;
      transform: translateY(-10px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }
}

/* ===== CARDS MOBILE ===== */
@media (max-width: 639px) {
  .card {
    margin-bottom: var(--mobile-gap);
    border-radius: 0.5rem;
  }

  .card-header {
    padding: 1rem;
  }

  .card-body {
    padding: 1rem;
  }

  .card-footer {
    padding: 1rem;
  }

  /* Cards em lista no mobile */
  .grid {
    gap: var(--mobile-gap);
  }

  /* Cards de materiais */
  .material-card {
    display: flex;
    flex-direction: column;
  }

  .material-card img {
    width: 100%;
    height: auto;
    max-height: 200px;
    object-fit: cover;
  }

  .material-card .card-body {
    flex: 1;
  }
}

/* ===== TIPOGRAFIA MOBILE ===== */
@media (max-width: 639px) {
  h1 {
    font-size: 1.5rem;
    line-height: 2rem;
  }

  h2 {
    font-size: 1.25rem;
    line-height: 1.75rem;
  }

  h3 {
    font-size: 1.125rem;
    line-height: 1.5rem;
  }

  h4, h5, h6 {
    font-size: 1rem;
    line-height: 1.5rem;
  }

  p {
    font-size: var(--mobile-font-size);
    line-height: 1.5;
  }

  /* Garantir legibilidade */
  body {
    font-size: var(--mobile-font-size);
  }
}

/* ===== BOTÕES MOBILE ===== */
@media (max-width: 639px) {
  .btn {
    width: 100%;
    justify-content: center;
    padding: 0.75rem 1rem;
    font-size: var(--mobile-font-size);
  }

  .btn-sm {
    padding: 0.5rem 0.75rem;
    font-size: 0.8125rem;
  }

  /* Grupo de botões em coluna */
  .btn-group {
    flex-direction: column;
    gap: 0.5rem;
  }

  .btn-group .btn {
    width: 100%;
    margin: 0;
  }

  /* Botões inline apenas quando necessário */
  .btn-group-inline {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .btn-group-inline .btn {
    flex: 1;
    min-width: fit-content;
  }
}

/* ===== FORMULÁRIOS MOBILE ===== */
@media (max-width: 639px) {
  .form-group {
    margin-bottom: 1rem;
  }

  .form-label {
    font-size: var(--mobile-font-size);
    margin-bottom: 0.25rem;
  }

  .form-input,
  .form-select,
  .form-textarea {
    font-size: 1rem; /* Importante: 16px+ previne zoom no iOS */
    padding: 0.75rem;
  }

  .form-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  /* Labels flutuantes para economizar espaço */
  .form-floating {
    position: relative;
  }

  .form-floating input,
  .form-floating textarea {
    padding-top: 1.5rem;
    padding-bottom: 0.5rem;
  }

  .form-floating label {
    position: absolute;
    top: 0.75rem;
    left: 0.75rem;
    font-size: 0.75rem;
    color: var(--gray-600);
    pointer-events: none;
    transition: all 0.2s ease;
  }
}

/* ===== TABELAS MOBILE ===== */
@media (max-width: 639px) {
  /* Tabela como cards no mobile */
  .table-responsive {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .table {
    min-width: 600px;
  }

  /* Ou tabela em formato de lista */
  .table-card tbody tr {
    display: block;
    margin-bottom: 1rem;
    border: 1px solid var(--gray-200);
    border-radius: 0.5rem;
    padding: 1rem;
  }

  .table-card tbody td {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    border: none;
  }

  .table-card tbody td::before {
    content: attr(data-label);
    font-weight: 600;
    margin-right: 1rem;
  }

  .table-card thead {
    display: none;
  }
}

/* ===== MODAIS MOBILE ===== */
@media (max-width: 639px) {
  .modal {
    padding: 0;
    align-items: flex-end;
  }

  .modal-content {
    max-width: 100%;
    max-height: 90vh;
    border-radius: 1rem 1rem 0 0;
    animation: slideUp 0.3s ease-out;
  }

  @keyframes slideUp {
    from {
      transform: translateY(100%);
    }
    to {
      transform: translateY(0);
    }
  }

  .modal-header {
    position: sticky;
    top: 0;
    background: white;
    border-bottom: 1px solid var(--gray-200);
    padding: 1rem;
    z-index: 1;
  }

  .modal-body {
    padding: 1rem;
  }

  .modal-footer {
    position: sticky;
    bottom: 0;
    background: white;
    border-top: 1px solid var(--gray-200);
    padding: 1rem;
  }
}

/* ===== DASHBOARD MOBILE ===== */
@media (max-width: 639px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .metric-card {
    padding: 1rem;
  }

  .metric-value {
    font-size: 1.5rem;
  }

  .metric-label {
    font-size: 0.75rem;
  }

  /* Stats em uma coluna */
  .stats-grid {
    grid-template-columns: 1fr;
  }
}

/* ===== MENU LATERAL MOBILE (SIDEBAR) ===== */
@media (max-width: 1023px) {
  .sidebar {
    position: fixed;
    top: 4rem;
    left: -100%;
    width: 280px;
    height: calc(100vh - 4rem);
    background: white;
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.1);
    transition: left 0.3s ease;
    z-index: 40;
    overflow-y: auto;
  }

  .sidebar.active {
    left: 0;
  }

  .sidebar-overlay {
    position: fixed;
    top: 4rem;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 39;
  }

  .sidebar-overlay.active {
    opacity: 1;
    pointer-events: all;
  }

  /* Conteúdo principal ajustado */
  .main-content {
    margin-left: 0;
    width: 100%;
  }
}

/* ===== LISTAS MOBILE ===== */
@media (max-width: 639px) {
  .list-group-item {
    padding: 1rem;
    font-size: var(--mobile-font-size);
  }

  .list-group-item .actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.5rem;
  }

  .list-group-item .actions .btn {
    flex: 1;
    min-width: fit-content;
  }
}

/* ===== IMAGENS E MÍDIA MOBILE ===== */
@media (max-width: 639px) {
  img,
  video,
  iframe {
    max-width: 100%;
    height: auto;
  }

  .image-gallery {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
  }

  .video-container {
    position: relative;
    padding-bottom: 56.25%; /* 16:9 */
    height: 0;
    overflow: hidden;
  }

  .video-container iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
  }
}

/* ===== FOOTER ===== */
.footer-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 2rem;
  margin-bottom: 2rem;
}

.footer-bottom {
  display: flex;
  justify-content: center;
  align-items: center;
  padding-top: 2rem;
  border-top: 1px solid #e5e7eb;
  text-align: center;
  color: #6b7280;
  font-size: 0.875rem;
}

@media (max-width: 1023px) {
  .footer-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
  }
}

@media (max-width: 639px) {
  .footer-grid {
    grid-template-columns: 1fr;
    gap: 2rem;
  }

  .footer-bottom {
    flex-direction: column;
    text-align: center;
    gap: 1rem;
  }
}

/* ===== BREADCRUMBS MOBILE ===== */
@media (max-width: 639px) {
  .breadcrumb {
    font-size: 0.75rem;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
  }

  .breadcrumb-item {
    display: inline-block;
  }
}

/* ===== TABS MOBILE ===== */
@media (max-width: 639px) {
  .tabs {
    overflow-x: auto;
    whitespace: nowrap;
    -webkit-overflow-scrolling: touch;
    border-bottom: 1px solid var(--gray-200);
  }

  .tab {
    padding: 0.75rem 1rem;
    font-size: var(--mobile-font-size);
  }
}

/* ===== TOOLTIPS E POPOVERS MOBILE ===== */
@media (max-width: 639px) {
  .tooltip {
    font-size: 0.75rem;
    max-width: 200px;
  }

  .popover {
    max-width: calc(100vw - 2rem);
  }
}

/* ===== DRAG AND DROP MOBILE ===== */
@media (max-width: 639px) {
  .dropzone {
    padding: 2rem 1rem;
    font-size: var(--mobile-font-size);
  }

  .dropzone-text {
    font-size: var(--mobile-font-size);
  }
}

/* ===== TOAST NOTIFICATIONS MOBILE ===== */
@media (max-width: 639px) {
  .toast {
    left: 1rem;
    right: 1rem;
    width: auto;
    font-size: var(--mobile-font-size);
  }
}

/* ===== LOADING STATES MOBILE ===== */
@media (max-width: 639px) {
  .spinner {
    width: 2rem;
    height: 2rem;
  }

  .skeleton {
    border-radius: 0.5rem;
  }
}

/* ===== TOUCH OPTIMIZATIONS ===== */
@media (max-width: 639px) and (hover: none) {
  /* Aumentar área de toque */
  a,
  button,
  input[type="button"],
  input[type="submit"] {
    min-height: 44px;
    min-width: 44px;
  }

  /* Remover hover states em dispositivos touch */
  .btn:hover,
  .card:hover {
    transform: none;
  }

  /* Feedback visual no tap */
  .btn:active {
    transform: scale(0.98);
  }
}

/* ===== SCROLL BEHAVIOR MOBILE ===== */
@media (max-width: 639px) {
  /* Smooth scrolling */
  html {
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
  }

  /* Esconder scrollbar mas manter funcionalidade */
  .scrollable::-webkit-scrollbar {
    width: 0;
    height: 0;
  }

  .scrollable {
    scrollbar-width: none;
    -ms-overflow-style: none;
  }
}

/* ===== FIXES ESPECÍFICOS PARA MOBILE ===== */
@media (max-width: 639px) {
  /* Prevenir zoom indesejado no iOS */
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  textarea,
  select {
    font-size: 16px !important;
  }

  /* Fix para 100vh em mobile (considerando barra de endereço) */
  .min-h-screen-mobile {
    min-height: 100vh;
    min-height: -webkit-fill-available;
  }

  /* Garantir que elementos não ultrapassem a tela */
  body {
    overflow-x: hidden;
  }

  /* Safe area para iPhone com notch */
  .safe-top {
    padding-top: env(safe-area-inset-top);
  }

  .safe-bottom {
    padding-bottom: env(safe-area-inset-bottom);
  }

  .safe-left {
    padding-left: env(safe-area-inset-left);
  }

  .safe-right {
    padding-right: env(safe-area-inset-right);
  }
}

/* ===== ORIENTAÇÃO LANDSCAPE MOBILE ===== */
@media (max-width: 1023px) and (orientation: landscape) {
  .navbar {
    padding: 0.25rem 0;
  }

  .modal-content {
    max-height: 80vh;
  }

  /* Reduzir padding em landscape */
  .container {
    padding: 0 1rem;
  }
}

/* ===== ACESSIBILIDADE MOBILE ===== */
@media (max-width: 639px) {
  /* Aumentar contraste para legibilidade em luz solar */
  .high-contrast {
    color: #000;
    background: #fff;
  }

  /* Focus visível para navegação por teclado */
  *:focus-visible {
    outline: 3px solid var(--primary-color);
    outline-offset: 2px;
  }
}

/* ===== PRINT NO MOBILE ===== */
@media print {
  .navbar,
  .sidebar,
  .btn,
  .modal,
  .toast {
    display: none !important;
  }
}

