/* MarketBZ Admin Shell R4.0
 * Clean consolidated shell. No cumulative R3.x mobile overrides.
 */
:root {
    --admin-shell-height: 64px;
    --admin-shell-bg: #0b1220;
    --admin-shell-bg-2: #101b2d;
    --admin-shell-line: #253651;
    --admin-shell-text: #eaf2ff;
    --admin-shell-muted: #9cb4d2;
    --admin-shell-blue: #2563eb;
    --admin-shell-blue-2: #1d4ed8;
    --admin-shell-danger: #fecaca;
    --admin-page-light: #f5f7fb;
    --admin-page-dark: #08111f;
}

html.admin-dark-preload { background: var(--admin-page-dark); color-scheme: dark; }
body.admin-body { margin: 0; background: var(--admin-page-light); }
body.admin-body.darkmode { background: var(--admin-page-dark) !important; }
body.admin-body *, body.admin-body *::before, body.admin-body *::after { box-sizing: border-box; }

/* ---------- shell ---------- */
#adminShell.admin-shell {
    position: sticky;
    top: 0;
    z-index: 6100;
    isolation: isolate;
    width: 100%;
    margin: 0;
    color: var(--admin-shell-text) !important;
    background: linear-gradient(135deg, var(--admin-shell-bg) 0%, var(--admin-shell-bg-2) 100%);
    border-bottom: 1px solid var(--admin-shell-line);
    box-shadow: 0 7px 22px rgba(2, 6, 23, .22);
}

#adminShell .admin-shell__bar {
    min-height: 64px;
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px 14px;
}

#adminShell a,
#adminShell button,
#adminShell summary,
#adminShell span {
    -webkit-tap-highlight-color: transparent;
}
#adminShell a,
#adminShell button,
#adminShell summary,
.admin-drawer a,
.admin-drawer button,
.admin-drawer summary { touch-action: manipulation; }

#adminShell .admin-brand {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 9px;
    min-width: 174px;
    text-decoration: none !important;
}

#adminShell .admin-brand__icon {
    width: 38px;
    height: 38px;
    flex: 0 0 38px;
    display: grid;
    place-items: center;
    border-radius: 11px;
    background: linear-gradient(145deg, #3b82f6, #1d4ed8);
    border: 1px solid rgba(147, 197, 253, .44);
    box-shadow: 0 8px 18px rgba(37, 99, 235, .32);
}

#adminShell .admin-brand__icon img { width: 21px; height: 21px; max-width: none; }
#adminShell .admin-brand__text { min-width: 0; display: block; }
#adminShell .admin-brand__title,
#adminShell .admin-brand__sub {
    display: block;
    opacity: 1 !important;
    visibility: visible !important;
}
#adminShell .admin-brand__title {
    color: #fff !important;
    -webkit-text-fill-color: #fff !important;
    font-size: 14px;
    font-weight: 900;
    line-height: 1.08;
    white-space: nowrap;
}
#adminShell .admin-brand__sub {
    margin-top: 3px;
    color: #93c5fd !important;
    -webkit-text-fill-color: #93c5fd !important;
    font-size: 8px;
    font-weight: 900;
    letter-spacing: .035em;
    line-height: 1;
    white-space: nowrap;
}

/* ---------- frequent links ---------- */
#adminShell .admin-quick-nav {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 5px;
}

#adminShell .admin-quick-nav__mobile-extra { display: none !important; }

#adminShell .admin-quick-nav__link,
#adminShell .admin-quick-nav__link:link,
#adminShell .admin-quick-nav__link:visited {
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 11px;
    border: 1px solid transparent;
    border-radius: 9px;
    color: #dbeafe !important;
    -webkit-text-fill-color: #dbeafe !important;
    background: rgba(30, 64, 175, .08);
    font-size: 11px;
    font-weight: 900;
    line-height: 1;
    white-space: nowrap;
    text-decoration: none !important;
    opacity: 1 !important;
    visibility: visible !important;
}

#adminShell .admin-quick-nav__link:hover {
    color: #fff !important;
    -webkit-text-fill-color: #fff !important;
    border-color: #36557d;
    background: #172b49;
}

#adminShell .admin-quick-nav__link.is-active {
    color: #fff !important;
    -webkit-text-fill-color: #fff !important;
    border-color: #5b8ed6;
    background: #1e4f91;
    box-shadow: inset 0 -2px 0 #bfdbfe;
}

