/* CRM mobile app shell — top bar + bottom nav (KV tokens from capture) */

:root {
    --crm-shell-top-h: 56px;
    --crm-shell-bottom-h: 44px;
    --crm-nav-fab-size: 48px;
    --crm-sheet-side-w: 440px;
}

body.crm-capture-body.has-crm-shell {
    padding-top: calc(var(--crm-shell-top-h) + env(safe-area-inset-top, 0px));
}

.crm-topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 80;
    height: calc(var(--crm-shell-top-h) + env(safe-area-inset-top, 0px));
    padding: env(safe-area-inset-top, 0px) 14px 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: color-mix(in srgb, var(--crm-navy-deep, #1e2a3a) 92%, transparent);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid rgba(247, 227, 161, 0.12);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
    transition: right 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    container-type: inline-size;
    container-name: crm-topbar;
}

.crm-topbar-brand {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    color: #fff;
    min-width: 0;
    flex-shrink: 1;
}

.crm-topbar-brand img {
    height: 28px;
    width: auto;
    display: block;
    flex-shrink: 0;
}

.crm-topbar-brand-text {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-width: 0;
    gap: 1px;
}

.crm-topbar-brand-label {
    font-size: 15px;
    font-weight: 800;
    letter-spacing: 0.02em;
    text-transform: none;
    color: #fff;
    white-space: nowrap;
    line-height: 1.1;
}

.crm-topbar-brand-sub {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.01em;
    color: rgba(255, 255, 255, 0.62);
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: min(42vw, 280px);
}

.crm-topbar-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 1;
    min-width: 0;
}

.crm-topbar-icon-btn {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: rgba(255, 255, 255, 0.06);
    color: rgba(255, 255, 255, 0.88);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    font-size: 15px;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

/* Shared topbar nav links */
.crm-topbar-nav {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 36px;
    padding: 0 10px;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: rgba(255, 255, 255, 0.88);
    text-decoration: none;
    font: inherit;
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
    cursor: pointer;
    transition: color 0.15s, background 0.15s, padding 0.15s, width 0.15s;
}

.crm-topbar-nav > i,
.crm-topbar-nav .crm-topbar-inbox-icon-wrap > i {
    font-size: 14px;
    flex-shrink: 0;
}

.crm-topbar-nav > span:not(.crm-topbar-inbox-icon-wrap):not(.crm-topbar-inbox-badge) {
    line-height: 1;
}

.crm-topbar-nav:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.06);
}

