:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --bg-body: #f3f4f6;
    --bg-card: #ffffff;
    --text-main: #1f2937;
    --text-muted: #6b7280;
    --border-color: #e5e7eb;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --sidebar-width: 260px;
    --header-height: 64px;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --btn-min-height: 44px;
    --safe-padding: 1rem;
    --login-gradient: linear-gradient(135deg, #2563eb 0%, #10b981 100%);
}

/* 1. RESET & FUNDAMENTALS (Mobile-First) */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    /* Melhora toque no mobile */
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    line-height: 1.5;
    overflow-x: hidden;
    min-height: 100vh;
}

/* 2. LAYOUT ESTRUTURAL (Base Mobile) */

/* Sidebar oculto por padrão (Mobile) */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-card);
    border-right: 1px solid var(--border-color);
    position: fixed;
    height: 100%;
    z-index: 1000;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar.active {
    transform: translateX(0);
    box-shadow: 10px 0 30px rgba(0, 0, 0, 0.15);
}

.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    z-index: 990;
    display: none;
    backdrop-filter: blur(2px);
}

/* Header Fixo e Responsivo */
.header {
    height: var(--header-height);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--safe-padding);
    position: sticky;
    top: 0;
    z-index: 500;
}

#menu-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--btn-min-height);
    height: var(--btn-min-height);
    background: #f8fafc;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-main);
}

.main-content {
    flex: 1;
    margin-left: 0;
    display: flex;
    flex-direction: column;
    min-width: 0;
    /* Impede quebra de layout por conteúdo largo */
}

/* 3. COMPONENTES (Fluidez) */

.p-2rem {
    padding: var(--safe-padding);
}

/* Grid de Cards - 1 coluna por padrão */
.grid-cards {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
    margin-bottom: 2rem;
}

.card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

.card-title {
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 500;
    text-transform: uppercase;
    margin-bottom: 0.5rem;
}

.card-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-main);
}

/* Botões e Inputs Touch-Friendly */
.btn-primary,
.btn-secondary,
.form-control,
select,
.nav-item {
    min-height: var(--btn-min-height);
    font-size: 1rem;
    /* Evita zoom automático no iOS */
    padding: 0.5rem 1rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    width: 100%;
    /* Botões full-width no mobile por padrão */
}

.btn-primary {
    background: var(--primary-color);
    color: white;
    border: none;
}

.btn-icon {
    width: var(--btn-min-height);
    padding: 0;
}

/* 4. TABELAS ADAPTÁVEIS (Transformam em Cards no Mobile) */
.table-container {
    background: var(--bg-card);
    border-radius: 12px;
    border: 1px solid var(--border-color);
    overflow: hidden;
}

.table-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.table-header h3 {
    font-size: 1rem;
}

/* Mobile Table Rules */
table {
    width: 100%;
    border-collapse: collapse;
}

thead {
    display: none;
}

/* Esconde cabeçalho da tabela no mobile */

tr {
    display: block;
    border-bottom: 4px solid var(--bg-body);
    padding: 0.2rem 0;
}

td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.4rem 1rem;
    border-bottom: 1px solid #f8fafc;
    text-align: right;
    font-size: 0.9rem;
}

td:last-child {
    border-bottom: none;
}

/* Adiciona legendas via pseudo-elementos */
td::before {
    content: attr(data-label);
    font-weight: 700;
    color: var(--text-muted);
    font-size: 0.7rem;
    text-transform: uppercase;
    text-align: left;
}

/* 5. BREAKPOINTS (Aprimoramentos para Telas Maiores) */

/* TABLETS E DESKTOPS PEQUENOS (>= 768px) */
@media (min-width: 768px) {
    :root {
        --safe-padding: 2rem;
    }

    .grid-cards {
        grid-template-columns: repeat(2, 1fr);
        gap: 1.5rem;
    }

    .btn-primary,
    .btn-secondary {
        width: auto;
    }

    /* Botões voltam ao tamanho natural */
}

/* DESKTOPS (>= 1024px) */
@media (min-width: 1024px) {
    .sidebar {
        transform: translateX(0);
    }

    /* Sidebar sempre visível */

    .main-content {
        margin-left: var(--sidebar-width);
    }

    #menu-toggle {
        display: none;
    }

    /* Esconde hambúrguer no PC */

    .grid-cards {
        grid-template-columns: repeat(4, 1fr);
    }

    /* Restaura visual de tabela tradicional no Computador */
    thead {
        display: table-header-group;
    }

    tr {
        display: table-row;
    }

    td {
        display: table-cell;
        text-align: left;
        border-bottom: 1px solid var(--border-color);
    }

    td::before {
        display: none;
    }
}

/* 6. CLASSES AUXILIARES */
/* Força visualização horizontal (tabela real) mesmo no mobile */
.table-horizontal {
    display: table !important;
}

.table-horizontal thead {
    display: table-header-group !important;
}

.table-horizontal tr {
    display: table-row !important;
    border-bottom: 1px solid var(--border-color) !important;
}

.table-horizontal td,
.table-horizontal th {
    display: table-cell !important;
    text-align: left !important;
    padding: 12px 15px !important;
    border-bottom: 1px solid var(--border-color) !important;
}

.table-horizontal td::before {
    display: none !important;
}

