/* Styles for new/templ/component/sidebar.templ (templ Sidebar) */
.sidebar {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    width: 300px;
    left: -320px;
    background: var(--bg-white, #fff);
    box-sizing: border-box;
    overflow: hidden;
    border-right: 1px solid rgba(15, 23, 42, 0.06);
    box-shadow: 0 24px 64px rgba(15, 23, 42, 0.12);
}
.sidebar.show {
    left: 0;
}
.sidebar.right {
    left: auto;
    right: -320px;
}
.sidebar.right.show {
    left: auto;
    right: 0;
}
.sidebar *, .sidebar *:before, .sidebar *:after {
    box-sizing: inherit;
}

/* ---------- Scrim ---------- */
/* custom.js appends .sidebar-scrim to <body> on pages with this sidebar.
   Visibility follows the sidebar itself via :has(), so every code path that
   adds/removes .show on .sidebar (menu toggler, notifications modal, inline
   sidebar scripts) drives the scrim for free. opacity + pointer-events
   instead of display:none so the fade animates in both directions and the
   page stays interactive while the sidebar is closed. */
.sidebar-scrim {
    position: fixed;
    inset: 0;
    z-index: 999998; /* directly under .sidebar (999999 in main.css) */
    background: rgba(15, 23, 42, 0.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}
body:has(.sidebar.show) .sidebar-scrim {
    opacity: 1;
    pointer-events: auto;
}

/* ---------- Header ---------- */

.sidebar-header {
    flex-shrink: 0;
    padding: 1.25rem 1.25rem 0.75rem;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    padding: 0.25rem 0.25rem 0.75rem;
}

.sidebar-brand-full {
    height: 40px;
    width: auto;
    max-width: 100%;
    object-fit: contain;
}

.sidebar-brand-mark {
    display: none;
    height: 36px;
    width: auto;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.25rem 0.25rem;
}

.sidebar-user-avatar {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    object-fit: cover;
    flex-shrink: 0;
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.12);
}

.sidebar-user-initials {
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary, #2f7deb) 0%, #8b5cf6 100%);
    color: #fff;
    font-weight: 800;
    font-size: 0.95rem;
    letter-spacing: 0.02em;
}

.sidebar-user-text {
    display: flex;
    flex-direction: column;
    gap: 0.05rem;
    min-width: 0;
}

.welcome-text {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--cd-muted, #64748b);
}

.sidebar-user .name {
    margin: 0;
    font-weight: 800;
    color: var(--cd-ink, #1e293b);
    font-size: 1.05rem;
    line-height: 1.25;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---------- Scrollable middle ---------- */

.sidebar-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0.25rem 1rem 1rem;
    scrollbar-width: thin;
    scrollbar-color: rgba(100, 116, 139, 0.3) transparent;
}

.sidebar-content::-webkit-scrollbar {
    width: 5px;
}

.sidebar-content::-webkit-scrollbar-thumb {
    background: rgba(100, 116, 139, 0.3);
    border-radius: 99px;
}

/* ---------- Tutor mode banner ---------- */

.sidebar .tutor-banner {
    position: relative;
    margin: 0.5rem 0.25rem 0.25rem;
    padding: 1rem;
    border-radius: 1.1rem;
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 55%, #9333ea 100%);
    color: #fff;
    overflow: hidden;
    box-shadow: 0 12px 28px rgba(79, 70, 229, 0.35);
}

.sidebar .tutor-banner::before {
    content: "";
    position: absolute;
    top: -40px;
    right: -40px;
    width: 140px;
    height: 140px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.12);
    pointer-events: none;
}

.sidebar .tutor-banner::after {
    content: "";
    position: absolute;
    bottom: -50px;
    left: -30px;
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.07);
    pointer-events: none;
}

.tutor-banner-main {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    position: relative;
    z-index: 1;
    color: #fff;
    text-decoration: none;
}

.tutor-banner-main:hover,
.tutor-banner-main:focus {
    color: #fff;
}

.tutor-banner-arrow {
    margin-left: auto;
    font-size: 0.8rem;
    opacity: 0.85;
    transition: transform 0.15s ease, opacity 0.15s ease;
}

.tutor-banner-main:hover .tutor-banner-arrow {
    transform: translateX(3px);
    opacity: 1;
}

