/* ===========================================
   Pombo - Component Styles
   Extracted from inline styles for better maintainability
   =========================================== */

/* ----- Storage Slider ----- */
.storage-slider {
    -webkit-appearance: none;
    appearance: none;
    background: linear-gradient(to right, #F6851B 0%, #F6851B var(--slider-progress, 49.3%), rgba(255,255,255,0.1) var(--slider-progress, 49.3%), rgba(255,255,255,0.1) 100%);
}

.storage-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #F6851B;
    cursor: pointer;
    border: 2px solid #09090b;
    box-shadow: 0 2px 6px rgba(246, 133, 27, 0.4);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.storage-slider::-webkit-slider-thumb:hover {
    transform: scale(1.15);
    box-shadow: 0 2px 10px rgba(246, 133, 27, 0.6);
}

.storage-slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #F6851B;
    cursor: pointer;
    border: 2px solid #09090b;
    box-shadow: 0 2px 6px rgba(246, 133, 27, 0.4);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.storage-slider::-moz-range-thumb:hover {
    transform: scale(1.15);
    box-shadow: 0 2px 10px rgba(246, 133, 27, 0.6);
}

.storage-slider::-moz-range-track {
    background: transparent;
}

/* ----- Base Layout ----- */
html {
    background-color: #000000;
    color-scheme: dark;
}

/* PWA standalone mode - force true black */
@media (display-mode: standalone) {
    html, body {
        background-color: #000000 !important;
    }
}

body {
    font-family: 'Inter', sans-serif;
    background-color: #000000;
    color: rgba(255, 255, 255, 0.87);
    margin: 0;
    padding: env(safe-area-inset-top, 0px) 0 env(safe-area-inset-bottom, 0px) 0;
}

.app-container {
    height: calc(100vh - 3.5rem - env(safe-area-inset-top, 0px));
}

.chat-container {
    height: calc(100vh - 3.5rem - env(safe-area-inset-top, 0px));
}

.messages-area {
    height: calc(100% - 120px);
    background-color: #0f0f12;
}

/* ----- Message Styles ----- */
.message-entry {
    animation: fadeIn 0.3s ease-in-out;
    max-width: 60%;
    display: flex;
    flex-direction: row;
    align-items: flex-end;
    gap: 8px;
    position: relative;
    width: fit-content;
}

/* Only last/single messages get margin for avatar overhang (margin collapses with spacing system) */
.message-entry.msg-group-last,
.message-entry.msg-group-single {
    margin-bottom: 12px;
}

.own-message {
    margin-left: auto;
}

.other-message {
    margin-right: auto;
}

.message-bubble {
    padding: 0.2rem 0.7rem;
    position: relative;
    min-width: 0;
}

/* ----- Bubble Tail ----- */
.message-bubble::before {
    content: '';
    position: absolute;
    bottom: 0;
    width: 12px;
    height: 12px;
    background: inherit;
}

/* Tail for other-message (left side) */
.other-message .message-bubble::before {
    left: -5px;
    border-bottom-right-radius: 8px;
    clip-path: polygon(100% 0, 100% 100%, 0 100%);
}

/* Tail for own-message on mobile (right side) */
.own-message .message-bubble::before {
    right: -5px;
    border-bottom-left-radius: 8px;
    clip-path: polygon(0 0, 100% 100%, 0 100%);
}

/* Hide tail on first/middle messages (only show where avatar is visible) */
.msg-group-first .message-bubble::before,
.msg-group-middle .message-bubble::before {
    display: none;
}


/* ----- Message Grouping - Stack Effect ----- */

/* Single message (not grouped) - only bottom anchor sharp, top fully rounded */
.own-message.msg-group-single .message-bubble {
    background-color: #272a2e;
    color: #f0f0f0;
    border-radius: 1rem 1rem 0 1rem;
}

.other-message.msg-group-single .message-bubble {
    background-color: #1e1e1e;
    color: #d1d5db;
    border-radius: 1rem 1rem 1rem 0;
}

/* First message in group - top corners rounded, bottom-right small (connection) */
.own-message.msg-group-first .message-bubble {
    background-color: #272a2e;
    color: #f0f0f0;
    border-radius: 1rem 1rem 0.25rem 1rem;
}

.other-message.msg-group-first .message-bubble {
    background-color: #1e1e1e;
    color: #d1d5db;
    border-radius: 1rem 1rem 1rem 0.25rem;
}

/* Middle message in group - both right corners small (continuation) */
.own-message.msg-group-middle .message-bubble {
    background-color: #272a2e;
    color: #f0f0f0;
    border-radius: 1rem 0.25rem 0.25rem 1rem;
}

.other-message.msg-group-middle .message-bubble {
    background-color: #1e1e1e;
    color: #d1d5db;
    border-radius: 0.25rem 1rem 1rem 0.25rem;
}

/* Last message in group - bottom corner sharp (anchor) */
.own-message.msg-group-last .message-bubble {
    background-color: #272a2e;
    color: #f0f0f0;
    border-radius: 1rem 0.25rem 0 1rem;
}

.other-message.msg-group-last .message-bubble {
    background-color: #1e1e1e;
    color: #d1d5db;
    border-radius: 0.25rem 1rem 1rem 0;
}

/* Desktop: all messages aligned to left, same style as received */
@media (min-width: 768px) {
    .own-message {
        margin-left: 0;
        margin-right: auto;
        flex-direction: row;
    }
    
    /* Move avatar to left on desktop */
    .own-message .message-avatar {
        order: -1;
    }
    
    /* Flip bubble corners to left-anchor style */
    .own-message.msg-group-single .message-bubble {
        border-radius: 1rem 1rem 1rem 0;
    }
    
    .own-message.msg-group-first .message-bubble {
        border-radius: 1rem 1rem 1rem 0.25rem;
    }
    
    .own-message.msg-group-middle .message-bubble {
        border-radius: 0.25rem 1rem 1rem 0.25rem;
    }
    
    .own-message.msg-group-last .message-bubble {
        border-radius: 0.25rem 1rem 1rem 0;
    }
    
    /* Flip tail to left side for own-messages on desktop */
    .own-message .message-bubble::before {
        left: -5px;
        right: auto;
        border-bottom-right-radius: 8px;
        border-bottom-left-radius: 0;
        clip-path: polygon(100% 0, 100% 100%, 0 100%);
    }
    
    /* Hide mobile close button on desktop (use desktop button on right side) */
    .mobile-close-btn {
        display: none !important;
    }
    
    /* Hide mobile channel menu button (kebab) on desktop - use chevron */
    .mobile-channel-menu-btn {
        display: none !important;
    }
    
    /* Modal close buttons: show X on desktop, hide back arrow */
    .modal-close-btn .icon-back {
        display: none !important;
    }
    
    .modal-close-btn .icon-close {
        display: block !important;
    }
}

/* Tighter spacing within groups - using margin-top system instead */
.msg-group-first,
.msg-group-middle {
    margin-bottom: 0;
}

.msg-group-last,
.msg-group-single {
    margin-bottom: 12px;
}

/* ----- 3-level spacing system (margin-top) ----- */

/* Stack: same sender consecutive - tight (2-4px) */
.spacing-stack {
    margin-top: 0.125rem;
}

/* Ping-pong: alternating sides - medium (12-16px) */
.spacing-ping-pong {
    margin-top: 0.875rem;
}

/* Same side, different sender - larger (16-24px) */
.spacing-same-side {
    margin-top: 1.25rem;
}

/* Hide sender name in middle/last of group */
.msg-group-middle .message-sender-row,
.msg-group-last .message-sender-row {
    display: none;
}

/* ----- Message Avatars ----- */
.message-avatar {
    width: 46px;
    height: 46px;
    flex-shrink: 0;
    align-self: flex-end;
    border-radius: 10px;
    overflow: hidden;
    position: relative;
    top: 12px; /* Avatar hangs below the bubble ~50% */
    margin-top: -46px; /* Neutralize height in flex cross-axis */
}

.message-avatar svg {
    width: 100%;
    height: 100%;
    display: block;
}

.message-avatar.message-avatar-hidden {
    opacity: 0;
    height: 0;
    overflow: hidden;
    top: 0;
    margin-top: 0;
}

/* ----- Video & Image Message Styles ----- */
.message-entry[data-type="video_announce"] .message-bubble {
    padding: 0.25rem;
    background: transparent;
}

.message-entry[data-type="video_announce"] .message-content {
    font-size: inherit;
}

.message-entry[data-type="video_announce"].own-message .message-bubble,
.message-entry[data-type="video_announce"].other-message .message-bubble {
    background-color: transparent;
}

.message-entry[data-type="image"] .message-bubble {
    padding: 0.25rem;
    background: transparent;
}

.message-entry[data-type="image"].own-message .message-bubble,
.message-entry[data-type="image"].other-message .message-bubble {
    background-color: transparent;
}

.video-container {
    max-width: 480px;
}

/* ----- YouTube Embed ----- */
.youtube-embed {
    position: relative;
    width: 100%;
    max-width: 400px;
    aspect-ratio: 16 / 9;
    margin-top: 8px;
    border-radius: 12px;
    overflow: hidden;
    background: #09090b;
}

.youtube-embed iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: none;
    border-radius: 8px;
}

