:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --secondary-color: #64748b;
    --accent-color: #ec4899;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --info-color: #06b6d4;
    --warning-color: #f59e0b;
    --dark: #0f172a;
    --light: #f8fafc;
    --border-color: #e2e8f0;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --glass: rgba(255, 255, 255, 0.7);
    --glass-border: rgba(255, 255, 255, 0.5);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    line-height: 1.6;
    color: var(--text-main);
    background-color: var(--light);
    overflow-x: hidden;
}

/* Background Gradients */
.bg-gradient-mesh {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: -1;
    background:
        radial-gradient(at 0% 0%, hsla(253, 16%, 7%, 1) 0, transparent 50%),
        radial-gradient(at 50% 0%, hsla(225, 39%, 30%, 1) 0, transparent 50%),
        radial-gradient(at 100% 0%, hsla(339, 49%, 30%, 1) 0, transparent 50%);
    background-size: cover;
    opacity: 0.05;
}

/* Container & Layout */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

/* Navbar */
.navbar {
    background-color: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.5);
    padding: 1rem 0;
    margin-bottom: 2rem;
    position: sticky;
    top: 0;
    z-index: 50;
}

.navbar .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.navbar-brand {
    font-size: 1.5rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--accent-color) 100%);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-decoration: none;
}

.navbar-menu {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.navbar-user {
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 500;
}

/* Main Content & Footer */
.main-content {
    min-height: calc(100vh - 200px);
    padding: 0.5rem 0;
}

.footer {
    background-color: white;
    padding: 2rem 0;
    text-align: center;
    color: var(--text-muted);
    margin-top: 3rem;
    border-top: 1px solid var(--border-color);
}

/* Alerts */
.alert {
    padding: 1rem;
    margin-bottom: 1.5rem;
    border-radius: 8px;
    border-left: 4px solid;
}

.alert ul {
    margin-left: 1.5rem;
}

.alert-success {
    background-color: #d1fae5;
    border-color: var(--success-color);
    color: #065f46;
}

.alert-danger {
    background-color: #fee2e2;
    border-color: var(--danger-color);
    color: #991b1b;
}

.alert-info {
    background-color: #cffafe;
    border-color: var(--info-color);
    color: #164e63;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.625rem 1.25rem;
    font-size: 1rem;
    font-weight: 600;
    text-align: center;
    text-decoration: none;
    border: 2px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
    border: none;
    box-shadow: 0 4px 14px 0 rgba(99, 102, 241, 0.39);
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.23);
}

.btn-secondary {
    background-color: var(--secondary-color);
    color: white;
}

.btn-secondary:hover {
    background-color: #475569;
}

.btn-block {
    display: block;
    width: 100%;
}

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.875rem;
}

/* Auth */
.auth-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: calc(100vh - 300px);
}

.auth-card {
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    padding: 2.5rem;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.5);
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    width: 100%;
    max-width: 450px;
}

.auth-card h1 {
    margin-bottom: 0.5rem;
    color: var(--dark);
}

/* Forms */
.text-muted {
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--dark);
}

.form-control {
    width: 100%;
    padding: 0.75rem;
    font-size: 1rem;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    transition: border-color 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
}

.form-control-lg {
    padding: 1rem;
    font-size: 1.25rem;
    font-weight: 600;
    letter-spacing: 2px;
}

.form-text {
    display: block;
    margin-top: 0.375rem;
    font-size: 0.875rem;
    color: var(--text-muted);
}

.form-check {
    display: flex;
    align-items: center;
}

.form-check-input {
    width: 1.25rem;
    height: 1.25rem;
    margin-right: 0.5rem;
    cursor: pointer;
}

.form-check-label {
    margin-bottom: 0;
    cursor: pointer;
}

.text-center {
    text-align: center;
}

.mt-3 {
    margin-top: 1.5rem;
}

/* Dashboard */
.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.dashboard-header h1 {
    margin: 0;
}

.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.empty-state h2 {
    color: var(--text-muted);
    margin-bottom: 1rem;
}

.challenges-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1.5rem;
}

/* Challenge Card */
.challenge-card {
    background: white;
    border-radius: 16px;
    border: 1px solid rgba(226, 232, 240, 0.8);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    overflow: hidden;
    transition: all 0.3s ease;
}

.challenge-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    border-color: rgba(99, 102, 241, 0.3);
}

.challenge-header {
    padding: 1.25rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.challenge-header h3 {
    margin: 0;
    font-size: 1.25rem;
}

.challenge-body {
    padding: 1.25rem;
}

.challenge-body p {
    margin-bottom: 0.75rem;
}

.challenge-body code {
    background-color: var(--light);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-family: monospace;
    font-size: 1.1rem;
    font-weight: 600;
}

.challenge-footer {
    padding: 1.25rem;
    border-top: 1px solid var(--border-color);
}

/* Badges */
.badge {
    display: inline-block;
    padding: 0.375rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 9999px;
    text-transform: uppercase;
}

.badge-success {
    background-color: #d1fae5;
    color: #065f46;
}

.badge-secondary {
    background-color: #e2e8f0;
    color: #475569;
}

.badge-info {
    background-color: #cffafe;
    color: #164e63;
}

/* Modals */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal.show {
    display: flex;
}

.modal-content {
    background-color: white;
    border-radius: 12px;
    width: 100%;
    max-width: 420px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.2);
}

.modal-header {
    padding: 0.875rem 1rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    background: white;
    z-index: 1;
    border-radius: 12px 12px 0 0;
}

.modal-header h2,
.modal-title {
    margin: 0;
    font-size: 1rem !important;
    font-weight: 700;
    color: var(--dark);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: calc(100% - 2rem);
}

.modal-body {
    padding: 0.875rem 1rem;
}

