/**
 * /assets/css/chat-sidebar.css
 *
 * Purpose:  Chat Sidebar Panel (rechts fixiert, Discord-Style)
 * Deps:     app.css (variables), sidebar-nav.css
 * Load:     index.php
 * Version:  1.5.0 – In-Character Chat + Dice→Chat Styling
 */

/* =========================
   CSS Variable
   ========================= */
:root {
    --chat-w: 340px;
    --chat-collapsed-w: 48px;
}

/* =========================
   Chat Toggle Button (always visible)
   ========================= */
.chat-toggle {
    position: fixed;
    bottom: 90px;
    right: 16px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 1px solid rgba(93,214,201,0.3);
    background: rgba(14,17,22,0.92);
    backdrop-filter: blur(12px) saturate(1.3);
    -webkit-backdrop-filter: blur(12px) saturate(1.3);
    color: var(--accent, #5dd6c9);
    font-size: 1.2rem;
    cursor: pointer;
    z-index: 10010;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(0,0,0,0.3);
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.chat-toggle:hover {
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 6px 24px rgba(93,214,201,0.2);
    background: rgba(14,17,22,0.98);
}

.chat-toggle__badge {
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    background: var(--danger, #ff6b6b);
    color: #fff;
    font-size: 0.6rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    line-height: 1;
}

/* =========================
   Chat Panel (right sidebar)
   ========================= */
.chat-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: var(--chat-w);
    max-width: 90vw;
    z-index: 10025;
    background: rgba(14,17,22,0.97);
    backdrop-filter: blur(24px) saturate(1.4);
    -webkit-backdrop-filter: blur(24px) saturate(1.4);
    border-left: 1px solid rgba(255,255,255,0.08);
    box-shadow: -4px 0 24px rgba(0,0,0,0.4);
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-panel.--open {
    transform: translateX(0);
}

/* =========================
   Chat Header
   ========================= */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    flex-shrink: 0;
}

.chat-header__title {
    font-size: 0.9rem;
    font-weight: 700;
    color: rgba(255,255,255,0.9);
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-header__title i {
    color: var(--accent, #5dd6c9);
}

.chat-header__actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.chat-header__btn {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: rgba(255,255,255,0.45);
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s, background 0.2s;
}

.chat-header__btn:hover {
    color: rgba(255,255,255,0.85);
    background: rgba(255,255,255,0.06);
}

/* =========================
   Room List
   ========================= */
.chat-rooms {
    flex: 1 1 auto;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.1) transparent;
}

.chat-rooms::-webkit-scrollbar {
    width: 4px;
}

.chat-rooms::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.1);
    border-radius: 2px;
}

.chat-rooms__empty {
    padding: 32px 16px;
    text-align: center;
    color: rgba(255,255,255,0.35);
    font-size: 0.85rem;
}

.chat-rooms__empty i {
    display: block;
    font-size: 2rem;
    margin-bottom: 8px;
    opacity: 0.4;
}

.chat-room-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    cursor: pointer;
    border-bottom: 1px solid rgba(255,255,255,0.03);
    transition: background 0.15s;
    text-decoration: none;
    color: inherit;
}

.chat-room-item:hover {
    background: rgba(255,255,255,0.04);
}

.chat-room-item.--active {
    background: rgba(93,214,201,0.08);
    border-left: 3px solid var(--accent, #5dd6c9);
}

.chat-room-item__avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 700;
}

