/* ─────────────────────────────────────────────────────────────
   The panel shell: sidebar, top bar and the canvas between them.
   Portal-agnostic — a school, teacher, parent or super-admin page
   is the same frame with a different nav and a different switcher.
   ───────────────────────────────────────────────────────────── */

/* ── Sidebar ── */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    border-right: 1px solid #E4EAF6;
    display: flex;
    flex-direction: column;
    z-index: 100;
}

.sidebar-header {
    flex-shrink: 0;
    padding: 20px 20px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.logo {
    display: flex;
    align-items: center;
    min-width: 0;
    text-decoration: none;
    color: var(--text-primary);
}

.logo img {
    width: 100%;
    max-width: 190px;
    height: auto;
    display: block;
}

.logo-icon {
    font-size: 24px;
}

.logo-text {
    font-size: 16px;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.sidebar-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    display: flex;
    flex-direction: column;
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
}

.sidebar-scroll::-webkit-scrollbar {
    width: 5px;
}

.sidebar-scroll::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 3px;
}

/* ── The context card under the logo ──
   Names the school, the selected child or the batch a page is
   scoped to. One block, whatever the portal puts in it. */
.sidebar-context {
    flex-shrink: 0;
    padding: 0 14px 14px;
}

.context-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: #ffffff;
    border: 1px solid #DDE5F2;
    border-radius: var(--radius-sm);
    text-decoration: none;
}

.context-card-icon {
    width: 32px;
    height: 32px;
    border-radius: 9px;
    background: var(--primary-soft);
    color: var(--primary-solid);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
}

.context-card-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.context-card-text {
    min-width: 0;
}

.context-label {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    line-height: 1.3;
}

.context-name {
    font-size: 13.5px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Navigation ── */
.sidebar-nav {
    flex: none;
    padding: 4px 10px 14px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 13px;
    padding: 12px 16px;
    color: var(--nav-ink);
    text-decoration: none;
    border-radius: var(--radius-sm);
    margin-bottom: 4px;
    transition: background .18s ease, color .18s ease;
    font-weight: 600;
    font-size: 14.5px;
    letter-spacing: -0.01em;
}

.nav-item:hover {
    background: var(--sidebar-hover);
    color: var(--text-primary);
}

.nav-item.active {
    background: var(--primary-soft);
    color: var(--primary-ink);
}

.nav-item.active .nav-icon {
    color: var(--primary-ink);
}

.nav-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: #7183A0;
    transition: color .18s ease;
}

.nav-item:hover .nav-icon {
    color: var(--nav-ink);
}

.nav-section-label {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 16px 14px 6px;
}

.nav-group {
    margin-top: 2px;
}

.nav-group-toggle {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 12px 16px;
    margin-bottom: 4px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--nav-ink);
    font: inherit;
    font-size: 14.5px;
    font-weight: 600;
    letter-spacing: -0.01em;
    cursor: pointer;
    transition: background .18s ease, color .18s ease;
}

.nav-group-toggle:hover {
    background: var(--sidebar-hover);
    color: var(--text-primary);
}

.nav-group-label {
    flex: 1;
    text-align: left;
}

.nav-group-chevron {
    flex-shrink: 0;
    color: var(--text-muted);
    transition: transform .2s ease;
}

.nav-group.is-open .nav-group-chevron {
    transform: rotate(180deg);
}

.nav-group.is-current > .nav-group-toggle {
    background: var(--primary-soft);
    color: var(--primary-ink);
}

.nav-group.is-current > .nav-group-toggle .nav-icon {
    color: var(--primary-ink);
}

/* Every group starts collapsed. The one holding the current page wears the
   active tint on its toggle, so the sidebar still says where you are. */
.nav-group-items {
    display: none;
    padding-left: 14px;
    border-left: 1.5px solid #DEE6F3;
    margin: 2px 0 6px 24px;
}

.nav-group.is-open .nav-group-items {
    display: block;
}

.nav-group-items .nav-item {
    padding: 10px 14px;
    margin-bottom: 3px;
    font-size: 13.5px;
    font-weight: 500;
}

.nav-group-items .nav-item.active {
    font-weight: 600;
}

/* ── Main / top bar ── */
.main-content {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
}

.topbar {
    background: var(--bg-main);
    padding: 14px 28px;
    display: flex;
    align-items: center;
    gap: 14px;
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    margin-left: auto;
}

.topbar-search {
    position: relative;
    display: flex;
    align-items: center;
    width: 330px;
    max-width: 38vw;
    height: 44px;
    padding: 0 10px 0 14px;
    background: var(--field-bg);
    border: 1px solid var(--field-border);
    border-radius: var(--radius-sm);
    transition: border-color .18s ease, background .18s ease, box-shadow .18s ease;
}

