html, body {
    min-width: 310px;
}

body.chat-page {
    margin-bottom: 0;
    height: calc(var(--vh, 1vh) * 100);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding-bottom: 60px;
    box-sizing: border-box;
}

body.chat-page > .container {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding-bottom: 0;
}

body.chat-page main[role="main"] {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

#chatContent {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.toolbar {
    flex: 0 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 6px;
    flex-wrap: nowrap;
    margin-bottom: 6px;
}

.toolbar .btn {
    padding: clamp(4px, 1.5vw, 8px) clamp(6px, 2.5vw, 16px);
    font-size: clamp(11px, 3vw, 14px);
    white-space: nowrap;
}

.chat-layout {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 8px; 
}

.chat-main {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.messages-list {
    flex: 1 1 auto;
    height: auto;
    min-height: 0;
    overflow-y: scroll;
    border: 3px solid var(--teal-200);
    scrollbar-width: thin;
    scrollbar-color: var(--teal-400) var(--surface-2);
    border-radius: var(--notch);
    padding: 10px;
    background: var(--surface);
    background-size: cover;
    background-position: center;
    background-attachment: local;
    transition: background 0.3s ease;
}

.messages-list-wrapper {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
}

.custom-scrollbar-track {
    position: absolute;
    top: 6px;
    right: 4px;
    bottom: 6px;
    width: 4px;
    pointer-events: none;
    z-index: 10;
}

.custom-scrollbar-thumb {
    position: absolute;
    top: 0;
    right: 0;
    width: 4px;
    border-radius: 2px;
    background: var(--teal-400);
    opacity: 0.75;
    transition: opacity 0.15s;
}

.typing-indicator {
    flex: 0 0 auto;
    height: 20px;
    font-family: var(--font-m);
    font-style: normal;
    color: var(--text-3);
    font-size: 0.85em;
}

.input-row {
    flex: 0 0 auto;
    display: flex;
    gap: clamp(3px, 1vw, 5px);
    position: relative;
    flex-wrap: nowrap;
    align-items: center;
    min-width: 0;
}

.input-wrapper {
    position: relative;
    flex: 1 1 auto;
    min-width: 0;
}

#messageInput {
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
}

.input-row > .btn {
    flex: 0 0 auto;
    padding: clamp(4px, 1.5vw, 8px) clamp(6px, 2.5vw, 12px);
    font-size: clamp(11px, 3vw, 14px);
    white-space: nowrap;
}

.unstyled-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.app-toast {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    padding: 10px 16px;
    border-radius: 0 0 8px 8px;
    font-family: var(--font-b);
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(4, 52, 44, 0.15);
    max-width: calc(100vw - 20px);
    text-align: center;
}

.app-toast-success {
    background: var(--teal-50);
    color: var(--teal-800);
}

.app-toast-error {
    background: var(--coral-bg);
    color: var(--coral);
}

@keyframes slideDownFade {
    from {
        transform: translate(-50%, -100%);
        opacity: 0;
    }

    to {
        transform: translate(-50%, 0);
        opacity: 1;
    }
}

.app-toast.visa {
    animation: slideDownFade 0.3s ease-out forwards;
}

.mention-btn {
    display: inline-flex;
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 10;
}

.background-panel,
.online-panel {
    display: block;
    position: absolute;
    right: 0;
    left: auto;
    bottom: 45px;
    transform: none;
    z-index: 1000;
    background: var(--surface);
    border: 2px solid var(--teal-200);
    border-radius: var(--notch);
    box-shadow: 0 4px 16px rgba(4, 52, 44, 0.12);
}


.panel-label {
    font-family: var(--font-m);
    font-size: 11px;
    letter-spacing: .04em;
    text-transform: uppercase;
    font-weight: 500;
    color: var(--text-3);
    padding: 4px 8px;
}

.mention-item {
    padding: 6px 8px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    font-size: 13px;
    color: var(--text-1);
}

.mention-item:hover {
    background: var(--surface-2);
    border-radius: 6px;
}

.background-panel {
    display: block;
    position: absolute;
    bottom: 45px;
    right: 40px;
    z-index: 1000;
    background: var(--surface);
    border-radius: var(--notch);
    padding: 12px;
    width: fit-content;
}


.bakgrund-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
    gap: 6px;
    margin-top: 8px;
}

.bakgrund-thumb {
    height: 44px;
    border-radius: 6px;
    cursor: pointer;
    border: 2px solid var(--teal-200);
    transition: border-color 0.15s, transform 0.1s;
    background-size: cover;
    background-position: center;
}