.modal-footer {
    padding: 0.875rem 1rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

.close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-muted);
    line-height: 1;
    flex-shrink: 0;
    padding: 0.1rem 0.25rem;
    border-radius: 4px;
    transition: background 0.15s;
}

.close:hover {
    color: var(--dark);
    background: var(--light);
}

/* Móvil: bottom-sheet (desliza desde abajo, ancho completo) */
@media (max-width: 480px) {
    .modal {
        align-items: flex-end;
        padding: 0;
    }

    .modal-content {
        border-radius: 16px 16px 0 0;
        max-width: 100%;
        max-height: 85vh;
        width: 100%;
        animation: slideUp 0.25s ease;
    }

    .modal-header {
        border-radius: 16px 16px 0 0;
    }

    /* Indicador de arrastre (barra visual en top de la sheet) */
    .modal-content::before {
        content: '';
        display: block;
        width: 40px;
        height: 4px;
        background: #d1d5db;
        border-radius: 2px;
        margin: 8px auto 4px;
    }
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
}

/* Join Challenge */
.join-challenge-container {
    max-width: 600px;
    margin: 0 auto;
}

.join-challenge-card {
    background: white;
    padding: 2.5rem;
    border-radius: 12px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    margin-bottom: 2rem;
}

.join-challenge-card h2 {
    margin-bottom: 0.5rem;
}

.info-box {
    background: white;
    padding: 2rem;
    border-radius: 12px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.info-box h3 {
    margin-bottom: 1rem;
    color: var(--primary-color);
}

.info-box ol {
    margin-left: 1.5rem;
}

.info-box li {
    margin-bottom: 0.75rem;
}

/* Challenge Show */
.challenge-show-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 2rem;
    padding: 1.5rem;
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.challenge-show-header h1 {
    margin: 0 0 0.5rem 0;
}

.challenge-meta {
    display: flex;
    gap: 1rem;
    align-items: center;
    flex-wrap: wrap;
}

.participants-table-container {
    background: white;
    padding: 2rem;
    border-radius: 12px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    margin-bottom: 2rem;
}

.participants-table-container h2 {
    margin-bottom: 1.5rem;
}

.participants-table {
    width: 100%;
    border-collapse: collapse;
}

.participants-table thead {
    background-color: var(--light);
}

.participants-table th {
    padding: 1rem;
    text-align: left;
    font-weight: 600;
    color: var(--dark);
    border-bottom: 2px solid var(--border-color);
}

.participants-table td {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.participants-table tbody tr:hover {
    background-color: var(--light);
}

.participants-table .position {
    width: 80px;
    font-weight: 600;
    font-size: 1.1rem;
}

.participants-table .medal {
    font-size: 1.5rem;
}

.participants-table .student-name {
    font-weight: 500;
}

.participants-table .points {
    width: 100px;
}

.points-badge {
    display: inline-block;
    background-color: var(--primary-color);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 9999px;
    font-weight: 700;
    font-size: 1.1rem;
}

.participants-table .actions {
    width: 150px;
}

.back-link {
    margin-top: 2rem;
}

/* Responsive */
@media (max-width: 768px) {
    .navbar .container {
        flex-direction: column;
        gap: 1rem;
    }

    .dashboard-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .challenge-show-header {
        flex-direction: column;
        gap: 1rem;
    }

    .challenges-grid {
        grid-template-columns: 1fr;
    }

    .participants-table {
        font-size: 0.875rem;
    }

    .participants-table th,
    .participants-table td {
        padding: 0.75rem 0.5rem;
    }
}

/* Participants Grid Layout */
.participants-grid-container {
    margin-bottom: 2rem;
}

.participants-grid-container h2 {
    margin-bottom: 1.5rem;
    font-size: 1.5rem;
    color: var(--dark);
}

.participants-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1.5rem;
}

.participant-card {
    background: white;
    border-radius: 16px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    transition: all 0.3s ease;
    position: relative;
    border: 1px solid var(--border-color);
}

.participant-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    border-color: var(--primary-color);
}

/* Top Ranks Styling */
.participant-card.top-rank {
    border: 2px solid transparent;
}

.participant-card.rank-1 {
    border-color: #fbbf24;
    background: linear-gradient(to bottom right, #fff, #fffbeb);
}

.participant-card.rank-2 {
    border-color: #94a3b8;
    background: linear-gradient(to bottom right, #fff, #f8fafc);
}

.participant-card.rank-3 {
    border-color: #b45309;
    background: linear-gradient(to bottom right, #fff, #fff7ed);
}

.card-header {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 1rem;
    position: relative;
}

.position-badge {
    font-size: 2rem;
    line-height: 1;
}

.rank-number {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-muted);
    background: var(--light);
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
}

.current-user-badge {
    position: absolute;
    top: -10px;
    right: -10px;
    background-color: var(--info-color);
    color: white;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
}

.student-info {
    margin-bottom: 1rem;
    width: 100%;
}

.student-name {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--dark);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin: 0;
}

.points-display {
    margin-bottom: 1.25rem;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.points-value {
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--primary-color);
    line-height: 1;
}

.points-label {
    font-size: 0.875rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-top: 0.25rem;
}

.card-actions {
    width: 100%;
    margin-top: auto;
}

.btn-point-add {
    width: 100%;
    background-color: var(--success-color);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 0.5rem;
    cursor: pointer;
    transition: background-color 0.2s;
    display: flex;
    justify-content: center;
    align-items: center;
}

.btn-point-add:hover {
    background-color: #059669;
}

.plus-icon {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1;
}

@media (max-width: 480px) {
    .participants-grid {
        grid-template-columns: 1fr 1fr;
        gap: 1rem;
    }

    .participant-card {
        padding: 1rem;
    }

    .points-value {
        font-size: 2rem;
    }
}