﻿:root,
html[data-theme="light"] {
    --brand: #f59e0b;
    --brand-deep: #d97706;
    --brand-hover: #fbbf24;
    --brand-soft: #fffbeb;
    --brand-line: rgba(245, 158, 11, 0.22);
    --nav-from: #f59e0b;
    --nav-to: #d97706;
    --surface: #ffffff;
    --surface-2: #fef3c7;
    --text: #2f2f2f;
    --text-muted: #78716c;
    --border: rgba(217, 119, 6, 0.2);
    --shadow: rgba(217, 119, 6, 0.1);
    --table-head: #d97706;
    --accent: #f59e0b;
    --accent-deep: #d97706;
    --accent-soft: #fef3c7;
    --accent-glow: rgba(245, 158, 11, 0.28);
    color-scheme: light;
}

html[data-theme="dark"] {
    --brand: #a5b4fc;
    --brand-deep: #6366f1;
    --brand-hover: #818cf8;
    --brand-soft: #0a0f1a;
    --brand-line: rgba(148, 163, 184, 0.22);
    --nav-from: #0a0f1a;
    --nav-to: #0f172a;
    --surface: #0f172a;
    --surface-2: #1e293b;
    --text: #e2e8f0;
    --text-muted: #94a3b8;
    --border: rgba(148, 163, 184, 0.22);
    --shadow: rgba(2, 6, 23, 0.35);
    --table-head: #1e293b;
    --accent: #6366f1;
    --accent-deep: #4f46e5;
    --accent-soft: #1e293b;
    --accent-glow: rgba(99, 102, 241, 0.28);
    color-scheme: dark;
}

/* =========================
   GLOBAL SCROLLBAR
   ========================= */

/* Chrome, Edge, Safari */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--brand-soft);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb {
    background-color: var(--brand);
    border-radius: 10px;
    border: 2px solid var(--brand-soft);
}

    ::-webkit-scrollbar-thumb:hover {
        background-color: var(--brand-deep);
    }

/* Firefox */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--brand) var(--brand-soft);
}

/* =========================
   SIDEBAR
   ========================= */

.sidebar {
    background: linear-gradient(180deg, var(--nav-from), var(--nav-to)) !important;
    color: #fff !important;
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 12px 12px 8px;
    padding: 10px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.12);
}

.sidebar-user .avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #fff;
    color: var(--brand);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    flex-shrink: 0;
}

.sidebar-user .meta { min-width: 0; }
.sidebar-user .name {
    font-weight: 700;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-user .role {
    font-size: 11px;
    opacity: 0.8;
}

.sidebar-filter {
    margin: 0 12px 10px;
}

.sidebar-filter input {
    width: 100%;
    border: 0;
    border-radius: 8px;
    padding: 7px 10px;
    font-size: 13px;
    background: rgba(255, 255, 255, 0.16);
    color: #fff;
}

.sidebar-filter input::placeholder { color: rgba(255, 255, 255, 0.72); }
.sidebar-filter input:focus { outline: none; background: rgba(255, 255, 255, 0.24); }

.sidebar .sidebar-nav { flex: 1; }

.sidebar-foot {
    padding: 10px 14px 14px;
    font-size: 11px;
    opacity: 0.75;
}

.sidebar .menu-count {
    margin-left: auto;
    background: rgba(255, 255, 255, 0.18);
    border-radius: 999px;
    padding: 0 7px;
    font-size: 11px;
}

header.app-header .nav-page {
    color: #fff;
    font-weight: 600;
    font-size: 14px;
    padding: 6px 12px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.14);
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

header.app-header .nav-clock {
    color: #fff;
    font-weight: 700;
    letter-spacing: 0.04em;
    padding: 0 8px;
}

header.app-header .nav-goto {
    position: relative;
}

header.app-header .nav-goto input {
    width: 220px;
    border: 0;
    border-radius: 999px;
    padding: 6px 12px;
    font-size: 13px;
    background: rgba(255, 255, 255, 0.16);
    color: #fff;
}

header.app-header .nav-goto input::placeholder { color: rgba(255, 255, 255, 0.75); }
header.app-header .nav-goto input:focus { outline: none; background: rgba(255, 255, 255, 0.24); }

.nav-goto-list {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 12px 28px var(--shadow);
    overflow: hidden;
    z-index: 10070;
}

.nav-goto-item {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 12px;
    color: var(--text);
    text-decoration: none;
}

.nav-goto-item small { color: var(--text-muted); }
.nav-goto-item:hover { background: var(--surface-2); }

    /* Icon menu */
    .sidebar .nav-icon {
        color: #fff !important;
    }

    /* Link menu */
    .sidebar .nav-link {
        color: #fff !important;
        font-weight: 500;
        border-radius: 6px;
        margin: 2px 8px;
        transition: all 0.2s ease;
    }

    .sidebar .nav-dropdown-toggle {
        display: flex;
        align-items: center;
        gap: 6px;
    }

        /* Hover */
        .sidebar .nav-link:hover,
        .sidebar .nav-link:focus {
            background-color: rgba(255, 255, 255, 0.1) !important;
            color: #fff !important;
            transform: translateX(2px);
        }

        /* Active */
        .sidebar .nav-link.active {
            background-color: rgba(255, 255, 255, 0.12) !important;
            color: #fff !important;
            font-weight: 600;
            box-shadow: inset 3px 0 0 var(--brand);
        }

html[data-theme="dark"] .sidebar {
    background: linear-gradient(180deg, var(--nav-from), var(--nav-to)) !important;
    border-right: 1px solid var(--border);
}

html[data-theme="dark"] .sidebar .nav-link {
    color: var(--text) !important;
}

html[data-theme="dark"] .sidebar .nav-link:hover,
html[data-theme="dark"] .sidebar .nav-link:focus {
    background: rgba(255, 255, 255, 0.06) !important;
    color: #f8fafc !important;
}

html[data-theme="dark"] .sidebar .nav-link.active {
    background: linear-gradient(90deg, rgba(99, 102, 241, 0.22), rgba(99, 102, 241, 0.08)) !important;
    color: #f8fafc !important;
    box-shadow: inset 3px 0 0 #6366f1;
}

/* Dropdown arrow */
.nav-dropdown-toggle::after {
    color: #fff !important;
}

/* Sub menu group */
.nav-dropdown-items {
    border-left: 3px solid rgba(255, 255, 255, 0.2);
    margin-left: 6px;
}

/* Group title */
.nav-title {
    color: #fff !important;
    font-size: 0.85rem;
    letter-spacing: 1px;
    opacity: 0.85;
}

/* Badge */
.badge-primary {
    background-color: #fff !important;
    color: var(--brand) !important;
    font-weight: 600;
    border-radius: 10px;
    padding: 2px 8px;
}

/* Disabled */
.sidebar .nav-item .nav-link.disabled {
    color: #ffffff99 !important;
    cursor: not-allowed;
}

/* =========================
   FORM / SWITCH
   ========================= */

.form-check-input.toggle-secure {
    width: 50px;
    height: 25px;
    transform: scale(1.4);
    cursor: pointer;
    border-radius: 30px;
}

/* =========================
   GLOBAL LOADING DIALOG
   ========================= */

#globalLoadingDialog.loading-dialog-overlay {
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: rgba(0, 0, 0, 0.35);
    pointer-events: all;
}

