/*
 * components/shell.css — admin shell + dashboard
 *
 * Mobile-first: the sidebar is an off-canvas drawer (slides in over a
 * scrim); the topbar carries the hamburger. At >= 900px (desktop.css) the
 * sidebar becomes a fixed rail and the content shifts right.
 */

/* ── Shell frame ─────────────────────────────────────────────────────── */
.admin-shell { min-height: 100dvh; }
.admin-shell__body { min-height: 100dvh; display: flex; flex-direction: column; }

/* ── Sidebar (navy off-canvas drawer on mobile) ──────────────────────── */
.admin-sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: var(--sidebar-w); max-width: 84vw;
    background: linear-gradient(180deg, var(--navy-800), var(--navy-900));
    z-index: var(--z-sidebar);
    display: flex; flex-direction: column;
    padding: 16px 12px;
    transform: translateX(-100%);
    transition: transform .22s ease;
    overflow-y: auto;
}
body.sidebar-open .admin-sidebar { transform: translateX(0); }
.admin-sidebar__brand {
    display: flex; align-items: center; gap: 10px; padding: 6px 8px 16px;
    border-bottom: 1px solid var(--navy-600); margin-bottom: 12px;
}
.admin-sidebar__logo {
    width: 36px; height: 36px; object-fit: contain; background: #fff;
    border-radius: 9px; padding: 5px;
}
.admin-sidebar__name { color: #fff; font-weight: 700; font-size: 1.02rem; }
.admin-sidebar__name span { color: var(--color-primary); }

.admin-nav { display: flex; flex-direction: column; gap: 3px; }
.admin-nav__item {
    display: flex; align-items: center; gap: 12px;
    padding: 11px 12px; border-radius: 10px;
    color: #c2c9da; font-size: 0.92rem; font-weight: 500;
    border: 0; background: transparent; width: 100%; text-align: left;
    transition: background .14s ease, color .14s ease;
}
.admin-nav__item:hover { background: var(--navy-700); color: #fff; }
.admin-nav__item.is-active { background: var(--color-primary); color: #fff; box-shadow: 0 6px 16px rgba(229,37,42,.35); }
.admin-nav__ic { width: 22px; text-align: center; font-size: 1.05rem; }

/* Settings group (collapsible <details>) */
.admin-nav__group { border-radius: 10px; }
.admin-nav__sum { cursor: pointer; list-style: none; user-select: none; }
.admin-nav__sum::-webkit-details-marker { display: none; }
.admin-nav__chev { margin-left: auto; font-size: 0.9rem; transition: transform .16s ease; opacity: .7; }
.admin-nav__group[open] > .admin-nav__sum .admin-nav__chev { transform: rotate(90deg); }
.admin-nav__sub { display: flex; flex-direction: column; gap: 3px; margin: 3px 0 3px 14px; padding-left: 8px; border-left: 1px solid var(--navy-600); }
.admin-nav__subitem { font-size: 0.88rem; padding: 9px 12px; }

.admin-sidebar__logout { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--navy-600); }
.admin-nav__item--logout { color: #f0a6a6; }
.admin-nav__item--logout:hover { background: rgba(229,37,42,.18); color: #fff; }

/* ── Scrim behind the open drawer ────────────────────────────────────── */
.admin-scrim {
    position: fixed; inset: 0; background: rgba(8,12,24,.5);
    z-index: var(--z-scrim); border: 0;
}
body.sidebar-open .admin-scrim { display: block !important; }

/* ── Topbar ──────────────────────────────────────────────────────────── */
/* Mobile bottom navigation (native-app style) — phones only. */
.admin-bottomnav { display: none; }
@media (max-width: 720px) {
    .admin-bottomnav {
        display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 45;
        background: #fff; border-top: 1px solid var(--color-border);
        padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
        box-shadow: 0 -2px 14px rgba(15, 23, 42, .07);
    }
    .admin-bottomnav__item { flex: 1 1 0; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 4px 2px; text-decoration: none; color: var(--color-text-soft); font-size: 0.64rem; font-weight: 700; min-width: 0; }
    .admin-bottomnav__ic { font-size: 1.25rem; line-height: 1; }
    .admin-bottomnav__lbl { white-space: nowrap; }
    .admin-bottomnav__item.is-active { color: var(--color-primary); }
    /* Make room above the fixed bar so the last card clears it. Higher
       specificity (body.has-shell) so it wins over the base .admin-main
       padding shorthand, plus the iOS safe-area inset. */
    body.has-shell .admin-main { padding-bottom: calc(86px + env(safe-area-inset-bottom, 0px)); }
}

/* Global loading bar (driven by app.js: AJAX + navigation). */
#admin-loader { position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 9999; pointer-events: none; opacity: 0; transition: opacity .15s ease; overflow: hidden; }
#admin-loader.is-on { opacity: 1; }
.admin-loader__bar { display: block; height: 100%; width: 38%; background: var(--color-primary); border-radius: 0 3px 3px 0; box-shadow: 0 0 8px var(--color-primary); animation: admin-loader-slide 1.05s ease-in-out infinite; }
@keyframes admin-loader-slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(285%); } }

.admin-topbar {
    position: sticky; top: 0; z-index: 40;
    height: var(--topbar-h);
    display: flex; align-items: center; gap: 12px;
    padding: 0 16px;
    background: rgba(255,255,255,.9);
    backdrop-filter: saturate(180%) blur(8px);
    border-bottom: 1px solid var(--color-border);
}
.admin-topbar__burger {
    border: 0; background: transparent; color: var(--color-text);
    display: inline-flex; padding: 6px; margin-left: -4px; border-radius: 8px;
}
.admin-topbar__burger:hover { background: var(--color-bg-alt); }
.admin-topbar__title { font-size: 1.02rem; font-weight: 700; }
/* Company switcher / label */
.admin-topbar__company { display: inline-flex; align-items: center; gap: 8px; margin-left: 14px; min-width: 0; }
.admin-topbar__company-ic { color: var(--color-text-soft); display: inline-flex; flex: 0 0 auto; }
.admin-topbar__company-select {
    border: 1.5px solid var(--color-border); border-radius: 9px; background: #fff;
    padding: 7px 30px 7px 10px; font: inherit; font-size: 0.86rem; font-weight: 600; color: var(--color-text);
    max-width: 200px; cursor: pointer;
    appearance: none; -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23939AA6' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 10px center;
}
.admin-topbar__company-select:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px var(--color-primary-soft); }
.admin-topbar__company-go { margin-left: 6px; border: 0; background: var(--color-primary); color: #fff; border-radius: 8px; padding: 7px 12px; font-weight: 700; cursor: pointer; }
.admin-topbar__company-label {
    display: inline-flex; align-items: center; gap: 7px; margin-left: 14px;
    font-size: 0.86rem; font-weight: 700; color: var(--color-text-muted);
    background: var(--color-bg-alt); border: 1px solid var(--color-border); border-radius: 9px; padding: 6px 12px;
    max-width: 220px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.admin-topbar__company-label svg { color: var(--color-primary); flex: 0 0 auto; }

/* Searchable company switcher (super admin) */
.admin-company { position: relative; margin-left: 14px; }
.admin-company__btn {
    display: inline-flex; align-items: center; gap: 8px;
    border: 1.5px solid var(--color-border); background: #fff; border-radius: 9px;
    padding: 7px 12px; cursor: pointer; font: inherit; font-size: 0.86rem; font-weight: 600;
    color: var(--color-text); max-width: 240px;
}
.admin-company__btn:hover { border-color: var(--color-primary); }
.admin-company__ic { color: var(--color-text-soft); display: inline-flex; flex: 0 0 auto; }
.admin-company__current { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-company__chev { color: var(--color-text-soft); display: inline-flex; flex: 0 0 auto; }
.admin-company__panel {
    position: absolute; top: calc(100% + 6px); left: 0; width: 300px; max-width: 82vw;
    background: #fff; border: 1px solid var(--color-border); border-radius: 12px;
    box-shadow: var(--shadow-3); z-index: 50; overflow: hidden;
}
.admin-company__search {
    display: flex; align-items: center; gap: 8px; padding: 10px 12px;
    border-bottom: 1px solid var(--color-border); color: var(--color-text-soft);
}
.admin-company__search-input { flex: 1; border: 0; outline: none; font: inherit; font-size: 0.9rem; background: transparent; color: var(--color-text); min-width: 0; }
.admin-company__list { list-style: none; margin: 0; padding: 6px; max-height: 320px; overflow-y: auto; }
.admin-company__opt {
    display: block; width: 100%; text-align: left; border: 0; background: transparent;
    border-radius: 8px; padding: 9px 12px; font: inherit; font-size: 0.88rem; color: var(--color-text);
    cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.admin-company__opt:hover { background: var(--color-bg-alt); }
.admin-company__opt.is-selected { background: var(--color-primary-soft); color: var(--color-primary); font-weight: 700; }
.admin-company__empty { padding: 14px 12px; text-align: center; color: var(--color-text-soft); font-size: 0.85rem; }

/* Admin account menu (topbar dropdown) */
.admin-menu { position: relative; }
.admin-menu__trigger {
    display: inline-flex; align-items: center; gap: 9px;
    border: 0; background: transparent; cursor: pointer; padding: 4px 6px; border-radius: 9px;
}
.admin-menu__trigger:hover { background: var(--color-bg-alt); }
.admin-menu__chev { color: var(--color-text-soft); flex: 0 0 auto; }
.admin-menu__panel {
    position: absolute; top: calc(100% + 8px); right: 0; min-width: 210px;
    background: #fff; border: 1px solid var(--color-border); border-radius: 12px;
    box-shadow: var(--shadow-3); z-index: 50; padding: 6px; overflow: hidden;
}
.admin-menu__panel form { margin: 0; }
.admin-menu__item {
    display: flex; align-items: center; gap: 11px; width: 100%;
    padding: 10px 12px; border-radius: 9px; border: 0; background: transparent;
    font: inherit; font-size: 0.9rem; font-weight: 600; color: var(--color-text);
    cursor: pointer; text-align: left; text-decoration: none;
}
.admin-menu__item svg { color: var(--color-text-soft); flex: 0 0 auto; }
.admin-menu__item:hover { background: var(--color-bg-alt); }
.admin-menu__item:hover svg { color: var(--color-primary); }
.admin-menu__sep { height: 1px; background: var(--color-border-soft); margin: 5px 4px; }
.admin-menu__item--logout { color: var(--color-error); }
.admin-menu__item--logout svg { color: var(--color-error); }
.admin-menu__item--logout:hover { background: #fdecec; }

.admin-topbar__right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.admin-topbar__user { display: flex; align-items: center; gap: 9px; }
.admin-topbar__avatar {
    width: 32px; height: 32px; border-radius: 50%; background: var(--color-primary);
    color: #fff; font-weight: 700; font-size: 0.85rem;
    display: inline-flex; align-items: center; justify-content: center;
}
.admin-topbar__uname { font-size: 0.88rem; font-weight: 600; color: var(--color-text-muted); }
.admin-topbar__logout {
    border: 1px solid var(--color-border); background: #fff; color: var(--color-text-muted);
    width: 36px; height: 36px; border-radius: 9px; display: inline-flex; align-items: center; justify-content: center;
}
.admin-topbar__logout:hover { color: var(--color-primary); border-color: var(--color-primary-soft); background: var(--color-primary-soft); }

/* ── Content ─────────────────────────────────────────────────────────── */
.admin-main { padding: 18px 16px 40px; flex: 1; }
.admin-main--bare { min-height: 100dvh; }

/* ── Dashboard ───────────────────────────────────────────────────────── */
.dash { max-width: none; margin: 0; }
.dash__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.dash__title { font-size: 1.3rem; font-weight: 800; }
.dash__section-title { font-size: 1.05rem; font-weight: 800; margin: 26px 0 10px; }
.dash__sub { color: var(--color-text-muted); font-size: 0.88rem; }
.dash__period {
    font-size: 0.8rem; font-weight: 600; color: var(--color-text-muted);
    background: #fff; border: 1px solid var(--color-border); border-radius: 9px; padding: 7px 12px;
}
.dash__note {
    margin: 14px 0 16px; font-size: 0.82rem; color: #8a6d1e;
    background: #fff8e6; border: 1px solid #f5e2ad; border-radius: 10px; padding: 9px 12px;
}
.dash__status { font-size: 0.78rem; font-weight: 700; border-radius: 999px; padding: 6px 14px; white-space: nowrap; }
.dash__status.is-on  { background: #dcfce7; color: #166534; }
.dash__status.is-off { background: #fee2e2; color: #991b1b; }
.metric--link { text-decoration: none; transition: transform .06s ease, box-shadow .14s ease; }
.metric--link:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); }
.dash-table { display: flex; flex-direction: column; margin-top: 4px; }
/* Fixed Orders / Revenue columns (deterministic so the header and rows stay
   aligned) with a clear gap so the two numbers never run together. */
.dash-table__head, .dash-table__row { display: grid; grid-template-columns: minmax(0, 1fr) 64px 140px; gap: 18px; align-items: center; padding: 10px 4px; }
.dash-table__head { font-size: 0.74rem; font-weight: 700; letter-spacing: .3px; text-transform: uppercase; color: var(--color-text-soft); border-bottom: 1px solid var(--color-border); }
.dash-table__head span:not(:first-child), .dash-table__row span:not(:first-child) { text-align: right; font-weight: 700; white-space: nowrap; }
.dash-table__row { border-bottom: 1px solid var(--color-border-soft); font-size: 0.9rem; }
.dash-table__row:last-child { border-bottom: 0; }
.dash-table__name { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Phones: tighten the number columns so the company name keeps room. */
@media (max-width: 560px) {
    .dash-table__head, .dash-table__row { grid-template-columns: minmax(0, 1fr) 46px 116px; gap: 10px; }
    .dash-table__row { font-size: 0.84rem; }
}

/* Dashboard → loyalty entry */
.dash__loyalty-link { font-size: 0.85rem; font-weight: 700; color: var(--color-primary); white-space: nowrap; }
.dash__loyalty-link:hover { text-decoration: underline; }
.dash__loyalty { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.dash__loyalty-text { color: var(--color-text-muted); font-size: 0.88rem; margin-top: 4px; }
.dash__loyalty-cta { flex: 0 0 auto; background: var(--color-primary); color: #fff; font-weight: 700; font-size: 0.88rem; padding: 10px 18px; border-radius: 10px; text-decoration: none; }
.dash__loyalty-cta:hover { filter: brightness(1.05); }

.dash__metrics { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.metric {
    background: #fff; border: 1px solid var(--color-border); border-radius: var(--radius-lg);
    padding: 16px; display: flex; flex-direction: column; gap: 4px; box-shadow: var(--shadow-1);
}
.metric__val { font-size: 1.55rem; font-weight: 800; line-height: 1; }
.metric__lbl { font-size: 0.78rem; color: var(--color-text-muted); font-weight: 500; }
.metric--green  { border-left: 4px solid #16a34a; } .metric--green  .metric__val { color: #15803d; }
.metric--blue   { border-left: 4px solid #2563eb; } .metric--blue   .metric__val { color: #1d4ed8; }
.metric--amber  { border-left: 4px solid #d97706; } .metric--amber  .metric__val { color: #b45309; }
.metric--purple { border-left: 4px solid #7c3aed; } .metric--purple .metric__val { color: #6d28d9; }

.dash__grid { display: grid; grid-template-columns: 1fr; gap: 14px; margin-top: 14px; }
.card {
    background: #fff; border: 1px solid var(--color-border); border-radius: var(--radius-lg);
    padding: 16px 18px; box-shadow: var(--shadow-1); margin-top: 14px;
}
.dash__grid .card { margin-top: 0; }
.card__title { font-size: 0.98rem; font-weight: 700; margin-bottom: 12px; }

.tierbar { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; font-size: 0.84rem; }
.tierbar:last-child { margin-bottom: 0; }
.tierbar__lbl { width: 78px; font-weight: 600; flex: 0 0 auto; }
.tierbar__track { flex: 1; height: 9px; background: #edf0f5; border-radius: 5px; overflow: hidden; }
.tierbar__fill { display: block; height: 100%; border-radius: 5px; }
.tierbar__n { width: 44px; text-align: right; font-weight: 700; flex: 0 0 auto; }

.feat-chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip { padding: 5px 11px; border-radius: 8px; font-size: 0.78rem; font-weight: 600; }
.chip--on    { background: #dcfce7; color: #166534; }
.chip--pause { background: #fef9c3; color: #854d0e; }
.chip--off   { background: #fee2e2; color: #991b1b; }

.quick { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.quick__tile {
    display: flex; flex-direction: column; align-items: center; gap: 8px;
    padding: 16px 10px; border: 1.5px solid var(--color-border); border-radius: var(--radius-md);
    font-size: 0.84rem; font-weight: 600; color: var(--color-text); text-align: center;
    transition: border-color .14s ease, transform .06s ease, box-shadow .14s ease;
}
.quick__tile:hover { border-color: var(--color-primary); box-shadow: var(--shadow-2); transform: translateY(-2px); }
.quick__ic { font-size: 1.5rem; }

/* ── Image lightbox (global; opened by [data-lightbox] via app.js) ──── */
.admin-lightbox { position: fixed; inset: 0; z-index: 200; display: none; align-items: center; justify-content: center; background: rgba(8, 12, 24, .85); padding: 24px; }
.admin-lightbox.is-on { display: flex; }
.admin-lightbox__img { max-width: 96vw; max-height: 92vh; border-radius: 10px; box-shadow: 0 20px 60px rgba(0, 0, 0, .5); object-fit: contain; background: #fff; }
.admin-lightbox__x { position: fixed; top: 16px; right: 18px; width: 42px; height: 42px; border-radius: 50%; border: none; background: rgba(255, 255, 255, .16); color: #fff; font-size: 1.1rem; cursor: pointer; }
.admin-lightbox__x:hover { background: rgba(255, 255, 255, .32); }