.bakgrund-thumb:hover {
    transform: scale(1.06);
    border-color: var(--border-strong);
}

.bakgrund-thumb.vald {
    border-color: var(--teal-600);
}

.bakgrund-thumb.ingen {
    background: var(--surface-2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: var(--text-3);
}

.bakgrund-panel-rubrik {
    font-family: var(--font-m);
    font-size: 12px;
    letter-spacing: .03em;
    text-transform: uppercase;
    font-weight: 500;
    color: var(--text-3);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.bakgrund-panel-rubrik button {
    background: none;
    border: none;
    font-size: 16px;
    cursor: pointer;
    color: var(--text-3);
    line-height: 1;
    padding: 0;
}

.bakgrund-panel-rubrik button:hover {
    color: var(--text-2);
}

.emoji-picker-wrapper {
    display: block;
    position: absolute;
    bottom: 45px;
    left: auto;
    right: 0;
    transform: none;
    z-index: 1000;
    max-width: calc(100vw - 20px);
    overflow: hidden;
}

.emoji-picker-wrapper emoji-picker {
    --emoji-size: 1.1rem;
    --num-columns: 6;
    width: 280px;
    height: 220px;
    background: var(--surface);
    border: 2px solid var(--teal-200);
    border-radius: var(--notch);
    box-shadow: 0 4px 16px rgba(4, 52, 44, 0.12);
}

.online-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 0 10px;
}

.online-dot-wrapper {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--teal-50);
    border: 1.5px solid var(--teal-400);
    display: flex;
    align-items: center;
    justify-content: center;
}

.online-count-badge {
    background: var(--teal-400);
    color: #fff;
    font-family: var(--font-m);
    font-size: 10px;
    font-weight: 500;
    border-radius: 99px;
    padding: 1px 6px;
    line-height: 1.4;
}

.online-panel {
    padding: 10px 0;
    width: fit-content;
}

.online-panel-label {
    font-family: var(--font-m);
    font-size: 11px;
    font-weight: 500;
    color: var(--text-3);
    padding: 0 12px 6px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.online-list-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 12px;
    font-size: 13px;
    color: var(--text-1);
}

.online-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--teal-400);
    box-shadow: 0 0 0 3px var(--teal-50);
    flex-shrink: 0;
    display: inline-block;
}

.message-row {
    display: flex;
    justify-content: flex-start;
    align-items: flex-end;
    gap: 8px;
    margin-bottom: 8px;
}

.message-row--me {
    justify-content: flex-end;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
}

.message-avatar--img {
    object-fit: cover;
    overflow: hidden;
}

.message-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.message-avatar--fallback {
    background: var(--teal-100);
    color: var(--teal-800);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-d);
    font-size: 13px;
    font-weight: 600;
}

.message-wrapper {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    max-width: 85%;
}

.message-wrapper--me {
    align-items: flex-end;
}

.message-name {
    font-family: var(--font-m);
    font-size: 11px;
    margin-bottom: 3px;
    color: var(--text-3);
    font-weight: normal;
}

.message-name--admin {
    color: var(--coral);
    font-weight: 600;
}

.message-name--moderator {
    color: var(--teal-600);
    font-weight: 600;
}

.message-bubble {
    background: var(--surface);
    color: var(--text-1);
    border: 1px solid var(--border);
    padding: 8px 12px;
    border-radius: var(--bubble);
    word-break: break-word;
    font-family: var(--font-b);
}

.message-bubble--me {
    background: var(--teal-600);
    color: #fff;
    border: none;
    border-radius: var(--bubble-own);
}

.message-bubble--unread {
    outline: 2px solid var(--amber);
    background: var(--amber-bg) !important;
}

.bubble-row {
    display: flex;
    align-items: center;
    gap: 4px;
}

.bubble-action-btn {
    border: none;
    background: none;
    cursor: pointer;
    font-size: 12px;
    opacity: 0;
    transition: opacity 0.15s;
    padding: 2px;
    color: var(--text-2);
}

.bubble-row:hover .bubble-action-btn {
    opacity: 1;
}

.message-time {
    font-family: var(--font-m);
    font-size: 11px;
    color: var(--text-3);
    margin-top: 3px;
}

.blocked-overlay {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    font-family: var(--font-b);
    background: var(--bg);
    padding: 20px;
    text-align: center;
}

.blocked-overlay-inner {
    text-align: center;
    color: var(--text-2);
}
