/*
 * Campaign Space shell and consultive navigation
 *
 * Ownership: docs/architecture/css-ownership.md
 * Loaded after custom.css and before surface-specific CSS.
 */

.chat-sidebar-toggle {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    border-radius: 999px;
    border: 1px solid rgba(120, 132, 220, 0.26);
    background: rgba(18, 20, 38, 0.82);
    color: var(--color-text-primary);
    transition: background var(--transition-fast), border-color var(--transition-fast), transform var(--transition-fast);
}

.chat-sidebar-toggle:hover {
    border-color: rgba(73,107,229,0.55);
    background: rgba(32, 36, 66, 0.92);
    transform: translateY(-1px);
}

.chat-sidebar {
    display: none !important; /* Forca display none por padrao */
    gap: 0;
    position: fixed;
    top: var(--dm-game-header-height, 68px);
    right: 0;
    width: min(1180px, calc(100vw - 88px));
    height: calc(100dvh - var(--dm-game-header-height, 68px));
    max-height: calc(100dvh - var(--dm-game-header-height, 68px));
    padding: 0;
    background:
        radial-gradient(circle at top left, rgba(218, 146, 88, 0.08), transparent 36%),
        #071013;
    border: 0;
    border-left: 1px solid rgba(118, 174, 164, 0.2);
    border-radius: 0;
    box-shadow: -28px 0 72px rgba(0, 0, 0, 0.42);
    overflow: hidden;
    z-index: 999;
}

.chat-sidebar.is-open {
    display: grid !important; /* So aparece quando explicitamente aberto */
}

.chat-consult-panel {
    grid-template-rows: auto auto minmax(0, 1fr);
}

.chat-consult-panel[data-consult-active-view="history"],
.chat-consult-panel[data-consult-active-view="gallery"] {
    width: min(1180px, calc(100vw - 88px));
}

.chat-campaign-space__header {
    align-items: center;
    min-height: 0;
}

.chat-campaign-space__heading {
    display: grid;
    gap: 4px;
    min-width: 0;
}

.chat-campaign-space__eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: #63aaa0;
    font-size: 0.7rem;
    font-weight: 800;
    text-transform: uppercase;
}

.chat-campaign-space__title {
    margin: 0;
    color: #edf2ec;
    font-family: Georgia, 'Times New Roman', serif;
    font-size: clamp(1.35rem, 2vw, 1.8rem);
    line-height: 1.2;
}

.chat-campaign-space__meta {
    margin: 0;
    color: #9eb0ad;
    font-size: 0.84rem;
    line-height: 1.45;
}

.chat-campaign-space__close {
    border-radius: 6px;
    padding: 8px 12px;
    min-width: auto;
    min-height: 44px;
    font-size: 0.82rem;
    gap: 8px;
    border: 1px solid rgba(118, 174, 164, 0.18);
    background: rgba(14, 27, 30, 0.58);
    color: #d8e7e2;
    justify-content: center;
    white-space: nowrap;
}

.chat-consult-panel__tabs {
    display: flex;
    flex-wrap: nowrap;
    gap: 6px;
    margin: 0;
    padding: 0 24px 12px;
    border-bottom: 1px solid rgba(118, 174, 164, 0.16);
    min-width: 0;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scroll-padding-inline: 24px;
    scrollbar-width: none;
}

.chat-consult-panel__tabs::-webkit-scrollbar {
    display: none;
}

.chat-consult-panel__tab {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: 1px solid transparent;
    border-bottom: 2px solid transparent;
    background: rgba(14, 27, 30, 0.22);
    color: #9eb0ad;
    border-radius: 6px 6px 0 0;
    padding: 8px 13px;
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
    min-height: 44px;
    flex: 0 0 auto;
    white-space: nowrap;
}

.chat-consult-panel__tab.is-active {
    border-color: rgba(118, 174, 164, 0.16);
    border-bottom-color: #da9258;
    background: rgba(14, 27, 30, 0.72);
    color: #edf2ec;
}

@media (min-width: 992px) and (hover: hover) and (pointer: fine) {
    .chat-consult-panel__tab:hover {
        border-bottom-color: #da9258;
        border-color: rgba(118, 174, 164, 0.16);
        background: rgba(14, 27, 30, 0.72);
        color: #edf2ec;
    }
}

.chat-consult-panel__tab:focus-visible {
    outline: 2px solid rgba(218, 146, 88, 0.75);
    outline-offset: 2px;
}

.chat-consult-view {
    display: grid;
    gap: 14px;
    min-height: 0;
    overflow: auto;
    padding: 20px 24px 28px;
    overscroll-behavior: contain;
}

.chat-campaign-space-shell__panel {
    width: 100%;
    height: auto;
    min-width: 0;
    margin: 0;
    border-radius: 6px;
    border: 1px solid rgba(118, 174, 164, 0.16);
    background: rgba(14, 27, 30, 0.5);
    box-shadow: none;
    overflow: hidden;
}

.chat-consult-panel[data-consult-active-view="history"] .chat-campaign-space-shell__panel {
    border-color: rgba(118, 174, 164, 0.12);
    background: rgba(7, 16, 19, 0.68);
}

.chat-campaign-space-shell__header {
    padding: 16px 18px;
}

.chat-sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--spacing-sm);
    padding: 14px 24px 10px;
    margin: 0;
    border-bottom: 0;
    position: relative;
    z-index: 10;
}

.chat-sidebar-close {
    background: rgba(18, 20, 38, 0.8);
    border: 1px solid rgba(120, 132, 220, 0.3);
    color: var(--color-text-primary);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 8px;
    min-width: 40px;
    min-height: 40px;
    border-radius: 50%;
    transition: all var(--transition-fast);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    z-index: 10;
}

