/* style.css — hand-written, mobile-first, dependency-free (no CDN, no framework).
   Base styles target small screens; min-width media queries layer on
   tablet/desktop enhancements. All class names below are load-bearing —
   every PHP page in the project renders against these exact selectors. */

:root {
    --color-bg: #f5f6fb;
    --color-bg-alt: #eef0f8;
    --color-surface: #ffffff;
    --color-border: #e3e6ef;
    --color-border-strong: #d3d7e6;
    --color-text: #16182b;
    --color-text-muted: #6b7086;
    --color-text-faint: #9297ac;

    --color-primary: #4f46e5;
    --color-primary-dark: #4338ca;
    --color-primary-light: #eef0ff;
    --color-primary-rgb: 79, 70, 229;

    --color-success: #10855a;
    --color-success-bg: #e5f8ef;
    --color-warning: #b5720a;
    --color-warning-bg: #fdf1dd;
    --color-danger: #d13c33;
    --color-danger-bg: #fceeed;
    --color-info: #0b7cb0;
    --color-info-bg: #e6f4fb;

    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 18px;
    --touch-target: 44px;
    --header-height: 60px;

    --shadow-xs: 0 1px 2px rgba(16, 24, 60, 0.05);
    --shadow-sm: 0 2px 8px rgba(16, 24, 60, 0.06);
    --shadow-md: 0 8px 24px rgba(16, 24, 60, 0.10);
    --shadow-lg: 0 20px 48px rgba(16, 24, 60, 0.16);

    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Roboto, Helvetica, Arial, sans-serif;
}

/* Dark mode — toggled via [data-theme="dark"] on <html>, set server-side from
   a cookie (no flash-of-wrong-theme) and flipped client-side by app.js. */
:root[data-theme="dark"] {
    --color-bg: #0f1220;
    --color-bg-alt: #171b2e;
    --color-surface: #1a1f35;
    --color-border: #2c3350;
    --color-border-strong: #3c4468;
    --color-text: #e8e9f3;
    --color-text-muted: #9ba0bd;
    --color-text-faint: #6f748f;

    --color-primary: #7c6cff;
    --color-primary-dark: #6355e0;
    --color-primary-light: #262a4a;
    --color-primary-rgb: 124, 108, 255;

    --color-success: #35c98a;
    --color-success-bg: #123527;
    --color-warning: #e0a83f;
    --color-warning-bg: #3a2c11;
    --color-danger: #f16d63;
    --color-danger-bg: #3a1a18;
    --color-info: #4db8e8;
    --color-info-bg: #12293a;

    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.25);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 20px 48px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
    font-family: var(--font-sans);
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--color-primary); text-decoration: none; }
a:hover { color: var(--color-primary-dark); text-decoration: underline; }
img { max-width: 100%; }

h1, h2, h3 { line-height: 1.25; margin: 0 0 .6em; letter-spacing: -0.01em; font-weight: 700; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 1em; }
code { background: var(--color-bg-alt); padding: 2px 6px; border-radius: 6px; font-size: 0.85em; }

/* ---------------------------------------------------------------- Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: var(--touch-target);
    padding: 0 18px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    color: var(--color-text);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: var(--shadow-xs);
    transition: transform .12s ease, box-shadow .12s ease, background-color .12s ease, border-color .12s ease;
    text-decoration: none;
}
.btn:hover { text-decoration: none; border-color: var(--color-border-strong); box-shadow: var(--shadow-sm); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary {
    background: linear-gradient(180deg, var(--color-primary), var(--color-primary-dark));
    border-color: var(--color-primary-dark);
    color: #fff;
    box-shadow: 0 4px 14px rgba(var(--color-primary-rgb), 0.35);
}
.btn-primary:hover { box-shadow: 0 6px 18px rgba(var(--color-primary-rgb), 0.42); filter: brightness(1.03); }
.btn-danger { background: var(--color-danger); border-color: var(--color-danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.06); }
.btn-small { min-height: 36px; padding: 0 12px; font-size: 13px; }
.btn-active { background: var(--color-primary-light); border-color: var(--color-primary); color: var(--color-primary-dark); box-shadow: none; }

/* ---------------------------------------------------------------- Forms */
input[type="text"], input[type="password"], input[type="email"], input[type="date"],
input[type="time"], input[type="number"], input[type="search"], input[type="file"], select, textarea {
    width: 100%;
    min-height: var(--touch-target);
    padding: 8px 14px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    color: var(--color-text);
    font-size: 15px;
    font-family: inherit;
    margin-bottom: 14px;
    transition: border-color .12s ease, box-shadow .12s ease;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(var(--color-primary-rgb), 0.15);
}
input[type="file"] { padding: 8px; background: var(--color-bg-alt); }
label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 6px; color: var(--color-text-muted); }

