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

:root {
    --wa-green: #25d366;
    --wa-green-dark: #128c7e;
    --wa-teal: #075e54;
    --wa-light-green: #dcf8c6;
    --bg-primary: #f0f2f5;
    --bg-chat: #e5ddd5;
    --bg-header: #ffffff;
    --text-primary: #111b21;
    --text-secondary: #667781;
    --text-timestamp: #8696a0;
    --border-color: #e0e0e0;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.12);
    --radius: 8px;
}

html, body {
    height: 100%;
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 960px;
    margin: 0 auto;
    background: var(--bg-chat);
    box-shadow: var(--shadow-md);
}

/* Header */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: var(--wa-teal);
    color: #ffffff;
    flex-shrink: 0;
}

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

.header-icon {
    display: flex;
    align-items: center;
    opacity: 0.9;
}

.header-text h1 {
    font-size: 1.1rem;
    font-weight: 600;
    letter-spacing: 0.2px;
}

.header-subtitle {
    font-size: 0.75rem;
    opacity: 0.75;
}

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

.listings-link {
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.85rem;
    font-weight: 600;
    text-decoration: none;
    padding: 4px 10px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.15);
}

.listings-link:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.25);
}

/* Connection status */
.status-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 500;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.status-connected {
    background: rgba(37, 211, 102, 0.2);
    color: #dcf8c6;
}

.status-connected .status-dot {
    background: var(--wa-green);
    box-shadow: 0 0 6px var(--wa-green);
}

.status-disconnected {
    background: rgba(255, 255, 255, 0.15);
    color: rgba(255, 255, 255, 0.7);
}

.status-disconnected .status-dot {
    background: #ff6b6b;
}

.status-reconnecting {
    background: rgba(255, 193, 7, 0.2);
    color: #ffe082;
}

.status-reconnecting .status-dot {
    background: #ffc107;
    animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* Messages area */
.messages-container {
    flex: 1;
    overflow: hidden;
    position: relative;
    background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M30 5 L35 15 L30 12 L25 15 Z' fill='%23ccc' opacity='0.05'/%3E%3C/svg%3E");
}

.message-list {
    height: 100%;
    overflow-y: auto;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

/* Message bubble */
.message-bubble {
    max-width: 85%;
    background: #ffffff;
    border-radius: var(--radius);
    padding: 8px 12px;
    box-shadow: var(--shadow-sm);
    animation: slideIn 0.25s ease-out;
    position: relative;
}

.message-bubble::before {
    content: '';
    position: absolute;
    top: 0;
    left: -6px;
    width: 0;
    height: 0;
    border-top: 6px solid #ffffff;
    border-left: 6px solid transparent;
}

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

.msg-header {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 3px;
}

.msg-sender {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--wa-teal);
}

.msg-group {
    font-size: 0.7rem;
    color: var(--text-secondary);
    background: var(--bg-primary);
    padding: 1px 6px;
    border-radius: 4px;
}

.msg-body {
    font-size: 0.9rem;
    line-height: 1.4;
    word-wrap: break-word;
    color: var(--text-primary);
}

.msg-footer {
    display: flex;
    justify-content: flex-end;
    margin-top: 4px;
}

.msg-time {
    font-size: 0.68rem;
    color: var(--text-timestamp);
}

.msg-type-badge {
    font-size: 0.65rem;
    color: var(--text-secondary);
    background: var(--bg-primary);
    padding: 1px 5px;
    border-radius: 3px;
    margin-left: 6px;
}

/* Document download link */
.doc-download {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--wa-teal);
    text-decoration: none;
    font-weight: 500;
}

.doc-download:hover {
    text-decoration: underline;
}

.doc-download-label {
    font-size: 0.75rem;
    color: var(--wa-green-dark);
    font-weight: 600;
}

/* Loading & empty states */
.loading-indicator {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 40px;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border-color);
    border-top-color: var(--wa-green-dark);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

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

.empty-state p {
    font-size: 0.95rem;
    font-weight: 500;
}

.empty-hint {
    font-size: 0.8rem !important;
    font-weight: 400 !important;
    opacity: 0.7;
}

/* Footer */
.app-footer {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 20px;
    background: var(--bg-header);
    border-top: 1px solid var(--border-color);
    font-size: 0.75rem;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.footer-sep {
    opacity: 0.4;
}

/* Date separator */
.date-separator {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 12px 0;
}

.date-separator span {
    background: rgba(225, 218, 208, 0.85);
    color: var(--text-secondary);
    font-size: 0.72rem;
    font-weight: 500;
    padding: 4px 14px;
    border-radius: 8px;
    box-shadow: var(--shadow-sm);
}
