/* ============================================================
   JustPlay Portal — Mobile-first design system
   ============================================================ */

:root {
    --hm-primary: #dc2626;
    --hm-primary-dark: #b91c1c;
    --hm-primary-hover: #b91c1c;
    --hm-primary-light: rgba(220, 38, 38, 0.1);
    --hm-primary-soft: rgba(220, 38, 38, 0.08);
    --hm-primary-subtle: rgba(220, 38, 38, 0.15);
    --hm-bg-light: #f8fafc;
    --hm-card-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
    --jp-radius: 16px;
    --jp-radius-lg: 20px;
    --jp-touch: 44px;
    --jp-bottom-nav-h: 4.25rem;
    --jp-safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* --- Brand utilities --- */
.bg-hm { background-color: var(--hm-primary) !important; }
.text-hm { color: var(--hm-primary) !important; }
.border-hm { border-color: var(--hm-primary) !important; }
.bg-hm-subtle { background-color: var(--hm-primary-light) !important; }
.border-hm-subtle { border-color: rgba(220, 38, 38, 0.2) !important; }

.btn-hm {
    background-color: var(--hm-primary);
    color: white;
    border: none;
    min-height: var(--jp-touch);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
}

.btn-hm:hover,
.btn-hm:focus {
    background-color: var(--hm-primary-dark);
    color: white;
}

.btn-outline-hm {
    color: var(--hm-primary);
    border-color: var(--hm-primary);
    min-height: var(--jp-touch);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-outline-hm:hover,
.btn-outline-hm:focus {
    background-color: var(--hm-primary);
    color: white;
}

/* --- Base layout --- */
html {
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--hm-bg-light);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
}

body.jp-auth main {
    padding-bottom: calc(var(--jp-bottom-nav-h) + var(--jp-safe-bottom) + 0.5rem);
}

@media (min-width: 992px) {
    body.jp-auth main {
        padding-bottom: 0;
    }
}

.jp-page {
    padding-left: max(0.75rem, env(safe-area-inset-left));
    padding-right: max(0.75rem, env(safe-area-inset-right));
}

.jp-page-header {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

@media (min-width: 768px) {
    .jp-page-header {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }
}

.jp-page-title {
    font-size: clamp(1.25rem, 4vw, 1.75rem);
    font-weight: 700;
    margin: 0;
    line-height: 1.25;
}

.jp-page-subtitle {
    color: #64748b;
    font-size: 0.875rem;
    margin: 0.25rem 0 0;
    overflow-wrap: anywhere;
    word-break: break-word;
}

/* --- Global text overflow (all pages) --- */
.jp-text-truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
    max-width: 100%;
}

.jp-text-clamp-1,
.jp-text-clamp-2,
.jp-text-clamp-3,
.jp-text-clamp {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    overflow: hidden;
    overflow-wrap: anywhere;
    word-break: break-word;
    max-width: 100%;
}

.jp-text-clamp-1,
.jp-text-clamp { -webkit-line-clamp: 1; }
.jp-text-clamp-2 { -webkit-line-clamp: 2; }
.jp-text-clamp-3 { -webkit-line-clamp: 3; }

.jp-text-break {
    overflow-wrap: anywhere;
    word-break: break-word;
    hyphens: auto;
}

/* Flex/grid children must shrink so ellipsis/clamp works */
main .d-flex > :not(.flex-shrink-0):not(.btn):not(.badge):not(.input-group):not(.form-control):not(.form-select),
main .d-flex > .flex-grow-1,
main .card-body > .d-flex > div:first-child,
main .jp-page-header > div:first-child,
main .list-group-item .flex-grow-1,
main .kanban-card .d-flex > h6 {
    min-width: 0;
}

main h1, main h2, main h3, main h4, main h5, main h6,
.modal-title {
    overflow-wrap: anywhere;
    word-break: break-word;
    max-width: 100%;
}

/* Card / portal titles */
main .card-title,
main .course-title,
main .exam-title,
main .portal-card h5,
main .card-body > h5.fw-bold,
main .card-body h5.fw-bold.mb-1,
main .card-body h5.fw-bold.mb-2,
main .card-body h5.fw-bold.mb-3,
main .jp-dashboard-item-title {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    overflow: hidden;
    overflow-wrap: anywhere;
    word-break: break-word;
    -webkit-line-clamp: 2;
}

main .card-body > p.text-muted.mb-2,
main .card-body > p.text-muted.mb-3,
main .jp-dashboard-item-text {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    overflow: hidden;
    overflow-wrap: anywhere;
    word-break: break-word;
    -webkit-line-clamp: 3;
}

/* Tables — wrap long cell content */
main table.jp-table td,
main .table-responsive table td,
main .table-responsive table th {
    overflow-wrap: anywhere;
    word-break: break-word;
}

@media (min-width: 768px) {
    main table.jp-table td:not(.jp-td-actions),
    main .table-responsive table td:not(.jp-td-actions) {
        max-width: 280px;
    }

    main table td .fw-bold.text-dark,
    main table td h6.fw-bold,
    main table td .course-title {
        display: -webkit-box;
        -webkit-box-orient: vertical;
        overflow: hidden;
        -webkit-line-clamp: 2;
    }

    main table td .small.text-muted {
        display: -webkit-box;
        -webkit-box-orient: vertical;
        overflow: hidden;
        -webkit-line-clamp: 1;
    }
}

/* Kanban cards */
.kanban-card h6.fw-bold.text-dark {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    overflow: hidden;
    overflow-wrap: anywhere;
    word-break: break-word;
    -webkit-line-clamp: 2;
}

.kanban-card p.text-hm,
.kanban-card .x-small.text-hm {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    overflow: hidden;
    overflow-wrap: anywhere;
    word-break: break-word;
    -webkit-line-clamp: 2;
    margin-bottom: 0.35rem !important;
}

/* Announcement / list cards — stack action button on mobile */
main .card-body > .d-flex.justify-content-between.align-items-start {
    gap: 0.75rem;
}

main .card-body > .d-flex.justify-content-between.align-items-start > .btn {
    flex-shrink: 0;
}

@media (max-width: 767.98px) {
    main .card-body > .d-flex.justify-content-between.align-items-start:not(.flex-wrap) {
        flex-direction: column;
        align-items: stretch !important;
    }

    main .card-body > .d-flex.justify-content-between.align-items-start > .btn {
        width: 100%;
    }
}

/* Nav / drawer / bottom bar */
.navbar .text-truncate,
.jp-mobile-drawer .offcanvas-body .fw-bold,
.jp-bottom-nav a span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

.jp-mobile-drawer .offcanvas-body .fw-bold {
    max-width: calc(100vw - 7rem);
}

/* Badges in tight rows */
main .d-flex .badge,
main .d-flex.align-items-center .badge {
    flex-shrink: 0;
    max-width: min(100%, 12rem);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Alerts, breadcrumbs, dropdowns */
main .alert,
.breadcrumb-item.active,
.dropdown-item {
    overflow-wrap: anywhere;
    word-break: break-word;
}

.breadcrumb {
    flex-wrap: wrap;
}

/* Form read-only / mono text (emails, codes) */
.jp-mono-text,
main code,
main .font-monospace {
    overflow-wrap: anywhere;
    word-break: break-all;
}

/* Long URLs and pre blocks */
main a[href^="http"],
main pre {
    overflow-wrap: anywhere;
    word-break: break-word;
}

@media (max-width: 767.98px) {
    main .breadcrumb-item {
        max-width: 100%;
    }

    main .breadcrumb-item.active {
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    main .input-group[style*="width"] {
        width: 100% !important;
        max-width: 100% !important;
    }
}

/* --- Navbar --- */
.navbar {
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
    padding-top: 0.65rem;
    padding-bottom: 0.65rem;
    padding-left: max(0.75rem, env(safe-area-inset-left));
    padding-right: max(0.75rem, env(safe-area-inset-right));
}

.navbar-brand img {
    height: 40px;
    width: auto;
    object-fit: contain;
    filter: brightness(0) invert(1);
}

@media (min-width: 768px) {
    .navbar-brand img {
        height: 45px;
    }
}

.nav-link {
    font-weight: 500;
    color: rgba(255, 255, 255, 0.9) !important;
    transition: background 0.2s, color 0.2s;
    margin: 0 2px;
    padding: 0.65rem 1rem !important;
    border-radius: 50rem;
    min-height: var(--jp-touch);
    display: flex;
    align-items: center;
}

.nav-link:hover {
    color: white !important;
    background-color: rgba(255, 255, 255, 0.15);
}

.nav-link.active {
    background-color: white !important;
    color: var(--hm-primary) !important;
    font-weight: 700;
    box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
}

.nav-link.locked {
    opacity: 0.6;
    cursor: not-allowed;
}

.nav-link.locked:hover {
    background-color: transparent;
    color: rgba(255, 255, 255, 0.85) !important;
}

.navbar-toggler {
    width: var(--jp-touch);
    height: var(--jp-touch);
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Mobile drawer */
.jp-mobile-drawer {
    width: min(88vw, 320px);
    background: linear-gradient(180deg, #b91c1c 0%, #991b1b 100%);
    color: white;
    border: none;
}

.jp-mobile-drawer .offcanvas-header {
    border-bottom: 1px solid rgba(255, 255, 255, 0.15);
}

.jp-mobile-drawer .nav-link {
    width: 100%;
    margin: 0.15rem 0;
}

.jp-mobile-drawer .dropdown-divider {
    border-color: rgba(255, 255, 255, 0.2);
}

.jp-mobile-drawer .dropdown-item {
    border-radius: 0.5rem;
}

/* --- Bottom navigation (mobile app style) --- */
.jp-bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1030;
    display: flex;
    justify-content: space-around;
    align-items: stretch;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid rgba(15, 23, 42, 0.08);
    box-shadow: 0 -4px 24px rgba(15, 23, 42, 0.08);
    padding-bottom: var(--jp-safe-bottom);
    min-height: calc(var(--jp-bottom-nav-h) + var(--jp-safe-bottom));
}

.jp-bottom-nav a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.15rem;
    padding: 0.45rem 0.25rem;
    text-decoration: none;
    color: #64748b;
    font-size: 0.625rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    transition: color 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.jp-bottom-nav a i {
    font-size: 1.35rem;
    line-height: 1;
}

.jp-bottom-nav a.active {
    color: var(--hm-primary);
}

.jp-bottom-nav a.active i {
    transform: scale(1.05);
}

.jp-bottom-nav .jp-nav-badge {
    position: absolute;
    top: 0.2rem;
    margin-left: 1.1rem;
    font-size: 0.6rem;
    padding: 0.15em 0.45em;
}

.jp-bottom-nav-item {
    position: relative;
    flex: 1;
    display: flex;
}

/* --- Cards & surfaces --- */
.card {
    border-radius: var(--jp-radius);
}

.rounded-4 {
    border-radius: var(--jp-radius-lg) !important;
}

.shadow-sm {
    box-shadow: var(--hm-card-shadow) !important;
}

/* --- Forms (touch-friendly) --- */
.form-control,
.form-select {
    min-height: var(--jp-touch);
    font-size: 16px; /* prevent iOS zoom */
    border-radius: 12px;
}

.form-control-sm,
.form-select-sm {
    min-height: 38px;
    font-size: 14px;
}

.form-label {
    font-weight: 600;
    font-size: 0.8125rem;
    margin-bottom: 0.35rem;
}

.input-group-text {
    min-height: var(--jp-touch);
}

textarea.form-control {
    min-height: 6rem;
}

/* --- Tables: responsive card stack on mobile --- */
.jp-table-wrap {
    border-radius: var(--jp-radius);
    overflow: hidden;
    -webkit-overflow-scrolling: touch;
}

.jp-table-wrap:not(.jp-table-scroll) {
    overflow-x: auto;
}

.jp-table {
    margin-bottom: 0;
}

@media (max-width: 767.98px) {
    .jp-table-stack thead {
        display: none;
    }

    .jp-table-stack tbody tr {
        display: block;
        background: white;
        border: 1px solid #e2e8f0;
        border-radius: var(--jp-radius);
        margin-bottom: 0.75rem;
        padding: 0.75rem;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
    }

    .jp-table-stack tbody td {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        gap: 1rem;
        padding: 0.45rem 0;
        border: none;
        text-align: right !important;
        white-space: normal;
        word-break: break-word;
    }

    .jp-table-stack tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        font-size: 0.75rem;
        color: #64748b;
        text-align: left;
        flex-shrink: 0;
        max-width: 45%;
    }

    .jp-table-stack tbody td:empty,
    .jp-table-stack tbody td.jp-td-actions {
        justify-content: flex-end;
    }

    .jp-table-stack tbody td.jp-td-actions::before {
        display: none;
    }

    .jp-table-stack tfoot {
        display: block;
        padding: 0.5rem;
    }

    .jp-table-stack tfoot tr {
        display: flex;
        justify-content: space-between;
    }
}

/* KPI wide table — scroll hint on mobile */
.jp-kpi-scroll {
    position: relative;
}

.jp-kpi-scroll::after {
    content: '← Vuốt ngang →';
    display: block;
    text-align: center;
    font-size: 0.7rem;
    color: #94a3b8;
    padding: 0.35rem;
    background: #f1f5f9;
}

@media (min-width: 768px) {
    .jp-kpi-scroll::after {
        display: none;
    }
}

@media (max-width: 767.98px) {
    .sticky-col-1,
    .sticky-col-2,
    .sticky-col-header-1,
    .sticky-col-header-2 {
        position: static !important;
        left: auto !important;
        box-shadow: none !important;
        min-width: auto !important;
    }

    .table-kpi th,
    .table-kpi td {
        font-size: 0.8rem;
        padding: 8px !important;
    }

    .input-score,
    .input-readonly {
        width: 56px !important;
        min-height: 38px;
    }
}

/* --- Horizontal scroll tabs (admin dashboard, etc.) --- */
.jp-scroll-tabs,
.nav-pills-hm {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 0.35rem;
    max-width: 100%;
}

.jp-scroll-tabs::-webkit-scrollbar,
.nav-pills-hm::-webkit-scrollbar {
    display: none;
}

.jp-scroll-tabs .nav-link,
.nav-pills-hm .nav-link {
    white-space: nowrap;
    flex-shrink: 0;
}

/* --- Kanban mobile --- */
@media (max-width: 767.98px) {
    .kanban-wrapper {
        padding: 1rem 0.75rem !important;
    }

    .kanban-container {
        min-height: 60vh;
        gap: 0.75rem;
        padding-bottom: 0.5rem;
    }

    .col-kanban {
        flex: 0 0 85vw;
        max-width: 85vw;
    }

    .column-card {
        max-height: 70vh;
    }
}

/* --- Portal home cards --- */
.portal-container {
    min-height: auto;
    padding-top: 1rem;
    padding-bottom: 2rem;
}

@media (min-width: 768px) {
    .portal-container {
        min-height: auto;
        padding-top: 1.5rem;
        padding-bottom: 2.5rem;
    }
}

/* Dashboard widgets on home */
.jp-dashboard-panel {
    background: #fff;
    border-radius: var(--jp-radius-lg);
    box-shadow: 0 4px 18px rgba(15, 23, 42, 0.07);
    overflow: hidden;
    border: 1px solid #e2e8f0;
}

.jp-dashboard-panel-header {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.85rem 1.1rem;
    background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
    color: #fff;
    font-weight: 700;
    font-size: 0.95rem;
}

.jp-dashboard-list {
    display: flex;
    flex-direction: column;
}

.jp-dashboard-item {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding: 0.9rem 1.1rem;
    text-decoration: none;
    color: inherit;
    border-bottom: 1px solid #f1f5f9;
    transition: background 0.15s;
}

.jp-dashboard-item:last-child {
    border-bottom: none;
}

.jp-dashboard-item:hover {
    background: #f8fafc;
    color: inherit;
}

.jp-dashboard-item-icon {
    flex-shrink: 0;
    width: 42px;
    height: 42px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
}

.jp-dashboard-item--danger .jp-dashboard-item-icon {
    background: #fef2f2;
    color: #dc2626;
}

.jp-dashboard-item--warning .jp-dashboard-item-icon {
    background: #fffbeb;
    color: #d97706;
}

.jp-dashboard-item--info .jp-dashboard-item-icon {
    background: #eff6ff;
    color: #2563eb;
}

.jp-dashboard-item-body {
    flex: 1;
    min-width: 0;
}

.jp-dashboard-item-title {
    font-weight: 700;
    font-size: 0.9rem;
    color: #1e293b;
    margin-bottom: 0.15rem;
}

.jp-dashboard-item-text {
    font-size: 0.82rem;
    color: #64748b;
    line-height: 1.4;
}

.jp-dashboard-item-action {
    flex-shrink: 0;
    font-size: 0.8rem;
    font-weight: 700;
    color: #dc2626;
    white-space: nowrap;
}

.portal-card-badge {
    position: absolute;
    top: 10px;
    right: 10px;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: 999px;
    background: #dc2626;
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.portal-card {
    transition: transform 0.2s, box-shadow 0.2s;
    border: none;
    border-radius: var(--jp-radius-lg);
    overflow: hidden;
    text-decoration: none;
    background: white;
    height: 100%;
}

.portal-card:active {
    transform: scale(0.98);
}

@media (hover: hover) {
    .portal-card:hover {
        transform: translateY(-6px);
        box-shadow: 0 12px 28px rgba(220, 38, 38, 0.15) !important;
    }
}

.icon-circle {
    width: 64px;
    height: 64px;
    background: var(--hm-primary-soft);
    color: var(--hm-primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    margin: 0 auto 1rem;
}

@media (min-width: 768px) {
    .icon-circle {
        width: 80px;
        height: 80px;
        font-size: 2.5rem;
        margin-bottom: 1.5rem;
    }
}

/* --- Login / auth pages --- */
.login-container,
.change-password-container {
    margin-top: 5vh;
    margin-bottom: 3vh;
    padding-left: 0.75rem;
    padding-right: 0.75rem;
}

.card-login {
    border: none;
    border-radius: var(--jp-radius-lg);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.08);
    overflow: hidden;
    background: white;
}

.login-header {
    background-color: var(--hm-primary);
    padding: 2rem 1rem;
    color: white;
    text-align: center;
}

/* --- Sticky action bar (forms) --- */
.jp-sticky-actions {
    position: sticky;
    bottom: calc(var(--jp-bottom-nav-h) + var(--jp-safe-bottom));
    z-index: 1020;
    background: rgba(248, 250, 252, 0.95);
    backdrop-filter: blur(8px);
    margin: 0 -0.75rem;
    padding: 0.75rem;
    border-top: 1px solid #e2e8f0;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

@media (min-width: 992px) {
    .jp-sticky-actions {
        position: static;
        background: transparent;
        backdrop-filter: none;
        margin: 0;
        padding: 0;
        border: none;
    }
}

.jp-sticky-actions .btn {
    flex: 1 1 auto;
    min-width: min(100%, 140px);
}

/* --- Modals full-screen on mobile --- */
@media (max-width: 575.98px) {
    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }

    .modal-fullscreen-sm-down {
        width: 100vw;
        max-width: none;
        margin: 0;
    }
}

/* --- Alerts --- */
.alert {
    border-radius: 12px;
    font-size: 0.9rem;
}

/* --- Global mobile compact UI --- */
@media (max-width: 767.98px) {
    main .container,
    main .container-fluid {
        padding-left: max(0.65rem, env(safe-area-inset-left));
        padding-right: max(0.65rem, env(safe-area-inset-right));
    }

    main h1, main .h1 { font-size: 1.35rem; }
    main h2, main .h2, main .jp-page-title { font-size: 1.15rem; }
    main h3, main .h3 { font-size: 1.05rem; }
    main h4, main .h4 { font-size: 0.98rem; }
    main h5, main .h5 { font-size: 0.92rem; }

    main .jp-page-subtitle,
    main .text-muted.small:not(.badge):not(.jp-dashboard-item-text) {
        font-size: 0.78rem;
    }

    main .card-body {
        padding: 0.85rem 1rem !important;
    }

    main .card-header {
        padding: 0.7rem 1rem !important;
    }

    main .card-body.p-4,
    main .card-body.p-5,
    main .p-4:not(.modal-body):not(.offcanvas-body) {
        padding: 0.85rem 1rem !important;
    }

    main .p-5 {
        padding: 1rem !important;
    }

    main .py-5 {
        padding-top: 1.25rem !important;
        padding-bottom: 1.25rem !important;
    }

    main .mb-5 {
        margin-bottom: 1.25rem !important;
    }

    main .mb-4 {
        margin-bottom: 1rem !important;
    }

    main .gap-4 {
        gap: 0.65rem !important;
    }

    main .btn-lg {
        padding: 0.5rem 1rem;
        font-size: 0.9rem;
        min-height: 42px;
    }

    main .btn.rounded-pill.px-5,
    main .btn.rounded-pill.px-4 {
        padding-left: 1rem !important;
        padding-right: 1rem !important;
        font-size: 0.85rem;
    }

    main .display-1,
    main .display-4 {
        font-size: 2.25rem !important;
    }

    main .fs-4 { font-size: 1.05rem !important; }
    main .fs-5 { font-size: 0.95rem !important; }

    main .breadcrumb {
        font-size: 0.75rem;
        padding: 0.45rem 0.65rem !important;
        margin-bottom: 0.65rem !important;
    }

    main .alert {
        padding: 0.65rem 0.85rem;
        font-size: 0.85rem;
    }

    main .modal-body {
        padding: 1rem;
    }

    main .modal-header,
    main .modal-footer {
        padding: 0.75rem 1rem;
    }

    main .table .btn-sm {
        min-height: 38px;
        min-width: 38px;
    }

    .portal-container {
        padding-top: 0.5rem !important;
    }

    .icon-circle {
        width: 52px !important;
        height: 52px !important;
        font-size: 1.45rem !important;
        margin-bottom: 0.65rem !important;
    }

    .portal-card {
        padding: 0.75rem !important;
    }

    .portal-card h5 {
        font-size: 0.88rem !important;
        margin-bottom: 0.15rem !important;
    }

    .jp-dashboard-panel-header {
        padding: 0.65rem 0.85rem;
        font-size: 0.85rem;
    }

    .jp-dashboard-item {
        padding: 0.7rem 0.85rem;
        gap: 0.65rem;
    }

    .jp-dashboard-item-icon {
        width: 36px;
        height: 36px;
        font-size: 1rem;
    }

    .jp-dashboard-item-title {
        font-size: 0.82rem;
    }

    .jp-dashboard-item-text {
        font-size: 0.75rem;
    }

    .jp-bottom-nav a {
        font-size: 0.62rem;
        padding: 0.35rem 0.15rem 0.2rem;
    }

    .jp-bottom-nav a i {
        font-size: 1.15rem;
    }

    .jp-scroll-tabs-wrap {
        max-width: 100%;
        overflow: hidden;
    }

    main .custom-pills .nav-link {
        font-size: 0.78rem;
        padding: 0.4rem 0.75rem !important;
        white-space: nowrap;
    }

    /* Page headers: stack title + actions */
    main .d-flex.justify-content-between.align-items-center.mb-4,
    main .d-flex.justify-content-between.align-items-center.mb-3,
    main .d-flex.justify-content-between.align-items-start.mb-4,
    main .d-flex.justify-content-between.align-items-start.mb-3 {
        flex-direction: column;
        align-items: stretch !important;
        gap: 0.65rem;
    }

    main .d-flex.justify-content-between.align-items-center.mb-4 > .d-flex,
    main .d-flex.justify-content-between.align-items-center.mb-3 > .d-flex,
    main .d-flex.justify-content-between.align-items-start.mb-4 > .d-flex,
    main .d-flex.justify-content-between.align-items-start.mb-3 > .d-flex {
        flex-wrap: wrap;
        width: 100%;
    }

    main .d-flex.justify-content-between.align-items-center.mb-4 .btn,
    main .d-flex.justify-content-between.align-items-center.mb-3 .btn,
    main .d-flex.justify-content-between.align-items-start.mb-4 .btn,
    main .d-flex.justify-content-between.align-items-start.mb-3 .btn {
        flex: 1 1 auto;
        min-width: 0;
    }

    /* Kanban board */
    .kanban-wrapper {
        padding: 0.65rem 0.35rem 1rem !important;
    }

    .kanban-container {
        gap: 0.75rem;
        min-height: 65vh;
    }

    .col-kanban {
        flex: 0 0 260px;
        max-width: 280px;
    }

    .jp-kanban-toolbar .btn {
        font-size: 0.78rem;
        padding: 0.45rem 0.65rem;
        min-height: 40px;
    }

    .jp-kanban-filter {
        min-width: 100% !important;
    }

    /* Admin dashboard stat cards */
    main .stat-card {
        padding: 0.85rem 1rem !important;
        border-radius: 14px !important;
    }

    main .stat-card h2 {
        font-size: 1.35rem !important;
    }

    main .stat-card .icon-box {
        width: 40px !important;
        height: 40px !important;
        font-size: 1.1rem !important;
    }

    main .nav-pills-hm .nav-link {
        padding: 0.45rem 0.85rem !important;
        font-size: 0.78rem !important;
    }

    /* KPI matrix table — narrower sticky columns */
    .table-kpi-wrap .sticky-col-1,
    .table-kpi-wrap .sticky-col-header-1 {
        min-width: 88px !important;
        left: 0 !important;
        font-size: 0.72rem;
    }

    .table-kpi-wrap .sticky-col-2,
    .table-kpi-wrap .sticky-col-header-2 {
        min-width: 130px !important;
        left: 88px !important;
        font-size: 0.75rem;
    }

    .table-kpi-wrap .table-kpi th {
        font-size: 0.65rem;
        padding: 8px 6px;
    }

    .table-kpi-wrap .input-score,
    .table-kpi-wrap .input-readonly {
        width: 52px !important;
        font-size: 0.8rem;
    }

    .table-kpi-wrap .period-block {
        min-width: 180px;
    }

    .table-kpi-wrap .btn-mode {
        font-size: 0.6rem;
        padding: 2px 6px;
    }

    /* Guide page role badges — wrap tighter */
    .jp-guide-page .badge.rounded-pill {
        font-size: 0.72rem;
        padding: 0.35rem 0.65rem !important;
    }

    /* Hide verbose subtitles on small screens */
    main .jp-hide-mobile-subtitle {
        display: none !important;
    }
}

@media (min-width: 768px) {
    .jp-hide-mobile-subtitle {
        display: block !important;
    }
}

/* --- Utility --- */
.jp-hide-mobile {
    display: none !important;
}

@media (min-width: 768px) {
    .jp-hide-mobile {
        display: initial !important;
    }

    .jp-hide-desktop {
        display: none !important;
    }
}

.jp-stat-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
}

@media (min-width: 576px) {
    .jp-stat-grid {
        gap: 1rem;
    }
}

/* --- Reports entry table mobile --- */
#lines-table .form-control-sm,
#lines-table .form-select-sm {
    min-height: 38px;
    font-size: 14px;
}

@media (max-width: 767.98px) {
    #lines-table thead {
        display: none;
    }

    #lines-table .line-row {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0.5rem;
        padding: 0.75rem;
        margin-bottom: 0.75rem;
        background: #fff;
        border: 1px solid #e2e8f0;
        border-radius: 12px;
    }

    #lines-table .line-row td {
        display: block;
        border: none;
        padding: 0;
    }

    #lines-table .line-row td:nth-child(1)::before { content: 'Công đoạn'; display: block; font-size: 0.7rem; font-weight: 600; color: #64748b; margin-bottom: 0.2rem; }
    #lines-table .line-row td:nth-child(2)::before { content: 'Mã đơn'; display: block; font-size: 0.7rem; font-weight: 600; color: #64748b; margin-bottom: 0.2rem; }
    #lines-table .line-row td:nth-child(3)::before { content: 'Tên SP'; display: block; font-size: 0.7rem; font-weight: 600; color: #64748b; margin-bottom: 0.2rem; }
    #lines-table .line-row td:nth-child(4)::before { content: 'SL'; display: block; font-size: 0.7rem; font-weight: 600; color: #64748b; margin-bottom: 0.2rem; }
    #lines-table .line-row td:nth-child(5)::before { content: 'ĐVT'; display: block; font-size: 0.7rem; font-weight: 600; color: #64748b; margin-bottom: 0.2rem; }
    #lines-table .line-row td:nth-child(6)::before { content: 'Ghi chú'; display: block; font-size: 0.7rem; font-weight: 600; color: #64748b; margin-bottom: 0.2rem; }

    #lines-table .line-row td:last-child {
        grid-column: 1 / -1;
        text-align: right;
    }
}

