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

:root {
    --primary: #075E54;
    --primary-dark: #054D44;
    --secondary: #25D366;
    --bg: #ECE5DD;
    --sidebar-bg: #FFFFFF;
    --chat-bg: #E4DDD6;
    --bubble-out: #DCF8C6;
    --bubble-in: #FFFFFF;
    --text: #111B21;
    --text-muted: #667781;
    --border: #E9EDEF;
    --radius: 8px;
    --header-h: 56px;
}

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

#app {
    display: flex;
    height: 100vh;
}

/* ===== SIDEBAR ===== */
.sidebar {
    width: 360px;
    min-width: 360px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: transform .3s ease;
    z-index: 10;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    height: var(--header-h);
    background: var(--primary);
    color: white;
}

.sidebar-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.app-title { font-size: 18px; font-weight: 600; }

.sidebar-tabs {
    display: flex;
    background: var(--primary);
    padding: 0 8px;
    gap: 4px;
}
.tab-btn {
    flex: 1;
    padding: 8px 4px;
    border: none;
    background: transparent;
    color: rgba(255,255,255,.7);
    font-size: 13px;
    cursor: pointer;
    border-bottom: 3px solid transparent;
    transition: all .2s;
}
.tab-btn.active {
    color: #fff;
    border-bottom-color: #fff;
    font-weight: 600;
}

.tab-content { display: none; flex: 1; overflow-y: auto; }
.tab-content.active { display: flex; flex-direction: column; }

.search-box { padding: 8px 12px; }
.search-box input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 14px;
    outline: none;
}
.search-box input:focus { border-color: var(--primary); }

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

.chat-item {
    display: flex;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background .15s;
}
.chat-item:hover { background: #F0F2F5; }
.chat-item.active { background: #E8F4FD; }
.chat-item .avatar {
    width: 48px; height: 48px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 18px;
    margin-right: 12px;
    flex-shrink: 0;
}
.chat-item .info { flex: 1; overflow: hidden; }
.chat-item .info .name { font-weight: 500; font-size: 15px; }
.chat-item .info .preview { font-size: 13px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item .meta { text-align: right; font-size: 11px; color: var(--text-muted); flex-shrink: 0; }

/* ===== AUTO REPLY ===== */
.panel-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.panel-header h3 { font-size: 16px; }

.auto-reply-item {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}
.auto-reply-item .keyword { font-weight: 600; font-size: 14px; color: var(--primary); }
.auto-reply-item .reply { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.auto-reply-item .meta { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.auto-reply-item .actions { margin-top: 6px; }

/* ===== SETTINGS ===== */
.settings-form { padding: 16px; }
.settings-form label { display: block; font-size: 13px; font-weight: 500; margin: 10px 0 4px; color: var(--text-muted); }
.settings-form textarea, .settings-form select {
    width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius);
    font-size: 14px; font-family: inherit;
}
.settings-form textarea:focus, .settings-form select:focus { outline: none; border-color: var(--primary); }

.stats-cards {
    display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 12px 16px;
}
.stat-card {
    background: #F0F2F5; padding: 12px; border-radius: var(--radius); text-align: center;
}
.stat-card .num { font-size: 22px; font-weight: 700; color: var(--primary); }
.stat-card .label { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* ===== MAIN CONTENT ===== */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--chat-bg);
    position: relative;
}

.welcome-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    text-align: center;
    background: #F0F2F5;
}
.welcome-icon { font-size: 64px; margin-bottom: 16px; }
.welcome-screen h2 { font-size: 22px; margin-bottom: 8px; color: #333; }
.welcome-screen p { color: var(--text-muted); margin-bottom: 24px; }

.quick-stats { display: flex; gap: 16px; flex-wrap: wrap; justify-content: center; }

/* ===== CHAT VIEW ===== */
.chat-view { flex: 1; display: flex; flex-direction: column; }

.chat-header {
    display: flex;
    align-items: center;
    padding: 10px 16px;
    background: var(--primary);
    color: #fff;
    height: var(--header-h);
}
.chat-header-info { flex: 1; margin-left: 12px; }
.chat-header-info strong { font-size: 16px; display: block; }
.chat-header-info small { font-size: 12px; opacity: .8; }
.chat-actions { display: flex; gap: 8px; }

.message-list {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.message {
    max-width: 75%;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.45;
    word-wrap: break-word;
    position: relative;
    margin-bottom: 2px;
}
.message.inbound {
    align-self: flex-start;
    background: var(--bubble-in);
    border-bottom-left-radius: 4px;
}
.message.outbound {
    align-self: flex-end;
    background: var(--bubble-out);
    border-bottom-right-radius: 4px;
}
.message .time {
    font-size: 10px;
    color: var(--text-muted);
    text-align: right;
    margin-top: 4px;
}
.message .status {
    font-size: 10px;
    margin-left: 4px;
}

.chat-input {
    display: flex;
    align-items: flex-end;
    padding: 8px 12px;
    background: #F0F2F5;
    gap: 8px;
}
.chat-input textarea {
    flex: 1;
    padding: 10px 12px;
    border: none;
    border-radius: 20px;
    font-size: 15px;
    resize: none;
    outline: none;
    font-family: inherit;
    max-height: 120px;
}

/* ===== BUTTONS ===== */
.btn {
    border: none;
    cursor: pointer;
    font-size: 14px;
    padding: 8px 16px;
    border-radius: var(--radius);
    transition: opacity .2s;
}
.btn:active { opacity: .7; }
.btn-icon {
    background: transparent;
    color: inherit;
    font-size: 20px;
    padding: 4px 8px;
    border: none;
    cursor: pointer;
}
.btn-sync { font-size: 18px; }
.btn-sync.syncing { animation: spin 1s linear infinite; pointer-events: none; }
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-block { width: 100%; }
.btn-send {
    width: 44px; height: 44px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-danger { background: #E53935; color: #fff; }

/* ===== MODAL ===== */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,.4);
    z-index: 100;
}
.modal {
    display: none;
    position: fixed;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    background: #fff;
    border-radius: 12px;
    width: 90%;
    max-width: 400px;
    z-index: 101;
    box-shadow: 0 8px 32px rgba(0,0,0,.2);
}
.modal.open, .modal-overlay.open { display: block; }
.modal-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 16px; border-bottom: 1px solid var(--border);
}
.modal-body { padding: 16px; }
.modal-body label { display: block; font-size: 13px; margin: 8px 0 4px; color: var(--text-muted); }
.modal-body input, .modal-body select, .modal-body textarea {
    width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px;
    font-size: 14px; font-family: inherit; margin-bottom: 8px;
}
.modal-body input:focus, .modal-body select:focus, .modal-body textarea:focus {
    outline: none; border-color: var(--primary);
}

/* ===== Mobile ===== */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: 0; left: 0; bottom: 0;
        width: 85%;
        max-width: 340px;
        transform: translateX(-100%);
    }
    .sidebar.open { transform: translateX(0); }

    .hamburger {
        display: flex !important;
        position: fixed;
        top: 8px; left: 8px;
        width: 40px; height: 40px;
        background: var(--primary);
        color: #fff;
        border-radius: 50%;
        align-items: center;
        justify-content: center;
        font-size: 20px;
        z-index: 9;
        box-shadow: 0 2px 8px rgba(0,0,0,.2);
    }
    .mobile-back { display: block !important; }
    .welcome-screen { display: none; }
}

.hamburger { display: none; }
.mobile-back { display: none; }

.loading { padding: 24px; text-align: center; color: var(--text-muted); }
.empty { padding: 24px; text-align: center; color: var(--text-muted); }