/* ----- Message Content ----- */
.message-content {
    font-size: 0.95rem;
    line-height: 1.4rem;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Inline emojis - slightly larger than text */
.message-content .inline-emoji {
    font-size: 1.2em;
    vertical-align: -0.15em;
    line-height: 1;
}

/* Emoji-only messages - larger emojis, no bubble */
.message-entry[data-emoji-only="true"] .message-bubble,
.message-entry[data-emoji-only="many"] .message-bubble {
    background: transparent !important;
    padding: 0.25rem 0.5rem;
}

.message-entry[data-emoji-only="true"] .message-content {
    font-size: 2.0rem;
    line-height: 1.3;
}

.message-entry[data-emoji-only="many"] .message-content {
    font-size: 1.6rem;
    line-height: 1.3;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Modal animation utilities */
.animate-fadeIn {
    animation: fadeIn 0.15s ease-out;
}

.animate-slideUp {
    animation: slideUp 0.2s ease-out;
}

/* Dropdown open/close animation */
@keyframes dropdownOpen {
    from {
        transform: scale(0.95) translateY(-4px);
    }
    to {
        transform: scale(1) translateY(0);
    }
}

@keyframes dropdownOpenUp {
    from {
        transform: scale(0.95) translateY(4px);
    }
    to {
        transform: scale(1) translateY(0);
    }
}

.dropdown-animate-open {
    animation: dropdownOpen 0.18s ease-out;
}

.dropdown-animate-open-up {
    animation: dropdownOpenUp 0.18s ease-out;
}

/* Thin scrollbar for modal lists */
.scrollbar-thin::-webkit-scrollbar {
    width: 3px;
}

.scrollbar-thin::-webkit-scrollbar-track {
    background: transparent;
}

.scrollbar-thin::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.12);
    border-radius: 3px;
}

/* Wallet selection indicator */
.wallet-item.selected .selected-dot {
    opacity: 1;
}

