/* App shell: desktop sidebar + compact mobile topbar. Mobile bottom nav stays in layouts/app.blade.php */

:root {
    --app-sidebar-width: 276px;
    --app-sidebar-collapsed-width: 80px;
    --app-sidebar-bg: rgba(255, 255, 255, 0.92);
    --app-sidebar-border: rgba(15, 23, 42, 0.08);
    --app-sidebar-text: #0f172a;
    --app-sidebar-muted: #64748b;
    --app-sidebar-hover: #f1f5f9;
    --app-sidebar-active-bg: rgba(14, 165, 233, 0.14);
    --app-sidebar-active-text: #0c4a6e;
    --app-sidebar-accent: #0284c7;
    --app-topbar-height: 56px;
}

.app-skip-link {
    position: absolute;
    top: 8px;
    inset-inline-start: 8px;
    z-index: 1100;
    padding: 10px 14px;
    border-radius: 10px;
    background: #0f172a;
    color: #fff !important;
    text-decoration: none !important;
    transform: translateY(-140%);
}
.app-skip-link:focus {
    transform: translateY(0);
    outline: 2px solid #38bdf8;
    outline-offset: 2px;
}

body:not(.auth-shell) {
    min-height: 100%;
    min-height: 100dvh;
    display: flex;
    flex-direction: row; /* body is RTL via modern-styles — sidebar first = visual right */
    overflow-x: clip;
}

.app-sidebar {
    position: sticky;
    top: 0;
    z-index: 1025;
    isolation: isolate;
    flex: 0 0 var(--app-sidebar-width);
    width: var(--app-sidebar-width);
    height: 100dvh;
    display: flex;
    flex-direction: column;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.62) 0%, rgba(255, 255, 255, 0.28) 46%, rgba(255, 255, 255, 0.5) 100%);
    backdrop-filter: blur(12px) saturate(1.45);
    -webkit-backdrop-filter: blur(12px) saturate(1.45);
    border: 1px solid rgba(255, 255, 255, 0.72);
    box-shadow:
        0 18px 40px rgba(31, 38, 62, 0.12),
        inset 0 1px 0 rgba(255, 255, 255, 0.9);
    transition: flex-basis 0.22s ease, width 0.22s ease;
    overflow: visible;
}
.app-sidebar::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    pointer-events: none;
    z-index: 0;
    backdrop-filter: blur(20px) saturate(1.2);
    -webkit-backdrop-filter: blur(20px) saturate(1.2);
    -webkit-mask-image: linear-gradient(to bottom, #000 0%, rgba(0, 0, 0, 0.45) 22%, transparent 58%);
    mask-image: linear-gradient(to bottom, #000 0%, rgba(0, 0, 0, 0.45) 22%, transparent 58%);
}
.app-sidebar > * {
    position: relative;
    z-index: 1;
}

.app-sidebar__brand {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 16px 14px;
    padding-inline-end: 22px;
    min-height: 76px;
    border-bottom: 1px solid var(--app-sidebar-border);
    background: linear-gradient(180deg, rgba(102, 126, 234, 0.08) 0%, transparent 100%);
}

.app-sidebar__brand-link {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    color: var(--app-sidebar-text) !important;
    text-decoration: none !important;
    flex: 1;
}

.app-sidebar__logo {
    width: 42px;
    height: 42px;
    object-fit: contain;
    flex-shrink: 0;
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
}

.app-sidebar__brand-text {
    font-weight: 700;
    font-size: 0.82rem;
    line-height: 1.45;
    color: var(--app-sidebar-text);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.app-sidebar__collapse {
    position: absolute;
    top: 22px;
    inset-inline-end: -13px;
    width: 26px;
    height: 26px;
    border: 1px solid var(--app-sidebar-border);
    border-radius: 50%;
    background: #fff;
    color: #475569;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.12);
    padding: 0;
    line-height: 0;
    transition: transform 0.2s ease, background 0.2s ease, color 0.2s ease;
}
.app-sidebar__collapse:hover,
.app-sidebar__collapse:focus-visible {
    background: #0ea5e9;
    color: #fff;
    outline: none;
}
.app-sidebar__collapse .bi {
    font-size: 0.85rem;
    transition: transform 0.2s ease;
}

.app-sidebar__nav {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 12px 10px 16px;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    scrollbar-width: thin;
}

.app-sidebar__section {
    margin-bottom: 14px;
}

.app-sidebar__section-title {
    display: block;
    padding: 4px 12px 8px;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: var(--app-sidebar-muted);
    text-transform: none;
}

.app-sidebar__link {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 44px;
    padding: 8px 12px;
    margin-bottom: 2px;
    border-radius: 12px;
    color: #334155 !important;
    text-decoration: none !important;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.18s ease, color 0.18s ease, transform 0.18s ease;
}
.app-sidebar__link .bi {
    font-size: 1.15rem;
    width: 1.25rem;
    text-align: center;
    color: #64748b;
    flex-shrink: 0;
}
.app-sidebar__link:hover {
    background: var(--app-sidebar-hover);
    color: var(--app-sidebar-text) !important;
}
.app-sidebar__link:focus-visible {
    outline: 2px solid #38bdf8;
    outline-offset: 2px;
}
.app-sidebar__link.is-active {
    background: var(--app-sidebar-active-bg);
    color: var(--app-sidebar-active-text) !important;
    box-shadow: inset 0 0 0 1px rgba(2, 132, 199, 0.28);
}
.app-sidebar__link.is-active .bi {
    color: var(--app-sidebar-accent);
}
.app-sidebar__link.is-accent {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.12), rgba(118, 75, 162, 0.1));
}
.app-sidebar__label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-sidebar__group {
    border: 0;
    margin: 0;
}
.app-sidebar__group-toggle {
    list-style: none;
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 44px;
    padding: 8px 12px;
    margin-bottom: 4px;
    border-radius: 12px;
    cursor: pointer;
    color: #334155;
    font-size: 0.9rem;
    font-weight: 600;
    user-select: none;
}
.app-sidebar__group-toggle::-webkit-details-marker {
    display: none;
}
.app-sidebar__group-toggle .bi:first-child {
    font-size: 1.15rem;
    width: 1.25rem;
    text-align: center;
    color: #7c3aed;
}
.app-sidebar__chevron {
    margin-inline-start: auto;
    font-size: 0.8rem !important;
    color: #94a3b8;
    transition: transform 0.2s ease;
}
.app-sidebar__group[open] > .app-sidebar__group-toggle {
    background: rgba(124, 58, 237, 0.08);
}
.app-sidebar__group[open] > .app-sidebar__group-toggle .app-sidebar__chevron {
    transform: rotate(180deg);
}
.app-sidebar__group-body {
    display: flex;
    flex-direction: column;
    padding-inline-start: 6px;
}