/* ---------- desktop grouped navigation ---------- */
#adminShell .admin-nav {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 3px;
}

#adminShell .admin-nav details { position: relative; }
#adminShell .admin-nav details > summary { list-style: none; }
#adminShell .admin-nav details > summary::-webkit-details-marker { display: none; }

#adminShell .admin-nav__trigger {
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 0 10px;
    border: 1px solid transparent;
    border-radius: 9px;
    color: #dbeafe !important;
    -webkit-text-fill-color: #dbeafe !important;
    background: transparent;
    font-size: 11px;
    font-weight: 900;
    white-space: nowrap;
    cursor: pointer;
    opacity: 1 !important;
    visibility: visible !important;
}

#adminShell .admin-nav__trigger::after { content: '⌄'; color: #93c5fd; font-size: 10px; }
#adminShell .admin-nav details[open] .admin-nav__trigger,
#adminShell .admin-nav__trigger:hover {
    color: #fff !important;
    -webkit-text-fill-color: #fff !important;
    border-color: #36557d;
    background: #172b49;
}

#adminShell .admin-nav__menu {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    z-index: 3100;
    width: max-content;
    min-width: 210px;
    max-width: 320px;
    padding: 7px;
    border: 1px solid #2d4261;
    border-radius: 12px;
    background: #0f1b2d;
    box-shadow: 0 18px 45px rgba(2, 6, 23, .42);
}

#adminShell .admin-nav__menu-link,
#adminShell .admin-nav__menu-link:link,
#adminShell .admin-nav__menu-link:visited {
    min-height: 38px;
    display: flex;
    align-items: center;
    padding: 0 11px;
    border-radius: 8px;
    color: #dbeafe !important;
    -webkit-text-fill-color: #dbeafe !important;
    font-size: 11px;
    font-weight: 800;
    text-decoration: none !important;
    white-space: nowrap;
    opacity: 1 !important;
    visibility: visible !important;
}

#adminShell .admin-nav__menu-link:hover,
#adminShell .admin-nav__menu-link.is-active {
    color: #fff !important;
    -webkit-text-fill-color: #fff !important;
    background: #1e3a5f;
}

/* ---------- actions ---------- */
#adminShell .admin-shell__actions {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
}

#adminShell .admin-shell__icon-button,
#adminShell .admin-shell__plain-link {
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: 1px solid transparent;
    border-radius: 9px;
    padding: 0 9px;
    color: #f8fafc !important;
    -webkit-text-fill-color: #f8fafc !important;
    background: transparent;
    font-size: 10px;
    font-weight: 900;
    text-decoration: none !important;
    white-space: nowrap;
    cursor: pointer;
    opacity: 1 !important;
    visibility: visible !important;
}

#adminShell .admin-shell__icon-button:hover,
#adminShell .admin-shell__plain-link:hover {
    border-color: #36557d;
    background: #172b49;
}

#adminShell .admin-shell__icon-button svg { width: 18px; height: 18px; color: inherit; stroke: currentColor; }
#adminShell .admin-shell__theme-button[aria-pressed="true"] { background: #17365f; border-color: #3b6eac; }
#adminShell .admin-shell__env {
    min-width: 28px;
    height: 18px;
    display: inline-grid;
    place-items: center;
    padding: 0 5px;
    border-radius: 999px;
    color: #bfdbfe !important;
    -webkit-text-fill-color: #bfdbfe !important;
    background: rgba(37, 99, 235, .35);
    font-size: 8px;
    font-weight: 900;
}
#adminShell .admin-shell__plain-link--danger,
#adminShell .admin-shell__plain-link--danger span {
    color: var(--admin-shell-danger) !important;
    -webkit-text-fill-color: var(--admin-shell-danger) !important;
}
#adminShell .admin-remote-support {
    padding: 5px 8px;
    border-radius: 999px;
    color: #fde68a;
    background: rgba(146, 64, 14, .32);
    font-size: 9px;
    font-weight: 900;
    white-space: nowrap;
}
#adminShell .admin-shell__mobile-only { display: none; }
#adminShell .admin-shell__menu-toggle [data-admin-menu-icon="close"] { display: none; }
#adminShell .admin-shell__menu-toggle[aria-expanded="true"] [data-admin-menu-icon="open"] { display: none; }
#adminShell .admin-shell__menu-toggle[aria-expanded="true"] [data-admin-menu-icon="close"] { display: block; }

