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

body {
    font-family: 'Segoe UI', Arial, sans-serif;
    background: var(--bg, #f3f4f6);
    color: var(--text, #1f2937);
}

/* ===== Login Page ===== */
.login-body {
    background: linear-gradient(135deg, var(--primary, #4f46e5) 0%, var(--primary-light, #7c3aed) 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-wrapper {
    text-align: center;
}

.login-card {
    background: var(--card-bg, #ffffff);
    border-radius: 16px;
    padding: 40px 36px;
    width: 380px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}

.login-logo {
    margin-bottom: 28px;
}

.logo-circle {
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, var(--primary, #4f46e5), var(--primary-light, #7c3aed));
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 18px;
    margin: 0 auto 14px;
    overflow: hidden;
}

.logo-circle img { width: 100%; height: 100%; object-fit: cover; }

.login-logo h1 {
    font-size: 20px;
    color: var(--text, #1f2937);
    margin-bottom: 4px;
}

.subtitle {
    color: var(--text-muted, #6b7280);
    font-size: 14px;
}

.form-group {
    text-align: left;
    margin-bottom: 18px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text, #374151);
    margin-bottom: 6px;
}

.form-group input {
    width: 100%;
    padding: 11px 14px;
    border: 1.5px solid var(--border, #e5e7eb);
    border-radius: 8px;
    font-size: 14px;
    background-color: var(--input-bg, #ffffff);
    color: var(--text, #1f2937);
    transition: border-color 0.2s;
}

.form-group select {
    width: 100%;
    padding: 11px 14px;
    border: 1.5px solid var(--border, #e5e7eb);
    border-radius: 8px;
    font-size: 14px;
    color: var(--text, #1f2937);
    background-color: var(--input-bg, #ffffff);
    cursor: pointer;
    transition: border-color 0.2s;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b7280' stroke-width='1.5' fill='none' fill-rule='evenodd'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 36px;
}

.form-group select:focus {
    outline: none;
    border-color: var(--primary-light, #7c3aed);
    box-shadow: 0 0 0 3px rgba(124,58,237,0.12);
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary-light, #7c3aed);
}

.btn-login {
    width: 100%;
    padding: 12px;
    background: linear-gradient(135deg, var(--primary, #4f46e5), var(--primary-light, #7c3aed));
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
}

.btn-login:hover {
    opacity: 0.9;
}

.alert {
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 13px;
    margin-bottom: 16px;
    text-align: left;
}

/* Status alerts stay semantically red/green regardless of theme */
.alert-error {
    background: #fee2e2;
    color: #b91c1c;
    border: 1px solid #fecaca;
}

.alert-success {
    background: #dcfce7;
    color: #15803d;
    border: 1px solid #bbf7d0;
}

.footer-note {
    color: rgba(255,255,255,0.85);
    font-size: 13px;
    margin-top: 20px;
}

/* ===== Dashboard Pages (legacy topbar, used by Teacher/Student/Parent) ===== */
.topbar {
    background: var(--navbar-bg, #1f2937);
    color: var(--nav-text-strong, #ffffff);
    padding: 16px 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logout-link {
    color: #fca5a5;
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
}

.logout-link:hover {
    text-decoration: underline;
}

.page-content {
    max-width: 1000px;
    margin: 40px auto;
    padding: 0 20px;
}

.page-content h1 {
    color: var(--text, #1f2937);
    margin-bottom: 10px;
}

.page-content p {
    color: var(--text-muted, #6b7280);
    margin-bottom: 20px;
}

/* ===== Forms & Tables ===== */
.card {
    background: var(--card-bg, #ffffff);
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    margin-bottom: 24px;
}

.card h2 {
    font-size: 16px;
    color: var(--text, #1f2937);
    margin-bottom: 16px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border, #e5e7eb);
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.form-grid .form-group.full-width {
    grid-column: 1 / -1;
}

.btn-primary {
    padding: 10px 22px;
    background: linear-gradient(135deg, var(--primary, #4f46e5), var(--primary-light, #7c3aed));
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 6px;
}

.btn-primary:hover {
    opacity: 0.9;
}

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

table th, table td {
    text-align: left;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border, #e5e7eb);
    font-size: 14px;
    color: var(--text, #1f2937);
}

table th {
    background: var(--surface, #f9fafb);
    color: var(--text, #374151);
    font-weight: 600;
}

.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}

/* Status badges stay semantically green/gray regardless of theme */
.badge-active {
    background: #dcfce7;
    color: #15803d;
}

.badge-inactive {
    background: #f3f4f6;
    color: #6b7280;
}

.back-link {
    display: inline-block;
    margin-bottom: 16px;
    color: var(--primary, #4f46e5);
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
}

.back-link:hover {
    text-decoration: underline;
}

/* ===== Navbar ===== */
.navbar {
    background: var(--navbar-bg, #1f2937);
    padding: 8px 24px;
    display: flex;
    align-items: center;
    gap: 4px;
    row-gap: 6px;
    flex-wrap: wrap;
    box-shadow: 0 2px 10px rgba(0,0,0,0.15);
    position: relative;
    z-index: 100;
}

.navbar-brand {
    color: var(--nav-text-strong, #ffffff);
    font-weight: 800;
    font-size: 16px;
    padding: 8px 20px 8px 0;
    margin-right: 10px;
    border-right: 1px solid rgba(128,128,128,0.3);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 8px;
}

.navbar-brand img { height: 28px; width: auto; border-radius: 4px; }

.navbar-links {
    display: flex;
    flex: 1;
    flex-wrap: wrap;
    gap: 3px;
    row-gap: 6px;
    align-items: center;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--nav-text, #d1d5db);
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    padding: 9px 14px;
    border-radius: 9px;
    transition: color 0.15s, background-color 0.15s, transform 0.1s;
}

.nav-link:hover {
    color: var(--nav-text-strong, #ffffff);
    background: rgba(255,255,255,0.09);
}

.nav-link:active {
    transform: scale(0.97);
}

.nav-link.active {
    color: var(--nav-text-strong, #ffffff);
    background: var(--primary-light, #7c3aed);
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.nav-icon {
    font-size: 15px;
}

.navbar-user {
    display: flex;
    align-items: center;
    gap: 14px;
    color: var(--nav-text, #d1d5db);
    font-size: 13px;
    padding: 14px 0;
    white-space: nowrap;
}

.navbar-user .logout-link {
    color: #fca5a5;
    text-decoration: none;
    font-weight: 600;
}

.navbar-user .logout-link:hover {
    text-decoration: underline;
}

@media (max-width: 768px) {
    .navbar { padding: 0 14px; position: relative; }
    .nav-label { display: none; }
    .navbar-brand { padding: 10px 10px 10px 0; }
}

/* ===== Mobile hamburger menu ===== */
.navbar-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--nav-text-strong, #ffffff);
    font-size: 22px;
    cursor: pointer;
    padding: 12px 8px;
    margin-left: auto;
}

@media (max-width: 768px) {
    .navbar { flex-wrap: wrap !important; align-items: center; }
    .navbar-toggle { display: block !important; }
    .navbar-links, .navbar-user { display: none !important; }

    .quick-links-bar { padding: 10px 14px; overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; }
    .quick-link-btn { flex-shrink: 0; }
}

/* ===== Mobile full-screen menu overlay ===== */
.mobile-menu-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--card-bg, #ffffff);
    z-index: 9999;
    flex-direction: column;
    overflow-y: auto;
}
.mobile-menu-overlay.open { display: flex; }

.mobile-menu-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border, #e5e7eb);
    flex-shrink: 0;
}
.mobile-menu-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 800;
    font-size: 16px;
    color: var(--text, #1f2937);
}
.mobile-menu-brand img { height: 28px; width: auto; border-radius: 4px; }
.mobile-menu-close {
    background: none;
    border: none;
    font-size: 28px;
    line-height: 1;
    color: var(--text, #1f2937);
    cursor: pointer;
    padding: 4px 8px;
}

.mobile-menu-list { flex: 1; padding: 4px 0; }
.mobile-menu-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 20px;
    color: var(--text, #1f2937);
    text-decoration: none;
    font-size: 15px;
    font-weight: 600;
    border-bottom: 1px solid var(--border, #e5e7eb);
}
.mobile-menu-item.active { color: var(--primary, #4f46e5); }
.mobile-menu-item .mm-caret { margin-left: auto; font-size: 12px; color: var(--text-muted, #9ca3af); transition: transform 0.2s; }
.mobile-menu-item.expanded .mm-caret { transform: rotate(180deg); }

.mobile-submenu { display: none; background: var(--surface, #f9fafb); }
.mobile-submenu.open { display: block; }
.mobile-submenu a {
    display: block;
    padding: 14px 20px 14px 50px;
    color: var(--text-muted, #6b7280);
    text-decoration: none;
    font-size: 14px;
    border-bottom: 1px solid var(--border, #e5e7eb);
}
.mobile-submenu a.active { color: var(--primary, #4f46e5); font-weight: 700; }

.mobile-menu-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 20px;
    border-top: 1px solid var(--border, #e5e7eb);
    font-size: 14px;
    color: var(--text, #1f2937);
    flex-shrink: 0;
}
.mobile-logout-link { color: #dc2626; text-decoration: none; font-weight: 700; }

@media (min-width: 769px) {
    .mobile-menu-overlay { display: none !important; }
}

/* ===== Sidebar Navigation (Left/Right position, desktop only) ===== */
@media (min-width: 769px) {
    body.nav-position-left .navbar,
    body.nav-position-right .navbar {
        position: fixed;
        top: 0;
        bottom: 0;
        width: 230px;
        flex-direction: column;
        align-items: stretch;
        padding: 0;
        overflow-y: auto;
        overflow-x: hidden;
        z-index: 500;
    }
    body.nav-position-left .navbar { left: 0; }
    body.nav-position-right .navbar { right: 0; }

    body.nav-position-left .navbar-brand,
    body.nav-position-right .navbar-brand {
        border-right: none;
        border-bottom: 1px solid rgba(128,128,128,0.15);
        padding: 18px 16px;
        width: 100%;
        margin-right: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    body.nav-position-left .navbar-links,
    body.nav-position-right .navbar-links {
        flex-direction: column;
        align-items: stretch;
        width: 100%;
        flex-wrap: nowrap;
    }

    body.nav-position-left .nav-link,
    body.nav-position-right .nav-link {
        width: 100%;
        padding: 13px 16px;
        border-bottom: none;
        border-left: 3px solid transparent;
        min-width: 0;
    }
    body.nav-position-left .nav-link .nav-label,
    body.nav-position-right .nav-link .nav-label {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        min-width: 0;
    }
    body.nav-position-left .nav-link.active { border-left-color: var(--primary-light); background: rgba(255,255,255,0.06); }
    body.nav-position-right .nav-link { border-left: none; border-right: 3px solid transparent; }
    body.nav-position-right .nav-link.active { border-right-color: var(--primary-light); background: rgba(255,255,255,0.06); }

    body.nav-position-left .nav-dropdown,
    body.nav-position-right .nav-dropdown { width: 100%; }
    body.nav-position-left .nav-dropdown-toggle,
    body.nav-position-right .nav-dropdown-toggle { justify-content: space-between; width: 100%; }

    body.nav-position-left .nav-dropdown-menu,
    body.nav-position-right .nav-dropdown-menu {
        position: static;
        display: none;
        box-shadow: none;
        border: none;
        border-radius: 0;
        background: rgba(0,0,0,0.15);
        margin-top: 0;
        padding: 0;
        min-width: 0;
        width: 100%;
    }
    body.nav-position-left .nav-dropdown.open .nav-dropdown-menu,
    body.nav-position-right .nav-dropdown.open .nav-dropdown-menu { display: block; }
    body.nav-position-left .nav-dropdown-menu a,
    body.nav-position-right .nav-dropdown-menu a {
        padding: 11px 16px 11px 34px;
        color: var(--nav-text);
        font-size: 13px;
        border-radius: 0;
    }

    body.nav-position-left .navbar-user,
    body.nav-position-right .navbar-user {
        flex-direction: column;
        align-items: stretch;
        width: 100%;
        margin-top: auto;
        padding: 14px 16px;
        border-top: 1px solid rgba(128,128,128,0.15);
        gap: 8px;
        white-space: normal;
    }
    body.nav-position-left .navbar-user span,
    body.nav-position-right .navbar-user span {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    body.nav-position-left .navbar-toggle,
    body.nav-position-right .navbar-toggle { display: none !important; }

    body.nav-position-left { padding-left: 230px; }
    body.nav-position-right { padding-right: 230px; }
}

/* ===== Buttons & action links ===== */
/* Danger actions stay semantically red regardless of theme */
.btn-danger {
    padding: 6px 14px;
    background: #dc2626;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}
.btn-danger:hover { opacity: 0.9; }

.btn-secondary {
    display: inline-block;
    padding: 10px 22px;
    background: var(--card-bg, #ffffff);
    color: var(--primary, #4f46e5);
    border: 1.5px solid var(--primary, #4f46e5);
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
}
.btn-secondary:hover { background: var(--surface, #eef2ff); }

.action-links { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.action-links a, .action-links button.link-delete, .action-links button.link-toggle, .action-links button.link-edit {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 5px 12px; border-radius: 6px; font-size: 12px; font-weight: 700;
    text-decoration: none; border: none; cursor: pointer; white-space: nowrap;
    font-family: inherit; transition: background 0.15s, color 0.15s;
}
.action-links .link-view { background: #e0f2fe; color: #0369a1; }
.action-links .link-view:hover { background: #0ea5e9; color: #fff; }
.action-links .link-edit { background: #ede9fe; color: var(--primary, #4f46e5); }
.action-links .link-edit:hover { background: var(--primary, #4f46e5); color: #fff; }
.action-links .link-toggle { background: #fef3c7; color: #a16207; }
.action-links .link-toggle:hover { background: #d97706; color: #fff; }
.action-links .link-delete { background: #fee2e2; color: #dc2626; }
.action-links .link-delete:hover { background: #dc2626; color: #fff; }

/* ===== Detail view grid ===== */
.detail-grid { display: grid; grid-template-columns: 150px 1fr; gap: 10px 16px; font-size: 14px; }
.detail-grid .d-label { color: var(--text-muted, #6b7280); font-weight: 600; }
.detail-grid .d-value { color: var(--text, #1f2937); }
.detail-photo {
    width: 130px; height: 150px; border-radius: 12px; object-fit: cover;
    border: 2px solid var(--border, #e0e7ff); background: var(--surface, #eef2ff);
    display: flex; align-items: center; justify-content: center; font-size: 40px; flex-shrink: 0;
}

.class-thumb {
    width: 44px; height: 44px; border-radius: 8px; object-fit: cover;
    background: var(--surface, #eef2ff); display: inline-flex; align-items: center; justify-content: center;
    font-size: 18px; vertical-align: middle; margin-right: 8px;
}
.class-photo-large {
    width: 100%; max-width: 220px; height: 140px; border-radius: 12px; object-fit: cover;
    border: 2px solid var(--border, #e0e7ff); background: var(--surface, #eef2ff); display: flex; align-items: center;
    justify-content: center; font-size: 40px; flex-shrink: 0;
}

/* ===== Theme swatches (used on the Settings page) ===== */
.theme-swatch {
    border: 2px solid var(--border, #e5e7eb); border-radius: 12px; padding: 4px; cursor: pointer;
    transition: border-color 0.2s;
}
.theme-swatch.selected { border-color: var(--primary, #4f46e5); }
.theme-swatch input { display: none; }
.theme-preview-bar { height: 28px; border-radius: 6px 6px 0 0; }
.theme-preview-body { height: 50px; border-radius: 0 0 6px 6px; padding: 6px; }
.theme-preview-body span { display: block; height: 8px; border-radius: 3px; margin-bottom: 4px; width: 70%; }
/* ===== Navbar dropdown submenus ===== */
.nav-dropdown { position: relative; }
.nav-dropdown-toggle { cursor: pointer; }
.nav-caret { font-size: 9px; margin-left: 2px; opacity: 0.7; transition: transform 0.2s; }
.nav-dropdown.open .nav-caret { transform: rotate(180deg); }
.nav-dropdown-menu {
    display: none; position: absolute; top: 100%; left: 0; background: var(--card-bg);
    border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,0.18);
    min-width: 210px; z-index: 200; padding: 6px; margin-top: 8px;
}
.nav-dropdown.open .nav-dropdown-menu { display: block; animation: navDropIn 0.15s ease; }
@keyframes navDropIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }
.nav-dropdown-menu a {
    display: block; padding: 10px 12px; color: var(--text); text-decoration: none; font-size: 13px;
    border-radius: 6px; font-weight: 500;
}
.nav-dropdown-menu a:hover { background: var(--surface); }
.nav-dropdown-menu a.active { color: var(--primary); font-weight: 700; }

/* ===== Quick Links bar ===== */
.quick-links-bar {
    background: var(--card-bg); border-bottom: 1px solid var(--border);
    padding: 14px 24px; display: flex; gap: 12px; flex-wrap: wrap; align-items: center;
}
.quick-link-btn {
    display: flex; align-items: center; gap: 8px; padding: 11px 20px; border-radius: 10px;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: #fff; text-decoration: none; font-size: 13px; font-weight: 700;
    box-shadow: 0 2px 8px rgba(0,0,0,0.12); transition: transform 0.15s, box-shadow 0.15s;
    border: none;
}
.quick-link-btn:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(0,0,0,0.2); color: #fff; }
.quick-link-icon { font-size: 18px; }
.quick-link-manage {
    background: var(--surface); color: var(--text); box-shadow: none; margin-left: auto;
    opacity: 0.75; border: 1px solid var(--border);
}
.quick-link-manage:hover { opacity: 1; transform: none; box-shadow: none; color: var(--text); }

/* ===== Quick Links management (drag-and-drop) ===== */
.sortable-item {
    display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--card-bg);
    border: 1px solid var(--border); border-radius: 10px; margin-bottom: 8px; cursor: grab; list-style: none;
}
.sortable-item.dragging { opacity: 0.4; }
.drag-handle { color: var(--text-muted); font-size: 14px; cursor: grab; }
.ql-icon { font-size: 18px; }
.ql-label { font-weight: 600; color: var(--text); min-width: 140px; }
.ql-url { color: var(--text-muted); font-size: 12px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.emoji-picker { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.emoji-picker button {
    border: 1px solid var(--border); background: var(--surface); border-radius: 6px;
    padding: 4px 8px; font-size: 16px; cursor: pointer;
}
.emoji-picker button:hover { border-color: var(--primary); }