/* ============================================================
   Hệ thống Chấm công - UI/UX Pro Max (Minimalism & Swiss Style)
   Palette: trust blue + orange CTA | Type: Outfit + Work Sans
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700;800&family=Work+Sans:wght@300;400;500;600;700&display=swap');

/* ===== Design Tokens (Swiss) ===== */
/* attribute hidden luôn thắng (tránh CSS display override) */
[hidden] { display: none !important; }

:root {
    /* Color */
    --primary:        #2563EB;
    --primary-dark:   #1E40AF;
    --on-primary:     #FFFFFF;
    --secondary:      #3B82F6;
    --accent:         #EA580C;   /* checkout / CTA focus */
    --accent-dark:    #C2410C;
    --background:     #F8FAFC;
    --foreground:     #1E293B;
    --card:           #FFFFFF;
    --card-fg:        #1E293B;
    --muted:          #E9EFF8;
    --muted-fg:       #5A6577;
    --border:         #E2E8F0;
    --destructive:    #DC2626;
    --on-destructive: #FFFFFF;
    --success:        #16A34A;
    --success-dark:   #15803D;
    --on-success:     #FFFFFF;
    --ring:           #2563EB;

    /* Sidebar navy + topbar (14/09) */
    --sidebar:        #0F172A;
    --sidebar-head:   #0B1220;   /* đậm hơn cho khối logo */
    --sidebar-fg:     #E2E8F0;
    --sidebar-muted:  #94A3B8;
    --sidebar-hover:  rgba(255,255,255,.06);
    --sidebar-active: #2563EB;
    --topbar-h:       60px;
    --sidebar-w:      248px;

    /* var từng thiếu (dùng ở .ai-body / .sb-hamburger) — trước đây fallback rỗng */
    --paper:          #FFFFFF;
    --shadow-md:      0 4px 12px rgba(15,23,42,.08);

    /* Type */
    --font-head: 'Outfit', 'Segoe UI', system-ui, sans-serif;
    --font-body: 'Work Sans', 'Segoe UI', system-ui, sans-serif;

    /* Spacing (spacious) */
    --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px;
    --sp-5: 24px; --sp-6: 32px; --sp-7: 48px; --sp-8: 64px;

    /* Shape / depth */
    --radius: 8px;
    --radius-lg: 14px;
    --shadow-sm: 0 1px 2px rgba(15,23,42,.05);
    --shadow: 0 1px 3px rgba(15,23,42,.06), 0 4px 12px rgba(15,23,42,.04);
    --shadow-lg: 0 12px 24px rgba(15,23,42,.10);

    /* Motion (subtle) */
    --dur: 200ms;
    --ease: ease-out;

    /* Touch */
    --touch-min: 48px;
}

/* ===== Dark mode — đổi token, ko đụng layout ===== */
:root[data-theme="dark"] {
    --primary:        #3B82F6;
    --primary-dark:   #60A5FA;
    --secondary:      #60A5FA;
    --on-primary:     #0F172A;
    --accent:         #F97316;
    --accent-dark:    #FB923C;
    --background:     #0B1220;
    --foreground:     #E6EBF2;
    --card:           #111A2E;
    --card-fg:        #E6EBF2;
    --muted:          #1B2740;
    --muted-fg:       #94A3B8;
    --border:         #223049;
    --destructive:    #F87171;
    --on-destructive: #0B1220;
    --success:        #4ADE80;
    --success-dark:   #86EFAC;
    --on-success:     #0B1220;
    --ring:           #60A5FA;
    --paper:          #111A2E;
    --shadow-sm:      0 1px 2px rgba(0,0,0,.4);
    --shadow:         0 1px 3px rgba(0,0,0,.4), 0 4px 12px rgba(0,0,0,.3);
    --shadow-lg:      0 12px 24px rgba(0,0,0,.5);
    --shadow-md:      0 4px 12px rgba(0,0,0,.4);

    /* sidebar giữ navy; nền page đã tối */
    --sidebar:        #0B1424;
    --sidebar-head:   #08101E;
    --sidebar-fg:     #E6EBF2;
    --sidebar-muted:  #7C8BAD;
    --sidebar-hover:  rgba(255,255,255,.08);
}

/* tránh viền trắng quanh ảnh logo khi nền tối */
:root[data-theme="dark"] .nav-logo,
:root[data-theme="dark"] .login-logo { filter: brightness(.9); }

/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
    font-family: var(--font-body);
    background: var(--background);
    color: var(--foreground);
    line-height: 1.6;
    min-height: 100vh;
    font-size: 15px;
}

