/* Custom scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Mobile-friendly scrollbar */
@supports (scrollbar-width: thin) {
    .overflow-x-auto {
        scrollbar-width: thin;
        scrollbar-color: #cbd5e1 transparent;
    }
}

/* Smooth transitions */
* {
    scroll-behavior: smooth;
}

/* Table responsive wrapper */
.overflow-x-auto {
    -webkit-overflow-scrolling: touch;
}

/* Tables must fit in container without forcing scroll */
table {
    table-layout: auto;
    width: 100%;
}

table th, table td {
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Mobile touch targets - minimum 44x44px */
button, a, input[type="button"], input[type="submit"], select, textarea {
    min-height: 44px;
}

/* Better input sizing on mobile */
@media (max-width: 640px) {
    input, select, textarea {
        font-size: 16px;
    }
}

/* Mobile form layout improvements */
@media (max-width: 640px) {
    .form-grid-2 {
        display: grid;
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }
    
    .form-grid-3 {
        display: grid;
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }
    
    .form-grid-4 {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }
}

/* Stack buttons vertically on very small screens */
@media (max-width: 480px) {
    .button-group-mobile {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
    }
    
    .button-group-mobile > button,
    .button-group-mobile > a {
        width: 100%;
    }
}

/* Improve table readability on mobile */
@media (max-width: 640px) {
    table {
        font-size: 0.875rem;
    }
    
    table td, table th {
        padding: 0.5rem 0.5rem !important;
    }
}

/* Modal improvements for mobile */
@media (max-width: 640px) {
    .modal-mobile {
        position: fixed !important;
        inset: 0 !important;
        width: 100% !important;
        height: 100% !important;
        max-height: 100vh !important;
        border-radius: 1.5rem 1.5rem 0 0 !important;
        bottom: 0 !important;
        max-width: none !important;
    }
}

/* Chart responsive height */
@media (max-width: 768px) {
    #profitChartWrap {
        height: 280px !important;
    }
}

@media (max-width: 480px) {
    #profitChartWrap {
        height: 240px !important;
    }
}

/* Force containers to not overflow */
html, body {
    width: 100%;
    overflow-x: hidden;
}

main {
    width: 100%;
    overflow-x: hidden;
}

/* Container should respect viewport width */
.max-w-7xl {
    width: 100%;
    padding: 0;
}

/* Smaller table font on mobile */
@media (max-width: 640px) {
    table {
        font-size: 0.75rem;
    }
    
    table td, table th {
        padding: 0.375rem 0.25rem !important;
    }
    
    table th {
        font-size: 0.625rem;
    }
}

/* =====================================================
   MOBILE DEVICE STYLES (Android / iPhone)
   Ativadas via JS (.is-mobile) + CSS media queries como fallback
   ===================================================== */

/* --- Grid dos cards: sempre 5 colunas (responsiva com scroll se necessário) --- */
.summary-cards {
    grid-auto-flow: column;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 0.75rem;
    min-width: min-content;
}

@media (max-width: 640px) {
    .summary-cards {
        gap: 0.5rem !important;
    }

    .summary-cards .card {
        padding: 0.75rem 0.5rem !important;
    }

    .summary-cards .card p.font-bold {
        font-size: 1rem !important;
        line-height: 1.2;
    }

    .summary-cards .card span[class*="uppercase"] {
        font-size: 0.65rem !important;
    }

    .summary-cards .card p[class*="text-gray"] {
        font-size: 0.65rem !important;
    }

    .summary-cards .w-7 {
        width: 1.5rem !important;
        height: 1.5rem !important;
    }
}

/* --- Grid dos cards mobile: manter 5 colunas --- */
.is-mobile .summary-cards {
    grid-template-columns: repeat(5, minmax(0, 1fr)) !important;
    gap: 0.625rem !important;
}

/* Propriedades: empilha no mobile */
.is-mobile .grid[class*="grid-cols"]:not(.summary-cards) {
    gap: 0.75rem !important;
}

@media (max-width: 480px) {
    .is-mobile .grid[class*="grid-cols"]:not(.summary-cards) {
        grid-template-columns: 1fr !important;
    }
}

/* --- Cards de valores: destaque visual no mobile --- */
.is-mobile .summary-cards .card {
    border-radius: 1rem;
    box-shadow: 0 4px 16px rgba(0,0,0,0.08);
    padding: 1.25rem 1rem 1.25rem 1.25rem !important;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.is-mobile .summary-cards .card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 5px;
    height: 100%;
    border-radius: 1rem 0 0 1rem;
}

/* Cores da barra lateral de cada card */
.is-mobile .summary-cards .card:nth-child(1)::before { background: linear-gradient(180deg, #3b82f6, #2563eb); }
.is-mobile .summary-cards .card:nth-child(2)::before { background: linear-gradient(180deg, #6366f1, #4f46e5); }
.is-mobile .summary-cards .card:nth-child(3)::before { background: linear-gradient(180deg, #ef4444, #dc2626); }
.is-mobile .summary-cards .card:nth-child(4)::before { background: linear-gradient(180deg, #10b981, #059669); }
.is-mobile .summary-cards .card:nth-child(5)::before { background: linear-gradient(180deg, #8b5cf6, #7c3aed); }

/* Valor principal: grande e 100% visível */
.is-mobile .summary-cards .card p.font-bold {
    font-size: 1.5rem !important;
    line-height: 1.3;
    margin-top: 0.375rem;
    white-space: nowrap;
    overflow: visible !important;
    text-overflow: unset !important;
}

/* Ícone do card maior no mobile */
.is-mobile .summary-cards .card .w-7 {
    width: 2.5rem !important;
    height: 2.5rem !important;
    min-width: 2.5rem;
}
.is-mobile .summary-cards .card .w-7 svg {
    width: 1.25rem;
    height: 1.25rem;
}

/* Label do card */
.is-mobile .summary-cards .card span[class*="uppercase"] {
    font-size: 0.8rem !important;
    letter-spacing: 0.04em;
    color: #475569;
    font-weight: 600;
}

/* Descrição do card */
.is-mobile .summary-cards .card p[class*="text-gray-400"] {
    font-size: 0.75rem !important;
    margin-top: 0.375rem;
    color: #94a3b8;
}

/* --- Property cards: empilhados e com padding adequado no mobile --- */
@media (max-width: 640px) {
    .is-mobile .card .font-bold {
        overflow: visible !important;
        text-overflow: unset !important;
        white-space: normal !important;
    }
}

/* --- Tabela por imóvel: legível no mobile --- */
.is-mobile table {
    font-size: 0.8rem;
}

.is-mobile table td,
.is-mobile table th {
    padding: 0.625rem 0.5rem !important;
}

.is-mobile table tr {
    border-bottom: 1px solid #f1f5f9;
}

.is-mobile table tbody tr:active {
    background: #f8fafc;
}

/* --- Gráficos: alinhamento e altura ajustados --- */
.is-mobile #profitChartWrap {
    height: 260px !important;
}

/* Remove margens negativas que desalinham legendas no mobile */
.is-mobile #profitScroll,
.is-mobile #revenueScroll {
    margin-left: 0 !important;
    margin-right: 0 !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
}

/* --- Filtros: selects full-width e touch-friendly --- */
.is-mobile select {
    font-size: 1rem !important;
    padding: 0.75rem 0.75rem !important;
    border-radius: 0.75rem;
    background-color: #f8fafc;
}

/* --- Geral: espaçamento e tipografia mobile --- */
.is-mobile h1 {
    font-size: 1.375rem !important;
    font-weight: 700;
}

.is-mobile h3 {
    font-size: 0.95rem !important;
}
