:root {
    --bg-main: #000000;
    --bg-sidebar-bots: #1C1C1E;
    --bg-sidebar-chats: #000000;
    --bg-chat-area: #000000;
    
    --text-primary: #FFFFFF;
    --text-secondary: #8E8E93;
    --text-muted: #48484A;
    
    --accent-color: #0A84FF; /* iOS Blue */
    --accent-hover: #007AFF;
    --danger-color: #FF453A; /* iOS Red */
    --warning-color: #FF9F0A; /* iOS Orange */
    --success-color: #30D158; /* iOS Green */
    
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-highlight: rgba(255, 255, 255, 0.03);
    
    --transition-smooth: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    --font-stack: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: var(--font-stack);
}

body {
    background-color: var(--bg-main);
    color: var(--text-primary);
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

.hidden {
    display: none !important;
}

.app-container {
    display: flex;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    background: var(--bg-main);
    overflow: hidden;
    position: relative;
}

/* Scrollbars */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.12);
    border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.24);
}

/* Sidebar Bots (Leftmost panel) */
.sidebar-bots {
    width: 290px;
    background: var(--bg-sidebar-bots);
    border-right: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    z-index: 10;
}

.sidebar-header {
    padding: 16px 20px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--glass-border);
    background: rgba(0, 0, 0, 0.05);
}

.sidebar-header h2 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
    letter-spacing: -0.3px;
}

.sidebar-header h2 i {
    color: var(--accent-color);
}

.sidebar-header button {
    background: transparent;
    border: none;
    color: var(--accent-color);
    cursor: pointer;
    font-size: 1rem;
    transition: var(--transition-smooth);
    padding: 6px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-header button:hover {
    background: rgba(255, 255, 255, 0.05);
}

.bots-list-container {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.section-title {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    margin: 12px 6px 8px;
    font-weight: 600;
}

.loading-placeholder {
    padding: 20px;
    font-size: 0.82rem;
    color: var(--text-secondary);
    text-align: center;
    font-style: italic;
}

/* Bot Card Item (iOS widget style) */
.bot-card {
    background: #2C2C2E;
    border: 1px solid rgba(255, 255, 255, 0.02);
    border-radius: 12px;
    padding: 14px;
    margin-bottom: 12px;
    cursor: pointer;
    transition: var(--transition-smooth);
    display: flex;
    align-items: center;
    gap: 12px;
    position: relative;
}

.bot-card:hover {
    background: #3A3A3C;
}

.bot-card.active {
    background: rgba(10, 132, 255, 0.15);
    border-color: rgba(10, 132, 255, 0.3);
}

.bot-icon {
    width: 40px;
    height: 40px;
    border-radius: 9px;
    background: rgba(255, 255, 255, 0.05);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    color: var(--text-secondary);
    transition: var(--transition-smooth);
}

.bot-card.active .bot-icon {
    background: var(--accent-color);
    color: white;
}

.bot-details {
    flex: 1;
    min-width: 0;
}

.bot-name {
    font-weight: 600;
    font-size: 0.88rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
    letter-spacing: -0.1px;
}

.bot-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.74rem;
    color: var(--text-secondary);
}

.dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    display: inline-block;
}

.dot-connected { background-color: var(--success-color); }
.dot-pending { background-color: var(--warning-color); }
.dot-offline { background-color: var(--danger-color); }

.bot-card-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.btn-delete-bot {
    background: transparent;
    border: none;
    color: var(--danger-color);
    cursor: pointer;
    font-size: 0.9rem;
    padding: 6px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-smooth);
    width: 28px;
    height: 28px;
    opacity: 0.8;
}

.btn-delete-bot:hover {
    background: rgba(255, 69, 58, 0.15);
    opacity: 1;
}

.bot-action-indicator {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Sidebar Chats (Middle panel) */
.sidebar-chats {
    width: 340px;
    background: var(--bg-sidebar-chats);
    border-right: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    z-index: 5;
}

.sidebar-chats .sidebar-header {
    border-bottom: none;
    background: transparent;
    padding: 16px 16px 8px;
    height: auto;
}

.search-box {
    width: 100%;
    background: #1C1C1E;
    border-radius: 10px;
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    border: 1px solid transparent;
    transition: var(--transition-smooth);
}

.search-box:focus-within {
    border-color: rgba(255, 255, 255, 0.08);
}

.search-box i {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.search-box input {
    background: transparent;
    border: none;
    color: var(--text-primary);
    width: 100%;
    outline: none;
    font-size: 0.85rem;
}

/* iOS Segmented Control Tab Bar */
.chat-tabs {
    display: flex;
    background: #1C1C1E;
    padding: 2px;
    border-radius: 8px;
    margin: 8px 16px 14px;
    border: 1px solid rgba(255, 255, 255, 0.04);
}

.chat-tab {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 6px 0;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    border-radius: 7px;
    transition: var(--transition-smooth);
    text-align: center;
}

.chat-tab:hover {
    color: #FFFFFF;
}

.chat-tab.active {
    background: #3A3A3C;
    color: #FFFFFF;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.chats-list-container {
    flex: 1;
    overflow-y: auto;
}

/* Chat Card Item (iOS Style list row) */
.chat-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    cursor: pointer;
    transition: var(--transition-smooth);
}

.chat-card:hover {
    background: #1C1C1E;
}

.chat-card.active {
    background: #2C2C2E;
}

.chat-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: #2C2C2E;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    color: var(--text-secondary);
}

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

