/* ============================================
   Sistema de Academia - Estilos Principais
   Tema: Preto, Cinza Escuro, Azul
   ============================================ */

:root {
    --bg-dark: #0d0d0d;
    --bg-card: #1a1a2e;
    --bg-sidebar: #121212;
    --bg-hover: #16213e;
    --primary: #0d6efd;
    --primary-dark: #0a58ca;
    --text-light: #e9ecef;
    --text-muted: #c2c9d1;
    --border-color: rgba(255, 255, 255, 0.08);
    --sidebar-width: 260px;
    --topbar-height: 60px;
}

[data-theme="light"] {
    --bg-dark: #f4f5f7;
    --bg-card: #ffffff;
    --bg-sidebar: #ffffff;
    --bg-hover: #eef1f6;
    --primary: #0d6efd;
    --primary-dark: #0a58ca;
    --text-light: #1c1f26;
    --text-muted: #5d6470;
    --border-color: rgba(0, 0, 0, 0.08);
}

/* Garante que qualquer texto "cinza" do Bootstrap use a variável de tema
   (que já tem contraste calculado para fundo escuro ou claro) em vez da
   cor cinza fixa do Bootstrap, que ficava ilegível no modo escuro */
.text-muted,
.text-secondary,
small,
.small,
.form-text {
    color: var(--text-muted) !important;
}

/* Corrige texto ilegível no autofill do navegador (CPF/senha), que mantém
   o fundo claro do autofill mas herdava cor de texto clara do tema escuro */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
textarea:-webkit-autofill,
select:-webkit-autofill {
    -webkit-text-fill-color: var(--text-light) !important;
    -webkit-box-shadow: 0 0 0px 1000px var(--bg-dark) inset !important;
    box-shadow: 0 0 0px 1000px var(--bg-dark) inset !important;
    caret-color: var(--text-light);
    transition: background-color 5000s ease-in-out 0s;
}

/* Badges: garante contraste mínimo independente do tema */
.badge.bg-secondary { color: #ffffff !important; }
.badge.bg-light { color: #212529 !important; }
.badge.bg-warning { color: #212529 !important; }

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-light);
    min-height: 100vh;
}

/* ========== Layout ========== */
.wrapper {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 1000;
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 1.5rem;
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--primary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

.sidebar-header i {
    font-size: 1.5rem;
}

.sidebar-nav {
    list-style: none;
    padding: 1rem 0;
    flex: 1 1 auto;
    /* Rola o menu quando há muitos itens, em vez de empurrar o "Sair" para
       fora da tela. min-height:0 é necessário para o filho flex poder encolher
       e ativar o scroll. */
    overflow-y: auto;
    min-height: 0;
}

.sidebar-nav li a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.85rem 1.5rem;
    color: var(--text-muted);
    text-decoration: none;
    transition: all 0.2s;
    border-left: 3px solid transparent;
}

.sidebar-nav li a:hover,
.sidebar-nav li a.active {
    background: var(--bg-hover);
    color: var(--text-light);
    border-left-color: var(--primary);
}

.sidebar-nav li a i {
    font-size: 1.1rem;
    width: 24px;
    text-align: center;
}

.sidebar-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    /* Sempre visível no rodapé; nunca some quando o menu rola. */
    flex-shrink: 0;
}

.sidebar-footer a {
    color: var(--text-muted);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.sidebar-footer a:hover {
    color: #dc3545;
}

.content {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-height: 100vh;
    transition: margin-left 0.3s ease;
}

.topbar {
    height: var(--topbar-height);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    gap: 1rem;
    position: sticky;
    top: 0;
    z-index: 999;
}

.sidebar-toggle {
    color: var(--text-light) !important;
    font-size: 1.5rem;
    padding: 0;
}

#themeToggle {
    color: var(--text-light) !important;
    font-size: 1.25rem;
    padding: 0;
    margin-left: auto;
}

.topbar-search {
    flex: 1;
    max-width: 400px;
}

.search-box {
    position: relative;
}

.search-box i {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

.search-box input {
    width: 100%;
    padding: 0.5rem 1rem 0.5rem 2.5rem;
    background: var(--bg-dark);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-light);
    outline: none;
}

.search-box input:focus {
    border-color: var(--primary);
}

.search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    margin-top: 4px;
    display: none;
    max-height: 300px;
    overflow-y: auto;
    z-index: 1001;
}

.search-results.active {
    display: block;
}

.search-results a {
    display: block;
    padding: 0.75rem 1rem;
    color: var(--text-light);
    text-decoration: none;
    border-bottom: 1px solid var(--border-color);
}

.search-results a:hover {
    background: var(--bg-hover);
}

.topbar-user {
    margin-left: auto;
    color: var(--text-muted);
    max-width: 40vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.main-content {
    padding: 1.5rem;
}

/* ========== Cards ========== */
.card-dark {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    color: var(--text-light);
}

.card-dark .card-header {
    background: rgba(0, 0, 0, 0.2);
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
}

.page-header {
    margin-bottom: 1.5rem;
}

.page-header h2 {
    font-size: 1.75rem;
    font-weight: 700;
}

.page-header h2 i {
    color: var(--primary);
    margin-right: 0.5rem;
}

/* ========== Stat Cards ========== */
.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.25rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: transform 0.2s;
}

.stat-card:hover {
    transform: translateY(-2px);
}

