/* ==========================================
   Beta UI CSS - Dark/Light Theme + Icon Sets
   ========================================== */

/* ========================
   CSS Variables (Theme)
   ======================== */

:root {
    /* Dark theme (default) */
    --bg-primary: #0f0f0f;
    --bg-secondary: #1a1a1a;
    --bg-tertiary: #262626;
    --bg-input: #2a2a2a;
    --text-primary: #ffffff;
    --text-secondary: #a0a0a0;
    --text-muted: #666666;
    --text-placeholder: #888888;
    
    /* Accent - Amber/Orange */
    --accent-primary: #f59e0b;
    --accent-primary-hover: #d97706;
    --accent-secondary: #ea580c;
    --accent-glow: rgba(245, 158, 11, 0.25);
    --accent-glow-strong: rgba(245, 158, 11, 0.5);
    
    /* Semantic */
    --success: #22c55e;
    --danger: #ef4444;
    --danger-bg: rgba(239, 68, 68, 0.15);
    --online: #10b981;
    --unread: #f59e0b;
    
    /* Bubble */
    --bubble-own: linear-gradient(135deg, #f59e0b, #ea580c);
    --bubble-other: #262626;
    
    /* Border */
    --border-color: rgba(255, 255, 255, 0.08);
    --border-focus: rgba(245, 158, 11, 0.5);
    
    /* Shadows */
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 20px rgba(245, 158, 11, 0.2);
    
    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
    
    /* Border radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
}

/* Light theme */
[data-theme="light"] {
    --bg-primary: #f5f5f5;
    --bg-secondary: #ffffff;
    --bg-tertiary: #e8e8e8;
    --bg-input: #f0f0f0;
    --text-primary: #1a1a1a;
    --text-secondary: #555555;
    --text-muted: #888888;
    --text-placeholder: #aaaaaa;
    --border-color: rgba(0, 0, 0, 0.08);
    --border-focus: rgba(245, 158, 11, 0.4);
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
    --bubble-other: #e5e5e5;
}

/* ========================
   Base Styles
   ======================== */

/* Hide chat-app when login-screen is visible */
#login-screen:not(.hidden) ~ #chat-app,
#login-screen:not(.hidden) + #chat-app {
    display: none !important;
}

/* Ensure login-screen is always on top */
#login-screen {
    z-index: 9999 !important;
}

body {
    font-family: "SF Pro Display", "SF Pro Text", -apple-system, BlinkMacSystemFont, 
                 "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    margin: 0;
    padding: 0;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    letter-spacing: -0.01em;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior: none;
    touch-action: pan-y;
}

* {
    box-sizing: border-box;
}

::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--text-muted);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* ========================
   Icon Sets Visibility
   ======================== */

/* ========================
   Icon Sets Visibility
   ======================== */

/* Default: show Phosphor */
[data-icons="phosphor"] i.ph,
[data-icons="phosphor"] .ph { 
    display: inline-block !important; 
    width: 1em !important;
    height: 1em !important;
}
[data-icons="phosphor"] i.ti,
[data-icons="phosphor"] i.lucide,
[data-icons="phosphor"] .ti,
[data-icons="phosphor"] .lucide { 
    display: none !important; 
    visibility: hidden !important;
}

[data-icons="tabler"] i.ti,
[data-icons="tabler"] .ti { 
    display: inline-block !important; 
    width: 1em !important;
    height: 1em !important;
}
[data-icons="tabler"] i.ph,
[data-icons="tabler"] i.lucide,
[data-icons="tabler"] .ph,
[data-icons="tabler"] .lucide { 
    display: none !important; 
    visibility: hidden !important;
}

[data-icons="lucide"] i.lucide,
[data-icons="lucide"] .lucide { 
    display: inline-block !important; 
    width: 1em !important;
    height: 1em !important;
}
[data-icons="lucide"] i.ph,
[data-icons="lucide"] i.ti,
[data-icons="lucide"] .ph,
[data-icons="lucide"] .ti { 
    display: none !important; 
    visibility: hidden !important;
}

/* ========================
   Beta Components
   ======================== */

.beta-input {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    outline: none;
    transition: all var(--transition-fast);
}

.beta-input:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.beta-input::placeholder {
    color: var(--text-placeholder);
}

