/* ============================================
   Leadersboard - Main Stylesheet
   ============================================ */

:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #818cf8;
    --secondary: #0ea5e9;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --dark: #1e293b;
    --darker: #0f172a;
    --light: #f8fafc;
    --gray: #64748b;
    --gray-light: #e2e8f0;
    --gray-lighter: #f1f5f9;
    --border: #e2e8f0;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -4px rgba(0,0,0,0.04);
    --radius: 12px;
    --radius-sm: 8px;
    --sidebar-width: 260px;
    --topbar-height: 64px;
    --transition: all 0.2s ease;
}

* { box-sizing: border-box; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--gray-lighter);
    color: var(--dark);
    margin: 0;
    padding: 0;
    min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; transition: var(--transition); }
a:hover { color: var(--primary-dark); }

/* ============================================
   LOGIN PAGE
   ============================================ */

.login-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 20px;
}

.login-card {
    background: white;
    border-radius: 20px;
    padding: 48px 40px;
    width: 100%;
    max-width: 440px;
    box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25);
    text-align: center;
}

.login-card .logo {
    width: 80px;
    height: 80px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 24px;
    font-size: 36px;
    color: white;
}

.login-card h1 {
    font-size: 28px;
    font-weight: 700;
    margin: 0 0 8px;
    color: var(--darker);
}

.login-card p {
    color: var(--gray);
    margin: 0 0 32px;
    font-size: 15px;
}

.btn-google {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    width: 100%;
    padding: 14px 24px;
    background: white;
    border: 2px solid var(--gray-light);
    border-radius: var(--radius);
    font-size: 16px;
    font-weight: 600;
    color: var(--dark);
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
}

.btn-google:hover {
    border-color: var(--primary);
    background: var(--gray-lighter);
    color: var(--dark);
    box-shadow: var(--shadow-md);
}

.btn-google img {
    width: 22px;
    height: 22px;
}

/* ============================================
   LAYOUT - SIDEBAR + MAIN
   ============================================ */

.app-wrapper {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--darker);
    color: white;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
}

.sidebar-brand {
    padding: 16px 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    overflow: hidden;
}

.sidebar-brand-icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

.sidebar-brand h2 {
    font-size: 18px;
    font-weight: 700;
    margin: 0;
    white-space: nowrap;
}

.sidebar-logo {
    max-width: 180px;
    max-height: 44px;
    object-fit: contain;
    display: block;
}

.btn-sidebar-close {
    display: none;
    background: none;
    border: none;
    color: rgba(255,255,255,0.6);
    font-size: 28px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
    margin-left: auto;
}

.btn-sidebar-close:hover {
    color: white;
}

.sidebar-menu {
    padding: 16px 12px;
    flex: 1;
    overflow-y: auto;
}

.sidebar-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(255,255,255,0.35);
    padding: 16px 12px 8px;
    margin: 0;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: rgba(255,255,255,0.65);
    font-size: 14px;
    font-weight: 500;
    transition: var(--transition);
    margin-bottom: 2px;
    text-decoration: none;
}

.sidebar-link:hover {
    background: rgba(255,255,255,0.08);
    color: white;
}

.sidebar-link.active {
    background: var(--primary);
    color: white;
}

.sidebar-link i {
    width: 20px;
    text-align: center;
    font-size: 16px;
}

.sidebar-footer {
    padding: 16px 12px;
    border-top: 1px solid rgba(255,255,255,0.08);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
}

.sidebar-user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(255,255,255,0.2);
}

.sidebar-user-info {
    flex: 1;
    min-width: 0;
}