.app-sidebar__user {
    flex-shrink: 0;
    border-top: 1px solid rgba(255, 255, 255, 0.45);
    padding: 12px;
    background: linear-gradient(180deg, transparent, rgba(255, 255, 255, 0.28));
}

.app-sidebar__user-main {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    color: inherit !important;
    text-decoration: none !important;
}

.app-sidebar__avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    box-shadow: 0 0 0 2px #fff, 0 0 0 4px rgba(14, 165, 233, 0.35);
}

.app-sidebar__user-meta {
    min-width: 0;
    flex: 1;
}
.app-sidebar__user-name {
    display: block;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--app-sidebar-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.app-sidebar__chips {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 4px;
}
.app-sidebar__chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 7px;
    border-radius: 999px;
    font-size: 0.68rem;
    font-weight: 700;
    line-height: 1.3;
}
.app-sidebar__chip--points {
    background: #dbeafe;
    color: #1d4ed8;
}
.app-sidebar__chip--wallet {
    background: #dcfce7;
    color: #15803d;
}
.app-sidebar__user-actions {
    display: flex;
    gap: 6px;
    margin-top: 10px;
}
.app-sidebar__user-actions .btn {
    flex: 1;
    min-height: 40px;
    font-size: 0.78rem;
    padding: 6px 8px;
}
.app-sidebar__logout {
    margin: 0;
    flex: 1;
}

/* Collapsed rail */
body.app-sidebar-collapsed .app-sidebar {
    flex-basis: var(--app-sidebar-collapsed-width);
    width: var(--app-sidebar-collapsed-width);
}
body.app-sidebar-collapsed .app-sidebar__brand-text,
body.app-sidebar-collapsed .app-sidebar__label,
body.app-sidebar-collapsed .app-sidebar__section-title,
body.app-sidebar-collapsed .app-sidebar__user-meta,
body.app-sidebar-collapsed .app-sidebar__user-actions,
body.app-sidebar-collapsed .app-sidebar__chevron {
    display: none !important;
}
body.app-sidebar-collapsed .app-sidebar__brand {
    justify-content: center;
    padding-inline: 8px;
}
body.app-sidebar-collapsed .app-sidebar__brand-link {
    justify-content: center;
}
body.app-sidebar-collapsed .app-sidebar__link,
body.app-sidebar-collapsed .app-sidebar__group-toggle {
    justify-content: center;
    padding-inline: 0;
}
body.app-sidebar-collapsed .app-sidebar__group-body {
    display: flex !important;
    padding-inline-start: 0;
}
body.app-sidebar-collapsed .app-sidebar__user-main {
    justify-content: center;
}
body.app-sidebar-collapsed .app-sidebar__collapse .bi {
    transform: rotate(180deg);
}

