:root {
    --primary: #0284c7;        /* Xanh dương Zalo / SaaS */
    --primary-dark: #0369a1;
    --primary-light: #e0f2fe;
    --accent: #ff7700;         /* Cam tươi CTA kiểu phanmemsmsmarketing.com */
    --accent-dark: #ea580c;
    --accent-light: #ffedd5;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --bg-body: #f8fafc;
    --bg-card: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --sidebar-width: 260px;
    --header-height: 64px;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    overflow-x: hidden;
    margin: 0;
}

/* SIDEBAR */
#sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    background: #ffffff;
    border-right: 1px solid var(--border-color);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transition: all 0.3s ease;
}

.sidebar-brand {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.brand-icon {
    width: 38px;
    height: 38px;
    background: linear-gradient(135deg, var(--primary), #0284c7);
    color: white;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 1.2rem;
    margin-right: 0.75rem;
    box-shadow: 0 4px 10px rgba(2, 132, 199, 0.3);
}

.brand-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--primary-dark);
}

.brand-subtitle {
    font-size: 0.68rem;
    color: var(--accent);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.sidebar-menu {
    flex: 1;
    padding: 1rem 0.75rem;
    overflow-y: auto;
    list-style: none;
    margin: 0;
}

.menu-category {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    color: #94a3b8;
    padding: 0.75rem 0.75rem 0.25rem 0.75rem;
    letter-spacing: 0.5px;
}

.menu-item {
    display: flex;
    align-items: center;
    padding: 0.7rem 0.85rem;
    border-radius: 8px;
    color: #475569;
    text-decoration: none;
    font-size: 0.88rem;
    font-weight: 500;
    margin-bottom: 3px;
    transition: all 0.2s ease;
    cursor: pointer;
}

.menu-item i {
    width: 24px;
    font-size: 1.05rem;
    margin-right: 0.65rem;
    color: #64748b;
    transition: all 0.2s ease;
}

.menu-item:hover {
    background-color: var(--primary-light);
    color: var(--primary-dark);
}

.menu-item:hover i {
    color: var(--primary);
}

.menu-item.active {
    background: linear-gradient(90deg, #e0f2fe, #f0f9ff);
    color: var(--primary-dark);
    font-weight: 600;
    border-left: 4px solid var(--primary);
}

.menu-item.active i {
    color: var(--primary);
}

/* SIDEBAR COLLAPSED MODE */
html.sidebar-collapsed,
body.sidebar-collapsed {
    --sidebar-width: 68px;
}

html.sidebar-collapsed #sidebar,
body.sidebar-collapsed #sidebar {
    width: 68px;
}

html.sidebar-collapsed #main-wrapper,
body.sidebar-collapsed #main-wrapper {
    margin-left: 68px;
}

html.sidebar-collapsed .sidebar-brand,
body.sidebar-collapsed .sidebar-brand {
    padding: 0 10px;
    justify-content: center !important;
}

html.sidebar-collapsed .brand-content,
body.sidebar-collapsed .brand-content {
    justify-content: center;
    width: 100%;
}

html.sidebar-collapsed .brand-content .brand-logo,
body.sidebar-collapsed .brand-content .brand-logo {
    margin-right: 0 !important;
}

html.sidebar-collapsed .brand-info,
body.sidebar-collapsed .brand-info,
html.sidebar-collapsed .sidebar-collapse-btn,
body.sidebar-collapsed .sidebar-collapse-btn,
html.sidebar-collapsed .menu-text,
body.sidebar-collapsed .menu-text,
html.sidebar-collapsed .sidebar-footer-text,
body.sidebar-collapsed .sidebar-footer-text {
    display: none !important;
}

html.sidebar-collapsed .menu-category,
body.sidebar-collapsed .menu-category {
    height: 1px;
    padding: 0;
    margin: 8px 10px;
    background-color: var(--border-color);
    font-size: 0;
    overflow: hidden;
}