/* ----- Reactions ----- */
.reactions-container {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.message-footer {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 8px;
    margin-top: 0px;
}

.message-footer .message-time {
    flex-shrink: 0;
}

.reaction-badge {
    background-color: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.8);
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: background-color 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.reaction-badge .reaction-emoji {
    font-size: 1.6rem;
    line-height: 1;
    margin: -4px -2px;
    display: inline-block;
}

.reaction-badge:hover {
    background-color: rgba(255, 255, 255, 0.12);
}

.reaction-badge.user-reacted {
    background-color: rgba(246, 133, 27, 0.15);
}

/* ----- Message Actions ----- */
.react-trigger,
.reply-trigger {
    opacity: 0;
    transition: opacity 0.15s;
    cursor: pointer;
    color: rgba(255, 255, 255, 0.2);
    user-select: none;
    position: absolute;
    display: flex;
    align-items: center;
}

.react-trigger {
    bottom: 4px;
}

.reply-trigger {
    bottom: 28px;
}

.own-message .react-trigger,
.own-message .reply-trigger {
    left: -28px;
}

.other-message .react-trigger,
.other-message .reply-trigger {
    right: -28px;
}

/* Desktop: own-message buttons also on right (all messages left-aligned) */
@media (min-width: 768px) {
    .own-message .react-trigger,
    .own-message .reply-trigger {
        left: auto;
        right: -28px;
    }
}

.react-trigger svg,
.reply-trigger svg {
    display: block;
    width: 20px;
    height: 20px;
}

.message-bubble:hover .react-trigger,
.message-bubble:hover .reply-trigger {
    opacity: 1;
}

.react-trigger:hover,
.reply-trigger:hover {
    color: rgba(255, 255, 255, 0.5);
}

/* ----- Reply Preview ----- */
.reply-preview {
    background: rgba(255, 255, 255, 0.05);
    border-left: 2px solid rgba(255, 255, 255, 0.15);
    padding: 4px 8px;
    margin-bottom: 6px;
    border-radius: 6px;
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.5);
    cursor: pointer;
    max-width: 280px;
}

.reply-preview:hover {
    background: rgba(255, 255, 255, 0.08);
}

.reply-preview-name {
    color: rgba(255, 255, 255, 0.6);
    font-weight: 500;
    font-size: 0.75rem;
}

.reply-preview-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
    margin-top: 2px;
}

/* ----- Reply Bar ----- */
.reply-bar {
    background: rgba(255, 255, 255, 0.03);
    padding: 8px 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    display: none;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.reply-bar.active {
    display: flex;
}

.reply-bar-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    min-width: 0;
}

.reply-bar-label {
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.3);
}

.reply-bar-name {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.5);
    font-weight: 500;
}

.reply-bar-text {
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.6);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.reply-bar-close {
    cursor: pointer;
    color: rgba(255, 255, 255, 0.25);
    padding: 4px;
    border-radius: 6px;
    transition: all 0.15s;
}

.reply-bar-close:hover {
    color: rgba(255, 255, 255, 0.6);
    background: rgba(255, 255, 255, 0.08);
}

/* ----- Message Highlight ----- */
.message-highlight {
    animation: highlightPulse 1.5s ease-out;
}

@keyframes highlightPulse {
    0%, 100% {
        background: transparent;
    }
    30% {
        background: rgba(255, 255, 255, 0.1);
    }
}

/* ----- Date Separator ----- */
.date-separator {
    display: flex;
    justify-content: center;
    margin: 1rem 0;
}

.date-pill {
    background-color: rgba(255, 255, 255, 0.06);
    color: rgba(255, 255, 255, 0.4);
    font-size: 0.75rem;
    padding: 4px 12px;
    border-radius: 12px;
}

/* ----- Reaction Picker ----- */
.reaction-picker {
    position: fixed;
    background-color: #16161b;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 0.5rem;
    padding: 0.5rem;
    z-index: 100;
    display: none;
    flex-wrap: wrap;
    gap: 4px;
    max-width: 220px;
}

.reaction-picker span {
    cursor: pointer;
    font-size: 1.4rem;
    padding: 2px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.reaction-picker span:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

/* ----- Emoji Picker ----- */
.emoji-picker {
    position: absolute;
    bottom: 50px;
    left: 10px;
    background-color: #16161b;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 0.75rem;
    padding: 0.5rem;
    z-index: 10;
    display: none;
    flex-wrap: wrap;
    max-width: 320px;
    max-height: 200px;
    overflow-y: auto;
}

.emoji-picker span {
    cursor: pointer;
    margin: 2px;
    font-size: 1.4rem;
}

.emoji-picker span:hover {
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

/* ----- Typing Indicator ----- */
@keyframes bounce {
    0%, 80%, 100% {
        transform: scale(0);
    }
    40% {
        transform: scale(1.0);
    }
}

.typing-dot {
    width: 8px;
    height: 8px;
    background-color: rgba(255, 255, 255, 0.4);
    border-radius: 50%;
    display: inline-block;
    margin: 0 2px;
    animation: bounce 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(1) {
    animation-delay: -0.32s;
}

.typing-dot:nth-child(2) {
    animation-delay: -0.16s;
}

/* ----- Input Buttons ----- */
.input-button {
    background-color: rgba(255, 255, 255, 0.06);
    color: white;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 9999px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
    cursor: pointer;
}

.input-button:hover {
    background-color: rgba(255, 255, 255, 0.12);
}

/* ----- Send Button ----- */
#send-message-btn {
    background-color: transparent;
    color: #FF5C00;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 9999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background-color 0.12s, color 0.12s, transform 0.08s;
}

#send-message-btn svg {
    display: block;
}

#send-message-btn:hover {
    color: #FF7A33;
    background-color: rgba(255, 92, 0, 0.08);
}