/* Password show/hide toggle — injected by app.js around every password input */
.password-field { position: relative; }
.password-field input[type="password"], .password-field input[type="text"] { padding-right: 44px; }
.password-toggle {
    position: absolute;
    top: 0;
    bottom: 14px; /* offsets the input's own margin-bottom so it centers on the field, not the wrapper */
    right: 4px;
    width: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    padding: 0;
    color: var(--color-text-faint);
    cursor: pointer;
    border-radius: var(--radius-sm);
}
.password-toggle:hover { color: var(--color-text-muted); background: var(--color-bg-alt); }
.password-toggle:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 1px; }
textarea { min-height: var(--touch-target); resize: vertical; font-family: var(--font-sans); }

/* ---------------------------------------------------------------- Auth pages */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    position: relative;
    overflow: hidden;
    background:
        radial-gradient(circle at 15% 20%, rgba(99, 91, 255, 0.20), transparent 45%),
        radial-gradient(circle at 85% 80%, rgba(79, 70, 229, 0.18), transparent 50%),
        linear-gradient(160deg, #12142b 0%, #1c1f3d 45%, #2b1f52 100%);
}
.auth-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 28px;
}
.auth-brand-mark {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: linear-gradient(135deg, #7c6cff, var(--color-primary-dark));
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 20px rgba(99, 91, 255, 0.45);
    flex-shrink: 0;
}
.auth-brand-mark svg { width: 22px; height: 22px; }
.auth-brand-name { color: #f4f4ff; font-weight: 700; font-size: 1.15rem; letter-spacing: -0.01em; }
.auth-card {
    width: 100%;
    max-width: 400px;
    background: rgba(255, 255, 255, 0.97);
    border: 1px solid rgba(255, 255, 255, 0.5);
    border-radius: var(--radius-lg);
    padding: 32px 28px;
    box-shadow: var(--shadow-lg);
    position: relative;
    z-index: 1;
    animation: auth-card-in .5s cubic-bezier(.2, .8, .2, 1);
}
@keyframes auth-card-in {
    from { opacity: 0; transform: translateY(10px) scale(.98); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}
.auth-card h1 { text-align: center; margin-bottom: 4px; }
.auth-subtitle { text-align: center; color: var(--color-text-muted); font-size: 13.5px; margin-bottom: 22px; }
.auth-card .btn-primary { width: 100%; margin-top: 4px; }
.auth-footnote { text-align: center; font-size: 12px; color: var(--color-text-faint); margin-top: 18px; margin-bottom: 0; }

/* ---------------------------------------------------------------- Header / nav */
.app-header {
    position: sticky;
    top: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    gap: 10px;
    height: var(--header-height);
    padding: 0 14px;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: saturate(180%) blur(10px);
    -webkit-backdrop-filter: saturate(180%) blur(10px);
    border-bottom: 1px solid var(--color-border);
    box-shadow: var(--shadow-xs);
}
.app-brand {
    display: flex;
    align-items: center;
    gap: 9px;
    font-weight: 700;
    font-size: 16px;
    color: var(--color-text);
}
.app-brand:hover { text-decoration: none; color: var(--color-text); }
.app-brand-mark {
    width: 30px;
    height: 30px;
    border-radius: 9px;
    background: linear-gradient(135deg, #7c6cff, var(--color-primary-dark));
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 3px 10px rgba(var(--color-primary-rgb), 0.35);
}
.app-brand-mark svg { width: 17px; height: 17px; }
.header-spacer { flex: 1; }
.header-username { font-size: 13px; color: var(--color-text-muted); display: none; font-weight: 600; }

.hamburger {
    width: var(--touch-target);
    height: var(--touch-target);
    background: none;
    border: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    cursor: pointer;
    flex-shrink: 0;
    border-radius: var(--radius-sm);
    -webkit-tap-highlight-color: transparent;
}
.hamburger:hover { background: var(--color-bg-alt); }
.hamburger span {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--color-text);
    border-radius: 2px;
    transition: transform .25s ease, opacity .2s ease;
}
.hamburger[aria-expanded="true"] span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.hamburger[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
.hamburger[aria-expanded="true"] span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

.theme-toggle {
    width: var(--touch-target);
    height: var(--touch-target);
    border: none;
    background: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 17px;
    color: var(--color-text-muted);
    flex-shrink: 0;
}
.theme-toggle:hover { background: var(--color-bg-alt); }
.theme-icon-light { display: none; }
:root[data-theme="dark"] .theme-icon-dark { display: none; }
:root[data-theme="dark"] .theme-icon-light { display: inline; }

/* Custom confirm/alert modal (replaces the browser's native dialogs) */
.app-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: rgba(15, 17, 33, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 0;
    pointer-events: none;
    transition: opacity .18s ease;
}
.app-modal-overlay.open { opacity: 1; pointer-events: auto; }
.app-modal-box {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 24px;
    width: 100%;
    max-width: 380px;
    transform: translateY(8px) scale(.98);
    transition: transform .18s ease;
}
.app-modal-overlay.open .app-modal-box { transform: translateY(0) scale(1); }
.app-modal-message {
    font-size: 15px;
    color: var(--color-text);
    line-height: 1.5;
    margin-bottom: 20px;
    white-space: pre-wrap;
}
.app-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}
.app-modal-actions .btn { min-width: 88px; }

/* Mobile nav = fixed slide-in drawer, so the toggle is always visually obvious. */
.app-nav {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 60;
    width: min(280px, 82vw);
    display: flex;
    flex-direction: column;
    background: var(--color-surface);
    box-shadow: var(--shadow-lg);
    padding: calc(var(--header-height) + 8px) 0 24px;
    transform: translateX(-100%);
    transition: transform .28s cubic-bezier(.2, .8, .2, 1);
    overflow-y: auto;
}
.app-nav.open { transform: translateX(0); }
.app-nav a {
    padding: 13px 20px;
    color: var(--color-text);
    font-size: 15px;
    font-weight: 500;
    border-left: 3px solid transparent;
}
.app-nav a:hover, .app-nav a.active {
    background: var(--color-primary-light);
    color: var(--color-primary-dark);
    text-decoration: none;
    border-left-color: var(--color-primary);
}

.nav-backdrop {
    position: fixed;
    inset: 0;
    z-index: 50;
    background: rgba(15, 17, 33, 0.45);
    backdrop-filter: blur(1px);
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s ease;
}
.nav-backdrop.open { opacity: 1; pointer-events: auto; }

.notif-wrap { position: relative; }
.notif-bell {
    position: relative;
    width: var(--touch-target);
    height: var(--touch-target);
    border: none;
    background: none;
    font-size: 19px;
    cursor: pointer;
    border-radius: var(--radius-sm);
}
.notif-bell:hover { background: var(--color-bg-alt); }
.notif-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    background: var(--color-danger);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    line-height: 1;
    padding: 3px 5px;
    border-radius: 999px;
    box-shadow: 0 0 0 2px var(--color-surface);
}
.notif-dropdown {
    position: absolute;
    right: 0;
    top: calc(var(--touch-target) + 8px);
    width: min(320px, 88vw);
    max-height: 60vh;
    overflow-y: auto;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    z-index: 55;
}
.notif-item { padding: 12px 14px; border-bottom: 1px solid var(--color-border); font-size: 13.5px; cursor: pointer; }
.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: var(--color-bg-alt); }
.notif-item.unread { background: var(--color-info-bg); font-weight: 600; }
.notif-empty { padding: 20px 16px; color: var(--color-text-muted); font-size: 13px; text-align: center; }

.app-main { padding: 20px 16px 40px; max-width: 1200px; margin: 0 auto; }

/* ---------------------------------------------------------------- Cards / lists */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
}
.filter-bar { display: flex; flex-direction: column; gap: 10px; margin-bottom: 18px; }
.filter-bar .filter-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.filter-bar select, .filter-bar input { margin-bottom: 0; flex: 1 1 140px; }