html.sidebar-collapsed .sidebar-menu,
body.sidebar-collapsed .sidebar-menu {
    padding: 0.75rem 0.35rem;
}

html.sidebar-collapsed .menu-item,
body.sidebar-collapsed .menu-item {
    justify-content: center;
    padding: 0.75rem 0;
    border-radius: 8px;
    position: relative;
}

html.sidebar-collapsed .menu-item i,
body.sidebar-collapsed .menu-item i {
    margin-right: 0;
    font-size: 1.25rem;
}

html.sidebar-collapsed .menu-item.active,
body.sidebar-collapsed .menu-item.active {
    border-left: none;
    background: #e0f2fe;
    color: var(--primary-dark);
}

html.sidebar-collapsed .sidebar-footer,
body.sidebar-collapsed .sidebar-footer {
    padding: 10px 8px !important;
}

html.sidebar-collapsed .sidebar-footer a,
body.sidebar-collapsed .sidebar-footer a {
    padding: 8px 0 !important;
    border-radius: 8px !important;
    justify-content: center;
}

html.sidebar-collapsed .sidebar-footer a i,
body.sidebar-collapsed .sidebar-footer a i {
    font-size: 1.1rem;
    margin: 0 !important;
}

/* Floating tooltip for collapsed sidebar items */
html.sidebar-collapsed .menu-item:hover::after,
body.sidebar-collapsed .menu-item:hover::after {
    content: attr(title);
    position: fixed;
    left: 78px;
    background: #0f172a;
    color: #ffffff;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.82rem;
    font-weight: 500;
    white-space: nowrap;
    z-index: 10001;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
    pointer-events: none;
    animation: fadeInTooltip 0.15s ease-out;
}

@keyframes fadeInTooltip {
    from { opacity: 0; transform: translateX(-4px); }
    to { opacity: 1; transform: translateX(0); }
}

/* MAIN CONTENT */
#main-wrapper {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: all 0.3s ease;
}

/* HEADER */
#topbar {
    height: var(--header-height);
    background: #ffffff;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    position: sticky;
    top: 0;
    z-index: 999;
}

/* CARDS & PANELS */
.card-saas {
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.03);
    margin-bottom: 1.5rem;
    transition: transform 0.2s, box-shadow 0.2s;
}

.card-saas:hover {
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.06);
}

.card-header-saas {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #ffffff;
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
}

.stat-card {
    padding: 1.25rem;
    display: flex;
    align-items: center;
}

.stat-icon {
    width: 52px;
    height: 52px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    margin-right: 1rem;
}

