:root {
    --bg: #f5f5f7;
    --surface: #ffffff;
    --primary: #6c5ce7;
    --primary-light: #a29bfe;
    --primary-dark: #5a4bd1;
    --text: #2d3436;
    --text-light: #636e72;
    --border: #e0e0e0;
    --danger: #e74c3c;
    --success: #00b894;
    --warning: #fdcb6e;
    --radius: 12px;
    --shadow: 0 2px 12px rgba(0,0,0,0.06);
    --sidebar-w: 240px;
    --transition: .2s ease;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

/* SIDEBAR */
.sidebar {
    position: fixed;
    left: 0; top: 0;
    width: var(--sidebar-w);
    height: 100vh;
    background: var(--text);
    color: #fff;
    padding: 1.5rem 0;
    z-index: 100;
    transition: transform var(--transition);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 0 1.5rem 1.5rem;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-header h1 {
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.menu-close {
    display: none;
    background: none;
    border: none;
    color: #fff;
    font-size: 1.5rem;
    cursor: pointer;
}

.nav-list {
    list-style: none;
    padding: 0.5rem 0;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1.5rem;
    color: rgba(255,255,255,0.65);
    text-decoration: none;
    font-size: 0.9rem;
    transition: all var(--transition);
}

.nav-link:hover,
.nav-link.active {
    color: #fff;
    background: rgba(255,255,255,0.1);
}

.nav-link.active {
    border-right: 3px solid var(--primary-light);
}

.nav-icon { font-size: 1.1rem; }

/* MAIN */
.main-content {
    margin-left: var(--sidebar-w);
    padding: 0 2rem 2rem;
    min-height: 100vh;
    transition: margin var(--transition);
}

.top-bar {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.5rem 0 1rem;
    position: sticky;
    top: 0;
    background: var(--bg);
    z-index: 50;
}

.top-bar h2 {
    font-size: 1.3rem;
    font-weight: 600;
}

.menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    color: var(--text);
}

.overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 90;
}

/* SECTIONS */
.section { display: none; }
.section.active { display: block; }

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.section-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
}

/* STATS */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
    text-align: center;
}

.stat-number {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--primary);
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-light);
    margin-top: 0.25rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* CARDS */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
    margin-bottom: 1rem;
}

.card h3 {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
}

.cards-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1rem;
}

.item-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
    transition: transform var(--transition);
}

.item-card:hover { transform: translateY(-2px); }

.item-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.5rem;
}

.item-card-header h4 {
    font-size: 1rem;
    font-weight: 600;
}

.item-card-body {
    font-size: 0.85rem;
    color: var(--text-light);
    line-height: 1.5;
}

.item-card-body p { margin-bottom: 0.25rem; }

.item-card-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
}

.badge {
    display: inline-block;
    padding: 0.15rem 0.6rem;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-primary { background: var(--primary-light); color: #fff; }
.badge-success { background: var(--success); color: #fff; }
.badge-warning { background: var(--warning); color: var(--text); }

.tag {
    display: inline-block;
    padding: 0.2rem 0.5rem;
    background: var(--bg);
    border-radius: 6px;
    font-size: 0.75rem;
    margin: 0.15rem;
    color: var(--text-light);
}

/* BUTTONS */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
}

.btn:hover { background: var(--bg); }

.btn-primary {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.btn-primary:hover { background: var(--primary-dark); }

.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }

.btn-success { color: var(--success); border-color: var(--success); }
.btn-success:hover { background: var(--success); color: #fff; }

.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.78rem; }

.btn-icon {
    padding: 0.4rem;
    min-width: 32px;
    justify-content: center;
}

/* FORMS */
.form-group {
    margin-bottom: 1rem;
    flex: 1;
}

.form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    margin-bottom: 0.35rem;
    color: var(--text-light);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.9rem;
    font-family: inherit;
    transition: border var(--transition);
    background: var(--surface);
    color: var(--text);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
}

.form-row {
    display: flex;
    gap: 1rem;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.checkbox-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    max-height: 120px;
    overflow-y: auto;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 8px;
}

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.85rem;
    padding: 0.25rem 0.5rem;
    border-radius: 6px;
    cursor: pointer;
    transition: background var(--transition);
}

.checkbox-group label:hover { background: var(--bg); }

