@import url('../assets/css/party_style.css');

html.chat-initial-hidden #chatBox {
    max-height: 0 !important;
    opacity: 0 !important;
    padding: 0 !important;
    margin-top: 0 !important;
    margin-bottom: 0 !important;
    border: none !important;
    box-shadow: none !important;
    transition: none !important;
}


/* --- Chat Drawer (right side) --- */
body.chat-drawer-open {
    overflow: hidden;
}

.chat-drawer-button {
    position: fixed;
    right: 0;
    top: 40%;
    transform: translateY(-50%);
    z-index: 5000;

    width: 44px;
    height: 50px;

    display: flex;
    align-items: center;
    justify-content: center;

    background: linear-gradient(to bottom, #a08040, #c0a060, #a08040);
    border: 1px solid #6a5a4a;
    border-right: none;
    border-top-left-radius: 10px;
    border-bottom-left-radius: 10px;

    box-shadow: 0 0 10px rgba(0, 0, 0, 0.6);
    cursor: pointer;
    padding: 0;
    overflow: visible;

    /* Hide initially to prevent flicker */
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.1s ease, visibility 0.1s ease;

    /* Make size responsive to zoom */
    width: 3vw; /* 3% of viewport width */
    height: 3.5vw; /* 3.5% of viewport height */
    min-width: 35px; /* Minimum size */
    min-height: 40px; /* Minimum size */
    max-width: 55px; /* Maximum size */
    max-height: 65px; /* Maximum size */
}

/* Show after positioning is calculated */
.chat-drawer-button.positioned {
    opacity: 1;
    visibility: visible;
}

@media (min-width: 769px) {
    .container.chat-anchor {
        overflow: visible;
    }

    .container.chat-anchor::before {
        right: 0;
    }

    /* Desktop: stick the chat button to the main container's right edge (ne „map-shell“ kairysis) */
    .container.chat-anchor .chat-drawer-button:not(.map-shell-button) {
        position: fixed;
        top: 200px; /* Fixed position from viewport top */
        transform: translateY(0);

        width: 44px;
        height: 50px;
        min-width: 44px;
        min-height: 50px;
        max-width: 44px;
        max-height: 50px;

        border: 1px solid #6a5a4a;
        border-left: none;
        border-top-left-radius: 0;
        border-bottom-left-radius: 0;
        border-top-right-radius: 10px;
        border-bottom-right-radius: 10px;
        z-index: 6000;
    }
}

.chat-drawer-button:active {
    transform: translateY(-50%) scale(0.98);
}

.chat-drawer-button-icon {
    width: 25px;
    height: 25px;
    object-fit: contain;
    display: block;
    pointer-events: none;
}

.chat-unread-badge {
    position: absolute;
    z-index: 3;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    box-sizing: border-box;

    display: inline-flex;
    align-items: center;
    justify-content: center;

    color: #fff;
    border-radius: 999px;
    font-size: 10px;
    font-weight: bold;
    font-family: Arial, sans-serif;
    line-height: 1;
    pointer-events: none;
}

.chat-unread-badge.hidden {
    display: none;
}

/* Kairė viršus — Global (raudonas) */
.chat-unread-badge--global {
    top: 2px;
    left: 2px;
    background: #a03030;
    border: 1px solid #c04040;
}

/* Kairė apačia — Lokacija (žalias) */
.chat-unread-badge--location {
    bottom: 2px;
    left: 2px;
    background: #2a7a38;
    border: 1px solid #3a9a48;
}

/* Dešinė viršus — PM (mėlynas, ateityje) */
.chat-unread-badge--pm {
    top: 2px;
    right: 2px;
    background: #2a4a8a;
    border: 1px solid #3a62b0;
}

/* Dešinė apačia — Party (mėlynas) */
.chat-unread-badge--party {
    bottom: 2px;
    right: 2px;
    background: #1e5a9a;
    border: 1px solid #2a72c0;
}

.chat-drawer-overlay {
    position: fixed;
    inset: 0;
    z-index: 6000;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(2px);
}

.chat-drawer {
    position: fixed;
    top: 12px;
    bottom: 12px;
    right: 10px;
    z-index: 7000;

    height: calc(100vh - 24px);
    width: min(420px, 92vw);

    background: linear-gradient(180deg, rgba(38, 34, 29, 0.99), rgba(22, 22, 22, 0.99));
    border: 2px solid #6a5a4a;
    border-radius: 18px;
    box-shadow: -8px 0 25px rgba(0, 0, 0, 0.65), 0 0 18px rgba(192, 160, 96, 0.12);
    overflow: hidden;

    display: flex;
    flex-direction: column;

    box-sizing: border-box;
    padding-bottom: calc(env(safe-area-inset-bottom) + var(--chat-vv-offset, 0px));

    transform: translateX(0);
}

/* If JS provides a measured visualViewport height, prefer it (Android reliability) */
:root {
    --chat-vv-height: ;
}

.chat-drawer {
    height: calc(var(--chat-vv-height, 100vh) - 24px);
    max-height: calc(var(--chat-vv-height, 100vh) - 24px);
}

.chat-drawer.hidden {
    display: none !important;
}

.chat-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;

    padding: 12px 14px;
    border-bottom: 1px solid #6a5a4a;
    background: linear-gradient(180deg, rgba(62, 50, 36, 0.82), rgba(24, 22, 20, 0.72));
}