.crm-topbar-nav.is-active {
    color: var(--crm-cream, #f7e3a1);
    background: rgba(247, 227, 161, 0.1);
}

.crm-topbar-nav--inbox {
    display: none;
}

.crm-topbar-inbox-icon-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.crm-topbar-inbox-badge {
    position: absolute;
    top: -6px;
    right: -8px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 999px;
    background: var(--crm-coral, #e74c3c);
    color: #fff;
    font-size: 9px;
    font-weight: 800;
    line-height: 16px;
    text-align: center;
    border: 2px solid rgba(30, 42, 58, 0.92);
}

.crm-topbar-inbox-badge[hidden] {
    display: none !important;
}

/* Narrow topbar: icon-only; active keeps icon + label */
@container crm-topbar (max-width: 1080px) {
    .crm-topbar-nav:not(.is-active) {
        width: 36px;
        padding: 0;
        gap: 0;
    }

    .crm-topbar-nav:not(.is-active) > span:not(.crm-topbar-inbox-icon-wrap):not(.crm-topbar-inbox-badge) {
        display: none;
    }

    .crm-topbar-nav.is-active {
        padding: 0 10px;
    }

    .crm-topbar-brand-label {
        font-size: 14px;
        max-width: 7.5em;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .crm-topbar-brand-sub {
        max-width: 9.5em;
    }

    .crm-topbar-personnel-rest,
    .crm-topbar-personnel-caret {
        display: none;
    }

    .crm-topbar-personnel-firstname {
        max-width: 7.5em;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .crm-topbar-unlock span {
        display: none;
    }

    .crm-topbar-unlock {
        width: 36px;
        padding: 0;
        justify-content: center;
    }
}

@container crm-topbar (max-width: 760px) {
    .crm-topbar-nav.is-active > span:not(.crm-topbar-inbox-icon-wrap):not(.crm-topbar-inbox-badge) {
        display: none;
    }

    .crm-topbar-nav.is-active {
        width: 36px;
        padding: 0;
        gap: 0;
    }
}

@supports not (container-type: inline-size) {
    @media (max-width: 1100px) {
        .crm-topbar-nav:not(.is-active) {
            width: 36px;
            padding: 0;
            gap: 0;
        }

        .crm-topbar-nav:not(.is-active) > span:not(.crm-topbar-inbox-icon-wrap):not(.crm-topbar-inbox-badge) {
            display: none;
        }

        .crm-topbar-brand-label {
            font-size: 14px;
            max-width: 6.5em;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        .crm-topbar-brand-sub {
            max-width: 8em;
        }

        .crm-topbar-personnel-rest,
        .crm-topbar-personnel-caret {
            display: none;
        }

        .crm-topbar-unlock span {
            display: none;
        }

        .crm-topbar-unlock {
            width: 36px;
            padding: 0;
            justify-content: center;
        }
    }
}

.crm-bottom-nav__icon-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.crm-bottom-nav__badge {
    position: absolute;
    top: -5px;
    right: -8px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 999px;
    background: var(--crm-coral, #e74c3c);
    color: #fff;
    font-size: 9px;
    font-weight: 800;
    line-height: 16px;
    text-align: center;
    border: 2px solid #fff;
}

.crm-bottom-nav__badge[hidden] {
    display: none !important;
}

.crm-topbar-icon-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
}

.crm-topbar-icon-btn.is-active {
    background: rgba(255, 255, 255, 0.16);
    border-color: rgba(247, 227, 161, 0.45);
    color: #fff;
    box-shadow: 0 0 0 1px rgba(247, 227, 161, 0.18);
}

.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;
}

.crm-topbar-personnel {
    position: relative;
}

.crm-topbar-personnel-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    border-radius: 999px;
    padding: 4px 10px 4px 4px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    max-width: 180px;
}

.crm-topbar-personnel-btn:hover,
.crm-topbar-personnel-btn[aria-expanded="true"] {
    background: rgba(255, 255, 255, 0.14);
}

.crm-topbar-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--crm-coral, #e74c3c);
    color: #fff;
    font-size: 11px;
    font-weight: 800;
}

.crm-topbar-personnel-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.crm-topbar-personnel-caret {
    font-size: 10px;
    opacity: 0.7;
    flex-shrink: 0;
}

.crm-topbar-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 180px;
    padding: 6px;
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.22);
    z-index: 50;
}

.crm-topbar-menu[hidden] {
    display: none !important;
}

.crm-topbar-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    border: none;
    background: transparent;
    color: var(--crm-navy, #2f4358);
    font-family: inherit;
    font-size: 13px;
    font-weight: 700;
    text-align: left;
    text-decoration: none;
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
}

.crm-topbar-menu-item:hover {
    background: rgba(47, 67, 88, 0.08);
}