#send-message-btn:active {
    transform: translateY(1px);
}

/* ----- Toast Notifications ----- */
.toast-container {
    position: fixed;
    top: 1.8rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    max-width: 380px;
    width: calc(100% - 2rem);
    pointer-events: none;
}

.toast {
    position: relative;
    padding: 0.875rem 1rem;
    border-radius: 0.75rem;
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.8125rem;
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    animation: toastSlideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    background-color: #16161b;
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4), 0 2px 8px rgba(0, 0, 0, 0.2);
    overflow: hidden;
    pointer-events: auto;
}

.toast-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    margin-top: 1px;
}

.toast-content {
    flex: 1;
    min-width: 0;
}

.toast-message {
    line-height: 1.4;
    word-break: break-word;
}

.toast-close {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255, 255, 255, 0.3);
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.15s;
    opacity: 0;
}

.toast:hover .toast-close {
    opacity: 1;
}

.toast-close:hover {
    color: rgba(255, 255, 255, 0.7);
    background: rgba(255, 255, 255, 0.1);
}

.toast-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 2px;
    background: rgba(255, 255, 255, 0.15);
    animation: toastProgress var(--toast-duration, 3000ms) linear forwards;
}

/* Toast variants */
.toast.success .toast-icon {
    color: #4ade80;
}

.toast.success .toast-progress {
    background: #4ade80;
}

.toast.error .toast-icon {
    color: #f87171;
}

.toast.error .toast-progress {
    background: #f87171;
}

.toast.info .toast-icon {
    color: #60a5fa;
}

.toast.info .toast-progress {
    background: #60a5fa;
}

.toast.warning .toast-icon {
    color: #fbbf24;
}

.toast.warning .toast-progress {
    background: #fbbf24;
}

.toast.invite {
    border-color: rgba(6, 182, 212, 0.3);
}

.toast.invite .toast-icon {
    color: #22d3ee;
}

.toast.invite .toast-progress {
    background: #22d3ee;
}

.toast.loading {
    border-color: rgba(255, 92, 0, 0.2);
}

.toast.loading .toast-icon {
    color: #ff5c00;
}

.toast.loading .toast-progress {
    background: linear-gradient(90deg, transparent, #ff5c00, transparent);
    width: 100% !important;
    animation: toastLoadingProgress 1.5s ease-in-out infinite;
}

.toast-exit {
    animation: toastSlideOut 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes toastSlideIn {
    from {
        opacity: 0;
        transform: translateY(-16px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes toastSlideOut {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(-16px);
    }
}

@keyframes toastProgress {
    from {
        width: 100%;
    }
    to {
        width: 0%;
    }
}

@keyframes toastLoadingProgress {
    0% {
        transform: translateX(-100%);
    }
    100% {
        transform: translateX(100%);
    }
}

/* ----- Toast Mobile Swipe Support ----- */
@media (max-width: 767px) {
    .toast {
        touch-action: pan-x;
        cursor: grab;
    }
    
    .toast.toast-swiping {
        transition: none !important;
        cursor: grabbing;
    }
    
    .toast:not(.toast-swiping) {
        transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), 
                    opacity 0.25s ease;
    }
    
    /* Minimized state - shows only right edge */
    .toast.toast-minimized {
        transform: translateX(calc(100% - 12px)) !important;
        opacity: 0.7;
        border-left: 3px solid currentColor;
    }
    
    .toast.toast-minimized.success {
        border-left-color: #4ade80;
    }
    
    .toast.toast-minimized.error {
        border-left-color: #f87171;
    }
    
    .toast.toast-minimized.loading {
        border-left-color: #ff5c00;
    }
    
    .toast.toast-minimized.invite {
        border-left-color: #22d3ee;
    }
    
    .toast.toast-minimized.info {
        border-left-color: #60a5fa;
    }
    
    .toast.toast-minimized.warning {
        border-left-color: #fbbf24;
    }
    
    /* Hide content when minimized */
    .toast.toast-minimized .toast-content,
    .toast.toast-minimized .toast-icon,
    .toast.toast-minimized .toast-close,
    .toast.toast-minimized .toast-progress {
        opacity: 0;
        pointer-events: none;
    }
    
    /* Show close button always on mobile */
    .toast .toast-close {
        opacity: 0.5;
    }
}

/* ----- Loading Spinner Overlay ----- */
.loading-overlay {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.7);
    z-index: 9998;
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 1rem;
}

.loading-overlay.active {
    display: flex;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(255, 255, 255, 0.08);
    border-top-color: #F6851B;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loading-text {
    color: rgba(255, 255, 255, 0.87);
    font-size: 0.9rem;
}

/* ----- Scrollbar ----- */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.02);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb {
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

/* ----- Online Users ----- */
.user-item {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    margin-bottom: 4px;
    font-size: 0.8rem;
}

#online-users-list::-webkit-scrollbar {
    width: 4px;
}

#online-users-list::-webkit-scrollbar-thumb {
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
}

.rotate-180 {
    transform: rotate(180deg);
}

/* ----- Custom Tooltip ----- */
.tooltip {
    position: relative;
    cursor: help;
}

.tooltip::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    background-color: #16161b;
    color: rgba(255, 255, 255, 0.6);
    font-size: 0.7rem;
    padding: 4px 8px;
    border-radius: 6px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s, visibility 0.15s;
    pointer-events: none;
    z-index: 100;
}