/* ---------- drawer ---------- */
.admin-drawer-backdrop {
    position: fixed;
    inset: var(--admin-shell-height) 0 0 0;
    z-index: 6080;
    display: none;
    background: rgba(2, 6, 23, .48);
}
.admin-drawer-backdrop.is-open { display: block; }

.admin-drawer {
    position: fixed;
    top: var(--admin-shell-height);
    right: 0;
    bottom: 0;
    z-index: 6090;
    width: min(92vw, 430px);
    padding: 14px;
    overflow-y: auto;
    color: #eaf2ff;
    background: #0b1526;
    border-left: 1px solid #29405f;
    box-shadow: -18px 0 48px rgba(2, 6, 23, .45);
    transform: translateX(104%);
    visibility: hidden;
    pointer-events: none;
    transition: transform .2s ease, visibility .2s ease;
}
.admin-drawer.is-open { transform: translateX(0); visibility: visible; pointer-events: auto; }
.admin-drawer__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.admin-drawer__title { color: #fff; font-size: 17px; font-weight: 900; }
.admin-drawer__sub { margin-top: 3px; color: #8fa8c8; font-size: 10px; font-weight: 700; }
.admin-drawer__close {
    width: 40px; height: 40px; flex: 0 0 40px;
    border: 1px solid #334b6d; border-radius: 10px;
    color: #fff !important; -webkit-text-fill-color: #fff !important;
    background: #13233a; font-size: 24px; line-height: 1; cursor: pointer;
}
.admin-drawer__search {
    width: 100%; height: 42px; margin-bottom: 12px; padding: 0 12px;
    border: 1px solid #334b6d; border-radius: 10px;
    color: #eaf2ff !important; background: #0e1b2d !important; outline: 0;
}
.admin-drawer__search:focus { border-color: #60a5fa; box-shadow: 0 0 0 3px rgba(37, 99, 235, .2); }
.admin-drawer__group { margin-bottom: 9px; overflow: hidden; border: 1px solid #263a57; border-radius: 12px; background: #0e1a2b; }
.admin-drawer__group > summary {
    min-height: 48px; display: flex; align-items: center; justify-content: space-between;
    padding: 0 14px; list-style: none; cursor: pointer;
    color: #eaf2ff !important; -webkit-text-fill-color: #eaf2ff !important;
    font-size: 13px; font-weight: 900;
}
.admin-drawer__group > summary::-webkit-details-marker { display: none; }
.admin-drawer__group > summary::after { content: '+'; color: #93c5fd; font-size: 18px; }
.admin-drawer__group[open] > summary::after { content: '−'; }
.admin-drawer__links { padding: 6px; border-top: 1px solid #263a57; background: #091322; }
.admin-drawer__link,
.admin-drawer__link:link,
.admin-drawer__link:visited {
    min-height: 44px; display: flex; align-items: center; padding: 0 11px;
    border-radius: 8px; color: #dbeafe !important; -webkit-text-fill-color: #dbeafe !important;
    font-size: 12px; font-weight: 800; text-decoration: none !important;
}
.admin-drawer__link:hover,
.admin-drawer__link.is-active { color: #fff !important; -webkit-text-fill-color: #fff !important; background: #17365f; }
.admin-drawer__footer { display: grid; grid-template-columns: 1fr; gap: 8px; margin-top: 14px; padding-top: 14px; border-top: 1px solid #263a57; }
.admin-drawer__footer button,
.admin-drawer__footer a {
    min-height: 44px; display: flex; align-items: center; justify-content: center;
    border: 1px solid #334b6d; border-radius: 10px;
    color: #eaf2ff !important; -webkit-text-fill-color: #eaf2ff !important;
    background: #11213a; font-size: 12px; font-weight: 900; text-decoration: none !important;
}
.admin-drawer__footer .admin-drawer__logout { color: #fecaca !important; -webkit-text-fill-color: #fecaca !important; border-color: #6b3340; background: #2a1820; }
.admin-remote-support--drawer { display: block; width: fit-content; margin-top: 10px; }
html.admin-drawer-open,
html.admin-drawer-open body { overflow: hidden !important; }
html.admin-drawer-open .admin-legacy-stage { pointer-events: none !important; user-select: none; }

/* ---------- legacy mobile canvas ---------- */
.admin-legacy-toolbar { display: none; }
.admin-legacy-stage { position: relative; z-index: 0; isolation: isolate; width: 100%; min-width: 0; }
.admin-legacy-canvas { min-width: 0; transform-origin: 0 0; }
.admin-legacy-view-toggle { display: none !important; }

/* ---------- scroll tools, responsive pages only ---------- */
.admin-scroll-tools {
    position: fixed; right: 12px; bottom: 14px; z-index: 2050;
    display: none; flex-direction: column; gap: 6px;
}
.admin-scroll-tools.is-visible { display: flex; }
.admin-scroll-tools__button {
    width: 42px; height: 42px; display: grid; place-items: center;
    border: 1px solid #60a5fa; border-radius: 12px;
    color: #fff; background: rgba(37, 99, 235, .94); box-shadow: 0 8px 22px rgba(2, 6, 23, .24);
}
.admin-scroll-tools__button svg { width: 19px; height: 19px; }
.admin-scroll-tools__button span { position: absolute; clip: rect(0 0 0 0); width: 1px; height: 1px; overflow: hidden; }
.admin-scroll-tools__button:disabled { opacity: .35; cursor: default; }

/* ---------- tablet/mobile ---------- */
@media (max-width: 1180px) {
    :root { --admin-shell-height: 108px; }

    body.admin-body { overflow-x: hidden !important; }

    #adminShell.admin-shell {
        padding-top: max(8px, env(safe-area-inset-top));
        overflow: visible;
    }

    #adminShell .admin-shell__bar {
        min-height: 0;
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        grid-template-areas: "brand actions" "quick quick";
        align-items: center;
        column-gap: 8px;
        row-gap: 8px;
        padding: 0 max(10px, env(safe-area-inset-right)) 8px max(10px, env(safe-area-inset-left));
    }

    #adminShell .admin-brand { grid-area: brand; min-width: 0; }
    #adminShell .admin-brand__icon { width: 40px; height: 40px; flex-basis: 40px; }
    #adminShell .admin-brand__title { font-size: 15px; }
    #adminShell .admin-brand__sub { font-size: 8.5px; }

    #adminShell .admin-nav { display: none !important; }
    #adminShell .admin-shell__actions { grid-area: actions; margin-left: 0; }
    #adminShell .admin-shell__plain-link,
    #adminShell .admin-remote-support { display: none !important; }
    #adminShell .admin-shell__theme-label { display: none !important; }
    #adminShell .admin-shell__mobile-only { display: inline-flex !important; }
    #adminShell .admin-shell__theme-button,
    #adminShell .admin-shell__menu-toggle {
        width: 40px; min-width: 40px; height: 40px; min-height: 40px; padding: 0;
        border-color: #2c4568; background: #0e1b2d;
    }

    #adminShell .admin-quick-nav {
        grid-area: quick;
        width: 100%;
        display: grid;
        grid-template-columns: repeat(5, minmax(0, 1fr));
        gap: 0;
        overflow: hidden;
        border-top: 1px solid #263a57;
        border-bottom: 1px solid #263a57;
        background: #0a1526;
    }
    #adminShell .admin-quick-nav__mobile-extra { display: flex !important; }
    #adminShell .admin-quick-nav__link,
    #adminShell .admin-quick-nav__link:link,
    #adminShell .admin-quick-nav__link:visited {
        width: 100%; min-width: 0; min-height: 39px; height: 39px;
        padding: 0 2px; margin: 0;
        border: 0; border-left: 1px solid #20334e; border-radius: 0;
        color: #cfe2ff !important; -webkit-text-fill-color: #cfe2ff !important;
        background: transparent;
        font-size: clamp(9px, 2.45vw, 11px); font-weight: 900; letter-spacing: -.045em;
        overflow: hidden; text-overflow: clip;
    }
    #adminShell .admin-quick-nav__link:first-child { border-left: 0; }
    #adminShell .admin-quick-nav__link:hover { border-color: #20334e; background: #132742; }
    #adminShell .admin-quick-nav__link.is-active {
        color: #fff !important; -webkit-text-fill-color: #fff !important;
        background: #1d4f91; box-shadow: inset 0 -3px 0 #93c5fd;
    }
    #adminShell .admin-quick-nav__link span {
        display: block; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: clip;
        color: inherit !important; -webkit-text-fill-color: inherit !important;
    }

    .admin-drawer-backdrop { top: var(--admin-shell-height); }
    .admin-drawer { top: var(--admin-shell-height); }

    body.admin-legacy-desktop-page .admin-scroll-tools { display: none !important; }
    body.admin-legacy-desktop-page .admin-legacy-toolbar {
        position: relative; z-index: 20;
        width: 100%; min-height: 38px; display: flex; align-items: center; gap: 6px;
        padding: 5px 8px; overflow-x: auto;
        border-bottom: 1px solid #d9e1ec; background: #f8fafc;
        scrollbar-width: none;
    }
    body.darkmode.admin-legacy-desktop-page .admin-legacy-toolbar { border-color: #26364e; background: #0e1a2b; }
    body.admin-legacy-desktop-page .admin-legacy-toolbar::-webkit-scrollbar { display: none; }
    body.admin-legacy-desktop-page .admin-legacy-toolbar__status {
        flex: 1 1 auto; min-width: 82px; color: #475569; font-size: 10px; font-weight: 900; white-space: nowrap;
    }
    body.darkmode.admin-legacy-desktop-page .admin-legacy-toolbar__status { color: #cbd5e1; }
    body.admin-legacy-desktop-page .admin-legacy-toolbar button {
        flex: 0 0 auto; min-height: 28px; padding: 0 9px;
        border: 1px solid #cbd5e1; border-radius: 8px;
        color: #1e293b; background: #fff; font-size: 10px; font-weight: 900; white-space: nowrap;
    }
    body.darkmode.admin-legacy-desktop-page .admin-legacy-toolbar button { color: #e5edf8; background: #13233a; border-color: #334155; }
    body.admin-legacy-desktop-page .admin-legacy-toolbar button.is-active { color: #fff; background: #2563eb; border-color: #2563eb; }

    body.admin-legacy-desktop-page .admin-legacy-stage {
        width: 100vw; max-width: 100vw; min-height: calc(100dvh - var(--admin-shell-height));
        overflow-y: visible; -webkit-overflow-scrolling: touch;
    }
    body.admin-legacy-desktop-page .admin-legacy-stage.is-fit { overflow-x: hidden; }
    body.admin-legacy-desktop-page .admin-legacy-stage.is-original { overflow-x: auto; scrollbar-gutter: stable; overscroll-behavior-x: contain; touch-action: pan-x pan-y; }
    body.admin-legacy-desktop-page .admin-legacy-canvas { width: max-content; min-width: 1180px; max-width: none !important; }
    body.admin-legacy-desktop-page .admin-legacy-canvas > * { max-width: none !important; }
    body.admin-legacy-desktop-page .admin-legacy-canvas .admin-table-scroll { width: auto !important; overflow: visible !important; border-radius: 0 !important; }
    body.admin-legacy-desktop-page .admin-legacy-canvas .admin-table-scroll::after { content: none !important; display: none !important; }
    body.admin-legacy-desktop-page .admin-legacy-canvas .admin-table-scroll table { min-width: 0 !important; }
    body.admin-legacy-desktop-page .admin-legacy-canvas .exception-grid { grid-template-columns: repeat(4, minmax(0, 1fr)) !important; gap: 10px !important; padding: 10px !important; }
    body.admin-legacy-desktop-page .admin-legacy-canvas .modal-content { width: auto !important; max-width: none !important; margin: 15% auto !important; }

    html.admin-drawer-open .admin-legacy-toolbar,
    html.admin-drawer-open .admin-scroll-tools { visibility: hidden; opacity: 0; pointer-events: none; }
}

@media (max-width: 420px) {
    :root { --admin-shell-height: 106px; }
    #adminShell .admin-shell__bar { padding-left: 8px; padding-right: 8px; }
    #adminShell .admin-brand { gap: 7px; }
    #adminShell .admin-brand__icon { width: 38px; height: 38px; flex-basis: 38px; }
    #adminShell .admin-brand__title { font-size: 14px; }
    #adminShell .admin-brand__sub { font-size: 8px; }
    #adminShell .admin-shell__theme-button,
    #adminShell .admin-shell__menu-toggle { width: 38px; min-width: 38px; height: 38px; min-height: 38px; }
    #adminShell .admin-quick-nav__link,
    #adminShell .admin-quick-nav__link:link,
    #adminShell .admin-quick-nav__link:visited { font-size: clamp(8.2px, 2.5vw, 9.6px); letter-spacing: -.06em; }
}

@media (min-width: 1181px) {
    .admin-drawer,
    .admin-drawer-backdrop { display: none !important; }
    .admin-legacy-toolbar { display: none !important; }
}

@media (prefers-reduced-motion: reduce) {
    .admin-drawer { transition: none; }
    * { scroll-behavior: auto !important; }
}