/* ---------------------------------------------------------------- KPI stat cards */
.stat-cards {
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
    margin-bottom: 22px;
}
.stat-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 18px;
    display: flex;
    align-items: center;
    gap: 14px;
    box-shadow: var(--shadow-sm);
    transition: transform .15s ease, box-shadow .15s ease;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-card-icon {
    width: 48px;
    height: 48px;
    border-radius: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 19px;
    flex-shrink: 0;
}
.stat-card-icon.icon-primary { background: var(--color-primary-light); color: var(--color-primary-dark); }
.stat-card-icon.icon-success { background: var(--color-success-bg); color: var(--color-success); }
.stat-card-icon.icon-warning { background: var(--color-warning-bg); color: var(--color-warning); }
.stat-card-icon.icon-danger  { background: var(--color-danger-bg); color: var(--color-danger); }
.stat-card-icon.icon-info    { background: var(--color-info-bg); color: var(--color-info); }
.stat-card-body { min-width: 0; }
.stat-card-value { font-size: 1.5rem; font-weight: 800; line-height: 1.1; letter-spacing: -0.02em; }
.stat-card-label { font-size: 12.5px; color: var(--color-text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; margin-top: 3px; }

@media (min-width: 640px) {
    .stat-cards { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 1024px) {
    .stat-cards { grid-template-columns: repeat(4, 1fr); }
}

/* Icon accents used throughout the app */
.nav-icon { width: 18px; text-align: center; margin-right: 10px; opacity: .85; }
.btn i, .btn .fa-solid, .btn .fas { margin-right: 2px; }
.search-wrap { position: relative; }
.search-wrap .search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--color-text-faint);
    pointer-events: none;
}
.search-wrap input[data-staff-search] { padding-left: 40px; }
.badge i { margin-right: 5px; }