.tooltip::before {
    content: '';
    position: absolute;
    bottom: calc(100% + 2px);
    left: 50%;
    transform: translateX(-50%);
    border: 4px solid transparent;
    border-top-color: #16161b;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s, visibility 0.15s;
    pointer-events: none;
    z-index: 100;
}

.tooltip:hover::after,
.tooltip:hover::before {
    opacity: 1;
    visibility: visible;
}

/* ===========================================
   RESPONSIVE STYLES - Mobile & Tablet
   Desktop styles remain unchanged above
   =========================================== */

/* ----- Chat area visibility classes for mobile ----- */
.chat-area {
    transition: transform 0.3s ease, opacity 0.3s ease;
}

/* ===========================================
   TABLET (768px - 1023px)
   Split view with narrower sidebar
   =========================================== */
@media (max-width: 1023px) {
    /* Narrower sidebar on tablet */
    .sidebar {
        width: 280px;
    }
    

    
    /* Smaller logo */
    .header-logo {
        width: 2.5rem;
        height: 2.5rem;
    }
}

/* ----- Network status dot depth effect ----- */
.network-dot {
    box-shadow:
        inset 0 -1px 2px rgba(0, 0, 0, 0.4),
        inset 0 1px 1px rgba(255, 255, 255, 0.15),
        0 0 0 0 transparent;
}

.network-dot.bg-emerald-400 {
    box-shadow:
        inset 0 -1px 2px rgba(0, 0, 0, 0.3),
        inset 0 1px 1px rgba(255, 255, 255, 0.25),
        0 0 6px 1px rgba(52, 211, 153, 0.4);
}

.network-dot.bg-amber-400 {
    box-shadow:
        inset 0 -1px 2px rgba(0, 0, 0, 0.3),
        inset 0 1px 1px rgba(255, 255, 255, 0.25),
        0 0 6px 1px rgba(251, 191, 36, 0.4);
}

/* ----- Always hide mobile-only pill elements on desktop ----- */
#mobile-pill-nav,
#sidebar-connect-float {
    display: none !important;
}

/* ===========================================
   MOBILE (< 768px)
   Sidebar = initial view, Chat = push navigation
   =========================================== */
