@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;
}

.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-list {
    overflow-y: auto;
    flex: 1;
}

.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-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-preview {
    font-size: 0.78rem;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 140px;
}

/* ── 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);
}

/* ── 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;
}

/* ══════════════════════════════════════
   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;
    }
}
