/*
 * Collapsible admin-style sidebar shell for authenticated pages (RTL).
 * Self-contained (no Tailwind dependency) so it doesn't rely on utility classes that may be
 * absent from the precompiled site.css build. Loaded after site.css + fonts.css.
 */

:root {
    --topbar-h: 3.5rem;
    --sidebar-w: 15.5rem;
    --sidebar-collapsed-w: 4.25rem;
    --sidebar-bg: #ffffff;
    --sidebar-border: #e2e8f0;
}

/* ---------- Top bar ---------- */
.app-topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    height: var(--topbar-h);
    padding: 0 1rem;
    background: #ffffff;
    border-bottom: 1px solid var(--sidebar-border);
}

.topbar-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 0.5rem;
    border: 1px solid var(--sidebar-border);
    background: #ffffff;
    color: #475569;
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.topbar-toggle:hover {
    background: #f1f5f9;
}

.topbar-toggle svg {
    width: 1.25rem;
    height: 1.25rem;
}

/* Theme toggle button shows the icon for the theme a click would switch TO: moon (go dark) in
   light mode, sun (go light) in dark mode. */
.topbar-toggle .icon-sun {
    display: none;
}

.dark .topbar-toggle .icon-sun {
    display: block;
}

.dark .topbar-toggle .icon-moon {
    display: none;
}

/* ---------- Sidebar ---------- */
.app-sidebar {
    position: fixed;
    top: var(--topbar-h);
    right: 0;
    bottom: 0;
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    border-left: 1px solid var(--sidebar-border);
    overflow-x: hidden;
    overflow-y: auto;
    z-index: 40;
    transition: width 0.2s ease, transform 0.2s ease;
    padding-bottom: 1.5rem;
}

.sidebar-section-title {
    padding: 1rem 1.25rem 0.35rem;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: #94a3b8;
    white-space: nowrap;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: 0.15rem 0.6rem;
    padding: 0.6rem 0.75rem;
    border-radius: 0.6rem;
    color: #475569;
    font-size: 0.9rem;
    font-weight: 500;
    text-decoration: none;
    white-space: nowrap;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.nav-item:hover {
    background: #f1f5f9;
    color: #0f172a;
}

.nav-item.active {
    background: #0d9488;
    color: #ffffff;
}

.nav-item.nav-admin {
    color: #b45309;
}

.nav-item.nav-admin:hover {
    background: #fffbeb;
    color: #92400e;
}

.nav-item.nav-admin.active {
    background: #d97706;
    color: #ffffff;
}

.nav-icon {
    flex-shrink: 0;
    width: 1.4rem;
    font-size: 1.05rem;
    line-height: 1;
    text-align: center;
}

.nav-label {
    flex: 1 1 auto;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ---------- Main content ---------- */
.app-main {
    padding: 1.5rem 1rem;
    transition: margin-right 0.2s ease;
}

.app-main.with-sidebar {
    margin-right: var(--sidebar-w);
}

.app-main-inner {
    max-width: 72rem;
    margin: 0 auto;
}

/* ---------- Collapsed (desktop icon rail) ---------- */
body.sidebar-collapsed .app-sidebar {
    width: var(--sidebar-collapsed-w);
}

body.sidebar-collapsed .app-main.with-sidebar {
    margin-right: var(--sidebar-collapsed-w);
}

body.sidebar-collapsed .nav-label,
body.sidebar-collapsed .sidebar-section-title {
    display: none;
}

body.sidebar-collapsed .nav-item {
    justify-content: center;
    padding-inline: 0;
}

/* Divider replaces the hidden section titles when collapsed */
body.sidebar-collapsed .sidebar-section + .sidebar-section {
    border-top: 1px solid var(--sidebar-border);
    margin-top: 0.5rem;
    padding-top: 0.5rem;
}

/* ---------- Overlay (mobile) ---------- */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    z-index: 39;
}

/* ---------- Mobile: off-canvas drawer ---------- */
@media (max-width: 767px) {
    .app-sidebar {
        transform: translateX(100%);
        width: var(--sidebar-w);
    }

    body.sidebar-open .app-sidebar {
        transform: translateX(0);
        box-shadow: -8px 0 24px rgba(15, 23, 42, 0.12);
    }

    /* Never reserve space for the drawer on mobile, collapsed or not. */
    .app-main.with-sidebar,
    body.sidebar-collapsed .app-main.with-sidebar {
        margin-right: 0;
    }

    /* On mobile the drawer always shows full labels. */
    body.sidebar-collapsed .nav-label,
    body.sidebar-collapsed .sidebar-section-title {
        display: initial;
    }

    body.sidebar-collapsed .nav-item {
        justify-content: flex-start;
        padding-inline: 0.75rem;
    }

    body.sidebar-open .sidebar-overlay {
        display: block;
    }
}

/* ---------- Dark theme ----------
   This file is plain CSS (not Tailwind), so unlike Styles/app.css's token swap, these colors
   need their own explicit dark values. */
:root.dark {
    --sidebar-bg: #0f172a;
    --sidebar-border: #1e293b;
}

.dark .app-topbar,
.dark .topbar-toggle,
.dark .app-sidebar {
    background: var(--sidebar-bg);
}

.dark .topbar-toggle {
    color: #cbd5e1;
}

.dark .topbar-toggle:hover {
    background: #1e293b;
}

.dark .sidebar-section-title {
    color: #64748b;
}

.dark .nav-item {
    color: #cbd5e1;
}

.dark .nav-item:hover {
    background: #1e293b;
    color: #f8fafc;
}

.dark .nav-item.nav-admin {
    color: #fbbf24;
}

.dark .nav-item.nav-admin:hover {
    background: #78350f;
    color: #fde68a;
}

/* .dark .nav-item / .dark .nav-item.nav-admin above tie the .active rules' specificity and
   come later in the file, so without this they'd silently win and wash out the active pill's
   white text. Re-assert white explicitly for the active state under dark theme. */
.dark .nav-item.active,
.dark .nav-item.nav-admin.active {
    color: #ffffff;
}

/* Emoji picker (see site.js). Lives here rather than as Tailwind utilities because the popup is
   built in JS — classes that only ever appear in a JS string aren't seen by the compiled/purged
   site.css build. Colors come from the theme's CSS variables so dark mode flips automatically. */
.emoji-toggle {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 38px;
    width: 38px;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    border: 1px solid var(--color-slate-300);
    border-radius: 0.375rem;
    background: transparent;
    color: var(--color-slate-600);
}

.emoji-toggle:hover {
    background: var(--color-slate-100);
}

.emoji-popup {
    position: fixed;
    z-index: 60;
    display: none;
    grid-template-columns: repeat(8, minmax(0, 1fr));
    gap: 2px;
    width: 320px;
    max-width: calc(100vw - 24px);
    max-height: 220px;
    overflow-y: auto;
    padding: 8px;
    border-radius: 0.75rem;
    background: var(--color-white);
    border: 1px solid var(--color-slate-200);
    box-shadow: 0 10px 25px -5px rgba(15, 23, 42, 0.25);
}

.dark .emoji-popup {
    background: oklch(25% 0.03 265.755);
}

.emoji-cell {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 34px;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    border: 0;
    background: transparent;
    border-radius: 0.375rem;
}

.emoji-cell:hover {
    background: var(--color-slate-100);
}
