/**
 * MumbleChat CSS Styles
 * Centralized styles for the entire application
 */

/* ===== Reset & Base ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #1b8cff;
    --primary-soft: #0f6bd7;
    --success: #33d69f;
    --error: #f43f5e;
    --warning: #f97316;
    --text: #e8f1ff;
    --text-secondary: #9fb4d6;
    --bg: #0c1729;
    --bg-panel: #0f1f34;
    --bg-card: #132842;
    --bg-soft: #1a3050;
    --border: rgba(255, 255, 255, 0.07);
    --shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: radial-gradient(circle at 20% 20%, rgba(29, 94, 255, 0.2), transparent 35%),
                radial-gradient(circle at 80% 0%, rgba(45, 212, 191, 0.12), transparent 30%),
                #0a1424;
    color: var(--text);
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
    overflow-y: auto;
}

/* Lock scroll only when app is loaded */
body.app-loaded {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

/* ===== Loading Screen ===== */
.loading-screen {
    height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    border-top-color: var(--primary);
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ===== App Container ===== */
.app-container {
    display: flex;
    height: 100vh;
    width: 100%;
    padding-bottom: 70px;
}

.main-view {
    width: 340px;
    background: linear-gradient(180deg, #0f1f34 0%, #0c1729 100%);
    border-right: 1px solid var(--border);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: linear-gradient(180deg, #0f1f34 0%, #0b1425 100%);
}

/* ===== Top Bar ===== */
.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 22px;
    border-bottom: 1px solid var(--border);
    background: rgba(15, 31, 52, 0.85);
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-logo {
    width: 44px;
    height: 44px;
    border-radius: 14px;
    background: radial-gradient(circle at 30% 30%, #2dd4bf, #1b8cff);
    display: grid;
    place-items: center;
    color: white;
    font-size: 22px;
    box-shadow: 0 12px 32px rgba(27, 140, 255, 0.35);
}

.brand-text h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
}

.brand-text p {
    margin: 0;
    color: var(--text-secondary);
    font-size: 12px;
}

/* ===== Empty State ===== */
.empty-state {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    text-align: center;
    color: var(--text-secondary);
    flex-direction: column;
    gap: 18px;
    padding: 20px;
}

.empty-icon {
    width: 160px;
    height: 160px;
    border-radius: 50%;
    background: radial-gradient(circle at 40% 40%, rgba(27, 140, 255, 0.35), rgba(0,0,0,0));
    display: grid;
    place-items: center;
    box-shadow: 0 20px 40px rgba(0,0,0,0.35);
}

.empty-icon span {
    font-size: 64px;
}

.empty-state h2 {
    font-size: 22px;
    margin: 0;
    color: var(--text);
}

.empty-state p {
    color: var(--text-secondary);
    margin-top: 6px;
    font-size: 14px;
}

.empty-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
}

/* ===== Buttons ===== */
.btn-primary {
    background: linear-gradient(135deg, #1b8cff, #4bc0c8);
    color: white;
    border: none;
    border-radius: 12px;
    padding: 12px 20px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 10px 28px rgba(27, 140, 255, 0.35);
    font-size: 14px;
    transition: transform 0.2s, opacity 0.2s;
}

.btn-primary:hover {
    transform: translateY(-2px);
    opacity: 0.95;
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 20px;
    font-weight: 600;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.2s;
}

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

.btn {
    padding: 10px 16px;
    border-radius: 10px;
    font-weight: 600;
    cursor: pointer;
    font-size: 14px;
    border: none;
    transition: opacity 0.2s;
}

.btn:hover {
    opacity: 0.9;
}

/* ===== Bottom Navigation ===== */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 70px;
    background: linear-gradient(180deg, #0a1424 0%, #050d16 100%);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: 1000;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.5);
    padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px 16px;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-secondary);
    border-radius: 12px;
    min-width: 60px;
    position: relative;
}

.nav-item.active {
    color: var(--success);
}

.nav-item.active::before {
    content: '';
    position: absolute;
    top: -2px;
    width: 32px;
    height: 3px;
    background: var(--success);
    border-radius: 0 0 3px 3px;
    box-shadow: 0 2px 8px rgba(51, 214, 159, 0.5);
}

.nav-item svg {
    width: 24px;
    height: 24px;
    stroke-width: 2;
}

.nav-item span {
    font-size: 11px;
    font-weight: 600;
}

.nav-item:active {
    transform: scale(0.95);
}

/* ===== Sidebar (Contacts Panel) ===== */
.sidebar {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.sidebar-header {
    flex-shrink: 0;
    padding: 16px;
    border-bottom: 1px solid var(--border);
}

.header-top {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-top h1 {
    font-size: 20px;
    font-weight: 700;
    margin: 0;
    flex: 1;
}

.header-btn {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    transition: background 0.2s;
}

.header-btn:hover {
    background: var(--bg-soft);
}

.back-arrow {
    color: var(--text);
    text-decoration: none;
    font-size: 20px;
    padding: 4px 8px;
    border-radius: 8px;
    transition: background 0.2s;
}

.back-arrow:hover {
    background: var(--bg-soft);
}

.search-container {
    padding: 10px 16px;
    flex-shrink: 0;
}

.search-box {
    width: 100%;
    padding: 10px 14px;
    background: rgba(15, 31, 52, 0.8);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    font-size: 14px;
}

.search-box::placeholder {
    color: var(--text-secondary);
}

/* ===== Contacts List - SCROLLABLE ===== */
.contacts-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0;
}

.contact-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    transition: background 0.15s;
    border-bottom: 1px solid rgba(255,255,255,0.03);
}

.contact-item:hover {
    background: var(--bg-soft);
}

.contact-item.active {
    background: rgba(27, 140, 255, 0.15);
    border-left: 3px solid var(--primary);
}

.contact-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: white;
    font-size: 16px;
    flex-shrink: 0;
    position: relative;
}

.contact-avatar .online-dot {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 12px;
    height: 12px;
    background: var(--success);
    border-radius: 50%;
    border: 2px solid var(--bg-panel);
}

.contact-info {
    flex: 1;
    min-width: 0;
}

.contact-name {
    font-weight: 600;
    font-size: 14px;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.contact-preview {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

.contact-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    flex-shrink: 0;
}

.contact-time {
    font-size: 11px;
    color: var(--text-secondary);
}

.unread-badge {
    background: var(--primary);
    color: white;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 10px;
    min-width: 20px;
    text-align: center;
}

.muted-icon {
    font-size: 12px;
}

.empty-contacts {
    padding: 40px 20px;
    text-align: center;
    color: var(--text-secondary);
}

.empty-contacts .hint {
    font-size: 12px;
    margin-top: 8px;
    opacity: 0.7;
}

/* ===== Sidebar Status Bar (inside main-view) ===== */
.sidebar-status-bar {
    padding: 10px 16px;
    background: rgba(10, 20, 36, 0.95);
    border-top: 1px solid var(--border);
    font-size: 11px;
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex-shrink: 0;
}

/* Old fixed status bar - HIDDEN */
.status-bar {
    display: none !important;
}

.status-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #53607a;
    box-shadow: 0 0 0 2px rgba(83,96,122,0.25);
}

.status-dot.connected {
    background: var(--success);
    box-shadow: 0 0 0 2px rgba(51,214,159,0.25);
}

/* ===== Badge ===== */
.badge-pill {
    background: rgba(27, 140, 255, 0.15);
    color: #7fc2ff;
    border: 1px solid rgba(27, 140, 255, 0.3);
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 600;
}

/* ===== Modal ===== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 0;
    transition: opacity 0.3s;
    backdrop-filter: blur(4px);
}

.modal-overlay.show {
    opacity: 1;
}

.modal-dialog {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0,0,0,0.6);
    transform: scale(0.9);
    transition: transform 0.3s;
}

.modal-overlay.show .modal-dialog {
    transform: scale(1);
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h3 {
    margin: 0;
    font-size: 18px;
}

.modal-close {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: none;
    border: none;
    color: var(--text);
    font-size: 24px;
    cursor: pointer;
    transition: background 0.2s;
}

.modal-close:hover {
    background: var(--bg-soft);
}

.modal-content {
    padding: 20px;
    max-height: 60vh;
    overflow-y: auto;
}

.modal-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

/* ===== Toast Notification ===== */
.toast-notification {
    position: fixed;
    top: 20px;
    right: 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px 20px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
    z-index: 3000;
    transform: translateX(400px);
    transition: transform 0.3s;
    max-width: 350px;
}

.toast-notification.show {
    transform: translateX(0);
}

.toast-success {
    border-left: 4px solid var(--success);
}

.toast-error {
    border-left: 4px solid var(--error);
}

.toast-warning {
    border-left: 4px solid var(--warning);
}

.toast-info {
    border-left: 4px solid var(--primary);
}

/* ===== Loading Overlay ===== */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    z-index: 2500;
    opacity: 0;
    transition: opacity 0.3s;
}

.loading-overlay.show {
    opacity: 1;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    border-top-color: var(--primary);
    animation: spin 1s linear infinite;
}

.loading-message {
    color: var(--text);
    font-size: 16px;
}

/* ===== Context Menu ===== */
.context-menu {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 8px 0;
    min-width: 180px;
    z-index: 1500;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
}

.context-menu-item {
    padding: 10px 16px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.15s;
}

.context-menu-item:hover {
    background: var(--bg-soft);
}

.context-menu-item.danger {
    color: var(--error);
}

.context-menu-divider {
    height: 1px;
    background: var(--border);
    margin: 8px 0;
}

/* ===== Form Elements ===== */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 13px;
    margin-bottom: 8px;
    color: var(--text-secondary);
    font-weight: 500;
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: 12px;
    background: rgba(15, 31, 52, 0.8);
    color: var(--text);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(27, 140, 255, 0.15);
}

