/* sidebar.css — app-shell sidebar + slim topbar + command palette
   Tokens reuse --premium-* and --lg-* declared in site.css/premium.css. */

:root {
    --sb-w: 264px;
    --sb-w-collapsed: 76px;
    --topbar-h: 64px;
    --sb-bg: linear-gradient(180deg, #ffffff 0%, #f6f8fd 100%);
    --sb-border: rgba(91, 61, 245, 0.08);
    --sb-shadow: 0 10px 30px -12px rgba(15, 23, 42, 0.12), 0 2px 6px rgba(15, 23, 42, 0.04);
    --sb-item-radius: 12px;
    --sb-active-bg: linear-gradient(135deg, rgba(91, 61, 245, 0.10) 0%, rgba(123, 95, 250, 0.10) 100%);
    --sb-active-color: var(--premium-primary, #5b3df5);
    --sb-hover-bg: rgba(91, 61, 245, 0.06);
    --sb-text: #1f2937;
    --sb-muted: #64748b;
    --sb-label: #94a3b8;
}

/* ---------- App shell grid ---------- */
.app-shell {
    display: grid;
    grid-template-columns: var(--sb-w) 1fr;
    grid-template-rows: var(--topbar-h) 1fr;
    grid-template-areas:
        "sidebar topbar"
        "sidebar main";
    min-height: 100vh;
    transition: grid-template-columns 0.25s ease;
}

.app-shell.is-collapsed {
    grid-template-columns: var(--sb-w-collapsed) 1fr;
}

.app-shell__topbar { grid-area: topbar; }
.app-shell__main   { grid-area: main; min-width: 0; }

/* ---------- Sidebar ---------- */
.app-sidebar {
    grid-area: sidebar;
    position: sticky;
    top: 0;
    align-self: start;
    height: 100vh;
    width: 100%;
    background: var(--sb-bg);
    border-right: 1px solid var(--sb-border);
    box-shadow: var(--sb-shadow);
    display: flex;
    flex-direction: column;
    z-index: 1040;
    overflow: hidden;
}

.app-sidebar__brand {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 1rem 1rem 0.9rem;
    border-bottom: 1px solid var(--sb-border);
    flex-shrink: 0;
    min-height: 96px;
}

.app-sidebar__brand-link {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    overflow: hidden;
}

.app-sidebar__brand-logo {
    max-width: 100%;
    max-height: 76px;
    width: auto;
    height: auto;
    object-fit: contain;
    transition: max-height 0.2s ease, max-width 0.2s ease;
}

.app-shell.is-collapsed .app-sidebar__brand-logo {
    max-height: 44px;
    max-width: 44px;
}

.app-shell.is-collapsed .app-sidebar__brand { min-height: 64px; padding: 0.6rem; }

.app-sidebar__collapse-btn {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--sb-muted);
    cursor: pointer;
    transition: all 0.18s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.app-sidebar__collapse-btn:hover {
    background: var(--sb-hover-bg);
    color: var(--sb-active-color);
}

.app-shell.is-collapsed .app-sidebar__collapse-btn i {
    transform: rotate(180deg);
}

.app-sidebar__scroll {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 0.75rem 0.6rem 1rem;
    scrollbar-width: thin;
    scrollbar-color: rgba(91, 61, 245, 0.2) transparent;
}

.app-sidebar__scroll::-webkit-scrollbar { width: 6px; }
.app-sidebar__scroll::-webkit-scrollbar-thumb {
    background: rgba(91, 61, 245, 0.2);
    border-radius: 6px;
}

.app-sidebar__group-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.85rem 0.85rem 0.35rem;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--sb-label);
}

.app-sidebar__group-label i {
    font-size: 0.7rem;
    opacity: 0.7;
}