/* Viber admin modals — trên loading overlay & sidebar CoreUI */
body.app .viber-modal {
    z-index: 2100;
}
body.app .modal-backdrop.viber-modal-backdrop {
    z-index: 2090;
}

/* Viber admin — khung tab (đồng bộ filter-form border-warning-subtle) */
body.app .viber-nav-shell {
    padding: 0.65rem 0.75rem 0;
    background: linear-gradient(180deg, #fffdf5 0%, var(--bs-light, #f8f9fa) 100%);
    border: 1px solid var(--bs-warning-border-subtle, #ffe69c);
    border-radius: 0.375rem;
    box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.06);
}

body.app .viber-nav-tabs {
    border-bottom: 1px solid var(--bs-warning-border-subtle, #ffe69c);
    gap: 0.15rem;
    flex-wrap: wrap;
}

body.app .viber-nav-tabs .nav-item {
    margin-bottom: -1px;
}

body.app .viber-nav-tabs .nav-link {
    border: 1px solid transparent;
    border-top-left-radius: 0.375rem;
    border-top-right-radius: 0.375rem;
    color: #5c4a03;
    font-weight: 500;
    padding: 0.5rem 0.85rem;
}

body.app .viber-nav-tabs .nav-link:hover:not(.active) {
    border-color: var(--bs-warning-border-subtle, #ffe69c);
    border-bottom-color: transparent;
    background: rgba(255, 255, 255, 0.75);
}

body.app .viber-nav-tabs .nav-link.active {
    color: #212529;
    font-weight: 600;
    background: #fff;
    border-color: var(--bs-warning-border-subtle, #ffe69c);
    border-bottom-color: #fff;
}

html[data-theme="dark"] body.app .viber-nav-shell {
    background: linear-gradient(180deg, var(--surface-2) 0%, var(--surface) 100%);
    border-color: var(--border);
    box-shadow: none;
}

html[data-theme="dark"] body.app .viber-nav-tabs {
    border-bottom-color: var(--border);
}

html[data-theme="dark"] body.app .viber-nav-tabs .nav-link {
    color: var(--text-muted);
}

html[data-theme="dark"] body.app .viber-nav-tabs .nav-link.active {
    color: var(--text);
    background: var(--surface);
    border-color: var(--border);
    border-bottom-color: var(--surface);
}

#viber-catalog-page .filter-form,
#viber-groups-page .filter-form {
    --viber-filter-control-height: calc(1.5em + 0.75rem + 2px);
}

#viber-catalog-page .viber-filter-actions,
#viber-groups-page .viber-filter-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}

#viber-catalog-page .viber-filter-actions .btn,
#viber-groups-page .viber-filter-actions .btn {
    min-height: var(--viber-filter-control-height);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
}

#viber-catalog-page .viber-filter-actions-label,
#viber-groups-page .viber-filter-actions-label {
    min-height: 1.25rem;
}

@media (min-width: 992px) {
    #viber-catalog-page .filter-form > .col-lg-auto,
    #viber-groups-page .filter-form > .col-lg-auto {
        flex: 0 0 auto;
        width: auto;
        max-width: 100%;
    }
}

#catalogModal .modal-content {
    background: #fff;
}

#catalogModal .catalog-modal-body {
    padding: 1rem 1.25rem 1.25rem;
}

#catalogModal .catalog-field-label {
    margin-bottom: 0.35rem;
    font-size: 0.875rem;
    font-weight: 600;
    min-height: 1.35rem;
}

#catalogModal .catalog-field-control {
    min-height: calc(1.5em + 0.75rem + 2px);
}

#catalogModal .catalog-active-check {
    display: flex;
    align-items: center;
    padding-left: 0.15rem;
}

#catalogModal .catalog-active-check .form-check-label {
    font-weight: 500;
}

@media (min-width: 768px) {
    #catalogModal .catalog-info-row {
        align-items: flex-end;
    }
}

#catalogModal .catalog-viber-grid {
    display: grid;
    gap: 0.85rem 1rem;
    grid-template-columns: 1fr;
    grid-template-areas:
        "opening"
        "footer"
        "options"
        "preview";
}

@media (min-width: 992px) {
    #catalogModal .catalog-viber-grid {
        grid-template-columns: 1fr 1fr;
        grid-template-areas:
            "opening footer"
            "options options"
            "preview preview";
    }
}

#catalogModal .catalog-viber-opening {
    grid-area: opening;
}

#catalogModal .catalog-viber-footer {
    grid-area: footer;
}

#catalogModal .catalog-viber-options {
    grid-area: options;
    padding: 0.5rem 0.75rem;
    background: rgba(248, 249, 250, 0.9);
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-radius: 0.375rem;
}

#catalogModal .catalog-viber-preview-wrap {
    grid-area: preview;
}

#catalogModal .catalog-viber-text {
    min-height: 5.25rem;
    resize: vertical;
}

#catalogModal .catalog-form-section {
    margin-bottom: 1.25rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

#catalogModal .catalog-form-section:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

#catalogModal .catalog-section-title {
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #6c757d;
    margin-bottom: 0.85rem;
}

#catalogModal .catalog-section-title i {
    opacity: 0.9;
}

#catalogModal .catalog-sub-label {
    font-size: 0.8125rem;
    font-weight: 600;
    color: #495057;
}

#catalogModal .catalog-api-accordion .accordion-item {
    border: 1px solid rgba(255, 193, 7, 0.35);
    border-radius: 0.5rem;
    overflow: hidden;
    background: #fff;
}

#catalogModal .catalog-api-accordion .accordion-body {
    padding: 1rem;
    background: #fcfcfc;
}

#catalogModal .catalog-api-accordion-btn {
    font-size: 0.95rem;
    font-weight: 600;
    background: linear-gradient(180deg, rgba(255, 193, 7, 0.14), rgba(255, 193, 7, 0.06));
    box-shadow: none;
}

