:root {
    /* Brand & Accent */
    --color-primary: #1d4ed8;
    --color-primary-hover: #1e40af;
    --color-primary-light: #eff6ff;
    --color-accent: #0284c7;
    --color-accent-light: #f0f9ff;
    --color-accent-gold: #d97706;
    --color-accent-gold-light: #fffbeb;

    /* Neutrals & Surfaces (Light Mode) */
    --color-bg: #f8fafc;
    --color-surface: #ffffff;
    --color-surface-subtle: #f1f5f9;
    --color-border: #e2e8f0;
    --color-border-subtle: #f1f5f9;
    --color-border-strong: #cbd5e1;

    /* Typography Colors */
    --color-text: #0f172a;
    --color-text-subtle: #334155;
    --color-text-muted: #64748b;
    --color-text-disabled: #94a3b8;

    /* Semantic States */
    --color-success: #10b981;
    --color-success-bg: #ecfdf5;
    --color-success-text: #065f46;
    --color-warning: #f59e0b;
    --color-warning-bg: #fffbeb;
    --color-warning-text: #92400e;
    --color-danger: #ef4444;
    --color-danger-bg: #fef2f2;
    --color-danger-text: #991b1b;
    --color-purple: #8b5cf6;
    --color-purple-bg: #f5f3ff;
    --color-purple-text: #5b21b6;

    /* Backward-compatible token aliases */
    --ink: var(--color-text);
    --muted: var(--color-text-muted);
    --line: var(--color-border);
    --blue: var(--color-primary);
    --blue-dark: var(--color-primary-hover);
    --blue-soft: var(--color-primary-light);
    --white: #ffffff;

    /* Dashboard & Module Aliases */
    --dash-bg: var(--color-bg);
    --dash-card-bg: var(--color-surface);
    --dash-border: var(--color-border);
    --dash-text: var(--color-text);
    --dash-text-muted: var(--color-text-muted);
    --dash-primary: var(--color-primary);
    --dash-primary-hover: var(--color-primary-hover);
    --dash-primary-light: var(--color-primary-light);
    --dash-success: var(--color-success);
    --dash-success-light: var(--color-success-bg);
    --dash-warning: var(--color-warning);
    --dash-warning-light: var(--color-warning-bg);
    --dash-danger: var(--color-danger);
    --dash-danger-light: var(--color-danger-bg);
    --dash-purple: var(--color-purple);
    --dash-purple-light: var(--color-purple-bg);

    /* Radii & Shadows */
    --radius-sm: 6px;
    --radius-md: 9px;
    --radius-lg: 14px;
    --radius-xl: 18px;
    --radius-full: 9999px;

    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-card: 0 1px 3px 0 rgba(15, 23, 42, 0.05), 0 1px 2px -1px rgba(15, 23, 42, 0.05);
    --shadow-hover: 0 4px 12px -2px rgba(15, 23, 42, 0.08), 0 2px 4px -2px rgba(15, 23, 42, 0.04);
    --shadow-dropdown: 0 12px 32px -4px rgba(15, 23, 42, 0.12), 0 4px 6px -2px rgba(15, 23, 42, 0.04);
    --shadow-modal: 0 25px 50px -12px rgba(15, 23, 42, 0.25);

    /* Fonts */
    --font-sans: 'Plus Jakarta Sans', ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-display: 'Space Grotesk', 'Plus Jakarta Sans', sans-serif;

    /* Transitions */
    --transition-fast: 0.15s cubic-bezier(0.16, 1, 0.3, 1);
    --transition-base: 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Dark Mode Unified Tokens */
body.theme-dark {
    --color-bg: #0b1220;
    --color-surface: #17243a;
    --color-surface-subtle: #1d2d47;
    --color-border: #2b3d58;
    --color-border-subtle: #22334d;
    --color-border-strong: #3b5272;

    --color-text: #f1f5f9;
    --color-text-subtle: #cbd5e1;
    --color-text-muted: #94a3b8;
    --color-text-disabled: #718096;

    --color-primary: #4f8cff;
    --color-primary-hover: #73a4ff;
    --color-primary-light: rgba(79, 140, 255, 0.16);
    --color-accent: #a78bfa;
    --color-accent-light: rgba(167, 139, 250, 0.15);

    --color-success: #34d399;
    --color-success-bg: rgba(52, 211, 153, 0.15);
    --color-success-text: #34d399;
    --color-warning: #fbbf24;
    --color-warning-bg: rgba(251, 191, 36, 0.15);
    --color-warning-text: #fbbf24;
    --color-danger: #fb7185;
    --color-danger-bg: rgba(251, 113, 133, 0.15);
    --color-danger-text: #fb7185;
    --color-purple: #a78bfa;
    --color-purple-bg: rgba(167, 139, 250, 0.15);
    --color-purple-text: #c4b5fd;

    --shadow-card: 0 1px 4px rgba(0, 0, 0, 0.3);
    --shadow-hover: 0 6px 20px rgba(0, 0, 0, 0.45);
    --shadow-dropdown: 0 18px 50px rgba(0, 0, 0, 0.6);
    --shadow-modal: 0 25px 60px rgba(0, 0, 0, 0.7);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    color: var(--color-text);
    font-family: var(--font-sans);
    font-size: 13.5px;
    line-height: 1.5;
    background: var(--color-bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-display);
    color: var(--color-text);
    letter-spacing: -0.015em;
    margin-top: 0;
}

button,
input,
select,
textarea {
    font-family: var(--font-sans);
    font-size: 13.5px;
}

button,
a {
    -webkit-tap-highlight-color: transparent;
}

a {
    color: inherit;
    text-decoration: none;
}

/* ============================================================================
 * UNIFIED BUTTON SYSTEM
 * ========================================================================== */
.btn,
.submit-button,
.workflow-primary,
.emp-btn-primary,
.users-btn-primary,
.settings-btn--primary,
.att-primary,
.ct-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 38px;
    padding: 0 16px;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
    white-space: nowrap;
    user-select: none;
    transition: all var(--transition-fast);
}

