/*
Theme Name: BR2.Run Theme
Description: Custom WordPress theme designed to work seamlessly with the corridasbr-api and its plugin. Features fast AJAX search, SEO-friendly URLs, region/distance filters, and ACF Pro compatibility.
Version: 1.0.0
Author: Rhuan Carlos
Text Domain: br2run-theme
Requires at least: 5.0
Tested up to: 6.4
Requires PHP: 7.4
License: GPL v2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Features:
- ACF Pro compatibility
- AJAX-powered search functionality
- SEO-friendly URLs (/state/city/distance/race, etc.)
- Fast performance with caching
- Mobile-responsive design with Tailwind CSS
*/

/* Reset básico */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: #333;
}

/* Estilos customizados que complementam o Tailwind */
.race-table {
    overflow-x: auto;
}

.filter-section {
    background: #f8fafc;
    border-radius: 8px;
    padding: 1.5rem;
    margin-bottom: 2rem;
}

.race-card {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.race-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
}

/* Loading spinner */
.loading {
    display: inline-block;
    width: 24px;
    height: 24px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #3498db;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    will-change: transform; /* Optimize for animation */
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Table structure fixes */
.race-table table {
    table-layout: fixed;
    width: 100%;
}

.race-table th,
.race-table td {
    vertical-align: top;
    word-wrap: break-word;
}

/* Column width distribution */
.race-table th:nth-child(1),
.race-table td:nth-child(1) {
    width: 28%; /* Corrida - reduzido para dar mais espaço à data */
    min-width: 180px;
    max-width: 300px;
}

/* Específico para a coluna de corrida */
.race-table td:nth-child(1) .text-sm {
    line-height: 1.4;
    word-break: break-word;
    hyphens: auto;
}

.race-table th:nth-child(2),
.race-table td:nth-child(2) {
    width: 15%; /* Data - aumentada para evitar sobreposição */
    min-width: 110px;
    max-width: 140px;
}

.race-table th:nth-child(3),
.race-table td:nth-child(3) {
    width: auto; /* Local - dinâmica */
    min-width: 120px;
    max-width: 200px;
}

.race-table th:nth-child(4),
.race-table td:nth-child(4) {
    width: 14%; /* Distâncias - reduzida para compensar data */
    min-width: 80px;
}

.race-table th:nth-child(5),
.race-table td:nth-child(5) {
    width: 18%; /* Ações - aumentada para melhor visualização */
    min-width: 120px;
    text-align: center;
    padding-left: 1rem; /* Padding lateral esquerdo */
    padding-right: 1rem; /* Padding lateral direito */
}

/* Centralizar botões na coluna de ações */
.race-table td:nth-child(5) .flex {
    justify-content: center;
    align-items: center;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .race-table {
        border-radius: 0.5rem;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch; /* Scroll suave no iOS */
    }
    
    .race-table table {
        font-size: 0.8rem;
        min-width: 600px; /* Força scroll horizontal em mobile */
        border-collapse: separate;
        border-spacing: 0;
    }
    
    .race-table th:nth-child(1),
    .race-table td:nth-child(1) {
        width: 26%; /* Corrida - reduzido para dar mais espaço à data */
        min-width: 150px;
        max-width: 180px;
    }
    
    .race-table th:nth-child(2),
    .race-table td:nth-child(2) {
        width: 12%; /* Data - aumentada em mobile */
        min-width: 100px;
        max-width: 120px;
    }
    
    .race-table th:nth-child(3),
    .race-table td:nth-child(3) {
        width: auto; /* Local - dinâmica em mobile */
        min-width: 100px;
        max-width: 150px;
    }
    
    .race-table th:nth-child(4),
    .race-table td:nth-child(4) {
        width: 11%; /* Distâncias - reduzida em mobile para compensar data */
        min-width: 70px;
    }
    
    .race-table th:nth-child(5),
    .race-table td:nth-child(5) {
        width: 20%; /* Ações - mais espaço em mobile */
        min-width: 110px;
        padding-left: 0.75rem; /* Padding lateral esquerdo mobile */
        padding-right: 0.75rem; /* Padding lateral direito mobile */
    }
    
    /* Ajustes específicos para texto em mobile */
    .race-table td {
        padding: 0.5rem 0.75rem; /* Padding reduzido */
        line-height: 1.3;
    }
    
    .race-table th {
        padding: 0.5rem 0.75rem;
        font-size: 0.7rem;
    }
    
    /* Texto da corrida em mobile */
    .race-table td:nth-child(1) .text-sm {
        font-size: 0.8rem;
        line-height: 1.2;
        word-break: break-word;
        hyphens: auto;
    }
    
    /* Localização em mobile - dinâmica e responsiva */
    .race-table td:nth-child(3) {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    
    .race-table td:nth-child(3) .text-sm {
        font-size: 0.75rem;
        line-height: 1.2;
        display: block;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        max-width: 100%;
    }
    
    /* Hover para mostrar texto completo na localização */
    .race-table td:nth-child(3):hover .text-sm {
        white-space: normal;
        overflow: visible;
        text-overflow: unset;
        position: relative;
        z-index: 10;
        background: white;
        padding: 0.25rem;
        border-radius: 0.25rem;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    }
    
    /* Data em mobile */
    .race-table td:nth-child(2) .text-sm {
        font-size: 0.75rem;
        line-height: 1.2;
    }
    
    /* Distâncias em mobile */
    .race-table td:nth-child(4) .text-sm {
        font-size: 0.75rem;
        line-height: 1.2;
    }
}

/* Optimized transitions for instant feel */
.race-table tr {
    transition: opacity 0.15s ease-in-out;
}

/* Loading animation improvements */
.race-table {
    transition: opacity 0.2s ease-in-out;
}

.race-table.opacity-30 {
    opacity: 0.3;
}

.race-table.pointer-events-none {
    pointer-events: none;
}

/* Loading state styling */
.loading-row td {
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

.race-table tr.fade-in {
    opacity: 0;
    animation: fadeIn 0.2s ease-in-out forwards;
}

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

/* Sticky actions column */
.sticky-actions {
    position: sticky;
    right: 0;
    background: white;
    z-index: 10;
    min-width: 120px;
    box-shadow: -2px 0 4px rgba(0, 0, 0, 0.1);
}

.sticky-actions-header {
    position: sticky;
    right: 0;
    background: #f9fafb;
    z-index: 11;
    min-width: 120px;
    box-shadow: -2px 0 4px rgba(0, 0, 0, 0.1);
}

/* Enhanced button styles */
.race-table .sticky-actions a {
    position: relative;
    overflow: hidden;
}

.race-table .sticky-actions a:before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s;
}

.race-table .sticky-actions a:hover:before {
    left: 100%;
}

/* Pulse animation for call-to-action */
@keyframes pulse-green {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.4);
    }
    50% {
        box-shadow: 0 0 0 8px rgba(34, 197, 94, 0);
    }
}


