@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@400;500;600;700&display=swap');

:root {
    --app-bg: #f2f5ff;
    --ink: #202945;
    --muted: #65708d;
    --surface: #ffffff;
    --line: #e6ebf7;
    --brand: #2c5cff;
    --brand-dark: #1f45d6;
    --success: #1a8f58;
    --danger: #b84155;
}

body {
    font-family: 'Outfit', sans-serif;
    color: var(--ink);
    background: radial-gradient(circle at top right, #dfe8ff 0, transparent 40%), var(--app-bg);
}

.app-shell .card {
    border-radius: 1rem;
}

.app-navbar {
    background: linear-gradient(100deg, #18274f, #1e3a8a);
    box-shadow: 0 12px 30px rgba(24, 39, 79, 0.2);
}

.navbar-brand {
    font-weight: 700;
    letter-spacing: 0.2px;
}

.nav-link {
    color: rgba(255, 255, 255, 0.84) !important;
}

.nav-link:hover,
.nav-link:focus {
    color: #fff !important;
}

.role-badge {
    padding: 0.45rem 0.7rem;
    border-radius: 999px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.role-badge-admin {
    background: #f8d681;
    color: #4d2f00;
}

.role-badge-supervisor {
    background: #d4f4ff;
    color: #004f6d;
}

.role-badge-agent {
    background: #d8f5e8;
    color: #0c5f3a;
}

.auth-page {
    min-height: 100vh;
    background:
        radial-gradient(circle at 15% 20%, rgba(55, 124, 255, 0.24) 0, transparent 35%),
        radial-gradient(circle at 85% 80%, rgba(96, 212, 170, 0.28) 0, transparent 34%),
        #edf2ff;
}

.auth-shell {
    padding: 1rem;
}

.login-wrapper-grid {
    min-height: min(720px, calc(100vh - 2rem));
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 1.25rem;
    overflow: hidden;
    box-shadow: 0 30px 60px rgba(39, 55, 97, 0.12);
    display: grid;
    grid-template-columns: 1.2fr 1fr;
}

.login-brand-panel {
    padding: 2.5rem;
    position: relative;
    overflow: hidden;
    color: #fff;
    background: linear-gradient(160deg, #0f255d 0%, #1f4fcf 60%, #2c5cff 100%);
}

.login-brand-panel::before {
    content: '';
    position: absolute;
    inset: auto -30% -35% auto;
    width: 380px;
    height: 380px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.14);
}

.brand-content {
    position: relative;
    z-index: 1;
    max-width: 420px;
}

.brand-kicker {
    display: inline-block;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 999px;
    font-size: 0.82rem;
    padding: 0.3rem 0.7rem;
}

.brand-title {
    margin-top: 1.2rem;
    font-size: 2.2rem;
    line-height: 1.2;
}

.brand-text {
    margin-top: 1rem;
    color: rgba(255, 255, 255, 0.86);
}

.login-form-panel {
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 2rem;
}

.login-form-head h2 {
    font-weight: 700;
    margin-bottom: 0.35rem;
}

.login-form-head p {
    color: var(--muted);
    margin-bottom: 1.4rem;
}

.login-form .form-label {
    font-weight: 500;
    color: #39466f;
}

.login-form .form-control {
    border-radius: 0.85rem;
    border-color: #d8e1f5;
    padding: 0.82rem 0.9rem;
}

.login-form .form-control:focus {
    border-color: #7e9dff;
    box-shadow: 0 0 0 0.25rem rgba(44, 92, 255, 0.15);
}

.btn-primary {
    background-color: var(--brand);
    border-color: var(--brand);
    border-radius: 0.85rem;
}

.btn-primary:hover,
.btn-primary:focus {
    background-color: var(--brand-dark);
    border-color: var(--brand-dark);
}

.user-admin-card {
    border: 1px solid #e9eefb;
}

/* Unread conversation row highlight */
.conv-row--unread {
    background: rgba(44, 92, 255, 0.055) !important;
    border-left: 3px solid var(--brand);
}
.conv-row--unread td:first-child {
    padding-left: calc(.75rem - 3px);
}

/* Unread badge pulse animation (triggered by JS) */
@keyframes conv-badge-pulse {
    0%   { transform: scale(1);    box-shadow: 0 0 0 0   rgba(184, 65, 85, 0.7); }
    40%  { transform: scale(1.35); box-shadow: 0 0 0 6px rgba(184, 65, 85, 0); }
    70%  { transform: scale(0.95); }
    100% { transform: scale(1);    box-shadow: 0 0 0 0   rgba(184, 65, 85, 0); }
}
.conv-unread-badge--pulse {
    animation: conv-badge-pulse 0.55s ease-out;
}

.user-table thead th {
    font-size: 0.8rem;
    letter-spacing: 0.2px;
    text-transform: uppercase;
    color: #526288;
}

.user-table tbody td {
    vertical-align: middle;
}

.user-role-select {
    min-width: 130px;
}

.dataTables_wrapper .dataTables_filter input,
.dataTables_wrapper .dataTables_length select {
    border: 1px solid #d7e0f5;
    border-radius: 0.6rem;
    padding: 0.35rem 0.6rem;
}

.dataTables_wrapper .dataTables_filter input:focus,
.dataTables_wrapper .dataTables_length select:focus {
    outline: none;
    border-color: #7e9dff;
    box-shadow: 0 0 0 0.2rem rgba(44, 92, 255, 0.12);
}

.dataTables_wrapper .dataTables_info,
.dataTables_wrapper .dataTables_length,
.dataTables_wrapper .dataTables_filter {
    color: #59698f;
    font-size: 0.9rem;
    margin-bottom: 0.75rem;
}

.dataTables_wrapper .pagination .page-link {
    border-radius: 0.5rem;
    margin: 0 2px;
    border: 1px solid #d8e2fb;
    color: #2a3d70;
}

.dataTables_wrapper .pagination .page-item.active .page-link {
    background-color: #2c5cff;
    border-color: #2c5cff;
}

/* ═══════════════════════════════════════════════
   CHAT INTERFACE
═══════════════════════════════════════════════ */

.chat-shell {
    overflow: hidden;
    height: 100vh;
}

.chat-outer {
    height: calc(100vh - 56px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Chat layout: sidebar + main */
.chat-layout {
    display: grid;
    grid-template-columns: 300px 1fr;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* ── Sidebar ── */
.chat-sidebar {
    border-right: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    background: #fff;
    overflow: hidden;
}

.chat-sidebar-header {
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--line);
    flex-shrink: 0;
}

.chat-sidebar-search {
    position: relative;
    margin-bottom: 0.5rem;
}

.chat-sidebar-search::before {
    content: '';
    position: absolute;
    left: 0.85rem;
    top: 50%;
    width: 1rem;
    height: 1rem;
    transform: translateY(-50%);
    background: no-repeat center / contain url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23657394' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E");
    opacity: 0.75;
    pointer-events: none;
    z-index: 2;
}

.chat-sidebar-search-input {
    border-radius: 999px !important;
    border-color: #d7e0f5 !important;
    padding-left: 2.35rem !important;
}

.chat-sidebar-search-input:focus {
    border-color: #7e9dff !important;
    box-shadow: 0 0 0 0.2rem rgba(44, 92, 255, 0.12) !important;
}

.chat-sidebar-tabs {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.35rem;
}

.chat-sidebar-tab {
    border: 1px solid #d7e0f5;
    background: #fff;
    color: #49587d;
    border-radius: 999px;
    font-size: 0.74rem;
    font-weight: 600;
    line-height: 1;
    padding: 0.48rem 0.35rem;
}

.chat-sidebar-tab:hover {
    background: #f4f7ff;
    border-color: #c7d6fb;
}

.chat-sidebar-tab.is-active {
    background: #2c5cff;
    border-color: #2c5cff;
    color: #fff;
}

.chat-sidebar-list {
    overflow-y: auto;
    flex: 1;
}

.chat-sidebar-item.is-filter-hidden {
    display: none;
}

.chat-sidebar-item {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--line);
    text-decoration: none;
    color: var(--ink);
    transition: background 0.12s;
}

.chat-sidebar-item:hover { background: #f5f7ff; color: var(--ink); }
.chat-sidebar-item--active { background: #eef2ff; color: var(--ink); font-weight: 600; }

.chat-sidebar-item--status-open {
    border-left: 3px solid #15a46b;
    padding-left: calc(1rem - 3px);
}

.chat-sidebar-item--status-assigned {
    border-left: 3px solid #f59e0b;
    padding-left: calc(1rem - 3px);
}

.chat-sidebar-item--status-new {
    border-left: 3px solid #38bdf8;
    padding-left: calc(1rem - 3px);
}

.chat-sidebar-item--status-closed {
    border-left: 3px solid #9ca3af;
    padding-left: calc(1rem - 3px);
    opacity: 0.9;
}

.chat-sidebar-item--read {
    background: #ffffff;
}

.chat-sidebar-item--unread {
    background: #eef1f5;
}

.chat-sidebar-item--unread .chat-sidebar-name {
    font-weight: 700;
}

.chat-sidebar-item--unread .chat-sidebar-preview {
    color: #445066;
}

.chat-sidebar-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #4f7ef8, #2c5cff);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.95rem;
    flex-shrink: 0;
}

.chat-sidebar-info {
    min-width: 0;
    flex: 1;
}

.chat-sidebar-name {
    font-weight: 600;
    font-size: 0.88rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-sidebar-name-row {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    min-width: 0;
}

.chat-sidebar-preview {
    font-size: 0.78rem;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 140px;
}

.chat-sidebar-time {
    font-size: 0.68rem;
    color: #6b7280;
    margin-bottom: 0.2rem;
}



/* ── Chat main ── */
.chat-main {
    display: flex;
    flex-direction: column;
    background: #edf1fb;
    overflow: hidden;
}

/* ── Chat header ── */
.chat-header {
    background: #fff;
    border-bottom: 1px solid var(--line);
    padding: 0.65rem 1.2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}

.contact-avatar-lg {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: linear-gradient(135deg, #4f7ef8, #2c5cff);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1rem;
    flex-shrink: 0;
}

.chat-contact-name {
    font-weight: 700;
    font-size: 0.97rem;
}

.chat-contact-sub {
    font-size: 0.8rem;
    color: var(--muted);
}

.contact-enrich-btn {
    border: 1px solid #d9e0f2;
    background: #ffffff;
    color: #42506b;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    line-height: 1;
    padding: 0.28rem 0.62rem;
    transition: all 0.15s ease;
}

.contact-enrich-btn:hover {
    border-color: #b9c8f0;
    background: #f3f6ff;
    color: #2f4474;
}

.btn-xs {
    padding: 0.22rem 0.5rem;
    font-size: 0.75rem;
    line-height: 1.4;
    border-radius: 0.35rem;
}

/* ── Messages area ── */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.1rem 1.2rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.msg-row {
    display: flex;
    width: 100%;
    margin-bottom: 0.15rem;
}

.msg-row--in  { justify-content: flex-start; }
.msg-row--out { justify-content: flex-end; }

.msg-bubble {
    max-width: 68%;
    padding: 0.5rem 0.85rem 0.35rem;
    border-radius: 1rem;
    font-size: 0.92rem;
    line-height: 1.55;
    word-break: break-word;
    box-shadow: 0 2px 6px rgba(0,0,0,0.07);
}

.msg-bubble--in {
    background: #fff;
    border-bottom-left-radius: 0.25rem;
    color: var(--ink);
}

.msg-bubble--out {
    background: linear-gradient(145deg, #3d6bff, #2c5cff);
    color: #fff;
    border-bottom-right-radius: 0.25rem;
}

.msg-body {
    line-height: 1.55;
}

.msg-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.3rem;
    margin-top: 0.25rem;
}

.msg-time {
    font-size: 0.7rem;
    opacity: 0.72;
}

.msg-status {
    font-size: 0.78rem;
    line-height: 1;
}

.msg-status--sent      { color: rgba(255,255,255,0.65); }
.msg-status--delivered { color: rgba(255,255,255,0.65); }
.msg-status--read      { color: #93c5fd; }
.msg-status--failed    { color: #fca5a5; }
.msg-status--queued    { color: rgba(255,255,255,0.45); font-size: 0.7rem; }

.msg-date-divider {
    text-align: center;
    margin: 0.75rem 0 0.5rem;
}

.msg-date-divider span {
    background: rgba(255,255,255,0.78);
    border: 1px solid var(--line);
    padding: 0.18rem 0.8rem;
    border-radius: 999px;
    font-size: 0.76rem;
    color: var(--muted);
}

.msg-empty {
    text-align: center;
    color: var(--muted);
    font-size: 0.9rem;
    margin: auto;
    padding: 2rem;
}

/* ── Chat footer ── */
.chat-footer {
    background: #fff;
    border-top: 1px solid var(--line);
    padding: 0.75rem 1.2rem;
    flex-shrink: 0;
}

.chat-closed-notice {
    text-align: center;
    color: var(--muted);
    font-size: 0.9rem;
    padding: 0.25rem 0;
}

.chat-textarea {
    resize: none;
    border-radius: 1.4rem !important;
    padding: 0.6rem 1rem !important;
    border-color: #d8e2fb !important;
    min-height: 44px;
    max-height: 130px;
    overflow-y: auto;
    line-height: 1.5;
}

.chat-textarea:focus {
    border-color: #7e9dff !important;
    box-shadow: 0 0 0 0.2rem rgba(44,92,255,0.12) !important;
}

.chat-send-btn {
    border-radius: 50% !important;
    width: 44px;
    height: 44px;
    min-width: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* ── Flash banner in chat ── */
.chat-flash {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.55rem 1.2rem;
    font-size: 0.88rem;
    flex-shrink: 0;
}

.chat-flash--error   { background: #fef2f2; color: #991b1b; border-bottom: 1px solid #fecaca; }
.chat-flash--success { background: #f0fdf4; color: #166534; border-bottom: 1px solid #bbf7d0; }

.chat-flash-close {
    background: none;
    border: none;
    font-size: 1.1rem;
    cursor: pointer;
    opacity: 0.6;
    padding: 0 0.25rem;
}

/* ── Media messages ── */
.msg-media-img {
    max-width: 240px;
    max-height: 200px;
    border-radius: 0.65rem;
    display: block;
    object-fit: cover;
    cursor: pointer;
}

.msg-media-audio {
    display: block;
    width: 220px;
    height: 36px;
}

.msg-file-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.35rem 0.75rem;
    border-radius: 0.5rem;
    font-size: 0.85rem;
    font-weight: 500;
    text-decoration: none;
    word-break: break-all;
}

.msg-bubble--in  .msg-file-btn { background: #f0f4ff; color: var(--brand); }
.msg-bubble--out .msg-file-btn { background: rgba(255,255,255,0.15); color: #fff; }
.msg-bubble--out .msg-file-btn:hover { background: rgba(255,255,255,0.25); color: #fff; }

/* ── Attach button ── */
.chat-attach-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    min-width: 40px;
    border-radius: 50%;
    background: var(--app-bg);
    color: var(--brand);
    cursor: pointer;
    flex-shrink: 0;
    transition: background .15s;
}
.chat-attach-btn:hover { background: #dce7ff; }

.chat-emoji-btn {
    width: 40px;
    height: 40px;
    min-width: 40px;
    border-radius: 50%;
    border: 1px solid #d7e0f5;
    background: #fff;
    color: #33416f;
    font-size: 1.05rem;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.chat-emoji-btn:hover {
    background: #f3f6ff;
    border-color: #c8d5fb;
}

.emoji-picker {
    position: absolute;
    left: 56px;
    bottom: calc(100% + 10px);
    width: min(320px, 88vw);
    display: grid;
    grid-template-columns: repeat(8, minmax(0, 1fr));
    gap: 0.3rem;
    padding: 0.55rem;
    border: 1px solid #d7e0f5;
    border-radius: 0.8rem;
    background: #fff;
    box-shadow: 0 12px 30px rgba(28, 42, 76, 0.18);
    z-index: 25;
}

.emoji-item {
    border: none;
    background: transparent;
    border-radius: 0.45rem;
    padding: 0.28rem;
    font-size: 1.1rem;
    line-height: 1;
}

.emoji-item:hover {
    background: #eff3ff;
}

/* ── Upload preview bar ── */
.upload-preview-bar {
    border-top: 1px solid var(--line);
    padding: 0.55rem 0.75rem 0.35rem;
    background: #f8faff;
}

.upload-img-thumb {
    width: 48px;
    height: 48px;
    border-radius: 0.4rem;
    object-fit: cover;
    border: 1px solid var(--line);
}

.upload-caption {
    flex: 1;
    min-width: 120px;
    border-radius: 0.8rem !important;
}

/* ══════════════════════════════════════
   RESPONSIVE
══════════════════════════════════════ */
@media (max-width: 991.98px) {
    .auth-shell {
        padding: 0.8rem;
    }

    .login-wrapper-grid {
        min-height: auto;
        grid-template-columns: 1fr;
    }

    .login-form-panel {
        padding: 1.4rem;
    }

    .user-role-select {
        min-width: 110px;
    }

    .chat-layout {
        grid-template-columns: 1fr;
    }

    .chat-sidebar {
        display: none;
    }
}