.badge {
    padding: 0.25rem 0.6rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-success {
    background: #d1fae5;
    color: #065f46;
}

.badge-warning {
    background: #fef3c7;
    color: #92400e;
}

/* Sidebar Nav */
.brand {
    padding: 1.5rem 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-bottom: 1px solid var(--border-color);
}

.brand img {
    max-width: 100%;
    height: auto;
    display: block;
    cursor: pointer;
}

.nav-menu {
    padding: 1.5rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.nav-item {
    color: var(--text-muted);
    text-decoration: none;
    justify-content: flex-start;
}

.nav-item:hover,
.nav-item.active {
    background: #eff6ff;
    color: var(--primary-color);
}

.nav-item i {
    margin-right: 0.75rem;
    width: 20px;
    text-align: center;
}

.nav-group-title {
    font-size: 0.7rem;
    text-transform: uppercase;
    color: #94a3b8;
    font-weight: 700;
    padding: 0.5rem 1rem;
    margin-top: 1rem;
}

/* 7. FORMULÁRIOS E GRIDS FLUIDOS */
.registration-container {
    padding: var(--safe-padding);
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
}

@media (min-width: 768px) {
    .form-grid-2 {
        grid-template-columns: repeat(2, 1fr);
    }

    .form-grid-3 {
        grid-template-columns: repeat(3, 1fr);
    }
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-main);
}

.form-control {
    width: 100%;
    border: 1px solid var(--border-color);
    padding: 0.75rem;
    border-radius: 8px;
    background: #fff;
    transition: border-color 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

textarea.form-control {
    min-height: 100px;
    resize: vertical;
}

/* Ajustes para a Tabela de Frequência dentro do formulário */
.attendance-table {
    margin-top: 1.5rem;
    border-top: 1px solid var(--border-color);
}

.attendance-row-mobile {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
}

.attendance-controls-mobile {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.label-pill {
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    background: var(--bg-body);
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-weight: 500;
}

.label-pill input[type="checkbox"] {
    display: none;
}

.label-pill.active-warning {
    background: var(--warning);
    color: #fff;
    border-color: var(--warning);
}

.label-pill.active-primary {
    background: var(--primary-color);
    color: #fff;
    border-color: var(--primary-color);
}

/* 8. MODAIS RESPONSIVOS */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    padding: var(--safe-padding);
    backdrop-filter: blur(4px);
}

.modal-content {
    background: var(--bg-card);
    border-radius: 16px;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    animation: modalSlideUp 0.3s ease-out;
}

@keyframes modalSlideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    padding: 1.25rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.125rem;
}

.modal-body {
    padding: 1.25rem;
}

.modal-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.btn-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0.5rem;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-close:hover {
    color: var(--danger);
}

/* 9. UTILITÁRIOS PARA TABELAS LARGAS */
.horizontal-scroll-wrapper {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 8px;
    background: var(--bg-card);
    margin-bottom: 1rem;
}

.table-matrix {
    min-width: 1200px;
    /* Garante que a matriz tenha espaço para scroll */
    border-collapse: collapse;
}

.sticky-col {
    position: sticky;
    left: 0;
    background: var(--bg-card);
    z-index: 10;
    box-shadow: 2px 0 5px rgba(0, 0, 0, 0.05);
}

thead .sticky-col {
    z-index: 20;
}

@media (max-width: 767px) {

    .table-matrix td,
    .table-matrix th {
        padding: 0.5rem !important;
        font-size: 0.8rem !important;
        text-align: center !important;
    }

    .table-matrix td:first-child,
    .table-matrix th:first-child {
        text-align: left !important;
    }
}

/* 10. PREMIUM LOGIN SCREEN */
.login-wrapper {
    display: flex;
    height: 100vh;
    width: 100vw;
    align-items: center;
    justify-content: center;
    background: var(--bg-body);
    background-image:
        radial-gradient(at 0% 0%, rgba(37, 99, 235, 0.1) 0, transparent 50%),
        radial-gradient(at 100% 100%, rgba(16, 185, 129, 0.1) 0, transparent 50%);
    position: fixed;
    top: 0;
    left: 0;
    z-index: 9999;
    padding: 1.5rem;
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    padding: 3rem 2.5rem;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.5);
    text-align: center;
    animation: loginFadeIn 0.6s ease-out;
}

@keyframes loginFadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.login-logo-section {
    margin-bottom: 2.5rem;
}

.login-logo {
    max-width: 220px;
    height: auto;
    /* Removido drop-shadow para evitar borda retangular se o PNG não for 100% transparente */
    animation: logoFloat 3s ease-in-out infinite;
    mix-blend-mode: multiply;
    /* Tenta misturar se o fundo do logo for branco e o card for quase branco */
}

@keyframes logoFloat {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-5px);
    }
}

.login-card form {
    text-align: left;
}

.login-card .form-group {
    margin-bottom: 1.5rem;
}

.login-card label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text-main);
}

.login-card .form-control {
    background: #f8fafc;
    border: 1.5px solid var(--border-color);
    transition: all 0.2s;
}

.login-card .form-control:focus {
    background: #fff;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1);
}

.login-card .btn-primary {
    margin-top: 1rem;
    background: var(--login-gradient);
    border: none;
    font-weight: 700;
    letter-spacing: 0.5px;
    box-shadow: 0 4px 6px rgba(37, 99, 235, 0.2);
}

.login-card .btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(37, 99, 235, 0.3);
}

.login-error-msg {
    color: var(--danger);
    margin-top: 1.25rem;
    font-size: 0.875rem;
    font-weight: 500;
    display: none;
    padding: 0.75rem;
    background: rgba(239, 68, 68, 0.1);
    border-radius: 8px;
}