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

:root {
    --primary: #25D366;
    --primary-dark: #128C7E;
    --bg-light: #ECE5DD;
    --bg-dark: #DDDBE1;
    --chat-bg: #E4D8C8;
    --white: #FFFFFF;
    --text-dark: #111B21;
    --text-light: #667781;
    --sent-bg: #DCF8C6;
    --received-bg: #FFFFFF;
    --border: #D1D7DC;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-light);
    color: var(--text-dark);
    height: 100vh;
    overflow: hidden;
}

#app {
    height: 100vh;
    display: flex;
    flex-direction: column;
}

.screen {
    height: 100%;
}

.hidden {
    display: none !important;
}

/* Connect Screen */
#connect-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
}

.qr-container {
    background: var(--white);
    padding: 40px;
    border-radius: 20px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    max-width: 350px;
}

.qr-container h1 {
    color: var(--text-dark);
    margin-bottom: 20px;
    font-size: 24px;
}

#qr-code {
    margin: 20px 0;
    min-height: 256px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#qr-code img {
    width: 256px;
    height: 256px;
    border-radius: 8px;
}

#qr-status {
    color: var(--text-light);
    margin-bottom: 20px;
}

.btn {
    background: var(--primary);
    color: var(--white);
    border: none;
    padding: 12px 24px;
    border-radius: 25px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn:hover {
    background: var(--primary-dark);
    transform: scale(1.02);
}

/* Dashboard */
#dashboard {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.header {
    background: var(--primary);
    color: var(--white);
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.header h2 {
    font-size: 18px;
    font-weight: 600;
}

.status-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255,255,255,0.2);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 12px;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #ccc;
}

.status-dot.connected {
    background: var(--primary);
}

.main-container {
    flex: 1;
    display: flex;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 320px;
    background: var(--white);
    border-right: 1px solid var(--border);
    overflow-y: auto;
}

.chat-list {
    padding: 10px;
}

.chat-item {
    display: flex;
    padding: 12px;
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.2s;
    margin-bottom: 4px;
}

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

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

.chat-avatar {
    width: 48px;
    height: 48px;
    background: var(--primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--white);
    font-weight: 600;
    font-size: 18px;
    margin-right: 12px;
    flex-shrink: 0;
}

.chat-info {
    flex: 1;
    overflow: hidden;
}

.chat-name {
    font-weight: 600;
    font-size: 14px;
    color: var(--text-dark);
    display: block;
    margin-bottom: 4px;
}

.chat-preview {
    font-size: 13px;
    color: var(--text-light);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-time {
    font-size: 11px;
    color: var(--text-light);
    margin-left: 8px;
}

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

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

.no-chat-selected {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-light);
    font-size: 16px;
}

#chat-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.chat-header {
    padding: 15px 20px;
    background: var(--white);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
}

.chat-header .chat-name {
    font-weight: 600;
    font-size: 16px;
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

#messages-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.message {
    max-width: 70%;
    padding: 10px 14px;
    border-radius: 12px;
    position: relative;
    line-height: 1.4;
}

.message.sent {
    background: var(--sent-bg);
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.message.received {
    background: var(--received-bg);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.message-content {
    margin-bottom: 4px;
    word-wrap: break-word;
}

.message-meta {
    display: flex;
    justify-content: flex-end;
    gap: 4px;
    font-size: 11px;
    color: var(--text-light);
}

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

.message-image {
    max-width: 280px;
    border-radius: 8px;
    cursor: pointer;
    margin-top: 4px;
}

.message-document {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    background: rgba(0,0,0,0.05);
    border-radius: 8px;
    margin-top: 4px;
    text-decoration: none;
    color: var(--text-dark);
}

.message-document svg {
    flex-shrink: 0;
}

/* Message Input */
.message-input-container {
    padding: 15px 20px;
    background: var(--bg-light);
    display: flex;
    align-items: flex-end;
    gap: 10px;
    border-top: 1px solid var(--border);
}

.attach-btn {
    width: 44px;
    height: 44px;
    background: var(--white);
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-light);
    transition: all 0.2s;
    flex-shrink: 0;
}

.attach-btn:hover {
    background: var(--bg-dark);
    color: var(--primary);
}

#message-input {
    flex: 1;
    padding: 12px 16px;
    border: none;
    border-radius: 25px;
    font-size: 14px;
    outline: none;
    background: var(--white);
    resize: none;
    max-height: 120px;
}

.send-btn {
    width: 44px;
    height: 44px;
    background: var(--primary);
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--white);
    transition: all 0.2s;
    flex-shrink: 0;
}

.send-btn:hover {
    background: var(--primary-dark);
    transform: scale(1.05);
}

.send-btn:disabled {
    background: var(--text-light);
    cursor: not-allowed;
}

/* Preview Container */
#preview-container {
    position: relative;
    display: inline-block;
}

#preview-image {
    max-width: 100px;
    max-height: 80px;
    border-radius: 8px;
    object-fit: cover;
}

.remove-preview-btn {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 24px;
    height: 24px;
    background: #f44336;
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal img {
    max-width: 90%;
    max-height: 90%;
    border-radius: 8px;
}

.close-modal {
    position: absolute;
    top: 20px;
    right: 30px;
    font-size: 40px;
    color: white;
    cursor: pointer;
}

/* Loading */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

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

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

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        width: 100%;
        position: absolute;
        z-index: 10;
        height: calc(100vh - 60px);
    }

    .sidebar.hidden-mobile {
        display: none;
    }

    .chat-area {
        width: 100%;
    }

    .main-container {
        position: relative;
    }
}