.app-frame {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
    position: relative;
    z-index: 1;
}

.app-frame > .app-main {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    overflow-x: clip;
}

/* Keep footer at the bottom on short pages without stretching page cards to 100dvh.
   height:100% on .cs-card / nested grids otherwise balloons the first card and hides lists. */
.app-frame > .app-main > *:not(.app-site-footer) {
    flex: 0 0 auto;
    min-width: 0;
    max-width: 100%;
    height: auto;
}

.app-frame > .app-main > .app-site-footer {
    margin-top: auto;
    flex-shrink: 0;
}

/* Inner views still wrap themselves in .container — drop the second white-card chrome. */
.app-main.container .container,
.app-main.container .container-fluid {
    width: 100%;
    max-width: none;
    margin-inline: 0;
    margin-top: 0;
    margin-bottom: 0;
    padding-inline: 0;
    padding-top: 0;
    padding-bottom: 0;
    background: transparent;
    box-shadow: none;
    border-radius: 0;
}

.app-main .card,
.app-main .card-body,
.app-main .cs-page,
.app-main .cs-card,
.app-main .cs-card-body {
    min-width: 0;
    max-width: 100%;
}

.app-main .table-responsive {
    display: block;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* modern-styles .table { overflow:hidden } blocks sticky columns and inner scroll. */
.app-main .table-responsive > .table {
    overflow: visible;
    margin-bottom: 0;
}

.app-main .card-body:has(> table),
.app-main .cs-card-body:has(> table) {
    overflow-x: auto;
}

/* Keep the last (actions) column reachable while the table scrolls. */
.app-main .table thead th:last-child,
.app-main .table tbody td:last-child,
.app-main .cs-table thead th:last-child,
.app-main .cs-table tbody td:last-child {
    position: sticky;
    inset-inline-end: 0;
    z-index: 2;
}

.app-main .table thead th:last-child {
    z-index: 3;
    background: var(--gray-color, #797979);
    color: #fff;
}

.app-main .cs-table thead th:last-child {
    z-index: 3;
    background: #fff;
    color: var(--cs-muted, #64748b);
}

.app-main .table tbody td:last-child,
.app-main .cs-table tbody td:last-child {
    background: #fff;
    box-shadow: 8px 0 16px -10px rgba(15, 23, 42, 0.22);
}

.app-main .table tbody tr:hover td:last-child,
.app-main .cs-table tbody tr:hover td:last-child {
    background: #f8fafc;
}

.app-topbar {
    display: none;
    position: sticky;
    top: 0;
    z-index: 1020;
    height: var(--app-topbar-height);
    padding: 0 12px;
    align-items: center;
    gap: 10px;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--app-sidebar-border);
}

.app-topbar__brand {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    flex: 1;
    color: var(--app-sidebar-text) !important;
    text-decoration: none !important;
}
.app-topbar__logo {
    height: 36px;
    width: auto;
    max-width: 36px;
    object-fit: contain;
}
.app-topbar__title {
    font-size: 0.78rem;
    font-weight: 700;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.app-topbar__actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}
.app-topbar__avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    box-shadow: 0 0 0 2px #fff, 0 0 0 3px rgba(14, 165, 233, 0.4);
}
.app-topbar__btn {
    min-height: 40px;
    padding: 6px 10px;
    font-size: 0.8rem;
    font-weight: 600;
}

.mobile-bottom-more-sheet__heading {
    margin: 12px 8px 6px;
    padding: 0;
    font-size: 0.72rem;
    font-weight: 700;
    color: #94a3b8;
}

@media (max-width: 767.98px) {
    body:not(.auth-shell) {
        flex-direction: column;
        overflow-x: hidden;
    }
    .app-sidebar {
        display: none !important;
    }
    .app-topbar {
        display: flex;
    }
    .app-frame > .container.app-main {
        margin-top: 8px;
        margin-bottom: 8px;
    }
    .has-bottom-nav-padding {
        padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px));
    }
}