.form-textarea {
    resize: vertical;
    min-height: 100px;
}

.prompt-input {
    width: 100%;
    padding: 12px;
    background: var(--bg-soft);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
}

/* ===== Mobile Responsive ===== */
@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }

    .main-view {
        width: 100%;
        height: calc(100vh - 70px);
        border-right: none;
        border-bottom: none;
    }

    .chat-area {
        display: none;
        width: 100%;
        height: calc(100vh - 70px);
    }

    .chat-area.active {
        display: flex !important;
    }

    .main-view.hidden {
        display: none;
    }

    .status-bar {
        display: none !important;
    }

    .empty-icon {
        width: 120px;
        height: 120px;
    }

    .empty-icon span {
        font-size: 48px;
    }

    .empty-state h2 {
        font-size: 18px;
    }

    .empty-state p {
        font-size: 13px;
    }

    .modal-dialog {
        width: 95%;
    }

    .toast-notification {
        right: 10px;
        left: 10px;
        max-width: none;
    }
}

@media (max-width: 480px) {
    .brand-logo {
        width: 36px;
        height: 36px;
        font-size: 18px;
    }

    .brand-text h2 {
        font-size: 16px;
    }

    .brand-text p {
        font-size: 11px;
    }
}

/* ===== Scrollbar Styling ===== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

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

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.15);
}

/* ===== Mobile Layout Fixes ===== */
@media (max-width: 768px) {
    /* Sidebar status bar visible on mobile */
    .sidebar-status-bar {
        display: flex !important;
    }
    
    /* Hide old fixed status bar */
    .status-bar {
        display: none !important;
    }
    
    .app-container {
        padding-bottom: 70px !important;
    }
    
    .chat-area {
        height: calc(100vh - 70px) !important;
    }
    
    .conversation-container {
        height: calc(100vh - 70px) !important;
        padding-bottom: 0 !important;
    }
    
    /* Input area fixed above bottom nav with more spacing */
    .input-area {
        position: fixed !important;
        bottom: 80px !important;
        left: 8px !important;
        right: 8px !important;
        background: rgba(15, 31, 52, 0.98) !important;
        border: 1px solid var(--border) !important;
        border-radius: 16px !important;
        padding: 8px 12px !important;
        z-index: 999 !important;
        margin: 0 !important;
        box-shadow: 0 -4px 20px rgba(0,0,0,0.3) !important;
    }
    
    .messages-container {
        max-height: calc(100vh - 240px) !important;
        padding-bottom: 90px !important;
        margin-bottom: 0 !important;
    }
}

/* ===== Desktop Input Area ===== */
@media (min-width: 769px) {
    .input-area {
        position: relative !important;
        margin-bottom: 10px !important;
        padding: 12px 16px !important;
        background: rgba(15, 31, 52, 0.9) !important;
        border-radius: 12px !important;
        margin-left: 10px !important;
        margin-right: 10px !important;
    }
}

/* ===== Wallet Info Box ===== */
.wallet-info-box {
    background: rgba(27, 140, 255, 0.1);
    border: 1px solid rgba(27, 140, 255, 0.3);
    border-radius: 12px;
    padding: 12px 16px;
    margin: 16px 0;
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.5;
}

.wallet-info-box p {
    margin: 0;
}

.wallet-info-box p + p {
    margin-top: 8px;
}

.wallet-info-box strong {
    color: var(--text);
}
