/* =====================================================================
   Attendance System — UI theme (Bootstrap 5.3, RTL/LTR, light/dark)
   ===================================================================== */
:root {
    --app-font: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, system-ui, -apple-system, "Noto Sans Arabic", sans-serif;
    --app-primary: #2457d6;
    --app-primary-rgb: 36, 87, 214;
    --app-primary-dark: #1b43a8;
    --app-accent: #2dd4bf;
    --app-sidebar-bg: #0f1e3d;
    --app-sidebar-bg-2: #13284f;
    --app-sidebar-text: #b9c5dd;
    --app-bg: #f3f5fa;
    --app-surface: #ffffff;
    --app-border: #e5e9f2;
    --app-muted: #6b778c;
    --app-radius: 14px;
    --app-shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 4px 16px rgba(16, 24, 40, .06);
    --app-sidebar-w: 264px;
    --app-topbar-h: 64px;
    --bs-body-font-family: var(--app-font);
    --bs-primary: var(--app-primary);
    --bs-primary-rgb: var(--app-primary-rgb);
    --bs-link-color: var(--app-primary);
    --bs-link-color-rgb: var(--app-primary-rgb);
    --bs-link-hover-color: var(--app-primary-dark);
    --bs-border-radius: 10px;
}
[data-bs-theme="dark"] {
    --app-bg: #0b1220;
    --app-surface: #111a2e;
    --app-border: #1f2a44;
    --app-muted: #94a3b8;
    --app-sidebar-bg: #070d1a;
    --app-sidebar-bg-2: #0c162b;
    --app-shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .35);
    --app-primary: #5b8cff;
    --app-primary-rgb: 91, 140, 255;
    --app-primary-dark: #7aa2ff;
}

