/* --- GLOBAL VARIABLES (Modern Clean Theme) --- */
:root {
    /* The "AI Tutor" Palette */
    --bg-base: #ffffff;
    --bg-body: #ffffff;
    --bg-body-image: 
        radial-gradient(circle at 90% 10%, rgba(255, 182, 193, 0.4) 0%, transparent 40%),
        radial-gradient(circle at 10% 90%, rgba(162, 155, 254, 0.3) 0%, transparent 40%);
    --brand-gradient: linear-gradient(135deg, #ff6b6b 0%, #a29bfe 100%);
    
    --text-main: #2d3436;
    --text-light: #636e72;
    
    --card-bg: #ffffff;
    --card-bg-gradient: linear-gradient(to bottom right, #ffffff, #fafafa);
    --card-shadow: 0 20px 40px rgba(0, 0, 0, 0.05);
    --card-border: 1px solid rgba(0,0,0,0.05);
    
    --input-bg: #fdfdfd;
    --input-border: #f1f2f6;
    --input-focus-bg: #fff;
    
    --nav-bg: rgba(255, 255, 255, 0.9);
    --nav-border: 1px solid rgba(0,0,0,0.05);
    --user-display-bg: white;
    --user-display-border: #f0f0f0;
    
    --table-row-bg: white;
    --table-header-color: #95a5a6;
    
    --modal-overlay: rgba(255, 255, 255, 0.8);
    --modal-bg: white;
    --modal-border: #eee;
    
    --btn-primary-bg: #000000;
    --btn-primary-color: white;
    
    --font-family: 'Poppins', 'Segoe UI', sans-serif;
}

/* --- DARK MODE OVERRIDES --- */
body.dark-mode {
    --bg-base: #1a1a2e;
    --bg-body: #1a1a2e;
    --bg-body-image: 
        radial-gradient(circle at 90% 10%, rgba(255, 107, 107, 0.15) 0%, transparent 40%),
        radial-gradient(circle at 10% 90%, rgba(162, 155, 254, 0.12) 0%, transparent 40%);
    
    --text-main: #e0e0e0;
    --text-light: #a0a0b0;
    
    --card-bg: rgba(30, 30, 50, 0.85);
    --card-bg-gradient: linear-gradient(to bottom right, rgba(30, 30, 50, 0.9), rgba(25, 25, 45, 0.85));
    --card-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    --card-border: 1px solid rgba(255,255,255,0.08);
    
    --input-bg: rgba(255,255,255,0.06);
    --input-border: rgba(255,255,255,0.1);
    --input-focus-bg: rgba(255,255,255,0.1);
    
    --nav-bg: rgba(26, 26, 46, 0.92);
    --nav-border: 1px solid rgba(255,255,255,0.06);
    --user-display-bg: rgba(255,255,255,0.08);
    --user-display-border: rgba(255,255,255,0.1);
    
    --table-row-bg: rgba(30, 30, 50, 0.7);
    --table-header-color: #8888a0;
    
    --modal-overlay: rgba(0, 0, 0, 0.7);
    --modal-bg: #1e1e32;
    --modal-border: rgba(255,255,255,0.1);
    
    --btn-primary-bg: #6c5ce7;
    --btn-primary-color: white;
}

/* --- RESET & BODY --- */
* { box-sizing: border-box; transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1); }

body {
    font-family: var(--font-family);
    margin: 0;
    min-height: 100vh;
    color: var(--text-main);
    display: flex;
    flex-direction: column;
    overflow-x: hidden;

    /* --- THE "CHATBOT" BACKGROUND EFFECT --- */
    background-color: var(--bg-body);
    background-image: var(--bg-body-image);
    background-attachment: fixed; 
}

/* --- AUTHENTICATION (Login/Register) --- */
.auth-body {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
}

.auth-container {
    background: var(--card-bg);
    backdrop-filter: blur(12px);
    padding: 3.5rem;
    border-radius: 24px;
    box-shadow: var(--card-shadow);
    width: 420px;
    text-align: center;
    border: var(--card-border);
}

.auth-container h2 {
    margin-bottom: 1.5rem;
    font-size: 2rem;
    font-weight: 800;
    background: var(--brand-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    letter-spacing: -1px;
}

/* --- INPUT FIELDS --- */
input, select, textarea {
    width: 100%;
    padding: 16px;
    margin: 12px 0;
    border: 2px solid var(--input-border);
    border-radius: 16px;
    font-size: 1rem;
    background: var(--input-bg);
    outline: none;
    color: var(--text-main);
    font-family: inherit;
}

input:focus, select:focus, textarea:focus {
    border-color: #a29bfe;
    background: var(--input-focus-bg);
    box-shadow: 0 4px 12px rgba(162, 155, 254, 0.2);
}

/* --- INTERACTIVE BUTTONS --- */
button {
    width: 100%;
    padding: 16px;
    margin-top: 20px;
    background: var(--btn-primary-bg);
    color: var(--btn-primary-color);
    border: none;
    border-radius: 16px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 10px 20px rgba(0,0,0,0.1);
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 15px 30px rgba(0,0,0,0.15);
}

button:active {
    transform: scale(0.98);
}

a {
    color: #a29bfe;
    font-weight: 600;
    text-decoration: none;
}
a:hover { text-decoration: underline; color: #6c5ce7; }

/* --- NAVIGATION BAR (Layout Fixed) --- */
nav {
    background: var(--nav-bg);
    backdrop-filter: blur(12px);
    padding: 1rem 3rem;
    display: flex;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: var(--nav-border);
}

/* 1. Title stays on left */
nav h2 { 
    margin: 0; 
    font-size: 1.5rem; 
    font-weight: 800;
    background: var(--brand-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    letter-spacing: -0.5px;
    white-space: nowrap;
}

/* 2. User Name sits next to Title */
#user-display {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--user-display-bg);
    padding: 8px 24px 8px 8px;
    border-radius: 50px;
    border: 2px solid var(--user-display-border);
    box-shadow: 0 4px 20px rgba(0,0,0,0.05);
    
    font-weight: 700;
    color: var(--text-main);
    font-size: 1.05rem;
    
    margin-left: 25px;
    transition: transform 0.2s ease;
}

/* Avatar Circle */
#user-display::before {
    content: ''; 
    display: block;
    width: 36px;
    height: 36px;
    background: var(--brand-gradient);
    border-radius: 50%;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

#user-display:hover {
    transform: translateY(-1px);
    border-color: #a29bfe;
    box-shadow: 0 6px 25px rgba(0,0,0,0.08);
}

/* 3. Logout Button pushed to far right */
.logout-btn {
    width: auto;
    background: #ff7675;
    color: white;
    border: none;
    padding: 10px 28px;
    margin-left: auto; /* THIS pushes it to the far right */
    margin-top: 0; /* Reset top margin */
    font-size: 0.95rem;
    border-radius: 50px;
    transition: all 0.3s;
    box-shadow: 0 5px 15px rgba(255, 118, 117, 0.3);
}

.logout-btn:hover {
    background: #d63031;
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(214, 48, 49, 0.4);
}

/* --- DASHBOARD LAYOUT --- */
.container {
    padding: 3rem;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

.card {
    background: var(--card-bg);
    backdrop-filter: blur(12px);
    padding: 2.5rem;
    margin-bottom: 2rem;
    border-radius: 24px;
    box-shadow: var(--card-shadow);
    border: var(--card-border);
    animation: fadeUp 0.5s ease-out;
}

.card h4 {
    margin-top: 0;
    font-size: 1.25rem;
    color: var(--text-main);
}

/* --- TABLES (Fixed Vertical Alignment) --- */
table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0 12px;
    margin-top: 1rem;
}

thead th {
    text-align: left;
    padding: 1rem 1.5rem;
    color: var(--table-header-color);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    border: none;
}

tbody tr {
    background: var(--table-row-bg);
    border-radius: 16px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.03);
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    position: relative;
    z-index: 1;
}

tbody tr:hover { 
    transform: translateY(-5px) scale(1.01); 
    box-shadow: 0 15px 30px rgba(0,0,0,0.08);
    z-index: 10;
}

/* VERTICAL ALIGNMENT FIX */
td { 
    padding: 1.5rem; 
    color: var(--text-main);
    font-weight: 500;
    border: none;
    vertical-align: middle; /* Keeps text and badges centered vertically */
}

td:first-child { border-top-left-radius: 16px; border-bottom-left-radius: 16px; }
td:last-child { border-top-right-radius: 16px; border-bottom-right-radius: 16px; }

td:nth-child(4) { 
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text-main);
}