.chat-room-item__avatar--group {
    background: rgba(93,214,201,0.15);
    color: var(--accent, #5dd6c9);
    border: 1px solid rgba(93,214,201,0.25);
}

.chat-room-item__avatar--direct {
    background: rgba(176,140,255,0.15);
    color: rgba(176,140,255,0.9);
    border: 1px solid rgba(176,140,255,0.25);
}

.chat-room-item__avatar--world {
    background: rgba(255,211,107,0.15);
    color: var(--gold, #ffd36b);
    border: 1px solid rgba(255,211,107,0.25);
}

.chat-room-item__avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.chat-room-item__info {
    flex: 1 1 auto;
    min-width: 0;
}

.chat-room-item__name {
    font-size: 0.8rem;
    font-weight: 600;
    color: rgba(255,255,255,0.85);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-room-item__preview {
    font-size: 0.7rem;
    color: rgba(255,255,255,0.4);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

.chat-room-item__meta {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
}

.chat-room-item__time {
    font-size: 0.6rem;
    color: rgba(255,255,255,0.3);
}

.chat-room-item__unread {
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    background: var(--accent, #5dd6c9);
    color: #0e1116;
    font-size: 0.6rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
}

/* =========================
   Chat View (Messages)
   ========================= */
.chat-view {
    display: none;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
}

.chat-view.--active {
    display: flex;
}

.chat-view__header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    flex-shrink: 0;
}

.chat-view__back {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: rgba(255,255,255,0.5);
    font-size: 0.9rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s, background 0.2s;
}

.chat-view__back:hover {
    color: rgba(255,255,255,0.85);
    background: rgba(255,255,255,0.06);
}

.chat-view__room-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: rgba(255,255,255,0.85);
    flex: 1 1 auto;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-messages {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.1) transparent;
}

.chat-messages::-webkit-scrollbar {
    width: 4px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.1);
    border-radius: 2px;
}

.chat-msg {
    max-width: 85%;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 0.8rem;
    line-height: 1.4;
    word-wrap: break-word;
}

.chat-msg.--mine {
    align-self: flex-end;
    background: rgba(93,214,201,0.15);
    border: 1px solid rgba(93,214,201,0.2);
    color: rgba(255,255,255,0.9);
    border-bottom-right-radius: 4px;
}

.chat-msg.--other {
    align-self: flex-start;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.08);
    color: rgba(255,255,255,0.85);
    border-bottom-left-radius: 4px;
}

.chat-msg.--system {
    align-self: center;
    max-width: 90%;
    background: rgba(255,211,107,0.08);
    border: 1px solid rgba(255,211,107,0.15);
    color: rgba(255,211,107,0.8);
    font-size: 0.72rem;
    font-style: italic;
    text-align: center;
    border-radius: 8px;
}

.chat-msg.--roll {
    align-self: center;
    max-width: 90%;
    background: rgba(176,140,255,0.1);
    border: 1px solid rgba(176,140,255,0.2);
    color: rgba(176,140,255,0.9);
    font-size: 0.75rem;
    text-align: center;
    border-radius: 8px;
}

.chat-msg.--emote {
    align-self: center;
    max-width: 90%;
    background: rgba(93,214,201,0.06);
    border: 1px solid rgba(93,214,201,0.12);
    color: rgba(93,214,201,0.8);
    font-size: 0.75rem;
    font-style: italic;
    text-align: center;
    border-radius: 8px;
}

.chat-msg__sender {
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--accent, #5dd6c9);
    margin-bottom: 2px;
}

.chat-msg__time {
    font-size: 0.55rem;
    color: rgba(255,255,255,0.25);
    margin-top: 3px;
    text-align: right;
}

/* =========================
   Chat Input
   ========================= */
.chat-input {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border-top: 1px solid rgba(255,255,255,0.08);
    flex-shrink: 0;
}

.chat-input__field {
    flex: 1 1 auto;
    border: 1px solid rgba(255,255,255,0.1);
    background: rgba(255,255,255,0.04);
    border-radius: 20px;
    padding: 8px 16px;
    font-size: 0.8rem;
    color: rgba(255,255,255,0.9);
    outline: none;
    transition: border-color 0.2s;
}

.chat-input__field::placeholder {
    color: rgba(255,255,255,0.3);
}

.chat-input__field:focus {
    border-color: rgba(93,214,201,0.4);
}

.chat-input__send {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: var(--accent, #5dd6c9);
    color: #0e1116;
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s, opacity 0.15s;
    flex-shrink: 0;
}

.chat-input__send:hover {
    transform: scale(1.08);
}

.chat-input__send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

/* =========================
   Messages Panel (in Profile Menu)
   ========================= */
.msg-panel {
    position: absolute;
    top: 100%;
    right: 0;
    width: 320px;
    max-height: 420px;
    background: rgba(20,25,35,.97);
    backdrop-filter: blur(12px) saturate(1.3);
    -webkit-backdrop-filter: blur(12px) saturate(1.3);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
    z-index: 1060;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.msg-panel__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}

.msg-panel__header-title {
    font-size: 0.8rem;
    font-weight: 700;
    color: rgba(255,255,255,0.9);
}

.msg-panel__header-btn {
    font-size: 0.65rem;
    color: rgba(255,255,255,0.4);
    border: none;
    background: none;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    transition: color 0.15s, background 0.15s;
}

.msg-panel__header-btn:hover {
    color: var(--accent, #5dd6c9);
    background: rgba(93,214,201,0.08);
}

.msg-panel__list {
    flex: 1 1 auto;
    overflow-y: auto;
    max-height: 340px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.1) transparent;
}

.msg-panel__list::-webkit-scrollbar {
    width: 4px;
}

.msg-panel__list::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.1);
    border-radius: 2px;
}

