/* ==========================================================================
   NotaHR — Design System
   NOTA Group · Hệ thống Quản trị Nhân sự
   ========================================================================== */

:root {
    color-scheme: light;

    /* Brand — Base.vn-inspired */
    --navy:        #1e293b;   /* Sidebar & dark surfaces */
    --graphite:    #334155;   /* Table header, hover on dark */
    --slate:       #334155;
    --slate-mid:   #475569;
    --slate-light: #94A3B8;
    --slate-border:#CBD5E1;
    --off-white:   #F8FAFC;   /* App background */
    --line:        #E2E8F0;

    /* Primary — corporate navy blue (interactive elements) */
    --primary:     #1d4ed8;
    --primary-dk:  #1e40af;
    --primary-fg:  #ffffff;   /* Text/icons sitting ON --primary */

    /* Accents — for text/icons on DARK surfaces */
    --sky:    #38bdf8;
    --green:  #059669;
    --red:    #DC2626;
    --orange: #d97706;
    --yellow: #d97706;

    /* Semantic */
    --ok-bg:   #DCFCE7;  --ok-fg:   #166534;
    --warn-bg: #FEF3C7;  --warn-fg: #92400E;
    --err-bg:  #FEE2E2;  --err-fg:  #991B1B;
    --info-bg: #DBEAFE;  --info-fg: #1E40AF;
    --mute-bg: #F1F5F9;  --mute-fg: #475569;

    --shadow-sm: 0 1px 2px rgba(15,23,42,.06);
    --shadow:    0 1px 3px rgba(15,23,42,.10), 0 1px 2px rgba(15,23,42,.06);
    --shadow-lg: 0 10px 30px rgba(15,23,42,.12);

    --sidebar-w: 248px;
    --radius: 8px;
    --radius-lg: 12px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--off-white);
    color: var(--navy);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ============================ LAYOUT ============================ */

.layout { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    background: var(--navy);
    position: fixed;
    inset: 0 auto 0 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 100;
    transition: transform .25s ease-in-out;
}

/* Chỉ phần menu cuộn; khối người dùng + Đăng xuất luôn neo ở đáy */
.nav { flex: 1; min-height: 0; overflow-y: auto; padding: 12px 10px; }
.nav::-webkit-scrollbar { width: 6px; }
.nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 3px; }