.beta-btn {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    color: #000;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.beta-btn:hover {
    filter: brightness(1.1);
    box-shadow: var(--shadow-glow);
}

.beta-btn:active {
    transform: scale(0.97);
}

.beta-secondary-btn {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-weight: 500;
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.beta-secondary-btn:hover {
    background: var(--bg-input);
}

.beta-secondary-btn:active {
    transform: scale(0.98);
}

.beta-danger-btn {
    background: var(--danger-bg);
    color: var(--danger);
    font-weight: 500;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.beta-danger-btn:hover {
    background: var(--danger);
    color: #fff;
}

.beta-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
}

/* ========================
   Avatar
   ======================== */

.avatar {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    color: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 18px;
    flex-shrink: 0;
    position: relative;
    box-shadow: var(--shadow-sm);
}

.avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: var(--radius-md);
}

.avatar-placeholder {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
}

/* Online/Offline dots */
.online-dot {
    position: absolute;
    bottom: -2px;
    right: -2px;
    width: 12px;
    height: 12px;
    background-color: var(--online);
    border: 2px solid var(--bg-primary);
    border-radius: 50%;
    animation: pulse-online 2s ease-in-out infinite;
}

@keyframes pulse-online {
    0%, 100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.5); }
    50% { box-shadow: 0 0 0 4px rgba(16, 185, 129, 0); }
}

/* ========================
   Header
   ======================== */

header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 30;
}

header .flex.items-center.gap-3 {
    cursor: pointer;
}

/* ========================
   Chat List
   ======================== */

.chat-item {
    display: flex;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.chat-item:hover {
    background: var(--bg-tertiary);
}

.chat-item:active {
    background: var(--bg-input);
}

.chat-item.unread {
    background: rgba(245, 158, 11, 0.12);
    border-left: 3px solid var(--unread);
    box-shadow: inset 0 0 20px rgba(245, 158, 11, 0.1);
}

.chat-info-left {
    margin-left: 12px;
    flex: 1;
    min-width: 0;
}

.chat-info-left .title {
    font-weight: 600;
    font-size: 16px;
    margin-bottom: 2px;
}

.chat-info-left .status-text {
    font-size: 13px;
    color: var(--text-secondary);
}

.chat-preview-right {
    text-align: right;
    flex-shrink: 0;
}

.chat-preview-right .time {
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 2px;
}

.chat-preview-right .preview-text {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 140px;
}

/* ========================
   Messages
   ======================== */

#messages {
    padding: 16px;
    padding-bottom: 100px;
}

.msg-group {
    display: flex;
    flex-direction: column;
    margin-bottom: 16px;
    position: relative;
}

.msg-group.own {
    align-items: flex-end;
}

.msg-group.other {
    align-items: flex-start;
}

.bubble {
    padding: 12px 16px;
    padding-bottom: 20px;
    font-size: 16px;
    line-height: 1.4;
    color: var(--text-primary);
    word-wrap: break-word;
    margin-bottom: 2px;
    position: relative;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    max-width: 80%;
    border: 1px solid var(--border-color);
    transition: all var(--transition-fast);
}

.msg-group.own .bubble {
    background: var(--bubble-own);
    color: #fff;
}

.msg-group.other .bubble {
    background: var(--bubble-other);
}

.msg-group.own .bubble:last-of-type {
    border-bottom-right-radius: var(--radius-lg);
}

.msg-group.other .bubble:last-of-type {
    border-bottom-left-radius: var(--radius-lg);
}

/* iPhone copy prevention */
.msg-group,
.message-reactions,
.reaction-bubble,
.reply-preview {
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    user-select: none;
    touch-action: manipulation;
}

.bubble.allow-copy {
    -webkit-user-select: text;
    user-select: text;
}

.timestamp-row {
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 2px;
    margin-left: 6px;
    margin-right: 6px;
}

/* ========================
   Reply Preview
   ======================== */

.reply-preview {
    display: flex;
    gap: 8px;
    padding: 8px 12px;
    margin: 4px 0;
    font-size: 13px;
    border-left: 3px solid var(--accent-primary);
    background: var(--bg-tertiary);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    max-width: 90%;
}

.msg-group.own .reply-preview {
    border-left: none;
    border-right: 3px solid var(--accent-primary);
    border-radius: var(--radius-sm) 0 0 var(--radius-sm);
}