.app-sidebar__list {
    list-style: none;
    padding: 0;
    margin: 0 0 0.4rem;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.app-sidebar__item {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 0.6rem 0.85rem;
    border-radius: var(--sb-item-radius);
    color: var(--sb-text);
    font-size: 0.92rem;
    font-weight: 500;
    text-decoration: none;
    position: relative;
    transition: background-color 0.18s ease, color 0.18s ease, transform 0.18s ease;
    overflow: hidden;
}

.app-sidebar__item > i {
    width: 20px;
    text-align: center;
    font-size: 0.95rem;
    color: var(--sb-muted);
    flex-shrink: 0;
    transition: color 0.18s ease;
}

.app-sidebar__item > span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.app-sidebar__item:hover {
    background: var(--sb-hover-bg);
    color: var(--sb-active-color);
    transform: translateX(2px);
}

.app-sidebar__item:hover > i {
    color: var(--sb-active-color);
}

.app-sidebar__item.is-active {
    background: var(--sb-active-bg);
    color: var(--sb-active-color);
    font-weight: 600;
}

.app-sidebar__item.is-active > i {
    color: var(--sb-active-color);
}

.app-sidebar__item.is-active::before {
    content: "";
    position: absolute;
    left: 0;
    top: 25%;
    bottom: 25%;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: linear-gradient(180deg, var(--premium-primary, #5b3df5) 0%, var(--premium-primary-light, #7b5ffa) 100%);
}

.app-sidebar__pin {
    margin-left: auto;
    border: none;
    background: transparent;
    color: var(--sb-label);
    width: 24px;
    height: 24px;
    border-radius: 6px;
    opacity: 0;
    transition: opacity 0.18s ease, color 0.18s ease, background 0.18s ease;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.78rem;
}

.app-sidebar__item:hover .app-sidebar__pin,
.app-sidebar__pin.is-pinned { opacity: 1; }

.app-sidebar__pin:hover {
    color: #f59e0b;
    background: rgba(245, 158, 11, 0.12);
}

.app-sidebar__pin.is-pinned {
    color: #f59e0b;
}

.app-sidebar__pin.is-pinned i::before { content: "\f005"; font-weight: 900; }

.app-sidebar__favorites {
    margin-bottom: 0.4rem;
    padding-bottom: 0.4rem;
    border-bottom: 1px dashed var(--sb-border);
}

.app-sidebar__footer {
    flex-shrink: 0;
    padding: 0.6rem 0.6rem 0.8rem;
    border-top: 1px solid var(--sb-border);
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(8px);
}

.app-sidebar__palette-cta {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    border: 1px solid var(--sb-border);
    background: #fff;
    border-radius: 10px;
    padding: 0.55rem 0.75rem;
    color: var(--sb-muted);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.18s ease;
}

.app-sidebar__palette-cta:hover {
    border-color: var(--sb-active-color);
    color: var(--sb-active-color);
    box-shadow: 0 4px 14px rgba(91, 61, 245, 0.12);
}

.app-sidebar__kbd {
    margin-left: auto;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.7rem;
    background: #f1f5f9;
    border: 1px solid var(--sb-border);
    border-radius: 6px;
    padding: 1px 6px;
    color: var(--sb-muted);
}

.app-sidebar__logout-form { margin-top: 0.5rem; }

.app-sidebar__logout-btn {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 0.65rem;
    border: 1px solid rgba(239, 68, 68, 0.18);
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.05), rgba(239, 68, 68, 0.1));
    color: #b91c1c;
    border-radius: 10px;
    padding: 0.55rem 0.85rem;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.18s ease;
}

.app-sidebar__logout-btn > i { width: 20px; text-align: center; }

.app-sidebar__logout-btn:hover {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: #fff;
    border-color: #dc2626;
    box-shadow: 0 6px 16px rgba(239, 68, 68, 0.32);
    transform: translateY(-1px);
}

/* ---------- Guest shell (no sidebar) ---------- */
.app-shell.is-guest {
    grid-template-columns: 1fr;
    grid-template-areas:
        "topbar"
        "main";
}

.app-shell.is-guest .app-sidebar,
.app-shell.is-guest .app-topbar__menu-btn { display: none; }

/* ---------- Collapsed state ---------- */
.app-shell.is-collapsed .app-sidebar__item > span,
.app-shell.is-collapsed .app-sidebar__group-label > span,
.app-shell.is-collapsed .app-sidebar__pin,
.app-shell.is-collapsed .app-sidebar__palette-cta > span,
.app-shell.is-collapsed .app-sidebar__kbd,
.app-shell.is-collapsed .app-sidebar__logout-btn > span {
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
}

.app-shell.is-collapsed .app-sidebar__logout-btn {
    justify-content: center;
    padding: 0.55rem 0;
}

.app-shell.is-collapsed .app-sidebar__item {
    justify-content: center;
    padding: 0.65rem 0;
}

.app-shell.is-collapsed .app-sidebar__group-label {
    justify-content: center;
    padding: 0.85rem 0 0.35rem;
}

.app-shell.is-collapsed .app-sidebar__item:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    left: calc(100% + 10px);
    top: 50%;
    transform: translateY(-50%);
    background: #1f2937;
    color: #fff;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.78rem;
    white-space: nowrap;
    z-index: 1050;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

/* ---------- Topbar ---------- */
.app-topbar {
    height: var(--topbar-h);
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: saturate(160%) blur(12px);
    border-bottom: 1px solid var(--sb-border);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0 1.25rem;
    position: sticky;
    top: 0;
    z-index: 1030;
}

.app-topbar__menu-btn {
    display: none;
    border: 1px solid var(--sb-border);
    background: #fff;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    color: var(--sb-text);
    cursor: pointer;
}

.app-topbar__search {
    flex: 1;
    max-width: 460px;
    position: relative;
}

.app-topbar__search-btn {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    border: 1px solid var(--sb-border);
    background: #f8fafc;
    border-radius: 10px;
    padding: 0.5rem 0.85rem;
    color: var(--sb-muted);
    font-size: 0.88rem;
    cursor: pointer;
    transition: all 0.18s ease;
}

.app-topbar__search-btn:hover {
    background: #fff;
    border-color: var(--sb-active-color);
    color: var(--sb-active-color);
    box-shadow: 0 4px 14px rgba(91, 61, 245, 0.10);
}

.app-topbar__search-btn .kbd-group {
    margin-left: auto;
    display: inline-flex;
    gap: 4px;
}

.app-topbar__search-btn kbd {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.7rem;
    background: #fff;
    border: 1px solid var(--sb-border);
    border-radius: 5px;
    padding: 1px 5px;
}

.app-topbar__spacer { flex: 1; }

.app-topbar__actions {
    display: flex;
    align-items: center;
    gap: 0.55rem;
}

.app-topbar__icon-btn {
    position: relative;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    border: 1px solid var(--sb-border);
    background: #fff;
    color: var(--sb-text);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.18s ease;
}

.app-topbar__icon-btn:hover {
    color: var(--sb-active-color);
    border-color: var(--sb-active-color);
    background: #fff;
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(91, 61, 245, 0.14);
}

.app-topbar__icon-btn .nav-count-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 18px;
    height: 18px;
    background: linear-gradient(135deg, #ef4444, #f97316);
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    border-radius: 9px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    box-shadow: 0 4px 10px rgba(239, 68, 68, 0.4);
}

/* ---------- Main content area ---------- */
.app-shell__main {
    padding: 1.25rem 1.5rem 2rem;
    background: #f6f8fd;
}

/* ---------- Mobile drawer ---------- */
.app-sidebar__backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 1039;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.app-sidebar__backdrop.is-visible {
    opacity: 1;
}

@media (max-width: 991.98px) {
    .app-shell {
        grid-template-columns: 1fr;
        grid-template-rows: var(--topbar-h) 1fr;
        grid-template-areas:
            "topbar"
            "main";
    }

    .app-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: var(--sb-w);
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        z-index: 1041;
    }

    .app-shell.is-drawer-open .app-sidebar {
        transform: translateX(0);
    }

    .app-topbar__menu-btn { display: inline-flex; align-items: center; justify-content: center; }
    .app-shell.is-collapsed { grid-template-columns: 1fr; }
}