.sidebar-user-name {
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-role {
    font-size: 11px;
    color: rgba(255,255,255,0.45);
    text-transform: capitalize;
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Top Bar */
.topbar {
    height: var(--topbar-height);
    background: white;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.topbar-title {
    font-size: 20px;
    font-weight: 700;
    color: var(--darker);
    margin: 0;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.btn-sidebar-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 22px;
    color: var(--dark);
    cursor: pointer;
    padding: 4px 8px;
}

/* Page Content */
.page-content {
    padding: 28px;
    flex: 1;
}

/* ============================================
   CARDS
   ============================================ */

.card {
    background: white;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    margin-bottom: 24px;
    overflow: hidden;
}

.card-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.card-body {
    padding: 24px;
}

/* Stat cards */
.stat-card {
    background: white;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    padding: 24px;
    display: flex;
    align-items: center;
    gap: 16px;
    transition: var(--transition);
}

.stat-card:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
}

.stat-icon {
    width: 52px;
    height: 52px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    flex-shrink: 0;
}

.stat-icon.purple { background: #ede9fe; color: var(--primary); }
.stat-icon.blue { background: #e0f2fe; color: var(--secondary); }
.stat-icon.green { background: #d1fae5; color: var(--success); }
.stat-icon.orange { background: #fef3c7; color: var(--warning); }
.stat-icon.red { background: #fee2e2; color: var(--danger); }

.stat-info h4 {
    margin: 0;
    font-size: 13px;
    font-weight: 500;
    color: var(--gray);
}

.stat-info .stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--darker);
    line-height: 1.2;
}

/* ============================================
   BUTTONS
   ============================================ */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    border: none;
    text-decoration: none;
    line-height: 1.4;
}

.btn-sm {
    padding: 6px 14px;
    font-size: 13px;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); color: white; }

.btn-secondary { background: var(--gray-light); color: var(--dark); }
.btn-secondary:hover { background: #cbd5e1; color: var(--dark); }

.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #059669; color: white; }

.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #dc2626; color: white; }

.btn-warning { background: var(--warning); color: white; }
.btn-warning:hover { background: #d97706; color: white; }

.btn-outline {
    background: transparent;
    border: 2px solid var(--border);
    color: var(--dark);
}
.btn-outline:hover {
    border-color: var(--primary);
    color: var(--primary);
}

/* ============================================
   TABLES
   ============================================ */

.table-responsive {
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: collapse;
}

.table th {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--gray);
    padding: 12px 16px;
    text-align: left;
    border-bottom: 2px solid var(--border);
    background: var(--gray-lighter);
}

.table td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
    vertical-align: middle;
}

.table tbody tr:hover {
    background: var(--gray-lighter);
}

.table .rank-cell {
    font-weight: 700;
    font-size: 16px;
    width: 50px;
}

.table .rank-1 { color: #FFD700; }
.table .rank-2 { color: #C0C0C0; }
.table .rank-3 { color: #CD7F32; }

/* ============================================
   FORMS
   ============================================ */

.form-group {
    margin-bottom: 20px;
}

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--dark);
    margin-bottom: 6px;
}

.form-control {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: inherit;
    transition: var(--transition);
    background: white;
    color: var(--dark);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2364748b' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10l-5 5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

/* ============================================
   ALERTS / FLASH MESSAGES
   ============================================ */

.alert {
    padding: 14px 20px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.alert-success { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert-warning { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.alert-info { background: #e0f2fe; color: #075985; border: 1px solid #bae6fd; }

/* ============================================
   BADGES
   ============================================ */

.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.badge-success { background: #d1fae5; color: #065f46; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-info { background: #e0f2fe; color: #075985; }
.badge-purple { background: #ede9fe; color: #5b21b6; }

/* Achievement badges */
.achievement-badge {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 12px;
    width: 90px;
}

.achievement-badge .badge-icon {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    margin-bottom: 6px;
    position: relative;
}

.achievement-badge .badge-name {
    font-size: 11px;
    font-weight: 600;
    color: var(--dark);
    line-height: 1.2;
}

.achievement-badge.locked .badge-icon {
    background: var(--gray-light);
    color: var(--gray);
    opacity: 0.5;
}

/* ============================================
   PAGE COUNTER BLOCKS (Student Page Entry)
   ============================================ */

.counter-block {
    background: white;
    border-radius: var(--radius);
    border: 2px solid var(--border);
    padding: 32px;
    text-align: center;
    transition: var(--transition);
    cursor: default;
}

.counter-block:hover {
    box-shadow: var(--shadow-lg);
}

.counter-block.quran {
    border-color: #a78bfa;
    background: linear-gradient(135deg, #faf5ff 0%, #ede9fe 100%);
}

.counter-block.book {
    border-color: #67e8f9;
    background: linear-gradient(135deg, #f0fdfa 0%, #e0f2fe 100%);
}

.counter-block .counter-icon {
    font-size: 42px;
    margin-bottom: 12px;
}

.counter-block .counter-label {
    font-size: 14px;
    font-weight: 600;
    color: var(--gray);
    margin-bottom: 16px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.counter-input {
    font-size: 52px;
    font-weight: 800;
    color: var(--darker);
    line-height: 1;
    margin-bottom: 20px;
    text-align: center;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    background: transparent;
    width: 160px;
    padding: 8px 4px;
    font-family: inherit;
    outline: none;
    transition: var(--transition);
    -moz-appearance: textfield;
}

.counter-input::-webkit-outer-spin-button,
.counter-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.counter-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

@media (max-width: 768px) {
    .counter-input { font-size: 38px; width: 120px; }
}

@media (max-width: 480px) {
    .counter-input { font-size: 32px; width: 100px; }
}

.counter-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
}

.counter-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 2px solid var(--border);
    background: white;
    font-size: 22px;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--dark);
}

.counter-btn:hover {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

.counter-btn.minus:hover {
    background: var(--danger);
    border-color: var(--danger);
}

/* ============================================
   LEADERBOARD TABS
   ============================================ */

.tab-nav {
    display: flex;
    gap: 4px;
    background: var(--gray-lighter);
    padding: 4px;
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
}

.tab-btn {
    flex: 1;
    padding: 10px 16px;
    border: none;
    background: transparent;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    color: var(--gray);
    cursor: pointer;
    transition: var(--transition);
}

.tab-btn.active {
    background: white;
    color: var(--primary);
    box-shadow: var(--shadow);
}

.tab-btn:hover:not(.active) {
    color: var(--dark);
}

/* ============================================
   MODAL
   ============================================ */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 200;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-overlay.show {
    display: flex;
}

.modal {
    background: white;
    border-radius: var(--radius);
    width: 100%;
    max-width: 520px;
    box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25);
    animation: modalIn 0.2s ease;
}

@keyframes modalIn {
    from { transform: scale(0.95); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h3 { margin: 0; font-size: 18px; }

.modal-close {
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    color: var(--gray);
    padding: 4px;
}

.modal-body { padding: 24px; }

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* ============================================
   NOTIFICATION TOAST
   ============================================ */

.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    background: white;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 300px;
    animation: toastIn 0.3s ease;
    border-left: 4px solid var(--success);
}

.toast.badge-toast {
    border-left-color: #FFD700;
}

@keyframes toastIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ============================================
   UTILITIES
   ============================================ */

.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 24px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 24px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 24px; }

.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--gray); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }

.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }

.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }

.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
}

.avatar-sm { width: 28px; height: 28px; }
.avatar-lg { width: 48px; height: 48px; }

.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--gray);
}

.empty-state i {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.4;
}

.empty-state h4 {
    margin: 0 0 8px;
    color: var(--dark);
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 1024px) {
    .grid-4 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
    }

    .btn-sidebar-toggle {
        display: block;
    }

    .btn-sidebar-close {
        display: block;
    }

    .page-content {
        padding: 16px;
    }

    .topbar {
        padding: 0 16px;
    }

    .grid-2,
    .grid-3,
    .grid-4 {
        grid-template-columns: 1fr;
    }

    .counter-block {
        padding: 20px 16px;
    }

    .tab-nav {
        flex-wrap: wrap;
    }

    .tab-btn {
        flex: none;
        padding: 8px 14px;
        font-size: 12px;
    }

    .login-card {
        padding: 32px 24px;
    }

    .card-header {
        flex-direction: column;
        gap: 10px;
        align-items: flex-start;
    }

    .stat-card {
        padding: 16px;
    }

    .stat-info .stat-value {
        font-size: 22px;
    }

    .modal {
        max-width: 100% !important;
        margin: 10px;
        max-height: 90vh;
        overflow-y: auto;
    }

    .d-flex:not(.counter-controls) {
        flex-wrap: wrap;
    }

    .toast {
        min-width: auto;
        max-width: calc(100vw - 40px);
    }

    .toast-container {
        left: 10px;
        right: 10px;
    }

    /* Filter bars - stack on mobile */
    .card-body form.d-flex {
        flex-direction: column;
        align-items: stretch;
    }

    .card-body form.d-flex .form-control {
        max-width: 100% !important;
    }

    .card-body form.d-flex .tab-nav {
        width: 100%;
    }

    /* Table horizontal scroll */
    .table-responsive {
        -webkit-overflow-scrolling: touch;
    }

    .table {
        min-width: 600px;
    }
}

@media (max-width: 480px) {
    .topbar-title {
        font-size: 16px;
    }

    .table th, .table td {
        padding: 10px 8px;
        font-size: 12px;
    }

    .btn-sm {
        padding: 5px 10px;
        font-size: 12px;
    }

    .counter-btn {
        width: 40px;
        height: 40px;
        font-size: 18px;
    }

    .sidebar-logo {
        max-height: 36px;
    }
}

/* Sidebar overlay for mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 99;
}

.sidebar-overlay.show {
    display: block;
}

/* ============================================
   LOADING SPINNER
   ============================================ */

.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--gray-light);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ============================================
   TAB NAV LINKS (for leaderboard period tabs)
   ============================================ */

a.tab-btn {
    text-decoration: none;
    text-align: center;
}

/* ============================================
   SMOOTH TRANSITIONS
   ============================================ */

.card, .stat-card, .badge-card {
    transition: var(--transition);
}

/* ============================================
   PRINT STYLES
   ============================================ */

@media print {
    .sidebar, .topbar, .btn-sidebar-toggle, .sidebar-overlay, .toast-container {
        display: none !important;
    }
    .main-content {
        margin-left: 0 !important;
    }
    .page-content {
        padding: 0 !important;
    }
    .card {
        box-shadow: none !important;
        border: 1px solid #ddd !important;
    }
}
