/* ──────────────────────────────────────────────
   ZeroBra Chat Dashboard — Pastel Theme
   Mobile-first, responsive design
   ────────────────────────────────────────────── */

:root {
    --primary: #d4649a;
    --primary-light: #f0a6c7;
    --primary-dark: #b84d80;
    --primary-bg: #fdf2f8;

    --bg: #faf8fc;
    --bg-warm: #fef7f0;
    --surface: #ffffff;
    --surface-hover: #f9f5ff;
    --surface-alt: #f3f0f9;

    --text: #3d3352;
    --text-secondary: #7c6f8a;
    --text-light: #b0a5be;

    --border: #ede8f5;
    --border-light: #f5f1fb;

    --green: #7dc9a0;
    --green-bg: #edf8f2;
    --green-text: #2d6a4f;

    --red: #e88a8a;
    --red-bg: #fdf0f0;
    --red-text: #9b2c2c;

    --orange: #f0b87a;
    --orange-bg: #fef6ec;
    --orange-text: #8a5a1e;

    --blue: #8ab4f0;
    --blue-bg: #eef4fd;
    --blue-text: #1e4a8a;

    --purple: #b49ae0;
    --purple-bg: #f3effc;
    --purple-text: #4a2d8a;

    --lavender: #c4b5e0;
    --peach: #f5c6aa;
    --mint: #a8dcc8;
    --lemon: #f5e6a3;

    --inbound-bg: #ffffff;
    --outbound-bg: #edf8f2;

    --shadow-sm: 0 1px 3px rgba(100, 80, 140, 0.06);
    --shadow: 0 2px 8px rgba(100, 80, 140, 0.08);
    --shadow-lg: 0 4px 16px rgba(100, 80, 140, 0.1);
    --radius: 12px;
    --radius-lg: 18px;
    --radius-xl: 24px;
}

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

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

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

/* ── Sidebar ── */
.sidebar {
    width: 380px;
    min-width: 380px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-header {
    padding: 20px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(135deg, var(--primary-bg), #f9f0ff);
}

.logo {
    font-size: 22px;
    font-weight: 800;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, var(--primary), var(--purple));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-actions { display: flex; gap: 8px; }

.icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 10px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}
.icon-btn:hover { background: var(--surface-hover); color: var(--primary); }

/* Stats */
.stats-bar {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    padding: 14px 20px;
    gap: 10px;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
}
.stat {
    text-align: center;
    padding: 10px 6px;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-light);
}
.stat:nth-child(1) .stat-value { color: var(--green); }
.stat:nth-child(2) .stat-value { color: var(--orange); }
.stat:nth-child(3) .stat-value { color: var(--purple); }
.stat:nth-child(4) .stat-value { color: var(--blue); }

.stat-value { display: block; font-size: 22px; font-weight: 800; }
.stat-label { font-size: 10px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.8px; font-weight: 600; margin-top: 2px; }

/* Filter Tabs */
.filter-tabs {
    display: flex;
    padding: 10px 16px;
    gap: 6px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}
.filter-tab {
    flex: 1;
    padding: 9px 8px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    border-radius: 10px;
    transition: all 0.2s;
}
.filter-tab:hover { background: var(--surface-hover); color: var(--text); }
.filter-tab.active {
    background: linear-gradient(135deg, var(--primary-light), var(--lavender));
    color: white;
    box-shadow: 0 2px 8px rgba(212, 100, 154, 0.25);
}

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

.convo-item {
    padding: 16px 22px;
    border-bottom: 1px solid var(--border-light);
    cursor: pointer;
    transition: all 0.15s;
    position: relative;
    border-left: 3px solid transparent;
}
.convo-item:hover { background: var(--surface-hover); }
.convo-item.active { background: var(--primary-bg); border-left-color: var(--primary); }
.convo-item.escalated { border-left-color: var(--orange); background: var(--orange-bg); }
.convo-item.has-draft { border-left-color: var(--blue); background: var(--blue-bg); }

