/**
 * Cloud Gaming Map - Responsividade
 * Version: 2.5.7
 * Arquivo: Media queries e adaptações mobile-first
 */

/* ===============================================
   RESPONSIVIDADE MOBILE-FIRST
   =============================================== */

/* Tablets e telas médias (768px e abaixo) */
@media (max-width: 768px) {
    .cgm-container {
        padding: 16px;
    }
    
    .cgm-page-title {
        font-size: 32px;
        text-align: center;
        margin-bottom: 20px;
        color: var(--cgm-text);
        padding-top: 20px;
    }
    
    /* Controles principais */
    .cgm-controls {
        flex-direction: column;
        align-items: stretch;
        gap: 16px;
        padding: 16px;
        margin-bottom: 16px;
    }
    
    .cgm-controls-main {
        flex-direction: column;
        align-items: stretch;
        gap: 16px;
    }
    
    /* Filtros adaptados */
    .cgm-filters {
        justify-content: center;
        flex-wrap: wrap;
        gap: 8px;
    }
    
    .cgm-filters label {
        flex: 1;
        justify-content: center;
        min-width: 100px;
        padding: 10px 16px;
        font-size: 14px;
    }
    
    /* Mapa responsivo */
    #cgm-map {
        height: 400px;
        margin: 16px 0;
        border-radius: var(--cgm-radius);
    }
    
    /* Leaderboard adaptado para tablet */
    .cgm-leaderboard-icon {
        width: 52px;
        height: 52px;
        font-size: 18px;
        position: fixed;
        top: 20px;
        right: 20px;
        z-index: 1002;
    }
    
    .cgm-leaderboard-drawer {
        width: 100%;
        right: -100%;
        height: 100vh;
        top: 0;
    }
    
    .cgm-leaderboard-entry {
        padding: 16px;
        gap: 12px;
    }
    
    .cgm-avatar {
        width: 48px;
        height: 48px;
    }
    
    .cgm-avatar-initials {
        font-size: 18px;
    }
    
    /* Tabela responsiva com scroll horizontal */
    .cgm-table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        border-radius: var(--cgm-radius);
        box-shadow: var(--cgm-shadow);
    }
    
    .cgm-table {
        min-width: 600px;
        font-size: 14px;
    }
    
    .cgm-table th,
    .cgm-table td {
        padding: 12px 8px;
        white-space: nowrap;
    }
    
    /* Botões maiores para toque */
    .cgm-button {
        min-height: 48px;
        font-size: 16px;
        padding: 12px 20px;
        white-space: normal;
        word-wrap: break-word;
        text-align: center;
        line-height: 1.3;
    }
    
    /* Botão de simular em tablet */
    #cgm-btn-sim {
        font-size: 15px;
        padding: 12px 20px;
        min-height: 56px;
        display: flex;
        align-items: center;
        justify-content: center;
        line-height: 1.4;
    }
    
    /* Resultados */
    #cgm-results h4 {
        padding: 16px;
        font-size: 18px;
        text-align: center;
    }
    
    /* Popups adaptados */
    .cgm-popup {
        width: 95%;
        max-width: 450px;
        margin: 20px;
    }
}