/* --- GRID CARDS --- */
.grid-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 2rem;
}

.grid-container .card {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    background-image: var(--card-bg-gradient);
    background-color: var(--card-bg);
}

/* --- STATUS BADGES (Perfectly Centered) --- */
.status-final {
    display: inline-flex; /* Fixes alignment issues */
    align-items: center;  /* Centers text vertically */
    justify-content: center;
    height: 32px;         /* Fixed height for consistent look */
    color: #00b894;
    background: rgba(0, 184, 148, 0.08);
    padding: 0 16px;      /* Horizontal padding only */
    border-radius: 30px;
    font-weight: 700;
    font-size: 0.75rem;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    box-shadow: 0 2px 10px rgba(0, 184, 148, 0.1);
}

.status-pending {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 32px;
    color: #e17055;
    background: rgba(225, 112, 85, 0.08);
    padding: 0 16px;
    border-radius: 30px;
    font-weight: 700;
    font-size: 0.75rem;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    box-shadow: 0 2px 10px rgba(225, 112, 85, 0.1);
}

/* --- MODAL --- */
.modal {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: var(--modal-overlay);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background: var(--modal-bg);
    padding: 3rem;
    border-radius: 24px;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 25px 50px rgba(0,0,0,0.1);
    border: 1px solid var(--modal-border);
}

