/* ============================================================
   admin_layout.css – Admin shell: sidebar, topbar, flash
   Colour scheme: dark purple (#1a1060), blue (#2563eb), white
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --purple-deep:   #1a1060;
    --purple-dark:   #140d4f;
    --purple-mid:    #2d1a8c;
    --purple-light:  #ede9ff;
    --purple-faint:  #f5f3ff;
    --blue:          #2563eb;
    --blue-light:    #dbeafe;
    --white:         #ffffff;
    --gray-50:       #f8f9fb;
    --gray-100:      #f0f2f8;
    --gray-200:      #e2e8f0;
    --gray-300:      #cbd5e1;
    --gray-500:      #64748b;
    --gray-700:      #374151;
    --gray-900:      #111827;
    --success:       #16a34a;
    --success-bg:    #f0fdf4;
    --success-border:#bbf7d0;
    --error:         #dc2626;
    --error-bg:      #fef2f2;
    --error-border:  #fecaca;
    --warn:          #d97706;
    --warn-bg:       #fffbeb;
    --warn-border:   #fde68a;
    --sidebar-w:     248px;
    --topbar-h:      60px;
    --radius-sm:     6px;
    --radius-md:     10px;
    --radius-lg:     14px;
    --transition:    0.18s ease;
    --shadow-sm:     0 1px 3px rgba(0,0,0,0.08);
    --shadow-md:     0 4px 16px rgba(26,16,96,0.10);
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
                 'Helvetica Neue', Arial, sans-serif;
    font-size: 15px;
    color: var(--gray-900);
    background: var(--gray-100);
    -webkit-font-smoothing: antialiased;
}

/* ── Shell ─────────────────────────────────────────────────── */
.admin-shell {
    display: flex;
    height: 100vh;
    min-height: 0;
    overflow: hidden;
}

/* ── Sidebar ───────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: var(--purple-deep);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    transition: transform var(--transition);
    z-index: 100;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 18px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    flex-shrink: 0;
}

.sidebar-logo {
    width: 36px;
    height: 36px;
    background: rgba(255,255,255,0.12);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 800;
    color: #a78bfa;
    letter-spacing: 1px;
    flex-shrink: 0;
}

.sidebar-brand-name {
    font-size: 13px;
    font-weight: 600;
    color: rgba(255,255,255,0.85);
}

/* Nav */
.sidebar-nav {
    flex: 1;
    padding: 12px 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    color: rgba(255,255,255,0.62);
    text-decoration: none;
    transition: background var(--transition), color var(--transition);
    white-space: nowrap;
}

.nav-item:hover {
    background: rgba(255,255,255,0.08);
    color: rgba(255,255,255,0.90);
}

.nav-item.active {
    background: rgba(255,255,255,0.14);
    color: #ffffff;
}

.nav-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    stroke-width: 2;
}

/* Sidebar footer */
.sidebar-footer {
    padding: 12px 8px;
    border-top: 1px solid rgba(255,255,255,0.08);
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.sidebar-avatar {
    width: 32px;
    height: 32px;
    background: var(--purple-mid);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    color: #ffffff;
    flex-shrink: 0;
}

.sidebar-user-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.sidebar-user-name {
    font-size: 12px;
    font-weight: 600;
    color: rgba(255,255,255,0.85);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-role {
    font-size: 11px;
    color: rgba(255,255,255,0.45);
}

.sidebar-logout {
    display: flex;
    align-items: center;
    color: rgba(255,255,255,0.45);
    padding: 6px;
    border-radius: 6px;
    text-decoration: none;
    transition: background var(--transition), color var(--transition);
    flex-shrink: 0;
}

.sidebar-logout:hover {
    background: rgba(220,38,38,0.18);
    color: #fca5a5;
}

/* ── Main area ─────────────────────────────────────────────── */
.admin-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
    min-height: 0;
}

/* Topbar */
.admin-topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    height: var(--topbar-h);
    background: var(--white);
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 16px;
    flex-shrink: 0;
}

.topbar-hamburger {
    display: none;
    flex-direction: column;
    gap: 5px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
}

.topbar-hamburger span {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--gray-700);
    border-radius: 2px;
    transition: var(--transition);
}

.topbar-center {
    flex: 1;
    display: flex;
    align-items: center;
}

.topbar-term-badge {
    font-size: 12px;
    font-weight: 600;
    padding: 4px 12px;
    border-radius: 20px;
    background: var(--purple-light);
    color: var(--purple-mid);
}