/* Primary Style */
.btn-primary,
.submit-button,
.workflow-primary,
.emp-btn-primary,
.users-btn-primary,
.settings-btn--primary,
.att-primary,
.ct-primary {
    color: #ffffff;
    background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
    box-shadow: 0 2px 6px rgba(29, 78, 216, 0.25);
}

.btn-primary:hover,
.submit-button:hover,
.workflow-primary:hover,
.emp-btn-primary:hover,
.users-btn-primary:hover,
.settings-btn--primary:hover,
.att-primary:hover,
.ct-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(29, 78, 216, 0.35);
    background: linear-gradient(135deg, var(--color-primary-hover), var(--color-primary));
}

.btn-primary:active,
.submit-button:active,
.workflow-primary:active {
    transform: translateY(0);
}

.submit-button {
    width: 100%;
    height: 48px;
    font-size: 14px;
}

/* Secondary & Outline Buttons */
.btn-secondary,
.workflow-secondary,
.emp-btn-outline,
.users-btn-secondary,
.settings-btn--secondary,
.outline-button,
.ct-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 38px;
    padding: 0 14px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    color: var(--color-text-subtle);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-secondary:hover,
.workflow-secondary:hover,
.emp-btn-outline:hover,
.users-btn-secondary:hover,
.settings-btn--secondary:hover,
.outline-button:hover,
.ct-secondary:hover {
    background: var(--color-surface-subtle);
    border-color: var(--color-border-strong);
    color: var(--color-text);
}

/* Small Button Modifier */
.btn-sm,
.btn-xs {
    height: 30px;
    padding: 0 10px;
    font-size: 12px;
    border-radius: var(--radius-sm);
}

/* Disabled & Loading States */
button:disabled,
.btn:disabled,
.submit-button:disabled {
    cursor: not-allowed;
    opacity: 0.65;
    transform: none !important;
    box-shadow: none !important;
}

.submit-button.is-loading i,
.btn.is-loading i {
    display: none;
}

/* ============================================================================
 * UNIFIED SKELETON LOADERS
 * ========================================================================== */
.skeleton-shimmer {
    background: linear-gradient(
        90deg,
        rgba(226, 232, 240, 0.6) 25%,
        rgba(241, 245, 249, 0.9) 37%,
        rgba(226, 232, 240, 0.6) 63%
    );
    background-size: 400% 100%;
    animation: skeletonWave 1.4s ease infinite;
    border-radius: var(--radius-sm);
}

body.theme-dark .skeleton-shimmer {
    background: linear-gradient(
        90deg,
        rgba(30, 41, 59, 0.8) 25%,
        rgba(51, 65, 85, 0.9) 37%,
        rgba(30, 41, 59, 0.8) 63%
    );
    background-size: 400% 100%;
}

@keyframes skeletonWave {
    0% {
        background-position: 100% 50%;
    }
    100% {
        background-position: 0 50%;
    }
}

