@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ─── Reset & Base ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    /* WhatsApp Dark Theme */
    --bg-primary:       #0B141A;
    --bg-secondary:     #111B21;
    --bg-tertiary:      #202C33;
    --bg-hover:         #2A3942;
    --bg-input:         #2A3942;

    /* Message Bubbles */
    --bubble-out:       #005C4B;
    --bubble-out-hover: #006B58;
    --bubble-in:        #202C33;
    --bubble-in-hover:  #2A3942;

    /* Accent */
    --green:            #00A884;
    --green-light:      #25D366;
    --green-glow:       rgba(0, 168, 132, 0.2);

    /* Text */
    --text-primary:     #E9EDEF;
    --text-secondary:   #8696A0;
    --text-muted:       #667781;
    --text-timestamp:   #8696A0;

    /* Status */
    --bot-active:       #00A884;
    --bot-paused:       #F0B429;
    --online:           #00A884;

    /* Borders */
    --border:           rgba(134, 150, 160, 0.15);
    --border-hover:     rgba(134, 150, 160, 0.25);

    /* Shadows */
    --shadow-sm:        0 1px 3px rgba(0,0,0,0.3);
    --shadow-md:        0 4px 12px rgba(0,0,0,0.4);
    --shadow-lg:        0 8px 32px rgba(0,0,0,0.5);

    --radius-sm:        8px;
    --radius-md:        12px;
    --radius-lg:        18px;
    --radius-xl:        24px;

    --sidebar-width:    360px;
    --header-height:    60px;
}

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

/* ─── Layout ────────────────────────────────────────────────────────────── */
.app {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ─── Sidebar ───────────────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
}

