* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    overflow: hidden; /* Prevent scrolling on the main document */
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #333;
}

#app {
    display: flex;
    height: 100vh; /* Fixed height instead of min-height */
    max-width: 1400px;
    margin: 0 auto;
    background: white;
    box-shadow: 0 0 20px rgba(0,0,0,0.1);
    overflow: hidden; /* Prevent scrolling within app */
}

/* Sidebar styles */
.sidebar {
    width: 280px;
    background: #f8f9fa;
    border-right: 1px solid #e9ecef;
    padding: 20px;
    display: none; /* Hidden on mobile by default */
    flex-shrink: 0;
}

.sidebar-header h2 {
    color: #4a5568;
    margin-bottom: 5px;
    font-size: 20px;
}

.sidebar-header p {
    color: #718096;
    font-size: 14px;
    margin-bottom: 30px;
}

.profile-section, .stats-section {
    margin-bottom: 30px;
}

.profile-section h3, .stats-section h3 {
    color: #2d3748;
    font-size: 16px;
    margin-bottom: 15px;
    padding-bottom: 8px;
    border-bottom: 2px solid #e9ecef;
}

.profile-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding: 8px 0;
}

.profile-label {
    font-size: 13px;
    color: #718096;
    font-weight: 500;
}

.profile-value {
    font-size: 13px;
    font-weight: 600;
    color: #2d3748;
}

.profile-value.user-id, .profile-value.partner-id {
    font-family: 'Courier New', monospace;
    background: #e2e8f0;
    padding: 4px 8px;
    border-radius: 6px;
    border: 1px solid #cbd5e0;
}

.connection-status.connected {
    color: #38a169;
}

.connection-status.waiting {
    color: #d69e2e;
}

.connection-status.disconnected {
    color: #e53e3e;
}

.connection-status.retrying {
    color: #d69e2e;
}

.stop-retry-btn {
    background: #e53e3e;
    color: white;
    border: none;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 11px;
    cursor: pointer;
    margin-left: 8px;
}

.stop-retry-btn:hover {
    background: #c53030;
}

.message-status {
    font-size: 12px;
    margin-left: 5px;
    display: inline-block;
}

.message.failed .message-content {
    opacity: 0.7;
    text-decoration: line-through;
}

/* Main content area */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    position: relative; /* For absolute positioning of screens */
}

/* Mobile header (shown on small screens) */
.mobile-header {
    background: rgba(255,255,255,0.95);
    padding: 20px;
    text-align: center;
    border-bottom: 1px solid #eee;
    display: block; /* Shown by default on mobile */
}

.mobile-header h1 {
    color: #4a5568;
    margin-bottom: 5px;
}

.mobile-header p {
    color: #718096;
    font-size: 14px;
    margin-bottom: 15px;
}

.user-info {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: 10px;
    flex-wrap: wrap;
}

.user-id-container, .partner-id-container, .tab-indicator-container {
    display: flex;
    align-items: center;
    gap: 8px;
}

.label {
    font-size: 12px;
    color: #718096;
    font-weight: 500;
}

.user-id, .partner-id {
    font-family: 'Courier New', monospace;
    font-size: 13px;
    font-weight: bold;
    padding: 4px 8px;
    border-radius: 12px;
    background: #f8f9fa;
    border: 1px solid #e9ecef;
}

.user-id {
    color: #667eea;
}

.partner-id {
    color: #28a745;
}

.tab-indicator {
    font-size: 12px;
    color: #6c757d;
    font-weight: bold;
}

.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    padding: 20px;
    display: none;
    overflow-y: auto;
    background: white;
    z-index: 1;
}

.screen.active {
    display: flex;
    flex-direction: column;
    z-index: 10;
}

/* Home Screen */
.home-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    max-width: 500px;
    margin: 0 auto;
    text-align: center;
}

.home-content h2 {
    color: #4a5568;
    margin-bottom: 15px;
    font-size: 28px;
}

.home-content > p {
    color: #718096;
    margin-bottom: 25px;
    font-size: 16px;
    line-height: 1.5;
}

.features {
    margin-bottom: 30px;
}

.features ul {
    list-style: none;
    text-align: left;
}

.features li {
    padding: 8px 0;
    color: #4a5568;
    font-size: 15px;
}

.btn-large {
    padding: 15px 40px;
    font-size: 18px;
    margin-bottom: 15px;
}

.disclaimer {
    font-size: 12px;
    color: #718096;
    max-width: 400px;
    line-height: 1.4;
}

/* Waiting Screen */
.waiting-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 20px 0;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Chat Screen */
#chat-screen {
    padding: 0;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: #f8f9fa;
    border-bottom: 1px solid #eee;
    flex-shrink: 0;
}

.status {
    color: #28a745;
    font-weight: 500;
}

.messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: #f8f9fa;
    min-height: 0; /* Important for flexbox scrolling */
}

.message {
    margin-bottom: 15px;
    max-width: 70%;
    word-wrap: break-word;
}