.topbar-search:focus-within {
    border-color: var(--primary-light);
    box-shadow: 0 0 0 4px rgba(var(--primary-rgb), 0.12);
}

.topbar-search > svg {
    flex-shrink: 0;
    color: var(--text-muted);
}

.topbar-search input {
    flex: 1;
    min-width: 0;
    border: none;
    outline: none;
    background: transparent;
    font: inherit;
    font-size: 13.5px;
    font-weight: 500;
    color: var(--text-primary);
    padding: 0 10px;
}

.topbar-search input::placeholder {
    color: var(--text-muted);
    font-weight: 500;
}

.topbar-search input::-webkit-search-cancel-button {
    -webkit-appearance: none;
}

.search-kbd {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 4px 8px;
    border-radius: 7px;
    background: #fff;
    border: 1px solid var(--border-color);
    font-family: inherit;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    line-height: 1;
}

/* ── Scope switcher (school / child / batch) ── */
.space-switcher {
    position: relative;
}

.space-trigger {
    display: flex;
    align-items: center;
    gap: 10px;
    height: 44px;
    padding: 0 12px;
    background: #ffffff;
    border: 1px solid #DDE5F2;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font: inherit;
    text-align: left;
    transition: border-color .18s ease, box-shadow .18s ease;
}

.space-trigger:hover {
    border-color: var(--border-strong);
    box-shadow: var(--shadow-xs);
}

.space-trigger-icon {
    width: 30px;
    height: 30px;
    border-radius: 9px;
    background: var(--primary-soft);
    color: var(--primary-solid);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.space-trigger-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.space-name {
    font-weight: 700;
    font-size: 13.5px;
    color: var(--text-primary);
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 130px;
}

.space-label {
    font-size: 11.5px;
    color: var(--text-muted);
    font-weight: 500;
    line-height: 1.25;
}

.space-trigger-chevron {
    color: var(--text-muted);
    flex-shrink: 0;
}

.space-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 244px;
    max-height: 340px;
    overflow-y: auto;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    z-index: 200;
    padding: 6px;
}

.space-dropdown.show {
    display: block;
}

.space-dropdown-item {
    display: block;
    width: 100%;
    padding: 10px 12px;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 13.5px;
    font-weight: 600;
    border-radius: var(--radius-xs);
    transition: background .15s ease;
}

.space-dropdown-item:hover {
    background: var(--bg-subtle);
}

.space-dropdown-item.active {
    background: var(--primary-soft);
    color: var(--primary-ink);
}

/* ── Top bar user ── */
.topbar-user-wrapper {
    position: relative;
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    height: 44px;
    padding: 0 8px 0 6px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background .18s ease;
    text-decoration: none;
}

.topbar-user:hover {
    background: var(--sidebar-hover);
}

.topbar-user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 14px;
    flex-shrink: 0;
}

.topbar-user-info {
    text-align: left;
    min-width: 0;
}

.topbar-user-name {
    font-weight: 700;
    font-size: 13.5px;
    color: var(--text-primary);
    line-height: 1.25;
    white-space: nowrap;
}

.topbar-user-email {
    font-size: 11.5px;
    color: var(--text-muted);
    font-weight: 500;
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 140px;
}

.topbar-user-chevron {
    color: var(--text-muted);
    flex-shrink: 0;
}

.topbar-user-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    min-width: 224px;
    z-index: 100;
    overflow: hidden;
    padding: 6px;
}

.topbar-user-dropdown.show {
    display: block;
}

.topbar-user-dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 13.5px;
    font-weight: 600;
    border-radius: var(--radius-xs);
    transition: background .15s ease;
    border: none;
    background: none;
    width: 100%;
    cursor: pointer;
    font-family: inherit;
}

.topbar-user-dropdown-item:hover {
    background: var(--bg-subtle);
}

.topbar-user-dropdown-item.logout {
    color: var(--danger);
    margin-top: 6px;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
    border-radius: 0 0 var(--radius-xs) var(--radius-xs);
}

.topbar-user-dropdown-item svg {
    opacity: .65;
    flex-shrink: 0;
}

/* ── Page heading + canvas ── */
.content {
    padding: 26px 28px 40px;
}

.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 22px;
}

.page-head-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.page-title {
    font-size: 25px;
    font-weight: 800;
    letter-spacing: -0.03em;
    line-height: 1.2;
    color: var(--text-primary);
}

.page-subtitle {
    font-size: 13.5px;
    color: var(--text-secondary);
    font-weight: 500;
    margin-top: 3px;
}

