/**
 * Shell layout fixes — admin, team, client portals
 * v1 — sidebar, hero, toolbar, panels, responsive
 */

/* ---- Layout frame ---- */
.admin-shell__layout.ca-layout,
.client-shell .ca-layout {
    display: flex;
    align-items: stretch;
    width: 100%;
}

.admin-shell .ca-content-wrap,
.client-shell .ca-content-wrap {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

/* ---- Desktop sidebar (nav was collapsing / only sign-out visible) ---- */
@media (min-width: 992px) {
    .admin-shell .ca-sidebar,
    .client-shell .ca-sidebar {
        position: sticky;
        top: var(--admin-topbar-h, 76px);
        height: calc(100vh - var(--admin-topbar-h, 76px));
        max-height: calc(100vh - var(--admin-topbar-h, 76px));
        display: flex !important;
        flex-direction: column;
        overflow: hidden;
        flex-shrink: 0;
    }

    .admin-shell .ca-sidebar__nav,
    .client-shell .ca-sidebar__nav {
        flex: 1 1 auto;
        min-height: 0;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
    }

    .admin-shell .ca-sidebar__footer,
    .client-shell .ca-sidebar__footer {
        flex-shrink: 0;
        margin-top: auto;
    }

    .admin-shell .ca-nav-list,
    .client-shell .ca-nav-list {
        display: block;
        width: 100%;
    }

    .admin-shell .ca-nav-list li,
    .client-shell .ca-nav-list li {
        display: block;
        width: 100%;
    }

    .admin-shell .ca-nav-list a,
    .client-shell .ca-nav-list a {
        display: flex !important;
        width: auto;
        opacity: 1 !important;
        visibility: visible !important;
    }
}

/* ---- Top bar ---- */
.admin-topbar {
    display: none;
}

@media (min-width: 992px) {
    .admin-topbar.d-lg-flex {
        display: flex !important;
    }
}

/* ---- Hero / project header ---- */
.cx-hero {
    color: var(--cx-text, #1f2937);
}

.cx-hero__title {
    color: var(--cx-text, #1f2937) !important;
}

.cx-hero__media {
    max-height: 220px;
    overflow: hidden;
}

.cx-hero__info {
    background: var(--cx-card, #fff);
}

/* ---- Stats grid ---- */
.cx-stats {
    display: grid;
    gap: 0.75rem;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.cx-stats--4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

@media (min-width: 768px) {
    .cx-stats--4 {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

.cx-stat {
    min-height: 0;
}

/* ---- Panels ---- */
.cx-panel,
.grow-panel,
.cx-project .card.border-0 {
    background: #fff;
    border: 1px solid #e8edf3 !important;
    border-radius: 16px;
    box-shadow: 0 4px 18px rgba(15, 23, 42, 0.04);
    overflow: hidden;
}

.cx-panel__head,
.grow-panel__head,
.grow-panel > .card-header {
    padding: 0.9rem 1rem;
    border-bottom: 1px solid #eef2f7;
    background: #fafbfc;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.cx-panel__body {
    padding: 1rem;
}

.cx-empty {
    text-align: center;
    padding: 2rem 1rem;
    color: #94a3b8;
}

.cx-empty i {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    display: block;
}

/* ---- Milestones tracker ---- */
.ms-hero .ms-panel--hero,
.ms-panel.ms-panel--hero {
    border: 1px solid #e8edf3 !important;
    border-radius: 16px !important;
    background: #fff;
    box-shadow: 0 4px 18px rgba(15, 23, 42, 0.04);
}

.ms-step__toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    align-items: center;
}

.ms-step__toolbar .btn {
    white-space: nowrap;
}

@media (max-width: 575.98px) {
    .ms-step__toolbar .btn {
        flex: 1 1 calc(50% - 0.4rem);
        min-width: 0;
    }
}

/* ---- Project page columns ---- */
.cx-project .row.g-3 {
    align-items: flex-start;
}

@media (min-width: 992px) {
    .cx-project .col-lg-4 .cx-panel {
        position: sticky;
        top: calc(var(--admin-topbar-h, 76px) + 1rem);
    }
}

/* ---- Toolbar: keep actions visible on all breakpoints ---- */
body.cx-shell .ca-toolbar.cx-toolbar {
    display: flex !important;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.85rem 1.25rem 0.5rem !important;
}

@media (max-width: 991.98px) {
    body.cx-shell .cx-toolbar__titles {
        display: none !important;
    }

    body.cx-shell .cx-toolbar__actions {
        display: grid !important;
        grid-template-columns: 1fr 1fr;
        gap: 0.5rem;
        width: 100%;
    }

    body.cx-shell .cx-toolbar__actions > .btn,
    body.cx-shell .cx-toolbar__actions > a.btn {
        width: 100%;
        min-height: 44px;
    }

    body.cx-shell .cx-toolbar__actions > .btn-primary,
    body.cx-shell .cx-toolbar__actions > a.btn-primary {
        grid-column: 1 / -1;
    }

    body.cx-shell .cx-toolbar__actions .dropdown {
        grid-column: 1 / -1;
    }

    body.cx-shell .cx-toolbar__actions .dropdown .btn {
        width: 100%;
    }
}

@media (min-width: 992px) {
    body.cx-shell .cx-toolbar__titles {
        display: block !important;
    }

    body.cx-shell .cx-toolbar__actions {
        display: flex !important;
        flex-wrap: wrap;
        width: auto;
    }
}

/* ---- Mobile shell (only when .is-mobile-viewport on body) ---- */
@media (max-width: 991.98px) {
    body.is-mobile-viewport.admin-shell .ca-sidebar,
    body.is-mobile-viewport.client-shell .ca-sidebar {
        display: none !important;
    }

    body.is-mobile-viewport {
        padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px));
    }

    body.is-mobile-viewport nav.app-tabbar {
        display: flex !important;
    }
}

@media (min-width: 992px) {
    body nav.app-tabbar {
        display: none !important;
    }

    body .ca-mobile-top {
        display: none !important;
    }
}

/* ---- Client shell accent ---- */
.client-shell {
    --cx-accent: #d4a017;
    --cx-accent-soft: #f6e7b8;
}

.client-shell .ca-sidebar__nav a.active,
.client-shell .ca-nav-list a.active {
    background: #fff8e6 !important;
    color: #9a7b12 !important;
    border-left-color: #d4a017 !important;
}

/* ---- Auth pages ---- */
.auth-shell {
    min-height: 100vh;
    background: linear-gradient(180deg, #f7f4ef 0%, #f1f5f9 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

.auth-card {
    width: 100%;
    max-width: 420px;
    background: #fff;
    border: 1px solid #e8edf3;
    border-radius: 18px;
    box-shadow: 0 12px 40px rgba(15, 23, 42, 0.08);
    padding: 1.75rem;
}

.auth-card__brand {
    text-align: center;
    margin-bottom: 1.25rem;
}

.auth-card__brand img {
    max-height: 56px;
    width: auto;
}

/* ---- Forms & tables ---- */
.pro-form .grow-panel,
.admin-shell .pro-page .card {
    margin-bottom: 1rem;
}

.admin-shell .table-responsive {
    border-radius: 12px;
    border: 1px solid #e8edf3;
    background: #fff;
}

/* ---- Update rows ---- */
.update-row {
    padding: 1rem 1.1rem;
    border-bottom: 1px solid #f1f5f9;
}

.update-row:last-child {
    border-bottom: 0;
}

.update-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    align-items: center;
}

/* ---- Dashboard ---- */
.cx-dash {
    max-width: 1400px;
}

.cx-project-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* ---- Brand logo in topbar ---- */
.admin-topbar__brand .brand-logo-img {
    max-height: 52px !important;
    max-width: 200px !important;
    object-fit: contain;
}

/* ---- Drawer footer ---- */
.admin-drawer-footer {
    padding: 1rem;
    border-top: 1px solid #e8edf3;
    margin-top: auto;
}

.ca-mobile-drawer {
    display: none;
    flex-direction: column;
}

.ca-mobile-drawer.is-open {
    display: flex;
}

.ca-mobile-drawer .ca-sidebar__nav {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem 0;
}

/* ---- Fix invisible content on cream background ---- */
body.cx-shell .ca-content {
    color: #1f2937;
}

body.cx-shell .text-muted {
    color: #64748b !important;
}

/* ---- Client project sidebar nav ---- */
.client-shell {
    --admin-sidebar-w: 280px;
}

.client-project-nav__label {
    list-style: none;
    padding: 0.85rem 1.15rem 0.35rem;
    pointer-events: none;
}

.client-project-nav__label span {
    display: block;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #94a3b8 !important;
    opacity: 0.9;
}

body.sidebar-theme-dark .client-project-nav__label span {
    color: #64748b !important;
}

.client-shell .ca-nav-list.client-project-nav a.client-project-nav__link,
.client-shell .ca-mobile-drawer .ca-nav-list.client-project-nav a.client-project-nav__link {
    align-items: flex-start !important;
    gap: 0.7rem;
    min-height: 2.75rem;
    padding-top: 0.65rem !important;
    padding-bottom: 0.65rem !important;
    line-height: 1.25;
}

.client-shell .ca-nav-list.client-project-nav a.client-project-nav__link i {
    margin-top: 0.15rem;
    flex-shrink: 0;
}

.client-project-nav__text {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-width: 0;
    flex: 1;
}

.client-project-nav__title {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    white-space: normal !important;
    word-break: break-word;
    font-size: 0.9rem;
    font-weight: 600;
    line-height: 1.3;
}

.client-project-nav__meta {
    display: block;
    font-size: 0.72rem;
    font-weight: 500;
    color: #94a3b8 !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.client-shell .ca-nav-list a.active .client-project-nav__meta,
.client-shell .ca-nav-list a.client-project-nav__link.active .client-project-nav__meta {
    color: color-mix(in srgb, var(--primary-color, #2563eb) 70%, #64748b) !important;
}

body.sidebar-theme-dark .client-shell .ca-nav-list a .client-project-nav__meta {
    color: #94a3b8 !important;
}

body.admin-sidebar-collapsed .client-project-nav__label,
body.admin-sidebar-collapsed .client-project-nav__text {
    display: none !important;
}

body.admin-sidebar-collapsed .client-shell .ca-nav-list.client-project-nav a.client-project-nav__link {
    justify-content: center;
    align-items: center !important;
}