.data-list { display: flex; flex-direction: column; gap: 12px; }
.data-row {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 14px 16px;
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    box-shadow: var(--shadow-xs);
    transition: box-shadow .15s ease, border-color .15s ease;
}
.data-row:hover { box-shadow: var(--shadow-sm); border-color: var(--color-border-strong); }
.data-row .field { display: flex; justify-content: space-between; align-items: center; font-size: 14px; gap: 10px; }
.data-row .field .field-label { color: var(--color-text-muted); font-weight: 600; font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.03em; }
.data-row a.row-link { font-weight: 700; }

.data-table { display: none; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; letter-spacing: 0.01em; }
.badge-on-time { background: var(--color-success-bg); color: var(--color-success); }
.badge-late { background: var(--color-warning-bg); color: var(--color-warning); }
.badge-left-early { background: var(--color-warning-bg); color: var(--color-warning); }
.badge-absent { background: var(--color-danger-bg); color: var(--color-danger); }
.badge-no-clockout { background: var(--color-danger-bg); color: var(--color-danger); }
.badge-holiday { background: var(--color-info-bg); color: var(--color-info); }
.badge-on-leave { background: var(--color-primary-light); color: var(--color-primary-dark); }
.badge-info { background: var(--color-info-bg); color: var(--color-info); }