.reply-preview-name {
    font-weight: 600;
    color: var(--accent-primary);
    font-size: 12px;
    margin-bottom: 2px;
}

.reply-preview-text {
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ========================
   Reactions
   ======================== */

.message-reactions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 4px;
}

.msg-group.other .message-reactions {
    justify-content: flex-start;
}

.msg-group.own .message-reactions {
    justify-content: flex-end;
}

.reaction-bubble {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 4px 8px;
    font-size: 12px;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.reaction-bubble:hover {
    transform: scale(1.1);
    background: var(--accent-glow);
}

.reaction-bubble.my-reaction {
    background: var(--accent-glow);
    border-color: var(--accent-primary);
}

/* ========================
   Typing Indicator
   ======================== */

.typing-indicator-container {
    display: flex;
    justify-content: flex-start;
    margin-bottom: 12px;
}

.typing-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: var(--bubble-other);
    border-radius: var(--radius-md);
    border-bottom-left-radius: 4px;
}

.typing-text {
    font-size: 13px;
    color: var(--text-secondary);
}

.typing-dots {
    display: flex;
    gap: 4px;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background: var(--accent-primary);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) { animation-delay: 0s; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-6px); }
}

/* ========================
   Bottom Navigation
   ======================== */

.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-around;
    padding: 12px 0;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    z-index: 40;
}

.nav-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px 20px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition-fast);
    border-radius: var(--radius-md);
}

.nav-btn:hover {
    background: var(--bg-tertiary);
}

.nav-btn.active {
    color: var(--accent-primary);
}

.nav-btn.active i {
    filter: drop-shadow(0 0 6px var(--accent-glow));
}

/* ========================
   Theme Toggle
   ======================== */

.theme-btn {
    background: var(--bg-tertiary) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border-color) !important;
    transition: all var(--transition-fast);
    cursor: pointer;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

.theme-btn:hover {
    background: var(--bg-input);
}

.theme-btn.active {
    background: var(--accent-glow);
    color: var(--accent-primary);
    border-color: var(--accent-primary);
}

/* ========================
   Icon Set Toggle
   ======================== */

.icon-btn {
    background: var(--bg-tertiary) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border-color) !important;
    transition: all var(--transition-fast);
    cursor: pointer;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

.icon-btn:hover {
    background: var(--bg-input);
}

.icon-btn.active {
    background: var(--accent-glow);
    color: var(--accent-primary);
    border-color: var(--accent-primary);
}

/* ========================
   Profile View
   ======================== */

#profile-view {
    background: var(--bg-primary);
}

#profile-view > div {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
}

#profile-view input.beta-input {
    background: var(--bg-input);
}

/* ========================
   Action Modal
   ======================== */

#action-modal {
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
}

#action-modal > div {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
}

#action-modal input.beta-input {
    background: var(--bg-input);
}

/* QR Reader */
#qr-reader-container {
    border-color: var(--accent-primary) !important;
}

/* ========================
   Chat View
   ======================== */

#chat-view {
    background: var(--bg-primary);
}

#chat-view > div:first-child {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
}

#chat-view > div:last-child {
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
}

#reply-bar {
    background: var(--bg-tertiary);
    border-top: 1px solid var(--border-color);
}

/* Progress bars */
#image-upload-progress-bar,
#upload-progress-bar {
    background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary));
}

/* ========================
   Context Menu
   ======================== */

.context-menu {
    position: absolute;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 8px;
    display: flex;
    gap: 8px;
    z-index: 100;
}

.context-btn {
    font-size: 20px;
    background: transparent;
    border: none;
    padding: 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--text-primary);
    transition: all var(--transition-fast);
}

.context-btn:hover {
    background: var(--bg-tertiary);
    color: var(--accent-primary);
}

/* ========================
   Reaction Picker
   ======================== */

.reaction-picker {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    z-index: 100;
}

.reaction-btn {
    font-size: 22px;
    background: transparent;
    border: none;
    padding: 4px 6px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.reaction-btn:hover {
    background: var(--bg-tertiary);
    transform: scale(1.2);
}

/* ========================
   Edit Mode
   ======================== */

.edit-textarea {
    background: var(--bg-input);
    border: 2px solid var(--accent-glow);
    border-radius: var(--radius-md);
    padding: 12px;
    color: var(--text-primary);
    font-size: 16px;
    line-height: 1.4;
    width: 100%;
    min-height: 60px;
    resize: none;
    font-family: inherit;
    outline: none;
}

.edit-textarea:focus {
    border-color: var(--accent-primary);
}

.edit-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    justify-content: flex-end;
}

