/* ========================================
   SISTEMA MOBILE PROFISSIONAL V2.0
   ANTECH O&M - Design Moderno e Responsivo
   ======================================== */

/* ========================================
   1. VARIÁVEIS E CONFIGURAÇÕES GLOBAIS
   ======================================== */

:root {
  --mobile-header-height: 56px;
  --mobile-bottom-nav-height: 60px;
  --mobile-sidebar-width: 280px;
  --mobile-transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --touch-target-min: 44px;
  --mobile-padding: 16px;
  --mobile-gap: 12px;
}

/* ========================================
   2. RESET E FUNDAMENTOS MOBILE
   ======================================== */

@media (max-width: 768px) {
  * {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
  }

  html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    -webkit-font-smoothing: antialiased;
  }

  body {
    overflow-x: hidden !important;
    max-width: 100vw;
    position: relative;
    touch-action: pan-y;
  }

  /* Prevenir zoom em inputs iOS */
  input, select, textarea, button {
    font-size: 16px !important;
  }

  /* Melhorar áreas de toque */
  button, a, [role="button"], [onclick] {
    min-height: var(--touch-target-min);
    min-width: var(--touch-target-min);
    touch-action: manipulation;
  }
}

/* ========================================
   3. HEADER MOBILE FIXO
   ======================================== */

@media (max-width: 768px) {
  .mobile-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--mobile-header-height);
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    z-index: 999;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  }

  .mobile-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
  }

  .mobile-menu-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
  }

  .mobile-menu-btn:active {
    transform: scale(0.95);
    background: rgba(255, 255, 255, 0.3);
  }

  .mobile-header-title {
    font-size: 18px;
    font-weight: 600;
    margin: 0;
  }

  .mobile-header-right {
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .mobile-header-icon {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
  }

  .mobile-header-icon:active {
    transform: scale(0.95);
  }

  .mobile-header-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    background: #ef4444;
    color: white;
    font-size: 10px;
    font-weight: 600;
    padding: 2px 5px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
  }
}

/* ========================================
   4. SIDEBAR MOBILE OVERLAY
   ======================================== */

@media (max-width: 768px) {
  /* Overlay escuro */
  .mobile-sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 998;
    opacity: 0;
    visibility: hidden;
    transition: all var(--mobile-transition);
  }

  .mobile-sidebar-overlay.active {
    opacity: 1;
    visibility: visible;
  }

  /* Sidebar */
  #sidebar {
    position: fixed !important;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--mobile-sidebar-width);
    max-width: 85vw;
    z-index: 999;
    transform: translateX(-100%);
    transition: transform var(--mobile-transition);
    box-shadow: 4px 0 16px rgba(0, 0, 0, 0.2);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  #sidebar.mobile-open {
    transform: translateX(0);
  }

  /* Logo e header da sidebar */
  .sidebar-header {
    padding: 20px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    gap: 12px;
  }

  .sidebar-header img {
    width: 40px;
    height: 40px;
  }

  .sidebar-header-text h2 {
    font-size: 18px;
    margin: 0;
    font-weight: 600;
  }

  .sidebar-header-text p {
    font-size: 12px;
    margin: 0;
    opacity: 0.7;
  }

  /* Items do menu */
  #sidebar nav button {
    width: 100%;
    padding: 14px 16px !important;
    margin: 4px 8px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 48px;
    transition: all 0.2s;
  }

  #sidebar nav button i {
    width: 24px;
    text-align: center;
    font-size: 18px;
  }

  #sidebar nav button span {
    flex: 1;
    text-align: left;
    font-size: 15px;
    font-weight: 500;
  }

  /* Botão de fechar sidebar */
  .sidebar-close-btn {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 10;
  }
}

/* ========================================
   5. CONTENT AREA MOBILE
   ======================================== */

@media (max-width: 768px) {
  #content {
    margin-left: 0 !important;
    padding-top: calc(var(--mobile-header-height) + 16px) !important;
    padding-bottom: calc(var(--mobile-bottom-nav-height) + 16px) !important;
    padding-left: 16px !important;
    padding-right: 16px !important;
    min-height: 100vh;
  }

  /* Container principal */
  .container, .max-w-7xl {
    max-width: 100% !important;
    padding: 0 !important;
  }
}