.stat-icon {
    width: 56px;
    height: 56px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.stat-primary .stat-icon { background: rgba(13, 110, 253, 0.15); color: var(--primary); }
.stat-success .stat-icon { background: rgba(25, 135, 84, 0.15); color: #198754; }
.stat-danger .stat-icon { background: rgba(220, 53, 69, 0.15); color: #dc3545; }
.stat-info .stat-icon { background: rgba(13, 202, 240, 0.15); color: #0dcaf0; }

.stat-info h3 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0;
}

.stat-info p {
    color: var(--text-muted);
    margin-bottom: 0;
    font-size: 0.875rem;
}

/* ========== Alert Items ========== */
.alert-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.03);
}

.alert-item i {
    font-size: 1.5rem;
}

.alert-item strong {
    display: block;
    font-size: 1.25rem;
}

.alert-item span {
    color: var(--text-muted);
    font-size: 0.875rem;
}

.alert-warning { border-left: 4px solid #ffc107; }
.alert-warning i { color: #ffc107; }
.alert-info-custom { border-left: 4px solid #0dcaf0; }
.alert-info-custom i { color: #0dcaf0; }
.alert-danger-custom { border-left: 4px solid #dc3545; }
.alert-danger-custom i { color: #dc3545; }
.alert-ok { border-left: 4px solid #198754; }
.alert-ok i { color: #198754; }

/* ========== Tables ========== */
.table-dark {
    --bs-table-bg: transparent;
    --bs-table-color: var(--text-light);
    --bs-table-border-color: var(--border-color);
    --bs-table-hover-bg: rgba(255, 255, 255, 0.03);
}

.table-dark thead th {
    background: rgba(0, 0, 0, 0.3);
    font-weight: 600;
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom-width: 1px;
}

.table-dark thead th a {
    color: var(--text-light);
    text-decoration: none;
}

.table-danger {
    --bs-table-bg: rgba(220, 53, 69, 0.1) !important;
}

/* ========== Forms ========== */
.form-control, .form-select {
    background: var(--bg-dark);
    border: 1px solid var(--border-color);
    color: var(--text-light);
}

.form-control:focus, .form-select:focus {
    background: var(--bg-dark);
    border-color: var(--primary);
    color: var(--text-light);
    box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.15);
}

.form-label {
    font-weight: 500;
    font-size: 0.875rem;
}

/* ========== Avatar / Photos ========== */
.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
}

.avatar-placeholder {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--bg-hover);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
}

.profile-photo {
    width: 150px;
    height: 150px;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid var(--primary);
}

.profile-photo-placeholder {
    width: 150px;
    height: 150px;
    border-radius: 50%;
    background: var(--bg-hover);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 4rem;
    color: var(--text-muted);
    margin: 0 auto;
}

.profile-info p {
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.profile-info i {
    color: var(--primary);
    width: 20px;
}

/* ========== Tabs ========== */
.nav-tabs-dark {
    border-bottom-color: var(--border-color);
}

.nav-tabs-dark .nav-link {
    color: var(--text-muted);
    border: none;
    border-bottom: 2px solid transparent;
    background: transparent;
}

.nav-tabs-dark .nav-link.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    background: transparent;
}

/* ========== Login Page ========== */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--bg-dark) 0%, var(--bg-card) 50%, var(--bg-hover) 100%);
}

.login-container {
    width: 100%;
    max-width: 420px;
    padding: 1rem;
}

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 2.5rem;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.login-header {
    text-align: center;
    margin-bottom: 2rem;
}

.login-header i {
    font-size: 3rem;
    color: var(--primary);
}

.login-header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    margin-top: 0.5rem;
}

.login-header p {
    color: var(--text-muted);
}

/* ========== Treino Cards ========== */
.treino-card {
    transition: transform 0.2s, box-shadow 0.2s;
}

.treino-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
}

/* ========== Pagination ========== */
.pagination .page-link {
    background: var(--bg-card);
    border-color: var(--border-color);
    color: var(--text-light);
}

.pagination .page-item.active .page-link {
    background: var(--primary);
    border-color: var(--primary);
}

/* ========== Buttons ========== */
.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
}

.btn-primary:hover {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
}

/* ========== Responsive ========== */
html, body {
    overflow-x: hidden;
    max-width: 100%;
}

.page-header.d-flex {
    flex-wrap: wrap;
    gap: 0.75rem;
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.active {
        transform: translateX(0);
    }

    .content {
        margin-left: 0;
        overflow-x: hidden;
        max-width: 100vw;
    }

    .topbar-search {
        max-width: 200px;
    }

    .stat-card {
        padding: 1rem;
    }

    .stat-info h3 {
        font-size: 1.25rem;
    }

    /* Cabeçalhos com botão ao lado quebram a linha em vez de
       empurrar a página pra fora da tela (forçando zoom/scroll lateral) */
    .page-header.d-flex {
        flex-direction: column;
        align-items: stretch !important;
    }

    .page-header.d-flex > a,
    .page-header.d-flex > button,
    .page-header.d-flex > form {
        width: 100%;
    }

    /* Botões/badges/forms que ficam em linha (d-flex) também quebram
       em telas pequenas, evitando overflow horizontal */
    .card-body .d-flex.justify-content-between {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .card-body,
    .card-header {
        padding: 0.85rem;
    }

    .modal-dialog {
        margin: 0.5rem;
    }

    table.table {
        font-size: 0.85rem;
    }

    h2 {
        font-size: 1.35rem;
    }
}

/* ========== Scrollbar ========== */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg-dark);
}

::-webkit-scrollbar-thumb {
    background: var(--bg-hover);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--primary);
}
