/* ============================================================
   Custom CSS — Design System + Responsive + Visual Polish
   ============================================================ */

/* ─── CSS Variables ─────────────────────────────────────── */
:root {
    --primary: #2563eb;
    --primary-light: #dbeafe;
    --primary-dark: #1d4ed8;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --shadow-card:
        0 1px 3px 0 rgba(0, 0, 0, 0.06), 0 1px 2px -1px rgba(0, 0, 0, 0.06);
    --shadow-card-hover:
        0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
    --shadow-modal:
        0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
}

/* ─── Scrollbar ──────────────────────────────────────────── */
.custom-scrollbar::-webkit-scrollbar {
    width: 5px;
}
.custom-scrollbar::-webkit-scrollbar-track {
    background: transparent;
}
.custom-scrollbar::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 10px;
}
.custom-scrollbar::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

/* ─── Responsive: Mobile Chat Layout ──────────────────── */
@media (max-width: 1023px) {
    /* Sidebar: full-width trên mobile, luôn hiển thị khi chưa chọn hội thoại */
    #chatSidebar {
        width: 100% !important;
    }
    #chatSidebar.mobile-chat-hidden {
        display: none !important;
    }

    /* Main chat area: ẩn khi chưa chọn, full-screen khi đã chọn */
    #chatMainArea {
        display: none;
    }
    #chatMainArea.mobile-chat-open {
        display: flex !important;
        flex-direction: column;
        position: fixed;
        inset: 0;
        top: 48px; /* chừa header */
        z-index: 20;
        background: #f9fafb;
    }

    /* Ẩn noConvSelected trên mobile */
    #noConvSelected {
        display: none !important;
    }

    /* Sidebar overlay (không dùng nữa) */
    .sidebar-open {
        display: none !important;
    }
}

/* ─── Sidebar Links ──────────────────────────────────────── */
.sidebar-link {
    transition: all 0.15s ease;
    border-left: 3px solid transparent;
}
.sidebar-link:hover {
    background-color: #f0f7ff;
    color: var(--primary);
}
.sidebar-link.active {
    background-color: var(--primary-light);
    color: var(--primary-dark);
    font-weight: 600;
    border-left-color: var(--primary);
}

/* ─── Cards ──────────────────────────────────────────────── */
.card {
    background: white;
    border-radius: 12px;
    box-shadow: var(--shadow-card);
    outline: 1px solid var(--gray-200);
    outline-offset: -1px;
    transition:
        box-shadow 0.2s ease,
        transform 0.15s ease;
}
.card:hover {
    box-shadow: var(--shadow-card-hover);
}
.card-interactive {
    cursor: pointer;
}
.card-interactive:active {
    transform: scale(0.985);
}

/* ─── Buttons ────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    padding: 0.5rem 1rem;
    border-radius: 10px;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.15s ease;
    cursor: pointer;
    white-space: nowrap;
    line-height: 1.25rem;
}
.btn:active {
    transform: scale(0.97);
}
.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.btn-primary {
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    color: white;
    box-shadow: 0 1px 2px rgba(37, 99, 235, 0.3);
}
.btn-primary:hover:not(:disabled) {
    background: linear-gradient(135deg, #1d4ed8, #1e40af);
    box-shadow: 0 2px 4px rgba(37, 99, 235, 0.35);
}

.btn-secondary {
    background: white;
    color: var(--gray-700);
    border: 1px solid var(--gray-200);
}
.btn-secondary:hover:not(:disabled) {
    background: var(--gray-50);
    border-color: #d1d5db;
}

.btn-danger {
    background: white;
    color: #ef4444;
    border: 1px solid #fecaca;
}
.btn-danger:hover:not(:disabled) {
    background: #fef2f2;
    border-color: #fca5a5;
}

.btn-success {
    background: white;
    color: #16a34a;
    border: 1px solid #bbf7d0;
}
.btn-success:hover:not(:disabled) {
    background: #f0fdf4;
    border-color: #86efac;
}

.btn-warning {
    background: white;
    color: #d97706;
    border: 1px solid #fde68a;
}
.btn-warning:hover:not(:disabled) {
    background: #fffbeb;
    border-color: #fcd34d;
}

.btn-ghost {
    background: transparent;
    color: var(--gray-600);
    border: none;
    padding: 0.375rem 0.5rem;
}
.btn-ghost:hover:not(:disabled) {
    background: var(--gray-100);
    color: var(--gray-700);
}

.btn-sm {
    padding: 0.25rem 0.625rem;
    font-size: 0.75rem;
    border-radius: 8px;
}

.btn-icon {
    padding: 0.375rem;
    min-width: 2rem;
    min-height: 2rem;
}

/* ─── Form Inputs ────────────────────────────────────────── */
.input {
    width: 100%;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    border: 1px solid var(--gray-200);
    border-radius: 10px;
    background: white;
    transition:
        border-color 0.15s ease,
        box-shadow 0.15s ease;
    outline: none;
}
.input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}
.input::placeholder {
    color: #9ca3af;
}