.nav-group {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .8px;
    text-transform: uppercase;
    color: rgba(255,255,255,.32);
    padding: 14px 12px 6px;
}
.brand {
    padding: 20px 20px 18px;
    border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand h1 {
    font-size: 21px;
    font-weight: 800;
    letter-spacing: -.4px;
    color: #fff;
}
.brand h1 span { color: var(--sky); }  /* "HR" giữ tông sáng để nổi trên nền tối */
.brand p {
    font-size: 11px;
    color: rgba(255,255,255,.5);
    margin-top: 2px;
    letter-spacing: .3px;
    text-transform: uppercase;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 9px 12px;
    margin-bottom: 2px;
    border-radius: 8px;
    color: rgba(255,255,255,.72);
    text-decoration: none;
    font-size: 13.5px;
    font-weight: 500;
    transition: background .15s, color .15s;
}
.nav-link:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-link.active { background: var(--primary); color: var(--primary-fg); font-weight: 600; }
.nav-link.active svg { stroke: var(--primary-fg); }
.nav-link svg { width: 17px; height: 17px; flex-shrink: 0; }

.nav-badge {
    margin-left: auto;
    background: var(--red);
    color: #fff;
    font-size: 10.5px;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 9px;
    min-width: 18px;
    text-align: center;
}

.sidebar-foot {
    padding: 12px 10px 16px;
    border-top: 1px solid rgba(255,255,255,.08);
}

.user-chip {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 11px;
    border-radius: 8px;
    background: rgba(255,255,255,.06);
    margin-bottom: 8px;
}
.user-avatar {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: var(--primary);
    color: var(--primary-fg);
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: 13px;
    flex-shrink: 0;
}
.user-meta { min-width: 0; }
.user-meta strong {
    display: block;
    font-size: 12.5px;
    color: #fff;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.user-meta small { font-size: 10.5px; color: rgba(255,255,255,.55); }

.main {
    flex: 1;
    margin-left: var(--sidebar-w);
    min-width: 0;
}

.topbar {
    background: #fff;
    border-bottom: 1px solid var(--line);
    padding: 0 28px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 30;
}
.topbar > div:first-child { min-width: 0; flex: 1; }
.topbar h2 {
    font-size: 17px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.topbar .crumb {
    font-size: 12px;
    color: var(--slate-light);
    margin-top: 1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.content { padding: 24px 28px 60px; }

.payroll-section-heading { margin: 0 0 12px; }
.payroll-section-heading h3 { font-size: 16px; font-weight: 600; }
.payroll-summary { margin-bottom: 16px; }
.payroll-summary .table-wrap,
#payroll-detail .table-wrap { overflow-x: auto; }
.payroll-summary table { min-width: 1180px; }
.payroll-summary-total { background: #F0F9FF; font-size: 14px; font-weight: 700; }
.payroll-summary-total td { padding: 14px 12px; white-space: nowrap; }
.payroll-summary-total td.num { color: var(--primary-dk); }
.payroll-summary-total td.money-neg { color: var(--red); }
.payroll-summary-total td.payroll-net { color: var(--green); }
.payroll-summary-actions { display: flex; justify-content: flex-end; padding: 10px 20px; border-top: 1px solid var(--line); }
.payroll-empty { margin-bottom: 16px; }
#payroll-detail { scroll-margin-top: 76px; }

/* Trang con thanh toán: khoá phần trên trên desktop; mobile được cuộn trang
   để bộ lọc không ép danh sách nhân viên xuống chiều cao bằng 0. */
body.payroll-payment-page { height: 100dvh; overflow: hidden; }
body.payroll-payment-page .layout { height: 100dvh; min-height: 0; }
body.payroll-payment-page .main {
    height: 100dvh; min-height: 0; display: flex; flex-direction: column;
}
body.payroll-payment-page .topbar { flex-shrink: 0; }
body.payroll-payment-page .content {
    flex: 1; min-height: 0; display: flex; flex-direction: column;
    overflow: hidden; padding-bottom: 24px;
}
body.payroll-payment-page #payroll-detail {
    flex: 1; min-height: 0; display: flex; flex-direction: column; margin-bottom: 0;
}
body.payroll-payment-page #payroll-detail .card-head { flex-shrink: 0; }
body.payroll-payment-page #payroll-detail .table-wrap {
    flex: 1; min-height: 0; overflow: auto;
}
body.payroll-payment-page #payroll-detail thead { position: sticky; top: 0; z-index: 10; }
.payroll-detail-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

/* Tablet kiosk và trang quét: dùng chung design system, không khóa cuộn mobile. */
.modal-box.leave-history-box { max-width: 1100px; width: 96vw; }
.year-calendar { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; margin: 16px 0; }
.month-calendar { border: 1px solid var(--line); border-radius: 8px; padding: 12px; }
.month-calendar h3 { margin-bottom: 8px; }
.calendar-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 3px; }
.calendar-weekday { text-align: center; font-size: 11px; color: var(--graphite); }
.calendar-day { min-height: 38px; padding: 3px; border: 1px solid var(--line); border-radius: 4px; background: var(--off-white); color: var(--navy); cursor: pointer; font: inherit; }
.calendar-day small { display: block; font-size: 9px; }
.calendar-day.calendar-warn { background: var(--warn-bg); color: var(--warn-fg); }
.calendar-day.calendar-danger { background: var(--err-bg); color: var(--red); }
.calendar-day.selected { outline: 2px solid var(--primary); outline-offset: -2px; }
.cal-day.holiday { background: var(--err-bg); border-color: var(--red); }
.cal-day.holiday .cal-num { color: var(--red); }
.t-hol { background: var(--err-bg); color: var(--red); }
.holiday-plan { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; border-top: 1px solid var(--line); padding: 16px 0; }
.holiday-plan > div:first-child { flex: 1; min-width: 220px; }
.holiday-reminder { display: block; padding: 10px 24px; color: var(--warn-fg); background: var(--warn-bg); }
.shift-choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 8px; }
.shift-choice { display: flex; align-items: center; gap: 8px; padding: 10px; border: 1px solid var(--line); border-radius: 6px; cursor: pointer; }
.shift-choice input, [data-shift-select], #shiftSelectAll { width: 16px; height: 16px; flex: 0 0 auto; }
#historyRows { margin-top: 16px; }
.kiosk-page [hidden], .checkin-page [hidden] { display: none !important; }
.kiosk-page { min-height: 100dvh; }
.kiosk-top { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; padding: 16px 24px; background: #fff; border-bottom: 1px solid var(--line); }
.kiosk-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.kiosk-screen { display: grid; gap: 24px; padding: 24px; max-width: 1200px; margin: auto; }
.kiosk-qr-card { padding: 24px; text-align: center; }
.kiosk-qr-card h1 { font-size: 20px; }
.kiosk-qr-frame { aspect-ratio: 1; width: min(100%, 440px); margin: 16px auto; display: grid; place-items: center; background: #fff; }
.kiosk-qr-frame img { display: block; width: 100%; height: 100%; object-fit: contain; }
.kiosk-qr-frame p { padding: 24px; color: var(--red); }
.kiosk-qr-card progress { width: min(100%, 360px); height: 10px; accent-color: var(--primary); }
.kiosk-status { color: var(--green); margin-top: 12px; }
.is-error { color: var(--red); }
.is-success { color: var(--green); font-weight: 600; }
.kiosk-info { align-self: center; }
.kiosk-info h2 { font-size: 26px; }
.kiosk-info ol { padding-left: 24px; margin: 20px 0; }
.kiosk-info li { margin-bottom: 12px; }
.kiosk-clock { font-size: clamp(32px, 6vw, 64px); font-variant-numeric: tabular-nums; font-weight: 700; margin-top: 24px; }
.kiosk-help { margin-top: 16px; }
.kiosk-create { margin-top: 20px; }
#kioskForm .btn, #createKioskForm .btn { margin-top: 16px; }
#deviceStatus { margin-top: 16px; }
.checkin-content { max-width: 640px; padding: 16px; margin: auto; }
.checkin-content .card-body > * + * { margin-top: 16px; }
.checkin-confirm { justify-content: center; width: 100%; min-height: 44px; }
.checkin-gps { display: flex; gap: 8px; align-items: center; }
.scan-video { display: block; width: 100%; max-height: 50dvh; background: var(--navy); border-radius: var(--radius); }
.scan-time-row { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.checkin-links { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 16px; margin: 24px 0; }
@media (min-width: 901px) { .kiosk-screen { grid-template-columns: 1fr 1fr; align-items: center; } }

/* ============================ COMPONENTS ============================ */

.card {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
.card-head {
    padding: 16px 20px;
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}
.card-head h3 { font-size: 15px; font-weight: 700; }
.card-head p { font-size: 12.5px; color: var(--slate-light); margin-top: 2px; }
.card-body { padding: 20px; }

.btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 8px 15px;
    border: 1px solid transparent;
    border-radius: 8px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: all .15s;
    white-space: nowrap;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg { width: 15px; height: 15px; }

.btn-primary { background: var(--primary); color: var(--primary-fg); }
.btn-primary:hover:not(:disabled) { background: var(--primary-dk); }

.btn-dark { background: var(--navy); color: #fff; }
.btn-dark:hover:not(:disabled) { background: var(--graphite); }

.btn-ghost { background: #fff; color: var(--slate); border-color: var(--slate-border); }
.btn-ghost:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); background: #EFF6FF; }

.btn-ok { background: var(--green); color: #fff; }
.btn-ok:hover:not(:disabled) { background: #047857; }

.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #B91C1C; }

.btn-sm { padding: 5px 11px; font-size: 12px; }
.btn-sm svg { width: 13px; height: 13px; }

/* Badges */
.badge {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 20px;
    font-size: 11.5px;
    font-weight: 700;
    white-space: nowrap;
}
.badge-ok    { background: var(--ok-bg);   color: var(--ok-fg); }
.badge-warn  { background: var(--warn-bg); color: var(--warn-fg); }
.badge-err   { background: var(--err-bg);  color: var(--err-fg); }
.badge-info  { background: var(--info-bg); color: var(--info-fg); }
.badge-mute  { background: var(--mute-bg); color: var(--mute-fg); }
.badge-purple{ background: #EDE9FE;        color: #5B21B6; }

/* Stats */
.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 10px;
    margin-bottom: 12px;
}
.stat {
    background: var(--stat-bg, #EFF6FF);
    border: 1px solid var(--stat-border, #DBEAFE);
    border-radius: var(--radius);
    padding: 10px 14px;
    box-shadow: var(--shadow-sm);
}

/* Xen kẽ các tông pastel lạnh cho đỡ đơn điệu, vẫn đồng bộ với màu chủ đạo */
.stats > .stat:nth-child(4n+1) { --stat-bg: #EFF6FF; --stat-border: #DBEAFE; }
.stats > .stat:nth-child(4n+2) { --stat-bg: #EEF2FF; --stat-border: #E0E7FF; }
.stats > .stat:nth-child(4n+3) { --stat-bg: #ECFEFF; --stat-border: #CFFAFE; }
.stats > .stat:nth-child(4n)   { --stat-bg: #F5F3FF; --stat-border: #EDE9FE; }

/* Thẻ mang ý nghĩa trạng thái thì ưu tiên tông tương ứng */
.stats > .stat.ok,
.stat.ok     { --stat-bg: #F0FDF4; --stat-border: #DCFCE7; }
.stats > .stat.warn,
.stat.warn   { --stat-bg: #FFFBEB; --stat-border: #FEF3C7; }
.stats > .stat.danger,
.stat.danger { --stat-bg: #FEF2F2; --stat-border: #FEE2E2; }

.stat-label {
    font-size: 11.5px;
    font-weight: 600;
    color: var(--slate-light);
    text-transform: uppercase;
    letter-spacing: .4px;
    margin-bottom: 4px;
}
.stat-value {
    font-size: 22px;
    font-weight: 800;
    letter-spacing: -.8px;
    line-height: 1.1;
    color: var(--primary-dk);
}
.stat-sub { font-size: 11.5px; color: var(--slate-mid); margin-top: 4px; }
.stat.danger .stat-value { color: var(--red); }
.stat.warn   .stat-value { color: var(--orange); }
.stat.ok     .stat-value { color: var(--green); }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
    background: var(--navy);
    color: #fff;
    padding: 11px 12px;
    text-align: left;
    font-size: 11.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .3px;
    white-space: nowrap;
    position: sticky;
    top: 0;
}
thead th.num, tbody td.num { text-align: right; font-variant-numeric: tabular-nums; }
thead th.ctr, tbody td.ctr { text-align: center; }
tbody td {
    padding: 11px 12px;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
}
tbody tr:hover { background: #F8FAFC; }
tbody tr:last-child td { border-bottom: none; }

.code { font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 12px; font-weight: 600; }
.money { font-variant-numeric: tabular-nums; font-weight: 600; }
.money-neg { color: var(--red); }
.muted { color: var(--slate-light); }

/* Filter bar */
.filters {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: flex-end;
    padding: 10px 14px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    margin-bottom: 12px;
    box-shadow: var(--shadow-sm);
}
.field { display: flex; flex-direction: column; gap: 5px; }
.filters .field { gap: 3px; }
.filters input, .filters select {
    font-size: 13px;
    padding: 5px 9px;
    height: 32px;
}
.filters .btn { padding: 5px 12px; min-height: 32px; font-size: 12.5px; }
body.payroll-payment-page .content > .filters { flex-shrink: 0; }
.filters.payroll-filters { display: block; }
.payroll-filter-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.payroll-filter-head strong { font-size: 12.5px; color: var(--slate-mid); }
.filters .payroll-filter-toggle {
    width: 36px; height: 36px; padding: 0; flex-shrink: 0;
    justify-content: center; gap: 0;
}
.payroll-filter-toggle svg { width: 16px; height: 16px; display: block; }
.payroll-filter-fields { display: flex; align-items: flex-end; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.payroll-filter-fields[hidden] { display: none; }
.payroll-filter-search { flex: 1; min-width: 200px; }
.field label {
    font-size: 11.5px;
    font-weight: 600;
    color: var(--slate-mid);
    text-transform: uppercase;
    letter-spacing: .3px;
}
input, select, textarea {
    font-family: inherit;
    font-size: 13.5px;
    padding: 8px 11px;
    border: 1px solid var(--slate-border);
    border-radius: 8px;
    background: #fff;
    color: var(--navy);
    min-width: 0;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(29,78,216,.12);
}
select { cursor: pointer; }
textarea { resize: vertical; min-height: 70px; }

/* Modal */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,.55);
    backdrop-filter: blur(2px);
    z-index: 100;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.modal.open { display: flex; }
.modal-box {
    background: #fff;
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 560px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: rise .18s ease;
}
.modal-box.wide { max-width: 860px; }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
.modal-head {
    padding: 20px 24px 0;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}
.modal-head h3 { font-size: 17px; font-weight: 700; }
.modal-head p { font-size: 12.5px; color: var(--slate-light); margin-top: 3px; }
.modal-close {
    background: none; border: none; cursor: pointer;
    font-size: 22px; line-height: 1; color: var(--slate-light); padding: 2px 6px;
}
.modal-close:hover { color: var(--navy); }
.modal-body { padding: 20px 24px; }
.modal-foot {
    padding: 16px 24px;
    border-top: 1px solid var(--line);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    background: #FCFDFE;
}

.form-grid { display: grid; gap: 14px; }
.form-grid.two { grid-template-columns: 1fr 1fr; }

/* Empty / loading */
.state {
    padding: 48px 20px;
    text-align: center;
    color: var(--slate-light);
}
.state svg { width: 40px; height: 40px; margin-bottom: 10px; opacity: .4; }
.state p { font-size: 13.5px; }
.spinner {
    width: 30px; height: 30px; margin: 0 auto 12px;
    border: 3px solid var(--line);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Toast */
#toasts {
    position: fixed; top: 18px; right: 18px;
    z-index: 999; display: flex; flex-direction: column; gap: 9px;
}
.toast {
    display: flex; align-items: flex-start; gap: 10px;
    background: #fff;
    border-left: 4px solid var(--primary);
    border-radius: 9px;
    padding: 12px 16px;
    box-shadow: var(--shadow-lg);
    font-size: 13.5px;
    max-width: min(380px, calc(100vw - 32px));
    animation: slide-in .2s ease;
}
.toast.ok   { border-left-color: var(--green); }
.toast.err  { border-left-color: var(--red); }
.toast.warn { border-left-color: var(--yellow); }
@keyframes slide-in { from { opacity: 0; transform: translateX(30px); } to { opacity: 1; transform: none; } }

/* Progress bar */
.bar {
    height: 7px;
    background: var(--line);
    border-radius: 4px;
    overflow: hidden;
    min-width: 70px;
}
.bar > i { display: block; height: 100%; background: var(--primary); border-radius: 4px; transition: width .3s; }
.bar.ok   > i { background: var(--green); }
.bar.warn > i { background: var(--orange); }
.bar.err  > i { background: var(--red); }

/* Day picker (weekly off) */
.day-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 9px; }
.day-cell {
    border: 2px solid var(--line);
    border-radius: var(--radius);
    padding: 12px 8px;
    text-align: center;
    cursor: pointer;
    background: #fff;
    transition: all .15s;
    position: relative;
}
.day-cell:hover:not(.disabled) { border-color: var(--primary); transform: translateY(-2px); box-shadow: var(--shadow); }
.day-cell.selected { border-color: var(--primary); background: #EFF6FF; }
.day-cell.disabled { opacity: .45; cursor: not-allowed; background: var(--mute-bg); }
.day-cell.mine { border-color: var(--green); background: #F0FDF4; }

/* Mức tải theo ngày — cảnh báo khi nhiều người cùng chọn 1 ngày.
   Vàng = bắt đầu mỏng người, Đỏ = rủi ro thiếu người trực, Xám = đã kín. */
.day-cell.warn {
    border-color: #FCD34D;
    background: #FFFBEB;
}
.day-cell.danger {
    border-color: #FCA5A5;
    background: #FEF2F2;
}
.day-cell.danger .day-num { color: var(--red); }
.day-cell.full {
    border-color: var(--slate-border);
    background: var(--mute-bg);
}
.day-cell.mine.warn   { border-color: var(--green); background: #F0FDF4; }
.day-cell.mine.danger { border-color: var(--green); background: #F0FDF4; }

/* Nhãn mức tải góc trên-trái */
.day-level {
    position: absolute; top: 5px; left: 5px;
    width: 7px; height: 7px; border-radius: 50%;
}
.day-level.warn   { background: #F59E0B; }
.day-level.danger { background: var(--red); }
.day-level.full   { background: var(--slate-light); }

.day-dow { font-size: 11px; font-weight: 700; color: var(--slate-light); text-transform: uppercase; }
.day-num { font-size: 21px; font-weight: 800; line-height: 1.2; margin: 2px 0; }
.day-slot { font-size: 11px; color: var(--slate-light); font-variant-numeric: tabular-nums; }
.day-cell.warn .day-slot   { color: #B45309; font-weight: 700; }
.day-cell.danger .day-slot { color: var(--red); font-weight: 700; }
.day-cell.full .day-slot { color: var(--red); font-weight: 700; }

/* Danh sách người đã đăng ký trước — hiện khi rê chuột */
.day-tip {
    visibility: hidden; opacity: 0;
    position: absolute; z-index: 60;
    bottom: calc(100% + 8px); left: 50%;
    transform: translateX(-50%);
    min-width: 230px; max-width: 300px;
    background: var(--navy); color: #fff;
    border-radius: 9px; padding: 10px 12px;
    box-shadow: var(--shadow-lg);
    font-size: 11.5px; font-weight: 500;
    text-align: left; pointer-events: none;
    transition: opacity .15s, visibility .15s;
}
.day-cell:hover .day-tip { visibility: visible; opacity: 1; }
.day-tip::after {
    content: ''; position: absolute; top: 100%; left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent; border-top-color: var(--navy);
}
.day-tip-head {
    font-size: 10px; font-weight: 700; text-transform: uppercase;
    letter-spacing: .5px; color: var(--sky); margin-bottom: 6px;
    padding-bottom: 5px; border-bottom: 1px solid rgba(255,255,255,.15);
}
.day-tip-row { display: flex; justify-content: space-between; gap: 10px; padding: 2px 0; }
.day-tip-row .o {
    color: var(--sky); font-weight: 700; min-width: 16px;
}
.day-tip-row .t { color: rgba(255,255,255,.55); font-size: 10.5px; white-space: nowrap; }
.day-tip-more { color: rgba(255,255,255,.5); font-style: italic; margin-top: 4px; font-size: 10.5px; }

.day-tag {
    position: absolute; top: 5px; right: 5px;
    font-size: 9.5px; font-weight: 700; padding: 1px 5px; border-radius: 6px;
    background: var(--green); color: #fff;
}

/* Bảng cảnh báo trên đầu trang */
.alert-strip {
    display: flex; flex-wrap: wrap; gap: 10px;
    margin-bottom: 16px;
}
.alert-chip {
    display: flex; align-items: center; gap: 8px;
    padding: 9px 13px; border-radius: var(--radius);
    font-size: 12.5px; font-weight: 600;
    border: 1px solid;
}
.alert-chip.warn   { background: var(--warn-bg); color: var(--warn-fg); border-color: #FDE68A; }
.alert-chip.danger { background: var(--err-bg);  color: var(--err-fg);  border-color: #FECACA; }
.alert-chip .n { font-size: 15px; font-weight: 800; }

/* ============================ MONTH CALENDAR ============================ */
/* Lịch tháng: phân biệt ngày làm / ngày OFF / ngày lễ */

.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }

.cal-head {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .4px;
    color: var(--slate-light);
    text-align: center;
    padding: 6px 0;
}

.cal-day {
    border: 1px solid var(--line);
    border-radius: 9px;
    padding: 8px;
    background: #fff;
    min-height: 92px;
    font-size: 11.5px;
    position: relative;
    transition: box-shadow .15s, transform .15s;
}
.cal-day:hover:not(.empty) { box-shadow: var(--shadow); }

/* Ngày trong tuần làm việc bình thường */
.cal-day.work { background: #fff; }

/* Ngày nghỉ hàng tuần (OFF) — nền xám */
.cal-day.off { background: var(--mute-bg); }
.cal-day.off .cal-num { color: var(--slate-light); }

/* Ngày lễ, Tết — nền đỏ, ký hiệu AL */
.cal-day.holiday { background: var(--err-bg); border-color: var(--red); }
.cal-day.holiday .cal-num { color: var(--red); }

/* Ô trống đầu/cuối tháng */
.cal-day.empty { background: transparent; border: none; }

/* Ngày hôm nay */
.cal-day.today { border: 2px solid var(--primary); }
.cal-day.today .cal-num { color: var(--primary); }

.cal-num { font-weight: 800; font-size: 14px; }
.cal-type { font-size: 9.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .3px; }
.cal-hours { margin-top: 6px; font-variant-numeric: tabular-nums; }
.cal-hours div { display: flex; justify-content: space-between; }

.cal-badge {
    position: absolute;
    top: 6px;
    right: 6px;
    font-size: 9px;
    font-weight: 700;
    padding: 1px 5px;
    border-radius: 6px;
}

/* Nhãn loại ngày */
.t-work { background: var(--info-bg);  color: var(--info-fg); }
.t-off  { background: var(--mute-bg);  color: var(--mute-fg); }
.t-hol  { background: var(--err-bg); color: var(--red); }

/* Chú giải màu bên dưới lịch */
.cal-legend {
    display: flex;
    gap: 18px;
    flex-wrap: wrap;
    align-items: center;
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--line);
    font-size: 12.5px;
    color: var(--slate-mid);
}
.cal-legend span { display: inline-flex; align-items: center; gap: 7px; }
.cal-legend i {
    width: 13px; height: 13px;
    border-radius: 4px;
    border: 1px solid var(--slate-border);
    flex-shrink: 0;
}
.cal-legend i.lg-work { background: #fff; }
.cal-legend i.lg-off  { background: var(--mute-bg); }
.cal-legend i.lg-hol  { background: var(--warn-bg); border-color: #FCD34D; }

/* Hamburger menu button */
.menu-btn {
    display: none;
    position: fixed;
    top: 12px;
    left: 16px;
    z-index: 110;
    width: 40px;
    height: 40px;
    background: var(--navy);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    padding: 0;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-lg);
}
.menu-btn svg {
    width: 22px;
    height: 22px;
    stroke: #fff;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* Overlay khi mở sidebar trên mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.6);
    z-index: 90;
    backdrop-filter: blur(2px);
}

@media (max-width: 900px) {
    .sidebar {
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-overlay.show { display: block; }
    .menu-btn { display: flex; }
    .main { margin-left: 0; }
    .topbar { padding-left: 72px; }
    .content { padding-left: 16px; padding-right: 16px; }
    .form-grid.two { grid-template-columns: 1fr; }
    .day-grid { grid-template-columns: repeat(4, 1fr); }
    .cal { grid-template-columns: repeat(3, 1fr); }
    .cal-head { display: none; }

    /* Toast không tràn màn hình hẹp */
    #toasts { top: 12px; left: 12px; right: 12px; }
    .toast { max-width: none; }

    /* Modal: to hơn, cho phép cuộn, footer luôn bấm được */
    .modal { padding: 0; align-items: flex-end; }
    .modal-box,
    .modal-box.wide {
        max-width: 100%;
        max-height: 92vh;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    }
    .modal-head { padding: 18px 18px 0; }
    .modal-body { padding: 16px 18px; }
    .modal-foot {
        padding: 14px 18px;
        position: sticky;
        bottom: 0;
    }
    .modal-foot .btn { flex: 1; justify-content: center; }

    /* Bảng: cuộn ngang, giảm đệm cho vừa màn hình */
    thead th, tbody td { padding: 10px 10px; }
    .table-wrap { -webkit-overflow-scrolling: touch; }

    /* Vùng chạm tối thiểu 40px cho nút bấm trên điện thoại */
    .btn-sm { padding: 7px 12px; }
    .nav-link { padding: 11px 12px; }

    /* Thống kê xếp gọn hơn */
    .stats { gap: 10px; }
    .stat { padding: 10px 12px; }
    .stat-value { font-size: 22px; }

    /* Lọc: xếp các ô thành hàng gọn, tự xuống dòng khi thiếu chỗ */
    .filters { padding: 10px 12px; gap: 8px; }
    .filters .field { flex: 1 1 140px; }

    .payroll-filter-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .payroll-filter-fields .field { min-width: 0; }
    .payroll-filter-fields input, .payroll-filter-fields select { width: 100%; min-width: 0; }
    .payroll-filter-search { grid-column: 1 / -1; }
    .filters .payroll-filter-toggle { width: 40px; height: 40px; min-height: 40px; }

    body.payroll-payment-page { height: auto; overflow: auto; }
    body.payroll-payment-page .layout { height: auto; min-height: 100dvh; }
    body.payroll-payment-page .main { height: auto; display: block; }
    body.payroll-payment-page .content { display: block; overflow: visible; }
    body.payroll-payment-page #payroll-detail { flex: none; }
    body.payroll-payment-page #payroll-detail .table-wrap {
        flex: none; max-height: 65dvh; overflow: auto;
    }
}

/* Màn hình rất hẹp (điện thoại nhỏ) */
@media (max-width: 480px) {
    .content { padding: 16px 12px 48px; }
    .day-grid { grid-template-columns: repeat(3, 1fr); }
    .cal { grid-template-columns: repeat(2, 1fr); }
    .stat-value { font-size: 20px; }
    .brand h1 { font-size: 19px; }
}

/* ==========================================================================
   Trang danh sách — khoá phần trên, CHỈ cuộn bảng bên dưới
   Bật bằng cách thêm class "freeze" vào <body> và "table-card" vào card
   chứa bảng chính. Chỉ áp dụng từ 901px trở lên: trên điện thoại, bộ lọc
   xếp dọc chiếm gần hết màn hình nên khoá lại sẽ chẳng còn chỗ cho bảng.
   ========================================================================== */
@media (min-width: 901px) {
    body.freeze { height: 100vh; overflow: hidden; }

    body.freeze .layout { height: 100vh; min-height: 0; }

    body.freeze .main {
        height: 100vh;
        min-height: 0;
        display: flex;
        flex-direction: column;
    }

    body.freeze .topbar { flex-shrink: 0; }

    body.freeze .content {
        flex: 1;
        min-height: 0;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        padding-bottom: 24px;
    }

    body.freeze .content {
        flex: 1;
        min-height: 0;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        padding-bottom: 24px;
    }

    /* Thống kê, bộ lọc, thanh tiêu đề card: giữ nguyên chiều cao */
    body.freeze .content > .stats,
    body.freeze .content > .filters,
    body.freeze .content > .card.no-grow,
    body.freeze .table-card > .card-head { flex-shrink: 0; }

    /* Card chứa bảng chính: giãn hết phần còn lại */
    body.freeze .content > .table-card {
        flex: 1;
        min-height: 0;
        margin-bottom: 0;
        display: flex;
        flex-direction: column;
    }

    /* Chỉ ruột bảng cuộn. thead đã position:sticky nên tiêu đề cột dính lại. */
    body.freeze .table-card > .table-wrap {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
        overflow-x: auto;
    }

    /* Sticky table header */
    body.freeze .table-card thead {
        position: sticky;
        top: 0;
        z-index: 10;
    }

    body.freeze .table-card thead th {
        box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    }

    /* Card đứng trước bảng (vd bảng tổng hợp ở trang Bảng lương) không giãn */
    body.freeze .content > .card:not(.table-card) {
        flex-shrink: 0;
        margin-bottom: 16px;
    }
}

/* Thành phần bảng thanh toán tiền lương */

    /* Cột thành phần lương */
    .comp { font-size: 12.5px; }
    .comp-row { display: flex; justify-content: space-between; gap: 14px; padding: 4px 0; }
    .comp-row + .comp-row { border-top: 1px dashed var(--line); }
    .comp-row span:first-child { color: var(--slate-light); }
    .comp-row span:last-child { font-variant-numeric: tabular-nums; font-weight: 600; }
    .comp-sec { margin-bottom: 16px; }
    .comp-sec h4 {
        font-size: 11.5px; font-weight: 700; text-transform: uppercase;
        letter-spacing: .5px; color: var(--slate-mid); margin-bottom: 6px;
    }
    .comp-total {
        display: flex; justify-content: space-between;
        padding: 10px 12px; border-radius: 8px; font-weight: 700; margin-top: 6px;
    }
    .t-green { background: var(--ok-bg); color: var(--ok-fg); }
    .t-red   { background: var(--err-bg); color: var(--err-fg); }
    .t-blue  { background: var(--info-bg); color: var(--info-fg); }
    .t-navy  { background: var(--navy); color: #fff; }
    .t-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px,1fr)); gap: 18px; }
    .expand-row td { background: #F8FAFC !important; padding: 0 !important; }
    .expand-inner { padding: 20px 24px; border-left: 3px solid var(--sky); }

    /* Tooltip cho cột gom nhóm */
    .has-tip { position: relative; cursor: help; }
    .has-tip > .tip-value {
        border-bottom: 1px dotted var(--slate-border);
    }
    .has-tip:hover > .tip-value { border-bottom-color: var(--sky-dk); }
    .tip {
        visibility: hidden; opacity: 0;
        position: absolute; z-index: 50;
        bottom: calc(100% + 8px); right: 0;
        min-width: 250px;
        background: var(--navy); color: #fff;
        border-radius: 9px; padding: 11px 14px;
        box-shadow: var(--shadow-lg);
        font-size: 12px; font-weight: 500;
        text-align: left;
        transition: opacity .15s, visibility .15s;
        pointer-events: none;
    }
    .has-tip:hover > .tip { visibility: visible; opacity: 1; }
    .tip::after {
        content: ''; position: absolute; top: 100%; right: 18px;
        border: 6px solid transparent; border-top-color: var(--navy);
    }
    .tip-head {
        font-size: 10.5px; font-weight: 700; text-transform: uppercase;
        letter-spacing: .5px; color: var(--sky); margin-bottom: 7px;
        padding-bottom: 6px; border-bottom: 1px solid rgba(255,255,255,.15);
    }
    .tip-row { display: flex; justify-content: space-between; gap: 16px; padding: 3px 0; }
    .tip-row span:first-child { color: rgba(255,255,255,.72); }
    .tip-row span:last-child { font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
    .tip-sum {
        display: flex; justify-content: space-between; gap: 16px;
        margin-top: 7px; padding-top: 7px;
        border-top: 1px solid rgba(255,255,255,.15); font-weight: 800;
    }
    .tip-sum span:last-child { color: var(--sky); }
    .tip-empty { color: rgba(255,255,255,.5); font-style: italic; }

/* Trang Rubric cuộn tự do khi mở mô tả tiêu chí dài. */
.review-criteria-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 10px;
    align-items: start;
}
.review-page:not(.review-detail-page) { overflow-y: auto; }
#scoreModal .modal-box { display: flex; flex-direction: column; overflow: hidden; }
#scoreModal .modal-head, #scoreModal .modal-foot { flex-shrink: 0; }
#scoreModal .modal-body { min-height: 0; overflow-y: auto; }
.score-guide-trigger {
    display: flex; align-items: center; gap: 8px; width: 100%;
    border: 0; padding: 0; background: transparent; color: var(--navy);
    font-family: inherit; font-size: 13.5px; text-align: left; cursor: help;
}
.score-guide-trigger strong { flex: 1; }
.score-guide-hint { color: var(--primary); }
.score-guide-panel {
    display: none; margin-top: 10px; padding: 12px; border: 1px solid var(--line);
    border-radius: var(--radius); background: var(--off-white);
    max-height: min(280px, 38vh); overflow-y: auto;
}
.score-guide:hover .score-guide-panel,
.score-guide:focus-within .score-guide-panel,
.score-guide.is-open .score-guide-panel { display: block; }
.score-guide-title { font-size: 12.5px; font-weight: 600; margin-bottom: 8px; }
.score-guide-panel .lvl-row + .lvl-row { margin-top: 8px; }
.score-input { width: 100%; }
.score-input[aria-invalid="true"] { border-color: var(--red); }
.score-input-hint { display: block; font-size: 11.5px; color: var(--slate-mid); margin: 4px 0 8px; }

/* Rubric và form đánh giá năng lực */
/* Thẻ tiêu chí Rubric — bấm để xem mô tả 5 mức điểm */
    .crit-card {
        background: var(--off-white);
        border: 1px solid var(--line);
        border-radius: 8px;
        padding: 10px 12px;
        font-size: 13px;
    }
    .crit-card[open] { border-color: var(--primary); background: #fff; }
    .crit-card summary {
        cursor: pointer; list-style: none;
        display: flex; align-items: center; gap: 8px;
    }
    .crit-card summary::-webkit-details-marker { display: none; }
    .crit-card summary::before {
        content: '▸'; color: var(--slate-light); font-size: 11px;
        transition: transform .15s;
    }
    .crit-card[open] summary::before { transform: rotate(90deg); }
    .crit-card summary strong { flex: 1; }
    .crit-levels { margin-top: 10px; display: flex; flex-direction: column; gap: 7px; }
    .lvl-row { display: flex; gap: 9px; align-items: flex-start; font-size: 12.5px; }
    .lvl-score {
        flex-shrink: 0; width: 22px; height: 22px; border-radius: 6px;
        display: grid; place-items: center; font-weight: 700; font-size: 11.5px;
    }
    .lvl-row.s5 .lvl-score { background: #DCFCE7; color: #166534; }
    .lvl-row.s4 .lvl-score { background: #DBEAFE; color: #1E40AF; }
    .lvl-row.s3 .lvl-score { background: #E0E7FF; color: #3730A3; }
    .lvl-row.s2 .lvl-score { background: #FEF3C7; color: #92400E; }
    .lvl-row.s1 .lvl-score { background: #FEE2E2; color: #991B1B; }
    .lvl-text { color: var(--slate-mid); line-height: 1.45; }

    /* Chấm điểm */
    .score-row { padding: 14px 0; border-bottom: 1px solid var(--line); }
    .score-row:last-child { border-bottom: none; }
    .crit { font-size: 13.5px; }
    .crit small { display: block; color: var(--slate-light); font-size: 11.5px; margin-top: 1px; }
    .picks { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 10px; }
    .pick-label {
        display: block; font-size: 11px; font-weight: 700; text-transform: uppercase;
        letter-spacing: .3px; color: var(--slate-light); margin-bottom: 5px;
    }
    .lvls { display: flex; gap: 5px; }
    .lvl-btn {
        flex: 1; padding: 6px 0; border: 1px solid var(--slate-border); background: #fff;
        border-radius: 6px; font-family: inherit; font-size: 12.5px; font-weight: 700;
        color: var(--slate-mid); cursor: pointer; transition: all .12s;
    }
    .lvl-btn:hover { border-color: var(--primary); color: var(--primary); }
    .lvl-btn.on { background: var(--primary); border-color: var(--primary); color: #fff; }
    .lvl-desc {
        margin-top: 7px; font-size: 12px; color: var(--slate-mid); line-height: 1.45;
        background: var(--off-white); border-radius: 6px; padding: 8px 10px;
        min-height: 38px;
    }
    .lvl-desc:empty { display: none; }
    .grade-box { padding: 16px; border-radius: 10px; text-align: center; }

    /* Trên điện thoại, QL và PQL xếp dọc để mô tả không bị bóp hẹp */
    @media (max-width: 900px) {
        .picks { grid-template-columns: 1fr; gap: 12px; }
        .lvl-btn { padding: 9px 0; font-size: 13.5px; }
        .crit-levels { gap: 9px; }
    }

/* Tách rõ hai cặp ca trong phần giới thiệu đăng ký. */
.shift-pair-line + .shift-pair-line { margin-top: 6px; }

/* Phản hồi đổi mật khẩu tại trang đăng nhập. */
.password-result { margin-top: 12px; font-size: 13px; }
.password-result.error { color: var(--red); }
.password-result.success { color: var(--green); }
#changeModal .modal-box { max-height: 90dvh; overflow-y: auto; }