#catalogModal .catalog-api-accordion-btn:not(.collapsed) {
    background: rgba(255, 193, 7, 0.16);
    color: inherit;
}

#catalogModal .catalog-api-connect {
    background: rgba(255, 255, 255, 0.85);
}

#catalogModal .catalog-api-compact {
    min-height: 4.5rem;
    resize: vertical;
}

#catalogModal .catalog-api-toolbar {
    padding: 0.65rem 0.85rem;
    background: rgba(248, 249, 250, 0.95);
    border: 1px dashed rgba(255, 193, 7, 0.45);
    border-radius: 0.375rem;
}

#catalogModal .catalog-api-summary {
    flex: 1 1 12rem;
    min-width: 0;
    word-break: break-word;
}

#catalogModal .catalog-api-results {
    padding: 0.85rem;
    background: #fafafa;
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-radius: 0.375rem;
}

#catalogModal .catalog-api-test-response {
    white-space: pre-wrap;
    max-height: min(36vh, 280px);
    overflow: auto;
    font-size: 0.78rem;
    padding: 0.75rem;
    background: #fff;
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 0.375rem;
}

#catalogModal .catalog-api-test-response.is-error {
    color: #b02a37;
    border-color: rgba(220, 53, 69, 0.45);
    background-color: rgba(220, 53, 69, 0.06);
}

#catalogModal .catalog-content-columns {
    padding: 0.65rem 0.85rem;
    background: #fff;
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 0.375rem;
    min-height: 2.5rem;
}

#catalogModal .catalog-content-columns.text-muted {
    color: #6c757d !important;
    font-style: italic;
}

#catalogModal .catalog-content-columns .catalog-field-row {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

#catalogModal .catalog-content-columns .catalog-field-row:last-child {
    border-bottom: none;
}

#catalogModal .catalog-content-columns .catalog-field-order {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}

#catalogModal .catalog-content-columns .btn-field-order {
    line-height: 1;
    padding: 0.05rem 0.35rem;
    font-size: 0.65rem;
}

#catalogModal .catalog-content-columns .form-check {
    flex: 1;
    min-width: 0;
    margin-bottom: 0;
    margin-right: 0;
}

#catalogModal .catalog-content-columns-hint {
    font-size: 0.75rem;
    color: #6c757d;
    margin-bottom: 0.35rem;
}

#catalogModal .catalog-message-preview {
    white-space: pre-wrap;
    font-size: 0.8125rem;
    line-height: 1.55;
    padding: 1rem 1.1rem;
    background: linear-gradient(180deg, #fffef8, #fff);
    border: 1px solid rgba(255, 193, 7, 0.35);
    border-radius: 0.5rem;
    max-height: min(40vh, 320px);
    overflow: auto;
}

#groupModal .modal-content {
    background: #fff;
}

#groupModal .group-modal-body {
    padding: 1rem 1.25rem 1.25rem;
}

#groupModal .group-field-label {
    margin-bottom: 0.35rem;
    font-size: 0.875rem;
    font-weight: 600;
    min-height: 1.35rem;
}

#groupModal .group-field-control {
    min-height: calc(1.5em + 0.75rem + 2px);
    background-color: #fff;
}

#groupModal .group-bot-meta {
    margin-top: 0.15rem;
    padding-top: 0.85rem;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
}

#groupModal .group-bot-meta-fields {
    --bs-gutter-x: 0.85rem;
}

@media (min-width: 768px) {
    #groupModal .group-bot-meta-fields {
        align-items: flex-end;
    }
}

#groupModal .group-retry-panel {
    margin-top: 1rem;
    padding: 0.85rem 1rem;
    background: #fff;
    border: 1px solid rgba(255, 193, 7, 0.35);
    border-radius: 0.5rem;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

#groupModal .group-retry-inputs .form-label {
    font-weight: 600;
    color: rgba(33, 37, 41, 0.78);
}

#groupModal .group-active-check {
    display: flex;
    align-items: center;
    padding-left: 0.15rem;
    min-height: calc(1.5em + 0.75rem + 2px);
}

#groupModal .group-active-check .form-check-label {
    font-weight: 500;
}

@media (min-width: 768px) {
    #groupModal .group-info-row {
        align-items: flex-end;
    }
}

#groupModal .catalog-api-accordion .accordion-item {
    border: 1px solid rgba(255, 193, 7, 0.35);
    border-radius: 0.5rem;
    overflow: hidden;
    background: #fff;
}

#groupModal .catalog-api-accordion .accordion-body {
    padding: 1rem;
    background: #fcfcfc;
}

#groupModal .catalog-api-accordion-btn {
    font-size: 0.95rem;
    font-weight: 600;
    background: linear-gradient(180deg, rgba(255, 193, 7, 0.14), rgba(255, 193, 7, 0.06));
    box-shadow: none;
}

#groupModal .catalog-api-accordion-btn:not(.collapsed) {
    background: rgba(255, 193, 7, 0.16);
    color: inherit;
}

#groupModal .group-form-section {
    margin-bottom: 1.25rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

#groupModal .group-form-section:last-of-type {
    border-bottom: none;
    padding-bottom: 0;
    margin-bottom: 0;
}

#groupModal .group-section-title {
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: rgba(33, 37, 41, 0.75);
    margin-bottom: 0.75rem;
}

#groupModal .group-section-title i {
    opacity: 0.85;
}

#groupModal .group-schedules-list {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

#groupModal .schedule-card {
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 0.5rem;
    background: rgba(248, 249, 250, 0.65);
    padding: 0.85rem 1rem;
}

#groupModal .schedule-card-head {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 0.75rem;
    align-items: flex-end;
    margin-bottom: 0.75rem;
}

#groupModal .schedule-card-head .sch-card-index {
    font-size: 0.75rem;
    font-weight: 600;
    margin-bottom: 0.35rem;
}

#groupModal .schedule-card-head .sch-report-wrap {
    flex: 1 1 14rem;
    min-width: 12rem;
}

#groupModal .recurrence-block {
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-radius: 0.375rem;
    background: #fff;
    padding: 0.65rem 0.75rem;
    margin-bottom: 0.5rem;
}

#groupModal .recurrence-block.is-active {
    border-color: rgba(255, 193, 7, 0.45);
    box-shadow: 0 0 0 1px rgba(255, 193, 7, 0.12);
}

#groupModal .recurrence-block:not(.is-active) .recurrence-head {
    margin-bottom: 0;
}