.chat-sidebar-close:hover,
.chat-sidebar-close:focus-visible {
    color: var(--color-text-primary);
    background: rgba(73, 107, 229, 0.2);
    border-color: rgba(73, 107, 229, 0.5);
    transform: scale(1.05);
    outline: none;
}

.chat-sidebar-close:active {
    transform: scale(0.95);
}

.chat-sidebar-close.chat-campaign-space__close {
    border-radius: 6px;
    padding: 10px 14px;
}

.chat-sidebar-close.chat-campaign-space__close:hover,
.chat-sidebar-close.chat-campaign-space__close:focus-visible {
    background: rgba(21, 40, 42, 0.86);
    border-color: rgba(218, 146, 88, 0.58);
    color: #edf2ec;
    box-shadow: 0 0 0 3px rgba(218, 146, 88, 0.12);
    transform: none;
}

.chat-sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(3, 8, 10, 0.74);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-medium);
    z-index: 998;
    backdrop-filter: blur(3px);
    -webkit-tap-highlight-color: transparent;
}

.chat-sidebar-overlay.is-open {
    opacity: 1;
    pointer-events: auto;
    cursor: pointer;
}

.chat-action-bar {
    position: sticky;
    top: calc(var(--dm-game-header-height, 68px) + 16px);
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-top: 2px;
    z-index: 5;
}

.chat-action-bar__button {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 7px;
    width: 72px;
    min-height: 72px;
    padding: 8px 4px;
    border-radius: 6px;
    border: 1px solid transparent;
    background: transparent;
    color: #9eb0ad;
    font-size: 0.68rem;
    font-weight: 700;
    cursor: pointer;
    transition: border-color var(--transition-fast), background var(--transition-fast), transform var(--transition-fast);
}

.chat-action-bar__button i {
    font-size: 1rem;
    color: #63aaa0;
}

.chat-action-bar__button:hover,
.chat-action-bar__button.is-active {
    border-color: rgba(118, 174, 164, 0.22);
    background: #0e1b1e;
    color: #edf2ec;
}

.chat-action-bar__button span {
    line-height: 1.1;
}

/* No mobile, o overlay deve ser mais escuro e mais facil de clicar */
@media (max-width: 991px) {
    .chat-sidebar-overlay {
        background: rgba(6, 7, 16, 0.92);
        z-index: 998;
    }

    .chat-sidebar-overlay.is-open {
        cursor: pointer;
    }

    .chat-action-bar {
        display: none;
    }

    .chat-sidebar {
        top: var(--dm-game-header-height, 58px);
        right: 0;
        width: 100%;
        height: calc(100dvh - var(--dm-game-header-height, 58px));
        max-height: calc(100dvh - var(--dm-game-header-height, 58px));
        border-radius: 0;
        border-left: none;
        border-right: none;
        border-bottom: none;
        border-left: none;
        padding: 0;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        z-index: 999;
    }

    .chat-consult-panel {
        top: var(--dm-game-header-height, 58px);
        bottom: 0;
        height: calc(100dvh - var(--dm-game-header-height, 58px));
        max-height: calc(100dvh - var(--dm-game-header-height, 58px));
        width: 100%;
        left: 0;
        right: 0;
        border-radius: 0;
        border-left: none;
        border-right: none;
        border-bottom: none;
        padding: 0;
    }

    .chat-sidebar-header {
        position: sticky;
        top: 0;
        padding: 7px 12px 6px;
        margin: 0;
        background: rgba(7, 16, 19, 0.98);
        backdrop-filter: blur(10px);
        border-bottom: 0;
        flex-shrink: 0;
        padding-top: 8px;
        z-index: 1000;
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        gap: 12px;
        min-height: 48px;
    }

    .chat-campaign-space__header {
        align-items: center !important;
        flex-wrap: nowrap;
        gap: 12px;
    }

    .chat-campaign-space__heading {
        width: auto;
        flex: 1 1 auto;
        gap: 3px;
    }

    .chat-campaign-space__title {
        font-size: 1rem;
        overflow-wrap: anywhere;
    }

    .chat-campaign-space__meta {
        display: none;
    }

    .chat-consult-panel__tabs {
        padding: 0 8px 7px;
        flex: 0 0 auto;
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        scroll-padding-inline: 8px;
        margin-bottom: 0;
    }

    .chat-consult-panel__tab {
        flex: 0 0 auto;
        min-height: 44px;
        padding: 6px 10px;
        border-radius: 6px 6px 0 0;
        background: rgba(14, 27, 30, 0.34);
    }

    .chat-campaign-space-shell__panel {
        border-radius: 6px;
        height: 100%;
        min-height: 0;
        border-left: 1px solid rgba(120, 132, 220, 0.16);
        border-right: 1px solid rgba(120, 132, 220, 0.16);
        border-top: 1px solid rgba(120, 132, 220, 0.16);
    }

    .chat-consult-view {
        flex: 1 1 auto;
        min-height: 0;
        overflow: auto;
        padding: 12px 12px max(24px, env(safe-area-inset-bottom));
        -webkit-overflow-scrolling: touch;
    }

    .chat-campaign-space__close {
        align-self: center;
        width: auto;
        min-width: auto;
        min-height: 44px;
        padding: 8px 11px;
        font-size: 0.8rem;
        white-space: nowrap;
    }
}

@media (min-width: 992px) {
    .chat-sidebar {
        top: var(--dm-game-header-height, 68px);
        right: 0;
    }
}

@media (max-width: 420px) {
    .chat-campaign-space__eyebrow {
        font-size: 0.62rem;
    }

    .chat-campaign-space__title {
        font-size: 1rem;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .chat-campaign-space__close {
        padding: 8px 8px;
        font-size: 0.72rem;
    }
}
