/**
 * App-wide visual theme.
 *
 * Built on top of Bootstrap 5.3's CSS custom properties rather than
 * fighting them: overriding --bs-primary, --bs-body-*, and
 * --bs-border-radius here recolors/reshapes every Bootstrap component
 * (buttons, links, form focus rings, badges, etc.) without needing to
 * touch each page's markup. On top of that, a small set of custom
 * classes (.app-navbar, .brand-mark, .user-avatar, .stat-card/-label/
 * -value) cover the handful of things Bootstrap's variables don't reach.
 */

:root {
    --bs-body-font-family: 'Inter', ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --bs-body-bg: #eef0f9;
    --bs-body-color: #1c2033;

    --bs-primary: #4f46e5;
    --bs-primary-rgb: 79, 70, 229;
    --bs-link-color: #4f46e5;
    --bs-link-color-rgb: 79, 70, 229;
    --bs-link-hover-color: #3730a3;
    --bs-link-hover-color-rgb: 55, 48, 163;

    --bs-border-radius: 0.65rem;
    --bs-border-radius-sm: 0.5rem;
    --bs-border-radius-lg: 0.9rem;

    --app-muted: #676f8c;
    --app-border: rgba(28, 32, 51, 0.09);
    --app-navy: #171b30;
    --app-navy-2: #232849;
}

body {
    letter-spacing: -0.01em;
    background: linear-gradient(180deg, #e3e7fb 0%, #eef0f9 340px, #eef0f9 100%);
    min-height: 100vh;
}

/* ---------------------------------------------------------------- Nav */

.app-navbar {
    background: linear-gradient(120deg, var(--app-navy) 0%, var(--app-navy-2) 100%);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    box-shadow: 0 4px 20px -8px rgba(23, 27, 48, 0.5);
    position: sticky;
    top: 0;
    z-index: 1030;
}

.app-navbar .navbar-brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-weight: 700;
    color: #fff;
}