/* Smartphones (480px e abaixo) */
@media (max-width: 480px) {
    .cgm-container {
        padding: 8px;
        margin: 0;
        width: 100vw;
        max-width: 100vw;
    }
    
    .cgm-page-title {
        font-size: 28px;
        margin-bottom: 16px;
        color: var(--cgm-text);
        text-align: center;
    }
    
    /* Controles compactos */
    .cgm-controls {
        padding: 8px;
        margin: 0 0 8px 0;
        border-radius: var(--cgm-radius-sm);
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }
    
    /* Mapa menor no mobile */
    #cgm-map {
        height: 300px;
        margin: 8px 0;
        border-radius: var(--cgm-radius-sm);
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }
    
    /* Filtros empilhados */
    .cgm-filters {
        flex-direction: column;
        gap: 8px;
    }
    
    .cgm-filters label {
        width: 100%;
        min-width: auto;
        padding: 12px 16px;
        font-size: 15px;
        justify-content: center;
    }
    
    /* Leaderboard mobile-first */
    .cgm-leaderboard-icon {
        width: 48px;
        height: 48px;
        font-size: 16px;
        top: 15px;
        right: 15px;
    }
    /* Em telas bem pequenas, evita sobreposição do ícone com o título */
    @media (max-width: 420px) {
        .cgm-header-container { align-items: center; }
        .cgm-leaderboard-icon {
            position: static;
            margin: 8px 0 0 0;
            align-self: center;
        }
        .cgm-leaderboard-label { display: none; }
    }
    
    .cgm-leaderboard-drawer {
        width: 100vw;
        height: 100vh;
        right: -100vw;
        border-radius: 0;
    }
    
    .cgm-drawer-header {
        padding: 20px;
    }
    
    .cgm-drawer-header h3 {
        font-size: 18px;
    }
    
    .cgm-leaderboard-entry {
        padding: 16px;
        gap: 12px;
        border-radius: var(--cgm-radius-sm);
        margin-bottom: 8px;
    }
    
    .cgm-position {
        font-size: 18px;
        min-width: 28px;
    }
    
    .cgm-avatar {
        width: 44px;
        height: 44px;
    }
    
    .cgm-avatar-initials {
        font-size: 16px;
    }
    
    .cgm-user-name {
        font-size: 15px;
        font-weight: 600;
    }
    
    .cgm-user-location {
        font-size: 13px;
    }
    
    .cgm-ping {
        font-size: 16px;
    }
    
    /* Tabela mobile com cards */
    .cgm-table-container {
        overflow: visible;
    }
    
    .cgm-table {
        min-width: auto;
        font-size: 13px;
    }
    
    .cgm-table thead {
        display: none;
    }
    
    .cgm-table tbody tr {
        display: block;
        background: var(--cgm-white);
        border: 1px solid var(--cgm-border);
        border-radius: var(--cgm-radius-sm);
        margin-bottom: 12px;
        padding: 16px;
        box-shadow: var(--cgm-shadow-sm);
    }
    
    .cgm-table tbody td {
        display: block;
        text-align: left;
        padding: 6px 0;
        border: none;
        position: relative;
        padding-left: 50%;
    }
    
    .cgm-table tbody td:before {
        content: attr(data-label);
        position: absolute;
        left: 6px;
        width: 45%;
        font-weight: 600;
        color: var(--cgm-dark);
    }
    
    /* Botões mobile */
    .cgm-button {
        width: 100%;
        min-height: 52px;
        font-size: 16px;
        padding: 16px 20px;
        border-radius: var(--cgm-radius);
        white-space: normal;
        word-wrap: break-word;
        text-align: center;
        line-height: 1.3;
    }
    
    /* Botão de simular específico - texto longo */
    #cgm-btn-sim {
        font-size: 15px;
        padding: 12px 16px;
        min-height: 60px;
        display: flex;
        align-items: center;
        justify-content: center;
        text-align: center;
        line-height: 1.4;
    }
    
    /* Input de endereço */
    .cgm-address-input {
        flex-direction: column;
        gap: 12px;
        padding: 16px;
        align-items: stretch;
    }
    
    .cgm-address-input input {
        width: 100%;
        max-width: none;
        padding: 16px;
        font-size: 16px;
        border-radius: var(--cgm-radius);
    }
    
    .cgm-address-input button {
        width: 100%;
        padding: 16px;
        font-size: 16px;
    }
    
    /* Informações de localização */
    .cgm-location-info {
        padding: 12px;
        font-size: 14px;
        text-align: center;
        border-radius: var(--cgm-radius-sm);
    }
    
    /* Resultados compactos */
    #cgm-results {
        margin: 8px 0;
        border-radius: var(--cgm-radius-sm);
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }
    
    #cgm-results h4 {
        padding: 16px;
        font-size: 16px;
    }
    
    /* Popups mobile */
    .cgm-popup {
        width: 95vw;
        max-width: none;
        margin: 10px;
        max-height: 85vh;
        border-radius: var(--cgm-radius);
    }
    
    /* Notificações mobile */
    .cgm-notification {
        width: 95%;
        max-width: none;
        left: 50%;
        transform: translateX(-50%);
        border-radius: var(--cgm-radius);
        padding: 16px 20px;
        font-size: 15px;
    }
}

