/**
 * Mobile Enhancements - Melhorias específicas para mobile
 * @version 2.1.0
 */

/* ========================================
   TABELAS RESPONSIVAS
   ======================================== */

/* Mobile Table Cards - Transformar tabelas em cards em mobile */
@media (max-width: 768px) {
  .mobile-table-card {
    display: none; /* Esconder por padrão, ativar via JS se necessário */
  }

  /* Stack de tabela em mobile */
  .repertorio-table thead {
    position: absolute;
    left: -9999px;
    top: -9999px;
  }

  .repertorio-table tr {
    display: block;
    margin-bottom: 16px;
    background: var(--apple-surface);
    border-radius: var(--apple-radius);
    padding: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  }

  .repertorio-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border: none;
    border-bottom: 1px solid var(--apple-surface-secondary);
  }

  .repertorio-table td:last-child {
    border-bottom: none;
  }

  .repertorio-table td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--apple-text-secondary);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
  }

  .repertorio-table td .table-actions {
    margin-left: auto;
  }
}

/* ========================================
   FORMULÁRIOS MOBILE
   ======================================== */

@media (max-width: 768px) {
  /* Form Groups */
  .form-group label {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 8px;
  }

  .form-control,
  .form-select {
    font-size: 16px !important; /* Previne zoom no iOS */
    padding: 14px;
    border-radius: 10px;
  }

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

  /* Checkbox e Radio maiores para touch */
  input[type="checkbox"],
  input[type="radio"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
  }

  /* Select personalizado */
  select.form-control {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%23a1a1a6' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 20px;
    padding-right: 40px;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
  }

  /* Botões de formulário */
  .form-actions {
    display: flex;
    flex-direction: column-reverse;
    gap: 12px;
  }

  .form-actions .btn {
    width: 100%;
    padding: 14px;
    font-size: 16px;
  }

  .form-actions .btn-secondary {
    order: 2;
  }

  .form-actions .btn-primary {
    order: 1;
  }
}

/* ========================================
   NAVEGAÇÃO MOBILE
   ======================================== */

/* Barra de navegação inferior (opcional) */
.mobile-bottom-nav {
  display: none;
}

@media (max-width: 768px) {
  .mobile-bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 64px;
    background: var(--apple-surface);
    border-top: 1px solid var(--apple-surface-secondary);
    z-index: 999;
    padding-bottom: env(safe-area-inset-bottom); /* iPhone X+ */
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.2);
  }

  .mobile-bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    color: var(--apple-text-secondary);
    text-decoration: none;
    font-size: 11px;
    font-weight: 500;
    transition: all 0.2s ease;
  }

  .mobile-bottom-nav-item:active {
    transform: scale(0.95);
    background: var(--apple-surface-secondary);
  }

  .mobile-bottom-nav-item.active {
    color: var(--apple-accent);
  }

  .mobile-bottom-nav-item i {
    width: 24px;
    height: 24px;
  }

  /* Adicionar padding no conteúdo quando bottom nav está ativo */
  body.has-bottom-nav .main-content {
    padding-bottom: calc(64px + env(safe-area-inset-bottom));
  }
}

/* ========================================
   MODALS MOBILE
   ======================================== */

@media (max-width: 768px) {
  .modal {
    padding: 0;
  }

  .modal-content {
    min-height: 100vh;
    border-radius: 0;
    margin: 0;
  }

  .modal-header {
    position: sticky;
    top: 0;
    background: var(--apple-surface);
    z-index: 10;
    border-top-left-radius: 0;
    border-top-right-radius: 0;
  }

  .modal-body {
    padding: 20px;
  }

  .modal-footer {
    position: sticky;
    bottom: 0;
    background: var(--apple-surface);
    padding: 16px;
    border-top: 1px solid var(--apple-surface-secondary);
  }
}

/* ========================================
   CARDS MOBILE
   ======================================== */