/* ========================================
   6. CARDS E COMPONENTES MOBILE
   ======================================== */

@media (max-width: 768px) {
  /* Cards responsivos */
  .card, .bg-white.rounded-lg {
    border-radius: 12px !important;
    padding: 16px !important;
    margin-bottom: 12px !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08) !important;
  }

  /* Grid responsivo */
  .grid {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }

  /* Dashboard cards */
  .dashboard-card {
    padding: 16px;
    border-radius: 12px;
    background: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  }

  .dashboard-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
  }

  .dashboard-card-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
  }

  .dashboard-card-value {
    font-size: 28px;
    font-weight: 700;
    margin: 8px 0;
  }

  .dashboard-card-label {
    font-size: 14px;
    color: #6b7280;
  }
}

/* ========================================
   7. TABELAS MOBILE (CARDS)
   ======================================== */

@media (max-width: 768px) {
  /* Ocultar tabelas tradicionais */
  table {
    display: none !important;
  }

  /* Criar view de cards */
  .mobile-table-card {
    background: white;
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  }

  .mobile-table-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid #e5e7eb;
  }

  .mobile-table-card-title {
    font-size: 16px;
    font-weight: 600;
    color: #111827;
  }

  .mobile-table-card-badge {
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
  }

  .mobile-table-card-body {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .mobile-table-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
  }

  .mobile-table-label {
    font-size: 13px;
    color: #6b7280;
    font-weight: 500;
  }

  .mobile-table-value {
    font-size: 14px;
    color: #111827;
    font-weight: 500;
    text-align: right;
  }

  .mobile-table-card-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #e5e7eb;
  }

  .mobile-table-action-btn {
    flex: 1;
    padding: 10px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all 0.2s;
  }
}

/* ========================================
   8. FORMULÁRIOS MOBILE
   ======================================== */

@media (max-width: 768px) {
  /* Inputs otimizados */
  input, select, textarea {
    width: 100% !important;
    padding: 12px 16px !important;
    border-radius: 8px !important;
    font-size: 16px !important;
    border: 1px solid #d1d5db !important;
    transition: all 0.2s !important;
  }

  input:focus, select:focus, textarea:focus {
    outline: none !important;
    border-color: #667eea !important;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1) !important;
  }

  /* Labels */
  label {
    display: block;
    font-size: 14px !important;
    font-weight: 500 !important;
    color: #374151 !important;
    margin-bottom: 6px !important;
  }

  /* Form groups */
  .form-group {
    margin-bottom: 16px;
  }

  /* Botões de formulário */
  .form-actions {
    display: flex;
    gap: 8px;
    margin-top: 20px;
    position: sticky;
    bottom: 0;
    background: white;
    padding: 12px 0;
    border-top: 1px solid #e5e7eb;
  }

  .form-btn {
    flex: 1;
    padding: 14px !important;
    border-radius: 8px !important;
    font-size: 16px !important;
    font-weight: 600 !important;
    min-height: 48px !important;
    transition: all 0.2s !important;
  }

  .form-btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
    color: white !important;
    border: none !important;
  }

  .form-btn-primary:active {
    transform: scale(0.98);
  }

  .form-btn-secondary {
    background: white !important;
    color: #6b7280 !important;
    border: 1px solid #d1d5db !important;
  }
}

/* ========================================
   9. BOTTOM NAVIGATION
   ======================================== */

@media (max-width: 768px) {
  .mobile-bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--mobile-bottom-nav-height);
    background: white;
    border-top: 1px solid #e5e7eb;
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: 900;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
  }

  .bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px;
    color: #6b7280;
    text-decoration: none;
    transition: all 0.2s;
    cursor: pointer;
    min-height: 52px;
  }

  .bottom-nav-item.active {
    color: #667eea;
  }

  .bottom-nav-item i {
    font-size: 22px;
  }

  .bottom-nav-item span {
    font-size: 11px;
    font-weight: 500;
  }

  .bottom-nav-item:active {
    transform: scale(0.95);
  }

  /* Badge para notificações */
  .bottom-nav-item .badge {
    position: absolute;
    top: 6px;
    right: calc(50% - 18px);
    background: #ef4444;
    color: white;
    font-size: 10px;
    font-weight: 600;
    padding: 2px 5px;
    border-radius: 10px;
    min-width: 16px;
    text-align: center;
  }
}