/* Telas muito pequenas (360px e abaixo) */
@media (max-width: 360px) {
    .cgm-container {
        padding: 4px;
        margin: 0;
        width: 100vw;
        max-width: 100vw;
    }
    
    #cgm-map {
        height: 280px;
    }
    
    .cgm-leaderboard-icon {
        width: 44px;
        height: 44px;
        font-size: 14px;
        top: 10px;
        right: 10px;
    }
    
    .cgm-drawer-header {
        padding: 16px;
    }
    
    .cgm-drawer-header h3 {
        font-size: 16px;
    }
    
    .cgm-leaderboard-entry {
        padding: 12px;
        gap: 8px;
    }
    
    .cgm-avatar {
        width: 36px;
        height: 36px;
    }
    
    .cgm-avatar-initials {
        font-size: 14px;
    }
    
    .cgm-position {
        font-size: 16px;
        min-width: 24px;
    }
    
    .cgm-user-name {
        font-size: 14px;
    }
    
    .cgm-user-location {
        font-size: 12px;
    }
    
    .cgm-ping {
        font-size: 15px;
    }
    
    .cgm-button {
        min-height: 48px;
        font-size: 15px;
        padding: 14px 16px;
        white-space: normal;
        word-wrap: break-word;
        text-align: center;
        line-height: 1.3;
    }
    
    /* Botão de simular para telas pequenas */
    #cgm-btn-sim {
        font-size: 14px;
        padding: 10px 12px;
        min-height: 64px;
        display: flex;
        align-items: center;
        justify-content: center;
        line-height: 1.4;
        text-align: center;
    }
}

/* ===============================================
   MELHORIAS ESPECÍFICAS PARA TOUCH E UX MOBILE
   =============================================== */

/* Scroll suave em todos os elementos */
* {
    -webkit-overflow-scrolling: touch;
}

/* Previne overflow horizontal em mobile */
@media (max-width: 768px) {
    body {
        overflow-x: hidden;
    }
    
    .cgm-container {
        overflow-x: hidden;
    }
    
    .cgm-container > * {
        max-width: 100%;
        box-sizing: border-box;
    }
}

/* Otimizações para touch targets */
@media (max-width: 768px) {
    /* Área de toque mínima de 44px */
    .cgm-button,
    .cgm-leaderboard-icon,
    .cgm-drawer-close,
    .cgm-filters label {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Zoom desabilitado em inputs */
    input, select, textarea {
        font-size: 16px !important;
    }
    
    /* Prevent zoom on double tap */
    * {
        touch-action: manipulation;
    }
}

/* Orientação landscape para smartphones */
@media (max-width: 768px) and (orientation: landscape) {
    #cgm-map {
        height: 250px;
    }
    
    .cgm-leaderboard-drawer {
        width: 50%;
        right: -50%;
    }
    
    .cgm-container {
        padding: 8px;
    }
    
    .cgm-controls {
        padding: 8px;
        margin-bottom: 8px;
    }
    
    .cgm-filters {
        flex-direction: row;
        gap: 4px;
    }
    
    .cgm-filters label {
        font-size: 12px;
        padding: 8px 12px;
    }
}

/* ===============================================
   MELHORIAS PARA ACESSIBILIDADE
   =============================================== */

/* Melhorias para acessibilidade */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .cgm-avatar-custom {
        border-width: 3px;
        border-style: solid;
    }
    
    .cgm-button {
        border: 2px solid var(--cgm-dark);
    }
    
    .cgm-table th,
    .cgm-table td {
        border: 1px solid var(--cgm-dark);
    }
}

/* Dark mode preferences */
@media (prefers-color-scheme: dark) {
    /* Manter cores claras no plugin mesmo em dark mode do sistema */
    .cgm-container {
        color-scheme: light;
    }
}