.date-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: 40px;
    padding: 0 14px;
    border-radius: var(--radius-sm);
    background: #ffffff;
    border: 1px solid #DDE5F2;
    font-size: 13px;
    font-weight: 700;
    color: var(--text-secondary);
    white-space: nowrap;
}

.date-chip svg {
    color: var(--primary-solid);
    flex-shrink: 0;
}

/* ── Notifications ── */
.notif-bell-wrapper {
    position: relative;
}

.notif-bell {
    width: 42px;
    height: 42px;
    border-radius: var(--radius-sm);
    border: none;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #475467;
    transition: all 0.18s ease;
    position: relative;
}

.notif-bell:hover {
    background: var(--sidebar-hover);
    color: var(--primary-solid);
}

.notif-bell.has-unread {
    color: var(--primary-solid);
}

.notif-badge {
    position: absolute;
    top: 1px;
    right: 1px;
    min-width: 19px;
    height: 19px;
    padding: 0 5px;
    border-radius: 9.5px;
    background: var(--danger);
    color: white;
    font-size: 10.5px;
    font-weight: 800;
    display: none;
    align-items: center;
    justify-content: center;
    line-height: 1;
    border: 2px solid var(--bg-main);
}

.notif-badge.show {
    display: flex;
}

.notif-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 380px;
    max-height: 480px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    z-index: 200;
    overflow: hidden;
}

.notif-dropdown.show {
    display: flex;
    flex-direction: column;
}

.notif-dropdown-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}

.notif-dropdown-title {
    font-weight: 800;
    font-size: 15px;
    letter-spacing: -0.02em;
}

.notif-mark-all {
    font-size: 12.5px;
    color: var(--primary-solid);
    cursor: pointer;
    font-weight: 700;
    border: none;
    background: none;
    font-family: inherit;
    padding: 0;
}

.notif-mark-all:hover {
    text-decoration: underline;
}

.notif-list {
    flex: 1;
    overflow-y: auto;
    max-height: 380px;
}

.notif-item {
    display: flex;
    gap: 12px;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border-color);
    transition: background 0.15s;
    cursor: pointer;
    /* An item that leads somewhere is an anchor; one that does not is a div. */
    color: inherit;
    text-decoration: none;
}

.notif-item:hover {
    background: var(--bg-subtle);
}

.notif-item:last-child {
    border-bottom: none;
}

.notif-item.unread {
    background: var(--primary-soft);
}

.notif-item.unread::before {
    content: '';
    flex-shrink: 0;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary-solid);
    margin-top: 6px;
}

.notif-item:not(.unread)::before {
    content: '';
    flex-shrink: 0;
    width: 8px;
    height: 8px;
    margin-top: 6px;
}

.notif-item-content {
    flex: 1;
    min-width: 0;
}

.notif-item-title {
    font-weight: 700;
    font-size: 13px;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.notif-item-body {
    font-size: 12px;
    color: var(--text-secondary);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.notif-item-time {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
}

.notif-empty {
    padding: 40px 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
}

.notif-empty-icon {
    font-size: 32px;
    margin-bottom: 8px;
}

.notif-loading {
    padding: 30px 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

/* ── Mobile ── */
.mobile-menu-toggle {
    display: none;
    width: 40px;
    height: 40px;
    border: 1px solid #DDE5F2;
    background: #ffffff;
    border-radius: var(--radius-xs);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    color: var(--text-primary);
    transition: all 0.2s;
    flex-shrink: 0;
}

.mobile-menu-toggle:hover {
    background: var(--bg-subtle);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(20, 27, 52, 0.45);
    z-index: 99;
    opacity: 0;
    transition: opacity 0.3s;
}

.sidebar-overlay.show {
    display: block;
    opacity: 1;
}

@media (max-width: 1024px) {
    .space-trigger-text,
    .topbar-user-info { display: none; }
}

@media (max-width: 680px) {
    .topbar-search { display: none; }
}

@media (max-width: 768px) {
    .mobile-menu-toggle {
        display: flex;
    }

    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s;
        box-shadow: var(--shadow-lg);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
    }

    .content {
        padding: 16px;
    }

    .topbar {
        padding: 12px 16px;
        gap: 10px;
    }

    .page-title {
        font-size: 20px;
    }

    .page-head {
        margin-bottom: 16px;
    }

    .page-head-actions {
        width: 100%;
    }

    .topbar-actions {
        gap: 8px;
    }

    .notif-dropdown {
        width: calc(100vw - 32px);
        max-width: 380px;
        right: -56px;
    }

    .space-dropdown {
        right: -44px;
    }
}

@media (max-width: 520px) {
    .notif-bell { width: 40px; height: 40px; }
    .space-trigger { height: 40px; padding: 0 8px; }
    .topbar-user { height: 40px; }
}