.close {
    float: right;
    font-size: 2rem;
    cursor: pointer;
    color: #ccc;
}
.close:hover { color: #2d3436; }

.warning {
    background: #fff5f5;
    color: #e17055;
    padding: 15px;
    border-radius: 12px;
    margin-top: 15px;
    font-size: 0.9rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 10px;
}

/* --- UTILITIES --- */
.hidden { display: none !important; }
.error-msg { color: #ff7675; margin-top: 10px; font-weight: 500; }
.text-muted { color: #b2bec3; font-size: 0.85rem; }

@keyframes fadeUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* --- FILTER BAR (Search + Dropdown + CSV) --- */
.filter-bar {
    display: flex;
    gap: 12px;
    margin-bottom: 1.5rem;
    align-items: center;
    flex-wrap: wrap;
}

.filter-bar input[type="text"] {
    flex: 1;
    min-width: 200px;
    margin: 0;
}

.filter-bar select {
    width: 180px;
    margin: 0;
}

.csv-btn {
    width: auto;
    background: linear-gradient(135deg, #00b894, #00cec9);
    color: white;
    border: none;
    padding: 14px 24px;
    margin: 0;
    font-size: 0.9rem;
    border-radius: 16px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 8px 20px rgba(0, 184, 148, 0.25);
    white-space: nowrap;
}

.csv-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 28px rgba(0, 184, 148, 0.35);
}

/* --- PROFILE BUTTON (Nav) --- */
.profile-btn {
    width: auto;
    background: #6c5ce7;
    color: white;
    border: none;
    padding: 10px 24px;
    margin-left: 12px;
    margin-top: 0;
    font-size: 0.95rem;
    border-radius: 50px;
    transition: all 0.3s;
    box-shadow: 0 5px 15px rgba(108, 92, 231, 0.3);
}

.profile-btn:hover {
    background: #5b4cdb;
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(108, 92, 231, 0.4);
}

/* --- UNLOCK BUTTON --- */
.unlock-btn {
    width: auto;
    padding: 8px 18px;
    margin: 0;
    font-size: 0.8rem;
    background: #fdcb6e;
    color: #2d3436;
    border: none;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(253, 203, 110, 0.3);
}

.unlock-btn:hover {
    background: #f9c846;
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(253, 203, 110, 0.45);
}

/* --- TOTAL DISPLAY (Rubric Modal) --- */
.total-display {
    background: linear-gradient(135deg, #dfe6e9, #ffeaa7);
    padding: 16px;
    border-radius: 16px;
    font-size: 1.2rem;
    font-weight: 700;
    text-align: center;
    margin: 12px 0;
    color: #2d3436;
    letter-spacing: 0.5px;
}

/* --- ANALYTICS SECTION --- */
.analytics-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--card-bg);
    backdrop-filter: blur(12px);
    padding: 2rem;
    border-radius: 24px;
    box-shadow: var(--card-shadow);
    border: var(--card-border);
    text-align: center;
    animation: fadeUp 0.5s ease-out;
}

.stat-card .stat-number {
    font-size: 2.8rem;
    font-weight: 800;
    background: var(--brand-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.stat-card .stat-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 1.5px;
    margin-top: 6px;
}

.stat-card.stat-pending .stat-number {
    background: linear-gradient(135deg, #e17055, #fdcb6e);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.stat-card.stat-completed .stat-number {
    background: linear-gradient(135deg, #00b894, #00cec9);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.charts-row {
    display: grid;
    grid-template-columns: 1fr 1.5fr;
    gap: 2rem;
    margin-bottom: 2rem;
}

.chart-card {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.chart-card canvas {
    max-height: 300px;
    width: 100% !important;
}

/* --- FIX: Restore table-cell display when status badges are on <td> --- */
td.status-final,
td.status-pending,
td.status-overdue {
    display: table-cell;
    vertical-align: middle;
    text-align: center;
}

/* --- OVERDUE BADGE --- */
.status-overdue {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 32px;
    color: #d63031;
    background: rgba(214, 48, 49, 0.1);
    padding: 0 16px;
    border-radius: 30px;
    font-weight: 700;
    font-size: 0.75rem;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    box-shadow: 0 2px 10px rgba(214, 48, 49, 0.15);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* --- DARK MODE TOGGLE BUTTON --- */
.theme-toggle {
    width: auto;
    background: var(--user-display-bg);
    border: 2px solid var(--user-display-border);
    padding: 8px 16px;
    margin-left: 12px;
    margin-top: 0;
    font-size: 1.2rem;
    border-radius: 50px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
    color: var(--text-main);
    line-height: 1;
}

.theme-toggle:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(0,0,0,0.1);
}

/* Auth page theme toggle (positioned top-right) */
.auth-theme-toggle {
    position: fixed;
    top: 1.5rem;
    right: 1.5rem;
    width: auto;
    background: var(--card-bg);
    border: 2px solid var(--input-border);
    padding: 10px 18px;
    margin: 0;
    font-size: 1.3rem;
    border-radius: 50px;
    cursor: pointer;
    box-shadow: var(--card-shadow);
    z-index: 200;
    color: var(--text-main);
    line-height: 1;
}

.auth-theme-toggle:hover {
    transform: translateY(-2px) scale(1.05);
}

/* --- PDF DOWNLOAD BUTTON --- */
.pdf-btn {
    width: auto;
    display: inline-block;
    background: linear-gradient(135deg, #e17055, #d63031);
    color: white;
    border: none;
    padding: 8px 20px;
    margin: 4px 0 0 0;
    font-size: 0.8rem;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(214, 48, 49, 0.25);
}

.pdf-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(214, 48, 49, 0.35);
}

/* --- SCORECARD TEMPLATE (Hidden, for PDF rendering) --- */
#scorecard-template {
    position: fixed;
    left: -9999px;
    top: 0;
    z-index: -1;
}

.scorecard {
    width: 700px;
    padding: 40px;
    background: #ffffff;
    color: #000000;
    font-family: 'Poppins', 'Segoe UI', sans-serif;
}

.scorecard-header {
    text-align: center;
    border-bottom: 3px solid #2d3436;
    padding-bottom: 16px;
    margin-bottom: 24px;
}

.scorecard-header .logo-placeholder {
    width: 60px;
    height: 60px;
    margin: 0 auto 10px;
    background: linear-gradient(135deg, #ff6b6b, #a29bfe);
    border-radius: 50%;
}

.scorecard-header h2 {
    margin: 4px 0;
    font-size: 1.5rem;
    color: #2d3436;
    background: none;
    -webkit-background-clip: unset;
    background-clip: unset;
}

.scorecard-header p {
    margin: 2px 0;
    font-size: 0.85rem;
    color: #636e72;
}

.scorecard-info {
    display: flex;
    justify-content: space-between;
    margin-bottom: 24px;
    font-size: 0.95rem;
}

.scorecard-info div {
    color: #2d3436;
}

.scorecard-info strong {
    color: #2d3436;
}

.scorecard-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 24px;
}

.scorecard-table th,
.scorecard-table td {
    border: 1px solid #ddd;
    padding: 12px 16px;
    text-align: left;
    font-size: 0.95rem;
    color: #2d3436;
    background: #ffffff;
}

.scorecard-table th {
    background: #f5f6fa;
    font-weight: 700;
    text-transform: uppercase;
    font-size: 0.8rem;
    letter-spacing: 1px;
    color: #2d3436;
}

.scorecard-table .total-row {
    background: #f0f0f0;
    font-weight: 700;
}

.scorecard-remarks {
    padding: 12px;
    background: #f9f9f9;
    border: 1px solid #ddd;
    border-radius: 8px;
    margin-bottom: 24px;
    font-size: 0.9rem;
    color: #2d3436;
}

.scorecard-footer {
    text-align: center;
    font-size: 0.75rem;
    color: #999;
    border-top: 1px solid #eee;
    padding-top: 16px;
}