.stat-icon.blue { background: #e0f2fe; color: #0284c7; }
.stat-icon.orange { background: #ffedd5; color: #f97316; }
.stat-icon.green { background: #dcfce7; color: #16a34a; }
.stat-icon.purple { background: #f3e8ff; color: #9333ea; }

.stat-val {
    font-size: 1.65rem;
    font-weight: 700;
    line-height: 1.2;
    color: var(--text-main);
}

.stat-lbl {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-muted);
}

/* BUTTONS */
.btn-primary-saas {
    background-color: var(--primary);
    border-color: var(--primary);
    color: #ffffff;
    font-weight: 600;
    border-radius: 8px;
    padding: 0.5rem 1rem;
    transition: all 0.2s;
}

.btn-primary-saas:hover {
    background-color: var(--primary-dark);
    border-color: var(--primary-dark);
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(2, 132, 199, 0.3);
}

.btn-accent-saas {
    background: linear-gradient(135deg, #ff7700, #f97316);
    border: none;
    color: #ffffff;
    font-weight: 600;
    border-radius: 8px;
    padding: 0.55rem 1.2rem;
    transition: all 0.2s;
}

.btn-accent-saas:hover {
    background: linear-gradient(135deg, #ea580c, #c2410c);
    color: #ffffff;
    box-shadow: 0 4px 14px rgba(249, 115, 22, 0.4);
}

/* BADGES */
.badge-online {
    background: #dcfce7;
    color: #15803d;
    font-weight: 600;
    padding: 0.3rem 0.65rem;
    border-radius: 20px;
    font-size: 0.75rem;
}

.badge-pending {
    background: #fef3c7;
    color: #b45309;
    font-weight: 600;
    padding: 0.3rem 0.65rem;
    border-radius: 20px;
    font-size: 0.75rem;
}

.badge-running {
    background: #e0f2fe;
    color: #0369a1;
    font-weight: 600;
    padding: 0.3rem 0.65rem;
    border-radius: 20px;
    font-size: 0.75rem;
}

.badge-completed {
    background: #dcfce7;
    color: #15803d;
    font-weight: 600;
    padding: 0.3rem 0.65rem;
    border-radius: 20px;
    font-size: 0.75rem;
}

.badge-stopped {
    background: #fee2e2;
    color: #b91c1c;
    font-weight: 600;
    padding: 0.3rem 0.65rem;
    border-radius: 20px;
    font-size: 0.75rem;
}

/* TABLES */
.table-saas thead th {
    background-color: #f8fafc;
    color: #475569;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid var(--border-color);
    padding: 0.75rem 1rem;
}

.table-saas tbody td {
    padding: 0.85rem 1rem;
    vertical-align: middle;
    font-size: 0.88rem;
    border-bottom: 1px solid var(--border-color);
}

.table-saas .dropdown-menu {
    z-index: 1060 !important;
    border: 1px solid #e2e8f0;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.05);
}

.table-saas .dropdown-item {
    font-weight: 500;
    color: #334155;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.table-saas .dropdown-item:hover {
    background-color: #f1f5f9;
    color: #0f172a;
}

.table-saas .dropdown-item.text-danger:hover {
    background-color: #fee2e2;
    color: #dc2626 !important;
}

/* QR MODAL STREAM */
.qr-container {
    width: 360px;
    height: 360px;
    max-width: 100%;
    margin: 0 auto;
    border: 2.5px dashed var(--primary);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #ffffff;
    overflow: hidden;
    position: relative;
    box-shadow: 0 6px 20px rgba(2, 132, 199, 0.08);
    cursor: pointer;
    transition: all 0.2s ease;
}

.qr-container:hover {
    border-color: var(--primary-dark);
    box-shadow: 0 8px 25px rgba(2, 132, 199, 0.15);
}

.qr-container img {
    max-width: 100%;
    max-height: 100%;
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 8px;
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.qr-container.is-zoomed img {
    transform: scale(1.35);
}

/* PLACEHOLDER BADGES */
.tag-placeholder {
    cursor: pointer;
    background: #f1f5f9;
    color: var(--primary-dark);
    border: 1px solid #cbd5e1;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.78rem;
    font-weight: 600;
    display: inline-block;
    margin: 2px;
    transition: all 0.2s;
}

.tag-placeholder:hover {
    background: var(--primary-light);
    border-color: var(--primary);
}

/* ============================================================
   RESPONSIVE & MOBILE ADAPTATION (MOBILE FIRST / HYBRID)
   ============================================================ */

/* Backdrop cho Sidebar trên Mobile / Tablet */
#sidebar-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    z-index: 10040;
    opacity: 0;
    transition: opacity 0.25s ease;
    pointer-events: none;
}

body.sidebar-mobile-open #sidebar-backdrop {
    display: block;
    opacity: 1;
    pointer-events: auto;
}

/* TABLET & MOBILE (< 992px) */
@media (max-width: 991.98px) {
    /* Khung Sidebar Drawer trượt từ cạnh trái */
    #sidebar {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        bottom: 0 !important;
        width: 280px !important;
        max-width: 85vw !important;
        height: 100vh !important;
        transform: translateX(-100%) !important;
        z-index: 10050 !important;
        box-shadow: none !important;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.3s ease !important;
        border-right: 1px solid var(--border-color);
    }

    /* Đảm bảo hiển thị đầy đủ logo và chữ trên drawer mobile, không bị thu nhỏ 68px */
    body.sidebar-collapsed #sidebar {
        width: 280px !important;
    }
    body.sidebar-collapsed .brand-info,
    body.sidebar-collapsed .menu-text,
    body.sidebar-collapsed .sidebar-footer-text {
        display: block !important;
    }
    body.sidebar-collapsed .menu-category {
        height: auto !important;
        padding: 0.75rem 0.75rem 0.25rem 0.75rem !important;
        margin: 0 !important;
        background: transparent !important;
        font-size: 0.7rem !important;
    }
    body.sidebar-collapsed .menu-item {
        justify-content: flex-start !important;
        padding: 0.7rem 0.85rem !important;
    }
    body.sidebar-collapsed .menu-item i {
        margin-right: 0.65rem !important;
        font-size: 1.05rem !important;
    }
    body.sidebar-collapsed .menu-item:hover::after {
        display: none !important; /* Không cần floating tooltip trên mobile */
    }

    /* Mở drawer */
    body.sidebar-mobile-open {
        overflow: hidden !important; /* Khóa cuộn trang khi drawer đang mở */
    }

    body.sidebar-mobile-open #sidebar {
        transform: translateX(0) !important;
        box-shadow: 0 0 35px rgba(0, 0, 0, 0.45) !important;
    }

    /* Main wrapper mở rộng toàn màn hình */
    #main-wrapper {
        margin-left: 0 !important;
        width: 100% !important;
        max-width: 100vw !important;
    }

    /* Topbar gọn hơn */
    #topbar {
        padding: 0 1rem;
    }

    /* Content padding linh hoạt */
    main.p-4 {
        padding: 1rem !important;
    }

    /* Rút gọn tiêu đề bảng hoặc thẻ nếu cần */
    .card-saas {
        margin-bottom: 1rem;
    }
}