.convo-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 5px;
}
.convo-name {
    font-weight: 700;
    font-size: 14px;
    color: var(--text);
}
.convo-time {
    font-size: 11px;
    color: var(--text-light);
    font-weight: 500;
}
.convo-preview {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 300px;
    line-height: 1.4;
}
.convo-badges {
    display: flex;
    gap: 6px;
    margin-top: 8px;
}
.badge {
    font-size: 10px;
    padding: 3px 10px;
    border-radius: 20px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.badge-active { background: var(--green-bg); color: var(--green-text); border: 1px solid var(--mint); }
.badge-escalated { background: var(--orange-bg); color: var(--orange-text); border: 1px solid var(--peach); }
.badge-resolved { background: var(--surface-alt); color: var(--text-secondary); border: 1px solid var(--border); }
.badge-draft { background: var(--blue-bg); color: var(--blue-text); border: 1px solid var(--blue); }
.badge-bot { background: var(--purple-bg); color: var(--purple-text); border: 1px solid var(--lavender); }

.empty-state {
    padding: 48px 20px;
    text-align: center;
    color: var(--text-light);
    font-size: 14px;
}

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

.empty-chat {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    background: linear-gradient(180deg, var(--bg), var(--primary-bg) 100%);
}
.empty-chat-icon { font-size: 72px; margin-bottom: 20px; filter: drop-shadow(0 4px 8px rgba(212,100,154,0.15)); }
.empty-chat h2 { font-size: 26px; margin-bottom: 8px; color: var(--text); font-weight: 800; }
.empty-chat p { font-size: 15px; color: var(--text-light); }

.active-chat {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Chat Header */
.chat-header {
    padding: 14px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 14px;
    box-shadow: var(--shadow-sm);
}
.back-btn { display: none; }
.chat-header-info { flex: 1; min-width: 0; }
.chat-header-info h3 { font-size: 16px; font-weight: 700; color: var(--text); }
.phone-number { font-size: 12px; color: var(--text-light); font-weight: 500; }
.chat-header-actions { display: flex; gap: 10px; align-items: center; }
.status-select {
    padding: 7px 12px;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    transition: border-color 0.2s;
}
.status-select:focus { border-color: var(--primary-light); outline: none; }

/* Draft Banner */
.draft-banner {
    background: linear-gradient(135deg, var(--blue-bg), #f0f0ff);
    border-bottom: 2px solid var(--blue);
    padding: 18px 24px;
}
.draft-label {
    font-size: 11px;
    font-weight: 800;
    color: var(--blue);
    text-transform: uppercase;
    letter-spacing: 1.5px;
    margin-bottom: 10px;
}
.draft-original {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 10px;
    padding: 10px 14px;
    background: white;
    border-radius: 10px;
    border: 1px solid var(--border-light);
    line-height: 1.5;
}
.draft-reply-text {
    padding: 12px 14px;
    background: white;
    border: 2px solid var(--blue);
    border-radius: 10px;
    font-size: 14px;
    line-height: 1.6;
    min-height: 60px;
    max-height: 150px;
    overflow-y: auto;
    outline: none;
    margin-bottom: 12px;
    font-family: inherit;
}
.draft-reply-text:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(212,100,154,0.1); }
.draft-actions { display: flex; gap: 10px; }

/* Messages */
.messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    -webkit-overflow-scrolling: touch;
    background: linear-gradient(180deg, var(--bg) 0%, #f5f2fa 100%);
}

.message {
    max-width: 72%;
    padding: 12px 16px;
    border-radius: var(--radius-lg);
    font-size: 14px;
    line-height: 1.6;
    position: relative;
    word-wrap: break-word;
    box-shadow: var(--shadow-sm);
}
.message-inbound {
    align-self: flex-start;
    background: var(--surface);
    border: 1px solid var(--border-light);
    border-bottom-left-radius: 6px;
}
.message-outbound {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--green-bg), #e8f5e8);
    border: 1px solid #d4edda;
    border-bottom-right-radius: 6px;
}
.message-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 6px;
    gap: 10px;
}
.message-sender {
    font-size: 11px;
    font-weight: 700;
    color: var(--primary);
}
.message-outbound .message-sender { color: var(--green-text); }
.message-time {
    font-size: 10px;
    color: var(--text-light);
    white-space: nowrap;
    font-weight: 500;
}
.message-content {
    white-space: pre-wrap;
}
.message-content a {
    color: var(--primary-dark);
    text-decoration: underline;
    text-decoration-color: var(--primary-light);
    text-underline-offset: 2px;
    word-break: break-all;
}
.message-content a:hover {
    color: var(--primary);
    text-decoration-color: var(--primary);
}