.msg-panel__empty {
    padding: 24px 16px;
    text-align: center;
    color: rgba(255,255,255,0.35);
    font-size: 0.8rem;
}

.msg-panel__footer {
    padding: 8px 14px;
    border-top: 1px solid rgba(255,255,255,0.06);
    text-align: center;
}

.msg-panel__footer-link {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--accent, #5dd6c9);
    text-decoration: none;
}

.msg-panel__footer-link:hover {
    text-decoration: underline;
    color: var(--accent, #5dd6c9);
}

.msg-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 14px;
    border-bottom: 1px solid rgba(255,255,255,0.03);
    cursor: pointer;
    transition: background 0.15s;
}

.msg-item:hover {
    background: rgba(255,255,255,0.04);
}

.msg-item.--unread {
    background: rgba(93,214,201,0.04);
    border-left: 3px solid var(--accent, #5dd6c9);
}

.msg-item__icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
}

.msg-item__icon--direct {
    background: rgba(176,140,255,0.15);
    color: rgba(176,140,255,0.9);
}

.msg-item__icon--invitation {
    background: rgba(255,211,107,0.15);
    color: var(--gold, #ffd36b);
}

.msg-item__icon--system {
    background: rgba(93,214,201,0.15);
    color: var(--accent, #5dd6c9);
}

.msg-item__icon--quest {
    background: rgba(255,107,107,0.15);
    color: var(--danger, #ff6b6b);
}

.msg-item__icon--event {
    background: rgba(100,149,237,0.15);
    color: rgba(100,149,237,0.9);
}

.msg-item__body {
    flex: 1 1 auto;
    min-width: 0;
}

.msg-item__subject {
    font-size: 0.75rem;
    font-weight: 600;
    color: rgba(255,255,255,0.85);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.msg-item__preview {
    font-size: 0.68rem;
    color: rgba(255,255,255,0.4);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

.msg-item__time {
    font-size: 0.6rem;
    color: rgba(255,255,255,0.25);
    margin-top: 2px;
}

/* =========================
   Sidebar mode adjustments
   ========================= */
@media (min-width: 992px) {
    body.sidebar-active .chat-toggle {
        bottom: 16px;
    }
}

/* =========================
   Mobile adjustments
   ========================= */
@media (max-width: 576px) {
    .chat-panel {
        width: 100vw;
        max-width: 100vw;
    }

    /* Chat-Input ueber die Tabbar heben */
    .chat-input {
        padding-bottom: calc(10px + var(--tabbarH, 72px) + var(--safeB, 0px));
    }

    .msg-panel {
        width: 260px;
    }
}

/* =========================
   Chat overlay (mobile backdrop)
   ========================= */
.chat-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 10020;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.chat-overlay.--visible {
    opacity: 1;
    pointer-events: auto;
}

/* =========================
   Image Preview Bar
   ========================= */
.chat-img-preview {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: rgba(30,35,50,0.95);
    border-top: 1px solid rgba(255,255,255,0.08);
}

.chat-img-preview__img {
    max-height: 64px;
    max-width: 120px;
    border-radius: 6px;
    object-fit: cover;
    border: 1px solid rgba(255,255,255,0.1);
}

.chat-img-preview__cancel {
    background: rgba(255,107,107,0.15);
    border: 1px solid rgba(255,107,107,0.3);
    color: var(--danger, #ff6b6b);
    border-radius: 50%;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.75rem;
    margin-left: auto;
    transition: background 0.2s;
}

.chat-img-preview__cancel:hover {
    background: rgba(255,107,107,0.3);
}

/* =========================
   Image Messages
   ========================= */
.chat-msg__image {
    max-width: 220px;
    max-height: 200px;
    border-radius: 8px;
    cursor: pointer;
    object-fit: cover;
    border: 1px solid rgba(255,255,255,0.08);
    transition: transform 0.2s, box-shadow 0.2s;
}

.chat-msg__image:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}

/* =========================
   Context Menu (Nachricht loeschen)
   ========================= */
.chat-context-menu {
    position: fixed;
    z-index: 10070;
    background: rgba(20,25,35,0.97);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.5);
    backdrop-filter: blur(12px);
    padding: 4px 0;
    min-width: 140px;
}

.chat-context-menu__item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 14px;
    background: none;
    border: none;
    color: var(--danger, #ff6b6b);
    font-size: 0.8rem;
    cursor: pointer;
    transition: background 0.15s;
}

.chat-context-menu__item:hover {
    background: rgba(255,107,107,0.1);
}

/* =========================
   Friends List in Modal
   ========================= */
.chat-friends-label {
    font-size: 0.7rem;
    color: rgba(255,255,255,0.4);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 4px;
    padding: 0 2px;
}

/* =========================
   @Mention Highlight in Messages
   ========================= */
.chat-mention {
    color: var(--accent, #5dd6c9);
    font-weight: 600;
    cursor: default;
}

/* =========================
   @Mention Autocomplete Dropdown
   ========================= */
.chat-mention-dropdown {
    position: relative;
    background: rgba(20,25,35,0.97);
    border: 1px solid rgba(255,255,255,0.1);
    border-bottom: none;
    border-radius: 8px 8px 0 0;
    max-height: 180px;
    overflow-y: auto;
    z-index: 10;
}

.chat-mention-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    font-size: 0.8rem;
    color: rgba(255,255,255,0.85);
    cursor: pointer;
    transition: background 0.12s;
}

.chat-mention-item:hover,
.chat-mention-item.--active {
    background: rgba(93,214,201,0.12);
}

.chat-mention-item strong {
    font-weight: 600;
    color: #fff;
}

/* =========================
   Block Button in Chat Header
   ========================= */
#chatBlockBtn {
    margin-left: auto;
    color: rgba(255,255,255,0.4);
    font-size: 0.8rem;
}

#chatBlockBtn:hover {
    color: var(--danger, #ff6b6b);
}

/* =========================
   In-Character Mode
   ========================= */
.chat-ic-picker {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.chat-ic-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid rgba(255,255,255,0.12);
    background: rgba(255,255,255,0.04);
    color: rgba(255,255,255,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.75rem;
    transition: all 0.15s;
    margin-right: 6px;
}

.chat-ic-btn:hover {
    border-color: rgba(155,89,182,0.4);
    color: #9b59b6;
    background: rgba(155,89,182,0.1);
}

.chat-ic-btn.--active {
    border-color: #9b59b6;
    color: #9b59b6;
    background: rgba(155,89,182,0.15);
    box-shadow: 0 0 8px rgba(155,89,182,0.3);
}

.chat-ic-dropdown {
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    background: rgba(15,15,25,0.97);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 10px;
    padding: 8px;
    z-index: 10;
    max-height: 200px;
    overflow-y: auto;
    margin-bottom: 4px;
}

.chat-ic-title {
    font-size: 0.65rem;
    color: rgba(255,255,255,0.4);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 4px 8px;
    margin-bottom: 4px;
}

.chat-ic-empty {
    font-size: 0.75rem;
    color: rgba(255,255,255,0.3);
    padding: 8px;
    text-align: center;
}

.chat-ic-option {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 6px 10px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: #fff;
    cursor: pointer;
    font-size: 0.78rem;
    transition: background 0.12s;
    text-align: left;
}

.chat-ic-option:hover {
    background: rgba(155,89,182,0.15);
}

.chat-ic-option--ooc:hover {
    background: rgba(255,255,255,0.08);
}

.chat-ic-group {
    margin-left: auto;
    font-size: 0.65rem;
    color: rgba(255,255,255,0.3);
}

.chat-ic-indicator {
    font-size: 0.7rem;
    color: #9b59b6;
    padding: 4px 10px;
    background: rgba(155,89,182,0.08);
    border-top: 1px solid rgba(155,89,182,0.15);
}

/* IC Message Styling */
.chat-msg.--ic {
    border-left: 2px solid rgba(155,89,182,0.4);
}

.chat-msg__sender--ic {
    color: #9b59b6 !important;
    font-weight: 600;
}

.chat-msg__ic-name {
    font-size: 0.7rem;
    font-weight: 600;
    margin-bottom: 2px;
}

/* Dice Roll Messages - Enhanced */
.chat-msg.--roll {
    border-left: 2px solid rgba(155,89,182,0.3);
}

/* =========================
   Reduced Motion
   ========================= */
@media (prefers-reduced-motion: reduce) {
    .chat-panel,
    .chat-toggle,
    .chat-overlay {
        transition: none;
    }

    .chat-toggle:hover {
        transform: none;
    }

    .chat-msg__image:hover {
        transform: none;
    }
}