/* SMARTPHONE & NARROW SCREENS (< 576px) */
@media (max-width: 575.98px) {
    #topbar {
        padding: 0 0.75rem;
        height: 56px;
    }

    /* Giữ avatar & icon đăng xuất gọn gàng */
    #user-plan-container .badge {
        font-size: 0.72rem;
    }

    /* Tối ưu Stat Cards 2x2 */
    .stat-card {
        padding: 0.85rem 0.75rem;
    }

    .stat-icon {
        width: 42px;
        height: 42px;
        min-width: 42px;
        font-size: 1.15rem;
        margin-right: 0.6rem;
        border-radius: 10px;
    }

    .stat-val {
        font-size: 1.25rem;
    }

    .stat-lbl {
        font-size: 0.72rem;
        line-height: 1.25;
    }

    /* Header của thẻ SaaS */
    .card-header-saas {
        padding: 0.75rem 0.85rem;
        gap: 0.5rem;
    }

    /* Container biểu đồ Chart.js co giãn vừa tầm mắt điện thoại */
    .chart-container-responsive {
        height: 240px !important;
    }

    /* Cuộn bảng mượt mà trên cảm ứng */
    .table-responsive {
        -webkit-overflow-scrolling: touch;
        border-radius: 8px;
    }

    .table-saas thead th,
    .table-saas tbody td {
        padding: 0.55rem 0.65rem;
        font-size: 0.82rem;
    }

    /* Nút bấm trên mobile vừa vặn ngón tay */
    .btn-primary-saas,
    .btn-accent-saas {
        padding: 0.5rem 0.85rem;
        font-size: 0.85rem;
    }
}

/* Chống tự động phóng to (Auto-zoom) trên iOS Safari khi chạm vào ô nhập */
@media (max-width: 767.98px) {
    input.form-control,
    select.form-select,
    textarea.form-control {
        font-size: 16px !important;
    }
}

