/* ========================================
   ROOT VARIABLES
   ======================================== */

:root {
    /* Light theme */
    --bg-primary: #f0f2f5;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --accent-primary: #3b82f6;
    --accent-secondary: #8b5cf6;
    --accent-success: #10b981;
    --accent-warning: #f59e0b;
    --accent-danger: #ef4444;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.1);
    --hover-bg: #f8fafc;
    --table-stripe: #f8fafc;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-card: #1e293b;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --accent-primary: #60a5fa;
    --accent-secondary: #a78bfa;
    --border-color: #334155;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.3);
    --shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.3);
    --hover-bg: #2d3748;
    --table-stripe: #2d3748;
}

/* ========================================
   GLOBAL STYLES
   ======================================== */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Poppins', sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    transition: var(--transition);
    padding: 20px;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
}

/* ========================================
   LOADING ANIMATION
   ======================================== */

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-primary);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
}

.loading-overlay.active {
    opacity: 1;
    visibility: visible;
}

.loader {
    text-align: center;
}

.spinner {
    width: 60px;
    height: 60px;
    border: 4px solid var(--border-color);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

.loading-text {
    color: var(--text-primary);
    font-size: 1.1rem;
    animation: pulse 2s infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ========================================
   HEADER STYLES
   ======================================== */

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding: 20px;
    background: var(--bg-secondary);
    border-radius: 20px;
    box-shadow: var(--shadow-md);
    animation: slideDown 0.5s ease;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.header-left {
    display: flex;
    align-items: center;
    gap: 30px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 15px;
}

.logo i {
    font-size: 2.5rem;
    color: var(--accent-primary);
    animation: bounce 2s infinite;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

.logo h1 {
    font-size: 1.8rem;
    font-weight: 600;
}

.logo h1 span {
    color: var(--accent-primary);
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.header-stats {
    display: flex;
    gap: 15px;
}

.stat-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 15px;
    background: var(--bg-primary);
    border-radius: 30px;
    font-size: 0.9rem;
    color: var(--text-secondary);
    transition: var(--transition);
}

.stat-badge:hover {
    transform: scale(1.05);
    background: var(--accent-primary);
    color: white;
}

.stat-badge i {
    color: var(--accent-primary);
}

.stat-badge:hover i {
    color: white;
}

.header-right {
    display: flex;
    gap: 10px;
}

.theme-toggle,
.refresh-btn {
    width: 45px;
    height: 45px;
    border: none;
    border-radius: 50%;
    background: var(--bg-primary);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 1.2rem;
    transition: var(--transition);
}

.theme-toggle:hover,
.refresh-btn:hover {
    transform: rotate(180deg);
    background: var(--accent-primary);
    color: white;
}

/* ========================================
   ADD SECTION
   ======================================== */

.add-section {
    background: var(--bg-secondary);
    padding: 30px;
    border-radius: 20px;
    margin-bottom: 30px;
    box-shadow: var(--shadow-md);
    animation: fadeInUp 0.6s ease;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.section-title {
    font-size: 1.4rem;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.section-title i {
    color: var(--accent-primary);
    animation: shake 3s infinite;
}

@keyframes shake {
    0%, 100% { transform: rotate(0); }
    10%, 30%, 50%, 70%, 90% { transform: rotate(-5deg); }
    20%, 40%, 60%, 80% { transform: rotate(5deg); }
}

#studentForm {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 20px;
}

.form-group {
    position: relative;
}

.input-wrapper {
    position: relative;
}

.input-wrapper i {
    position: absolute;
    left: 15px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
    transition: var(--transition);
}

.input-wrapper input {
    width: 100%;
    padding: 15px 15px 15px 45px;
    border: 2px solid var(--border-color);
    border-radius: 15px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 1rem;
    transition: var(--transition);
}

.input-wrapper input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1);
}

.input-wrapper input:focus + i {
    color: var(--accent-primary);
    transform: translateY(-50%) scale(1.2);
}

.add-btn {
    padding: 15px 30px;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    color: white;
    border: none;
    border-radius: 15px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 10px;
    white-space: nowrap;
}

.add-btn:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 10px 20px rgba(59, 130, 246, 0.3);
}

.add-btn i {
    transition: var(--transition);
}

.add-btn:hover i {
    transform: rotate(90deg);
}

/* ========================================
   RATING TABLE
   ======================================== */

.rating-section {
    background: var(--bg-secondary);
    padding: 30px;
    border-radius: 20px;
    margin-bottom: 30px;
    box-shadow: var(--shadow-md);
    animation: fadeInUp 0.7s ease;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 20px;
}

.table-controls {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
}

.search-box {
    position: relative;
}

.search-box i {
    position: absolute;
    left: 15px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
}

.search-box input {
    padding: 10px 10px 10px 40px;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    background: var(--bg-primary);
    color: var(--text-primary);
    width: 250px;
    transition: var(--transition);
}

.search-box input:focus {
    outline: none;
    border-color: var(--accent-primary);
    width: 300px;
}

.sort-select {
    padding: 10px 15px;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    background: var(--bg-primary);
    color: var(--text-primary);
    cursor: pointer;
    transition: var(--transition);
}

.sort-select:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.table-container {
    overflow-x: auto;
    border-radius: 15px;
    box-shadow: var(--shadow-sm);
}

.rating-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-primary);
}

