* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
    font-family: 'Lato', sans-serif;
    font-weight: 400;
    color: #1f2937;
    -webkit-font-smoothing: antialiased;
}

body {
    min-height: 100vh;
    background: #f3f4f6;
}

a { color: inherit; }

/* ---------- Auth (login) page ---------- */
.auth-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0b2545 0%, #13315c 50%, #8da9c4 100%);
    padding: 20px;
}
.auth-card {
    background: #fff;
    width: 100%;
    max-width: 420px;
    border-radius: 14px;
    padding: 40px 36px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.25);
}
.auth-logo { display: flex; justify-content: center; margin-bottom: 28px; }
.auth-logo img { max-width: 240px; height: auto; }
.auth-title { text-align: center; font-weight: 700; font-size: 1.4rem; color: #0b2545; margin-bottom: 4px; }
.auth-sub { text-align: center; font-weight: 300; font-size: 0.95rem; color: #6b7280; margin-bottom: 28px; }
.field { margin-bottom: 18px; }
.field label { display: block; font-size: 0.85rem; font-weight: 700; color: #374151; margin-bottom: 6px; }
.field input, .field select, .field textarea {
    width: 100%; padding: 11px 14px;
    border: 1px solid #d1d5db; border-radius: 8px;
    font-family: 'Lato', sans-serif; font-size: 0.95rem;
    background: #f9fafb;
    transition: border-color .15s, background .15s;
}
.field input[type=file] { padding: 10px 12px; }
.field input:focus, .field select:focus, .field textarea:focus {
    outline: none; border-color: #0b2545; background: #fff;
}
.btn-primary {
    display: inline-block;
    padding: 11px 24px;
    border: none; border-radius: 8px;
    background: #0b2545; color: #fff;
    font-family: 'Lato', sans-serif;
    font-weight: 700; font-size: 0.92rem;
    cursor: pointer;
    transition: background .15s;
    text-decoration: none;
}
.btn-primary.full { display: block; width: 100%; }
.btn-primary:hover { background: #13315c; }
.auth-footer { text-align: center; margin-top: 22px; font-size: 0.8rem; color: #9ca3af; }

/* ---------- App shell (sidebar + main) ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 240px;
    background: #0b2545;
    color: #e5e7eb;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    height: 100vh;
}
.sidebar-logo {
    padding: 22px 24px 18px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar-logo img { width: 100%; max-width: 180px; height: auto; display: block; }

.sidebar-menu {
    flex: 1;
    padding: 14px 0;
    overflow-y: auto;
}
.sidebar-menu a {
    display: block;
    padding: 12px 24px;
    color: #cbd5e1;
    text-decoration: none;
    font-weight: 700;
    font-size: 0.9rem;
    border-left: 3px solid transparent;
    transition: background .12s, color .12s, border-color .12s;
}
.sidebar-menu a:hover { background: rgba(255,255,255,0.05); color: #fff; }
.sidebar-menu a.active {
    background: rgba(255,255,255,0.08);
    color: #fff;
    border-left-color: #f59e0b;
}

.sidebar-footer {
    padding: 16px 24px 20px;
    border-top: 1px solid rgba(255,255,255,0.08);
}
.sidebar-user { margin-bottom: 10px; }
.user-name { font-weight: 700; color: #fff; font-size: 0.88rem; }
.user-email { font-weight: 300; color: #94a3b8; font-size: 0.78rem; margin-top: 2px; word-break: break-all; }
.sidebar-signout {
    display: inline-block;
    padding: 7px 14px;
    background: rgba(255,255,255,0.1);
    color: #fff;
    text-decoration: none;
    border-radius: 6px;
    font-size: 0.78rem;
    font-weight: 700;
    transition: background .12s;
}
.sidebar-signout:hover { background: rgba(255,255,255,0.2); }

.main {
    flex: 1;
    min-width: 0;
    padding: 28px 36px 40px;
}
.page-header { margin-bottom: 22px; display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-header h1 { font-weight: 900; color: #0b2545; font-size: 1.6rem; }
.page-body { }

/* ---------- Card ---------- */
.card {
    background: #fff;
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

/* ---------- Search bar ---------- */
.search-bar {
    display: flex;
    gap: 10px;
    margin-bottom: 18px;
    align-items: center;
    flex-wrap: wrap;
}
.search-input-wrap {
    position: relative;
    flex: 1;
    min-width: 280px;
}
.search-bar input[type=text] {
    width: 100%;
    padding: 10px 38px 10px 14px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-family: 'Lato', sans-serif;
    font-size: 0.92rem;
    background: #fff;
    transition: border-color .15s;
}
.search-bar input[type=text]:focus {
    outline: none;
    border-color: #0b2545;
}
.search-clear {
    position: absolute;
    top: 50%;
    right: 8px;
    transform: translateY(-50%);
    width: 24px;
    height: 24px;
    border: none;
    background: #e5e7eb;
    color: #4b5563;
    border-radius: 50%;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background .12s, color .12s;
}
.search-clear:hover { background: #0b2545; color: #fff; }
.search-clear[hidden] { display: none; }
.search-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid #e5e7eb;
    border-top-color: #0b2545;
    border-radius: 50%;
    display: none;
}
.search-spinner.active {
    display: inline-block;
    animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#resultsContainer {
    transition: opacity .15s ease;
}
#resultsContainer.is-loading {
    opacity: 0.55;
    pointer-events: none;
}

/* ---------- Data table ---------- */
.table-wrap {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    overflow: hidden;
}
.table-scroll {
    overflow-x: auto;
    /* always show scrollbar track so horizontal scroll is discoverable */
    scrollbar-color: #9ca3af #e5e7eb;
}
.table-scroll::-webkit-scrollbar { height: 12px; }
.table-scroll::-webkit-scrollbar-track { background: #e5e7eb; border-radius: 6px; }
.table-scroll::-webkit-scrollbar-thumb { background: #9ca3af; border-radius: 6px; }
.table-scroll::-webkit-scrollbar-thumb:hover { background: #6b7280; }

table.data {
    width: auto;
    min-width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
    table-layout: auto;
}
table.data thead th {
    background: #f3f4f6;
    color: #374151;
    font-weight: 700;
    text-align: left;
    padding: 14px 18px;
    border-bottom: 1px solid #e5e7eb;
    white-space: nowrap;
}
table.data tbody td {
    padding: 22px 20px;
    border-bottom: 1px solid #f3f4f6;
    font-weight: 400;
    color: #374151;
    white-space: nowrap;
    vertical-align: middle;
    line-height: 1.4;
}
table.data tbody tr:hover { background: #fafbfc; }
table.data .rank {
    font-weight: 900;
    color: #0b2545;
    width: 60px;
}
table.data .overall {
    font-weight: 700;
    color: #0b2545;
}
.prefs-more {
    display: inline-block;
    background: #e0e7ff;
    color: #3730a3;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 700;
    cursor: pointer;
    margin-left: 6px;
}
.prefs-popover {
    display: none;
    position: absolute;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 12px 16px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.15);
    z-index: 50;
    font-size: 0.82rem;
    min-width: 360px;
}
.prefs-popover.show { display: block; }
.prefs-popover ol { margin-left: 18px; }
.prefs-popover li { padding: 2px 0; }

.pagination {
    padding: 14px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: #fafbfc;
    border-top: 1px solid #f3f4f6;
    font-size: 0.85rem;
    color: #6b7280;
}
.pagination .pages a, .pagination .pages span {
    display: inline-block;
    padding: 6px 11px;
    margin: 0 2px;
    border-radius: 6px;
    text-decoration: none;
    color: #0b2545;
    font-weight: 700;
}
.pagination .pages a:hover { background: #e5e7eb; }
.pagination .pages span.current {
    background: #0b2545;
    color: #fff;
}
.pagination .pages span.disabled { color: #d1d5db; }

/* ---------- Programs (accordion) ---------- */
.programs-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.program-card {
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    overflow: hidden;
}
.program-header {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 20px;
    background: #fff;
    border: none;
    border-left: 3px solid transparent;
    font-family: 'Lato', sans-serif;
    cursor: pointer;
    text-align: left;
    transition: background .12s, border-color .12s;
}
.program-header:hover { background: #f9fafb; }
.program-header[aria-expanded="true"] {
    border-left-color: #f59e0b;
    background: #fafbfc;
}
.program-name {
    flex: 1;
    font-weight: 700;
    color: #0b2545;
    font-size: 0.98rem;
}
.program-total {
    font-weight: 400;
    color: #6b7280;
    font-size: 0.85rem;
    padding: 4px 10px;
    background: #f3f4f6;
    border-radius: 999px;
}
.program-caret {
    color: #9ca3af;
    font-size: 0.9rem;
    transition: transform .15s;
}
.program-header[aria-expanded="true"] .program-caret {
    transform: rotate(180deg);
    color: #0b2545;
}
.program-body {
    padding: 12px 20px 20px;
    border-top: 1px solid #f3f4f6;
    overflow-x: auto;
}
.rank-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}
.rank-table thead th {
    padding: 6px 4px 10px;
    color: #6b7280;
    font-weight: 700;
    text-align: center;
    border-bottom: 1px solid #e5e7eb;
    white-space: nowrap;
}
.rank-table tbody td {
    padding: 10px 4px 6px;
    text-align: center;
    vertical-align: top;
    min-width: 56px;
}
.rank-bar-wrap {
    width: 100%;
    height: 64px;
    background: #f3f4f6;
    border-radius: 4px;
    position: relative;
    overflow: hidden;
    margin-bottom: 6px;
}
.rank-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(180deg, #13315c, #0b2545);
    border-radius: 0 0 4px 4px;
    transition: height .25s ease;
    min-height: 2px;
}
.rank-count {
    font-weight: 700;
    color: #0b2545;
    font-size: 0.9rem;
}

/* ---------- Empty state ---------- */
.empty {
    padding: 60px 20px;
    text-align: center;
    color: #6b7280;
}
.empty h3 { font-weight: 700; color: #374151; margin-bottom: 6px; }
.empty p { font-weight: 300; }

/* ---------- Upload form ---------- */
.upload-card { max-width: 640px; }
.upload-card .help {
    font-size: 0.85rem;
    color: #6b7280;
    font-weight: 300;
    margin-top: 4px;
}
.upload-card .btn-primary { margin-top: 8px; }

.flash {
    padding: 14px 18px;
    border-radius: 8px;
    margin-bottom: 18px;
    font-weight: 400;
    font-size: 0.92rem;
}
.flash.success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.flash.error   { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }

/* ---------- Modal ---------- */
.modal-backdrop {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.45);
    display: none;
    align-items: center; justify-content: center;
    z-index: 1000; padding: 20px;
}
.modal-backdrop.show { display: flex; }
.modal {
    background: #fff;
    width: 100%; max-width: 400px;
    border-radius: 12px;
    padding: 28px 28px 22px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.modal-title { font-weight: 700; font-size: 1.1rem; margin-bottom: 8px; color: #0b2545; }
.modal-body { font-weight: 300; color: #4b5563; margin-bottom: 20px; line-height: 1.5; }
.modal-actions { text-align: right; }
.modal-actions button {
    padding: 9px 20px;
    border: none; border-radius: 7px;
    background: #0b2545; color: #fff;
    font-family: 'Lato', sans-serif;
    font-weight: 700; font-size: 0.85rem;
    cursor: pointer;
}