.edit-save-btn {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    color: #000;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: none;
}

.edit-cancel-btn {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    cursor: pointer;
    border: 1px solid var(--border-color);
}

/* Deleted message */
.deleted-message {
    font-style: italic;
    color: var(--text-muted);
}

.deleted-bubble {
    opacity: 0.6;
}

/* Edited indicator */
.edited-indicator {
    font-size: 10px;
    color: var(--accent-primary);
    font-style: italic;
    margin-left: 4px;
}

/* ========================
   Image Modal
   ======================== */

#image-modal {
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(16px);
}

#image-modal img {
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
}

/* ========================
   Utilities
   ======================== */

.hidden {
    display: none !important;
}

.tab-content {
    height: 100%;
}

/* Safe area padding */
@supports (padding: max(0px)) {
    body {
        padding-bottom: max(0px, env(safe-area-inset-bottom));
    }
    
    #chat-view .p-4:last-child {
        padding-bottom: max(1rem, calc(1rem + env(safe-area-inset-bottom)));
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Touch devices */
@media (hover: none) and (pointer: coarse) {
    button,
    .chat-item,
    .avatar {
        min-height: 44px;
        min-width: 44px;
    }
}

/* Links in messages */
.bubble a {
    color: inherit;
    text-decoration: underline;
    text-decoration-color: var(--accent-primary);
}

.bubble a:hover {
    opacity: 0.8;
}

/* ========================
   Desktop Layout (min-width: 768px) - SIDENAV
   ======================== */

/* Hide mobile layout on desktop */
@media (min-width: 768px) {
    #mobile-layout {
        display: none !important;
    }
    
    #desktop-layout {
        display: flex !important;
    }
    
    /* Only show chat-app if login-screen is hidden */
    #login-screen.hidden ~ #chat-app,
    #chat-app:not(.hidden) {
        display: block !important;
    }
    
    /* Left sidebar */
    #left-sidebar {
        width: 280px;
        flex-shrink: 0;
        display: flex;
        flex-direction: column;
        background: var(--bg-secondary);
        border-right: 1px solid var(--border-color);
    }
    
    /* Main content area */
    #main-content {
        flex: 1;
        display: flex;
        flex-direction: column;
        overflow: visible;
        background: var(--bg-primary);
    }
    
    /* Desktop chat view */
    #desktop-chat-view {
        display: flex;
        flex-direction: column;
        min-height: 0;
        overflow: hidden;
    }
    
    /* Desktop messages container */
    #desktop-messages {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        min-height: 0;
    }
    
    /* Desktop nav items */
    .nav-section {
        margin-bottom: 8px;
    }
    
    .nav-section .nav-item {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 10px 16px;
        cursor: pointer;
        transition: all var(--transition-fast);
        border-radius: 0;
    }
    
    .nav-section .nav-item:hover {
        background: var(--bg-tertiary);
    }
    
    .nav-section .nav-item.active {
        background: var(--accent-glow);
        border-left: 3px solid var(--accent-primary);
    }
    
    /* Chat list item in desktop */
    .desktop-chat-item {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 12px 16px;
        cursor: pointer;
        transition: all var(--transition-fast);
    }
    
    .desktop-chat-item:hover {
        background: var(--bg-tertiary);
    }
    
    .desktop-chat-item.active {
        background: var(--accent-glow);
    }
    
    /* Info panel */
    #desktop-info-panel {
        width: 300px;
        flex-shrink: 0;
        background: var(--bg-secondary);
        border-left: 1px solid var(--border-color);
        display: none;
    }
    
    #desktop-info-panel.visible {
        display: block;
    }
}

/* Large desktop: 3 columns */
@media (min-width: 1200px) {
    #desktop-info-panel.visible {
        display: block;
    }
}

/* Mobile layout styles */
#mobile-layout {
    display: flex;
    flex-direction: column;
    height: 100%;
}

#desktop-layout {
    display: none;
}