#groupModal .recurrence-body {
    margin-top: 0.5rem;
    padding-top: 0.45rem;
    border-top: 1px dashed rgba(0, 0, 0, 0.08);
}

#groupModal .recurrence-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 0.75rem;
    margin-bottom: 0.45rem;
}

#groupModal .recurrence-head .form-check-label {
    font-weight: 600;
    font-size: 0.875rem;
}

#groupModal .sch-time {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.8125rem;
}

#groupModal .sch-time input {
    width: 3.25rem;
    text-align: center;
}

#groupModal .dow-toggle {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

#groupModal .dow-toggle .btn {
    min-width: 2.5rem;
    padding: 0.15rem 0.35rem;
    font-size: 0.75rem;
}

#groupModal .dom-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    max-width: 100%;
}

#groupModal .dom-grid .btn {
    min-width: 2rem;
    padding: 0.1rem 0.25rem;
    font-size: 0.7rem;
}

#groupModal .month-toggle {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

#groupModal .month-toggle .btn {
    font-size: 0.72rem;
    padding: 0.12rem 0.4rem;
}

#groupModal .sch-apiparams {
    font-size: 0.8125rem;
}

#groupPreviewModal .catalog-message-preview {
    max-height: min(65vh, 480px);
}

#globalLoadingDialog.loading-dialog-overlay .modal-dialog {
    pointer-events: none;
}

body.loading-dialog-open {
    overflow: hidden !important;
}

/* =========================
   RESPONSIVE - MAIN APP
   ========================= */

body.app {
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    background: var(--brand-soft);
    color: var(--text);
}

html[data-theme="dark"] body.app {
    background-color: #0a0f1a;
    background-image:
        radial-gradient(ellipse 80% 50% at 0% -10%, rgba(99, 102, 241, 0.18), transparent 50%),
        radial-gradient(ellipse 60% 40% at 100% 0%, rgba(34, 211, 238, 0.1), transparent 45%),
        linear-gradient(180deg, #0a0f1a 0%, #0f172a 48%, #111827 100%);
    background-attachment: fixed;
    color: var(--text);
}

html[data-theme="dark"] body.app .main,
html[data-theme="dark"] body.app .app-body {
    background: transparent;
    color: var(--text);
}

html[data-theme="dark"] .card,
html[data-theme="dark"] .modal-content,
html[data-theme="dark"] .filter-form {
    background: var(--surface) !important;
    color: var(--text);
    border-color: var(--border) !important;
}

html[data-theme="dark"] .card-header,
html[data-theme="dark"] .card-footer,
html[data-theme="dark"] .modal-header,
html[data-theme="dark"] .modal-footer {
    background: var(--surface-2) !important;
    color: var(--text);
    border-color: var(--border) !important;
}

html[data-theme="dark"] .form-control,
html[data-theme="dark"] .form-select,
html[data-theme="dark"] select.form-control {
    background: var(--surface-2);
    color: var(--text);
    border-color: var(--border);
}

html[data-theme="dark"] .form-control:focus,
html[data-theme="dark"] .form-select:focus {
    background: var(--surface-2);
    color: var(--text);
    border-color: var(--brand-deep);
    box-shadow: 0 0 0 0.2rem rgba(99, 102, 241, 0.34);
}

html[data-theme="dark"] .form-label,
html[data-theme="dark"] .text-dark,
html[data-theme="dark"] label {
    color: var(--text) !important;
}

html[data-theme="dark"] .text-muted {
    color: var(--text-muted) !important;
}

html[data-theme="dark"] .bg-light {
    background-color: var(--surface) !important;
}

html[data-theme="dark"] .border,
html[data-theme="dark"] .border-warning-subtle {
    border-color: var(--border) !important;
}

html[data-theme="dark"] .dashboard-wrapper,
html[data-theme="dark"] .chart-card,
html[data-theme="dark"] .time-box {
    background: var(--surface) !important;
    color: var(--text);
    border-color: var(--border) !important;
}

html[data-theme="dark"] .chart-title,
html[data-theme="dark"] .time-value {
    color: var(--text) !important;
}

html[data-theme="dark"] .time-label {
    color: var(--text-muted) !important;
}

html[data-theme="dark"] .accordion-item,
html[data-theme="dark"] .accordion-button,
html[data-theme="dark"] .accordion-body,
html[data-theme="dark"] .table,
html[data-theme="dark"] .table > :not(caption) > * > * {
    background-color: var(--surface) !important;
    color: var(--text);
    border-color: var(--border) !important;
}

html[data-theme="dark"] .accordion-button:not(.collapsed) {
    background-color: var(--surface-2) !important;
    color: var(--text);
    box-shadow: none;
}

html[data-theme="dark"] .accordion-button::after {
    filter: invert(1);
}

html[data-theme="dark"] .table thead th,
html[data-theme="dark"] .table-light,
html[data-theme="dark"] .table-light > :not(caption) > * > * {
    background-color: var(--table-head) !important;
    color: var(--text) !important;
}

html[data-theme="dark"] .table-hover tbody tr:hover > * {
    background-color: var(--surface-2) !important;
    color: var(--text);
}

html[data-theme="dark"] .btn-close {
    filter: invert(1);
    opacity: 0.7;
}

.theme-toggle {
    width: 36px;
    height: 36px;
    margin-right: 10px;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.theme-toggle:hover {
    background: rgba(255, 255, 255, 0.2);
}

.theme-toggle .theme-icon {
    width: 18px;
    height: 18px;
    display: none;
}

html[data-theme="light"] .theme-toggle .theme-icon-moon,
html:not([data-theme]) .theme-toggle .theme-icon-moon {
    display: block;
}

html[data-theme="dark"] .theme-toggle .theme-icon-sun {
    display: block;
}

html[data-theme="dark"] .theme-toggle {
    border-color: rgba(165, 180, 252, 0.35);
    background: rgba(99, 102, 241, 0.22);
    color: #c7d2fe;
}

html[data-theme="dark"] header.app-header.navbar.custom-header {
    border-bottom: 1px solid rgba(148, 163, 184, 0.22);
    box-shadow: 0 4px 24px rgba(2, 6, 23, 0.35);
}

html[data-theme="dark"] header.app-header .brand-fa {
    color: #6366f1;
}

header.app-header .brand-mark {
    width: 18px;
    height: 18px;
    display: block;
    fill: currentColor;
}

html[data-theme="dark"] .btn-search-glow {
    background-color: #6366f1;
}

html[data-theme="dark"] .btn-search-glow:hover {
    background-color: #4f46e5;
    box-shadow: 0 4px 10px rgba(99, 102, 241, 0.35);
}

html[data-theme="dark"] #pagination .page-item .page-link,
html[data-theme="dark"] .report-table-wrapper .pagination .page-item .page-link {
    background-color: #334155;
}

html[data-theme="dark"] #pagination .page-item.active .page-link,
html[data-theme="dark"] .report-table-wrapper .pagination .page-item.active .page-link {
    background-color: #6366f1;
}

html[data-theme="light"] .card,
html[data-theme="light"] .modal-content,
html[data-theme="light"] .filter-form,
html[data-theme="light"] .accordion-item,
html[data-theme="light"] .accordion-button,
html[data-theme="light"] .accordion-body,
html[data-theme="light"] .table,
html[data-theme="light"] .table > :not(caption) > * > *,
html[data-theme="light"] .bg-light,
html[data-theme="light"] .bg-white,
html[data-theme="light"] .dropdown-menu,
html[data-theme="light"] .list-group-item {
    background-color: var(--surface) !important;
    color: var(--text);
    border-color: var(--border) !important;
}

html[data-theme="light"] .card-header,
html[data-theme="light"] .card-footer,
html[data-theme="light"] .modal-header,
html[data-theme="light"] .modal-footer,
html[data-theme="light"] .table:not(.table-common) thead th,
html[data-theme="light"] .table-light,
html[data-theme="light"] .table-light > :not(caption) > * > * {
    background-color: var(--surface-2) !important;
    color: var(--text) !important;
    border-color: var(--border) !important;
}

html[data-theme="light"] .table-common thead th {
    background-color: var(--table-head) !important;
    color: #f4f1ea !important;
}

html[data-theme="light"] .form-control,
html[data-theme="light"] .form-select,
html[data-theme="light"] select.form-control {
    background-color: var(--surface-2);
    color: var(--text);
    border-color: var(--border);
}

html[data-theme="light"] .form-control:focus,
html[data-theme="light"] .form-select:focus {
    background-color: var(--surface);
    color: var(--text);
    border-color: var(--brand);
    box-shadow: 0 0 0 0.2rem var(--accent-glow);
}

body.app .main,
body.app .app-body {
    background: var(--brand-soft);
    color: var(--text);
}

body.app .main {
    padding: 1.25rem 1.5rem;
}

body.app .btn,
body.app .sidebar .nav-link,
body.app .navbar-toggler {
    touch-action: manipulation;
}

@media (max-width: 991.98px) {
    body.app .main {
        padding: 12px 16px;
    }

    body.app .container-fluid {
        padding-left: 12px;
        padding-right: 12px;
    }

    body.app .card {
        margin-bottom: 1rem;
    }
}

@media (max-width: 575.98px) {
    body.app .main {
        padding: 10px 12px;
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }

    body.app .container-fluid {
        padding-left: 10px;
        padding-right: 10px;
    }

    body.app .card-header .d-flex {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    body.app .card-header input[type="search"],
    body.app .card-header input[type="text"],
    body.app .card-header .form-control {
        width: 100% !important;
        max-width: 100%;
        min-width: 0;
    }

    body.app .card-header > .d-flex.align-items-center.gap-2,
    body.app .card-header > .d-flex:last-child {
        width: 100%;
    }

    body.app .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }

    body.app .pagination {
        flex-wrap: wrap;
        justify-content: center;
    }
}

/* Login fullscreen — styles chính ở ~/css/login.css */
body.flex-row.align-items-center {
    min-height: 100vh;
    min-height: 100dvh;
    padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right))
        max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
}

