/* ===== SMP Sales App — Light Blue Professional (v3) ===== */

.smp-sales-app {
    --smp-primary: #2563eb;
    --smp-primary-soft: #3b82f6;
    --smp-primary-bg: #eff6ff;
    --smp-primary-bg2: #dbeafe;
    --smp-navy: #1e3a8a;
    --smp-text: #1e293b;
    --smp-muted: #64748b;
    --smp-border: #dbeafe;
    --smp-border-2: #bfdbfe;
    --smp-success: #059669;
    --smp-danger: #dc2626;
    --smp-warning: #d97706;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: var(--smp-text);
}

/* ── Navigation — xanh blue nhẹ, chuyên nghiệp ── */
.smp-app-nav {
    display: flex;
    gap: 4px;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 18px;
    background: linear-gradient(180deg, #ffffff, #f8fbff);
    border: 1px solid var(--smp-border-2);
    border-radius: 14px;
    padding: 6px;
    box-shadow: 0 2px 12px rgba(37,99,235,.08);
    scrollbar-width: thin;
}
.smp-app-nav::-webkit-scrollbar { height: 4px; }
.smp-app-nav::-webkit-scrollbar-thumb { background: var(--smp-border-2); border-radius: 4px; }
.smp-app-nav-item {
    position: relative;
    flex: 1 0 auto;
    min-width: 105px;
    padding: 11px 14px;
    border: none;
    background: transparent;
    border-radius: 9px;
    font-size: .84rem;
    font-weight: 600;
    color: var(--smp-muted);
    cursor: pointer;
    transition: all .18s;
    white-space: nowrap;
}
.smp-app-nav-item:hover { background: var(--smp-primary-bg); color: var(--smp-primary); }
.smp-app-nav-item.is-active {
    background: linear-gradient(135deg, var(--smp-primary-soft), var(--smp-primary));
    color: #fff;
    box-shadow: 0 3px 10px rgba(37,99,235,.35);
}
.smp-nav-badge {
    position: absolute;
    top: 2px; right: 4px;
    background: var(--smp-danger);
    color: #fff;
    font-size: .6rem;
    font-weight: 800;
    min-width: 16px; height: 16px;
    border-radius: 99px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    border: 2px solid #fff;
    box-shadow: 0 1px 4px rgba(220,38,38,.4);
}

/* ── Views ── */
.smp-app-view { display: none; }
.smp-app-view.is-active { display: block; animation: smpFadeIn .2s ease; }
@keyframes smpFadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ── Cards ── */
.smp-app-card {
    background: #fff;
    border: 1px solid var(--smp-border);
    border-radius: 14px;
    padding: 18px;
    box-shadow: 0 2px 10px rgba(37,99,235,.06);
}
.smp-app-card h3 {
    margin: 0 0 14px;
    font-size: .8rem;
    font-weight: 700;
    color: var(--smp-primary);
    text-transform: uppercase;
    letter-spacing: .06em;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--smp-primary-bg);
}

/* ── Stat cards ── */
.smp-app-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 13px;
    margin-bottom: 20px;
}
.smp-app-stat-card {
    background: linear-gradient(160deg, #ffffff 30%, var(--smp-primary-bg) 130%);
    border: 1px solid var(--smp-border);
    border-left: 4px solid var(--smp-primary-soft);
    border-radius: 12px;
    padding: 15px 14px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 2px 8px rgba(37,99,235,.07);
    transition: transform .15s, box-shadow .15s;
}
.smp-app-stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(37,99,235,.14);
}
.smp-app-stat-icon { font-size: 26px; line-height: 1; }
.smp-app-stat-card strong {
    display: block;
    font-size: 1.18rem;
    font-weight: 800;
    line-height: 1.2;
    color: var(--smp-navy);
}
.smp-app-stat-card span {
    font-size: .7rem;
    font-weight: 600;
    color: var(--smp-muted);
    text-transform: uppercase;
    letter-spacing: .02em;
}

/* ── Dashboard layout ── */
.smp-app-dash-cols {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}
.smp-dash-conv-item, .smp-dash-appt-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 11px;
    border-radius: 9px;
    cursor: pointer;
    transition: background .15s;
    border-bottom: 1px solid var(--smp-primary-bg);
}
.smp-dash-conv-item:hover { background: var(--smp-primary-bg); }
.smp-dash-conv-item strong { color: var(--smp-navy); }