h1, h2, h3, h4, .nav-brand, .current-time { font-family: var(--font-head); letter-spacing: -.01em; }

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== Login Page ===== */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 16px;
    /* Geometric gradient -- Swiss but softer than before */
    background:
        radial-gradient(1200px 600px at 110% -10%, rgba(37,99,235,.08), transparent 60%),
        radial-gradient(900px 500px at -20% 110%, rgba(234,88,12,.06), transparent 55%),
        var(--background);
}

.login-container { width: 100%; max-width: 400px; }

.login-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: var(--sp-7) var(--sp-6);
}

.login-header { text-align: center; margin-bottom: var(--sp-6); }

.login-logo {
    width: 220px; max-width: 80%;
    height: auto;
    margin: 0 auto var(--sp-4);
    display: block;
}

.login-header h1 { font-size: 24px; font-weight: 700; color: var(--foreground); margin-bottom: 4px; }
.login-header p { color: var(--muted-fg); font-size: 14px; }
.login-brand {
    font-family: var(--font-head); font-weight: 700; font-size: 15px;
    color: var(--primary) !important; letter-spacing: -.01em; margin-bottom: 2px;
}

.login-form .form-group { margin-bottom: var(--sp-4); }

.login-form label {
    display: block; font-size: 13px; font-weight: 600;
    margin-bottom: 6px; color: var(--foreground);
}

.login-form input {
    width: 100%;
    min-height: var(--touch-min);
    padding: 4px 14px;
    font-size: 15px;
    font-family: var(--font-body);
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}