.search-input {
    width: 100%;
    padding: 0.65rem 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.9rem;
    margin-bottom: 1rem;
    background: var(--surface);
    font-family: inherit;
}

.search-input:focus { outline: none; border-color: var(--primary); }

.filter-bar {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.filter-bar select,
.filter-bar input {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.85rem;
    font-family: inherit;
    background: var(--surface);
}

/* EJERCICIOS (inline in rutina form) */
.ejercicio-row {
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
    padding: 0.75rem;
    background: var(--bg);
    border-radius: 8px;
}

.ejercicio-row input,
.ejercicio-row select {
    padding: 0.45rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.82rem;
    font-family: inherit;
    background: var(--surface);
}

.ejercicio-row .ej-nombre { flex: 2; min-width: 120px; }
.ejercicio-row .ej-num { width: 70px; }

.ejercicio-row label {
    font-size: 0.7rem;
    color: var(--text-light);
    display: block;
    margin-bottom: 0.2rem;
}

.ejercicio-row .ej-field { display: flex; flex-direction: column; }

.ejercicios-list { margin-bottom: 1rem; }

/* TABLES */
.table-wrap { overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}

thead { background: var(--text); color: #fff; }

th {
    padding: 0.75rem 1rem;
    font-size: 0.78rem;
    font-weight: 600;
    text-align: left;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

td {
    padding: 0.65rem 1rem;
    font-size: 0.85rem;
    border-bottom: 1px solid var(--border);
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg); }

/* MODAL */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(0,0,0,0.45);
    justify-content: center;
    align-items: flex-start;
    padding: 2rem;
    overflow-y: auto;
}

.modal.open { display: flex; }

.modal-content {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.5rem;
    width: 100%;
    max-width: 480px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.15);
    animation: slideUp .2s ease;
}

.modal-lg { max-width: 640px; }
.modal-xl { max-width: 800px; }

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
}

.modal-header h3 { font-size: 1.1rem; }

.modal-close {
    background: none;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    color: var(--text-light);
    line-height: 1;
}

@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.empty-state {
    text-align: center;
    padding: 2rem;
    color: var(--text-light);
    font-size: 0.9rem;
}

.whatsapp-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    color: #25d366;
    font-size: 0.82rem;
    text-decoration: none;
    font-weight: 600;
}

.whatsapp-btn:hover { text-decoration: underline; }

/* INFO BOX (pago metodo info) */
.info-box {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
    font-size: 0.85rem;
    line-height: 1.5;
}

.info-box strong { color: var(--primary); }