/* ---------- Command palette ---------- */
.cmd-palette {
    position: fixed;
    inset: 0;
    z-index: 1080;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 12vh;
}

.cmd-palette[hidden] { display: none; }

.cmd-palette__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(4px);
}

.cmd-palette__panel {
    position: relative;
    width: min(640px, calc(100% - 2rem));
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 30px 80px -10px rgba(15, 23, 42, 0.45);
    overflow: hidden;
    animation: cmd-pop 0.18s ease-out;
    max-height: 70vh;
    display: flex;
    flex-direction: column;
}

@keyframes cmd-pop {
    from { opacity: 0; transform: translateY(-12px) scale(0.98); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.cmd-palette__head {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.9rem 1.1rem;
    border-bottom: 1px solid var(--sb-border);
}

.cmd-palette__icon {
    color: var(--sb-muted);
    font-size: 1rem;
}

.cmd-palette__input {
    flex: 1;
    border: none;
    outline: none;
    font-size: 1rem;
    background: transparent;
    color: var(--sb-text);
}

.cmd-palette__kbd {
    font-family: ui-monospace, monospace;
    font-size: 0.7rem;
    background: #f1f5f9;
    border: 1px solid var(--sb-border);
    border-radius: 6px;
    padding: 2px 7px;
    color: var(--sb-muted);
    cursor: pointer;
}

.cmd-palette__body {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.cmd-palette__hint {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    padding: 1.2rem 1rem 0.6rem;
    font-size: 0.82rem;
    color: var(--sb-muted);
}

.cmd-palette__hint kbd {
    font-family: ui-monospace, monospace;
    font-size: 0.7rem;
    background: #f1f5f9;
    border: 1px solid var(--sb-border);
    border-radius: 5px;
    padding: 1px 5px;
    margin-right: 4px;
}

.cmd-palette__section { padding: 0.4rem 0; }

.cmd-palette__section-head {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.45rem 0.85rem;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--sb-label);
}

.cmd-palette__clear {
    margin-left: auto;
    border: none;
    background: transparent;
    color: var(--sb-muted);
    font-size: 0.72rem;
    cursor: pointer;
    text-transform: none;
    letter-spacing: 0;
}

.cmd-palette__clear:hover { color: var(--sb-active-color); }

.cmd-palette__list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.cmd-palette__item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.55rem 0.85rem;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.15s ease;
    color: var(--sb-text);
    text-decoration: none;
}

.cmd-palette__item:hover,
.cmd-palette__item.is-focused {
    background: var(--sb-hover-bg);
    color: var(--sb-active-color);
}

.cmd-palette__item-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: var(--sb-active-bg);
    color: var(--sb-active-color);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.cmd-palette__item-body {
    flex: 1;
    min-width: 0;
}

.cmd-palette__item-title {
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--sb-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cmd-palette__item:hover .cmd-palette__item-title,
.cmd-palette__item.is-focused .cmd-palette__item-title { color: var(--sb-active-color); }

.cmd-palette__item-meta {
    font-size: 0.75rem;
    color: var(--sb-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cmd-palette__item-arrow {
    color: var(--sb-label);
    font-size: 0.75rem;
}

.cmd-palette__empty {
    padding: 2.2rem;
    text-align: center;
    color: var(--sb-muted);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    align-items: center;
}

.cmd-palette__empty i { font-size: 1.6rem; }

.cmd-palette__foot {
    display: flex;
    gap: 1rem;
    padding: 0.55rem 1rem;
    border-top: 1px solid var(--sb-border);
    background: #f8fafc;
    font-size: 0.72rem;
    color: var(--sb-muted);
}

.cmd-palette__foot kbd {
    font-family: ui-monospace, monospace;
    background: #fff;
    border: 1px solid var(--sb-border);
    border-radius: 4px;
    padding: 0 5px;
    margin-right: 4px;
}

.cmd-palette__foot-spacer { flex: 1; }

@media (max-width: 575.98px) {
    .cmd-palette { padding-top: 0; }
    .cmd-palette__panel { width: 100%; height: 100%; max-height: 100%; border-radius: 0; }
}