.select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 0.5rem center;
    background-repeat: no-repeat;
    background-size: 1.25rem;
    padding-right: 2rem;
}

/* ─── Modal ──────────────────────────────────────────────── */
.modal-overlay {
    animation: fadeIn 0.2s ease;
}
.modal-content {
    animation: scaleIn 0.2s ease;
    box-shadow: var(--shadow-modal);
}
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}
@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(8px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* ─── Chat Bubbles ──────────────────────────────────────── */
.chat-bubble-page {
    background: linear-gradient(135deg, #eff6ff, #dbeafe);
    border-radius: 18px 18px 4px 18px;
}
.chat-bubble-customer {
    background: #f3f4f6;
    border-radius: 18px 18px 18px 4px;
}

/* ─── Tag Pills ──────────────────────────────────────────── */
.tag-pill {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
}

/* ─── Tag Toggle Row (thanh tag phía trên input) ────────── */
.tag-toggle-row {
    display: flex;
    align-items: center;
    gap: 6px;
    background: #f8fafc;
    border-top: 1px solid #e5e7eb;
    padding: 10px 12px;
    flex-shrink: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: #d1d5db transparent;
}
.tag-toggle-row::-webkit-scrollbar {
    height: 3px;
}
.tag-toggle-row::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 3px;
}

/* ─── Tag Toggle Buttons (dạng pill màu) ────────────────── */
.tag-toggle-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 5px 14px;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
    flex-shrink: 0;
    line-height: 1.4;
    border: 1.5px solid transparent;
}
.tag-toggle-btn:active {
    transform: scale(0.94);
}
/* ĐÃ GẮN: nổi bật — màu đậm, chữ trắng, shadow mạnh, ring sáng */
.tag-toggle-btn.active {
    color: #fff !important;
    font-weight: 700;
    box-shadow:
        0 2px 8px rgba(0, 0, 0, 0.2),
        0 0 0 2px rgba(255, 255, 255, 0.5) inset;
    transform: scale(1.04);
    border-color: transparent !important;
}
/* CHƯA GẮN: nhạt — nền rất mờ, chữ mờ, border dashed */
.tag-toggle-btn.inactive {
    border-style: dashed;
    opacity: 0.72;
}
.tag-toggle-btn.inactive:hover {
    opacity: 0.92;
    filter: brightness(0.95);
}

/* ─── Tag Create Inline Input ────────────────────────────── */
.tag-create-input {
    width: 120px;
    padding: 5px 10px;
    border-radius: 9999px;
    border: 1.5px dashed #93c5fd;
    font-size: 0.75rem;
    outline: none;
    background: #fff;
    transition: border-color 0.15s;
    flex-shrink: 0;
}
.tag-create-input:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