/* ── Toolbar ── */
.smp-app-toolbar {
    display: flex;
    gap: 9px;
    align-items: center;
    margin-bottom: 15px;
    flex-wrap: wrap;
}
.smp-app-toolbar .smp-input,
.smp-app-toolbar .smp-select {
    border: 1.5px solid var(--smp-border-2);
    border-radius: 9px;
    font-weight: 500;
    background: #fff;
}
.smp-app-toolbar .smp-input:focus,
.smp-app-toolbar .smp-select:focus {
    border-color: var(--smp-primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.13);
    outline: none;
}

/* ── Tables — header xanh nhạt, sạch sẽ ── */
.smp-app-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .84rem;
}
.smp-app-table th {
    background: var(--smp-primary-bg);
    padding: 11px 9px;
    text-align: left;
    font-size: .68rem;
    font-weight: 700;
    color: var(--smp-navy);
    text-transform: uppercase;
    letter-spacing: .05em;
    border-bottom: 2px solid var(--smp-border-2);
    white-space: nowrap;
}
.smp-app-table th:first-child { border-radius: 8px 0 0 0; }
.smp-app-table th:last-child  { border-radius: 0 8px 0 0; }
.smp-app-table td {
    padding: 10px 9px;
    border-bottom: 1px solid var(--smp-primary-bg);
    vertical-align: middle;
    color: var(--smp-text);
}
.smp-app-table tbody tr { transition: background .12s; }
.smp-app-table tbody tr:hover { background: var(--smp-primary-bg); }
.smp-app-table code {
    background: var(--smp-primary-bg);
    border: 1px solid var(--smp-border);
    border-radius: 5px;
    padding: 2px 7px;
    font-size: .75rem;
    font-weight: 700;
    color: var(--smp-primary);
}

/* ── Mini buttons ── */
.smp-app-mini-btn {
    background: #fff;
    border: 1.5px solid var(--smp-border-2);
    border-radius: 7px;
    padding: 5px 9px;
    cursor: pointer;
    font-size: .78rem;
    font-weight: 600;
    transition: all .15s;
    color: var(--smp-text);
}
.smp-app-mini-btn:hover {
    background: var(--smp-primary);
    border-color: var(--smp-primary);
    color: #fff;
    box-shadow: 0 2px 6px rgba(37,99,235,.3);
}
.smp-app-close-btn {
    background: #fef2f2; border: none; cursor: pointer;
    font-size: 13px; color: var(--smp-danger);
    padding: 5px 9px; border-radius: 7px; font-weight: 700;
}
.smp-app-close-btn:hover { background: #fecaca; }

/* ── Buttons chính ── */
.smp-sales-app .smp-btn {
    cursor: pointer;
    border-radius: 9px;
    padding: 10px 19px;
    font-weight: 700;
    border: none;
    font-size: .84rem;
    transition: all .15s;
}
.smp-sales-app .smp-btn-primary {
    background: linear-gradient(135deg, var(--smp-primary-soft), var(--smp-primary));
    color: #fff;
    box-shadow: 0 2px 8px rgba(37,99,235,.3);
}
.smp-sales-app .smp-btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(37,99,235,.4);
}

/* ── Products layout ── */
.smp-app-products-layout { display: flex; gap: 16px; align-items: flex-start; }
.smp-app-product-form {
    width: 360px;
    flex-shrink: 0;
    border-top: 4px solid var(--smp-primary-soft);
}

/* ── Sales view ── */
.smp-app-view[data-view="sales"] .smp-inline-inbox {
    border: 1px solid var(--smp-border-2);
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 3px 14px rgba(37,99,235,.09);
}

