/**
 * Admin app chrome: sidebar + topbar + workspace (bakery-dashboard, management, etc.)
 * Loaded from admin.css so all shell pages stay aligned.
 */

:root {
    --adm-bg: #f3f4f6;
    --adm-sidebar-bg: linear-gradient(180deg, #1f2937 0%, #111827 100%);
    --adm-sidebar-border: rgba(255, 255, 255, 0.06);
    --adm-sidebar-text: #e5e7eb;
    --adm-sidebar-muted: #9ca3af;
    --adm-accent: #9c1c34;
    --adm-accent-soft: rgba(156, 28, 52, 0.15);
    --adm-sidebar-w: 17.5rem;
}

body.admin-body {
    margin: 0;
    min-height: 100vh;
    background: var(--adm-bg);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: #111827;
}

/* Mobile drawer open — prevent scroll behind overlay (iOS + desktop narrow) */
html.admin-html--nav-open,
html.admin-html--nav-open body.admin-body {
    overflow: hidden;
    height: 100%;
}

@media (prefers-reduced-motion: reduce) {
    .admin-sidebar {
        transition: none !important;
    }
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.admin-app {
    display: flex;
    min-height: 100vh;
    width: 100%;
}

/* —— Sidebar —— */
.admin-sidebar {
    flex: 0 0 var(--adm-sidebar-w);
    width: var(--adm-sidebar-w);
    background: var(--adm-sidebar-bg);
    color: var(--adm-sidebar-text);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--adm-sidebar-border);
    transition: flex-basis 0.2s ease, width 0.2s ease, opacity 0.2s ease;
    z-index: 40;
}

.admin-sidebar__brand {
    padding: 1rem 1rem 0.75rem;
    border-bottom: 1px solid var(--adm-sidebar-border);
}

.admin-sidebar__brand-link {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    text-decoration: none;
    color: inherit;
    border-radius: 10px;
    padding: 0.35rem 0.25rem;
}

.admin-sidebar__brand-link:hover {
    background: rgba(255, 255, 255, 0.06);
}

.admin-sidebar__brand-mark {
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--adm-accent) 0%, #bfa14a 100%);
    flex-shrink: 0;
}

.admin-sidebar__brand-text {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-width: 0;
}

.admin-app--collapsed .admin-sidebar__brand-text,
.admin-app--collapsed .admin-sidebar__section-label,
.admin-app--collapsed .admin-sidebar__link span:not(.admin-sidebar__ico),
.admin-app--collapsed .admin-sidebar__nav-badge,
.admin-app--collapsed .admin-sidebar__profile-text {
    display: none;
}

.admin-app--collapsed .admin-sidebar__brand-link {
    justify-content: center;
    padding: 0.35rem;
}

.admin-app--collapsed .admin-sidebar__link {
    justify-content: center;
    padding: 0.65rem 0.5rem;
}

.admin-app--collapsed .admin-sidebar__link--sub {
    display: none;
}

.admin-sidebar__site {
    font-weight: 700;
    font-size: 0.95rem;
    letter-spacing: -0.02em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.admin-sidebar__badge {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--adm-sidebar-muted);
}

.admin-sidebar__nav {
    flex: 1;
    min-height: 0; /* required so flex child can shrink and overflow-y scrolls */
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0.5rem 0 1rem;
}

.admin-sidebar__list {
    list-style: none;
    margin: 0;
    padding: 0 0.5rem;
}

.admin-sidebar__section-label {
    font-size: 0.65rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--adm-sidebar-muted);
    padding: 1rem 0.75rem 0.35rem;
    margin: 0;
}

.admin-sidebar__link {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.55rem 0.75rem;
    margin: 2px 0;
    border-radius: 8px;
    color: var(--adm-sidebar-text);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    transition: background 0.15s ease, color 0.15s ease;
}

.admin-sidebar__link:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}

.admin-sidebar__link.is-active {
    background: var(--adm-accent-soft);
    color: #fff;
    box-shadow: inset 3px 0 0 var(--adm-accent);
}

