/* ═══════════════════════════════════════════════════════════════
   WhatsApp CRM — Stylesheet
   ═══════════════════════════════════════════════════════════════ */

:root {
    --primary: #0f766e;
    --primary-dark: #0d5c56;
    --primary-light: #99f6e4;
    --bg: #f1f5f9;
    --bg-white: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-light: #64748b;
    --text-muted: #94a3b8;
    --danger: #dc2626;
    --warning: #f59e0b;
    --success: #16a34a;
    --info: #2563eb;
    --inbound-bg: #ffffff;
    --outbound-bg: #d1fae5;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    --radius: 8px;
}

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

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

/* ── Login ─────────────────────────────────────────────────── */

#login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
}

.login-box {
    background: var(--bg-white);
    padding: 40px;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
    width: 380px;
    max-width: 90vw;
}

.login-box h1 {
    font-size: 22px;
    margin-bottom: 6px;
    color: var(--primary-dark);
}

.login-box p {
    color: var(--text-light);
    margin-bottom: 24px;
    font-size: 14px;
}

.login-box input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    margin-bottom: 12px;
    outline: none;
    transition: border 0.2s;
}

.login-box input:focus { border-color: var(--primary); }

.login-box button {
    width: 100%;
    padding: 11px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.login-box button:hover { background: var(--primary-dark); }

.login-error {
    color: var(--danger);
    font-size: 13px;
    margin-top: 10px;
    display: none;
}

/* ── App Layout ────────────────────────────────────────────── */

#app-screen { display: none; height: 100vh; flex-direction: column; }
#app-screen.active { display: flex; }
#login-screen.hidden { display: none; }

/* ── Header ────────────────────────────────────────────────── */

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

.header-left {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 16px;
}

.header-logo {
    width: 28px;
    height: 28px;
    background: rgba(255,255,255,0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

.header-nav {
    display: flex;
    gap: 4px;
    margin-left: 16px;
}

.nav-btn {
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    color: rgba(255,255,255,0.8);
    padding: 5px 14px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    transition: all 0.2s;
}

.nav-btn:hover { background: rgba(255,255,255,0.2); color: white; }
.nav-btn.active { background: rgba(255,255,255,0.25); color: white; border-color: rgba(255,255,255,0.4); }

.header-right {
    display: flex;
    align-items: center;
    gap: 14px;
    font-size: 13px;
}

.header-right .agent-name { opacity: 0.9; }

#btn-logout {
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.3);
    color: white;
    padding: 5px 14px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: background 0.2s;
}

#btn-logout:hover { background: rgba(255,255,255,0.25); }

/* ── View containers ──────────────────────────────────────── */

.view-container {
    flex: 1;
    overflow: hidden;
}

#view-chat {
    display: flex;
}

#view-chat.hidden { display: none; }

/* ── Main 3-panel layout ───────────────────────────────────── */

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

/* ── Left Panel — Conversations ────────────────────────────── */

.panel-left {
    width: 300px;
    min-width: 300px;
    border-right: 1px solid var(--border);
    background: var(--bg-white);
    display: flex;
    flex-direction: column;
}

