/* Unified owner portfolio, property and tenant home context switcher */

.context-switcher {
    position: relative;
    width: 100%;
    min-width: 0;
    max-width: 310px;
    flex: 1 1 auto;
}

.top.has-context-switcher .top-leading { min-width: min(310px, 30vw); }

/* The fixed dialog and backdrop must never inherit a blurred containing block. */
.top.has-context-switcher {
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
}

.context-trigger {
    width: 100%;
    min-width: 220px;
    max-width: 310px;
    min-height: 48px;
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr) 16px;
    align-items: center;
    gap: 9px;
    padding: 6px 9px;
    color: var(--text-subtle);
    text-align: left;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 11px;
}

.context-trigger:hover,
.context-trigger[aria-expanded='true'] {
    background: var(--surface-soft);
    border-color: var(--border);
}

.context-trigger-icon,
.context-choice-icon {
    display: grid;
    place-items: center;
    color: var(--brand);
    background: var(--brand-soft);
    border-radius: 9px;
}

.context-trigger-icon { width: 34px; height: 34px; }
.context-trigger-copy { min-width: 0; }
.context-trigger-copy small,
.context-trigger-copy strong {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.context-trigger-copy small {
    color: var(--muted);
    font-size: 9px;
    font-weight: 760;
    letter-spacing: .055em;
    line-height: 1.2;
    text-transform: uppercase;
}
.context-trigger-copy strong { margin-top: 3px; font-size: 12px; line-height: 1.25; }
.context-trigger-action {
    display: none;
    color: var(--brand);
    font-size: 10px;
    font-weight: 750;
    white-space: nowrap;
}
.context-chevron {
    width: 16px;
    height: 16px;
    color: var(--muted);
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: transform 150ms ease;
}
.context-trigger[aria-expanded='true'] .context-chevron { transform: rotate(180deg); }

.context-backdrop {
    position: fixed;
    inset: 0;
    z-index: 39;
    padding: 0;
    background: transparent;
    border: 0;
    cursor: default;
}

.context-panel {
    position: absolute;
    top: calc(100% + 9px);
    left: 0;
    z-index: 40;
    width: min(430px, calc(100vw - 32px));
    max-height: min(690px, calc(100dvh - 94px));
    overflow: hidden;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 20px 52px rgba(16, 24, 40, .2), 0 2px 8px rgba(16, 24, 40, .08);
    animation: context-panel-in 150ms cubic-bezier(.2, .8, .2, 1) both;
}

.context-panel[hidden],
.context-backdrop[hidden] { display: none; }

.context-panel-head {
    min-height: 67px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}
.context-panel-head p {
    margin: 0 0 3px;
    color: var(--muted);
    font-size: 9px;
    font-weight: 760;
    letter-spacing: .065em;
    text-transform: uppercase;
}
.context-panel-head h2 { margin: 0; font-size: 17px; letter-spacing: -.02em; }
.context-close {
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    padding: 0;
    color: var(--muted-strong);
    background: var(--surface-soft);
    border: 1px solid var(--border);
    border-radius: 9px;
}
.context-close:hover { color: var(--text); background: var(--surface-brand); }

.context-panel-body {
    max-height: min(540px, calc(100dvh - 235px));
    overflow-y: auto;
    padding: 14px;
}

.context-mode-tabs {
    display: grid;
    gap: 7px;
    margin-bottom: 15px;
}
.context-mode-tabs > span,
.context-results-head h3 {
    color: var(--muted-strong);
    font-size: 10px;
    font-weight: 750;
    letter-spacing: .04em;
    text-transform: uppercase;
}
.context-mode-tabs > div {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    padding: 3px;
    background: var(--surface-soft);
    border: 1px solid var(--border);
    border-radius: 10px;
}
.context-mode-tabs button {
    flex: 1 1 105px;
    min-height: 36px;
    padding: 7px 12px;
    color: var(--muted-strong);
    font-size: 11px;
    font-weight: 720;
    background: transparent;
    border: 0;
    border-radius: 7px;
}
.context-mode-tabs button:hover { color: var(--brand); background: var(--brand-soft); }
.context-mode-tabs button[aria-selected='true'] {
    color: var(--brand-strong);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}

.context-results { display: grid; gap: 8px; }
.context-results-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.context-results-head h3 { margin: 0; }
.context-results-head small { color: var(--muted); font-size: 9px; }
.context-choice-list { display: grid; gap: 5px; }
.context-choice {
    width: 100%;
    min-width: 0;
    min-height: 64px;
    display: grid;
    grid-template-columns: 36px minmax(0, 1fr) auto 18px;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    color: var(--text-subtle);
    text-align: left;
    background: var(--surface);
    border: 1px solid transparent;
    border-radius: 11px;
}
.context-choice:hover { background: var(--surface-soft); border-color: var(--border); }
.context-choice.selected { background: var(--brand-soft); border-color: rgba(79, 70, 229, .18); }
.context-choice-icon { width: 36px; height: 36px; }
.context-choice.selected .context-choice-icon { color: #fff; background: var(--brand); }
.context-choice-copy { min-width: 0; }
.context-choice-copy strong,
.context-choice-copy small {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.context-choice-copy strong { color: var(--text); font-size: 11px; }
.context-choice-copy small { margin-top: 4px; color: var(--muted); font-size: 9px; }
.context-choice-meta {
    max-width: 90px;
    overflow: hidden;
    padding: 4px 7px;
    color: var(--muted-strong);
    font-size: 8px;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
    background: var(--surface-soft);
    border: 1px solid var(--border);
    border-radius: 999px;
}
.context-choice.selected .context-choice-meta { background: var(--surface); }
.context-choice-check { display: grid; place-items: center; color: var(--brand); }
.context-panel[aria-busy='true'] .context-choice-list { opacity: .55; pointer-events: none; }

.context-panel-foot {
    min-height: 43px;
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 10px 16px;
    color: var(--success);
    font-size: 9px;
    font-weight: 650;
    background: var(--success-soft);
    border-top: 1px solid color-mix(in srgb, var(--success) 12%, var(--border));
}

.context-loading { display: grid; gap: 9px; min-height: 180px; align-content: start; padding-top: 8px; }
.context-loading-line {
    height: 58px;
    background: linear-gradient(100deg, var(--surface-soft) 25%, #eef1f6 40%, var(--surface-soft) 55%);
    background-size: 220% 100%;
    border: 1px solid var(--border);
    border-radius: 11px;
    animation: context-loading 1.4s linear infinite;
}
.context-loading-line.short { width: 72%; }
.context-error,
.context-empty {
    min-height: 180px;
    display: grid;
    place-items: center;
    align-content: center;
    gap: 8px;
    padding: 22px;
    color: var(--muted);
    text-align: center;
}
.context-error > .icon { color: var(--danger); }
.context-error strong,
.context-empty strong { color: var(--text); font-size: 12px; }
.context-error p,
.context-empty p { max-width: 300px; margin: 0; font-size: 10px; line-height: 1.5; }
.context-error .secondary { margin-top: 5px; }

@keyframes context-panel-in {
    from { opacity: 0; transform: translateY(-5px) scale(.985); }
}
@keyframes context-loading {
    to { background-position-x: -220%; }
}

@media (max-width: 1040px) {
    .context-switcher { max-width: 270px; }
    .context-trigger {
        min-width: 190px;
        max-width: 270px;
        grid-template-columns: 34px minmax(0, 1fr) auto 16px;
    }
    .context-trigger-action { display: inline-flex; }
}

@media (max-width: 760px) {
    /* Keep the header opaque behind the mobile bottom sheet. */
    .top.has-context-switcher {
        background: var(--surface);
    }
    .top.has-context-switcher .top-leading { min-width: 0; }
    body.context-switcher-open { overflow: hidden; }
    .context-switcher {
        width: auto;
        min-width: 0;
        max-width: min(270px, calc(100vw - 174px));
        flex: 1 1 0;
    }
    .context-trigger {
        width: 100%;
        min-width: 0;
        max-width: none;
        min-height: 44px;
        grid-template-columns: 32px minmax(0, 1fr) auto 16px;
        padding-block: 5px;
    }
    .context-trigger-icon { width: 32px; height: 32px; }
    .context-backdrop { background: rgba(16, 24, 40, .52); backdrop-filter: blur(2px); }
    .context-panel {
        position: fixed;
        top: auto;
        right: 0;
        bottom: 0;
        left: 0;
        width: 100%;
        max-width: 100vw;
        height: min(82dvh, 720px);
        max-height: calc(100dvh - 8px - env(safe-area-inset-top, 0px));
        display: grid;
        grid-template-rows: auto minmax(0, 1fr) auto;
        border-width: 1px 0 0;
        border-radius: 20px 20px 0 0;
        animation-name: context-sheet-in;
    }
    .context-panel-body {
        min-width: 0;
        min-height: 0;
        max-height: none;
        overflow-x: hidden;
        overflow-y: auto;
        overscroll-behavior: contain;
        padding: 14px 16px 18px;
        -webkit-overflow-scrolling: touch;
    }
    .context-panel-foot {
        padding-bottom: max(10px, env(safe-area-inset-bottom, 0px));
    }
    .context-close {
        width: 44px;
        height: 44px;
    }
    .context-mode-tabs button { min-height: 44px; }
}

@media (max-width: 500px) {
    .context-switcher { max-width: calc(100vw - 122px); }
    .context-trigger {
        grid-template-columns: 30px minmax(0, 1fr) auto 14px;
        gap: 7px;
        padding-inline: 6px;
    }
    .context-trigger-icon { width: 30px; height: 30px; }
    .context-trigger-copy small { display: none; }
    .context-trigger-copy strong { margin: 0; font-size: 11px; }
    .context-choice { grid-template-columns: 36px minmax(0, 1fr) 18px; }
    .context-choice-meta { display: none; }
}

@media (max-width: 360px) {
    .context-trigger { grid-template-columns: 30px minmax(0, 1fr) 14px; }
    .context-trigger-copy { display: none; }
}

@keyframes context-sheet-in {
    from { opacity: 0; transform: translateY(28px); }
}

@media (prefers-reduced-motion: reduce) {
    .context-panel,
    .context-loading-line { animation: none; }
}