.chat-info-top {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 3px;
}

.chat-name {
    font-weight: 600;
    font-size: 0.92rem;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: -0.1px;
}

.chat-time {
    font-size: 0.72rem;
    color: var(--text-secondary);
}

.chat-lastmsg {
    font-size: 0.8rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 200px;
    color: var(--text-secondary);
    text-align: center;
    padding: 20px;
}

.empty-state i {
    font-size: 2.2rem;
    margin-bottom: 12px;
    color: var(--text-muted);
}

.empty-state p {
    font-size: 0.85rem;
    max-width: 200px;
    line-height: 1.4;
}

/* Welcome Screen (Right main area default) */
.welcome-screen {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-chat-area);
    padding: 40px;
    text-align: center;
}

.welcome-content {
    max-width: 420px;
    animation: fadeInUp 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: translateY(0); }
}

.welcome-logo {
    font-size: 3.5rem;
    color: var(--accent-color);
    margin-bottom: 20px;
    opacity: 0.95;
}

.welcome-screen h1 {
    font-size: 1.6rem;
    font-weight: 700;
    margin-bottom: 10px;
    letter-spacing: -0.3px;
}

.welcome-screen p {
    color: var(--text-secondary);
    line-height: 1.5;
    font-size: 0.88rem;
    margin-bottom: 24px;
}

.status-indicator-legend {
    display: flex;
    justify-content: center;
    gap: 16px;
    font-size: 0.76rem;
    color: var(--text-secondary);
}

.status-indicator-legend span {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Chat Area Panel */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-chat-area);
    position: relative;
}

.chat-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.chat-header {
    height: 64px;
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(0, 0, 0, 0.4);
    border-bottom: 1px solid var(--glass-border);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.chat-header-info .chat-avatar {
    width: 36px;
    height: 36px;
}

.chat-header-info h3 {
    font-size: 0.92rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-header-info span {
    font-size: 0.72rem;
    color: var(--text-secondary);
}

.chat-header-actions button {
    background: transparent;
    border: none;
    color: var(--accent-color);
    cursor: pointer;
    font-size: 1.05rem;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-header-actions button:hover {
    background: rgba(255, 255, 255, 0.05);
}

/* Messages Container (iOS Style bubbles) */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #000000;
}

.message-bubble {
    max-width: 70%;
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 0.88rem;
    line-height: 1.4;
    position: relative;
    word-break: break-word;
    display: flex;
    flex-direction: column;
}

.message-bubble.incoming {
    background: #2C2C2E;
    color: #FFFFFF;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.message-bubble.outgoing {
    background: var(--accent-color);
    color: #FFFFFF;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.msg-sender {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--success-color);
    margin-bottom: 4px;
}

.message-text {
    padding-bottom: 4px;
}

.msg-time {
    align-self: flex-end;
    font-size: 0.65rem;
    color: rgba(255, 255, 255, 0.5);
    margin-top: 2px;
}

/* Input Bar (iOS style input pill) */
.chat-input-bar {
    padding: 10px 16px;
    background: rgba(0, 0, 0, 0.6);
    border-top: 1px solid var(--glass-border);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

#message-form {
    display: flex;
    gap: 10px;
    width: 100%;
    align-items: center;
}

#message-form input {
    flex: 1;
    background: #1C1C1E;
    border: 1px solid rgba(255, 255, 255, 0.05);
    padding: 10px 18px;
    border-radius: 20px;
    color: var(--text-primary);
    font-size: 0.88rem;
    outline: none;
    transition: var(--transition-smooth);
}

#message-form input:focus {
    border-color: rgba(255, 255, 255, 0.15);
}

#message-form button {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--accent-color);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
    transition: var(--transition-smooth);
}

#message-form button:hover {
    background: var(--accent-hover);
    transform: scale(1.05);
}