@media (max-width: 767px) {
    /* Force true black on mobile for Samsung/Android nav bar */
    html {
        background-color: #000000 !important;
    }
    
    /* Modal close buttons: show back arrow on mobile, hide X */
    .modal-close-btn .icon-back {
        display: block !important;
    }
    
    .modal-close-btn .icon-close {
        display: none !important;
    }
    
    /* Re-enable mobile pill elements (override desktop hiding) */
    #mobile-pill-nav:not(.hidden),
    #sidebar-connect-float:not(.hidden) {
        display: block !important;
    }
    /* Use dynamic viewport height for mobile browsers */
    body {
        height: 100dvh;
        touch-action: pan-y;
        overscroll-behavior-y: none;
    }
    
    .app-container {
        height: calc(100dvh - 3.5rem - env(safe-area-inset-top, 0px));
        position: relative;
        overflow: hidden;
    }
    
    /* Header adjustments */
    header {
        padding-left: 0.5rem;
        padding-right: 0.75rem;
        height: 3.5rem;
        background-color: #000000 !important;
        backdrop-filter: none;
    }
    
    /* Explore tabs take available space and align right on mobile */
    #explore-type-tabs {
        flex: 1 !important;
        justify-content: flex-end !important;
    }
    
    /* Smaller logo on mobile */
    .header-logo {
        width: 2.25rem;
        height: 2.25rem;
    }
    
    /* Hide wallet address text */
    #wallet-info {
        max-width: 80px;
        overflow: hidden;
        text-overflow: ellipsis;
        font-size: 0.75rem;
    }

    /* Hide header wallet controls on mobile (moved to pill nav) */
    #connect-wallet,
    #desktop-account-wrapper,
    #wallet-info {
        display: none !important;
    }

    /* Hide desktop-only sidebar controls (moved to pill nav) */
    #quick-join-row {
        display: none !important;
    }
    #new-channel-btn {
        display: none !important;
    }
    
    /* ----- SIDEBAR: Full screen initial view ----- */
    .sidebar {
        position: absolute;
        inset: 0;
        width: 100% !important;
        max-width: 100%;
        z-index: 30;
        border-right: none;
        transform: translateX(0);
        transition: transform 0.3s ease;
        background-color: #000000 !important;
    }

    /* Border override for mobile - more visible */
    .border-white\/\[0\.01\] {
        border-color: rgb(255 255 255 / 0.08) !important;
    }
    
    /* Hide sidebar when chat is open */
    .sidebar.chat-active {
        transform: translateX(-100%);
    }
    
    /* ----- CHAT AREA: Push navigation ----- */
    .chat-area {
        position: absolute;
        inset: 0;
        z-index: 20;
        transform: translateX(100%);
        background-color: #000000;
    }
    
    /* Show chat when active */
    .chat-area.active {
        transform: translateX(0);
        z-index: 35;
    }

    /* ----- UNIFIED DARK BACKGROUND ON MOBILE ----- */
    /* Match all backgrounds to true black for OLED screens */
    .messages-area {
        background-color: #000000 !important;
    }

    #chat-header {
        background-color: #000000 !important;
    }

    #message-input-container {
        background-color: #000000 !important;
    }

    /* Chat main area */
    #chat-area main {
        background-color: #000000 !important;
    }

    /* Explore view */
    .explore-view {
        background-color: #000000 !important;
    }

    /* Modal containers on mobile */
    #new-channel-modal > div,
    #settings-modal > div,
    #channel-settings-modal > div,
    #contacts-modal > div,
    #channel-types-modal > div,
    #storage-info-modal > div {
        background-color: #000000 !important;
    }

    /* Modal header bars (contacts header hidden on mobile, channel-settings visible) */
    #new-channel-modal > div > .flex.border-b,
    #channel-settings-modal > div > .flex.border-b {
        background-color: #000000 !important;
    }

    /* Modal tab strips / sidebars — bg set in horizontal tabs rule below */

    /* Modal footers and sidebars with #0a0a0a background */
    .bg-\[\#0a0a0a\] {
        background-color: #000000 !important;
    }

    /* Note: .bg-[#111113] NOT overridden - account modals (Unlock, Create, Import, etc.) keep #111113 */
    
    /* ----- HIDE MAIN HEADER WHEN CHAT IS ACTIVE ----- */
    /* Use explicit combinatorial rule so settings-open always wins */
    body.chat-open:not(.settings-open):not(.contacts-open) header {
        display: none !important;
    }
    
    body.chat-open .app-container {
        height: calc(100dvh - env(safe-area-inset-top, 0px));
    }
    
    /* ----- CLOSE BUTTON POSITIONING ----- */
    /* Show mobile close button (left side) on mobile */
    .mobile-close-btn {
        display: flex !important;
        margin-right: 0.5rem;
        margin-left: -0.5rem;
    }
    
    /* Hide desktop close button on mobile */
    .desktop-close-btn {
        display: none !important;
    }
    
    /* Hide desktop channel menu button (chevron) on mobile - use kebab */
    .desktop-channel-menu-btn {
        display: none !important;
    }
    
    /* Show mobile channel menu button (kebab) on mobile */
    .mobile-channel-menu-btn {
        display: flex !important;
    }
    
    /* ----- INPUT BUTTONS SMALLER ON MOBILE ----- */
    .input-btn-wrapper .input-button,
    .input-btn-wrapper.input-button {
        width: 2rem;
        height: 2rem;
    }
    
    .input-btn-wrapper .input-button svg,
    .input-btn-wrapper.input-button svg {
        width: 1.125rem;
        height: 1.125rem;
    }
    
    /* Hide disconnect button text on mobile */
    #disconnect-wallet span {
        display: none;
    }
    
    #disconnect-wallet {
        padding: 0.5rem;
    }
    
    /* OLD sidebar footer replaced by pill nav */

    /* Hide desktop sidebar footer on mobile */
    #sidebar-footer-desktop {
        display: none !important;
    }

    /* Hide pill and connect float when chat is open or new channel modal is visible */
    body.chat-open #mobile-pill-nav,
    body.chat-open #sidebar-connect-float,
    body.new-channel-open #mobile-pill-nav,
    body.new-channel-open #sidebar-connect-float {
        display: none !important;
    }

    /* ----- FLOATING CONNECT BUTTON (Guest mode) ----- */
    #sidebar-connect-float {
        position: fixed;
        bottom: 4.5rem;
        left: 50%;
        transform: translateX(-50%);
        z-index: 101;
    }

    /* ----- PILL NAVIGATION BAR ----- */
    #mobile-pill-nav {
        position: fixed;
        bottom: 2rem;
        left: 50%;
        transform: translateX(-50%);
        z-index: 100;
        padding-bottom: env(safe-area-inset-bottom);
    }

    .pill-nav-inner {
        display: flex;
        align-items: center;
        gap: 0.25rem;
        background: rgba(255, 255, 255, 0.06);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        border: 1px solid rgba(255, 255, 255, 0.08);
        border-radius: 2rem;
        padding: 0.35rem 0.5rem;
    }

    .pill-nav-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 0.125rem;
        padding: 0.4rem 0.75rem;
        border-radius: 1.5rem;
        font-size: 0.625rem;
        font-weight: 500;
        color: rgba(255, 255, 255, 0.8);
        transition: all 0.2s ease;
        cursor: pointer;
        background: none;
        border: none;
        position: relative;
    }

    .pill-nav-item:active {
        transform: scale(0.95);
    }

    .pill-nav-item.active {
        color: #F6851B;
        background: rgba(246, 133, 27, 0.12);
    }

    .pill-nav-item.active svg {
        stroke-width: 2;
    }

    /* ----- PROFILE AVATAR IN PILL ----- */
    .pill-profile-wrapper {
        padding: 0.25rem;
    }

    .pill-profile-avatar {
        width: 2rem;
        height: 2rem;
        border-radius: 10px;
        background: rgba(255, 255, 255, 0.08);
        border: 1.5px solid rgba(255, 255, 255, 0.12);
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        transition: all 0.2s ease;
        overflow: hidden;
    }

    .pill-profile-avatar:active {
        transform: scale(0.93);
    }

    .pill-profile-avatar img {
        width: 100%;
        height: 100%;
        object-fit: cover;
        border-radius: 50%;
    }

    /* ----- PROFILE DROPDOWN ----- */
    .pill-profile-dropdown {
        position: absolute;
        bottom: calc(100% + 0.5rem);
        right: 0;
        min-width: 200px;
        background: #16161b;
        border: 1px solid rgba(255, 255, 255, 0.1);
        border-radius: 1rem;
        padding: 0.5rem;
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
        z-index: 50;
        transform-origin: bottom right;
    }

    .pill-dropdown-address {
        padding: 0.5rem 0.75rem;
        font-size: 0.75rem;
        color: rgba(255, 255, 255, 0.4);
        font-family: monospace;
        border-bottom: 1px solid rgba(255, 255, 255, 0.06);
        margin-bottom: 0.25rem;
    }

    .pill-dropdown-accounts {
        max-height: 120px;
        overflow-y: auto;
    }

    .pill-dropdown-item {
        display: flex;
        align-items: center;
        gap: 0.5rem;
        width: 100%;
        padding: 0.5rem 0.75rem;
        border-radius: 0.5rem;
        font-size: 0.8125rem;
        color: rgba(255, 255, 255, 0.6);
        background: none;
        border: none;
        cursor: pointer;
        transition: background 0.15s ease;
        text-align: left;
    }

    .pill-dropdown-item:hover,
    .pill-dropdown-item:active {
        background: rgba(255, 255, 255, 0.06);
    }

    .pill-dropdown-disconnect {
        color: #ef4444;
        border-top: 1px solid rgba(255, 255, 255, 0.06);
        margin-top: 0.25rem;
        padding-top: 0.5rem;
    }
    
    /* Channel filter tabs - lighter on mobile */
    .channel-filter-tab {
        color: rgba(255, 255, 255, 0.75) !important;
    }

    .channel-filter-tab:hover {
        color: rgba(255, 255, 255, 0.9) !important;
    }

    /* Keep active tab orange (override Tailwind text-[#F6851B]) */
    .channel-filter-tab.text-\[\#F6851B\] {
        color: #F6851B !important;
    }

    /* Channel list items taller on mobile */
    #channel-list .channel-item {
        padding-top: 1rem;
        padding-bottom: 1rem;
        border-color: rgba(255, 255, 255, 0.05);
    }

    /* Bottom padding so list doesn't hide behind pill */
    #channel-list {
        padding-bottom: 5rem;
    }
    
    /* Chat header adjustments */
    #chat-header {
        padding: 0.75rem 1rem;
    }
    
    #current-channel-name {
        font-size: 1rem;
    }
    
    /* Messages take more width on mobile */
    .message-entry {
        max-width: 85%;
    }
    
    /* Smaller message avatars */
    .message-avatar {
        width: 36px;
        height: 36px;
        margin-top: -36px;
    }
    
    /* Message input area - flush at bottom */
    #message-input-container {
        padding: 0.75rem;
        padding-bottom: calc(0.75rem + env(safe-area-inset-bottom));
    }
    
    /* Safe area padding utility */
    .pb-safe {
        padding-bottom: env(safe-area-inset-bottom);
    }
    
    /* Messages container scrollable */
    #messages-container {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Video container smaller on mobile */
    .video-container {
        max-width: 100%;
    }
    
    /* Toast notifications full width */
    .toast-container {
        max-width: calc(100% - 1rem);
        left: 0.5rem;
        right: 0.5rem;
        transform: none;
    }
    
    /* Reply preview smaller */
    .reply-preview {
        max-width: 200px;
    }
    
    /* ----- FULLSCREEN MODALS ON MOBILE ----- */
    #new-channel-modal {
        padding: 0 !important;
    }

    /* ----- SETTINGS & CHANNEL DETAILS AS SLIDE-IN CONTAINER ON MOBILE ----- */
    #settings-modal,
    #channel-settings-modal {
        padding: 0 !important;
        background: transparent !important;
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
        align-items: stretch !important;
        justify-content: flex-end !important;
    }

    #settings-modal > div,
    #channel-settings-modal > div {
        transform: translateX(100%);
        transition: transform 0.3s ease;
        display: flex;
        flex-direction: column;
    }

    #settings-modal:not(.hidden) > div,
    #channel-settings-modal:not(.hidden) > div {
        transform: translateX(0);
    }

    /* Hide main header only for channel details */
    body.channel-details-open header {
        display: none !important;
    }

    body.channel-details-open .app-container {
        height: calc(100dvh - env(safe-area-inset-top, 0px));
    }

    /* Settings/Contacts modal: minimal bottom padding (pill is fixed, overlaps content) */
    body.settings-open #settings-modal,
    body.contacts-open #contacts-modal {
        padding-bottom: 0 !important;
    }

    /* Hide settings modal close button on mobile (pill replaces it), keep header for dots menu */
    #settings-modal #close-settings-btn {
        display: none !important;
    }
    #settings-modal > div > .flex.border-b {
        justify-content: flex-end !important;
        align-items: center !important;
        padding: 0.375rem 1rem !important;
    }

    /* No extra top spacing needed since header is visible */
    #settings-modal > div {
        padding-top: 0 !important;
    }

    /* Hide contacts modal header and close button on mobile */
    #contacts-modal > div > .flex.items-center.gap-2.mb-4 {
        display: none !important;
    }
    #close-contacts-btn {
        display: none !important;
    }

    /* Contacts modal full-screen on mobile */
    #contacts-modal {
        padding: 0 !important;
        background: transparent !important;
        backdrop-filter: none !important;
    }
    #contacts-modal > div {
        width: 100% !important;
        max-width: 100% !important;
        height: 100% !important;
        max-height: 100% !important;
        border-radius: 0 !important;
        margin: 0 !important;
        padding: 1rem 1.25rem 7rem 1.25rem !important;
        border: none !important;
    }
    
    #new-channel-modal > div,
    #settings-modal > div,
    #channel-settings-modal > div {
        width: 100% !important;
        max-width: 100% !important;
        height: 100% !important;
        max-height: 100% !important;
        border-radius: 0 !important;
        margin: 0 !important;
        border: none !important;
    }

    /* Modal headers - same dark color as main header */
    #new-channel-modal > div > .flex.border-b,
    #channel-settings-modal > div > .flex.border-b {
        border-color: rgba(255, 255, 255, 0.06) !important;
    }

    /* Settings modal content area - full height flex */
    #settings-modal .flex.min-h-\[420px\] {
        flex: 1 !important;
        min-height: 0 !important;
        height: 100% !important;
    }

    /* Settings panel content scrollable */
    #settings-modal .flex-1.p-6.overflow-y-auto {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
    }
    
    /* Modal sidebars become horizontal tabs on mobile */
    #new-channel-modal .flex.flex-1.min-h-0,
    #settings-modal .flex.min-h-\[420px\],
    #channel-settings-modal .flex.min-h-\[420px\] {
        flex-direction: column;
        flex: 1;
        min-height: 0;
        overflow: hidden;
    }

    /* Modal content panel - scrollable */
    #new-channel-modal .flex-1.p-5.overflow-y-auto {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
    }
    
    /* Modal sidebars horizontal on mobile */
    #new-channel-modal .w-40,
    #settings-modal .w-44,
    #channel-settings-modal .w-44 {
        width: 100% !important;
        border-right: none !important;
        border-bottom: 1px solid rgba(255, 255, 255, 0.06);
        flex-direction: row !important;
        overflow: hidden;
        padding: 0 !important;
        flex-shrink: 0;
        min-height: auto;
        background: #000000 !important;
    }

    /* Hide "Type" label on mobile modals */
    #new-channel-modal .w-40 > .px-3.mb-2 {
        display: none;
    }
    
    /* Modal nav items horizontal */
    #new-channel-modal .w-40 nav {
        display: flex !important;
        flex-direction: row !important;
        gap: 0.5rem;
        flex-wrap: nowrap;
        justify-content: center;
        width: 100%;
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }

    /* Settings & Channel Settings modal carousel - hide nav on mobile */
    #settings-modal .w-44 nav,
    #channel-settings-modal .w-44 nav {
        display: none !important;
    }

    /* Settings carousel - replaces nav on mobile */
    #settings-carousel,
    #channel-settings-carousel {
        display: flex !important;
        align-items: center;
        justify-content: center;
        width: 100%;
        padding: 0;
        margin: 0;
        gap: 0;
        background: rgba(255, 255, 255, 0.02);
        border-top: 1px solid rgba(255, 255, 255, 0.06);
        border-bottom: 1px solid rgba(255, 255, 255, 0.06);
        position: relative;
        box-sizing: border-box;
    }

    /* Remove the orange glow effects */
    #settings-carousel::before,
    #settings-carousel::after,
    #channel-settings-carousel::before,
    #channel-settings-carousel::after {
        display: none;
    }

    #settings-carousel .carousel-tabs,
    #channel-settings-carousel .carousel-tabs {
        display: grid;
        grid-template-columns: 1fr 1fr 1fr;
        width: 100%;
        margin: 0;
        padding: 0;
    }

    #settings-carousel .carousel-tab,
    #channel-settings-carousel .carousel-tab {
        padding: 0.875rem 0 0.75rem 0;
        margin: 0;
        font-size: 14px;
        font-weight: 500;
        text-transform: none;
        color: rgba(255, 255, 255, 0.6);
        transition: all 0.3s ease;
        white-space: nowrap;
        text-align: center;
        cursor: pointer;
        border-bottom: 2px solid transparent;
        box-sizing: border-box;
    }

    #settings-carousel .carousel-tab.active,
    #channel-settings-carousel .carousel-tab.active {
        color: white;
        font-weight: 500;
        cursor: default;
        border-bottom-color: #F6851B;
    }

    #settings-carousel .carousel-tab.adjacent,
    #channel-settings-carousel .carousel-tab.adjacent {
        visibility: hidden;
        pointer-events: none;
    }
    
    #new-channel-modal .w-40 nav button {
        white-space: nowrap;
        flex-shrink: 0;
        width: auto !important;
    }
}