.rating-table th {
    background: var(--accent-primary);
    color: white;
    padding: 15px;
    font-weight: 600;
    text-align: left;
}

.rating-table td {
    padding: 15px;
    border-bottom: 1px solid var(--border-color);
    transition: var(--transition);
}

.rating-table tbody tr {
    animation: fadeInRow 0.5s ease;
    animation-fill-mode: both;
}

@keyframes fadeInRow {
    from {
        opacity: 0;
        transform: translateX(-10px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.rating-table tbody tr:hover {
    background: var(--hover-bg);
    transform: scale(1.01);
    box-shadow: var(--shadow-md);
}

.rating-table tbody tr:nth-child(even) {
    background: var(--table-stripe);
}

.rank-badge {
    display: inline-block;
    width: 30px;
    height: 30px;
    line-height: 30px;
    text-align: center;
    border-radius: 50%;
    font-weight: 600;
}

.rank-1 {
    background: linear-gradient(135deg, #ffd700, #ffb347);
    color: #fff;
    animation: pulse 2s infinite;
}

.rank-2 {
    background: linear-gradient(135deg, #c0c0c0, #a0a0a0);
    color: #fff;
}

.rank-3 {
    background: linear-gradient(135deg, #cd7f32, #b87333);
    color: #fff;
}

.student-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.student-avatar {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
}

.score-cell {
    font-weight: 600;
    color: var(--accent-primary);
    position: relative;
}

.score-change {
    display: inline-block;
    margin-left: 10px;
    font-size: 0.8rem;
    animation: bounce 0.5s ease;
}

.score-change.up {
    color: var(--accent-success);
}

.score-change.down {
    color: var(--accent-danger);
}

.action-buttons {
    display: flex;
    gap: 8px;
}

.edit-btn,
.delete-btn {
    width: 35px;
    height: 35px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
    font-size: 0.9rem;
}

.edit-btn {
    background: var(--accent-primary);
    color: white;
}

.delete-btn {
    background: var(--accent-danger);
    color: white;
}

.edit-btn:hover,
.delete-btn:hover {
    transform: scale(1.1);
}

.edit-btn:hover {
    background: #2563eb;
}

.delete-btn:hover {
    background: #dc2626;
}

/* ========================================
   PAGINATION
   ======================================== */

.pagination {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-top: 20px;
    flex-wrap: wrap;
}

.page-btn {
    min-width: 40px;
    height: 40px;
    border: none;
    border-radius: 10px;
    background: var(--bg-primary);
    color: var(--text-primary);
    cursor: pointer;
    transition: var(--transition);
    font-weight: 500;
}

.page-btn:hover:not(:disabled) {
    background: var(--accent-primary);
    color: white;
    transform: scale(1.1);
}

.page-btn.active {
    background: var(--accent-primary);
    color: white;
}

.page-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ========================================
   STATISTICS CARDS
   ======================================== */

.stats-section {
    animation: fadeInUp 0.8s ease;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background: var(--bg-secondary);
    padding: 25px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    gap: 20px;
    box-shadow: var(--shadow-md);
    transition: var(--transition);
    animation: scaleIn 0.5s ease;
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.stat-card:hover {
    transform: translateY(-5px) scale(1.02);
    box-shadow: var(--shadow-xl);
}

.stat-icon {
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.5rem;
    animation: pulse 2s infinite;
}

.stat-info h3 {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 5px;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--accent-primary);
    line-height: 1.2;
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* ========================================
   CHARTS
   ======================================== */

.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 20px;
}

.chart-card {
    background: var(--bg-secondary);
    padding: 25px;
    border-radius: 20px;
    box-shadow: var(--shadow-md);
    transition: var(--transition);
}

.chart-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-xl);
}

.chart-card h3 {
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-primary);
}

.chart-card h3 i {
    color: var(--accent-primary);
}

.chart-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chart-bar-item {
    display: flex;
    align-items: center;
    gap: 10px;
    animation: slideInRight 0.5s ease;
    animation-fill-mode: both;
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.chart-label {
    width: 80px;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.chart-bar-wrapper {
    flex: 1;
    height: 30px;
    background: var(--bg-primary);
    border-radius: 15px;
    overflow: hidden;
}

.chart-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary));
    border-radius: 15px;
    transition: width 1s ease;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 10px;
    color: white;
    font-size: 0.8rem;
    font-weight: 500;
}

.top-students-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.top-student-item {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 10px;
    background: var(--bg-primary);
    border-radius: 12px;
    transition: var(--transition);
    animation: slideInLeft 0.5s ease;
    animation-fill-mode: both;
}

@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX(20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.top-student-item:hover {
    transform: translateX(5px);
    background: var(--hover-bg);
}

.top-student-rank {
    width: 30px;
    height: 30px;
    background: linear-gradient(135deg, #ffd700, #ffb347);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 0.9rem;
}

.top-student-info {
    flex: 1;
}

.top-student-name {
    font-weight: 600;
    margin-bottom: 3px;
}

.top-student-score {
    font-size: 0.9rem;
    color: var(--accent-primary);
    font-weight: 500;
}

/* ========================================
   MODAL STYLES
   ======================================== */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--bg-secondary);
    border-radius: 20px;
    width: 90%;
    max-width: 500px;
    transform: scale(0.7);
    transition: var(--transition);
    box-shadow: var(--shadow-xl);
}

.modal-overlay.active .modal {
    transform: scale(1);
}

.modal-header {
    padding: 20px 30px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.3rem;
}

.modal-header i {
    color: var(--accent-primary);
}

.modal-close {
    width: 35px;
    height: 35px;
    border: none;
    border-radius: 50%;
    background: var(--bg-primary);
    color: var(--text-primary);
    cursor: pointer;
    transition: var(--transition);
}

.modal-close:hover {
    transform: rotate(90deg);
    color: var(--accent-danger);
}

.modal form {
    padding: 30px;
}

.modal-actions {
    display: flex;
    gap: 15px;
    margin-top: 30px;
}

.save-btn,
.cancel-btn {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: 10px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.save-btn {
    background: var(--accent-success);
    color: white;
}

.cancel-btn {
    background: var(--accent-danger);
    color: white;
}

.save-btn:hover,
.cancel-btn:hover {
    transform: translateY(-2px);
    filter: brightness(110%);
}

/* ========================================
   TOAST NOTIFICATIONS
   ======================================== */

.toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 15px 25px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    border-radius: 10px;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 2000;
    animation: slideInRight 0.3s ease;
}

.toast.success {
    border-left: 4px solid var(--accent-success);
}

.toast.error {
    border-left: 4px solid var(--accent-danger);
}

.toast.info {
    border-left: 4px solid var(--accent-primary);
}

@keyframes slideOutRight {
    to {
        opacity: 0;
        transform: translateX(100%);
    }
}

/* ========================================
   EMPTY STATE
   ======================================== */

.empty-state {
    text-align: center;
    padding: 50px;
    color: var(--text-secondary);
}

.empty-state i {
    font-size: 4rem;
    margin-bottom: 20px;
    opacity: 0.5;
}

.empty-state p {
    font-size: 1.1rem;
}

/* ========================================
   RESPONSIVE DESIGN
   ======================================== */

@media (max-width: 992px) {
    #studentForm {
        grid-template-columns: 1fr;
    }
    
    .header-left {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
    }
    
    .charts-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    body {
        padding: 10px;
    }
    
    .header {
        flex-direction: column;
        gap: 20px;
        text-align: center;
    }
    
    .header-left {
        width: 100%;
        align-items: center;
    }
    
    .header-stats {
        width: 100%;
        justify-content: center;
    }
    
    .logo h1 {
        font-size: 1.5rem;
    }
    
    .section-header {
        flex-direction: column;
        align-items: stretch;
    }
    
    .table-controls {
        flex-direction: column;
    }
    
    .search-box input,
    .search-box input:focus,
    .sort-select {
        width: 100%;
    }
    
    .rating-table {
        font-size: 0.9rem;
    }
    
    .rating-table th,
    .rating-table td {
        padding: 10px;
    }
    
    .action-buttons {
        flex-direction: column;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .modal {
        width: 95%;
        margin: 10px;
    }
}

@media (max-width: 576px) {
    .rating-table {
        font-size: 0.8rem;
    }
    
    .student-avatar {
        width: 30px;
        height: 30px;
        font-size: 0.8rem;
    }
    
    .edit-btn,
    .delete-btn {
        width: 30px;
        height: 30px;
    }
    
    .pagination {
        gap: 5px;
    }
    
    .page-btn {
        min-width: 35px;
        height: 35px;
        font-size: 0.9rem;
    }
}

/* ========================================
   ANIMATIONS
   ======================================== */

@keyframes glow {
    0%, 100% { box-shadow: 0 0 5px var(--accent-primary); }
    50% { box-shadow: 0 0 20px var(--accent-primary); }
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

/* New record animation */
.new-record {
    animation: glow 1s ease, shake 0.5s ease;
}

/* Row highlight animation */
.row-highlight {
    animation: glow 1s ease;
}

/* Confetti canvas */
#confetti-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
}