/* Page Transition animation */
.page-fade-in {
    animation: pageFadeIn 0.2s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes pageFadeIn {
    from {
        opacity: 0;
        transform: translateY(4px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.toast-region {
    position: fixed;
    z-index: 99999 !important;
    right: 24px;
    top: 24px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 18px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    color: var(--color-text);
    background: var(--color-surface);
    box-shadow: var(--shadow-dropdown);
    font-size: 13.5px;
    font-weight: 600;
    pointer-events: auto;
    animation: toastSlideIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes toastSlideIn {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.toast i {
    font-size: 18px;
    color: #10b981;
}

.toast--error i {
    color: #ef4444;
}

.toast--info i {
    color: #2563eb;
}

.toast--warning i {
    color: #f59e0b;
}

.toast--leaving {
    opacity: 0;
    transform: translateY(-8px);
    transition: 0.25s ease;
}

/* ============================================================================
 * MODERN ALERT / NOTIFICATION MODAL
 * Thay thế hoàn toàn alert() mặc định bằng popup modal cao cấp
 * ========================================================================== */
.app-alert-backdrop {
    position: fixed;
    inset: 0;
    z-index: 100010 !important;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    opacity: 0;
    transition: opacity 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.app-alert-backdrop.is-active {
    opacity: 1;
}

.app-alert-dialog {
    position: relative;
    width: 100%;
    max-width: 420px;
    background: #ffffff;
    border-radius: 20px;
    border: 1px solid rgba(226, 232, 240, 0.9);
    box-shadow:
        0 25px 50px -12px rgba(15, 23, 42, 0.28),
        0 0 0 1px rgba(15, 23, 42, 0.05);
    padding: 28px 24px 22px;
    text-align: center;
    transform: scale(0.92) translateY(8px);
    opacity: 0;
    transition:
        transform 0.22s cubic-bezier(0.16, 1, 0.3, 1),
        opacity 0.2s;
    box-sizing: border-box;
}

.app-alert-backdrop.is-active .app-alert-dialog {
    transform: scale(1) translateY(0);
    opacity: 1;
}

/* Dark Mode */
body.theme-dark .app-alert-dialog {
    background: #1e293b;
    border-color: #334155;
    box-shadow:
        0 25px 50px -12px rgba(0, 0, 0, 0.5),
        0 0 0 1px rgba(255, 255, 255, 0.05);
}

/* Close Button */
.app-alert-close-btn {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: none;
    background: #f1f5f9;
    color: #64748b;
    display: grid;
    place-items: center;
    font-size: 13px;
    cursor: pointer;
    transition:
        background 0.15s,
        color 0.15s,
        transform 0.15s;
}
.app-alert-close-btn:hover {
    background: #e2e8f0;
    color: #0f172a;
    transform: scale(1.05);
}
body.theme-dark .app-alert-close-btn {
    background: #0f172a;
    color: #94a3b8;
}
body.theme-dark .app-alert-close-btn:hover {
    background: #334155;
    color: #f8fafc;
}

/* Icon */
.app-alert-icon-wrap {
    width: 58px;
    height: 58px;
    border-radius: 50%;
    margin: 0 auto 16px;
    display: grid;
    place-items: center;
    font-size: 26px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
}

/* Title & Message */
.app-alert-title {
    margin: 0 0 8px;
    font-size: 18px;
    font-weight: 800;
    color: #0f172a;
    line-height: 1.3;
}
body.theme-dark .app-alert-title {
    color: #f8fafc;
}

.app-alert-message {
    margin: 0 0 22px;
    font-size: 14px;
    line-height: 1.55;
    color: #475569;
    word-break: break-word;
}
body.theme-dark .app-alert-message {
    color: #cbd5e1;
}

/* Footer & Buttons */
.app-alert-footer {
    display: flex;
    gap: 12px;
}
.app-alert-footer--confirm {
    display: grid;
    grid-template-columns: 1fr 1fr;
}

.app-alert-btn {
    height: 42px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 700;
    border: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease-in-out;
}

.app-alert-btn--primary {
    width: 100%;
    background: #2563eb;
    color: #ffffff;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.25);
}
.app-alert-btn--primary:hover {
    background: #1d4ed8;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
}
.app-alert-btn--primary:active {
    transform: translateY(0);
}

.app-alert-btn--cancel {
    background: #f1f5f9;
    color: #475569;
}
.app-alert-btn--cancel:hover {
    background: #e2e8f0;
    color: #0f172a;
}
body.theme-dark .app-alert-btn--cancel {
    background: #334155;
    color: #cbd5e1;
}
body.theme-dark .app-alert-btn--cancel:hover {
    background: #475569;
    color: #f8fafc;
}

.app-alert-btn--confirm {
    background: #2563eb;
    color: #ffffff;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.25);
}
.app-alert-btn--confirm:hover {
    background: #1d4ed8;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
}
button[aria-disabled="true"], .is-api-unsupported {
    cursor: not-allowed !important;
    opacity: .55;
}
.app-page-hidden{display:none!important}.app-pagination{display:flex;align-items:center;justify-content:space-between;gap:12px;padding:14px 16px;border-top:1px solid #e2e8f0;color:#64748b;font-size:12px}
.app-pagination>div{display:flex;align-items:center;gap:5px}.app-pagination button{display:grid;min-width:34px;height:34px;padding:0 8px;place-items:center;border:1px solid #cbd5e1;border-radius:8px;color:#334155;background:#fff;font-size:12px;font-weight:700;cursor:pointer;transition:.16s ease}
.app-pagination button:hover:not(:disabled),.app-pagination button.is-active{border-color:#2563eb;color:#fff;background:#2563eb;box-shadow:0 3px 9px rgba(37,99,235,.18)}.app-pagination button:disabled{opacity:.4;cursor:not-allowed}
body.theme-dark .app-pagination{border-color:#334155;color:#94a3b8}body.theme-dark .app-pagination button{border-color:#475569;color:#cbd5e1;background:#172033}body.theme-dark .app-pagination button:hover:not(:disabled),body.theme-dark .app-pagination button.is-active{border-color:#60a5fa;color:#fff;background:#2563eb}
@media(max-width:640px){.app-pagination{align-items:flex-start;flex-direction:column}.app-pagination>div{max-width:100%;overflow-x:auto}}
/* Khung tải luôn có sẵn trong CSS lõi để chuyển menu không lộ trang trắng. */
.wf-skeleton{display:grid;gap:12px;padding:24px;max-width:1440px;margin:0 auto}.wf-skeleton__row{display:grid;grid-template-columns:44px minmax(0,1fr) 92px;align-items:center;gap:14px;padding:16px;border:1px solid #e2e8f0;border-radius:12px;background:#fff}.wf-skeleton__row>div:nth-child(2){display:grid;gap:9px}.wf-skeleton__block{height:12px;border-radius:999px;background:linear-gradient(90deg,#edf2f7 25%,#f8fafc 50%,#edf2f7 75%);background-size:200% 100%;animation:wf-skeleton-pulse 1.25s ease-in-out infinite}.wf-skeleton__block--avatar{width:44px;height:44px;border-radius:10px}.wf-skeleton__block--short{width:45%}.wf-skeleton__block--pill{width:92px;height:28px}@keyframes wf-skeleton-pulse{to{background-position:-200% 0}}@media(max-width:640px){.wf-skeleton{padding:14px}.wf-skeleton__row{grid-template-columns:38px minmax(0,1fr)}.wf-skeleton__block--pill{display:none}}

/* Hard refresh: giữ màn khởi động sạch đến khi CSS route sẵn sàng. */
body.app-route-booting{margin:0;background:#f5f9ff;overflow:hidden}body.app-route-booting #app{visibility:visible}body.app-route-booting #toast-region{display:none}
/* Chuyển menu: giữ màn cũ ổn định, chỉ báo tiến độ bằng vạch mảnh trên cùng. */
body.app-route-pending::after{content:"";position:fixed;z-index:10000;top:0;left:0;width:35%;height:2px;background:linear-gradient(90deg,#2563eb,#06b6d4);box-shadow:0 0 8px rgba(37,99,235,.35);animation:app-route-progress .8s ease-in-out infinite alternate;pointer-events:none}@keyframes app-route-progress{from{transform:translateX(-25%)}to{transform:translateX(260%)}}

/* ---- Ảnh tối ưu (AppCore.images): nền chờ trong lúc tải, không nhấp nháy, ảnh lỗi gọn gàng ---- */
img[data-ps-thumb] {
    background: linear-gradient(110deg, #eef2f7 30%, #f8fafc 50%, #eef2f7 70%) 0 0 / 200% 100%;
    animation: ps-img-shimmer 1.2s linear infinite;
}
img[data-ps-thumb].is-loaded,
img[data-ps-thumb].is-broken {
    background: transparent;
    animation: none;
}
img.is-broken {
    object-fit: contain !important;
    background: #f8fafc !important;
}
@keyframes ps-img-shimmer {
    to { background-position: -200% 0; }
}
@media (prefers-reduced-motion: reduce) {
    img[data-ps-thumb] { animation: none; }
}