.topbar-term-badge--warn {
    background: var(--warn-bg);
    color: var(--warn);
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.topbar-logout-btn {
    font-size: 13px;
    color: var(--gray-500);
    text-decoration: none;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--gray-200);
    transition: var(--transition);
}

.topbar-logout-btn:hover {
    background: var(--error-bg);
    color: var(--error);
    border-color: var(--error-border);
}

/* ── Flash messages ───────────────────────────────────────── */
.flash-container {
    padding: 0 24px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
}

.flash-container:empty {
    display: none;
}

.flash {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    font-size: 13px;
    margin-top: 16px;
    animation: flashIn 0.25s ease;
}

@keyframes flashIn {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.flash--success {
    background: var(--success-bg);
    border: 1px solid var(--success-border);
    color: var(--success);
}

.flash--error {
    background: var(--error-bg);
    border: 1px solid var(--error-border);
    color: var(--error);
}

.flash-icon { font-size: 14px; flex-shrink: 0; }

.flash-close {
    margin-left: auto;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 18px;
    color: inherit;
    opacity: 0.6;
    line-height: 1;
    padding: 0 2px;
    flex-shrink: 0;
}

.flash-close:hover { opacity: 1; }

/* ── Content area ──────────────────────────────────────────── */
.admin-content {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 24px;
}

.site-footer {
    position: sticky;
    bottom: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    background: #ffffff;
    border-top: 1px solid var(--gray-200);
    padding: 14px 24px;
    font-size: 12px;
    color: var(--gray-500);
    box-shadow: 0 -4px 12px rgba(15, 23, 42, 0.04);
}

.site-footer__brand {
    font-weight: 500;
}

.site-footer__brand strong {
    color: var(--purple-deep);
}

.site-footer__meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
}

.site-footer a,
.auth-footer a {
    color: var(--gray-700);
    text-decoration: none;
}

.site-footer a:hover,
.auth-footer a:hover {
    color: var(--purple-deep);
    text-decoration: underline;
}

.site-footer__divider {
    color: var(--gray-300);
}

/* ── Page header ───────────────────────────────────────────── */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.page-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--purple-deep);
    margin-bottom: 4px;
}

.page-subtitle {
    font-size: 13px;
    color: var(--gray-500);
    line-height: 1.5;
    max-width: 560px;
}

/* ── Common buttons ────────────────────────────────────────── */
.btn-primary {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 18px;
    background: var(--purple-deep);
    color: var(--white);
    border: none;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background var(--transition);
    white-space: nowrap;
}

.btn-primary:hover { background: var(--purple-mid); }

.btn-secondary {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 16px;
    background: var(--white);
    color: var(--gray-700);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: background var(--transition), border-color var(--transition);
    white-space: nowrap;
}

.btn-secondary:hover { background: var(--gray-50); border-color: var(--gray-300); }

.btn-danger {
    display: inline-flex;
    align-items: center;
    padding: 9px 16px;
    background: var(--white);
    color: var(--error);
    border: 1px solid var(--error-border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: background var(--transition);
    white-space: nowrap;
}

.btn-danger:hover { background: var(--error-bg); }

.btn-success {
    display: inline-flex;
    align-items: center;
    padding: 9px 16px;
    background: var(--white);
    color: var(--success);
    border: 1px solid var(--success-border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: background var(--transition);
    white-space: nowrap;
}

.btn-success:hover { background: var(--success-bg); }

.btn-sm  { padding: 6px 12px; font-size: 12px; }
.btn-xs  { padding: 4px 10px; font-size: 11px; border-radius: 5px; }
.btn-link {
    font-size: 13px;
    color: var(--blue);
    text-decoration: none;
    font-weight: 500;
}
.btn-link:hover { text-decoration: underline; }

/* ── Badges ────────────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
}

.badge--green  { background: #dcfce7; color: #166534; }
.badge--amber  { background: #fef3c7; color: #92400e; }
.badge--gray   { background: var(--gray-100); color: var(--gray-500); }
.badge--purple { background: var(--purple-light); color: var(--purple-mid); }
.badge--blue   { background: var(--blue-light); color: #1d4ed8; }
.badge--red    { background: var(--error-bg); color: var(--error); }
.badge--sm     { font-size: 10px; padding: 2px 7px; }

/* ── Tables ────────────────────────────────────────────────── */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.data-table th {
    background: var(--gray-50);
    padding: 10px 14px;
    text-align: left;
    font-size: 11px;
    font-weight: 700;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    border-bottom: 1px solid var(--gray-200);
    white-space: nowrap;
}

.data-table td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--gray-100);
    color: var(--gray-700);
    vertical-align: middle;
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--gray-50); }