.login-form input:focus {
    outline: none;
    border-color: var(--ring);
    box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

.login-footer { margin-top: var(--sp-5); text-align: center; font-size: 12px; color: var(--muted-fg); }

.login-footer code {
    background: var(--muted); color: var(--foreground);
    padding: 2px 6px; border-radius: 5px; font-size: 11px;
}

/* ===== Navbar ===== */
/* body có sidebar → dịch nội dung sang phải (desktop), bỏ trên mobile */
body.has-sidebar {
    padding-left: var(--sidebar-w);
}
@media (max-width: 768px) {
    body.has-sidebar { padding-left: 0; }
}

.nav-brand {
    font-family: var(--font-head); font-weight: 700;
    display: flex; align-items: center; gap: 10px;
    text-decoration: none; line-height: 1.2;
}
.nav-brand:hover { text-decoration: none; }
.nav-brand .nav-logo { height: 34px; width: auto; display: block; flex: 0 0 auto; }
.nav-brand-txt { display: flex; flex-direction: column; min-width: 0; }
.nav-brand-txt strong {
    font-size: 14.5px; font-weight: 700; color: #FFFFFF;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.nav-brand-txt small {
    font-size: 11px; font-weight: 500; letter-spacing: .04em;
    text-transform: uppercase; color: var(--sidebar-muted);
}

.nav-badge {
    background: var(--destructive); color: #fff; border-radius: 999px;
    padding: 0 7px; font-size: 11px; font-weight: 700; min-width: 18px; text-align: center;
}
.nav-name { font-size: 13.5px; color: var(--muted-fg); }
.nav-dept { font-size: 12px; color: var(--primary); font-weight: 600; }

/* ===== SIDEBAR TRÁI — navy (kiểu 5F template) ===== */
.app-sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: var(--sidebar-w); z-index: 300;
    background: var(--sidebar); border-right: 1px solid rgba(255,255,255,.06);
    display: flex; flex-direction: column;
    transition: transform var(--dur) var(--ease);
}
.sb-head {
    padding: 14px 16px; min-height: var(--topbar-h);
    display: flex; align-items: center; justify-content: center;
    background: var(--sidebar-head);
    border-bottom: 1px solid rgba(255,255,255,.06);
}
.sb-head .nav-brand { justify-content: center; }
.sb-head .nav-logo { height: 38px; }
.sb-nav { flex: 1; overflow-y: auto; padding: 10px 10px 16px; }
.sb-nav-label {
    font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
    color: var(--sidebar-muted); opacity: .8; padding: 10px 10px 4px;
}
.sb-link {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 10px; margin: 2px 0; border-radius: var(--radius);
    font-size: 14px; font-weight: 600; color: var(--sidebar-muted);
    transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.sb-link:hover { background: var(--sidebar-hover); text-decoration: none; color: #fff; }
.sb-link.active { background: var(--sidebar-active); color: #fff; }

.sb-group { margin: 2px 0; }
.sb-group-btn {
    width: 100%; display: flex; align-items: center; gap: 10px;
    padding: 9px 10px; border-radius: var(--radius);
    font: inherit; font-size: 14px; font-weight: 600; color: var(--sidebar-muted);
    background: none; border: none; cursor: pointer; text-align: left;
    transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.sb-group-btn:hover { background: var(--sidebar-hover); color: #fff; }
.sb-group-btn .sb-label { flex: 1; }
.sb-group-btn .nav-badge { margin-left: auto; }
/* caret: vẽ bằng border (ASCII) — tránh 'â-¾' */
.sb-caret {
    display: inline-block; width: 0; height: 0; margin-left: 6px;
    border-left: 4px solid transparent; border-right: 4px solid transparent;
    border-top: 5px solid currentColor; opacity: .6;
    transition: transform var(--dur) var(--ease);
}
.sb-group.open > .sb-group-btn .sb-caret { transform: rotate(180deg); }

.sb-submenu {
    max-height: 0; overflow: hidden;
    transition: max-height var(--dur) var(--ease);
}
.sb-group.open > .sb-submenu {
    max-height: 620px;
    padding-left: 4px;
}
.sb-sublink {
    display: flex; align-items: center; gap: 9px;
    padding: 7px 10px; margin: 1px 0; border-radius: var(--radius);
    font-size: 13.5px; font-weight: 500; color: var(--sidebar-muted);
    border-left: 3px solid transparent;
    transition: background var(--dur) var(--ease), color var(--dur) var(--ease),
                border-color var(--dur) var(--ease);
}
.sb-sublink:hover { background: var(--sidebar-hover); text-decoration: none; color: #fff; }
.sb-sublink.active {
    background: rgba(37,99,235,.18); color: #fff; font-weight: 600;
    border-left-color: var(--sidebar-active);
}
.sb-sublink .nav-badge { margin-left: auto; }
.sb-sublink .ic, .sb-group-btn .ic { width: 16px; height: 16px; flex: 0 0 16px; opacity: .9; }
.sb-sublink.active .ic, .sb-group-btn:hover .ic { opacity: 1; }

/* hamburger + overlay (mobile) */
.sb-hamburger {
    display: none;
    position: fixed; top: 10px; left: 12px; z-index: 350;
    width: 40px; height: 40px; border-radius: var(--radius);
    background: var(--card); border: 1px solid var(--border);
    font-size: 20px; line-height: 1; cursor: pointer;
    box-shadow: var(--shadow-md);
}
.sb-overlay {
    display: none;
    position: fixed; inset: 0; z-index: 290; background: rgba(0,0,0,.45);
}
@media (max-width: 768px) {
    .app-sidebar { transform: translateX(-100%); }
    .app-sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
    .sb-hamburger { display: block; }
    .sb-overlay.show { display: block; }
}

/* ===== TOPBAR (sticky trên vùng nội dung) ===== */
.topbar {
    position: fixed; top: 0; left: var(--sidebar-w); right: 0; z-index: 250;
    height: var(--topbar-h);
    display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4);
    padding: 0 var(--sp-5);
    background: var(--card);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}
.tb-left { min-width: 0; display: flex; flex-direction: column; justify-content: center; }
.tb-right { display: flex; align-items: center; gap: var(--sp-3); flex: 0 0 auto; }

.tb-crumb {
    display: flex; align-items: center; gap: 6px;
    font-size: 11.5px; color: var(--muted-fg); line-height: 1.2;
}
.tb-crumb .tb-sep::before { content: '/'; opacity: .5; }
.tb-title {
    font-family: var(--font-head); font-size: 17px; font-weight: 700;
    color: var(--foreground); line-height: 1.25; margin: 0;
    display: flex; align-items: center; gap: 8px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tb-user {
    display: inline-flex; align-items: center; gap: 7px;
    font-size: 13.5px; color: var(--muted-fg); white-space: nowrap;
}
.tb-user .ic { width: 16px; height: 16px; opacity: .7; }
.tb-icon-btn {
    width: 38px; height: 38px; border-radius: var(--radius);
    border: 1px solid var(--border); background: var(--card); color: var(--foreground);
    display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
    transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.tb-icon-btn:hover { background: var(--muted); }
.tb-icon-btn .ic { width: 19px; height: 19px; }

@media (max-width: 768px) {
    .topbar { left: 0; padding-left: 62px; }
    .tb-crumb { display: none; }
    .tb-title { font-size: 16px; }
    .tb-user .nav-name { display: none; }
}

/* ===== Icon SVG dùng chung (icons.js) ===== */
/* 1em → tự ăn theo font-size của ngữ cảnh (nav 13px, h2 22px, badge 12px) */
.ic {
    width: 1em; height: 1em; flex: 0 0 auto;
    display: inline-block; vertical-align: -0.135em;
    stroke-width: 2;
}


/* ===== Container & Cards ===== */
.container {
    max-width: 1180px; margin: 0 auto;
    padding: calc(var(--topbar-h) + var(--sp-5)) var(--sp-5) var(--sp-7);
}

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: var(--sp-6);
    margin-bottom: var(--sp-5);
}

/* Tiêu đề trang trong card — tầng bậc rõ với nội dung bên dưới */
.card h2 {
    font-size: 19px; font-weight: 700; color: var(--card-fg); margin-bottom: var(--sp-4);
    display: flex; align-items: center; gap: 9px;
}
.card h2 .ic { width: 20px; height: 20px; color: var(--primary); }

/* ===== Buttons (Swiss: flat, sharp shadow, strong hover) ===== */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 44px;
    padding: 4px 18px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    font-size: 14px; font-weight: 600;
    font-family: var(--font-head);
    cursor: pointer;
    transition: all var(--dur) var(--ease);
    text-decoration: none;
    user-select: none;
}

.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.btn:focus-visible { outline: 3px solid var(--ring); outline-offset: 2px; }

.btn-primary { background: var(--primary); color: var(--on-primary); box-shadow: 0 4px 12px rgba(37,99,235,.22); }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }

.btn-success { background: var(--success); color: var(--on-success); box-shadow: 0 4px 12px rgba(22,163,74,.22); }
.btn-success:hover:not(:disabled) { background: var(--success-dark); }

.btn-danger { background: var(--accent); color: #fff; box-shadow: 0 4px 12px rgba(234,88,12,.22); }
.btn-danger:hover:not(:disabled) { background: var(--accent-dark); }

.btn-outline { background: var(--card); border-color: var(--border); color: var(--foreground); }
.btn-outline:hover:not(:disabled) { background: var(--muted); border-color: var(--muted-fg); }

.btn-block { width: 100%; }
.btn-large { min-height: var(--touch-min); padding: 6px 32px; font-size: 16px; }
.btn-large .ic { width: 19px; height: 19px; }
.btn-sm { min-height: 38px; padding: 2px 12px; font-size: 13px; }
.btn-sm .ic { width: 15px; height: 15px; }
/* nút trong bảng (sửa/xoá) — gọn, icon canh giữa */
.data-table .btn { padding: 2px 10px; min-height: 34px; }
.data-table .btn .ic { margin-right: 4px; vertical-align: -0.18em; }

/* ===== Dashboard ===== */
.dashboard-grid { display: grid; grid-template-columns: 1fr; gap: var(--sp-5); }

@media (min-width: 640px) { .dashboard-grid { grid-template-columns: 1fr 1fr; } }

.checkin-panel { text-align: center; display: flex; flex-direction: column; }

.current-time {
    font-size: 52px; font-weight: 700; color: var(--foreground);
    font-variant-numeric: tabular-nums;
    margin: var(--sp-4) 0 2px;
    line-height: 1.05;
}

.date-display { font-size: 15px; color: var(--muted-fg); margin-bottom: var(--sp-5); }

/* ===== IP Status chip ===== */
.ip-status {
    min-height: 44px;
    padding: 8px 16px;
    border-radius: var(--radius);
    font-size: 14px; font-weight: 500;
    margin-bottom: var(--sp-5);
    display: flex; align-items: center; justify-content: center; gap: 8px;
    border: 1px solid transparent;
}

.ip-status.loading { background: var(--muted); color: var(--muted-fg); }
.ip-status.allowed  { background: #ECFDF5; color: #065F46; border-color: #A7F3D0; }
.ip-status.denied   { background: #FEF2F2; color: #991B1B; border-color: #FECACA; }
.ip-status .ic { width: 16px; height: 16px; }

/* ===== Checkin actions ===== */
.checkin-actions { display: flex; flex-direction: column; gap: var(--sp-3); }

.check-result {
    margin-top: var(--sp-4);
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 14px; font-weight: 500;
    display: flex; align-items: center; gap: 7px;
}
.check-result:empty { display: none; }
.check-result .ic { width: 16px; height: 16px; flex: 0 0 16px; }

.check-result.success { background: #ECFDF5; color: #065F46; border: 1px solid #A7F3D0; }
.check-result.error   { background: #FEF2F2; color: #991B1B; border: 1px solid #FECACA; }

/* ===== History ===== */
.date-picker { margin-bottom: var(--sp-4); }

.history-list { max-height: 320px; overflow-y: auto; }

.history-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 4px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

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

.type-badge {
    padding: 4px 12px; border-radius: 999px;
    font-size: 12px; font-weight: 600; font-family: var(--font-head);
    display: inline-flex; align-items: center; gap: 5px; white-space: nowrap;
}
.type-badge .ic { width: 13px; height: 13px; }

.type-badge.checkin  { background: #DCFCE7; color: #166534; }
.type-badge.checkout { background: #FEF3C7; color: #92400E; }
.type-badge.admin    { background: #DBEAFE; color: #1E40AF; }

.summary {
    margin-top: var(--sp-4);
    padding: var(--sp-4);
    background: var(--muted);
    border-radius: var(--radius);
}

.summary-item { display: flex; justify-content: space-between; font-size: 14px; }
.summary-item .label { color: var(--muted-fg); }
.summary-item .value { font-weight: 700; font-family: var(--font-head); }

/* ===== Admin ===== */
/* LƯU Ý: giữ nguyên tên .admin-header / .admin-controls / .text-muted —
   js/ai-summary.js dùng chúng làm GUARD chặn non-admin (querySelectorAll
   '.admin-header, .text-muted' → el.hidden = true). Đổi tên là hỏng guard. */
.admin-header {
    display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
    gap: var(--sp-3); margin-bottom: var(--sp-5);
    padding-bottom: var(--sp-4); border-bottom: 1px solid var(--border);
}

.admin-header h2 { margin-bottom: 0; }

.admin-controls { display: flex; gap: var(--sp-2); align-items: center; flex-wrap: wrap; }

.form-control, input[type="date"], input[type="month"], select.form-control {
    min-height: 44px;
    padding: 2px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px; font-family: var(--font-body);
    background: var(--card); color: var(--foreground);
}

.form-control:focus { outline: none; border-color: var(--ring); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
select.form-control { width: 100%; }

.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.data-table {
    width: 100%; border-collapse: collapse; font-size: 13.5px;
    min-width: 620px;
}

.data-table th, .data-table td {
    padding: 12px 14px; text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.data-table thead th {
    background: var(--muted);
    font-family: var(--font-head); font-weight: 600; font-size: 12px;
    text-transform: uppercase; letter-spacing: .05em;
    color: var(--muted-fg);
    position: sticky; top: 0;
}

.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: var(--background); }

.data-table .cell-checkin  { color: var(--success-dark); font-weight: 600; }
.data-table .cell-checkout { color: #D97706; font-weight: 600; }
.data-table .cell-miss     { color: var(--muted-fg); }
/* icon trong ô bảng (công tác / nghỉ phép / chưa checkout) */
.data-table td .ic { width: 13px; height: 13px; vertical-align: -0.18em; margin-right: 2px; }
.cal-offsite .ic, .cal-leave .ic { width: 12px; height: 12px; }

/* ===== Modal ===== */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(15,23,42,.45);
    display: flex; align-items: center; justify-content: center;
    padding: 16px; z-index: 200;
    animation: fadeIn var(--dur) var(--ease);
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    width: 100%; max-width: 420px;
    padding: var(--sp-6);
    box-shadow: var(--shadow-lg);
    max-height: 90vh; overflow-y: auto;
    animation: slideUp var(--dur) var(--ease);
}

@keyframes slideUp { from { transform: translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }

.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--sp-5); }
.modal-header h3 { margin: 0; font-size: 20px; }

.modal-close {
    background: none; border: none; cursor: pointer;
    color: var(--muted-fg); line-height: 1; width: var(--touch-min); height: var(--touch-min);
    display: inline-flex; align-items: center; justify-content: center;
}
.modal-close .ic { width: 19px; height: 19px; }
.modal-close:hover { color: var(--foreground); }

.small { font-size: 12px; color: var(--muted-fg); }

/* ===== Loading & Empty ===== */
.loading-state, .empty-state { text-align: center; padding: var(--sp-7); color: var(--muted-fg); font-size: 14px; }

.spinner {
    display: inline-block; width: 18px; height: 18px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .6s linear infinite;
    vertical-align: -4px; margin-right: 8px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Bảng công theo tháng (dashboard) ===== */
.month-panel { margin-top: var(--sp-5); }

.month-summary {
    display: flex; flex-wrap: wrap; gap: 8px;
    margin-bottom: var(--sp-4);
}
.ms-item {
    display: inline-flex; align-items: center; gap: 6px;
    background: var(--card); border: 1px solid var(--border);
    padding: 8px 14px; border-radius: 999px;
    font-size: 13.5px; color: var(--muted-fg); box-shadow: var(--shadow-sm);
}
.ms-item strong { color: var(--foreground); font-family: var(--font-head); font-size: 14px; }
.ms-item .ic { width: 15px; height: 15px; justify-content: center; }
.ms-item[data-ic] { padding-left: 11px; }

/* ===== Bảng công theo tháng — Calendar ===== */
.cal { display: flex; flex-direction: column; gap: 6px; }
.cal-head, .cal-body { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-wd {
    text-align: center; padding: 4px 0;
    font-family: var(--font-head); font-size: 12px; font-weight: 700;
    text-transform: uppercase; letter-spacing: .06em; color: var(--muted-fg);
}
.cal-wd-sun { color: #DC2626; }

.cal-cell {
    background: var(--card); border: 1px solid var(--border); border-radius: 10px;
    padding: 6px; min-height: 76px;
    display: flex; flex-direction: column; gap: 3px;
    transition: box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.cal-cell:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.cal-empty { min-height: 76px; }

.cal-top { display: flex; align-items: center; min-height: 26px; }
.cal-num { font-family: var(--font-head); font-weight: 700; font-size: 14px; color: var(--foreground); }
.cal-num-today {
    background: var(--primary); color: #fff; border-radius: 50%;
    min-width: 26px; height: 26px;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 13px; box-shadow: 0 2px 6px rgba(37,99,235,.35);
}

.cal-times { display: flex; flex-direction: column; gap: 1px; line-height: 1.25; }
.t-in  { color: var(--success-dark); font-weight: 700; font-size: 12px; font-variant-numeric: tabular-nums; }
.t-out { color: #D97706; font-weight: 700; font-size: 12px; font-variant-numeric: tabular-nums; }

.cal-status { font-size: 11px; font-weight: 600; color: var(--muted-fg); }
.cal-status, .t-in, .t-out { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.cal-present { background: #F0FDF4; border-color: #BBF7D0; }
.cal-present .cal-status { color: #166534; }

.cal-leave { background: #FEFCE8; border-color: #FDE68A; }
.cal-leave .cal-status { color: #A16207; }

.cal-offsite { background: #EFF6FF; border-color: #BFDBFE; }
.cal-offsite .cal-status { color: #1E40AF; }

.cal-absent { background: #FEF2F2; border-color: #FECACA; }
.cal-absent .cal-status { color: #991B1B; }
.cal-absent .cal-num  { color: #B91C1C; }

.cal-off { background: #F8FAFC; border-style: dashed; }
.cal-off .cal-num  { color: var(--muted-fg); }
.cal-off .cal-status { color: var(--muted-fg); }

.cal-future { background: transparent; border-color: transparent; box-shadow: none; }
.cal-future:hover { transform: none; box-shadow: none; }
.cal-future .cal-num { color: #C9D3DF; }
.cal-future .cal-status { color: #C9D3DF; }

.cal-someday { border-color: var(--secondary); }
.cal-someday .cal-status { color: var(--primary); }

@media (max-width: 480px) {
    .cal-cell, .cal-empty { min-height: 62px; }
    .cal-cell { padding: 4px; }
    .cal-num { font-size: 12px; }
    .t-in, .t-out { font-size: 10px; }
    .cal-status { font-size: 10px; }
}

/* code / loginHint */
code, .data-table code {
    font-family: ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
    font-size: 12.5px;
    background: var(--muted);
    color: var(--foreground);
    padding: 2px 6px;
    border-radius: 5px;
}

/* Khối hướng dẫn (import.html, knowledge.html) */
.login-hint {
    margin-top: var(--sp-4);
    text-align: center;
    font-size: 13px;
    color: var(--muted-fg);
    line-height: 1.7;
}
.login-hint strong { color: var(--foreground); }
.login-hint em { color: var(--primary); font-style: normal; font-weight: 600; }

/* ===== Error ===== */
.error-message {
    background: #FEF2F2; color: #991B1B;
    padding: 10px 14px; border-radius: var(--radius);
    font-size: 13.5px; margin-bottom: var(--sp-4);
    border: 1px solid #FECACA;
}

.text-muted { color: var(--muted-fg); font-size: 14px; }

/* ===== AI Summary ===== */
.ai-result { margin-top: var(--sp-4); }
.ai-meta {
    font-weight: 700; color: var(--primary); margin-bottom: var(--sp-3);
    font-size: 14.5px;
}
.ai-body {
    background: var(--paper); border: 1px solid var(--border);
    border-radius: var(--radius); padding: var(--sp-4);
    font-size: 14.5px; line-height: 1.75; white-space: normal;
}
.ai-meta { display: flex; align-items: center; gap: 7px; }
.ai-meta .ic { width: 16px; height: 16px; }

/* ===== Leave form ===== */
.leave-form .form-group { margin-bottom: var(--sp-4); }
.leave-form label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--foreground); }
.leave-form .req { color: var(--destructive); }
.form-row { display: flex; gap: var(--sp-3); flex-wrap: wrap; }
.form-row .form-group { flex: 1 1 160px; }
.leave-reason { width: 100%; resize: vertical; font-family: var(--font-body); }

/* Bộ chọn giờ 24h (HH : MM) */
.time-pick { display: flex; align-items: center; gap: 4px; }
.time-pick .t-h { flex: 1 1 0; min-width: 0; }
.time-pick .t-m { flex: 1 1 0; min-width: 0; }
.time-pick .t-colon { font-weight: 700; color: var(--foreground); font-size: 16px; padding: 0 2px; }

/* ===== Phân quyền (admin-perms) ===== */
.perm-check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; min-height: 20px; }
.perm-check input { width: 18px; height: 18px; accent-color: var(--primary); cursor: pointer; }
.perm-dot {
    width: 12px; height: 12px; border-radius: 50%;
    background: transparent; border: 2px solid var(--border); display: inline-block;
    transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.perm-dot.on { background: var(--success); border-color: var(--success); }

/* ===== Chat AI ===== */
.chat-card { display: flex; flex-direction: column; min-height: 70vh; }
.chat-card h2 { margin-bottom: var(--sp-1); }
.chat-card .text-muted { margin-bottom: var(--sp-4); }
.chat-box {
    flex: 1 1 auto;
    overflow-y: auto;
    max-height: 52vh;
    padding: var(--sp-4);
    background: var(--muted);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    gap: var(--sp-3);
}
.chat-empty { text-align: center; color: var(--muted-fg); padding: var(--sp-5) 0; }
.chat-msg { display: flex; flex-direction: column; width: 100%; }
.msg-inner { display: flex; align-items: flex-end; gap: var(--sp-2); max-width: 100%; }
.msg-user .msg-inner { justify-content: flex-end; flex-direction: row-reverse; }
.msg-avatar {
    flex: 0 0 auto; line-height: 1; margin-bottom: 2px;
    width: 30px; height: 30px; border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--muted); color: var(--muted-fg);
}
.msg-user .msg-avatar { background: var(--primary); color: var(--on-primary); }
.msg-avatar .ic { width: 16px; height: 16px; }
.msg-bubble {
    max-width: 76%;
    padding: var(--sp-2) var(--sp-3);
    border-radius: var(--radius-lg);
    background: var(--card);
    color: var(--card-fg);
    box-shadow: var(--shadow-sm);
    font-size: 14px;
    line-height: 1.5;
    overflow-wrap: break-word;
    word-break: break-word;
}
.msg-user .msg-bubble { background: var(--primary); color: var(--on-primary); }
.msg-meta {
    font-size: 11px;
    color: var(--muted-fg);
    margin-top: var(--sp-1);
    text-align: right;
}
.msg-user .msg-meta { color: rgba(255,255,255,.8); }
.chat-error {
    display: flex; align-items: center; gap: 6px;
    background: rgba(220,38,38,.08);
    color: var(--destructive);
    border: 1px solid var(--destructive);
    border-radius: var(--radius);
    padding: var(--sp-2) var(--sp-3);
    margin-top: var(--sp-2);
    font-size: 13px;
}
.chat-loading {
    color: var(--muted-fg); font-size: 13px; padding: var(--sp-2) 0;
    display: flex; align-items: center; gap: 6px;
}
.chat-loading .ic { width: 15px; height: 15px; }
.chat-form { display: flex; gap: var(--sp-2); margin-top: var(--sp-3); }
.chat-form .form-control { flex: 1 1 auto; }
.chat-form .btn { flex: 0 0 auto; min-width: 80px; }

/* ===== Chat FAB + widget (góc phải dưới) ===== */
.chat-fab .ic { width: 24px; height: 24px; }
.chat-fab {
    position: fixed;
    right: var(--sp-4);
    bottom: var(--sp-4);
    z-index: 2000;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--primary);
    color: var(--on-primary);
    border: none;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform var(--dur) var(--ease), background var(--dur) var(--ease);
}
.chat-fab:hover { background: var(--primary-dark); transform: scale(1.06); }
.chat-fab.active { background: var(--destructive); transform: rotate(90deg); }

.chat-widget {
    position: fixed;
    right: var(--sp-4);
    bottom: calc(var(--sp-4) + 68px);
    z-index: 1999;
    width: 360px;
    max-width: calc(100vw - 2 * var(--sp-4));
    height: 480px;
    max-height: calc(100vh - 120px);
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.chat-widget:not([hidden]) { display: flex; }
.chat-widget-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--sp-3) var(--sp-4);
    background: var(--primary);
    color: var(--on-primary);
    font-weight: 600;
}
.chat-widget-title { font-size: 14.5px; }
.chat-widget-close {
    background: none;
    border: none;
    color: var(--on-primary);
    cursor: pointer;
    padding: 0 var(--sp-1);
    display: inline-flex; align-items: center;
}
.chat-widget-close .ic { width: 16px; height: 16px; }
.chat-widget-hint {
    padding: var(--sp-2) var(--sp-4);
    font-size: 12px;
    color: var(--muted-fg);
    background: var(--muted);
    border-bottom: 1px solid var(--border);
}
.chat-widget .chat-box {
    flex: 1 1 auto;
    max-height: none;
    border: none;
    border-radius: 0;
    background: var(--card);
}
.chat-widget .chat-form {
    padding: var(--sp-3);
    margin-top: 0;
    border-top: 1px solid var(--border);
}

/* Responsive mobile — gần full màn hình */
@media (max-width: 480px) {
    .chat-widget {
        right: var(--sp-2);
        left: var(--sp-2);
        bottom: var(--sp-2);
        width: auto;
        height: 72vh;
        max-width: none;
    }
    .chat-fab { right: var(--sp-3); bottom: var(--sp-3); }
}

/* ===== Responsive ===== */
@media (max-width: 480px) {
    .nav-brand { font-size: 16px; }
    .current-time { font-size: 42px; }
    .admin-controls { width: 100%; }
    .admin-controls .form-control, .admin-controls .btn { flex: 1 1 auto; width: auto; }
    .container { padding: calc(var(--topbar-h) + var(--sp-4)) var(--sp-3) var(--sp-6); }
    .card { padding: var(--sp-4); }
    .card h2 { font-size: 17px; }
}
/* ============================================================
   Dark mode — override màu hard-code (trạng thái / bảng / lịch)
   ============================================================ */
:root[data-theme="dark"] .ip-status.allowed  { background: #10251C; color: #6EE7B7; border-color: #1F3A2E; }
:root[data-theme="dark"] .ip-status.denied   { background: #2A1216; color: #FCA5A5; border-color: #3E1D22; }
:root[data-theme="dark"] .ip-status.loading  { background: var(--muted); color: var(--muted-fg); }

:root[data-theme="dark"] .check-result.success { background: #10251C; color: #6EE7B7; border-color: #1F3A2E; }
:root[data-theme="dark"] .check-result.error   { background: #2A1216; color: #FCA5A5; border-color: #3E1D22; }
:root[data-theme="dark"] .error-message        { background: #2A1216; color: #FCA5A5; border: 1px solid #3E1D22; }

:root[data-theme="dark"] .type-badge.checkin  { background: #123323; color: #86EFAC; }
:root[data-theme="dark"] .type-badge.checkout { background: #38230A; color: #FCD34D; }
:root[data-theme="dark"] .type-badge.admin    { background: #18274A; color: #93C5FD; }

:root[data-theme="dark"] .data-table tbody tr:hover td { background: var(--muted); }
:root[data-theme="dark"] .data-table .cell-checkin  { color: #6EE7B7; }
:root[data-theme="dark"] .data-table .cell-checkout { color: #FBBF24; }

:root[data-theme="dark"] .t-in  { color: #6EE7B7; }
:root[data-theme="dark"] .t-out { color: #FBBF24; }

:root[data-theme="dark"] .cal-present { background: #10251C; border-color: #1F3A2E; }
:root[data-theme="dark"] .cal-present .cal-status { color: #6EE7B7; }
:root[data-theme="dark"] .cal-leave   { background: #2A2003; border-color: #46340A; }
:root[data-theme="dark"] .cal-leave .cal-status   { color: #FCD34D; }
:root[data-theme="dark"] .cal-offsite { background: #101E30; border-color: #1F3450; }
:root[data-theme="dark"] .cal-offsite .cal-status { color: #93C5FD; }
:root[data-theme="dark"] .cal-absent  { background: #2A1216; border-color: #3E1D22; }
:root[data-theme="dark"] .cal-absent .cal-status  { color: #FCA5A5; }
:root[data-theme="dark"] .cal-absent .cal-num     { color: #F87171; }
:root[data-theme="dark"] .cal-off     { background: #111A2E; border-style: dashed; }
:root[data-theme="dark"] .cal-future .cal-num     { color: #33415C; }
:root[data-theme="dark"] .cal-future .cal-status  { color: #33415C; }