.race-table .sticky-actions a {
    animation: pulse-green 2s infinite;
}

/* Responsive adjustments - Mobile específico */
@media (max-width: 768px) {
    .filter-section {
        padding: 1rem;
    }
    
    .sticky-actions {
        min-width: 80px; /* Reduzido de 100px */
    }
    
    /* Botão de inscrever-se otimizado para mobile */
    .race-table .sticky-actions a.bg-gradient-to-r {
        font-size: 0.65rem;
        padding: 0.375rem 0.5rem;
        min-height: 1.75rem;
        border-radius: 0.25rem;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
        font-weight: 600;
        letter-spacing: 0.025em;
        white-space: nowrap;
    }
    
    /* Botão "Em breve" otimizado */
    .race-table .sticky-actions span {
        font-size: 0.65rem;
        padding: 0.375rem 0.5rem;
        min-height: 1.75rem;
        border-radius: 0.25rem;
        font-weight: 500;
        white-space: nowrap;
    }
    
    /* Botão de resultados menor e mais discreto */
    .race-table .sticky-actions a:not(.bg-gradient-to-r) {
        font-size: 0.6rem;
        padding: 0.25rem 0.375rem;
        min-height: 1.25rem;
        border-radius: 0.25rem;
        font-weight: 500;
        white-space: nowrap;
    }
    
    /* Espaçamento entre botões otimizado */
    .race-table .sticky-actions .flex {
        gap: 0.375rem;
        align-items: stretch;
    }
    
    /* Ícones proporcionais */
    .race-table .sticky-actions a.bg-gradient-to-r svg,
    .race-table .sticky-actions span svg {
        width: 0.875rem;
        height: 0.875rem;
    }
    
    .race-table .sticky-actions a:not(.bg-gradient-to-r) svg {
        width: 0.75rem;
        height: 0.75rem;
    }
    
    /* Melhor contraste e legibilidade */
    .race-table .sticky-actions a.bg-gradient-to-r {
        background: linear-gradient(135deg, #10b981 0%, #059669 100%);
        color: white;
        text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    }
    
    .race-table .sticky-actions a.bg-gradient-to-r:hover {
        background: linear-gradient(135deg, #059669 0%, #047857 100%);
        transform: translateY(-1px);
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
    }
}