/* --- User guide page (/huong-dan/) --- */
/* --- User guide page --- */
.jp-guide-page {
    --jp-guide-scroll-offset: 5.5rem;
}

@media (max-width: 991.98px) {
    .jp-guide-page {
        --jp-guide-scroll-offset: 8.75rem;
    }
}

.jp-guide-page .accordion-item[id] {
    scroll-margin-top: var(--jp-guide-scroll-offset);
}

.jp-guide-page .guide-sidebar {
    border: 1px solid #e2e8f0;
    overflow: hidden;
    background: #fff;
}

.jp-guide-page .guide-sidebar-header {
    background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
    color: #fff;
    padding: 1rem 1.1rem;
}

.jp-guide-page .guide-sidebar-header .small {
    color: rgba(255, 255, 255, 0.85) !important;
    letter-spacing: 0.04em;
}

.jp-guide-page .guide-toc {
    padding: 0.65rem 0.5rem 0.85rem;
}

.jp-guide-page .guide-toc-link {
    display: block;
    color: #475569 !important;
    font-weight: 500;
    font-size: 0.8125rem;
    padding: 0.45rem 0.75rem 0.45rem 0.85rem !important;
    margin: 0.1rem 0 !important;
    border-radius: 0.5rem !important;
    border-left: 3px solid transparent;
    text-decoration: none;
    line-height: 1.35;
    min-height: auto !important;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.jp-guide-page .guide-toc-link:hover {
    color: #dc2626 !important;
    background: #fef2f2 !important;
    border-left-color: #dc2626;
}

.jp-guide-page .guide-toc-link.active {
    color: #b91c1c !important;
    background: rgba(220, 38, 38, 0.08) !important;
    border-left-color: #dc2626;
    font-weight: 700;
    box-shadow: none !important;
}

.jp-guide-page .guide-mobile-toc {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 1rem;
    padding: 0.85rem 1rem;
    margin-bottom: 1rem;
}

.jp-guide-page .guide-mobile-toc-label {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #64748b;
    margin-bottom: 0.5rem;
}

.jp-guide-page .guide-mobile-toc-scroll {
    display: flex;
    gap: 0.4rem;
    overflow-x: auto;
    padding-bottom: 0.25rem;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}

.jp-guide-page .guide-mobile-toc-scroll .guide-toc-link {
    flex: 0 0 auto;
    white-space: nowrap;
    border: 1px solid #e2e8f0;
    border-left: 1px solid #e2e8f0 !important;
    border-radius: 999px !important;
    padding: 0.35rem 0.85rem !important;
    font-size: 0.75rem;
}

.jp-guide-page .guide-mobile-toc-scroll .guide-toc-link.active {
    background: #dc2626 !important;
    color: #fff !important;
    border-color: #dc2626 !important;
}

.jp-guide-page .guide-accordion .accordion-button:not(.collapsed) {
    background: rgba(220, 38, 38, 0.06);
    color: #b91c1c;
    box-shadow: none;
}

.jp-guide-page .guide-accordion .accordion-button:focus {
    box-shadow: none;
    border-color: transparent;
}

.jp-guide-page .guide-steps {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.jp-guide-page .guide-step {
    display: flex;
    gap: 0.85rem;
    align-items: flex-start;
    padding: 0.85rem 1rem;
    background: #f8fafc;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
    font-size: 0.95rem;
    line-height: 1.55;
}

.jp-guide-page .guide-step-num {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #dc2626;
    color: #fff;
    font-weight: 700;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.jp-guide-page .guide-step ul {
    padding-left: 1.1rem;
}

.jp-guide-page .guide-split {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.25rem;
    align-items: start;
    margin: 1rem 0 1.25rem;
}

@media (min-width: 768px) {
    .jp-guide-page .guide-split {
        grid-template-columns: 1fr min(280px, 38%);
    }

    .jp-guide-page .guide-split.guide-split-wide-img {
        grid-template-columns: 1fr min(320px, 42%);
    }
}

.jp-guide-page .guide-figure {
    margin: 0;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 1rem;
    overflow: hidden;
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.06);
}

.jp-guide-page .guide-figure img {
    display: block;
    width: 100%;
    max-width: 420px;
    margin: 0 auto;
    height: auto;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
}

.jp-guide-page .guide-figure figcaption {
    padding: 0.65rem 0.85rem;
    font-size: 0.78rem;
    color: #64748b;
    background: #f8fafc;
    border-top: 1px solid #e2e8f0;
    line-height: 1.4;
}

.jp-guide-page .guide-figure figcaption strong {
    color: #334155;
}

.jp-guide-page .guide-tip {
    border-left: 4px solid #dc2626;
    background: #fff;
    border-radius: 0 12px 12px 0;
    padding: 0.85rem 1rem;
    font-size: 0.875rem;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
}

.jp-guide-page .guide-preview-grid .guide-preview-item {
    display: block;
    text-decoration: none;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 0.75rem;
    overflow: hidden;
    transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
}

.jp-guide-page .guide-preview-grid .guide-preview-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(220, 38, 38, 0.12);
    border-color: #fecaca;
}

.jp-guide-page .guide-preview-grid img {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 9/16;
    object-fit: cover;
    object-position: top;
    border-radius: 10px;
    border: 1px solid #e2e8f0;
    background: #f8fafc;
}

.jp-guide-page .guide-preview-grid span {
    display: block;
    padding: 0.35rem 0.5rem;
    font-size: 0.68rem;
    font-weight: 700;
    text-align: center;
    color: #475569;
    background: #f8fafc;
    border-top: 1px solid #e2e8f0;
}

/* Dynamic guide content (CKEditor) */
.guide-prose {
    overflow-wrap: anywhere;
    word-break: break-word;
    line-height: 1.65;
    font-size: 0.95rem;
}

.guide-prose img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
}