.sidebar-header {
    height: var(--header-height);
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.sidebar-header h1 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.sidebar-header h1 .logo-icon {
    width: 28px;
    height: 28px;
    background: var(--green);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

.badge-count {
    font-size: 11px;
    background: var(--green);
    color: #fff;
    border-radius: 10px;
    padding: 1px 7px;
    font-weight: 600;
    margin-left: 4px;
}

/* Search */
.search-box {
    padding: 8px 12px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.search-input-wrap {
    position: relative;
}

.search-input-wrap svg {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

.search-input {
    width: 100%;
    background: var(--bg-input);
    border: none;
    border-radius: 8px;
    padding: 8px 12px 8px 38px;
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
    transition: background 0.2s;
}

.search-input::placeholder { color: var(--text-muted); }
.search-input:focus { background: var(--bg-hover); }

/* Conversation List */
.conversation-list {
    flex: 1;
    overflow-y: auto;
}

.conversation-list::-webkit-scrollbar { width: 5px; }
.conversation-list::-webkit-scrollbar-track { background: transparent; }
.conversation-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.conv-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
    text-decoration: none;
    color: inherit;
    position: relative;
}

.conv-item:hover { background: var(--bg-hover); }
.conv-item.active { background: var(--bg-tertiary); }

/* Avatar */
.avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: linear-gradient(135deg, #1a3c5e, #2d6a4f);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    color: #fff;
    flex-shrink: 0;
    position: relative;
    user-select: none;
}

.avatar-sm {
    width: 36px;
    height: 36px;
    font-size: 12px;
}

.avatar-colors-0 { background: linear-gradient(135deg, #1a3c5e, #2d6a4f); }
.avatar-colors-1 { background: linear-gradient(135deg, #4a1942, #8B1A5B); }
.avatar-colors-2 { background: linear-gradient(135deg, #1a3944, #0D5765); }
.avatar-colors-3 { background: linear-gradient(135deg, #3B1A08, #8B4513); }
.avatar-colors-4 { background: linear-gradient(135deg, #1A1A3E, #3D3D8F); }
.avatar-colors-5 { background: linear-gradient(135deg, #3E1A1A, #8B2222); }

.bot-indicator {
    position: absolute;
    bottom: -1px;
    right: -1px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid var(--bg-secondary);
    font-size: 7px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.bot-indicator.active { background: var(--bot-active); }
.bot-indicator.paused { background: var(--bot-paused); }

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

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

.conv-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.conv-time {
    font-size: 11px;
    color: var(--text-muted);
    flex-shrink: 0;
    margin-left: 8px;
}

.conv-preview {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 4px;
}

.conv-preview .direction-icon {
    font-size: 10px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.bot-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 10px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 10px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.bot-badge.active {
    background: rgba(0, 168, 132, 0.15);
    color: var(--bot-active);
}

.bot-badge.paused {
    background: rgba(240, 180, 41, 0.15);
    color: var(--bot-paused);
}

.empty-sidebar {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: var(--text-muted);
    padding: 40px;
    text-align: center;
}

.empty-sidebar-icon {
    font-size: 48px;
    opacity: 0.4;
}

/* ─── Main Chat Area ────────────────────────────────────────────────────── */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    background: var(--bg-primary);
    position: relative;
}

/* Subtle background pattern */
.chat-area::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M30 10c-.55 0-1 .45-1 1v1.07C17.4 13.07 8.07 22.4 8.07 34c0 .55.45 1 1 1s1-.45 1-1C10.07 23.51 19.51 14.07 30 14.07V15c0 .55.45 1 1 1s1-.45 1-1v-4c0-.55-.45-1-1-1z' fill='%23ffffff' fill-opacity='0.01'/%3E%3C/svg%3E");
    pointer-events: none;
    opacity: 0.5;
}

/* Chat Header */
.chat-header {
    height: var(--header-height);
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px 0 16px;
    flex-shrink: 0;
    z-index: 10;
}

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

.chat-header-info .contact-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
}

.chat-header-info .contact-sub {
    font-size: 12px;
    color: var(--text-secondary);
}

.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Toggle Button */
.btn-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border-radius: 20px;
    border: none;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    transition: all 0.25s ease;
    letter-spacing: 0.3px;
}

.btn-toggle.bot-on {
    background: rgba(0, 168, 132, 0.15);
    color: var(--bot-active);
    border: 1px solid rgba(0, 168, 132, 0.3);
}

.btn-toggle.bot-on:hover {
    background: rgba(0, 168, 132, 0.25);
    transform: scale(1.02);
}

.btn-toggle.bot-off {
    background: rgba(240, 180, 41, 0.15);
    color: var(--bot-paused);
    border: 1px solid rgba(240, 180, 41, 0.3);
}

.btn-toggle.bot-off:hover {
    background: rgba(240, 180, 41, 0.25);
    transform: scale(1.02);
}

.toggle-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
    animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%       { opacity: 0.6; transform: scale(0.85); }
}

.btn-toggle.bot-off .toggle-dot { animation: none; opacity: 0.7; }

/* ─── Messages ──────────────────────────────────────────────────────────── */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 16px 8%;
    display: flex;
    flex-direction: column;
    gap: 4px;
    position: relative;
    z-index: 1;
}

.messages-container::-webkit-scrollbar { width: 5px; }
.messages-container::-webkit-scrollbar-track { background: transparent; }
.messages-container::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

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

.date-separator::before,
.date-separator::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

.date-label {
    font-size: 11px;
    color: var(--text-muted);
    background: var(--bg-tertiary);
    padding: 3px 10px;
    border-radius: 10px;
    border: 1px solid var(--border);
    white-space: nowrap;
}

/* Message bubble */
.message-row {
    display: flex;
    margin-bottom: 2px;
}

.message-row.outbound { justify-content: flex-end; }
.message-row.inbound  { justify-content: flex-start; }

.bubble {
    max-width: 65%;
    padding: 8px 12px;
    border-radius: var(--radius-lg);
    position: relative;
    box-shadow: var(--shadow-sm);
    animation: bubble-in 0.2s ease-out;
}

@keyframes bubble-in {
    from { opacity: 0; transform: translateY(6px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.bubble.outbound {
    background: var(--bubble-out);
    border-bottom-right-radius: 4px;
    color: var(--text-primary);
}

.bubble.inbound {
    background: var(--bubble-in);
    border-bottom-left-radius: 4px;
    color: var(--text-primary);
}

.bubble-text {
    font-size: 14px;
    line-height: 1.4;
    word-break: break-word;
}

.bubble-meta {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 4px;
    justify-content: flex-end;
}

.bubble-time {
    font-size: 10px;
    color: rgba(233, 237, 239, 0.55);
    white-space: nowrap;
}

.bubble-status {
    font-size: 11px;
    color: rgba(233, 237, 239, 0.55);
}

.messages-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: var(--text-muted);
}

.messages-empty-icon {
    font-size: 64px;
    opacity: 0.2;
}

/* ─── Input Area ────────────────────────────────────────────────────────── */
.input-area {
    background: var(--bg-tertiary);
    border-top: 1px solid var(--border);
    padding: 12px 16px;
    flex-shrink: 0;
    z-index: 10;
}

.input-row {
    display: flex;
    align-items: flex-end;
    gap: 10px;
}

.input-field {
    flex: 1;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 22px;
    padding: 10px 18px;
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    outline: none;
    resize: none;
    min-height: 44px;
    max-height: 120px;
    line-height: 1.4;
    transition: border-color 0.2s, background 0.2s;
    overflow-y: auto;
}

.input-field::placeholder { color: var(--text-muted); }

.input-field:focus {
    border-color: var(--green);
    background: var(--bg-hover);
}

.btn-send {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: var(--green);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0, 168, 132, 0.4);
}

.btn-send:hover {
    background: #00C49A;
    transform: scale(1.08);
    box-shadow: 0 4px 16px rgba(0, 168, 132, 0.5);
}

.btn-send:active { transform: scale(0.95); }

.btn-send svg { transition: transform 0.2s; }
.btn-send:hover svg { transform: rotate(-15deg); }

.input-hint {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 6px;
    text-align: center;
}

.input-hint.bot-paused-hint {
    color: var(--bot-paused);
    font-weight: 500;
}

/* ─── Welcome Screen ───────────────────────────────────────────────────── */
.welcome-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    color: var(--text-muted);
    padding: 40px;
    text-align: center;
    border-left: 1px solid var(--border);
}

.welcome-icon {
    width: 120px;
    height: 120px;
    background: linear-gradient(135deg, rgba(0,168,132,0.15), rgba(0,168,132,0.05));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 52px;
    border: 1px solid rgba(0,168,132,0.2);
    margin-bottom: 8px;
}

.welcome-title {
    font-size: 22px;
    font-weight: 600;
    color: var(--text-primary);
}

.welcome-sub {
    font-size: 14px;
    max-width: 300px;
    line-height: 1.6;
}

/* ─── Notifications / Toast ─────────────────────────────────────────────── */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 12px 18px;
    font-size: 13px;
    color: var(--text-primary);
    box-shadow: var(--shadow-lg);
    animation: toast-in 0.3s ease-out;
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: 320px;
}

.toast.success { border-left: 3px solid var(--green); }
.toast.error   { border-left: 3px solid #E53E3E; }
.toast.info    { border-left: 3px solid #3182CE; }

@keyframes toast-in {
    from { opacity: 0; transform: translateX(20px); }
    to   { opacity: 1; transform: translateX(0); }
}

/* ─── Loading Spinner ───────────────────────────────────────────────────── */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,0.2);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

/* ─── Auto-refresh indicator ────────────────────────────────────────────── */
.refresh-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--green);
    animation: pulse-dot 2s infinite;
    display: inline-block;
    margin-left: 6px;
}

/* ─── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    :root { --sidebar-width: 100vw; }

    .app { flex-direction: column; }

    .sidebar {
        width: 100%;
        height: 50vh;
        min-width: unset;
    }

    .chat-area { height: 50vh; }
}

/* ── New Chat Button ──────────────────────────────────────────────────── */
.btn-new-chat {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    white-space: nowrap;
}
.btn-new-chat:hover  { background: var(--accent-hover); transform: scale(1.03); }
.btn-new-chat:active { transform: scale(0.97); }

/* ── Modal ────────────────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.15s ease;
}
.modal-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    width: 420px;
    max-width: 90vw;
    box-shadow: 0 24px 60px rgba(0,0,0,0.5);
    animation: slideUp 0.2s ease;
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px 0;
}
.modal-header h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}
.modal-close {
    background: none;
    border: none;
    font-size: 22px;
    color: var(--text-secondary);
    cursor: pointer;
    line-height: 1;
    padding: 0 4px;
    transition: color 0.2s;
}
.modal-close:hover { color: var(--text-primary); }
.modal-body  { padding: 20px 24px; }
.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 0 24px 20px;
}
.modal-label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}
.modal-input {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text-primary);
    font-size: 14px;
    padding: 10px 14px;
    outline: none;
    font-family: inherit;
    box-sizing: border-box;
    transition: border-color 0.2s;
}
.modal-input:focus { border-color: var(--accent); }
.btn-modal-cancel {
    padding: 9px 18px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-secondary);
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s;
}
.btn-modal-cancel:hover { background: var(--hover); }
.btn-modal-send {
    padding: 9px 18px;
    border-radius: 10px;
    border: none;
    background: var(--accent);
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}
.btn-modal-send:hover    { background: var(--accent-hover); }
.btn-modal-send:disabled { opacity: 0.6; cursor: not-allowed; }

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

/* ── Modal Tabs ───────────────────────────────────────────────────────── */
.modal-tabs {
    display: flex;
    gap: 8px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 12px;
}
.modal-tab {
    flex: 1;
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}
.modal-tab:hover  { background: var(--hover); color: var(--text-primary); }
.modal-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }
