/* Shared chat widget rules. The Minecraft page is the canonical source. */
.minecraft-chat-panel {
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.minecraft-chat-panel {
    --chat-widget-width: min(380px, calc(100vw - 32px));
    --chat-widget-min-width: 0;
    --chat-widget-max-height: min(620px, calc(100dvh - 96px));
    --chat-widget-radius: 14px;
    --chat-widget-bg: transparent;
    --chat-widget-border: 1px solid color-mix(in srgb, var(--handrive-border-soft) 88%, transparent);
    --chat-widget-shadow: 0 18px 42px rgba(15, 23, 42, 0.18), 0 4px 12px rgba(15, 23, 42, 0.1);
    --chat-header-bg: var(--shared-card-bg, #ffffff);
    --chat-header-color: var(--handrive-text-stronger);
    --chat-body-height: min(440px, calc(100dvh - 238px));
    --chat-surface-bg: color-mix(in srgb, var(--handrive-surface-muted) 72%, var(--shared-card-bg, #ffffff));
    --chat-bubble-bot-bg: var(--shared-card-bg, #ffffff);
    --chat-bubble-bot-color: var(--handrive-text-stronger);
    --chat-bubble-user-bg: var(--print-button-bg, #2f7d46);
    --chat-bubble-user-color: #ffffff;
    position: fixed;
    right: 16px;
    bottom: var(--minecraft-chat-bottom, 16px);
    z-index: var(--site-z-floating, 1000);
    width: var(--chat-widget-width);
    min-width: var(--chat-widget-min-width);
    max-width: calc(100vw - 32px);
    max-height: var(--chat-widget-max-height);
    flex: none;
    padding: 0;
    background: transparent;
    border: 0;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: var(--chat-widget-shadow);
    transition: width 180ms ease, max-height 220ms ease, border-radius 180ms ease, box-shadow 180ms ease;
}

/* The shared chat stylesheet hides generic chat widgets on ui pages. */
body.ui-page .minecraft-chat-panel.chat-widget {
    display: flex;
}

body.ui-page .minecraft-side-layout > .minecraft-chat-panel.chat-widget.is-open {
    width: var(--chat-widget-width);
    min-width: var(--chat-widget-min-width);
    max-width: calc(100vw - 32px);
    margin: 0;
}

.minecraft-chat-panel[hidden] {
    display: none;
}

.minecraft-chat-panel .chat-header {
    min-height: 54px;
    padding: 8px 8px 8px 12px;
    border-bottom: 1px solid var(--handrive-border-soft);
    cursor: default;
}

.minecraft-chat-panel .minecraft-chat-heading {
    display: inline-flex;
    align-items: center;
    min-width: 0;
    gap: 9px;
}

.minecraft-chat-panel .minecraft-chat-heading-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 32px;
    width: 32px;
    height: 32px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--chat-bubble-user-bg);
    cursor: pointer;
    font: inherit;
}

.minecraft-chat-panel .minecraft-chat-heading-icon {
    display: block;
    width: 32px;
    height: 32px;
    object-fit: contain;
}

.minecraft-chat-panel .minecraft-chat-heading-icon-unread {
    display: none;
}

.minecraft-chat-panel.has-unread-chat:not(.is-open) {
    animation: minecraft-chat-unread-shake 900ms ease-in-out infinite;
}

.minecraft-chat-panel.has-unread-chat:not(.is-open) .minecraft-chat-heading-icon-default {
    display: none;
}

.minecraft-chat-panel.has-unread-chat:not(.is-open) .minecraft-chat-heading-icon-unread {
    display: block;
}

@keyframes minecraft-chat-unread-shake {
    0%, 100% {
        transform: translateY(0);
    }
    20% {
        transform: translateY(-4px);
    }
    40% {
        transform: translateY(3px);
    }
    60% {
        transform: translateY(-3px);
    }
    80% {
        transform: translateY(2px);
    }
}

.minecraft-chat-panel .chat-header h3 {
    min-width: 0;
    margin: 0;
    overflow: hidden;
    font-size: 16px;
    font-weight: var(--site-weight-title-strong, 700);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.minecraft-chat-panel .minecraft-chat-header-meta {
    display: flex;
    align-items: center;
    min-width: 0;
    gap: 8px;
    margin-left: auto;
}

.minecraft-chat-status {
    min-width: 0;
    max-width: 150px;
    margin: 0;
    color: var(--handrive-text-muted);
    font-size: 11px;
    line-height: 1.3;
    text-align: right;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.minecraft-chat-status.is-error {
    color: #dc2626;
}

.minecraft-chat-empty {
    margin: auto;
    color: var(--handrive-text-muted);
    font-size: 13px;
    text-align: center;
}

.minecraft-chat-panel .chat-body {
    height: var(--chat-body-height);
    max-height: var(--chat-body-height);
    background: var(--chat-surface-bg);
}

.minecraft-chat-panel .minecraft-chat-messages {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    gap: 10px;
    min-height: 0;
    overflow: auto;
    padding: 12px;
    border: 0;
    border-radius: 0;
    background: var(--chat-surface-bg);
    overscroll-behavior: contain;
}

.minecraft-chat-message {
    display: grid;
    grid-template-columns: 40px minmax(0, 1fr);
    grid-template-areas: "avatar content";
    align-items: end;
    gap: 7px;
    width: fit-content;
    max-width: min(88%, 300px);
    min-width: 0;
    padding: 0;
    border: 0;
    background: transparent;
    box-shadow: none;
}

.minecraft-chat-date-separator {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    width: fit-content;
    max-width: 100%;
    margin: 4px auto;
    padding: 6px 10px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--handrive-border-soft) 42%, var(--chat-surface-bg));
    color: var(--handrive-text-muted);
    font-size: 12px;
    font-weight: 400;
    line-height: 1.3;
    text-align: center;
    white-space: nowrap;
}

.minecraft-chat-message.is-current-account {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "content";
    margin-left: auto;
}

.minecraft-chat-message.is-current-account.is-pending {
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas: "pending content";
    column-gap: 7px;
}

.minecraft-chat-message-pending-spinner {
    --site-loading-spinner-size: 16px;
    --site-loading-spinner-border-width: 2px;
    --site-loading-spinner-track: color-mix(in srgb, var(--handrive-text-muted) 28%, transparent);
    --site-loading-spinner-accent: var(--chat-bubble-user-bg);
    grid-area: pending;
    align-self: end;
    margin-bottom: 4px;
}

.minecraft-chat-message.is-current-account .minecraft-chat-message-avatar {
    display: none;
}

.minecraft-chat-message-avatar {
    grid-area: avatar;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    width: 40px;
    height: 40px;
    margin-bottom: 2px;
}

.minecraft-chat-message-avatar .minecraft-player-avatar-wrap {
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
    border: 0;
    border-radius: 0;
    background: color-mix(in srgb, var(--handrive-border-soft) 45%, transparent);
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.12);
}

.minecraft-chat-message-avatar .minecraft-player-avatar,
.minecraft-chat-message-avatar .minecraft-player-avatar-fallback {
    width: 100%;
    height: 100%;
    border-radius: 0;
}

.minecraft-chat-message-content {
    grid-area: content;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
        "meta meta"
        "text time";
    align-items: end;
    column-gap: 7px;
    row-gap: 2px;
    min-width: 0;
    width: fit-content;
    max-width: 100%;
    padding: 0;
    border: 0;
    background: transparent;
    box-shadow: none;
}

.minecraft-chat-message-meta {
    display: flex;
    align-items: baseline;
    grid-area: meta;
    min-width: 0;
    width: 100%;
    gap: 7px;
    margin: 0;
    padding: 0 4px;
    box-sizing: border-box;
}

.minecraft-chat-message-text {
    grid-area: text;
    max-width: 100%;
    margin: 0;
    padding: 4px 6px;
    border: 1px solid var(--handrive-border-soft);
    border-radius: 14px 14px 14px 4px;
    background: #f1f3f5;
    color: #000000;
    font-size: 13px;
    font-weight: 400;
    line-height: 1.45;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.06);
}

.minecraft-chat-message.is-current-account .minecraft-chat-message-text {
    border-color: color-mix(in srgb, var(--chat-bubble-user-bg) 58%, transparent);
    border-radius: 14px 14px 4px 14px;
    background: var(--chat-bubble-user-bg);
    color: var(--chat-bubble-user-color);
    box-shadow: 0 4px 10px color-mix(in srgb, var(--chat-bubble-user-bg) 22%, transparent);
}

.minecraft-chat-message-name {
    min-width: 0;
    overflow: hidden;
    color: var(--handrive-text-stronger);
    font-size: 12px;
    font-weight: 800;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.minecraft-chat-message-time {
    grid-area: time;
    align-self: end;
    margin: 0 0 2px;
    padding: 0;
    color: var(--handrive-text-muted);
    font-size: 10px;
    white-space: nowrap;
}

.minecraft-chat-message.is-current-account .minecraft-chat-message-name {
    display: none;
}

.minecraft-chat-message.is-current-account .minecraft-chat-message-content {
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas: "time text";
    column-gap: 7px;
    row-gap: 0;
}

.minecraft-chat-message.is-current-account .minecraft-chat-message-meta {
    display: none;
}

.minecraft-chat-message.is-current-account .minecraft-chat-message-time {
    margin: 0 0 2px;
}

.minecraft-chat-form {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 8px;
    margin-top: 0;
    padding: 10px;
    border-top: 1px solid var(--handrive-border-soft);
    background: var(--shared-card-bg, #ffffff);
}

.minecraft-chat-panel .minecraft-chat-input {
    flex: 1 1 auto;
    min-width: 0;
    margin: 0;
    width: 100%;
    height: 40px;
    padding: 0 12px;
    border: 1px solid var(--handrive-border-soft);
    border-radius: 12px;
    background: var(--shared-card-bg, #ffffff);
    color: var(--handrive-text-stronger);
    font-size: 13px;
    font-weight: 500;
    line-height: 40px;
    text-align: left;
    box-sizing: border-box;
    transition: border-color 140ms ease, box-shadow 140ms ease, background-color 140ms ease;
}

.minecraft-chat-panel .minecraft-chat-input::placeholder {
    color: var(--handrive-text-muted);
}

.minecraft-chat-panel .minecraft-chat-input:focus {
    border-color: color-mix(in srgb, var(--chat-bubble-user-bg) 60%, var(--handrive-border-soft));
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--chat-bubble-user-bg) 14%, transparent);
    outline: none;
}

.minecraft-chat-panel .minecraft-chat-send {
    flex: 0 0 40px;
    width: 40px;
    min-width: 40px;
    height: 40px;
    padding: 0;
    border: 0;
    border-radius: 12px;
    background: var(--chat-bubble-user-bg);
    color: #ffffff;
    box-shadow: none;
    transition: transform 140ms ease, background-color 140ms ease, opacity 140ms ease;
}

.minecraft-chat-panel .minecraft-chat-send:hover,
.minecraft-chat-panel .minecraft-chat-send:focus-visible {
    background: color-mix(in srgb, var(--chat-bubble-user-bg) 84%, #000000);
    transform: translateY(-1px);
    outline: none;
}

.minecraft-chat-panel .minecraft-chat-send:disabled {
    cursor: default;
    opacity: 0.6;
    transform: none;
}

.minecraft-chat-panel .minecraft-chat-send svg {
    display: none;
}

.minecraft-chat-panel .minecraft-chat-send::before {
    content: "";
    display: block;
    width: 28px;
    height: 28px;
    margin: auto;
    filter: brightness(0) invert(1);
    background: url("/static/media/icons/minecraft/chat-send.png") center / contain no-repeat;
}

.minecraft-chat-panel .chat-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 34px;
    width: 34px;
    height: 34px;
    padding: 0;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--chat-bubble-user-bg);
    cursor: pointer;
    transition: background-color 140ms ease, color 140ms ease;
}

.minecraft-chat-panel .chat-toggle:hover,
.minecraft-chat-panel .chat-toggle:focus-visible {
    background: transparent;
    outline: none;
}

.minecraft-chat-panel .minecraft-chat-toggle-icon {
    width: 32px;
    height: 32px;
    transition: transform 160ms ease;
}

.minecraft-chat-panel:not(.is-open) .minecraft-chat-toggle-icon {
    transform: rotate(180deg);
}

.minecraft-chat-panel:not(.is-open) {
    width: 54px;
    min-width: 54px;
    max-width: 54px;
    height: 54px;
    max-height: 54px;
    border-radius: 14px;
}

.minecraft-chat-panel:not(.is-open) .chat-header {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 54px;
    min-width: 54px;
    height: 54px;
    min-height: 54px;
    padding: 0;
    border-bottom: 0;
}

.minecraft-chat-panel:not(.is-open) .minecraft-chat-heading {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 54px;
    height: 54px;
    gap: 0;
}

.minecraft-chat-panel:not(.is-open) .minecraft-chat-heading-mark {
    flex: 0 0 54px;
    width: 54px;
    height: 54px;
    border-radius: 14px;
}

.minecraft-chat-panel:not(.is-open) .minecraft-chat-heading-icon {
    width: 32px;
    height: 32px;
}

.minecraft-chat-panel:not(.is-open) .minecraft-chat-heading h3,
.minecraft-chat-panel:not(.is-open) .minecraft-chat-header-meta {
    display: none;
}

.minecraft-chat-panel:not(.is-open) .chat-body {
    display: none;
}

.minecraft-chat-panel:not(.is-open) .minecraft-chat-status {
    display: none;
}

@media (max-width: 560px) {
    body.ui-page .minecraft-side-layout > .minecraft-chat-panel.chat-widget.is-open {
        right: 12px;
        left: 12px;
        width: auto;
        max-width: none;
        --chat-body-height: min(400px, calc(100dvh - 210px));
    }
}

@media (prefers-reduced-motion: reduce) {
    .minecraft-chat-panel,
    .minecraft-chat-panel .minecraft-chat-input,
    .minecraft-chat-panel .minecraft-chat-send,
    .minecraft-chat-panel .chat-toggle,
    .minecraft-chat-panel .minecraft-chat-toggle-icon,
    .minecraft-chat-panel.has-unread-chat:not(.is-open) {
        transition: none;
        animation: none;
    }
}

body.minecraft-page.theme-dark .minecraft-chat-panel {
    --chat-widget-bg: #242424;
    --chat-header-bg: #242424;
    --chat-header-color: #f0f0f0;
    --chat-surface-bg: #1d1d1d;
    --chat-bubble-bot-bg: #303030;
    --chat-bubble-bot-color: #f2f2f2;
    --chat-input-field-bg: #363636;
    --chat-input-field-color: #f0f0f0;
    --chat-input-field-border: rgba(255, 255, 255, 0.22);
    --chat-bubble-user-bg: #5c9d6d;
}

body.minecraft-page.theme-dark .minecraft-chat-panel .minecraft-chat-form {
    background: #242424;
}

body.minecraft-page.theme-dark .minecraft-chat-panel .minecraft-chat-input {
    background: #303030;
    color: #f0f0f0;
}

body.minecraft-page.theme-dark .minecraft-chat-panel .minecraft-chat-input::placeholder {
    color: #a8a8a8;
}

body.minecraft-page.theme-dark .minecraft-chat-panel .minecraft-chat-heading-icon {
    filter: brightness(0) invert(1);
}

body.minecraft-page.theme-dark .minecraft-chat-panel .minecraft-chat-toggle-icon {
    color: #ffffff;
}

body.minecraft-page.theme-dark .minecraft-chat-panel .minecraft-chat-message:not(.is-current-account) .minecraft-chat-message-text {
    background: #303030;
    color: #f2f2f2;
}

body.minecraft-page.theme-dark .minecraft-chat-panel .minecraft-chat-message-pending-spinner {
    --site-loading-spinner-track: rgba(255, 255, 255, 0.28);
    --site-loading-spinner-accent: #a7dfb4;
}

body.minecraft-page.theme-dark .minecraft-chat-panel .minecraft-chat-send {
    background: var(--chat-bubble-user-bg);
    color: #ffffff;
}

body.minecraft-page.theme-dark .minecraft-chat-panel .minecraft-chat-send:hover,
body.minecraft-page.theme-dark .minecraft-chat-panel .minecraft-chat-send:focus-visible {
    background: color-mix(in srgb, var(--chat-bubble-user-bg) 84%, #000000);
    color: #ffffff;
}

.minecraft-panel.minecraft-chat-panel.chat-widget {
    padding: 0;
    background: transparent;
    border: 0;
    outline: 0;
}

@media (max-width: 560px) {
    body.minecraft-page .minecraft-chat-panel.chat-widget.is-open {
        right: 12px;
        left: 12px;
        width: auto;
        max-width: none;
        --chat-body-height: min(400px, calc(100dvh - 210px));
    }
}