body.login-page-bg {
    min-height: 100vh;
    min-height: 100dvh;
}

/* =========================
   FLUID LAYOUT — ALL PAGES
   ========================= */

body.app .app-body,
body.app .main {
    min-width: 0;
    max-width: 100%;
}

body.app .container,
body.app .container-fluid {
    max-width: 100%;
}

body.app img,
body.app video,
body.app canvas {
    max-width: 100%;
    height: auto;
}

body.app .table-responsive,
body.app .report-table-wrapper {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

body.app .card > .card-body.p-0 {
    overflow: hidden;
}

body.app .card > .card-body.p-0::after {
    content: "";
    display: block;
    min-height: 16px;
    border-top: 1px solid var(--border);
    background: var(--surface-2);
}

body.app .sys-pane:not(:has(> .sys-pane-foot))::after {
    content: "";
    display: block;
    min-height: 42px;
    flex-shrink: 0;
    border-top: 1px solid var(--border);
    background: var(--surface-2);
}

body.app .filter-form .d-flex {
    flex-wrap: wrap;
    gap: 8px;
}

body.app #recordControlRow .d-flex {
    flex-wrap: wrap;
    gap: 8px;
}

@media (hover: none) {
    body.app .sys-actions {
        opacity: 1;
    }
}

@media (max-width: 1199.98px) {
    header.app-header .nav-goto input {
        width: min(180px, 28vw);
    }
}

@media (max-width: 991.98px) {
    body.app .sidebar {
        z-index: 1045;
    }

    header.app-header .nav-page {
        max-width: min(180px, 30vw);
    }

    body.app .filter-form {
        padding: 12px !important;
    }
}

@media (max-width: 767.98px) {
    body.app .main {
        padding: 10px 12px;
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }

    body.app h1,
    body.app h3.tracking-title {
        font-size: 1.35rem;
    }

    body.app .filter-form .col-12.d-flex,
    body.app .filter-form .col-md-12.d-flex {
        flex-direction: column;
        align-items: stretch !important;
    }

    body.app .filter-form .btn,
    body.app .filter-form .btn-search-glow,
    body.app #exportBtn {
        width: 100%;
    }

    body.app #recordControlRow .col-md-12 {
        flex-direction: column;
        align-items: stretch !important;
    }

    body.app #pageSizeSelect {
        width: 100% !important;
    }

    #tracking-page .input-group {
        flex-wrap: wrap;
        max-width: 100% !important;
    }

    #tracking-page .input-group .form-control {
        min-width: 0;
    }

    #tracking-page .input-group .btn {
        width: 100%;
        margin-top: 8px;
        border-radius: 0.375rem !important;
    }

    #tracking-page .tracking-card .border-end {
        border-right: 0 !important;
        border-bottom: 1px solid var(--border);
        padding-left: 0 !important;
        padding-right: 0 !important;
        padding-bottom: 12px;
        margin-bottom: 12px;
    }

    .swal2-popup {
        width: calc(100vw - 24px) !important;
        max-width: calc(100vw - 24px) !important;
    }
}