/* ── Badge / channel tags ── */
.smp-sales-app .smp-badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 99px;
    font-size: .69rem;
    font-weight: 700;
    background: var(--smp-primary-bg);
    color: var(--smp-navy);
}
.smp-sales-app .smp-channel-tag {
    font-size: .66rem;
    padding: 3px 9px;
    border-radius: 99px;
    font-weight: 700;
    white-space: nowrap;
}
.smp-sales-app .smp-channel-tag.smp-channel-zalo      { background: #e0eeff; color: #0058d6; }
.smp-sales-app .smp-channel-tag.smp-channel-messenger { background: #dbeafe; color: #1d4ed8; }
.smp-sales-app .smp-channel-tag.smp-channel-shopee    { background: #ffe9e3; color: #d63916; }
.smp-sales-app .smp-channel-tag.smp-channel-tiktok    { background: #e2e8f0; color: #0f172a; }

/* ── Form fields ── */
.smp-sales-app .smp-cf-label { font-size: .75rem; font-weight: 700; color: var(--smp-navy); }
.smp-sales-app .smp-input,
.smp-sales-app .smp-select {
    border: 1.5px solid var(--smp-border-2);
    border-radius: 8px;
    color: var(--smp-text);
}
.smp-sales-app .smp-input:focus,
.smp-sales-app .smp-select:focus {
    outline: none;
    border-color: var(--smp-primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

/* ── CRM panel tabs ── */
.smp-sales-app .smp-crm-tabs {
    background: var(--smp-primary-bg);
    border-bottom: 2px solid var(--smp-border-2);
}
.smp-sales-app .smp-crm-tab { color: var(--smp-muted); font-weight: 700; padding: 12px 6px; }
.smp-sales-app .smp-crm-tab.is-active {
    color: #fff;
    background: var(--smp-primary);
    border-radius: 0;
    border-bottom-color: transparent;
}

/* ── Chat ── */
.smp-sales-app .smp-chat-header {
    background: linear-gradient(180deg, #fff, var(--smp-primary-bg));
    border-bottom: 2px solid var(--smp-border);
}
.smp-sales-app .smp-chat-conv-name { font-size: .94rem; color: var(--smp-navy); }
.smp-sales-app .smp-msg-out .smp-msg-bubble {
    background: linear-gradient(135deg, var(--smp-primary-soft), var(--smp-primary));
    box-shadow: 0 2px 6px rgba(37,99,235,.22);
}
.smp-sales-app .smp-msg-in .smp-msg-bubble {
    background: #fff;
    border: 1.5px solid var(--smp-border);
    box-shadow: 0 1px 3px rgba(37,99,235,.06);
}
.smp-sales-app .smp-conv-item.is-active {
    background: var(--smp-primary-bg2);
    border-left: 4px solid var(--smp-primary);
}
.smp-sales-app .smp-conv-item.is-unread .smp-conv-name {
    color: var(--smp-primary);
    font-weight: 800;
}

.smp-sales-app .smp-loading {
    text-align: center;
    padding: 26px;
    color: var(--smp-muted);
    font-weight: 600;
    font-size: .84rem;
}

/* ── Nút back mobile trong chat ── */
.smp-mobile-back-btn {
    display: none;
    background: var(--smp-primary-bg);
    border: 1px solid var(--smp-border-2);
    border-radius: 8px;
    padding: 6px 11px;
    cursor: pointer;
    font-weight: 700;
    color: var(--smp-primary);
    font-size: .8rem;
}

/* ═══════════════ RESPONSIVE MOBILE ═══════════════ */
@media (max-width: 900px) {
    .smp-app-dash-cols { grid-template-columns: 1fr; }
    .smp-app-products-layout { flex-direction: column; }
    .smp-app-product-form { width: 100%; }
    .smp-app-stats-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 9px; }
    .smp-app-stat-card { padding: 12px 11px; gap: 9px; }
    .smp-app-stat-card strong { font-size: 1rem; }
    .smp-app-stat-icon { font-size: 21px; }
    .smp-app-nav-item { min-width: 92px; font-size: .74rem; padding: 9px 9px; }

    /* Bảng cuộn ngang trên mobile */
    .smp-app-card { padding: 12px; overflow-x: auto; }
    .smp-app-table { min-width: 640px; font-size: .76rem; }
    .smp-app-table th, .smp-app-table td { padding: 8px 6px; }
}

@media (max-width: 768px) {
    /* Inbox 1 cột: danh sách trước, chọn hội thoại → hiện chat + nút back */
    .smp-inline-inbox-3col,
    .smp-inline-inbox {
        display: block !important;
        min-height: 70vh;
    }
    .smp-inline-inbox .smp-conv-sidebar { border-right: none; }
    .smp-inline-inbox .smp-inline-chat-main {
        display: none;
        height: 75vh;
    }
    .smp-inline-inbox.is-chat-open .smp-conv-sidebar { display: none; }
    .smp-inline-inbox.is-chat-open .smp-inline-chat-main { display: flex; }
    .smp-inline-inbox .smp-crm-panel { display: none; }
    .smp-inline-inbox .smp-crm-panel.is-mobile-open {
        display: flex;
        position: fixed;
        right: 0; top: 0; bottom: 0;
        z-index: 99999;
        width: 92vw;
        max-width: 380px;
        background: #fff;
        box-shadow: -4px 0 24px rgba(15,23,42,.25);
    }
    .smp-mobile-back-btn { display: inline-flex; }
    .smp-chat-header { flex-wrap: wrap; gap: 6px; }
    .smp-msg-input { font-size: 16px; } /* tránh zoom iOS */
}

/* ═══════════════ CONTRAST FIX — chống theme làm mờ chữ ═══════════════ */

/* Heading card: "Hội thoại gần nhất", "Lịch hẹn sắp tới", "Doanh thu theo ngày", "Theo kênh"... */
.smp-sales-app .smp-app-card h3 {
    color: #1e40af !important;
    font-weight: 800 !important;
    font-size: .82rem !important;
    opacity: 1 !important;
}

/* Header bảng */
.smp-sales-app .smp-app-table th {
    color: #1e3a8a !important;
    font-weight: 800 !important;
    opacity: 1 !important;
}

/* Tab CRM panel: KHÁCH HÀNG / ĐƠN HÀNG */
.smp-sales-app .smp-crm-tab {
    color: #334155 !important;
    font-weight: 800 !important;
    opacity: 1 !important;
}
.smp-sales-app .smp-crm-tab.is-active {
    background: #2563eb !important;
    color: #ffffff !important;
}

/* Nav item */
.smp-sales-app .smp-app-nav-item {
    color: #475569;
    opacity: 1 !important;
}
.smp-sales-app .smp-app-nav-item.is-active { color: #fff !important; }

/* Nút back mobile: nền xanh đậm chữ trắng, rõ ràng */
.smp-mobile-back-btn {
    background: #2563eb !important;
    border: none !important;
    color: #fff !important;
    font-weight: 700 !important;
    box-shadow: 0 2px 6px rgba(37,99,235,.3);
}

/* Label form, tên heading section trong CRM panel */
.smp-sales-app .smp-cf-label,
.smp-sales-app .smp-order-header > span:first-child {
    color: #1e3a8a !important;
    font-weight: 700 !important;
    opacity: 1 !important;
}

/* Tên hội thoại trong header chat */
.smp-sales-app .smp-chat-conv-name {
    color: #0f172a !important;
    font-weight: 800 !important;
}

/* ═══════════════ LAYOUT V2 — CRM panel nằm DƯỚI ô chat ═══════════════ */

.smp-inline-inbox-v2 {
    display: grid;
    grid-template-columns: 280px 1fr;
    min-height: 640px;
    background: #fff;
}
.smp-chat-col {
    display: flex;
    flex-direction: column;
    min-width: 0;
    border-left: 1px solid var(--smp-border, #dbeafe);
}
.smp-inline-inbox-v2 .smp-inline-chat-main {
    flex: 1 1 auto;
    min-height: 380px;
    max-height: 55vh;
    display: flex;
    flex-direction: column;
}

/* Panel dưới chat — ngang, full width */
.smp-crm-below {
    width: 100% !important;
    border-left: none !important;
    border-top: 3px solid var(--smp-primary, #2563eb);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    height: 340px;
    background: #fbfdff;
    overflow: hidden;
}
.smp-crm-below .smp-crm-empty {
    flex-direction: row;
    gap: 12px;
    height: 100%;
    justify-content: center;
}
.smp-crm-below .smp-crm-tabs {
    display: flex;
    flex-shrink: 0;
}
.smp-crm-below .smp-crm-tab {
    flex: 0 0 auto;
    min-width: 160px;
    padding: 11px 22px !important;
}
.smp-crm-below .smp-crm-tab-content { padding: 14px 18px; }

/* Form khách hàng dàn 2 cột khi panel rộng */
.smp-crm-below .smp-crm-fields {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px 16px;
}
.smp-crm-below .smp-cf-row:has(textarea) { grid-column: 1 / -1; }
.smp-crm-below .smp-history-box {
    grid-template-columns: repeat(4, 1fr) !important;
}

/* Khu nhãn + lịch hẹn nằm gọn */
.smp-crm-below #smpConvTagsBox,
.smp-crm-below #smpApptBox { max-width: 900px; }

/* Order tab tận dụng chiều ngang */
.smp-crm-below .smp-order-table { font-size: .84rem; }
.smp-crm-below .smp-order-search { max-width: 480px; }

/* Mobile: chat + panel xếp dọc tự nhiên */
@media (max-width: 768px) {
    .smp-inline-inbox-v2 { display: block !important; }
    .smp-inline-inbox-v2 .smp-chat-col { display: none; border-left: none; }
    .smp-inline-inbox-v2.is-chat-open .smp-conv-sidebar { display: none; }
    .smp-inline-inbox-v2.is-chat-open .smp-chat-col { display: flex; }
    .smp-inline-inbox-v2 .smp-inline-chat-main { max-height: none; height: 62vh; }
    .smp-crm-below { height: auto; max-height: 70vh; }
    .smp-crm-below .smp-crm-fields { grid-template-columns: 1fr; }
    .smp-crm-below .smp-history-box { grid-template-columns: repeat(2, 1fr) !important; }
    .smp-crm-below .smp-crm-tab { min-width: 0; flex: 1; }
}
