/**
 * Estilos Responsivos para Mobile
 * Sistema de Escola - Teste de Programação
 */

/* Prevenir overflow horizontal */
html, body {
    overflow-x: hidden;
    width: 100%;
    max-width: 100%;
}

/* Tabelas em formato de cards no mobile */
@media (max-width: 768px) {
    /* Criar cards a partir das linhas da tabela */
    .tabela-container {
        overflow: visible !important;
        -webkit-overflow-scrolling: touch;
        width: 100%;
        max-width: 100%;
        overflow-x: hidden !important;
    }
    
    .tabela-container * {
        max-width: 100%;
    }
    
    .tabela-grid {
        display: block;
        border: none;
        width: 100%;
        max-width: 100%;
        min-width: 0 !important;
        table-layout: fixed;
    }
    
    .tabela-grid thead {
        display: none !important;
    }
    
    .tabela-grid thead tr,
    .tabela-grid thead tr.filtros-linha,
    .tabela-grid thead th,
    .tabela-grid thead th.filtro-celula {
        display: none !important;
    }
    
    .tabela-grid tbody {
        display: block;
        width: 100%;
    }
    
    .tabela-grid tbody tr {
        display: block;
        background: var(--bg-primary);
        border: 1px solid var(--border-color);
        border-radius: 12px;
        margin-bottom: 15px;
        padding: 15px;
        box-shadow: var(--shadow-sm);
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
        overflow: hidden;
    }
    
    .tabela-grid tbody tr:hover {
        box-shadow: var(--shadow-md);
        transform: translateY(-2px);
    }
    
    .tabela-grid tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 12px 0;
        border-bottom: 1px solid var(--border-color);
        border-right: none;
        border-left: none;
        border-top: none;
        text-align: left;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
        word-wrap: break-word;
        overflow-wrap: break-word;
        white-space: normal !important;
    }
    
    .tabela-grid tbody td > * {
        max-width: 100%;
        word-wrap: break-word;
        overflow-wrap: break-word;
        white-space: normal !important;
    }
    
    .tabela-grid tbody td button {
        white-space: nowrap;
    }
    
    .tabela-grid tbody td:last-child {
        border-bottom: none;
        padding-bottom: 0;
    }
    
    .tabela-grid tbody td:first-child {
        padding-top: 0;
    }
    
    .tabela-grid tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-secondary);
        text-transform: uppercase;
        font-size: 0.75em;
        margin-right: 15px;
        flex-shrink: 0;
        min-width: 100px;
        max-width: 40%;
        letter-spacing: 0.5px;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }
    
    .tabela-grid tbody td > *:not(::before) {
        flex: 1;
        min-width: 0;
        word-wrap: break-word;
        overflow-wrap: break-word;
        max-width: 60%;
    }
    
    /* Ocultar linha de filtros em mobile */
    .filtros-linha,
    .filtro-celula,
    .filtro-input {
        display: none !important;
    }
    
    /* Garantir que a tabela não ultrapasse a largura */
    .tabela-grid * {
        max-width: 100%;
    }
    
    /* Ajustar coluna de ações */
    .tabela-grid tbody td.acoes {
        flex-direction: row;
        align-items: center;
        justify-content: flex-end;
        gap: 10px;
        padding-top: 15px;
        border-top: 2px solid var(--border-color);
        margin-top: 10px;
    }
    
    .tabela-grid tbody td.acoes::before {
        content: 'Ações';
        align-self: flex-start;
        margin-right: auto;
    }
    
    .tabela-grid tbody td.acoes .btn-acao {
        flex-shrink: 0;
    }
    
    /* Ajustar toolbar de filtros */
    .tabela-toolbar-filtros {
        padding: 12px 15px;
        margin-bottom: 15px;
        width: 100%;
        box-sizing: border-box;
    }
    
    .busca-global {
        font-size: 16px; /* Evita zoom no iOS */
        width: 100%;
        box-sizing: border-box;
    }
    
    .tabela-toolbar-filtros .btn {
        width: 100%;
        margin-top: 10px;
    }
    
    /* Grid header mobile */
    .grid-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
    }
    
    .grid-header h2 {
        font-size: 1.2em;
    }
    
    .botoes-acao {
        width: 100%;
    }
    
    .botoes-acao .btn {
        width: 100%;
    }
    
    /* Cards do dashboard */
    .dashboard-cards {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .dashboard-card {
        padding: 20px;
    }
    
    .dashboard-card-value {
        font-size: 1.8em;
    }
    
    /* Breadcrumb mobile */
    .dashboard-breadcrumb {
        font-size: 0.85em;
        flex-wrap: wrap;
    }
    
    /* Page title mobile */
    .dashboard-page-title h1 {
        font-size: 1.5em;
    }
    
    .dashboard-page-title p {
        font-size: 0.9em;
    }
    
    /* Grid container mobile */
    .grid-container {
        padding: 20px 15px;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }
    
    /* Botões de ação em mobile */
    .acoes {
        flex-direction: row;
        gap: 8px;
        justify-content: flex-end;
        flex-wrap: wrap;
    }
    
    .btn-acao {
        padding: 8px 15px;
        font-size: 0.85em;
        white-space: nowrap;
        min-width: auto;
    }
    
    /* Garantir que o conteúdo não ultrapasse */
    .dashboard-content {
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
        overflow-x: hidden;
    }
    
    .dashboard-main {
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
        overflow-x: hidden;
    }
    
    /* Formulários mobile */
    .formulario {
        padding: 20px 15px;
    }
    
    .campo {
        margin-bottom: 15px;
    }
    
    /* Modais mobile */
    .modal-container {
        width: 95%;
        max-width: 95%;
        max-height: 90vh;
        margin: 20px auto;
        box-sizing: border-box;
    }
    
    .modal-header {
        padding: 15px 20px;
        box-sizing: border-box;
    }
    
    .modal-header h2 {
        font-size: 1.2em;
        word-wrap: break-word;
    }
    
    .modal-body {
        padding: 20px;
        box-sizing: border-box;
        overflow-y: auto;
        max-height: calc(90vh - 140px);
    }
    
    .modal-footer {
        padding: 15px 20px;
        flex-direction: column-reverse;
        box-sizing: border-box;
    }
    
    .modal-footer .btn {
        width: 100%;
        box-sizing: border-box;
        margin: 5px 0;
    }
    
    /* Formulários dentro de modais */
    .modal-body .campo {
        width: 100%;
        box-sizing: border-box;
    }
    
    .modal-body .campo input,
    .modal-body .campo select,
    .modal-body .campo textarea {
        width: 100%;
        box-sizing: border-box;
    }
}