.guide-prose table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
}

.guide-prose .guide-steps,
.jp-guide-page .guide-prose .guide-steps {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.guide-prose .guide-step,
.jp-guide-page .guide-prose .guide-step {
    display: flex;
    gap: 0.85rem;
    align-items: flex-start;
    padding: 0.85rem 1rem;
    background: #f8fafc;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
}

.guide-prose .guide-step-num,
.jp-guide-page .guide-prose .guide-step-num {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #dc2626;
    color: #fff;
    font-weight: 700;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* --- HRM admin (user list / form) --- */
.jp-hrm-page .jp-page-header {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

@media (min-width: 768px) {
    .jp-hrm-page .jp-page-header {
        flex-direction: row;
        align-items: flex-start;
        justify-content: space-between;
    }
}

.jp-hrm-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    width: 100%;
}

@media (min-width: 768px) {
    .jp-hrm-toolbar {
        width: auto;
        flex-wrap: nowrap;
        justify-content: flex-end;
    }
}

.jp-hrm-tool-btn {
    flex: 1 1 calc(33.333% - 0.35rem);
    min-height: var(--jp-touch);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-width: 2px;
    border-radius: 999px;
    font-size: 0.875rem;
    padding: 0.45rem 0.65rem;
}

@media (min-width: 768px) {
    .jp-hrm-tool-btn {
        flex: 0 0 auto;
        padding: 0.5rem 1rem;
    }
}

.jp-hrm-tool-btn-primary {
    flex: 1 1 100%;
}

@media (min-width: 768px) {
    .jp-hrm-tool-btn-primary {
        flex: 0 0 auto;
    }
}

.jp-hrm-card-header {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

@media (min-width: 768px) {
    .jp-hrm-card-header {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
    }
}

.jp-hrm-search {
    width: 100%;
}

@media (min-width: 768px) {
    .jp-hrm-search {
        max-width: 360px;
    }
}

.jp-hrm-search .form-control {
    min-height: var(--jp-touch);
}

.jp-hrm-avatar {
    width: 42px;
    height: 42px;
    flex-shrink: 0;
    background: linear-gradient(135deg, #dc2626, #ef4444);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    font-weight: 700;
    font-size: 1rem;
    box-shadow: 0 3px 6px rgba(220, 38, 38, 0.15);
}

.jp-hrm-actions {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.jp-hrm-actions .btn {
    min-width: var(--jp-touch);
    min-height: var(--jp-touch);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.jp-hrm-page .btn-white {
    background-color: #fff;
}

.jp-hrm-page .btn-white:hover {
    background-color: #f8f9fa;
}

.jp-hrm-page .bg-hm-subtle {
    background-color: rgba(220, 38, 38, 0.1) !important;
}

.jp-hrm-page .x-small {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

@media (max-width: 767.98px) {
    .jp-hrm-page .jp-table-stack tbody td.jp-td-primary {
        display: block;
        text-align: left !important;
        padding-bottom: 0.65rem;
        margin-bottom: 0.15rem;
        border-bottom: 1px dashed #e2e8f0;
    }

    .jp-hrm-page .jp-table-stack tbody td.jp-td-primary::before {
        display: none;
    }

    .jp-hrm-page .jp-table-stack tbody td.jp-td-empty {
        display: block;
        text-align: center !important;
    }

    .jp-hrm-page .jp-table-stack tbody td.jp-td-empty::before {
        display: none;
    }

    .jp-hrm-page .jp-table-stack tbody td.jp-td-actions {
        padding-top: 0.35rem;
    }

    .jp-hrm-page .jp-table-stack tbody td.jp-td-actions .jp-hrm-actions {
        width: 100%;
        justify-content: stretch;
    }

    .jp-hrm-page .jp-table-stack tbody td.jp-td-actions .jp-hrm-actions .btn,
    .jp-hrm-page .jp-table-stack tbody td.jp-td-actions .jp-hrm-actions form {
        flex: 1;
    }

    .jp-hrm-page .jp-table-stack tbody td.jp-td-actions .jp-hrm-actions .btn {
        width: 100%;
    }
}

.jp-hrm-back-btn {
    width: var(--jp-touch);
    height: var(--jp-touch);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.jp-hrm-page .custom-input-group input,
.jp-hrm-page .custom-input-group select,
.jp-hrm-page .form-control,
.jp-hrm-page .form-select {
    min-height: var(--jp-touch);
}

.jp-hrm-page .custom-input-group input,
.jp-hrm-page .custom-input-group select {
    border-top-left-radius: 0 !important;
    border-bottom-left-radius: 0 !important;
    border-left: 0 !important;
}

.jp-hrm-page select[multiple] {
    min-height: 150px;
    border: 1px solid #dee2e6 !important;
    border-radius: 8px !important;
    padding: 10px;
}

.jp-hrm-page .select2-container {
    width: 100% !important;
}

.jp-hrm-page .select2-container--bootstrap-5 .select2-selection {
    border-radius: 12px;
    border: 1px solid #dee2e6;
    padding: 0.3rem;
    min-height: var(--jp-touch);
}

.jp-hrm-page .select2-container--bootstrap-5 .select2-selection--multiple .select2-selection__choice {
    background-color: var(--hm-primary);
    color: #fff;
    border: none;
    border-radius: 20px;
    padding: 2px 10px;
    font-size: 0.85rem;
}

.jp-hrm-page .select2-container--bootstrap-5 .select2-selection--multiple .select2-selection__choice__remove {
    color: #fff;
    margin-right: 5px;
}

.jp-hrm-page .letter-spacing {
    letter-spacing: 0.5px;
}