@media (max-width: 575.98px) {
    header.app-header .brand-text {
        max-width: 42vw;
        overflow: hidden;
    }

    header.app-header .brand-title,
    header.app-header .brand-subtitle {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        display: block;
    }

    header.app-header .ms-auto.me-3 {
        margin-right: 8px !important;
    }

    .theme-toggle {
        width: 32px;
        height: 32px;
        margin-right: 6px;
    }

    body.app .modal-dialog {
        margin: max(0.5rem, env(safe-area-inset-top)) 0.5rem max(0.5rem, env(safe-area-inset-bottom));
        max-width: calc(100% - 1rem);
    }

    body.app .modal-body {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

html[data-theme="dark"] .home-hero,
html[data-theme="dark"] .home-hero[data-period],
html[data-theme="dark"] .home-hero[data-period="morning"],
html[data-theme="dark"] .home-hero[data-period="afternoon"],
html[data-theme="dark"] .home-hero[data-period="evening"] {
    background: linear-gradient(135deg, #6366f1, #4f46e5) !important;
    box-shadow: 0 10px 24px rgba(99, 102, 241, 0.28) !important;
}

/* Avatar: <img> phủ lên chữ cái đầu; ảnh lỗi hoặc chưa có thì JS bỏ img đi. */
.ems-avatar {
    position: relative;
    overflow: hidden;
}
.ems-avatar-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: inherit;
}
.ems-crop {
    position: fixed;
    inset: 0;
    z-index: 10080;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(15, 23, 42, 0.62);
    backdrop-filter: blur(2px);
}
.ems-crop[hidden] { display: none; }
.ems-crop-panel {
    width: min(360px, 100%);
    padding: 18px;
    border-radius: 16px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.35);
}
.ems-crop-title {
    font-weight: 700;
    margin-bottom: 12px;
    text-align: center;
}
.ems-crop-stage {
    position: relative;
    width: min(288px, 72vw);
    aspect-ratio: 1 / 1;
    margin: 0 auto;
    overflow: hidden;
    border-radius: 12px;
    background: #0b1220;
    cursor: grab;
    touch-action: none;
}
.ems-crop-stage.is-dragging { cursor: grabbing; }
.ems-crop-img {
    position: absolute;
    top: 0;
    left: 0;
    transform-origin: 0 0;
    user-select: none;
    -webkit-user-drag: none;
}
/* Bóng đổ khổng lồ bị stage cắt lại, tạo mặt nạ tròn mà không cần SVG. */
.ems-crop-mask {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    box-shadow: 0 0 0 9999px rgba(2, 6, 23, 0.6);
    border: 2px solid rgba(255, 255, 255, 0.85);
    pointer-events: none;
}
.ems-crop-zoom {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 14px;
    color: var(--text-muted);
}
.ems-crop-zoom input[type="range"] {
    flex: 1;
    accent-color: var(--accent);
}
.ems-crop-hint {
    margin-top: 6px;
    font-size: 12px;
    color: var(--text-muted);
    text-align: center;
}
.ems-crop-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 14px;
}
.profile-avatar {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 112px;
    height: 112px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--accent-deep));
    color: #fff;
    font-size: 42px;
    font-weight: 700;
    overflow: hidden;
}
.ems-avatar-name {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}
.ems-avatar-xs {
    width: 26px;
    height: 26px;
    flex-shrink: 0;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--accent-soft);
    color: var(--accent-deep);
    font-size: 12px;
    font-weight: 700;
}