@media (min-width: 768px) {
    body:not(.auth-shell) {
        gap: 20px;
    }
    .app-sidebar {
        top: 14px;
        height: calc(100dvh - 28px);
        margin-block: 14px;
        margin-inline-start: 14px;
        border-radius: 28px;
    }
    .app-topbar {
        display: none !important;
    }
    .app-frame > .container.app-main {
        margin-top: 16px;
        margin-bottom: 16px;
    }
    .has-bottom-nav-padding {
        padding-bottom: 1.5rem;
    }
}

@media (prefers-reduced-transparency: reduce) {
    .app-sidebar {
        background: rgba(255, 255, 255, 0.96);
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
    }
    .app-sidebar::before {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .app-sidebar,
    .app-sidebar__collapse,
    .app-sidebar__link,
    .app-sidebar__chevron {
        transition: none !important;
    }
}

.mobile-bottom-nav {
    display: none;
}

@media screen and (max-width: 767.98px) {
    .mobile-bottom-nav {
        position: fixed;
        z-index: 1030;
        inset: auto 0 0;
        display: flex;
        gap: 2px;
        padding: 5px 6px calc(5px + env(safe-area-inset-bottom, 0px));
        border-block-start: 1px solid #d8e2ec;
        background: #fff;
        box-shadow: 0 -4px 18px rgb(24 40 66 / 8%);
    }
    .mobile-nav-tab {
        flex: 1 1 0;
        min-width: 0;
        min-height: 54px;
        display: flex;
        align-items: center;
        justify-content: center;
        flex-direction: column;
        gap: 2px;
        padding: 3px;
        background: transparent;
        border: 0;
        border-radius: 10px;
        color: #41536a;
        font: inherit;
        font-size: .72rem;
        line-height: 1.2;
        text-align: center;
        text-decoration: none;
    }
    .mobile-nav-tab .bi { font-size: 1.2rem; }
    .mobile-nav-tab[aria-current],
    .mobile-nav-tab[aria-expanded="true"] {
        color: #144e82;
        background: #e9f3ff;
        font-weight: 700;
    }
    body.mobile-menu-open { overflow: hidden; }
    .mobile-menu {
        position: fixed;
        inset: auto 0 0;
        width: min(100%, 34rem);
        max-width: 100%;
        max-height: min(84dvh, 42rem);
        margin: 0 auto;
        padding: 0;
        border: 0;
        border-radius: 20px 20px 0 0;
        background: #fff;
        color: #1d3048;
        overflow: hidden;
    }
    .mobile-menu[open] { display: flex; flex-direction: column; }
    .mobile-menu::backdrop { background: rgb(20 35 54 / 52%); }
    .mobile-menu__header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 9px 16px;
        border-block-end: 1px solid #e3eaf2;
    }
    .mobile-menu__header h2 { margin: 0; font-size: 1rem; }
    .mobile-menu__close {
        min-width: 55px;
        height: 44px;
        background: #eff4fa;
        border: 0;
        border-radius: 10px;
        color: inherit;
        font-size: .8rem;
    }
    .mobile-menu__body {
        overflow-y: auto;
        overscroll-behavior: contain;
        padding: 12px 14px calc(12px + env(safe-area-inset-bottom, 0px));
    }
    .mobile-menu__group + .mobile-menu__group,
    .mobile-menu__logout {
        margin-block-start: 10px;
        padding-block-start: 10px;
        border-block-start: 1px solid #e3eaf2;
    }
    .mobile-menu__group h3 { margin: 0 8px 4px; font-size: .78rem; color: #52647b; }
    .mobile-menu__group a,
    .mobile-menu__logout button {
        display: flex;
        align-items: center;
        gap: 10px;
        width: 100%;
        min-height: 46px;
        padding: 7px 10px;
        background: transparent;
        border: 0;
        border-radius: 8px;
        color: inherit;
        text-align: start;
        text-decoration: none;
    }
    .mobile-menu__group a[aria-current] { color: #144e82; background: #e9f3ff; font-weight: 700; }
    .mobile-menu__logout button { color: #9e262d; }
    .mobile-nav-tab:focus-visible,
    .mobile-menu :is(a, button):focus-visible {
        outline: 2px solid #17588e;
        outline-offset: -2px;
    }
}

@media print {
    .app-sidebar,
    .app-topbar,
    .app-skip-link,
    .mobile-bottom-nav,
    .mobile-menu {
        display: none !important;
    }
    .app-frame {
        display: block;
    }
}