.chat-drawer-title {
    color: #c0a060;
    font-weight: bold;
    letter-spacing: 0.5px;
}

.chat-drawer-close {
    width: 34px;
    height: 34px;
    padding: 0;
    margin: 0;

    display: inline-flex;
    align-items: center;
    justify-content: center;

    background: #4a3a2a;
    color: #e0e0e0;
    border: 1px solid #6a5a4a;
    border-radius: 8px;
    cursor: pointer;
}

.chat-drawer-close:hover {
    background: #6a4a3a;
}

.chat-box--drawer {
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 10px 18px 12px 12px; /* extra right padding so it doesn't touch screen edge */
    box-sizing: border-box;
    background: transparent;
    border: none;
    box-shadow: none;
    flex: 1;

    display: flex;
    flex-direction: column;
    min-height: 0;
}

.chat-box--drawer .chat-messages {
    height: auto;
    flex: 1;
    min-height: 0;
    margin-bottom: 8px;
}

.chat-box--drawer .chat-input {
    width: 100%;
    flex: 0 0 auto;
}

@media (max-width: 768px) {
    .chat-drawer-button {
        top: 30%;
        width: 35px;
        height: 50px;
    }

    .chat-drawer {
        top: 8px;
        bottom: 8px;
        right: 6px;
        width: calc(100vw - 12px);
        height: calc(var(--chat-vv-height, 100svh) - 16px);
        max-height: calc(var(--chat-vv-height, 100svh) - 16px);
        border-radius: 16px;
    }
}

/* Chat Box Styles */
.chat-box {
    background: rgba(30, 30, 30, 0.9);
    padding: 0px;
    border-radius: 2px;
    border: 0px solid #4a4a4a;
    box-shadow: 0 0 0px rgba(0, 0, 0, 0.6);
    margin: 10px auto 10px 0px; /* Adjusted margin to push it to the left */
    width: 100%; /* Reduced width */
    max-width: 700px; /* Further increased max-width for chat box (horizontal) */
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: flex-start; /* Align children to the left */
    box-sizing: border-box; /* Ensure padding is included in the element's total width and height */
}

.chat-messages {
    height: 200px; /* Increased height for chat messages */
    overflow-y: auto; /* Enable scrolling for messages */
    border: 2px solid #6a5a4a;
    border-radius: 5px;
    padding: 5px; /* Consistent padding */
    background-color: #2a2a2a;
    display: flex;
    flex-direction: column;
    gap: 5px; /* Increased gap between messages */
    text-align: left;
    width: 100%; /* Ensure chat messages take full width */
    box-sizing: border-box; /* Ensure padding is included in the element's total width and height */
    line-height: 1.3em; /* Increased line height for better readability */
}

.chat-message {
    color: #e0e0e0;
    word-wrap: break-word; /* Legacy property */
    overflow-wrap: break-word; /* Modern equivalent for long words */
    font-size: 0.9em; /* Reduced font size */
    font-family: var(--player-font, Arial, sans-serif); /* Changed font to Arial */
    width: 100%; /* Ensure message takes full available width */
    box-sizing: border-box; /* Ensure padding is included in the element's total width and height */
    line-height: 1.3em; /* Increased line height for better readability */
    /* Grid: text column grows; time sits in narrow column, bottom-aligned = last message line */
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    column-gap: 8px;
    align-items: start;
}

.chat-message__body {
    grid-column: 1;
    grid-row: 1;
    min-width: 0;
    text-align: left;
}