.admin-sidebar__link--sub {
    padding-left: 2.75rem;
    font-size: 0.8125rem;
    font-weight: 450;
    color: var(--adm-sidebar-muted);
}

.admin-sidebar__link--sub:hover {
    color: #fff;
}

.admin-sidebar__link--sub.is-active {
    color: #fff;
}

.admin-sidebar__link--muted {
    opacity: 0.85;
}

.admin-sidebar__ico {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.35rem;
    height: 1.35rem;
}

.admin-sidebar__ico svg {
    width: 1.15rem;
    height: 1.15rem;
    display: block;
    opacity: 0.92;
}

.admin-sidebar__nav-badge {
    margin-left: auto;
    min-width: 1.35rem;
    padding: 0 6px;
    height: 1.35rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    font-size: 0.6875rem;
    font-weight: 800;
    background: var(--adm-accent);
    color: #fff;
}

.admin-sidebar__account {
    flex-shrink: 0;
    border-top: 1px solid var(--adm-sidebar-border);
    padding: 0.35rem 0.35rem 0.45rem;
}

.admin-sidebar__profile {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.25rem 0.35rem 0.35rem;
    min-width: 0;
}

.admin-sidebar__avatar {
    width: 1.85rem;
    height: 1.85rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.12);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.75rem;
    flex-shrink: 0;
}

.admin-sidebar__profile-name {
    font-weight: 600;
    font-size: 0.8125rem;
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.admin-sidebar__profile-role {
    font-size: 0.6875rem;
    color: var(--adm-sidebar-muted);
}

/* Compact grid: profile strip stays short; nav list above gets max scroll space */
.admin-sidebar__list--account {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 3px 6px;
    padding: 0.15rem 0.25rem 0.25rem;
    margin: 0;
    list-style: none;
}

.admin-sidebar__list--account > li {
    margin: 0;
    min-width: 0;
}

.admin-sidebar__list--account .admin-sidebar__link,
.admin-sidebar__list--account .admin-sidebar__logout-btn {
    padding: 0.38rem 0.4rem;
    margin: 0;
    font-size: 0.75rem;
    font-weight: 500;
    gap: 0.35rem;
    border-radius: 6px;
}

.admin-sidebar__list--account .admin-sidebar__ico {
    width: 1.05rem;
    height: 1.05rem;
}

.admin-sidebar__list--account .admin-sidebar__ico svg {
    width: 0.92rem;
    height: 0.92rem;
}

.admin-sidebar__account-logout {
    grid-column: 1 / -1;
}

.admin-sidebar__list--compact {
    padding-top: 0.25rem;
}

.admin-sidebar__list--compact .admin-sidebar__link {
    font-size: 0.8125rem;
    padding: 0.45rem 0.75rem;
}

/* —— Workspace —— */
.admin-workspace {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    background: var(--adm-bg);
}

.admin-topbar {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.65rem 1.25rem;
    background: #fff;
    border-bottom: 1px solid #e5e7eb;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.admin-topbar__start {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
}

.admin-sidebar-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    background: #f9fafb;
    cursor: pointer;
    padding: 0;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.admin-sidebar-toggle:hover {
    background: #f3f4f6;
    border-color: #d1d5db;
}

.admin-sidebar-toggle__bars {
    width: 1.1rem;
    height: 0.75rem;
    border-top: 2px solid #374151;
    border-bottom: 2px solid #374151;
    position: relative;
    display: block;
}

.admin-sidebar-toggle__bars::before {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    border-top: 2px solid #374151;
}

.admin-topbar__title {
    margin: 0;
    font-size: 1.125rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: #111827;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.admin-topbar__end {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-shrink: 0;
}

.admin-topbar__text-link {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--adm-accent);
    text-decoration: none;
}

.admin-topbar__text-link:hover {
    text-decoration: underline;
}

.admin-topbar__text-link--logout {
    color: #6b7280;
}

.admin-topbar__text-link--logout:hover {
    color: #374151;
}

.admin-topbar__user {
    display: none;
}