/* Tabelas muito pequenas - formato ainda mais compacto */
@media (max-width: 480px) {
    .tabela-grid tbody tr {
        padding: 12px;
        margin-bottom: 12px;
    }
    
    .tabela-grid tbody td {
        padding: 8px 0;
        font-size: 0.9em;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        gap: 10px;
    }
    
    .tabela-grid tbody td::before {
        margin-right: 10px;
        margin-bottom: 0;
        min-width: 80px;
        font-size: 0.7em;
    }
    
    .tabela-grid tbody td.acoes {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }
    
    .tabela-grid tbody td.acoes::before {
        margin-bottom: 5px;
    }
    
    .tabela-grid tbody td.acoes .btn-acao {
        width: 100%;
    }
    
    .dashboard-content {
        padding: 15px 10px;
    }
    
    .dashboard-header {
        padding: 0 10px;
        height: 60px;
    }
    
    .dashboard-user-info {
        display: none;
    }
    
    .dashboard-user-avatar {
        width: 35px;
        height: 35px;
        font-size: 1em;
    }
    
    .dashboard-header-icon {
        width: 35px;
        height: 35px;
    }
    
    .dashboard-card {
        padding: 15px;
    }
    
    .dashboard-card-value {
        font-size: 1.5em;
    }
    
    .dashboard-card-title {
        font-size: 0.85em;
    }
    
    .btn-acao {
        padding: 6px 12px;
        font-size: 0.8em;
    }
    
    .tabela-toolbar-filtros {
        padding: 10px 12px;
    }
    
    .toolbar-info {
        font-size: 0.85em;
    }
}

/* Sidebar Mobile */
@media (max-width: 768px) {
    .dashboard-sidebar {
        transform: translateX(-100%);
        z-index: 2000;
    }
    
    .dashboard-sidebar.active {
        transform: translateX(0);
    }
    
    .dashboard-main {
        margin-left: 0;
    }
    
    .sidebar-toggle {
        display: flex !important;
    }
    
    .dashboard-header-left {
        gap: 10px;
    }
    
    .dashboard-search {
        display: none;
    }
    
    .dashboard-header-right {
        gap: 10px;
    }
    
    .dashboard-user-info {
        display: none;
    }
    
    /* Overlay quando sidebar está aberto */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1500;
    }
    
    .sidebar-overlay.active {
        display: block;
    }
}

/* Melhorias para tablets */
@media (min-width: 769px) and (max-width: 1024px) {
    .dashboard-cards {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .dashboard-sidebar {
        width: 220px;
    }
    
    .dashboard-main {
        margin-left: 220px;
    }
    
    .sidebar-toggle {
        display: none;
    }
}

/* Ajustes para telas muito pequenas (iPhone SE, etc) */
@media (max-width: 375px) {
    .dashboard-sidebar {
        width: 100%;
    }
    
    .dashboard-page-title h1 {
        font-size: 1.3em;
    }
    
    .dashboard-card-value {
        font-size: 1.3em;
    }
    
    .btn {
        padding: 10px 15px;
        font-size: 0.9em;
    }
}