.brand-mark {
    width: 30px;
    height: 30px;
    border-radius: 9px;
    background: linear-gradient(135deg, #6366f1, #a78bfa);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 700;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.5);
}

.app-navbar .nav-link {
    color: rgba(255, 255, 255, 0.75);
    font-weight: 500;
    border-radius: 999px;
    padding: 0.4rem 0.95rem;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.app-navbar .nav-link:hover,
.app-navbar .nav-link.active {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.app-navbar .navbar-toggler {
    border-color: rgba(255, 255, 255, 0.25);
}

.app-navbar .navbar-toggler-icon {
    filter: invert(1) grayscale(100%) brightness(200%);
}

.user-chip {
    display: flex;
    align-items: center;
    gap: 0.55rem;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6366f1, #a78bfa);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.8rem;
    flex-shrink: 0;
}

.user-name {
    color: #fff;
    font-weight: 500;
    font-size: 0.9rem;
}

.user-chip-link {
    padding: 0.25rem 0.6rem !important;
    border-radius: 999px;
}

.user-chip-link:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* -------------------------------------------------------- Sortable tables */

.sortable-th {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

.sortable-th:hover {
    color: var(--bs-primary);
}

/* --------------------------------------------- Leaderboard vs. Entries */

/* Leaderboard: warm amber accent (matches the trophy icon), so it reads
   as a distinct "ranking/summary" table rather than another entries
   grid, even though both use Bootstrap's .table-striped base. */
.leaderboard-card {
    border-top: 3px solid #f59e0b;
}

.leaderboard-table thead th {
    background: rgba(245, 158, 11, 0.1);
    color: #92400e;
}

.leaderboard-table.table-striped {
    --bs-table-striped-bg: rgba(245, 158, 11, 0.05);
}

[data-bs-theme="dark"] .leaderboard-table thead th {
    background: rgba(245, 158, 11, 0.15);
    color: #fbbf24;
}

[data-bs-theme="dark"] .leaderboard-table.table-striped {
    --bs-table-striped-bg: rgba(245, 158, 11, 0.08);
}

/* Entries: cool indigo accent (matches the app's primary color), so the
   two tables are visually distinguishable at a glance. */
.entries-card {
    border-top: 3px solid var(--bs-primary);
}

.logout-link {
    color: rgba(255, 255, 255, 0.6) !important;
}

.logout-link:hover {
    color: #fca5a5 !important;
    background: rgba(220, 53, 69, 0.15) !important;
}

/* --------------------------------------------------------------- Cards */

.card {
    border: 1px solid var(--app-border);
    border-radius: var(--bs-border-radius-lg);
    box-shadow: 0 1px 2px rgba(23, 27, 48, 0.04), 0 12px 28px -14px rgba(23, 27, 48, 0.16);
}

.card-title {
    font-weight: 600;
}

h1.h3 {
    font-weight: 700;
    color: var(--app-navy);
}

/* -------------------------------------------------------------- Stats */

.stat-card {
    border: none;
    color: #fff;
    background: linear-gradient(135deg, var(--stat-color-a), var(--stat-color-b));
    box-shadow: 0 10px 22px -10px var(--stat-shadow, rgba(79, 70, 229, 0.45));
}

.stat-card .stat-label {
    text-transform: uppercase;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    color: rgba(255, 255, 255, 0.8) !important;
}

.stat-card .stat-value {
    font-weight: 700;
    max-width: 100%;
    overflow-wrap: break-word;
    word-wrap: break-word;
    color: #fff;
}

.stat-card-1 { --stat-color-a: #4f46e5; --stat-color-b: #7c6cf0; --stat-shadow: rgba(79, 70, 229, 0.45); }
.stat-card-2 { --stat-color-a: #0ea5e9; --stat-color-b: #38bdf8; --stat-shadow: rgba(14, 165, 233, 0.4); }
.stat-card-3 { --stat-color-a: #059669; --stat-color-b: #34d399; --stat-shadow: rgba(5, 150, 105, 0.4); }
.stat-card-4 { --stat-color-a: #d97706; --stat-color-b: #fbbf24; --stat-shadow: rgba(217, 119, 6, 0.4); }
.stat-card-5 { --stat-color-a: #db2777; --stat-color-b: #f472b6; --stat-shadow: rgba(219, 39, 119, 0.4); }
.stat-card-6 { --stat-color-a: #7c3aed; --stat-color-b: #a78bfa; --stat-shadow: rgba(124, 58, 237, 0.4); }
.stat-card-7 { --stat-color-a: #0d9488; --stat-color-b: #2dd4bf; --stat-shadow: rgba(13, 148, 136, 0.4); }
.stat-card-8 { --stat-color-a: #475569; --stat-color-b: #94a3b8; --stat-shadow: rgba(71, 85, 105, 0.4); }

/* -------------------------------------------------------------- Forms */

.form-label {
    font-weight: 500;
    font-size: 0.875rem;
    color: #3a4152;
}

.form-control,
.form-select {
    border-color: var(--app-border);
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
}

.form-control:focus,
.form-select:focus {
    border-color: var(--bs-primary);
    box-shadow: 0 0 0 0.2rem rgba(79, 70, 229, 0.15);
}

/* -------------------------------------------------------------- Buttons */

.btn {
    font-weight: 500;
    border-radius: var(--bs-border-radius);
}

.btn-primary {
    background: linear-gradient(135deg, #4f46e5, #6366f1);
    border: none;
    box-shadow: 0 4px 12px -2px rgba(79, 70, 229, 0.5);
}

.btn-primary:hover {
    background: linear-gradient(135deg, #4338ca, #4f46e5);
}

.btn-outline-secondary {
    color: #4b5165;
    border-color: var(--app-border);
}

.btn-outline-secondary:hover {
    background: #f1f2f8;
    border-color: var(--app-border);
    color: var(--bs-body-color);
}

/* -------------------------------------------------------------- Tables */

.table {
    --bs-table-striped-bg: #f5f6fc;
}

.table thead th {
    text-transform: uppercase;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    color: var(--app-muted);
    background: #f7f8fd;
    border-bottom-width: 1px;
    border-bottom-color: var(--app-border);
}

.table td,
.table th {
    border-color: var(--app-border);
    vertical-align: middle;
    font-size: 14px;
    text-align: center;
}

.table-hover > tbody > tr:hover > * {
    background-color: rgba(79, 70, 229, 0.05);
}

/* -------------------------------------------------------------- Badges */

.badge {
    font-weight: 600;
    letter-spacing: 0.02em;
    padding: 0.4em 0.7em;
}

.badge.bg-success {
    background: linear-gradient(135deg, #059669, #34d399) !important;
}

.badge.bg-secondary {
    background: linear-gradient(135deg, #64748b, #94a3b8) !important;
}

/* -------------------------------------------------------------- Alerts */

.alert {
    border: 1px solid transparent;
    border-left: 4px solid transparent;
}

.alert-success {
    border-left-color: #059669;
}

.alert-danger {
    border-left-color: #dc2626;
}

.alert-info {
    border-left-color: #0ea5e9;
}

/* ------------------------------------------------------------ Auth page */

.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at top left, #4f46e5 0%, #171b30 45%, #0f1220 100%);
    padding: 1.5rem;
}

.auth-card {
    width: 100%;
    max-width: 380px;
}

.auth-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
    text-align: center;
}

.auth-brand .brand-mark {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    font-size: 1.05rem;
}

.auth-title {
    font-weight: 700;
    font-size: 1.15rem;
    margin: 0;
    color: #fff;
}

.auth-subtitle {
    color: rgba(255, 255, 255, 0.65);
    font-size: 0.875rem;
    margin: 0;
}

/* --------------------------------------------------------- Responsive */

@media (max-width: 576px) {
    .table-responsive table {
        font-size: 0.8rem;
    }
}

/* Chart.js canvases: fix a sane height via a wrapper instead of letting
   the canvas stretch to fill its card at whatever aspect ratio the
   parent happens to be (this was causing giant, oddly-proportioned
   charts). Chart.js is configured with maintainAspectRatio: false, so
   it fills this fixed-height box instead of computing its own. */
.chart-box {
    position: relative;
    height: 260px;
    max-width: 100%;
}

.chart-box canvas {
    max-width: 100%;
}

/* ------------------------------------------------------ Theme toggle */

/* Icon visibility is driven purely by [data-bs-theme] on <html> so the
   correct icon (moon = "switch to dark" / sun = "switch to light")
   shows immediately on page load, before any JS runs. */
.theme-icon-dark { display: inline-block; }
.theme-icon-light { display: none; }
[data-bs-theme="dark"] .theme-icon-dark { display: none; }
[data-bs-theme="dark"] .theme-icon-light { display: inline-block; }

.theme-toggle-nav {
    color: rgba(255, 255, 255, 0.85);
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 999px;
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background-color 0.15s ease;
}

.theme-toggle-nav:hover {
    background: rgba(255, 255, 255, 0.18);
    color: #fff;
}

.theme-toggle-floating {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 1040;
    width: 40px;
    height: 40px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.25);
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(6px);
}

.theme-toggle-floating:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Password show/hide toggle button, paired with a text/password input
   inside a Bootstrap .input-group. */
.password-toggle {
    border-color: var(--app-border);
}

/* --------------------------------------------------------- Dark mode */

/* Bootstrap 5.3 already remaps most --bs-* variables automatically under
   [data-bs-theme="dark"] on <html>; these overrides adjust the small set
   of custom colors/backgrounds this theme layer introduced so the app
   doesn't end up with a light-mode page background or shadow under a
   dark navbar/cards. */
[data-bs-theme="dark"] {
    --bs-body-bg: #12141f;
    --bs-body-color: #e5e7f0;

    --app-muted: #9298b3;
    --app-border: rgba(255, 255, 255, 0.09);
}

[data-bs-theme="dark"] body {
    background: linear-gradient(180deg, #191c2c 0%, #12141f 340px, #12141f 100%);
}

[data-bs-theme="dark"] .card {
    background-color: #1b1e30;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 28px -14px rgba(0, 0, 0, 0.5);
}

[data-bs-theme="dark"] h1.h3 {
    color: #e5e7f0;
}

[data-bs-theme="dark"] .form-label {
    color: #c7cbe0;
}

[data-bs-theme="dark"] .form-control,
[data-bs-theme="dark"] .form-select {
    background-color: #14172480;
    border-color: var(--app-border);
    color: #e5e7f0;
}

[data-bs-theme="dark"] .form-control::placeholder {
    color: #6b7093;
}

[data-bs-theme="dark"] .btn-outline-secondary {
    color: #c7cbe0;
    border-color: var(--app-border);
}

[data-bs-theme="dark"] .btn-outline-secondary:hover {
    background: #262a40;
    color: #fff;
}

[data-bs-theme="dark"] .table {
    --bs-table-striped-bg: #1f2337;
    --bs-table-color: #e5e7f0;
    --bs-table-bg: #1b1e30;
}

[data-bs-theme="dark"] .table thead th {
    background: #1f2337;
    color: var(--app-muted);
}

[data-bs-theme="dark"] .table-hover > tbody > tr:hover > * {
    background-color: rgba(99, 102, 241, 0.12);
}

[data-bs-theme="dark"] .auth-page {
    background: radial-gradient(circle at top left, #4338ca 0%, #12141f 45%, #0a0b12 100%);
}