.message.sent {
    margin-left: auto;
    text-align: right;
}

.message-content {
    padding: 10px 15px;
    border-radius: 20px;
    display: inline-block;
}

.message.sent .message-content {
    background: #667eea;
    color: white;
}

.message.received .message-content {
    background: #e9ecef;
    color: #333;
}

.message-time {
    font-size: 11px;
    color: #6c757d;
    margin-top: 5px;
}

.chat-input {
    display: flex;
    padding: 20px;
    background: white;
    border-top: 1px solid #eee;
    flex-shrink: 0;
}

#message-input {
    flex: 1;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 25px;
    margin-right: 10px;
    outline: none;
}

#message-input:focus {
    border-color: #667eea;
}

/* Disconnected Screen */
.disconnected-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
}

.disconnect-reason {
    color: #e53e3e;
    font-size: 14px;
    font-style: italic;
    margin: 10px 0;
    padding: 8px 15px;
    background: #fed7d7;
    border-radius: 15px;
    border: 1px solid #feb2b2;
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 25px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.3s ease;
}

.btn-primary {
    background: #667eea;
    color: white;
}

.btn-primary:hover {
    background: #5a67d8;
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #545b62;
}

.btn-danger {
    background: #dc3545;
    color: white;
}

.btn-danger:hover {
    background: #c82333;
}

/* Responsive */
@media (max-width: 768px) {
    #app {
        margin: 0;
        border-radius: 0;
    }
    
    .message {
        max-width: 85%;
    }
}

/* Responsive Design */
@media (min-width: 768px) {
    /* Show sidebar and hide mobile header on larger screens */
    .sidebar {
        display: block;
    }
    
    .mobile-header {
        display: none;
    }
    
    /* Adjust main content layout for larger screens */
    #app {
        max-width: none;
    }
    
    .screen {
        padding: 0;
        height: 100%;
        top: 0; /* Reset top position for larger screens */
    }
    
    .screen:not(#chat-screen) {
        padding: 40px;
    }
    
    .home-content, .waiting-content, .disconnected-content {
        max-width: 600px;
        margin: 0 auto;
        height: 100%;
        justify-content: center;
    }
    
    .messages {
        max-height: calc(100vh - 140px); /* Header + input height */
    }
}

@media (max-width: 767px) {
    /* Mobile layout - keep current compact design */
    #app {
        max-width: 800px;
        margin: 0 auto;
    }
    
    .sidebar {
        display: none;
    }
    
    .mobile-header {
        display: block;
        flex-shrink: 0;
    }
    
    .screen {
        top: 140px; /* Position below mobile header */
        height: calc(100vh - 140px);
    }
    
    .user-info {
        flex-direction: column;
        gap: 10px;
    }
    
    .home-content h2 {
        font-size: 24px;
    }
    
    .features ul {
        text-align: center;
    }
    
    .btn {
        width: 100%;
        max-width: 280px;
    }
}

/* Emoji Picker Styles */
.emoji-btn {
    background: #f8f9fa;
    border: 1px solid #ddd;
    border-radius: 20px;
    width: 40px;
    height: 40px;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 8px;
    transition: all 0.2s ease;
}

.emoji-btn:hover {
    background: #e9ecef;
    border-color: #667eea;
}

.emoji-picker {
    position: absolute;
    bottom: 80px;
    left: 20px;
    right: 20px;
    background: white;
    border: 1px solid #ddd;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    display: none;
    z-index: 1000;
    max-width: 320px;
}

.emoji-categories {
    display: flex;
    border-bottom: 1px solid #eee;
    padding: 8px;
    background: #f8f9fa;
    border-radius: 12px 12px 0 0;
}

.emoji-category {
    background: none;
    border: none;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 20px;
    border-radius: 8px;
    transition: background-color 0.2s ease;
    flex: 1;
    text-align: center;
}

.emoji-category:hover {
    background: #e9ecef;
}

.emoji-category.active {
    background: #667eea;
    color: white;
}

.emoji-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 4px;
    padding: 12px;
    max-height: 200px;
    overflow-y: auto;
}

.emoji-item {
    background: none;
    border: none;
    padding: 8px;
    cursor: pointer;
    font-size: 20px;
    border-radius: 6px;
    transition: background-color 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 1;
}

.emoji-item:hover {
    background: #f0f0f0;
}

/* Mobile adjustments for emoji picker */
@media (max-width: 767px) {
    .emoji-picker {
        left: 10px;
        right: 10px;
        max-width: none;
    }
    
    .emoji-grid {
        grid-template-columns: repeat(6, 1fr);
    }
    
    .emoji-item {
        font-size: 18px;
        padding: 6px;
    }
}

/* Extra large screens */
@media (min-width: 1200px) {
    .sidebar {
        width: 320px;
    }
    
    .profile-item {
        padding: 10px 0;
    }
    
    .profile-label, .profile-value {
        font-size: 14px;
    }
}
}