.td-bold { font-weight: 600; color: var(--gray-900); }
.text-muted { color: var(--gray-500); font-style: italic; font-size: 12px; }

.action-btns {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.teacher-action-stack {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    flex-wrap: wrap;
}

.teacher-quick-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.action-menu {
    position: relative;
}

.action-menu-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.action-menu-caret {
    font-size: 10px;
    line-height: 1;
}

.action-menu-panel {
    position: fixed; /* escapes table-wrap's overflow clipping entirely */
    min-width: 170px;
    display: none;
    flex-direction: column;
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-md);
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.12);
    z-index: 300;
    overflow: hidden;
}

.action-menu.open .action-menu-panel {
    display: flex;
}

.action-menu-item,
.action-menu-form button.action-menu-item {
    width: 100%;
    border: 0;
    background: var(--white);
    color: var(--gray-700);
    text-align: left;
    padding: 10px 12px;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.35;
    cursor: pointer;
    text-decoration: none;
    transition: background var(--transition), color var(--transition);
}

.action-menu-item:hover,
.action-menu-form button.action-menu-item:hover {
    background: var(--gray-50);
    color: var(--gray-900);
}

.action-menu-item--danger {
    color: var(--error);
}

.action-menu-item--danger:hover {
    background: rgba(220, 38, 38, 0.06);
    color: var(--error);
}

.action-menu-form {
    margin: 0;
}

/* ── Cards ─────────────────────────────────────────────────── */
.section-card {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    overflow: hidden;
    margin-bottom: 24px;
}

.section-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--gray-100);
}

.section-card-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--purple-deep);
}

/* ── Info banner ───────────────────────────────────────────── */
.info-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--blue-light);
    border: 1px solid #bfdbfe;
    border-radius: var(--radius-md);
    padding: 12px 16px;
    font-size: 13px;
    color: #1e40af;
    margin-bottom: 20px;
}

.info-banner--warn {
    background: var(--warn-bg);
    border-color: var(--warn-border);
    color: #92400e;
}

.info-banner-link {
    color: inherit;
    font-weight: 600;
    text-decoration: underline;
}

/* ── Form elements ─────────────────────────────────────────── */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 18px;
}

.form-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--gray-700);
}

.form-input {
    width: 100%;
    height: 42px;
    padding: 0 12px;
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius-sm);
    font-size: 14px;
    color: var(--gray-900);
    background: var(--white);
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition);
    font-family: inherit;
}

.form-input:focus {
    border-color: var(--purple-mid);
    box-shadow: 0 0 0 3px rgba(45,26,140,0.10);
}

select.form-input { cursor: pointer; }

.form-hint {
    font-size: 12px;
    color: var(--gray-500);
    line-height: 1.5;
}

.form-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 8px;
}

.form-card {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    padding: 28px;
    max-width: 520px;
}

/* ── Modal ─────────────────────────────────────────────────── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 200;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal-overlay.open {
    display: flex;
}

.modal {
    background: var(--white);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-md);
    animation: modalIn 0.2s ease;
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.96) translateY(-10px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 22px;
    border-bottom: 1px solid var(--gray-100);
}

.modal-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--purple-deep);
}

.modal-close {
    background: none;
    border: none;
    font-size: 22px;
    color: var(--gray-500);
    cursor: pointer;
    line-height: 1;
    padding: 0 4px;
}

.modal-close:hover { color: var(--gray-900); }

.modal-body {
    padding: 22px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px 22px;
    border-top: 1px solid var(--gray-100);
}

/* ── Empty state ───────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 60px 24px;
    color: var(--gray-500);
}

.empty-state svg {
    stroke: var(--gray-300);
    margin-bottom: 16px;
}

.empty-state p {
    font-size: 14px;
    line-height: 1.6;
}

.empty-state a {
    color: var(--blue);
    font-weight: 600;
    text-decoration: none;
}

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 900px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100%;
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0,0,0,0.18);
    }

    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.4);
        z-index: 99;
    }

    .sidebar-overlay.open {
        display: block;
    }

    .topbar-hamburger {
        display: flex;
    }

    .admin-content {
        padding: 16px;
    }
}

@media (max-width: 480px) {
    .page-header {
        flex-direction: column;
        align-items: stretch;
    }

    .btn-primary, .btn-secondary {
        justify-content: center;
    }
}