.panel-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.filter-bar {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.filter-bar select {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 13px;
    outline: none;
    background: white;
}

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

.conv-item {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.15s;
    display: flex;
    gap: 10px;
}

.conv-item:hover { background: #f8fafc; }
.conv-item.active { background: #ecfdf5; border-left: 3px solid var(--primary); }

.conv-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary-light);
    color: var(--primary-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 15px;
    flex-shrink: 0;
}

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

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

.conv-name {
    font-weight: 600;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

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

.conv-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.badge {
    font-size: 10px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 10px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    flex-shrink: 0;
    margin-left: 6px;
}

.badge-new     { background: #dbeafe; color: #1d4ed8; }
.badge-open    { background: #d1fae5; color: #15803d; }
.badge-pending { background: #fef3c7; color: #b45309; }
.badge-closed  { background: #f1f5f9; color: #64748b; }
.badge-source  { background: #ede9fe; color: #6d28d9; }

/* ── Center Panel — Chat ──────────────────────────────────── */

.panel-center {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #eef2f7;
    min-width: 0;
}

.chat-header {
    padding: 10px 20px;
    background: var(--bg-white);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.chat-header-info h3 {
    font-size: 15px;
    margin-bottom: 2px;
}

.chat-header-info span {
    font-size: 12px;
    color: var(--text-light);
}

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

.chat-header-actions select,
.chat-header-actions button {
    padding: 5px 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 12px;
    background: white;
    cursor: pointer;
}

.chat-header-actions button:hover { background: #f1f5f9; }

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.msg {
    max-width: 65%;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 14px;
    line-height: 1.4;
    position: relative;
    word-wrap: break-word;
}

.msg-inbound {
    background: var(--inbound-bg);
    align-self: flex-start;
    border-bottom-left-radius: 2px;
    box-shadow: var(--shadow);
}

.msg-outbound {
    background: var(--outbound-bg);
    align-self: flex-end;
    border-bottom-right-radius: 2px;
    box-shadow: var(--shadow);
}

.msg-time {
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 4px;
    text-align: right;
}

.msg-type-label {
    font-size: 11px;
    color: var(--text-light);
    font-style: italic;
    margin-bottom: 2px;
}

.chat-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    color: var(--text-muted);
    font-size: 15px;
}

.chat-input-bar {
    display: flex;
    padding: 12px 16px;
    background: var(--bg-white);
    border-top: 1px solid var(--border);
    gap: 10px;
    flex-shrink: 0;
}

.chat-input-bar input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 14px;
    outline: none;
}

.chat-input-bar input:focus { border-color: var(--primary); }

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

#btn-send:hover { background: var(--primary-dark); }
#btn-send:disabled { background: var(--text-muted); cursor: not-allowed; }

/* ── Right Panel — Contact / Lead ──────────────────────────── */

.panel-right {
    width: 300px;
    min-width: 300px;
    border-left: 1px solid var(--border);
    background: var(--bg-white);
    overflow-y: auto;
}

.contact-card {
    padding: 24px 20px;
    text-align: center;
    border-bottom: 1px solid var(--border);
}

.contact-avatar {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--primary-light);
    color: var(--primary-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
    font-weight: 700;
    margin: 0 auto 12px;
}

.contact-card h3 { font-size: 16px; margin-bottom: 4px; }

.contact-card .phone {
    font-size: 13px;
    color: var(--text-light);
    margin-bottom: 2px;
}

.contact-card .email {
    font-size: 13px;
    color: var(--text-light);
}

.detail-section {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.detail-section h4 {
    font-size: 12px;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.5px;
    margin-bottom: 10px;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    font-size: 13px;
}

.detail-row label { color: var(--text-light); }
.detail-row span, .detail-row select { font-weight: 500; }

.detail-row select {
    padding: 3px 6px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 13px;
    background: white;
}

.notes-area {
    width: 100%;
    min-height: 80px;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    font-family: inherit;
    resize: vertical;
    outline: none;
}

.notes-area:focus { border-color: var(--primary); }

.btn-save-notes {
    margin-top: 8px;
    padding: 6px 14px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-save-notes:hover { background: var(--primary-dark); }

.btn-create-lead {
    width: 100%;
    padding: 8px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-create-lead:hover { background: var(--primary-dark); }

.panel-right-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    font-size: 14px;
    padding: 20px;
    text-align: center;
}

/* ══════════════════════════════════════════════════════════════
   KANBAN / PIPELINE
   ══════════════════════════════════════════════════════════════ */

.kanban-container {
    display: flex;
    gap: 12px;
    padding: 16px;
    height: 100%;
    overflow-x: auto;
}

.kanban-column {
    min-width: 260px;
    width: 260px;
    background: var(--bg);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    max-height: 100%;
}

.kanban-column-header {
    padding: 12px 14px;
    background: var(--bg-white);
    border-radius: 8px 8px 0 0;
    border-bottom: 1px solid var(--border);
}

.kanban-column-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    font-size: 14px;
}

.kanban-count {
    font-size: 11px;
    background: var(--border);
    padding: 2px 7px;
    border-radius: 10px;
    font-weight: 700;
    color: var(--text-light);
}

.kanban-value {
    font-size: 12px;
    color: var(--success);
    font-weight: 600;
    margin-top: 4px;
}

.kanban-cards {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 50px;
    transition: background 0.2s;
}

.kanban-cards.drag-over {
    background: rgba(15, 118, 110, 0.08);
    border-radius: 0 0 8px 8px;
}

.kanban-card {
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 12px;
    cursor: pointer;
    transition: box-shadow 0.2s, transform 0.15s;
    user-select: none;
}

.kanban-card:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transform: translateY(-1px);
}

.kanban-card.dragging {
    opacity: 0.5;
    transform: rotate(2deg);
}

.kanban-card-name {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 2px;
}

.kanban-card-phone {
    font-size: 12px;
    color: var(--text-light);
    margin-bottom: 4px;
}

.kanban-card-value {
    font-size: 13px;
    font-weight: 700;
    color: var(--success);
    margin-bottom: 4px;
}

.kanban-card-agent {
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.kanban-card-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 4px;
}

.kanban-card-date {
    font-size: 11px;
    color: var(--text-muted);
}

.kanban-card-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 6px;
}

.tag-pill {
    font-size: 10px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.tag-remove {
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    opacity: 0.7;
}

.tag-remove:hover { opacity: 1; }

/* ══════════════════════════════════════════════════════════════
   MODAL
   ══════════════════════════════════════════════════════════════ */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal-content {
    background: var(--bg-white);
    border-radius: 12px;
    width: 780px;
    max-width: 95vw;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
}

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

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-light);
    line-height: 1;
    padding: 4px;
}

.modal-close:hover { color: var(--text); }

.modal-body {
    padding: 20px 24px;
}

.modal-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

.modal-col .detail-section {
    padding: 0 0 16px 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 16px;
}

.modal-col .detail-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

/* ── History entries ──────────────────────────────────────── */

.history-entry {
    padding: 8px 0;
    border-bottom: 1px solid #f1f5f9;
    font-size: 13px;
}

.history-entry:last-child { border-bottom: none; }

.history-change { margin-bottom: 2px; }

.history-old {
    color: var(--danger);
    text-decoration: line-through;
}

.history-new {
    color: var(--success);
    font-weight: 500;
}

.history-meta {
    font-size: 11px;
    color: var(--text-muted);
}

/* ══════════════════════════════════════════════════════════════
   DASHBOARD
   ══════════════════════════════════════════════════════════════ */

.dashboard-container {
    padding: 24px;
    max-width: 900px;
    margin: 0 auto;
    overflow-y: auto;
    height: 100%;
}

.dashboard-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 20px;
    text-align: center;
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 4px;
}

.stat-label {
    font-size: 12px;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.dashboard-section {
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 24px;
}

.dashboard-section h3 {
    font-size: 14px;
    margin-bottom: 16px;
    color: var(--text);
}

/* Funnel */
.funnel-container { display: flex; flex-direction: column; gap: 8px; }

.funnel-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.funnel-label {
    width: 120px;
    font-size: 13px;
    font-weight: 500;
    text-transform: capitalize;
    flex-shrink: 0;
}

.funnel-label span {
    color: var(--text-muted);
    font-weight: 400;
}

.funnel-bar-wrap {
    flex: 1;
    background: #f1f5f9;
    border-radius: 4px;
    height: 28px;
    overflow: hidden;
}

.funnel-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--primary-light));
    border-radius: 4px;
    display: flex;
    align-items: center;
    padding: 0 8px;
    font-size: 11px;
    font-weight: 600;
    color: var(--primary-dark);
    min-width: 30px;
    transition: width 0.5s;
}

/* Source grid */
.source-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.source-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
}

/* Timeline chart */
.timeline-chart {
    display: flex;
    align-items: flex-end;
    height: 120px;
    gap: 2px;
}

.timeline-bar-wrap {
    flex: 1;
    height: 100%;
    display: flex;
    align-items: flex-end;
}

.timeline-bar {
    width: 100%;
    background: var(--primary);
    border-radius: 2px 2px 0 0;
    min-height: 2px;
    transition: height 0.3s;
}

.timeline-labels {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 6px;
}

/* ══════════════════════════════════════════════════════════════
   REMINDERS
   ══════════════════════════════════════════════════════════════ */

.reminder-wrapper {
    position: relative;
}

.reminder-bell {
    background: none;
    border: none;
    color: white;
    font-size: 18px;
    cursor: pointer;
    position: relative;
    padding: 4px;
    line-height: 1;
}

.reminder-badge {
    position: absolute;
    top: -4px;
    right: -6px;
    background: var(--danger);
    color: white;
    font-size: 10px;
    font-weight: 700;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.reminder-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    width: 320px;
    max-height: 360px;
    overflow-y: auto;
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
    z-index: 50;
    margin-top: 8px;
}

.reminder-empty {
    padding: 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

.reminder-item {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}

.reminder-item:last-child { border-bottom: none; }

.reminder-contact {
    font-weight: 600;
    margin-bottom: 2px;
    color: var(--text);
}

.reminder-msg {
    color: var(--text-light);
    margin-bottom: 4px;
}

.reminder-time {
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.reminder-dismiss {
    background: none;
    border: 1px solid var(--border);
    padding: 3px 10px;
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
    color: var(--text-light);
    transition: all 0.15s;
}

.reminder-dismiss:hover {
    background: #f1f5f9;
    color: var(--text);
}

/* ── Responsive ────────────────────────────────────────────── */

@media (max-width: 900px) {
    .panel-right { display: none; }
    .modal-grid { grid-template-columns: 1fr; }
    .dashboard-row { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 640px) {
    .panel-left { width: 100%; min-width: 100%; }
    .panel-center { display: none; }
    .panel-center.mobile-active { display: flex; position: absolute; inset: 52px 0 0 0; z-index: 10; }
    .header-nav { display: none; }
    .dashboard-row { grid-template-columns: 1fr; }
    .kanban-container { padding: 8px; }
    .kanban-column { min-width: 220px; width: 220px; }
}

/* ── Utilities ─────────────────────────────────────────────── */

.hidden { display: none !important; }

.toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: #1e293b;
    color: white;
    padding: 10px 20px;
    border-radius: 6px;
    font-size: 13px;
    z-index: 1000;
    animation: fadeIn 0.3s;
}

.toast.error { background: var(--danger); }

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

.conv-count {
    font-size: 12px;
    background: var(--primary-light);
    color: var(--primary-dark);
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 600;
}