/* ESTADO BADGES */
.badge-al-dia { background: var(--success); color: #fff; }
.badge-debe { background: var(--danger); color: #fff; }
.badge-parcial { background: var(--warning); color: var(--text); }

/* ALUMNO DETAIL */
.detail-section {
    margin-bottom: 1.25rem;
}

.detail-section h4 {
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    padding-bottom: 0.35rem;
    border-bottom: 2px solid var(--primary-light);
    color: var(--primary);
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 0.5rem;
}

.detail-item {
    font-size: 0.85rem;
}

.detail-item span {
    display: block;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.detail-rutina {
    background: var(--bg);
    border-radius: 8px;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
}

.detail-rutina h5 {
    font-size: 0.88rem;
    margin-bottom: 0.35rem;
}

/* EVOLUCION CORPORAL */
.evo-summary {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1rem;
}

.evo-summary-title {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-light);
    margin-bottom: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.evo-bars { display: flex; flex-direction: column; gap: 0.5rem; }

.evo-bar-row { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }

.evo-bar-label {
    width: 60px;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-light);
    flex-shrink: 0;
}

.evo-bar-values {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.82rem;
    min-width: 200px;
}

.evo-val-start { color: var(--text-light); }

.evo-arrow { font-weight: 600; }

.evo-diff {
    font-size: 0.72rem;
    font-weight: 700;
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
}

.evo-good { color: #00b894; }
.evo-good.evo-diff { background: rgba(0, 184, 148, 0.12); }
.evo-bad { color: #e74c3c; }
.evo-bad.evo-diff { background: rgba(231, 76, 60, 0.12); }
.evo-neutral { color: var(--text-light); }
.evo-neutral.evo-diff { background: var(--bg); }

.evo-bar-track {
    flex: 1;
    height: 6px;
    background: var(--bg);
    border-radius: 3px;
    overflow: hidden;
    min-width: 40px;
}

.evo-bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width .3s ease;
}

.evo-bar-fill.evo-good { background: var(--success); }
.evo-bar-fill.evo-bad { background: var(--danger); }
.evo-bar-fill.evo-neutral { background: var(--border); }

/* Timeline cards */
.evo-timeline {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.evo-card {
    background: var(--bg);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    position: relative;
    border-left: 3px solid var(--primary-light);
}

.evo-card-date {
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 0.4rem;
}

.evo-card-date small {
    font-weight: 400;
    color: var(--text-light);
}

.evo-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 0.3rem 0.75rem;
}

.evo-card-item-label {
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.evo-card-item-value {
    font-size: 0.85rem;
    font-weight: 500;
}

.evo-card-del {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    padding: 0.2rem 0.4rem;
    font-size: 0.7rem;
    min-width: auto;
    opacity: 0.4;
    transition: opacity var(--transition);
}

.evo-card:hover .evo-card-del { opacity: 1; }

.medicion-diff {
    font-size: 0.7rem;
    font-weight: 700;
    margin-left: 2px;
    border-radius: 4px;
    padding: 0 3px;
}

.medicion-up { color: #e74c3c; background: rgba(231, 76, 60, 0.1); }
.medicion-down { color: #00b894; background: rgba(0, 184, 148, 0.1); }
.medicion-neutral { color: var(--text-light); background: var(--bg); }

@media (max-width: 768px) {
    .evo-bar-values { min-width: unset; flex-wrap: wrap; }
    .evo-card-grid { grid-template-columns: repeat(3, 1fr); }
}

.item-card.clickable { cursor: pointer; }
.item-card.clickable:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(108, 92, 231, 0.15);
}

/* LOGIN */
.login-screen {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.login-screen.hidden { display: none; }

.login-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 2.5rem 2rem;
    width: 100%;
    max-width: 380px;
    box-shadow: var(--shadow);
    text-align: center;
}

.login-card h1 {
    color: var(--primary);
    font-size: 1.8rem;
    margin-bottom: 0.4rem;
}

.login-card > p {
    color: var(--text-light);
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
}

.login-card .form-group { text-align: left; }

.auth-msg {
    font-size: 0.83rem;
    margin-bottom: 0.75rem;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    display: none;
}

.auth-error {
    color: var(--danger);
    background: rgba(231, 76, 60, 0.08);
}

.auth-success {
    color: var(--success);
    background: rgba(0, 184, 148, 0.08);
}

.auth-toggle {
    margin-top: 1.25rem;
    font-size: 0.85rem;
    color: var(--text-light);
}

.auth-toggle a {
    color: var(--primary);
    font-weight: 600;
    text-decoration: none;
}

.auth-toggle a:hover { text-decoration: underline; }

/* SIDEBAR FOOTER */
.sidebar-footer {
    padding: 1rem 1.5rem;
    margin-top: auto;
    border-top: 1px solid rgba(255,255,255,0.1);
}

.sidebar-user {
    font-size: 0.75rem;
    color: rgba(255,255,255,0.5);
    margin-bottom: 0.5rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.btn-logout {
    width: 100%;
    color: rgba(255,255,255,0.6);
    border-color: rgba(255,255,255,0.15);
    background: transparent;
    font-size: 0.8rem;
    justify-content: center;
}

.btn-logout:hover {
    background: rgba(255,255,255,0.1);
    color: #fff;
}

/* LOADING */
.loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 999;
    background: var(--bg);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    transition: opacity .3s ease;
}

.loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay p {
    font-size: 0.95rem;
    color: var(--text-light);
}

/* RESPONSIVE */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .menu-close { display: block; }
    .menu-toggle { display: block; }
    .overlay.open { display: block; }

    .main-content {
        margin-left: 0;
        padding: 0 1rem 1rem;
    }

    .form-row { flex-direction: column; gap: 0; }

    .cards-list { grid-template-columns: 1fr; }

    .modal { padding: 1rem; }

    .ejercicio-row { flex-direction: column; align-items: stretch; }
    .ejercicio-row .ej-num { width: 100%; }
}