.tutor-banner-icon {
    width: 38px;
    height: 38px;
    border-radius: 11px;
    background: rgba(255, 255, 255, 0.18);
    border: 1px solid rgba(255, 255, 255, 0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.tutor-banner-icon i {
    font-size: 1rem;
    color: #fff;
}

.tutor-banner-titles {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.tutor-banner-title {
    font-weight: 800;
    font-size: 0.95rem;
    line-height: 1.2;
}

.tutor-banner-sub {
    font-size: 0.7rem;
    font-weight: 600;
    opacity: 0.85;
    line-height: 1.3;
}

.tutor-banner-links {
    position: relative;
    z-index: 1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.4rem;
    margin-top: 0.6rem;
}

.tutor-banner-links a {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.45rem 0.6rem;
    border-radius: 0.65rem;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.14);
    color: #fff;
    font-weight: 700;
    font-size: 0.72rem;
    text-decoration: none;
    transition: background 0.15s ease, border-color 0.15s ease;
    overflow: hidden;
    white-space: nowrap;
}

.tutor-banner-links a:hover {
    background: rgba(255, 255, 255, 0.24);
    border-color: rgba(255, 255, 255, 0.35);
    color: #fff;
}

.tutor-banner-links a i {
    font-size: 0.7rem;
    flex-shrink: 0;
    opacity: 0.9;
}

/* ---------- Nav ---------- */

.sidebar .navbar-nav {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    flex: 1 0 auto;
}

.sidebar .nav-sep {
    margin: 0.55rem 0.75rem;
    border-top: 1px solid rgba(15, 23, 42, 0.06);
}

/* The final separator (before logout / login) pushes its group to the
   bottom of the drawer so the space between nav and footer reads as
   intentional rather than a void. */
.sidebar .nav-sep-bottom {
    margin-top: auto;
}

.sidebar .navbar-nav li > a.nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.55rem 0.75rem;
    border-radius: 0.85rem;
    color: var(--cd-ink, #1e293b);
    font-weight: 600;
    font-size: 0.9rem;
    transition: background 0.15s ease, color 0.15s ease;
    text-decoration: none;
    position: relative;
}

.sidebar .navbar-nav li > a.nav-link:hover {
    background-color: rgba(47, 125, 235, 0.06);
    color: var(--primary, #2f7deb);
}

/* Chevron that fades in on hover (replaces main.css's default arrow). */
.sidebar .navbar-nav li > a:after {
    content: "\f105";
    font-family: "Font Awesome 6 Pro", "Font Awesome 6 Free";
    font-weight: 900;
    font-size: 11px;
    position: absolute;
    right: 0.85rem;
    top: 50%;
    transform: translateY(-50%) translateX(-4px);
    color: var(--primary, #2f7deb);
    opacity: 0;
    transition: opacity 0.15s ease, transform 0.15s ease;
}

.sidebar .navbar-nav li > a:hover:after {
    opacity: 0.8;
    transform: translateY(-50%) translateX(0);
}

.sidebar .navbar-nav li > a.nav-link-switch:after {
    display: none;
}

/* Ghost icons: no tile, just a quietly coloured glyph. */
.sidebar .dz-icon {
    width: 26px;
    height: 26px;
    margin-right: 0; /* main.css .dz-icon adds 12px that would stack with the flex gap */
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    flex-shrink: 0;
    border: none;
    box-shadow: none;
    background: transparent !important;
    position: relative;
    z-index: 1;
}

.sidebar .dz-icon i {
    font-size: 15px;
    color: var(--cd-muted, #64748b) !important;
    transition: color 0.15s ease;
}

.sidebar .nav-link:hover .dz-icon i {
    color: var(--primary, #2f7deb) !important;
}

/* Destructive rows (logout, cancel) warm up red on hover instead. */
.sidebar .nav-link:hover .dz-icon.bg-red i {
    color: #ef4444 !important;
}

.sidebar .navbar-nav li > a.nav-link:has(.dz-icon.bg-red):hover {
    background-color: rgba(239, 68, 68, 0.08);
    color: #dc2626;
}

.sidebar .navbar-nav li > a.nav-link:has(.dz-icon.bg-red):after {
    color: #ef4444;
}

.experiment-switch {
    display: inline-flex;
    margin-left: auto;
    padding: 0;
}

.experiment-switch .form-check-input {
    margin: 0;
    cursor: pointer;
}

/* Guest-only theme toggle (signed-in users get it in the profile dropdown). */
.sidebar .sidebar-theme {
    margin-top: 0.35rem;
}

.sidebar .sidebar-theme .tt-theme-row {
    padding: 6px 0.75rem;
}

/* ---------- Footer ---------- */

.sidebar-footer {
    flex-shrink: 0;
    background: rgba(248, 250, 252, 0.75);
    border-top: 1px solid rgba(15, 23, 42, 0.06);
    padding: 0.9rem 1rem calc(0.9rem + env(safe-area-inset-bottom, 0px));
    text-align: left;
}

.footer-app {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    cursor: pointer;
    user-select: none;
    padding: 0.25rem;
    border-radius: 0.75rem;
}

.footer-app-mark {
    width: 30px;
    height: 30px;
    object-fit: contain;
    flex-shrink: 0;
}

.footer-app-text {
    display: flex;
    flex-direction: column;
    line-height: 1.25;
    min-width: 0;
}

.footer-app-name {
    font-weight: 800;
    font-size: 0.85rem;
    color: var(--cd-ink, #1e293b);
}

.footer-copyright {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--cd-muted, #94a3b8);
}

.footer-version-badge {
    margin-left: auto;
    flex-shrink: 0;
    font-size: 0.62rem;
    font-weight: 800;
    letter-spacing: 0.03em;
    color: var(--primary, #2f7deb);
    background: rgba(47, 125, 235, 0.08);
    border: 1px solid rgba(47, 125, 235, 0.15);
    border-radius: 99px;
    padding: 0.2rem 0.55rem;
}

.footer-contact {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.4rem;
    margin-top: 0.6rem;
}

.footer-chip {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.45rem 0.5rem;
    border-radius: 0.65rem;
    background: #fff;
    border: 1px solid rgba(15, 23, 42, 0.08);
    color: var(--cd-muted, #64748b);
    font-size: 0.68rem;
    font-weight: 700;
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    transition: color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.footer-chip:hover {
    color: var(--primary, #2f7deb);
    border-color: rgba(47, 125, 235, 0.35);
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.06);
}

.footer-chip i {
    font-size: 0.7rem;
    flex-shrink: 0;
}

.footer-legal {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-top: 0.6rem;
    font-size: 0.64rem;
    font-weight: 600;
    color: var(--cd-muted, #94a3b8);
}

.footer-legal a {
    color: var(--cd-muted, #94a3b8);
    text-decoration: none;
    transition: color 0.15s ease;
}

.footer-legal a:hover {
    color: var(--primary, #2f7deb);
}

.footer-legal span {
    opacity: 0.5;
}

#deviceInfo {
    display: block;
    margin-top: 0.5rem;
    font-size: 0.6rem;
    color: var(--cd-muted, #94a3b8);
    opacity: 0.7;
    text-align: center;
}

#deviceInfo:empty {
    display: none;
}

/* ---------- Dark mode (theme.css stamps html[data-theme="dark"]) ---------- */

html[data-theme="dark"] .sidebar {
    background: var(--tt-surface, #111a2e);
    border-right-color: var(--tt-line, #263450);
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55);
}

html[data-theme="dark"] .sidebar-user-avatar {
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
}

html[data-theme="dark"] .sidebar .navbar-nav li > a.nav-link:hover {
    background-color: rgba(124, 128, 242, 0.12);
    color: var(--cd-accent, #7c80f2);
}

html[data-theme="dark"] .sidebar .nav-sep {
    border-top-color: var(--tt-line, #263450);
}

html[data-theme="dark"] .sidebar .dz-icon i {
    color: var(--tt-muted, #94a3b8) !important;
}

html[data-theme="dark"] .sidebar .nav-link:hover .dz-icon i {
    color: var(--cd-accent, #7c80f2) !important;
}

html[data-theme="dark"] .sidebar .nav-link:hover .dz-icon.bg-red i {
    color: #fca5a5 !important;
}

html[data-theme="dark"] .sidebar .navbar-nav li > a.nav-link:has(.dz-icon.bg-red):hover {
    background-color: rgba(239, 68, 68, 0.14);
    color: #fca5a5;
}

html[data-theme="dark"] .sidebar .navbar-nav li > a.nav-link:has(.dz-icon.bg-red):after {
    color: #fca5a5;
}

html[data-theme="dark"] .sidebar-footer {
    background: var(--tt-surface-2, #17233b);
    border-top-color: var(--tt-line, #263450);
}

html[data-theme="dark"] .footer-version-badge {
    color: #93c5fd;
    background: rgba(96, 165, 250, 0.14);
    border-color: rgba(96, 165, 250, 0.25);
}

html[data-theme="dark"] .footer-chip {
    background: var(--tt-surface-3, #1e2c48);
    border-color: var(--tt-line, #263450);
    color: var(--tt-muted, #94a3b8);
}

html[data-theme="dark"] .footer-chip:hover {
    color: #93c5fd;
    border-color: rgba(96, 165, 250, 0.35);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

html[data-theme="dark"] .footer-legal a:hover {
    color: #93c5fd;
}

/* ---------- Mobile ---------- */

@media (max-width: 576px) {
    .sidebar {
        width: 290px;
    }

    .sidebar-brand-full {
        display: none;
    }

    .sidebar-brand-mark {
        display: block;
    }
}