@media (min-width: 640px) {
    .admin-topbar__user {
        display: flex;
        align-items: center;
        gap: 0.45rem;
    }
}

.admin-topbar__avatar {
    width: 2rem;
    height: 2rem;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--adm-accent) 0%, #b45309 100%);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.admin-topbar__user-name {
    font-size: 0.875rem;
    font-weight: 600;
    max-width: 10rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Shell pages set their own dashboard cards; widen main content area vs legacy .admin-main */
.admin-workspace .admin-main {
    flex: 1;
    padding: 1.25rem 1.5rem 2rem;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
    box-sizing: border-box;
}

.admin-app-footer {
    flex-shrink: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
    justify-content: space-between;
    padding: 0.65rem 1.25rem;
    background: #fff;
    border-top: 1px solid #e5e7eb;
    font-size: 0.8125rem;
    color: #6b7280;
}

.admin-app-footer__extra {
    color: #374151;
    font-weight: 500;
}

/* Touch-friendly overlay when the mobile drawer is open */
.admin-sidebar-backdrop {
    display: none;
}

/* Desktop / tablet: cap sidebar to the viewport so long nav matches mobile—scroll inside __nav */
@media (min-width: 768px) {
    .admin-sidebar {
        position: sticky;
        top: 0;
        align-self: flex-start;
        height: 100vh;
        max-height: 100vh;
        overflow: hidden;
    }

    /* Collapsed = fully hidden (same idea as mobile), not a narrow icon rail */
    .admin-app--collapsed .admin-sidebar {
        flex-basis: 0;
        width: 0;
        min-width: 0;
        overflow: hidden;
        padding: 0;
        border: none;
        opacity: 0;
        pointer-events: none;
    }
}

@media (max-width: 767px) {
    .admin-app:not(.admin-app--collapsed) .admin-sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 38;
        background: rgba(17, 24, 39, 0.45);
        backdrop-filter: blur(2px);
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
        touch-action: pan-y pinch-zoom;
    }

    .admin-app:not(.admin-app--collapsed) .admin-sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        height: 100vh;
        max-width: min(90vw, 20rem);
        box-shadow: 8px 0 24px rgba(0, 0, 0, 0.2);
        z-index: 40;
    }

    .admin-app--collapsed .admin-sidebar {
        flex-basis: 0;
        width: 0;
        overflow: hidden;
        padding: 0;
        border: none;
        opacity: 0;
        pointer-events: none;
    }

    .admin-workspace .admin-main {
        padding: 1rem;
    }
}

@media print {
    html.admin-html--nav-open,
    html.admin-html--nav-open body.admin-body {
        overflow: visible !important;
        height: auto !important;
    }

    .admin-sidebar-backdrop {
        display: none !important;
    }

    .admin-sidebar,
    .admin-topbar,
    .admin-app-footer {
        display: none !important;
    }

    body.admin-body,
    .admin-app,
    .admin-workspace {
        display: block !important;
        min-height: 0 !important;
        background: #fff !important;
    }

    .admin-workspace .admin-main {
        max-width: none !important;
        margin: 0 !important;
        padding: 0 !important;
    }
}

/* Sidebar / topbar logout (POST forms) */
.admin-sidebar__logout-form {
    margin: 2px 0 0 0;
    padding: 0;
}

.admin-sidebar__logout-btn {
    width: 100%;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    background: transparent;
    border: none;
    cursor: pointer;
    font: inherit;
    text-align: left;
    color: inherit;
    padding: 0.45rem 0.75rem;
    margin: 2px 0;
    border-radius: 8px;
    transition: background 0.15s ease;
}

.admin-sidebar__logout-btn:hover {
    background: rgba(255, 255, 255, 0.08);
}

.admin-topbar__logout-form {
    margin: 0;
    display: inline-flex;
    align-items: center;
}

.admin-topbar__logout-btn {
    background: none;
    border: none;
    padding: 0;
    font: inherit;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    color: #6b7280;
}

.admin-topbar__logout-btn:hover {
    color: #374151;
    text-decoration: underline;
}