/* ─── Tag Context Menu (Popup right-click) ──────────────── */
.tag-context-menu {
    position: fixed;
    z-index: 100;
    background: #fff;
    border-radius: 12px;
    box-shadow:
        0 10px 40px rgba(0, 0, 0, 0.15),
        0 0 0 1px rgba(0, 0, 0, 0.05);
    padding: 4px;
    min-width: 160px;
    animation: tagMenuIn 0.12s ease;
}
@keyframes tagMenuIn {
    from {
        opacity: 0;
        transform: scale(0.92) translateY(-4px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}
.tag-context-menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    border-radius: 8px;
    font-size: 0.8125rem;
    color: #374151;
    cursor: pointer;
    transition: background 0.1s;
    white-space: nowrap;
}
.tag-context-menu-item:hover {
    background: #f3f4f6;
}
.tag-context-menu-item.danger {
    color: #ef4444;
}
.tag-context-menu-item.danger:hover {
    background: #fef2f2;
}
.tag-context-menu-divider {
    height: 1px;
    background: #e5e7eb;
    margin: 3px 6px;
}

/* ─── Tag Color Picker Mini (trong context menu) ────────── */
.tag-color-palette {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 6px 12px;
}
.tag-color-swatch {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid transparent;
    transition:
        border-color 0.1s,
        transform 0.1s;
}
.tag-color-swatch:hover {
    border-color: #9ca3af;
    transform: scale(1.15);
}
.tag-color-swatch.selected {
    border-color: #1f2937;
    box-shadow:
        0 0 0 2px #fff,
        0 0 0 3.5px #1f2937;
}

/* ─── Skeleton Loading ──────────────────────────────────── */
.skeleton {
    background: linear-gradient(90deg, #e5e7eb 25%, #f3f4f6 50%, #e5e7eb 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 8px;
}
@keyframes shimmer {
    0% {
        background-position: -200% 0;
    }
    100% {
        background-position: 200% 0;
    }
}

/* ─── Status Badge ──────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.125rem 0.625rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
}
.badge-success {
    background: #dcfce7;
    color: #166534;
}
.badge-warning {
    background: #fef3c7;
    color: #92400e;
}
.badge-danger {
    background: #fee2e2;
    color: #991b1b;
}
.badge-neutral {
    background: #f3f4f6;
    color: #4b5563;
}
.badge-info {
    background: #dbeafe;
    color: #1e40af;
}

/* ─── Status Dot ────────────────────────────────────────── */
.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}
.dot-green {
    background: #22c55e;
}
.dot-gray {
    background: #9ca3af;
}
.dot-red {
    background: #ef4444;
}
.dot-amber {
    background: #f59e0b;
}

/* ─── Utility: Empty State ──────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    background: white;
    border-radius: 16px;
    border: 2px dashed var(--gray-200);
}
.empty-state-icon {
    font-size: 3.5rem;
    margin-bottom: 1rem;
    opacity: 0.7;
}

/* ─── Transition utilities ──────────────────────────────── */
.transition-smooth {
    transition: all 0.2s ease;
}

/* ─── Avatar ring ───────────────────────────────────────── */
.avatar-ring {
    box-shadow:
        0 0 0 2px white,
        0 0 0 4px var(--gray-200);
}

/* ─── Loading skeleton ──────────────────────────────────── */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* ─── Conversation list item ────────────────────────────── */
.conv-item {
    transition: background-color 0.15s ease;
}

.conv-item:hover {
    background-color: #f9fafb;
}

.conv-item.active {
    background-color: #eff6ff;
    border-left: 20px solid #3b82f6;
}

/* ─── Unread badge ──────────────────────────────────────── */
.unread-badge {
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* ─── Responsive helpers ────────────────────────────────── */
@media (max-width: 768px) {
    .mobile-hidden {
        display: none !important;
    }
    .mobile-full {
        width: 100% !important;
    }
}