@media (max-width: 768px) {
  .card {
    border-radius: 12px;
    overflow: hidden;
  }

  .card-header {
    padding: 16px;
    background: var(--apple-surface-secondary);
  }

  .card-body {
    padding: 16px;
  }

  .card-footer {
    padding: 16px;
    background: var(--apple-surface-secondary);
  }

  /* Cards em lista */
  .card-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
  }

  .card-list-item {
    padding: 16px;
    background: var(--apple-surface);
    border-radius: 12px;
    transition: background 0.2s ease;
  }

  .card-list-item:active {
    background: var(--apple-surface-secondary);
  }
}

/* ========================================
   STICKY HEADER MOBILE
   ======================================== */

@media (max-width: 768px) {
  .sticky-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--apple-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  }

  /* Compensar altura do sticky header */
  .has-sticky-header {
    padding-top: 80px;
  }
}

/* ========================================
   LOADING STATES MOBILE
   ======================================== */

.mobile-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
}

.mobile-loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--apple-surface-secondary);
  border-top-color: var(--apple-accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.mobile-loading-text {
  margin-top: 16px;
  color: var(--apple-text-secondary);
  font-size: 14px;
}

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

/* ========================================
   SAFE AREA (iPhone X+)
   ======================================== */

@supports (padding-top: env(safe-area-inset-top)) {
  .main-header {
    padding-top: max(20px, env(safe-area-inset-top));
  }

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

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

/* ========================================
   PULL TO REFRESH INDICATOR
   ======================================== */

.pull-to-refresh {
  position: absolute;
  top: -60px;
  left: 50%;
  transform: translateX(-50%);
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: top 0.3s ease;
}

.pull-to-refresh.active {
  top: 20px;
}

.pull-to-refresh-icon {
  animation: spin 0.8s linear infinite;
}

/* ========================================
   TOAST NOTIFICATIONS MOBILE
   ======================================== */

.mobile-toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--apple-surface-secondary);
  color: var(--apple-text);
  padding: 16px 24px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
  z-index: 10000;
  max-width: calc(100vw - 40px);
  animation: slideInUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.mobile-toast-success {
  background: var(--apple-success);
  color: #000;
}

.mobile-toast-error {
  background: var(--apple-danger);
}

.mobile-toast-warning {
  background: var(--apple-warning);
  color: #000;
}

/* ========================================
   EMPTY STATES MOBILE
   ======================================== */

@media (max-width: 768px) {
  .empty-state {
    padding: 60px 20px;
  }

  .empty-state-icon {
    width: 80px;
    height: 80px;
    margin: 0 auto 20px;
  }

  .empty-state-icon i {
    width: 80px;
    height: 80px;
    color: var(--apple-text-tertiary);
  }

  .empty-state-title {
    font-size: 22px;
    font-weight: 600;
    color: var(--apple-text);
    margin-bottom: 8px;
  }

  .empty-state-description {
    font-size: 14px;
    color: var(--apple-text-secondary);
    margin-bottom: 24px;
    line-height: 1.5;
  }

  .empty-state-action {
    margin-top: 20px;
  }
}

/* ========================================
   ACCESSIBILITY MOBILE
   ======================================== */

/* Aumentar área de toque */
@media (max-width: 768px) {
  button,
  a,
  .clickable {
    position: relative;
  }

  button::after,
  a::after,
  .clickable::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    min-width: 44px;
    min-height: 44px;
    pointer-events: none;
  }
}

/* Focus visible para navegação por teclado */
:focus-visible {
  outline: 2px solid var(--apple-accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Reduzir motion para quem prefere */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ========================================
   UTILITIES MOBILE
   ======================================== */

@media (max-width: 768px) {
  .mobile-only {
    display: block;
  }

  .desktop-only {
    display: none;
  }

  .mobile-hide {
    display: none !important;
  }

  .mobile-text-center {
    text-align: center;
  }

  .mobile-full-width {
    width: 100% !important;
  }

  .mobile-stack {
    flex-direction: column !important;
  }

  .mobile-no-padding {
    padding: 0 !important;
  }

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

@media (min-width: 769px) {
  .mobile-only {
    display: none;
  }

  .desktop-only {
    display: block;
  }
}