/* Interactive button pills inside messages */
.message-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid rgba(0,0,0,0.06);
}
.msg-btn-pill {
    display: inline-block;
    padding: 6px 14px;
    background: var(--primary-bg);
    color: var(--primary-dark);
    border: 1.5px solid var(--primary-light);
    border-radius: 20px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.2px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}
.msg-btn-pill:hover {
    background: var(--primary-light);
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(212,100,154,0.25);
}
.message-inbound .msg-btn-pill {
    background: var(--blue-bg);
    color: var(--blue-text);
    border-color: var(--blue);
}
.message-inbound .msg-btn-pill:hover {
    background: var(--blue);
    color: white;
}

/* Order Panel */
.order-panel {
    background: var(--surface);
    border-top: 1px solid var(--border);
    max-height: 250px;
    overflow-y: auto;
    padding: 18px 24px;
    box-shadow: 0 -2px 8px rgba(100,80,140,0.05);
}
.order-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
}
.order-panel-header h4 { font-size: 14px; font-weight: 700; color: var(--text); }
.order-card {
    padding: 12px 14px;
    background: var(--bg);
    border-radius: var(--radius);
    margin-bottom: 10px;
    font-size: 13px;
    border: 1px solid var(--border-light);
    line-height: 1.6;
}
.order-card strong { color: var(--text); font-weight: 700; }
.order-status {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
}
.order-status-fulfilled { background: var(--green-bg); color: var(--green-text); }
.order-status-unfulfilled { background: var(--orange-bg); color: var(--orange-text); }
.order-status-paid { background: var(--green-bg); color: var(--green-text); }

.order-actions {
    margin-top: 8px;
    display: flex;
    gap: 6px;
}
.order-action-btn {
    padding: 5px 12px;
    border: 1.5px solid var(--primary-light);
    background: var(--primary-bg);
    color: var(--primary-dark);
    border-radius: 8px;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
}
.order-action-btn:hover {
    background: var(--primary-light);
    color: white;
}

/* Reply Box */
.reply-box {
    padding: 14px 24px 16px;
    background: var(--surface);
    border-top: 1px solid var(--border);
}
.reply-mode-toggle {
    display: flex;
    gap: 6px;
    margin-bottom: 10px;
}
.reply-mode-btn {
    flex: 1;
    padding: 8px 12px;
    border: 2px solid var(--border);
    background: var(--surface);
    border-radius: 10px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 700;
    color: var(--text-secondary);
    transition: all 0.2s;
}
.reply-mode-btn.active {
    border-color: var(--primary);
    background: var(--primary-bg);
    color: var(--primary);
}
.reply-mode-btn:last-child.active {
    border-color: var(--orange);
    background: var(--orange-bg);
    color: var(--orange-text);
}
.reply-mode-btn:hover:not(.active) {
    border-color: var(--lavender);
    background: var(--surface-hover);
}

.reply-input-wrap {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}
#reply-input {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: inherit;
    resize: none;
    max-height: 120px;
    outline: none;
    transition: all 0.2s;
    background: var(--bg);
    color: var(--text);
}
#reply-input:focus {
    border-color: var(--primary-light);
    background: white;
    box-shadow: 0 0 0 3px rgba(212,100,154,0.08);
}
#reply-input::placeholder { color: var(--text-light); }

.send-btn {
    width: 46px;
    height: 46px;
    border: none;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: white;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(212,100,154,0.3);
}
.send-btn:hover { transform: scale(1.05); box-shadow: 0 4px 12px rgba(212,100,154,0.4); }
.send-btn:disabled { background: var(--border); box-shadow: none; cursor: not-allowed; transform: none; }

.reply-shortcuts {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
    max-height: 72px;
    overflow-y: auto;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
}
.shortcut-btn {
    padding: 6px 14px;
    border: 1.5px solid var(--border);
    background: var(--surface);
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
    color: var(--text-secondary);
}
.shortcut-btn:hover {
    border-color: var(--primary-light);
    color: var(--primary);
    background: var(--primary-bg);
    box-shadow: 0 2px 6px rgba(212,100,154,0.12);
}