.alert { padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 14px; font-size: 14px; font-weight: 500; }
.alert-error { background: var(--color-danger-bg); color: var(--color-danger); }
.alert-success { background: var(--color-success-bg); color: var(--color-success); }
.alert-info { background: var(--color-info-bg); color: var(--color-info); }

/* Toggle switch — pure CSS */
.toggle-switch { position: relative; display: inline-block; width: 48px; height: 28px; flex-shrink: 0; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
    position: absolute; cursor: pointer; inset: 0;
    background: var(--color-border-strong); border-radius: 999px; transition: .2s;
}
.toggle-slider::before {
    content: ""; position: absolute; height: 22px; width: 22px; left: 3px; top: 3px;
    background: #fff; border-radius: 50%; transition: .2s; box-shadow: var(--shadow-xs);
}
.toggle-switch input:checked + .toggle-slider { background: var(--color-primary); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(20px); }

/* Search dropdown */
.search-wrap { position: relative; margin-bottom: 16px; }
.search-results {
    position: absolute; top: 100%; left: 0; right: 0; margin-top: 4px;
    background: var(--color-surface); border: 1px solid var(--color-border);
    border-radius: var(--radius); max-height: 300px; overflow-y: auto; z-index: 25;
    box-shadow: var(--shadow-md);
}
.search-result-item { padding: 11px 14px; border-bottom: 1px solid var(--color-border); cursor: pointer; font-size: 14px; }
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--color-primary-light); }

.donut-wrap { display: flex; flex-wrap: wrap; gap: 28px; }
.donut-chart { text-align: center; }
.donut-label { font-size: 13px; color: var(--color-text-muted); margin-top: 8px; font-weight: 600; }

.pagination { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 18px; }

/* Raw device event viewer */
.event-thumb { width: 56px; height: 56px; object-fit: cover; border-radius: var(--radius-sm); border: 1px solid var(--color-border); cursor: zoom-in; display: block; }
.field-empty { color: var(--color-text-faint); }
.event-field { font-size: 13px; }
.event-field strong { color: var(--color-text-muted); font-weight: 600; }
.event-raw { white-space: pre-wrap; word-break: break-all; max-width: 100%; max-height: 240px; overflow-y: auto; background: var(--color-bg-alt); border: 1px solid var(--color-border); border-radius: var(--radius-sm); padding: 10px; font-size: 11px; color: var(--color-text-muted); margin-top: 8px; }
details summary { cursor: pointer; color: var(--color-primary); font-size: 13px; font-weight: 600; }

/* Tablet+ */
@media (min-width: 768px) {
    .header-username { display: inline; }
    .hamburger { display: none; }
    .nav-backdrop { display: none; }
    .app-nav {
        position: static;
        transform: none;
        width: auto;
        flex-direction: row;
        flex-wrap: wrap;
        padding: 0;
        box-shadow: none;
        border-bottom: 1px solid var(--color-border);
        background: var(--color-surface);
        overflow: visible;
    }
    .app-nav a { border-left: none; border-bottom: 3px solid transparent; padding: 14px 16px; }
    .app-nav a:hover, .app-nav a.active { border-left-color: transparent; border-bottom-color: var(--color-primary); background: transparent; }
    .filter-bar .filter-row { flex-wrap: nowrap; }
}

/* Desktop — tables replace stacked cards */
@media (min-width: 1024px) {
    .data-list { display: none; }
    .data-table { display: table; width: 100%; border-collapse: collapse; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm); }
    .data-table th, .data-table td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--color-border); font-size: 14px; }
    .data-table tbody tr { transition: background-color .12s ease; }
    .data-table tbody tr:hover { background: var(--color-bg-alt); }
    .data-table tbody tr:last-child td { border-bottom: none; }
    .data-table th { background: var(--color-bg-alt); font-weight: 700; color: var(--color-text-muted); font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.03em; }
}