.ems-chat-fab {
    position: fixed;
    right: 20px;
    bottom: 20px;
    width: 56px;
    height: 56px;
    border: 0;
    border-radius: 50%;
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: #fff;
    box-shadow: 0 8px 24px rgba(217, 119, 6, 0.38);
    z-index: 1080;
    cursor: pointer;
    font-size: 22px;
    transition: transform .18s ease, box-shadow .18s ease;
}
html[data-theme="dark"] .ems-chat-fab {
    background: linear-gradient(135deg, #6366f1, #4f46e5);
    box-shadow: 0 8px 24px rgba(99, 102, 241, 0.4);
}
.ems-chat-fab:hover { transform: translateY(-2px) scale(1.06); }
.ems-chat-fab:active { transform: scale(.94); }

/* Idle breathing halo, only while there is something unread. */
.ems-chat-fab::after {
    content: "";
    position: absolute;
    inset: -6px;
    border-radius: 50%;
    border: 2px solid #d97706;
    opacity: 0;
    pointer-events: none;
}
html[data-theme="dark"] .ems-chat-fab::after { border-color: #6366f1; }
.ems-chat-fab.has-unread::after { animation: emsChatHalo 1.9s ease-out infinite; }
.ems-chat-fab.has-unread .ems-chat-fab-icon { animation: emsChatBreathe 1.9s ease-in-out infinite; }
.ems-chat-fab.is-ringing { animation: emsChatShake .72s cubic-bezier(.36, .07, .19, .97) both; }
/* Softer periodic nudge so the button stays noticeable with no unread. */
.ems-chat-fab.is-nudge { animation: emsChatNudge 1.1s ease-in-out both; }
.ems-chat-fab.is-nudge .ems-chat-fab-icon { animation: emsChatSwing .5s ease-in-out .6s both; }
.ems-chat-fab.is-ringing .ems-chat-fab-icon { animation: emsChatSwing .72s ease-in-out both; }
.ems-chat-fab.is-ringing .ems-chat-badge { animation: emsChatPop .45s ease-out both; }

@keyframes emsChatPop {
    0% { transform: scale(1); }
    40% { transform: scale(1.45); }
    100% { transform: scale(1); }
}

@keyframes emsChatHalo {
    0% { opacity: .55; transform: scale(.9); }
    100% { opacity: 0; transform: scale(1.35); }
}
@keyframes emsChatBreathe {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.12); }
}
@keyframes emsChatShake {
    0%, 100% { transform: translateX(0) rotate(0); }
    12% { transform: translateX(-4px) rotate(-9deg); }
    28% { transform: translateX(4px) rotate(9deg); }
    44% { transform: translateX(-3px) rotate(-6deg); }
    60% { transform: translateX(3px) rotate(6deg); }
    76% { transform: translateX(-2px) rotate(-3deg); }
    88% { transform: translateX(1px) rotate(1.5deg); }
}
@keyframes emsChatNudge {
    0%, 55%, 100% { transform: translateX(0) rotate(0); }
    62% { transform: translateX(-3px) rotate(-7deg); }
    70% { transform: translateX(3px) rotate(7deg); }
    78% { transform: translateX(-2px) rotate(-4deg); }
    86% { transform: translateX(2px) rotate(4deg); }
    93% { transform: translateX(-1px) rotate(-1.5deg); }
}
@keyframes emsChatSwing {
    0%, 100% { transform: rotate(0); }
    25% { transform: rotate(-18deg) scale(1.1); }
    50% { transform: rotate(14deg) scale(1.1); }
    75% { transform: rotate(-7deg) scale(1.05); }
}
.ems-chat-fab-icon {
    display: inline-block;
    transform-origin: 50% 15%;
}
@media (prefers-reduced-motion: reduce) {
    .ems-chat-fab,
    .ems-chat-fab::after,
    .ems-chat-fab-icon,
    .ems-chat-fab .ems-chat-fab-icon,
    .ems-chat-badge {
        animation: none !important;
        transition: none;
    }
}
.ems-chat-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border-radius: 10px;
    background: #ef4444;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    line-height: 20px;
}
.ems-chat-panel {
    position: fixed;
    right: 20px;
    bottom: 88px;
    width: min(380px, calc(100vw - 24px));
    height: min(560px, calc(100vh - 120px));
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 16px 40px var(--shadow);
    z-index: 1080;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.ems-chat-panel[hidden],
.ems-chat-toast[hidden],
.ems-chat-people[hidden],
.ems-chat-thread[hidden],
.ems-chat-back[hidden],
.ems-chat-badge[hidden],
.ems-chat-emoji-pop[hidden] {
    display: none !important;
}
.ems-chat-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: linear-gradient(90deg, var(--accent), var(--accent-deep));
    color: #fff;
}
.ems-chat-head-text { flex: 1; min-width: 0; }
.ems-chat-head-text strong { display: block; font-size: 14px; }
.ems-chat-head-text span { display: block; font-size: 11px; opacity: .85; }
.ems-chat-back,
.ems-chat-close {
    border: 0;
    background: rgba(255,255,255,.16);
    color: #fff;
    width: 32px;
    height: 32px;
    border-radius: 8px;
}
.ems-chat-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    padding: 8px 10px 0;
}
.ems-chat-tabs button {
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    border-radius: 10px;
    padding: 7px 8px;
    font-weight: 600;
    font-size: 13px;
}
.ems-chat-tabs button.is-on {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}
.ems-chat-people,
.ems-chat-thread {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}
.ems-chat-people input {
    margin: 8px 10px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    border-radius: 10px;
    padding: 8px 10px;
}
.ems-chat-people-list {
    overflow: auto;
    padding: 0 8px 10px;
}
.ems-chat-person {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    border: 0;
    background: transparent;
    color: var(--text);
    text-align: left;
    padding: 8px;
    border-radius: 10px;
}
.ems-chat-person:hover { background: var(--accent-soft); }
.ems-chat-ava {
    position: relative;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--accent-soft);
    color: var(--accent-deep);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    flex-shrink: 0;
}
.ems-chat-ava i {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #94a3b8;
    border: 2px solid var(--surface);
}
.ems-chat-ava i.is-on { background: #22c55e; }
/* Ảnh tròn nhờ border-radius inherit, nên không cần overflow hidden — giữ
   overflow visible để không cắt viền chấm online. */
.ems-chat-ava.ems-avatar { overflow: visible; }
.ems-chat-ava-sm {
    width: 26px;
    height: 26px;
    font-size: 12px;
}
.ems-chat-ava-sm.is-blank {
    background: none;
    visibility: hidden;
}
.ems-chat-line {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    max-width: 92%;
    align-self: flex-start;
}
.ems-chat-line.is-mine { align-self: flex-end; }
.ems-chat-line .ems-chat-bubble {
    max-width: 100%;
    align-self: auto;
}
.ems-chat-person-meta { flex: 1; min-width: 0; }
.ems-chat-person-meta strong { display: block; font-size: 13px; }
.ems-chat-tag {
    display: inline-block;
    margin-top: 2px;
    padding: 0 6px;
    border-radius: 8px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--muted);
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
}
.ems-chat-person em {
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    background: #ef4444;
    color: #fff;
    font-style: normal;
    font-size: 11px;
    font-weight: 700;
    text-align: center;
    line-height: 18px;
    padding: 0 5px;
}
.ems-chat-msgs {
    flex: 1;
    overflow: auto;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.ems-chat-bubble {
    max-width: 82%;
    background: var(--surface-2);
    border-radius: 12px;
    padding: 8px 10px;
    align-self: flex-start;
}
.ems-chat-bubble.is-mine {
    align-self: flex-end;
    background: var(--accent);
    color: #fff;
}
.ems-chat-bubble .who { font-size: 11px; font-weight: 700; margin-bottom: 2px; color: var(--accent-deep); }
.ems-chat-bubble button.who {
    display: block;
    padding: 0;
    border: 0;
    background: none;
    font-family: inherit;
    text-align: left;
    cursor: pointer;
    text-decoration: underline;
    text-decoration-style: dotted;
    text-underline-offset: 2px;
}
.ems-chat-bubble button.who:hover { text-decoration-style: solid; }
.ems-chat-bubble.is-mine .who { color: rgba(255,255,255,.9); }
.ems-chat-bubble .body { font-size: 13px; line-height: 1.4; white-space: pre-wrap; word-break: break-word; }
.ems-chat-bubble .at { font-size: 10px; opacity: .7; margin-top: 4px; text-align: right; }
.ems-chat-composer {
    position: relative;
    padding: 10px;
    border-top: 1px solid var(--border);
}
.ems-chat-composer-row {
    display: flex;
    gap: 8px;
    align-items: center;
}
.ems-chat-composer input {
    flex: 1;
    min-width: 0;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    border-radius: 10px;
    padding: 8px 10px;
}
.ems-chat-composer button[type="submit"] {
    border: 0;
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    border-radius: 10px;
    background: var(--accent);
    color: #fff;
}
.ems-chat-emoji-btn {
    border: 1px solid var(--border);
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    border-radius: 10px;
    background: var(--surface);
    color: var(--text-muted);
}
.ems-chat-emoji-btn:hover {
    color: var(--accent-deep);
    background: var(--accent-soft);
}
.ems-chat-emoji-pop {
    position: absolute;
    left: 10px;
    right: 10px;
    bottom: calc(100% + 4px);
    z-index: 5;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 8px 28px rgba(0, 0, 0, .18);
    border: 1px solid var(--border);
}
.ems-chat-emoji-pop emoji-picker {
    width: 100%;
    --num-columns: 8;
    --emoji-size: 1.35rem;
    --background: var(--surface);
    --border-color: var(--border);
    --button-active-background: var(--accent-soft);
    --input-border-color: var(--border);
    --input-font-color: var(--text);
    --outline-color: var(--accent);
}
.ems-chat-empty { color: var(--text-muted); font-size: 13px; padding: 16px; text-align: center; }
.ems-chat-toast {
    position: fixed;
    right: 20px;
    bottom: 88px;
    z-index: 1081;
    max-width: 280px;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 10px 24px var(--shadow);
    padding: 10px 12px;
}
.ems-chat-toast strong { display: block; font-size: 12px; margin-bottom: 2px; }
.ems-chat-toast span { font-size: 13px; }
@media (max-width: 575.98px) {
    .ems-chat-fab { right: 12px; bottom: 12px; }
    .ems-chat-panel { right: 8px; left: 8px; width: auto; bottom: 76px; }
}

/* =========================
   SWEETALERT2 — EMS theme (modal-style)
   ========================= */

.swal2-container {
    z-index: 2200 !important;
}

.swal2-container.swal2-backdrop-show {
    background: rgba(47, 47, 47, 0.45) !important;
    backdrop-filter: blur(4px);
}

html[data-theme="dark"] .swal2-container.swal2-backdrop-show {
    background: rgba(2, 6, 23, 0.65) !important;
}

.swal2-popup.ems-swal-popup {
    width: min(32em, calc(100vw - 28px));
    max-width: min(32em, calc(100vw - 28px));
    padding: 0 0 1.35rem;
    border-radius: 12px;
    border: none;
    background: var(--surface) !important;
    color: var(--text);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.12);
    font-family: inherit;
}