/* ===========================================
   SMALL MOBILE (< 480px)
   =========================================== */
@media (max-width: 479px) {
    /* Even smaller header */
    header {
        height: 3rem;
        padding-left: 0.375rem;
        padding-right: 0.5rem;
    }
    
    .app-container {
        height: calc(100dvh - 3rem - env(safe-area-inset-top, 0px));
    }
    
    /* Hide connect button text */
    #connect-wallet span,
    #disconnect-wallet span {
        display: none;
    }
    
    #connect-wallet,
    #disconnect-wallet {
        padding: 0.5rem;
    }
    
    /* Messages even wider */
    .message-entry {
        max-width: 90%;
    }
    
    /* Smaller avatars */
    .message-avatar {
        width: 32px;
        height: 32px;
        margin-top: -32px;
    }
    
    /* Channel list items compact */
    #channel-list .channel-item {
        padding: 0.625rem 0.75rem;
    }
}

/* ===========================================
   TOUCH DEVICE OPTIMIZATIONS
   =========================================== */
@media (hover: none) and (pointer: coarse) {
    /* Larger touch targets */
    .input-button {
        width: 2.75rem;
        height: 2.75rem;
    }
    
    /* Hide message actions by default on touch - show only when tapped */
    .react-trigger,
    .reply-trigger {
        opacity: 0;
        pointer-events: none;
    }
    
    /* Show actions when message is active (tapped) */
    .message-entry.message-active .react-trigger,
    .message-entry.message-active .reply-trigger {
        opacity: 0.6;
        pointer-events: auto;
    }
    
    /* Larger reaction badges for touch */
    .reaction-badge {
        padding: 6px 12px;
        font-size: 0.875rem;
    }
    
    .reaction-badge .reaction-emoji {
        font-size: 1.5rem;
        margin: -6px -3px;
    }
    
    /* Bigger emoji picker items */
    .emoji-picker span,
    .reaction-picker span {
        font-size: 1.6rem;
        padding: 4px;
    }
}