.chat-message--unread {
    border-bottom: 1px solid rgba(192, 160, 96, 0.7);
    padding-bottom: 2px;
}

.chat-message--party-system .chat-message__body {
    grid-column: 1 / -1;
}

.chat-message__party-event {
    display: block;
    width: 100%;
    text-align: left;
    font-style: italic;
    color: #c8b890;
    font-size: 0.85em;
}

.chat-scroll-to-unread {
    width: 100%;
    margin: 0;
    padding: 4px 8px;

    display: flex;
    align-items: center;
    justify-content: center;

    background: rgba(20, 20, 20, 0.6);
    border: 1px solid #6a5a4a;
    border-radius: 8px 8px 0 0;
    color: #c0a060;
    font-size: 12px;
    font-weight: bold;
    letter-spacing: 0.3px;
    cursor: pointer;
}

.chat-scroll-to-unread:hover {
    background: rgba(40, 30, 20, 0.75);
}

.chat-scroll-to-unread:active {
    transform: translateY(1px);
}

.chat-message .username {
    font-weight: bold;
    color: #c0a060; /* Golden color for username */
    margin-right: 2px; /* Reduced right margin */
    font-family: var(--player-font, Arial, sans-serif); /* Ensure username also uses Arial */
}

.chat-input {
    display: flex;
    gap: 10px; /* Increased gap for more spacing between input and button */
    width: 95%; /* Ensure chat input takes full width */
}

.chat-input input[type="text"],
.chat-message-composer {
    flex-grow: 1;
    margin: 0px; /* Override default input margin */
    width: 95%; /* Allow flex-grow to manage width */
    max-width: calc(95% - 80px); /* Adjusted max width for input (button width + gap) to accommodate wider chat box */
}

.chat-message-composer {
    box-sizing: border-box;
    text-align: left;
    min-height: 38px;
    padding: 8px 10px;
    border: 1px solid #6a5a4a;
    border-radius: 5px;
    background-color: #2a2a2a;
    color: #e0e0e0;
    font: inherit;
    font-family: var(--player-font, Arial, sans-serif);
    line-height: 1.35;
    overflow-x: auto;
    overflow-y: hidden;
    white-space: pre-wrap;
    word-break: break-word;
    outline: none;
}

.chat-message-composer:focus {
    border-color: #c0a060;
    box-shadow: 0 0 0 1px rgba(192, 160, 96, 0.25);
}

.chat-message-composer.chat-composer--disabled {
    opacity: 0.65;
    pointer-events: none;
}

.chat-message-composer.is-composer-empty:not(:focus)::before {
    content: attr(data-placeholder);
    color: #888888;
    pointer-events: none;
}

.chat-composer-item-chip {
    font-weight: bold;
    user-select: none;
    display: inline;
}

.chat-message__text .lw-item-bracket,
.chat-composer-item-chip .lw-item-bracket {
    color: #ffffff;
    font-weight: bold;
}