/* Auth Modal (iOS Style sheets) */
.auth-screen {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.auth-content {
    background: #1C1C1E;
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    max-width: 440px;
    width: 100%;
    padding: 24px;
    display: flex;
    flex-direction: column;
    animation: fadeInUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
}

.auth-header {
    margin-bottom: 20px;
    text-align: center;
}

.auth-header h2 {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 4px;
    letter-spacing: -0.2px;
}

.bot-num-display {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.auth-body {
    flex: 1;
}

.auth-option-container {
    text-align: center;
    margin-bottom: 20px;
}

.auth-option-container p {
    font-size: 0.82rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
    line-height: 1.4;
}

.qr-code-wrapper {
    background: white;
    padding: 14px;
    border-radius: 14px;
    display: inline-block;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
}

.qr-code-wrapper img {
    display: block;
    width: 220px;
    height: 220px;
}

.pairing-code-wrapper {
    display: inline-block;
    padding: 12px 24px;
    background: #2C2C2E;
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    font-family: monospace;
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: 2px;
    color: var(--accent-color);
    text-shadow: 0 0 10px rgba(10, 132, 255, 0.2);
}

.auth-instructions {
    background: rgba(255, 255, 255, 0.02);
    border-radius: 12px;
    padding: 14px 18px;
    border: 1px solid rgba(255, 255, 255, 0.04);
}

.auth-instructions h4 {
    font-size: 0.8rem;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.auth-instructions ol {
    padding-left: 16px;
    font-size: 0.78rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.auth-instructions li {
    margin-bottom: 4px;
}

.btn-close-auth {
    background: #2C2C2E;
    border: none;
    color: var(--text-primary);
    padding: 12px;
    border-radius: 10px;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    margin-top: 20px;
    transition: var(--transition-smooth);
}

.btn-close-auth:hover {
    background: #3A3A3C;
}

/* Toast Component */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(28, 28, 30, 0.95);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    padding: 10px 16px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 1000;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.toast.hidden {
    bottom: -60px;
    opacity: 0;
}

.toast-connecting i { color: var(--warning-color); }
.toast-connected i { color: var(--success-color); }
.toast-error i { color: var(--danger-color); }

/* Media Messages Styles */
.media-placeholder {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #2C2C2E;
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    padding: 10px 14px;
    margin-bottom: 6px;
    min-width: 200px;
    max-width: 300px;
}

.media-placeholder-info {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.82rem;
    color: var(--text-secondary);
}

.media-placeholder-info i {
    font-size: 1rem;
    color: var(--accent-color);
}

.btn-download-media {
    background: rgba(10, 132, 255, 0.15);
    border: 1px solid rgba(10, 132, 255, 0.3);
    color: #FFFFFF;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.74rem;
    cursor: pointer;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: var(--transition-smooth);
}

.btn-download-media:hover {
    background: var(--accent-color);
}

.media-loading {
    font-size: 0.78rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px;
}

.media-content-wrapper {
    margin-bottom: 6px;
    border-radius: 12px;
    overflow: hidden;
    display: flex;
}

.chat-media-image {
    max-width: 100%;
    max-height: 260px;
    border-radius: 12px;
    cursor: pointer;
    transition: var(--transition-smooth);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.chat-media-image:hover {
    opacity: 0.9;
}

.chat-media-sticker {
    width: 120px;
    height: 120px;
    object-fit: contain;
    margin: 5px auto;
    filter: drop-shadow(0 4px 8px rgba(0,0,0,0.3));
}

.sticker-bubble {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
}

.sticker-bubble .msg-time {
    bottom: -18px;
    right: 0;
    color: var(--text-secondary);
}

.sticker-bubble .msg-sender {
    margin-bottom: 2px;
}

.chat-media-video {
    max-width: 100%;
    max-height: 260px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.chat-media-audio {
    max-width: 100%;
    border-radius: 12px;
    outline: none;
}

/* Mobile responsive navigation styles */
.mobile-only-btn {
    display: none;
    background: transparent;
    border: none;
    color: var(--accent-color);
    font-size: 1.25rem;
    padding: 8px 12px;
    margin-right: 4px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    flex-shrink: 0;
}

.mobile-only-btn:hover {
    background: rgba(255, 255, 255, 0.05);
}

@media (max-width: 900px) {
    .sidebar-bots {
        width: 100% !important;
        display: flex !important;
    }
    
    .sidebar-chats {
        display: none !important;
    }
    
    .chat-area {
        display: none !important;
    }

    /* State: show-chats (Bot selected) -> Show Chats list, hide others */
    .app-container.show-chats .sidebar-bots {
        display: none !important;
    }
    .app-container.show-chats .sidebar-chats {
        width: 100% !important;
        display: flex !important;
    }
    .app-container.show-chats .chat-area {
        display: none !important;
    }

    /* State: show-messages (Chat selected OR Auth Screen) -> Show Chat Screen, hide others */
    .app-container.show-messages .sidebar-bots {
        display: none !important;
    }
    .app-container.show-messages .sidebar-chats {
        display: none !important;
    }
    .app-container.show-messages .chat-area {
        width: 100% !important;
        display: flex !important;
    }

    /* Display back buttons on mobile */
    .mobile-only-btn {
        display: flex !important;
    }

    /* UI Adjustments for mobile */
    .sidebar-header {
        padding: 12px 16px;
        height: 60px;
    }

    .chat-header {
        padding: 0 16px;
        height: 60px;
    }

    .message-bubble {
        max-width: 85%;
    }

    .chat-input-bar {
        padding: 8px 12px;
    }

    #message-form input {
        padding: 10px 16px;
    }

    #message-form button {
        width: 36px;
        height: 36px;
    }
}