/* Buttons */
.btn {
    padding: 9px 18px;
    border: none;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    letter-spacing: 0.2px;
}
.btn-primary { background: linear-gradient(135deg, var(--blue), #a0c4f0); color: white; box-shadow: 0 2px 6px rgba(138,180,240,0.3); }
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 4px 10px rgba(138,180,240,0.4); }
.btn-success { background: linear-gradient(135deg, var(--green), var(--mint)); color: white; box-shadow: 0 2px 6px rgba(125,201,160,0.3); }
.btn-success:hover { transform: translateY(-1px); box-shadow: 0 4px 10px rgba(125,201,160,0.4); }
.btn-danger { background: linear-gradient(135deg, var(--red), #f0aaaa); color: white; box-shadow: 0 2px 6px rgba(232,138,138,0.3); }
.btn-danger:hover { transform: translateY(-1px); box-shadow: 0 4px 10px rgba(232,138,138,0.4); }
.btn-secondary { background: var(--surface-alt); color: var(--text); border: 1.5px solid var(--border); }
.btn-secondary:hover { background: var(--surface-hover); border-color: var(--lavender); }

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(61, 51, 82, 0.3);
    backdrop-filter: blur(4px);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.modal-content {
    background: var(--surface);
    border-radius: var(--radius-xl);
    width: 100%;
    max-width: 440px;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-light);
}
.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: linear-gradient(135deg, var(--primary-bg), var(--purple-bg));
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
}
.modal-header h3 { font-size: 18px; font-weight: 700; color: var(--text); }
.modal-body { padding: 24px; }
.setting-group { margin-bottom: 22px; }
.setting-group label { font-size: 14px; font-weight: 700; display: block; margin-bottom: 10px; color: var(--text); }
.setting-desc { font-size: 12px; color: var(--text-secondary); margin-top: 8px; line-height: 1.5; }
.setting-input {
    width: 100%;
    padding: 11px 14px;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    font-size: 14px;
    background: var(--bg);
    color: var(--text);
    font-family: inherit;
}
.toggle-group { display: flex; gap: 10px; }
.toggle-btn {
    flex: 1;
    padding: 12px;
    border: 2px solid var(--border);
    background: var(--surface);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 13px;
    font-weight: 700;
    transition: all 0.2s;
    color: var(--text-secondary);
}
.toggle-btn.active {
    border-color: var(--primary);
    background: var(--primary-bg);
    color: var(--primary);
    box-shadow: 0 2px 8px rgba(212,100,154,0.15);
}
.toggle-btn:hover:not(.active) { border-color: var(--lavender); background: var(--surface-hover); }

/* Notification toast */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: linear-gradient(135deg, var(--text), #4a3d66);
    color: white;
    padding: 14px 22px;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    box-shadow: var(--shadow-lg);
    z-index: 200;
    animation: slideUp 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes slideUp {
    from { transform: translateY(24px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* ── Mobile Responsive ── */
@media (max-width: 768px) {
    .sidebar {
        width: 100%;
        min-width: 100%;
        position: absolute;
        inset: 0;
        z-index: 10;
        transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    }
    .sidebar.hidden {
        transform: translateX(-100%);
    }
    .chat-area {
        position: absolute;
        inset: 0;
    }
    .back-btn { display: flex !important; }
    .convo-preview { max-width: calc(100vw - 140px); }
    .message { max-width: 85%; }
    .stats-bar { padding: 10px 12px; gap: 8px; }
    .stat { padding: 8px 4px; }
    .stat-value { font-size: 18px; }
    .modal-content { margin: 16px; }
    .reply-shortcuts { gap: 6px; }
    .sidebar-header { padding: 16px 18px; }
    .chat-header { padding: 12px 16px; gap: 10px; }
    .messages { padding: 16px; }
    .reply-box { padding: 12px 16px; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--lavender); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--purple); }

/* Animations */
.convo-item { animation: fadeIn 0.25s cubic-bezier(0.16, 1, 0.3, 1); }
.message { animation: fadeIn 0.2s cubic-bezier(0.16, 1, 0.3, 1); }
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Selection color */
::selection { background: var(--primary-light); color: white; }