.chat-message__text .lw-item-name.rarity-Common,
.chat-composer-item-chip .lw-item-name.rarity-Common { color: #a0a0a0; }
.chat-message__text .lw-item-name.rarity-Uncommon,
.chat-composer-item-chip .lw-item-name.rarity-Uncommon { color: #60a030; }
.chat-message__text .lw-item-name.rarity-Rare,
.chat-composer-item-chip .lw-item-name.rarity-Rare { color: #3060a0; }
.chat-message__text .lw-item-name.rarity-Epic,
.chat-composer-item-chip .lw-item-name.rarity-Epic { color: #a030a0; }
.chat-message__text .lw-item-name.rarity-Legendary,
.chat-composer-item-chip .lw-item-name.rarity-Legendary { color: #ff8000; }
.chat-message__text .lw-item-name.rarity-Mythic,
.chat-composer-item-chip .lw-item-name.rarity-Mythic { color: #ff0000; }

.chat-input button {
    /* Inherit styles from other buttons */
    display: block;
    width: 70px; /* Adjusted width for the button */
    padding: 10px 10px; /* Adjusted padding for better appearance */
    margin: 0px; /* Override default button margin */
    background: #4a3a2a; /* Dark brown/earthy tone for buttons */
    color: #e0e0e0;
    text-decoration: none;
    border-radius: 6px;
    border: 1px solid #6a5a4a; /* Button border */
    box-shadow: 0 3px 5px rgba(0,0,0,0.4); /* Button shadow */
    transition: background 0.3s ease, transform 0.2s ease;
    font-weight: bold;
    font-family: var(--player-font, 'Cinzel Decorative'), cursive, Arial, sans-serif;
    text-transform: uppercase;
    letter-spacing: 1px;
    cursor: pointer;
    font-size: 0.8em; /* Adjusted font size for chat button */
    flex-shrink: 0; /* Prevent button from shrinking */
}

.chat-input button:hover {
    background: #6a4a3a; /* Lighter brown on hover */
    transform: translateY(-2px); /* Slight lift effect */
    box-shadow: 0 5px 8px rgba(0,0,0,0.6);
}

.chat-input button:active {
    transform: translateY(0);
    box-shadow: 0 2px 3px rgba(0,0,0,0.4);
}

.chat-timestamp {
    grid-column: 2;
    grid-row: 1;
    align-self: end;
    font-size: 0.8em; /* Smaller font size */
    color: #888888; /* Gray color */
    white-space: nowrap;
    text-align: right;
    line-height: 1.3em;
}

/* Item reference: balti skliaustai, retumo spalva tik ant pavadinimo */
.chat-message__text .chat-item-link {
    background: none;
    border: none;
    padding: 0;
    margin: 0 2px;
    font: inherit;
    line-height: inherit;
    font-weight: bold;
    text-decoration: none;
    cursor: pointer;
    display: inline;
    vertical-align: baseline;
    color: inherit;
}

.chat-message__text .chat-item-link:hover,
.chat-message__text .chat-item-link:focus-visible {
    filter: brightness(1.12);
    outline: none;
}

/* Responsive adjustments for chat */
@media (max-width: 768px) {
    .chat-input button {
        width: 50px; /* Further reduced width for mobile button */
        padding: 6px 3px; /* Further adjust padding for smaller width */
        font-size: 0.8em; /* Further smaller font size for button text */
    }
    .chat-input input[type="text"],
    .chat-message-composer {
        flex-grow: 1; /* Allow input to take remaining space */
        width: auto; /* Reset width to allow flex-grow */
        max-width: calc(100% - 80px); /* Adjusted max width for input on mobile (button width + gap) */
    }
}

/* Chat Toggle and Wrapper Styles */
.chat-toggle-bar {
    display: flex;
    width: 50%;
    height: 13px;
    position: relative;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    background: linear-gradient(to right, #a08040, #c0a060, #a08040);
    border: 1px solid #6a5a4a;
    border-radius: 8px;
    box-shadow: 0 0 8px rgba(0, 0, 0, 0.5);
    margin: 20px auto;
}

.chat-toggle-bar::before,
.chat-toggle-bar::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 10px;
    height: 10px;
    background-color: #c0a060;
    border: 1px solid #6a5a4a;
    transform: translateY(-50%) rotate(45deg);
    box-shadow: 0 0 2px rgba(0,0,0,0.4);
    border-radius: 2px;
    z-index: 2;
}

.chat-toggle-bar::before {
    left: -5px;
}

.chat-toggle-bar::after {
    right: -5px;
}

.chat-toggle-icon {
    width: 25px;
    height: 25px;
    background: linear-gradient(to bottom right, #a08040, #e0c080, #a08040);
    border: 2px solid #6a5a4a;
    border-radius: 5px;
    color: #333333;
    font-size: 1.2em;
    font-weight: bold;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1;
    box-shadow: 0 0 8px rgba(0,0,0,0.6), inset 0 0 3px rgba(255,255,255,0.4);
    text-shadow: 1px 1px 1px rgba(0,0,0,0.4);
}

.chat-toggle-bar.active .chat-toggle-icon {
    background: linear-gradient(to bottom right, #60a030, #80c050, #60a030); /* Green gradient when active */
    border-color: #4a7a2a; /* Darker green border */
    box-shadow: 0 0 8px rgba(0,0,0,0.6), inset 0 0 3px rgba(255,255,255,0.4);
}

.chat-wrapper {
    max-height: 500px;
    overflow: hidden;
    transition: max-height 0.5s ease-out, opacity 0.5s ease-out;
    opacity: 1;
    position: relative;
    margin-top: 0;
    margin-bottom: 0;
    padding: 0;
}

.chat-wrapper.hidden {
    max-height: 0 !important;
    opacity: 0 !important;
    padding: 0;
    margin-top: 0;
    margin-bottom: 0;
    border: none;
    box-shadow: none;
}

.chat-wrapper.hidden .chat-box {
    display: none; /* Ensure content is not interactive when hidden */
}