html, body { font-family: var(--app-font); }
body { background: var(--app-bg); font-size: .95rem; -webkit-font-smoothing: antialiased; }
[dir="rtl"] body { letter-spacing: 0; }
.icon { width: 1.15em; height: 1.15em; vertical-align: -.2em; flex-shrink: 0; }
code, .ltr { direction: ltr; unicode-bidi: embed; }
.skip-link { position: absolute; top: .5rem; inset-inline-start: .5rem; z-index: 2000; background: #fff; padding: .5rem 1rem; border-radius: 8px; }

/* Buttons */
.btn-primary {
    --bs-btn-bg: var(--app-primary); --bs-btn-border-color: var(--app-primary);
    --bs-btn-hover-bg: var(--app-primary-dark); --bs-btn-hover-border-color: var(--app-primary-dark);
    --bs-btn-active-bg: var(--app-primary-dark); --bs-btn-active-border-color: var(--app-primary-dark);
    --bs-btn-disabled-bg: var(--app-primary); --bs-btn-disabled-border-color: var(--app-primary);
}
.btn-outline-primary {
    --bs-btn-color: var(--app-primary); --bs-btn-border-color: var(--app-primary);
    --bs-btn-hover-bg: var(--app-primary); --bs-btn-hover-border-color: var(--app-primary);
    --bs-btn-active-bg: var(--app-primary); --bs-btn-active-border-color: var(--app-primary);
}
.btn { border-radius: 10px; font-weight: 500; display: inline-flex; align-items: center; justify-content: center; gap: .4rem; }
.btn-icon { width: 40px; height: 40px; padding: 0; border-radius: 12px; color: var(--bs-body-color); border: 0; background: transparent; }
.btn-icon:hover, .btn-icon:focus-visible { background: rgba(var(--app-primary-rgb), .08); color: var(--app-primary); }
.form-control, .form-select { border-radius: 10px; border-color: var(--app-border); padding-block: .55rem; }
.form-control:focus, .form-select:focus { border-color: rgba(var(--app-primary-rgb), .6); box-shadow: 0 0 0 .2rem rgba(var(--app-primary-rgb), .15); }
.form-check-input:checked { background-color: var(--app-primary); border-color: var(--app-primary); }
.form-label { font-weight: 500; font-size: .875rem; margin-bottom: .35rem; }
.page-link { color: var(--app-primary); }
.active > .page-link, .page-link.active { background-color: var(--app-primary); border-color: var(--app-primary); }

/* Shell */
.app-shell { display: flex; min-height: 100vh; }
.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.app-content { padding: 1.5rem; flex: 1; max-width: 1600px; width: 100%; margin-inline: auto; }

.app-sidebar {
    width: var(--app-sidebar-w); flex-shrink: 0;
    background: linear-gradient(180deg, var(--app-sidebar-bg) 0%, var(--app-sidebar-bg-2) 100%);
    color: var(--app-sidebar-text);
}
@media (min-width: 992px) {
    .app-sidebar { position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; }
}
@media (max-width: 991.98px) {
    .app-sidebar.offcanvas-lg { --bs-offcanvas-width: 280px; --bs-offcanvas-bg: var(--app-sidebar-bg); }
    /* Phone menu: the offcanvas is a fixed-height flex column with no .offcanvas-body, so the links must scroll themselves. */
    .app-sidebar.offcanvas-lg .sidebar-brand { flex-shrink: 0; }
    .app-sidebar.offcanvas-lg .sidebar-nav { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch; padding-bottom: calc(2rem + env(safe-area-inset-bottom)); }
}
.sidebar-brand { display: flex; align-items: center; gap: .75rem; padding: 1.25rem 1.25rem 1rem; color: #fff; }
.brand-mark { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; font-size: 1.4rem;
    background: linear-gradient(135deg, var(--app-accent), #3b82f6); color: #06122a; }
.brand-logo { width: 42px; height: 42px; object-fit: contain; border-radius: 10px; background: #fff; padding: 3px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.brand-text strong { font-size: 1rem; }
.brand-text small { color: var(--app-sidebar-text); font-size: .78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-nav { padding: .5rem .75rem 2rem; }
.nav-group-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: #7486a8; padding: 1.1rem .75rem .4rem; }
[dir="rtl"] .nav-group-label { letter-spacing: 0; font-size: .78rem; }
.sidebar-nav .nav-link { display: flex; align-items: center; gap: .75rem; padding: .62rem .8rem; margin-bottom: 2px; border-radius: 10px;
    color: var(--app-sidebar-text); font-weight: 500; transition: background .15s, color .15s; }
.sidebar-nav .nav-link .icon { width: 1.2em; height: 1.2em; opacity: .85; }
.sidebar-nav .nav-link:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.sidebar-nav .nav-link.active { background: rgba(45, 212, 191, .14); color: #fff; box-shadow: inset 3px 0 0 var(--app-accent); }
[dir="rtl"] .sidebar-nav .nav-link.active { box-shadow: inset -3px 0 0 var(--app-accent); }

.app-topbar {
    position: sticky; top: 0; z-index: 1020; height: var(--app-topbar-h);
    display: flex; align-items: center; gap: .75rem; padding: 0 1.5rem;
    background: rgba(255, 255, 255, .86); backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid var(--app-border);
}
[data-bs-theme="dark"] .app-topbar { background: rgba(17, 26, 46, .86); }
.topbar-title { flex: 1; min-width: 0; }
.topbar-actions { display: flex; align-items: center; gap: .25rem; }
.btn-user { display: flex; align-items: center; gap: .5rem; border: 0; padding: .25rem .5rem; border-radius: 12px; max-width: 220px; }
.btn-user:hover { background: rgba(var(--app-primary-rgb), .08); }
.user-name { max-width: 140px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: inline-grid; place-items: center; font-weight: 600;
    background: linear-gradient(135deg, var(--app-primary), #7c3aed); color: #fff; flex-shrink: 0; }
.avatar-lg { width: 64px; height: 64px; font-size: 1.5rem; }
.avatar-img { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; }
.theme-light { display: none; }
[data-bs-theme="dark"] .theme-light { display: inline; }
[data-bs-theme="dark"] .theme-dark { display: none; }

/* Notifications */
.notif-badge { position: absolute; top: 3px; inset-inline-end: 1px; font-size: .65rem; min-width: 18px; padding: .2em .45em; }
.notif-menu { width: min(380px, calc(100vw - 24px)); border-radius: var(--app-radius); overflow: hidden; }
.notif-list { max-height: 60vh; overflow-y: auto; }
.notif-item { display: flex; gap: .75rem; padding: .75rem 1rem; border-bottom: 1px solid var(--app-border); text-decoration: none; color: inherit; cursor: pointer; }
.notif-item:hover { background: rgba(var(--app-primary-rgb), .05); }
.notif-item.unread { background: rgba(var(--app-primary-rgb), .06); }
.notif-item .dot { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; flex-shrink: 0; }
.notif-item .title { font-weight: 600; font-size: .88rem; }
.notif-item .msg { font-size: .82rem; color: var(--app-muted); }
.notif-item .time { font-size: .72rem; color: var(--app-muted); }
.type-attendance .dot { background: #dcfce7; color: #15803d; }
.type-late .dot { background: #ffedd5; color: #c2410c; }
.type-absence .dot { background: #fee2e2; color: #b91c1c; }
.type-leave .dot { background: #dbeafe; color: #1d4ed8; }
.type-device .dot { background: #ede9fe; color: #6d28d9; }
.type-system .dot, .type-security .dot { background: #f1f5f9; color: #334155; }
@keyframes bell-ring { 0%, 100% { transform: rotate(0); } 20% { transform: rotate(14deg); } 40% { transform: rotate(-12deg); } 60% { transform: rotate(8deg); } 80% { transform: rotate(-4deg); } }
.ring .icon { animation: bell-ring .9s ease; transform-origin: top center; }

/* Cards */
.card { border: 1px solid var(--app-border); border-radius: var(--app-radius); box-shadow: var(--app-shadow); background: var(--app-surface); }
.card-header { background: transparent; border-bottom: 1px solid var(--app-border); padding: 1rem 1.25rem; font-weight: 600; }
.card-body { padding: 1.25rem; }
.stat-card { position: relative; overflow: hidden; height: 100%; }
.stat-card .card-body { display: flex; align-items: center; gap: 1rem; }
.stat-icon { width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center; font-size: 1.35rem; flex-shrink: 0; }
.stat-value { font-size: 1.65rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-label { color: var(--app-muted); font-size: .85rem; }
.tone-blue { background: #dbeafe; color: #1d4ed8; } .tone-green { background: #dcfce7; color: #15803d; }
.tone-orange { background: #ffedd5; color: #c2410c; } .tone-red { background: #fee2e2; color: #b91c1c; }
.tone-cyan { background: #cffafe; color: #0e7490; } .tone-violet { background: #ede9fe; color: #6d28d9; }
.tone-slate { background: #f1f5f9; color: #334155; } .tone-amber { background: #fef3c7; color: #b45309; }
[data-bs-theme="dark"] [class*="tone-"] { background: rgba(255, 255, 255, .07); }

.page-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: 1rem; }
.page-toolbar .actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.filter-bar { background: var(--app-surface); border: 1px solid var(--app-border); border-radius: var(--app-radius); padding: 1rem; margin-bottom: 1rem; }

/* Today status hero */
.today-hero { border: 0; color: #fff; background: linear-gradient(135deg, #1b3a8a 0%, #2457d6 55%, #0ea5a4 100%); }
.today-hero .muted { color: rgba(255, 255, 255, .78); }
.today-hero .big-status { font-size: 1.6rem; font-weight: 700; }
.today-hero .metric { background: rgba(255, 255, 255, .12); border-radius: 12px; padding: .75rem 1rem; }
.today-hero .metric strong { display: block; font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.status-dot { display: inline-block; width: .7rem; height: .7rem; border-radius: 50%; margin-inline-end: .4rem; }
.status-dot.present { background: #22c55e; } .status-dot.late { background: #f59e0b; } .status-dot.absent { background: #ef4444; }
.status-dot.leave { background: #3b82f6; } .status-dot.holiday, .status-dot.weekend { background: #e5e7eb; }
.status-dot.incomplete, .status-dot.not_arrived { background: #94a3b8; }

/* Live feed */
.feed { list-style: none; margin: 0; padding: 0; max-height: 440px; overflow-y: auto; }
.feed li { display: flex; gap: .75rem; padding: .7rem 0; border-bottom: 1px dashed var(--app-border); }
.feed li:last-child { border-bottom: 0; }
.feed .time { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 3.2rem; color: var(--app-primary); }
.feed .who { font-weight: 600; }
.feed .what { font-size: .83rem; color: var(--app-muted); }
.feed li.fresh { animation: flash-in 1.6s ease; }
@keyframes flash-in { from { background: rgba(45, 212, 191, .25); } to { background: transparent; } }
.live-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #22c55e; box-shadow: 0 0 0 0 rgba(34, 197, 94, .6); animation: pulse 2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, .55); } 70% { box-shadow: 0 0 0 8px rgba(34, 197, 94, 0); } 100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); } }

/* Charts (dependency-free SVG) */
.chart { width: 100%; height: 240px; }
.chart text { font-family: var(--app-font); font-size: 11px; fill: var(--app-muted); }
.chart .grid { stroke: var(--app-border); stroke-width: 1; }
.legend { display: flex; flex-wrap: wrap; gap: .75rem 1.25rem; font-size: .82rem; color: var(--app-muted); }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-inline-end: .35rem; background: var(--c); }
.donut-wrap { display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap; justify-content: center; }
.donut-center { font-size: 1.6rem; font-weight: 700; fill: var(--bs-body-color) !important; }

/* Tables */
.table { --bs-table-bg: transparent; margin-bottom: 0; vertical-align: middle; }
.table > thead th { font-size: .78rem; font-weight: 600; color: var(--app-muted); text-transform: uppercase; letter-spacing: .03em;
    background: rgba(var(--app-primary-rgb), .035); border-bottom-width: 1px; white-space: nowrap; }
[dir="rtl"] .table > thead th { letter-spacing: 0; font-size: .82rem; }
.table > :not(caption) > * > * { padding: .7rem .85rem; border-color: var(--app-border); }
.table-hover > tbody > tr:hover > * { --bs-table-bg-state: rgba(var(--app-primary-rgb), .04); }
.table .num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.table-responsive { border-radius: var(--app-radius); }
.card > .table-responsive { border-radius: 0 0 var(--app-radius) var(--app-radius); }

/* Stacked tables on phones: every row becomes a card (no horizontal overflow). */
@media (max-width: 575.98px) {
    .table-stack thead { display: none; }
    .table-stack, .table-stack tbody, .table-stack tr, .table-stack td { display: block; width: 100%; }
    .table-stack tr { border-bottom: 1px solid var(--app-border); padding: .6rem .25rem; }
    .table-stack > :not(caption) > * > * { border: 0; padding: .25rem .75rem; }
    .table-stack td { display: flex; justify-content: space-between; gap: 1rem; text-align: end; }
    .table-stack td::before { content: attr(data-label); font-weight: 600; color: var(--app-muted); text-align: start; flex-shrink: 0; }
    .table-stack td[data-label=""]::before { content: none; }
    .table-stack td.actions { justify-content: flex-end; }
}

.badge { font-weight: 500; padding: .38em .7em; }
.bg-light.text-dark { border: 1px solid var(--app-border); }
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--app-muted); }
.empty-state .icon { width: 2.5rem; height: 2.5rem; opacity: .5; margin-bottom: .5rem; }
.token-box { font-family: ui-monospace, Consolas, monospace; direction: ltr; word-break: break-all; background: #0f172a; color: #a7f3d0; padding: .75rem 1rem; border-radius: 10px; }
.kv dt { color: var(--app-muted); font-weight: 500; font-size: .85rem; }
.kv dd { margin-bottom: .75rem; }
.perm-matrix th, .perm-matrix td { text-align: center; }
.perm-matrix td:first-child, .perm-matrix th:first-child { text-align: start; }

/* Skeleton loading */
.skeleton { background: linear-gradient(90deg, var(--app-border) 25%, rgba(255, 255, 255, .5) 50%, var(--app-border) 75%); background-size: 200% 100%;
    animation: shimmer 1.2s infinite; border-radius: 6px; min-height: 1rem; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* Auth */
.auth-body { background: radial-gradient(1200px 600px at 10% -10%, #2457d6 0%, transparent 60%), radial-gradient(900px 500px at 110% 110%, #0ea5a4 0%, transparent 55%), #0f1e3d; min-height: 100vh; }
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1.25rem; }
.auth-card { width: 100%; max-width: 420px; background: var(--app-surface); border-radius: 20px; padding: 2rem; box-shadow: 0 20px 60px rgba(0, 0, 0, .35); }
.auth-card .brand-mark { width: 56px; height: 56px; font-size: 1.8rem; margin: 0 auto 1rem; }
.error-code { font-size: 4rem; font-weight: 700; color: var(--app-primary); line-height: 1; margin-bottom: 1rem; }
.auth-lang { position: fixed; top: 1rem; inset-inline-end: 1rem; }

/* Bottom navigation (phones & tablets) */
.bottom-nav { position: fixed; bottom: 0; inset-inline: 0; z-index: 1030; display: flex; background: var(--app-surface);
    border-top: 1px solid var(--app-border); padding-bottom: env(safe-area-inset-bottom); box-shadow: 0 -4px 16px rgba(16, 24, 40, .06); }
.bottom-nav a, .bottom-nav button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: .5rem .25rem .45rem;
    font-size: .7rem; color: var(--app-muted); text-decoration: none; border: 0; background: none; min-width: 0; }
.bottom-nav .icon { width: 1.35rem; height: 1.35rem; }
.bottom-nav .active { color: var(--app-primary); }
.bottom-nav span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }

@media (max-width: 991.98px) {
    .app-content { padding: 1rem 1rem calc(76px + env(safe-area-inset-bottom)); }
    .app-topbar { padding: 0 .75rem; }
    .toast-container { bottom: 70px !important; }
}
@media (max-width: 575.98px) {
    body { font-size: .92rem; }
    .app-content { padding-inline: .75rem; }
    .stat-value { font-size: 1.35rem; }
    .stat-icon { width: 40px; height: 40px; }
    .card-body { padding: 1rem; }
    .page-toolbar .actions .btn { flex: 1 1 auto; }
    .today-hero .big-status { font-size: 1.3rem; }
    .topbar-title h1 { font-size: 1rem; }
}

/* Print / PDF */
.print-page { font-family: var(--app-font); padding: 1.5rem; color: #000; background: #fff; }
.print-page table { width: 100%; border-collapse: collapse; font-size: 11px; }
.print-page th, .print-page td { border: 1px solid #999; padding: 4px 6px; text-align: start; }
.print-page th { background: #eef2f7; }
@media print {
    .no-print { display: none !important; }
    @page { size: A4 landscape; margin: 10mm; }
    .print-page { padding: 0; }
}

/* Client demo (APP_ENV=demo) — clear but unobtrusive indicators */
.demo-badge { background: linear-gradient(135deg, #f59e0b, #ea580c); color: #fff; font-weight: 600; letter-spacing: .02em; }
.demo-strip { display: flex; align-items: center; gap: .6rem; padding: .35rem 1.5rem; font-size: .8rem;
    background: rgba(245, 158, 11, .1); border-bottom: 1px solid rgba(245, 158, 11, .35); color: var(--bs-body-color); }
.demo-strip-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.demo-login { border: 1px dashed rgba(245, 158, 11, .6); border-radius: 12px; padding: .75rem; background: rgba(245, 158, 11, .06); }
.demo-fill { cursor: pointer; }
@media (max-width: 575.98px) { .demo-strip { padding: .35rem .75rem; } .demo-strip-text { white-space: normal; } }

/* ---- Mobile biometric attendance ------------------------------------------------------------ */
.mobile-card .mobile-icon .icon { width: 56px; height: 56px; color: var(--bs-primary); }
.mobile-card .btn-lg { font-size: 1.15rem; font-weight: 600; border-radius: 14px; }
.mobile-card .btn-lg .icon { width: 1.4em; height: 1.4em; vertical-align: -0.3em; }
.mobile-status { margin-bottom: 0; line-height: 1.7; }
.mobile-status:empty { display: none; }
@media (max-width: 575.98px) { .mobile-card .card-body { padding: 1.25rem 1rem; } }