/* ========================================
   10. BOTÕES MOBILE
   ======================================== */

@media (max-width: 768px) {
  /* Botões gerais */
  button, .btn {
    min-height: 44px !important;
    padding: 12px 20px !important;
    border-radius: 8px !important;
    font-size: 15px !important;
    font-weight: 600 !important;
    transition: all 0.2s !important;
  }

  button:active, .btn:active {
    transform: scale(0.98);
  }

  /* Botão flutuante (FAB) */
  .mobile-fab {
    position: fixed;
    bottom: calc(var(--mobile-bottom-nav-height) + 16px);
    right: 16px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    cursor: pointer;
    z-index: 800;
    transition: all 0.3s;
  }

  .mobile-fab:active {
    transform: scale(0.95);
  }

  /* Botões de ação inline */
  .mobile-action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    min-height: 40px;
    transition: all 0.2s;
  }
}

/* ========================================
   11. MODALS MOBILE
   ======================================== */

@media (max-width: 768px) {
  .modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1100;
  }

  .modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
  }

  .modal-content {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-radius: 16px 16px 0 0;
    max-height: 90vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    transform: translateY(100%);
    transition: transform var(--mobile-transition);
  }

  .modal.active .modal-content {
    transform: translateY(0);
  }

  .modal-header {
    padding: 16px;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    background: white;
    z-index: 10;
  }

  .modal-title {
    font-size: 18px;
    font-weight: 600;
    margin: 0;
  }

  .modal-close {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #f3f4f6;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
  }

  .modal-body {
    padding: 16px;
  }

  /* Pull indicator */
  .modal-pull-indicator {
    width: 40px;
    height: 4px;
    background: #d1d5db;
    border-radius: 2px;
    margin: 8px auto;
  }
}

/* ========================================
   12. SCROLL E PULL TO REFRESH
   ======================================== */

@media (max-width: 768px) {
  /* Custom scrollbar */
  ::-webkit-scrollbar {
    width: 4px;
  }

  ::-webkit-scrollbar-track {
    background: transparent;
  }

  ::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 2px;
  }

  /* Pull to refresh indicator */
  .pull-to-refresh {
    position: fixed;
    top: var(--mobile-header-height);
    left: 0;
    right: 0;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: white;
    transform: translateY(-100%);
    transition: transform 0.3s;
    z-index: 899;
  }

  .pull-to-refresh.active {
    transform: translateY(0);
  }
}

/* ========================================
   13. TOAST E NOTIFICATIONS
   ======================================== */

@media (max-width: 768px) {
  .mobile-toast {
    position: fixed;
    top: calc(var(--mobile-header-height) + 16px);
    left: 16px;
    right: 16px;
    background: white;
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 1000;
    transform: translateY(-120%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }

  .mobile-toast.show {
    transform: translateY(0);
  }

  .mobile-toast-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
  }

  .mobile-toast-content {
    flex: 1;
  }

  .mobile-toast-title {
    font-size: 15px;
    font-weight: 600;
    margin: 0 0 4px 0;
  }

  .mobile-toast-message {
    font-size: 13px;
    color: #6b7280;
    margin: 0;
  }
}

/* ========================================
   14. SEARCH BAR MOBILE
   ======================================== */

@media (max-width: 768px) {
  .mobile-search {
    position: relative;
    margin-bottom: 16px;
  }

  .mobile-search-input {
    width: 100%;
    padding: 12px 16px 12px 44px !important;
    border-radius: 12px !important;
    border: 1px solid #e5e7eb !important;
    font-size: 15px !important;
    background: #f9fafb;
  }

  .mobile-search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: #9ca3af;
    font-size: 18px;
  }

  .mobile-search-input:focus {
    background: white;
    border-color: #667eea !important;
  }
}

/* ========================================
   15. SWIPE GESTURES
   ======================================== */