.swal2-popup.ems-swal-popup .swal2-icon {
    margin: 1.35rem auto 0.5rem;
}

.ems-swal-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text);
    padding: 0 1.25rem;
    margin: 0;
    text-align: center;
}

.ems-swal-html {
    font-size: 0.9375rem;
    line-height: 1.5;
    color: var(--text-muted);
    padding: 0.5rem 1.35rem 0;
    margin: 0;
    text-align: center;
    font-weight: 400;
}

.ems-swal-actions {
    gap: 0.65rem;
    margin: 1.35rem 0 0;
    padding: 0 1.25rem;
    width: 100%;
    flex-wrap: wrap;
    justify-content: center;
    background: transparent;
    border-top: none;
    box-sizing: border-box;
}

/* CoreUI: button { border-radius:0 } — reset trong popup */
.swal2-popup.ems-swal-popup .swal2-actions button.ems-swal-btn,
.swal2-popup.ems-swal-popup .swal2-actions button.swal2-cancel,
.swal2-popup.ems-swal-popup .swal2-actions button.swal2-confirm {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    min-width: 6.5rem;
    padding: 0.5rem 1.35rem;
    font-size: 0.875rem;
    font-weight: 600;
    line-height: 1.35;
    border-radius: 6px !important;
    border-width: 1px;
    border-style: solid;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
    -webkit-appearance: none;
    appearance: none;
    box-shadow: none;
}

.swal2-popup.ems-swal-popup .swal2-actions button.ems-swal-btn:focus {
    outline: none;
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.ems-swal-btn-confirm {
    background-color: var(--brand, #f59e0b) !important;
    border-color: var(--brand-deep, #d97706) !important;
    color: #fff !important;
}

.ems-swal-btn-confirm:hover {
    background-color: var(--brand-deep, #d97706) !important;
    box-shadow: 0 4px 12px var(--accent-glow);
}

/* Xóa / xác nhận mạnh — cam brand (giống dialog admin) */
.ems-swal-btn-danger {
    background-color: var(--brand, #f59e0b) !important;
    border-color: var(--brand-deep, #d97706) !important;
    color: #fff !important;
}

.ems-swal-btn-danger:hover {
    background-color: var(--brand-deep, #d97706) !important;
    box-shadow: 0 4px 12px var(--accent-glow);
}

html[data-theme="dark"] .ems-swal-btn-danger {
    background-color: var(--brand, #6366f1) !important;
    border-color: var(--brand-deep, #4f46e5) !important;
}

html[data-theme="dark"] .ems-swal-btn-danger:hover {
    background-color: var(--brand-deep, #4f46e5) !important;
}

.ems-swal-btn-cancel {
    background: #f8fafc !important;
    border-color: #cbd5e1 !important;
    color: #334155 !important;
    font-weight: 500 !important;
}

.ems-swal-btn-cancel:hover {
    background: #f1f5f9 !important;
    border-color: #94a3b8 !important;
    color: #1e293b !important;
}

html[data-theme="dark"] .ems-swal-btn-cancel {
    background: var(--surface-2) !important;
    border-color: var(--border) !important;
    color: var(--text) !important;
}

html[data-theme="dark"] .ems-swal-btn-cancel:hover {
    background: var(--surface) !important;
    border-color: var(--brand-line) !important;
}

html[data-theme="dark"] .ems-swal-btn-confirm {
    background-color: var(--brand, #6366f1) !important;
    border-color: var(--brand-deep, #4f46e5) !important;
}

html[data-theme="dark"] .ems-swal-btn-confirm:hover {
    background-color: var(--brand-deep, #4f46e5) !important;
}

html[data-theme="light"] .swal2-popup.ems-swal-popup .swal2-icon.swal2-warning {
    border-color: var(--brand-hover, #fbbf24);
    color: var(--brand-deep, #d97706);
}

html[data-theme="light"] .swal2-popup.ems-swal-popup .swal2-icon.swal2-warning .swal2-icon-content {
    color: var(--brand-deep, #d97706);
}

html[data-theme="dark"] .swal2-popup.ems-swal-popup .swal2-icon.swal2-warning {
    border-color: #fbbf24;
    color: #fbbf24;
}

.swal2-popup.ems-swal-popup .swal2-icon.swal2-success,
.swal2-popup.ems-swal-popup .swal2-icon.swal2-error,
.swal2-popup.ems-swal-popup .swal2-icon.swal2-info,
.swal2-popup.ems-swal-popup .swal2-icon.swal2-question {
    transform: scale(0.88);
}

.swal2-timer-progress-bar {
    background: var(--brand);
}

@media (max-width: 575.98px) {
    .swal2-popup.ems-swal-popup {
        width: calc(100vw - 24px) !important;
        max-width: calc(100vw - 24px) !important;
    }

    .ems-swal-actions {
        flex-direction: row;
        justify-content: center;
    }

    .swal2-popup.ems-swal-popup .swal2-actions button.ems-swal-btn {
        min-width: 5.25rem;
        flex: 0 1 auto;
    }
}
