:root {
    --bg: #f4f7fb;
    --panel: #ffffff;
    --line: #d8e1ee;
    --text: #1f2a37;
    --muted: #5a6a7c;
    --brand: #0f766e;
    --brand-dark: #115e59;
    --accent: #f59e0b;
    --danger: #b91c1c;
    --ok: #166534;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: 'Outfit', 'Noto Sans Tamil', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: var(--text);
    background: linear-gradient(180deg, #edf5ff 0%, var(--bg) 100%);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a {
    color: var(--brand-dark);
    text-decoration: none;
}

/* ──────────────────────────────────────────────────────────────────
   MEGA MENU NAVIGATION
   ────────────────────────────────────────────────────────────────── */
.navbar {
    background: rgba(8, 51, 68, 0.98);
    backdrop-filter: blur(12px);
    color: #fff;
    position: sticky;
    top: 0;
    z-index: 9999;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.nav-container {
    width: min(1280px, 94%);
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 80px;
}

.nav-brand a {
    color: #fff !important;
    display: block;
}

.nav-brand h1 {
    font-size: 1.3rem;
    margin: 0;
    letter-spacing: -0.01em;
    font-weight: 700;
}

.nav-brand .subtitle {
    font-size: 0.75rem;
    margin: 2px 0 0;
    opacity: 0.7;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.nav-menu {
    display: flex;
    align-items: center;
    gap: 10px;
    height: 100%;
}

.nav-item {
    position: relative;
    height: 100%;
    display: flex;
    align-items: center;
}

.nav-link {
    color: rgba(255, 255, 255, 0.85) !important;
    font-weight: 600;
    padding: 0 20px;
    height: 100%;
    display: flex;
    align-items: center;
    transition: 0.3s;
    font-size: 0.95rem;
}

.nav-link:hover {
    color: #fff !important;
    background: rgba(255, 255, 255, 0.05);
}

/* Mega Menu Core */
.mega-menu {
    position: absolute;
    top: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(10px);
    background: #fff;
    color: #1f2a37;
    width: 600px;
    border-radius: 16px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
    padding: 30px;
    opacity: 0;
    visibility: hidden;
    transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid #e2e8f0;
}

.nav-item:hover .mega-menu {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

.mini-mega {
    width: 250px;
    padding: 15px;
}

.mega-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 30px;
}

.mini-mega .mega-grid {
    grid-template-columns: 1fr;
    gap: 10px;
}

.mega-col h4 {
    margin: 0 0 15px 0;
    font-size: 0.8rem;
    text-transform: uppercase;
    color: #64748b;
    letter-spacing: 0.1em;
}

.mega-col a {
    display: block;
    padding: 10px 15px;
    color: #334155 !important;
    font-weight: 500;
    border-radius: 8px;
    transition: 0.2s;
    font-size: 0.9rem;
}

.mega-col a:hover {
    background: #f1f5f9;
    color: var(--brand) !important;
    padding-left: 20px;
}

.btn-nav {
    background: var(--brand);
    color: white !important;
    padding: 8px 20px;
    border-radius: 8px;
    margin-left: 10px;
}

.btn-nav:hover {
    background: var(--brand-dark);
}

/* Mobile Toggle */
.nav-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 10px;
    flex-direction: column;
    gap: 5px;
}

.nav-toggle span {
    display: block;
    width: 25px;
    height: 3px;
    background: white;
    border-radius: 2px;
    transition: 0.3s;
}

@media (max-width: 992px) {
    .nav-toggle { display: flex; }
    .nav-menu {
        position: fixed;
        top: 80px;
        left: -100%;
        width: 100%;
        height: calc(100vh - 80px);
        background: #fff;
        flex-direction: column;
        padding: 40px 20px;
        transition: 0.4s;
        overflow-y: auto;
        align-items: flex-start;
        gap: 0;
    }
    .nav-menu.active { left: 0; }
    .nav-item { width: 100%; height: auto; display: block; border-bottom: 1px solid #f1f5f9; }
    .nav-link { color: #1f2a37 !important; padding: 20px 0; height: auto; font-size: 1.2rem; }
    .nav-link:hover { background: none; }
    .mega-menu {
        position: static !important;
        transform: none !important;
        width: 100% !important;
        box-shadow: none !important;
        padding: 0 0 20px 20px !important;
        opacity: 1 !important;
        visibility: visible !important;
        display: none !important;
        border: none !important;
    }
    .nav-item:hover .mega-menu, .nav-item.open .mega-menu { display: block !important; }
    .mega-grid { gap: 15px; }
    .btn-nav { margin: 20px 0; width: 100%; text-align: center; }
}

.container {
    width: min(1180px, 94%);
    margin: 24px auto;
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
}

.card,
.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 12px 30px rgba(15, 23, 42, 0.05);
    transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Global Image Safeguards */
img {
    max-width: 100%;
    height: auto;
}
table img {
    max-width: 120px;
    max-height: 120px;
    object-fit: contain;
    border-radius: 8px;
}
.img-box img, .img-wrap img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.hero {
    padding: 28px;
    border-radius: 22px;
    background: linear-gradient(135deg, #0f766e 0%, #164e63 100%);
    color: white;
    margin-bottom: 22px;
}

.hero h2 {
    margin-top: 0;
}

form {
    display: grid;
    gap: 14px;
}

label {
    display: grid;
    gap: 6px;
    font-weight: 600;
}

input,
select,
textarea,
button {
    font: inherit;
}

input,
select,
textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #bfd0e5;
    border-radius: 10px;
    background: #fff;
}

textarea {
    min-height: 100px;
    resize: vertical;
}

button,
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: 12px;
    border: 0;
    cursor: pointer;
    background: var(--brand);
    color: white;
    font-weight: 600;
    font-size: 0.95rem;
    transition: all 0.2s ease;
    box-shadow: 0 4px 12px rgba(15, 118, 110, 0.2);
}

button:hover,
.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(15, 118, 110, 0.3);
    background: var(--brand-dark);
}

button:active,
.btn:active {
    transform: translateY(0);
}

.btn-secondary {
    background: #475569;
    color: white !important;
    box-shadow: 0 4px 12px rgba(71, 85, 105, 0.15);
}

.btn-secondary:hover {
    background: #334155;
    color: white !important;
    box-shadow: 0 6px 16px rgba(71, 85, 105, 0.25);
}

.btn-warning {
    background: var(--accent);
    color: #111827;
    box-shadow: 0 4px 12px rgba(245, 158, 11, 0.2);
}

.btn-warning:hover {
    background: #d97706;
    box-shadow: 0 6px 16px rgba(245, 158, 11, 0.3);
}

.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.stat {
    background: white;
    padding: 24px;
    border-radius: 20px;
    border: 1px solid var(--line);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    color: white;
}

.stat:hover {
    transform: translateY(-4px);
    box-shadow: 0 20px 40px rgba(0,0,0,0.1);
}

.stat span {
    font-size: 0.9rem;
    font-weight: 600;
    opacity: 0.85;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stat strong {
    display: block;
    font-size: 34px;
    margin-top: 10px;
    letter-spacing: -0.02em;
}

/* Stat Gradients */
.stat-1 { background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%); } /* Indigo */
.stat-2 { background: linear-gradient(135deg, #10b981 0%, #059669 100%); } /* Emerald */
.stat-3 { background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%); } /* Amber */
.stat-4 { background: linear-gradient(135deg, #ec4899 0%, #db2777 100%); } /* Pink */

.chart-container {
    background: white;
    padding: 24px;
    border-radius: 20px;
    border: 1px solid var(--line);
    box-shadow: 0 12px 30px rgba(15, 23, 42, 0.05);
}

.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 16px;
    border: 1px solid var(--line);
    background: white;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    border-radius: 12px;
    overflow: hidden;
}

th,
td {
    padding: 16px;
    border-bottom: 1px solid #f1f5f9;
    text-align: left;
    vertical-align: middle;
}

th {
    background: #f8fafc;
    font-weight: 700;
    color: #475569;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

tr:last-child td {
    border-bottom: 0;
}

tr:hover td {
    background: #fdfdfd;
}

.alert {
    padding: 12px 14px;
    border-radius: 10px;
    margin-bottom: 16px;
}

.alert.success {
    background: #dcfce7;
    color: var(--ok);
}

.alert.error {
    background: #fee2e2;
    color: var(--danger);
}

.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.chip {
    padding: 4px 10px;
    background: #e0f2fe;
    border-radius: 999px;
    font-size: 13px;
}

.question-block {
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 16px;
    background: #fcfdff;
    margin-bottom: 14px;
}

.inline {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
}

.muted {
    color: var(--muted);
}

/* Removed Legacy Sidebar Drawer Styles */

/* Dashboard & Grid Fixes */
@media (max-width: 768px) {
    .container { width: 92%; margin: 16px auto; }
    .hero { padding: 20px; border-radius: 16px; }
    .hero h2 { font-size: 1.5rem; }
    .grid, .stats, .inline { grid-template-columns: 1fr; }
    .stat { padding: 20px; }
    .stat strong { font-size: 28px; }
    .card, .panel { padding: 15px; border-radius: 12px; }
    th, td { padding: 12px 10px; font-size: 0.85rem; }
    
    /* Fix forms to stack cleanly */
    form { display: flex; flex-direction: column; gap: 14px; }
    
    /* Search/Action Bars */
    form[method="get"] { 
        display: flex; 
        flex-direction: column; 
        gap: 10px; 
    }
    form[method="get"] select,
    form[method="get"] input,
    form[method="get"] button {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .topbar h1 { font-size: 1.1rem; }
    .hero h2 { font-size: 1.2rem; }
    .btn, button { width: 100%; padding: 12px; justify-content: center; }
    
    /* For header action div patterns */
    div[style*="display: flex; justify-content: space-between"] {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 15px !important;
    }
    div[style*="display: flex; justify-content: space-between"] h2 {
        margin-bottom: 0 !important;
    }
    
    /* Wrap long content in table cells */
    td { white-space: normal; word-break: break-word; }
    
    .chips { flex-direction: column; width: 100%; }
    .chip { text-align: center; }
}

/* Fix for overlapping headers in take_exam.php */
.take-exam-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
}
@media (max-width: 640px) {
    .take-exam-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
    }
    .take-exam-header > div:last-child {
        width: 100%;
        text-align: left !important;
    }
}