@media (max-width: 768px) {
  .swipeable {
    touch-action: pan-y;
    position: relative;
  }

  .swipe-actions {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    display: flex;
    transform: translateX(100%);
  }

  .swipe-action {
    width: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 20px;
    cursor: pointer;
  }

  .swipe-action.delete {
    background: #ef4444;
  }

  .swipe-action.edit {
    background: #3b82f6;
  }
}

/* ========================================
   16. LOADING E SKELETON
   ======================================== */

@media (max-width: 768px) {
  .mobile-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
  }

  .mobile-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #e5e7eb;
    border-top-color: #667eea;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
  }

  @keyframes spin {
    to { transform: rotate(360deg); }
  }

  /* Skeleton */
  .skeleton {
    background: linear-gradient(90deg, #f3f4f6 25%, #e5e7eb 50%, #f3f4f6 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 8px;
  }

  @keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
  }

  .skeleton-text {
    height: 14px;
    margin-bottom: 8px;
  }

  .skeleton-title {
    height: 20px;
    margin-bottom: 12px;
    width: 60%;
  }

  .skeleton-card {
    height: 120px;
    margin-bottom: 12px;
  }
}

/* ========================================
   17. UTILIDADES MOBILE
   ======================================== */

@media (max-width: 768px) {
  /* Mostrar apenas em mobile */
  .mobile-only {
    display: block !important;
  }

  /* Ocultar em mobile */
  .mobile-hidden, .desktop-only {
    display: none !important;
  }

  /* Texto mobile */
  .text-mobile-sm {
    font-size: 12px !important;
  }

  .text-mobile-base {
    font-size: 14px !important;
  }

  .text-mobile-lg {
    font-size: 16px !important;
  }

  /* Padding mobile */
  .p-mobile {
    padding: 16px !important;
  }

  .px-mobile {
    padding-left: 16px !important;
    padding-right: 16px !important;
  }

  .py-mobile {
    padding-top: 16px !important;
    padding-bottom: 16px !important;
  }

  /* Margin mobile */
  .m-mobile {
    margin: 16px !important;
  }

  .mb-mobile {
    margin-bottom: 16px !important;
  }

  /* Gap mobile */
  .gap-mobile {
    gap: 12px !important;
  }
}

/* ========================================
   18. ANIMAÇÕES E TRANSIÇÕES
   ======================================== */

@media (max-width: 768px) {
  /* Fade in */
  .fade-in {
    animation: fadeIn 0.3s ease-in;
  }

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

  /* Slide up */
  .slide-up {
    animation: slideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }

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

  /* Bounce */
  .bounce {
    animation: bounce 0.5s ease;
  }

  @keyframes bounce {
    0%, 100% {
      transform: translateY(0);
    }
    50% {
      transform: translateY(-10px);
    }
  }
}

/* ========================================
   19. DARK MODE MOBILE (OPCIONAL)
   ======================================== */

@media (max-width: 768px) {
  @media (prefers-color-scheme: dark) {
    body {
      background: #111827;
      color: #f9fafb;
    }

    .card, .bg-white {
      background: #1f2937 !important;
      color: #f9fafb;
    }

    .mobile-header {
      background: #1f2937;
      border-bottom: 1px solid #374151;
    }

    .mobile-bottom-nav {
      background: #1f2937;
      border-top: 1px solid #374151;
    }

    input, select, textarea {
      background: #374151 !important;
      border-color: #4b5563 !important;
      color: #f9fafb !important;
    }
  }
}

/* ========================================
   20. SAFE AREA (IPHONE NOTCH)
   ======================================== */

@media (max-width: 768px) {
  .mobile-header {
    padding-top: env(safe-area-inset-top);
    height: calc(var(--mobile-header-height) + env(safe-area-inset-top));
  }

  .mobile-bottom-nav {
    padding-bottom: env(safe-area-inset-bottom);
    height: calc(var(--mobile-bottom-nav-height) + env(safe-area-inset-bottom));
  }

  #content {
    padding-bottom: calc(var(--mobile-bottom-nav-height) + env(safe-area-inset-bottom) + 16px) !important;
  }
}