.crm-topbar-menu-item--danger {
    color: var(--crm-coral, #e74c3c);
}

.crm-topbar-unlock {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border-radius: 999px;
    padding: 8px 12px;
    background: var(--crm-coral, #e74c3c);
    color: #fff;
    text-decoration: none;
    font-size: 12px;
    font-weight: 800;
    white-space: nowrap;
}

.crm-topbar-unlock:hover {
    background: var(--crm-coral-dark, #c0392b);
    color: #fff;
}

/* App frame — center page columns on tablet/desktop */
.crm-app-frame {
    width: 100%;
    max-width: 100%;
    margin-inline: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.crm-app-frame > * {
    box-sizing: border-box;
}

body.has-crm-shell .crm-capture-shell {
    padding-top: 8px;
    padding-left: 16px;
    padding-right: 16px;
    padding-bottom: calc(
        var(--crm-shell-bottom-h)
        + (var(--crm-nav-fab-size) / 2)
        + 10px
        + env(safe-area-inset-bottom, 0px)
    );
}

body.has-crm-shell.crm-shell-no-bottomnav .crm-capture-shell {
    padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
}

@media (max-width: 767px) {
    body.has-crm-shell .crm-back-link {
        display: none !important;
    }

    body.has-crm-shell .crm-topbar-nav:not(.crm-topbar-nav--inbox) {
        display: none;
    }

    body.has-crm-shell .crm-manage-actor {
        display: none !important;
    }

    body.has-crm-shell .crm-manage-header--desktop-only {
        display: none !important;
    }

    body.has-crm-shell .crm-manage-board {
        padding-top: 4px;
    }

    body.has-crm-shell .crm-manage-toolbar {
        margin-top: 0;
    }
}

/* Bottom nav */
.crm-bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    align-items: flex-end;
    gap: 0;
    min-height: calc(var(--crm-shell-bottom-h) + env(safe-area-inset-bottom, 0px));
    padding: 0 6px env(safe-area-inset-bottom, 0px);
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-top: 1px solid rgba(47, 67, 88, 0.08);
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.08);
    overflow: visible;
    transform: translateY(0);
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transition:
        transform 0.28s cubic-bezier(0.4, 0, 0.2, 1),
        opacity 0.22s ease,
        visibility 0.28s;
}

.crm-bottom-nav--locked {
    grid-template-columns: repeat(3, 1fr);
}

@media (min-width: 900px) {
    body.crm-sheet-open .crm-topbar {
        right: min(var(--crm-sheet-side-w, 440px), 100%);
    }
}

body.crm-sheet-open .crm-bottom-nav {
    transform: translateY(calc(100% + (var(--crm-nav-fab-size) / 2) + env(safe-area-inset-bottom, 0px)));
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

body.has-crm-shell.crm-sheet-open .crm-capture-shell {
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    transition: padding-bottom 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

@media (prefers-reduced-motion: reduce) {
    .crm-topbar,
    .crm-bottom-nav,
    body.has-crm-shell .crm-capture-shell {
        transition: none;
    }
}

.crm-bottom-nav__item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    gap: 1px;
    min-height: var(--crm-shell-bottom-h);
    padding: 0 2px 3px;
    border: none;
    background: transparent;
    color: rgba(47, 67, 88, 0.55);
    text-decoration: none;
    font-family: inherit;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.02em;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.crm-bottom-nav__item i {
    font-size: 16px;
    line-height: 1;
}

.crm-bottom-nav__item.is-active {
    color: var(--crm-coral, #e74c3c);
}

.crm-bottom-nav__item--capture {
    position: relative;
    justify-content: flex-end;
    padding-bottom: 3px;
    margin-top: calc(var(--crm-nav-fab-size) / -2);
    padding-top: calc(var(--crm-nav-fab-size) / 2);
}

.crm-bottom-nav__capture-fab {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translate(-50%, -50%);
    width: var(--crm-nav-fab-size);
    height: var(--crm-nav-fab-size);
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--crm-coral, #e74c3c), var(--crm-coral-dark, #c0392b));
    color: #fff;
    box-shadow: 0 6px 16px rgba(231, 76, 60, 0.4);
    border: 2px solid #fff;
    z-index: 1;
}

.crm-bottom-nav__item--capture i {
    font-size: 18px;
    color: #fff;
}

.crm-bottom-nav__item--capture span:not(.crm-bottom-nav__capture-fab) {
    color: var(--crm-navy, #2f4358);
    font-size: 9px;
    line-height: 1.1;
}

.crm-bottom-nav__item--capture.is-active .crm-bottom-nav__capture-fab {
    box-shadow: 0 8px 20px rgba(231, 76, 60, 0.5), 0 0 0 2px color-mix(in srgb, var(--crm-coral, #e74c3c) 24%, transparent);
}

@media (min-width: 768px) {
    .crm-bottom-nav {
        display: none;
    }

    .crm-topbar-nav--inbox {
        display: inline-flex;
    }

    body.has-crm-shell .crm-capture-shell {
        padding-bottom: 48px;
    }

    body.has-crm-shell .crm-manage-actor {
        display: none !important;
    }

    body.has-crm-shell .crm-manage-header--desktop-only {
        display: flex;
    }
}

/* More sheet */
.crm-more-sheet {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.crm-more-sheet[hidden] {
    display: none !important;
}

.crm-more-sheet-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(30, 42, 58, 0.45);
    border: none;
    padding: 0;
    cursor: pointer;
}

.crm-more-sheet-panel {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 520px;
    background: #fff;
    border-radius: 20px 20px 0 0;
    padding: 10px 16px calc(18px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.2);
    animation: crmMoreSheetIn 0.22s ease;
}

@keyframes crmMoreSheetIn {
    from {
        transform: translateY(24px);
        opacity: 0.6;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.crm-more-sheet-handle {
    width: 40px;
    height: 4px;
    border-radius: 999px;
    background: rgba(47, 67, 88, 0.18);
    margin: 4px auto 14px;
}

.crm-more-sheet-title {
    margin: 0 0 12px;
    font-size: 16px;
    font-weight: 800;
    color: var(--crm-navy, #2f4358);
}

.crm-more-sheet-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.crm-more-sheet-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 14px 12px;
    border: none;
    border-radius: 12px;
    background: transparent;
    color: var(--crm-navy, #2f4358);
    font-family: inherit;
    font-size: 14px;
    font-weight: 700;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}

.crm-more-sheet-item:hover {
    background: rgba(47, 67, 88, 0.06);
}

.crm-more-sheet-item i {
    width: 22px;
    text-align: center;
    color: var(--crm-coral, #e74c3c);
}

.crm-more-sheet-item--muted {
    color: rgba(47, 67, 88, 0.65);
}

.crm-more-sheet-item--muted i {
    color: rgba(47, 67, 88, 0.45);
}

.crm-more-sheet-item--danger {
    color: var(--crm-coral, #e74c3c);
}

/* Manage greeting + scope tabs (greeting removed; scope tabs only) */
.crm-scope-tabs {
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 2px;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 10px;
}

.crm-scope-tab {
    flex: 0 0 auto;
    border: 2px solid rgba(47, 67, 88, 0.12);
    background: #fff;
    border-radius: 999px;
    padding: 7px 14px;
    font-size: 12px;
    font-weight: 700;
    font-family: inherit;
    color: var(--crm-navy, #2f4358);
    cursor: pointer;
}

.crm-scope-tab.is-active {
    border-color: var(--crm-navy, #2f4358);
    background: color-mix(in srgb, var(--crm-navy, #2f4358) 10%, #fff);
}

.crm-scope-tab:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

@media (prefers-reduced-motion: reduce) {
    .crm-more-sheet-panel {
        animation: none;
    }
}

/* Sticky back to top */
.crm-back-to-top {
    position: fixed;
    right: 16px;
    bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    z-index: 45;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 999px;
    background: var(--crm-navy, #2f4358);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    box-shadow: 0 10px 24px rgba(30, 42, 58, 0.28);
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(10px) scale(0.92);
    transition:
        opacity 0.2s ease,
        transform 0.2s ease,
        visibility 0.2s ease,
        background 0.15s ease,
        bottom 0.28s cubic-bezier(0.4, 0, 0.2, 1),
        right 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

.crm-back-to-top.is-visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: none;
}

.crm-back-to-top:hover {
    background: color-mix(in srgb, var(--crm-navy, #2f4358) 88%, #000);
}

.crm-back-to-top:focus-visible {
    outline: 2px solid var(--crm-cream, #f7e3a1);
    outline-offset: 3px;
}

@media (max-width: 767px) {
    body.has-crm-shell:not(.crm-shell-no-bottomnav):not(.crm-sheet-open) .crm-back-to-top {
        bottom: calc(
            var(--crm-shell-bottom-h)
            + (var(--crm-nav-fab-size) / 2)
            + 14px
            + env(safe-area-inset-bottom, 0px)
        );
    }
}

body.crm-sheet-open .crm-back-to-top {
    z-index: 75;
    bottom: calc(88px + env(safe-area-inset-bottom, 0px));
}

@media (prefers-reduced-motion: reduce) {
    .crm-back-to-top {
        transition: none;
    }
}
