:root {
    --pmi-red: #d32f2f;
    --pmi-red-dark: #a02622;
    --bg: #f4f5f7;
    --card-bg: #ffffff;
    --text: #24292f;
    --text-muted: #6b7280;
    --border: #e2e5e9;
    --success: #1e7e34;
    --warning: #b45309;
    --danger: #b91c1c;
    --info: #0d6efd;
    --secondary: #6b7280;
    --radius: 8px;
    --transition-fast: 200ms;
    --transition-base: 250ms;
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
}

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

.error-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    gap: 8px;
}
.error-page h1 { font-size: 64px; margin: 0; color: var(--pmi-red); }

/* ---- Layout ---- */
.app-shell { display: flex; min-height: 100vh; }

/* ═══════════════════════════════════════════
   SIDEBAR — Modern SaaS Style
═══════════════════════════════════════════ */
.sidebar {
    width: 256px;
    flex-shrink: 0;
    background: #0f172a;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Brand / Logo */
.sidebar .brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 18px 18px;
    border-bottom: 1px solid rgba(255,255,255,.06);
    flex-shrink: 0;
}
.sidebar .brand-icon {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    background: var(--pmi-red);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.sidebar .brand-icon svg { width: 18px; height: 18px; color: #fff; }
.sidebar .brand-text { min-width: 0; }
.sidebar .brand-text strong { display: block; font-size: 13px; font-weight: 700; color: #f8fafc; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar .brand-text small { display: block; font-size: 11px; color: #64748b; margin-top: 1px; }

/* Scrollable nav area */
.sidebar nav {
    flex: 1;
    overflow-y: auto;
    padding: 12px 0 8px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,.08) transparent;
}
.sidebar nav::-webkit-scrollbar { width: 4px; }
.sidebar nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.1); border-radius: 4px; }

/* Group label */
.sidebar nav .nav-group-label {
    display: block;
    padding: 16px 16px 5px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: #334155;
    pointer-events: none;
}

/* Nav item */
.sidebar nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px 8px 16px;
    margin: 1px 8px;
    border-radius: 7px;
    color: #94a3b8;
    font-size: 13.5px;
    font-weight: 500;
    text-decoration: none;
    transition: background 150ms ease, color 150ms ease;
    position: relative;
}
.sidebar nav a .nav-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    opacity: 0.7;
    transition: opacity 150ms ease;
}
.sidebar nav a:hover {
    background: rgba(255,255,255,.06);
    color: #e2e8f0;
    text-decoration: none;
}
.sidebar nav a:hover .nav-icon { opacity: 1; }
.sidebar nav a.active {
    background: rgba(211,47,47,.15);
    color: #fca5a5;
    text-decoration: none;
}
.sidebar nav a.active .nav-icon { opacity: 1; color: #f87171; }
.sidebar nav a.active::before {
    content: '';
    position: absolute;
    left: -8px;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 60%;
    border-radius: 0 3px 3px 0;
    background: var(--pmi-red);
}

/* Divider */
.sidebar nav .nav-divider {
    border: none;
    border-top: 1px solid rgba(255,255,255,.05);
    margin: 6px 16px;
}

/* User profile di bawah sidebar */
.sidebar-user {
    border-top: 1px solid rgba(255,255,255,.06);
    padding: 12px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}
.sidebar-user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--pmi-red);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
    text-transform: uppercase;
}
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-info strong { display: block; font-size: 12px; font-weight: 600; color: #e2e8f0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-info small { display: block; font-size: 11px; color: #475569; }
.sidebar-user-logout {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: none;
    background: transparent;
    color: #475569;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 150ms ease, color 150ms ease;
    padding: 0;
}
.sidebar-user-logout:hover { background: rgba(255,255,255,.08); color: #e2e8f0; }
.sidebar-user-logout svg { width: 16px; height: 16px; }

.ph-install-btn { display: none; }
.ph-install-btn.show { display: block; }
@media (min-width: 769px) {
    .ph-install-btn.show { display: none; }
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    padding: 12px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.topbar .user-info { display: flex; align-items: center; gap: 12px; }
.topbar form { margin: 0; }

.content { padding: 24px; flex: 1; animation: pageFadeSlide var(--transition-base) ease both; }

@keyframes pageFadeSlide {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

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

.hamburger-btn {
    display: none;
    background: none;
    border: none;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    padding: 4px 8px;
    color: var(--text);
}

.sidebar-backdrop {
    display: none;
}

/* ---- Mobile: menu "smart slide" - sidebar diam di belakang, konten utama digeser + mengecil ---- */
@media (max-width: 768px) {
    .app-shell { display: block; position: relative; overflow-x: hidden; }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        width: 256px;
        z-index: 1;
        overflow-y: auto;
    }

    .main {
        position: relative;
        z-index: 2;
        width: 100%;
        min-height: 100vh;
        background: var(--card-bg, #fff);
        transition: transform .32s cubic-bezier(.4, 0, .2, 1), border-radius .32s ease, box-shadow .32s ease;
        will-change: transform;
    }
    .main.menu-open {
        transform: translateX(228px) scale(.88);
        border-radius: 24px;
        box-shadow: -12px 0 32px rgba(0, 0, 0, .3);
    }

    .sidebar-backdrop.open {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 3;
        background: transparent;
    }

    .hamburger-btn { display: inline-flex; align-items: center; }

    .content { padding: 16px; }

    .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }

    table { display: block; overflow-x: auto; }

    .ph-header { margin: -16px -16px 0; }
}

/* ---- Components ---- */
.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
}

.card-title { margin: 0 0 16px; font-size: 16px; font-weight: 600; }

.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 900px) {
    .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr 1fr; }
}

.stat-tile {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}
.stat-tile .label { color: var(--text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.stat-tile .value { font-size: 28px; font-weight: 700; margin-top: 4px; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { background: #fafafa; font-weight: 600; color: var(--text-muted); text-transform: uppercase; font-size: 11px; letter-spacing: .03em; }
tbody tr:hover { background: #fafafa; }
.table-responsive { overflow-x: auto; }

.btn {
    display: inline-block;
    padding: 8px 16px;
    border-radius: 6px;
    border: 1px solid transparent;
    background: var(--pmi-red);
    color: #fff;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    transition: transform var(--transition-fast) ease, background var(--transition-fast) ease;
}
.btn:hover { background: var(--pmi-red-dark); text-decoration: none; }
.btn:active { transform: scale(0.98); }
.btn-secondary { background: #fff; color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: #f2f2f2; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-success { background: var(--success); }
.btn-danger { background: var(--danger); }

.form-group { margin-bottom: 14px; }
.form-group label { display: block; margin-bottom: 4px; font-weight: 500; font-size: 13px; }
.form-control {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    background: #fff;
    color: var(--text);
}
.form-control:focus { outline: none; border-color: var(--pmi-red); }
.form-row { display: flex; gap: 16px; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: 200px; }
.form-hint { color: var(--text-muted); font-size: 12px; margin-top: 4px; }
.form-error { color: var(--danger); font-size: 12px; margin-top: 4px; }

.badge {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 100px;
    font-size: 11px;
    font-weight: 600;
    color: #fff;
}
.badge-success { background: var(--success); }
.badge-warning { background: var(--warning); }
.badge-danger { background: var(--danger); }
.badge-info { background: var(--info); }
.badge-secondary { background: var(--secondary); }

.alert { padding: 12px 16px; border-radius: 6px; margin-bottom: 16px; font-size: 13px; animation: toastSlideDown var(--transition-base) ease both; }
.alert-error { background: #fdecea; color: #a02622; border: 1px solid #f5c6c2; }
.alert-success { background: #e6f4ea; color: #1e7e34; border: 1px solid #b7dfc0; }

.filter-bar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; align-items: flex-end; }
.filter-bar .form-group { margin-bottom: 0; min-width: 160px; }

.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; flex-wrap: wrap; gap: 10px; }

.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); }

.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, var(--pmi-red), var(--pmi-red-dark));
}
.login-card {
    background: #fff;
    border-radius: var(--radius);
    padding: 32px;
    width: 100%;
    max-width: 360px;
    box-shadow: 0 10px 40px rgba(0,0,0,.2);
}
.login-card h1 { font-size: 18px; margin: 0 0 4px; text-align: center; }
.login-card .subtitle { text-align: center; color: var(--text-muted); margin-bottom: 24px; font-size: 13px; }

.text-muted { color: var(--text-muted); }
.text-right { text-align: right; }
.mb-0 { margin-bottom: 0; }
.d-flex { display: flex; gap: 8px; }

/* ---- Gaya kartu mobile (dipakai di Presensi Mandiri) ---- */
.ph-header {
    background: linear-gradient(to bottom, var(--pmi-red), var(--pmi-red-dark));
    color: #fff;
    padding: 28px 20px 56px;
    border-radius: 0 0 28px 28px;
    margin: -16px -16px 0;
}
.ph-header h1 { font-size: 22px; margin: 4px 0 0; }
.ph-header .subtitle { color: rgba(255,255,255,.8); font-size: 13px; margin: 0; }

.ph-cards { padding: 0; margin: -40px 0 0; display: flex; flex-direction: column; gap: 12px; }

.ph-card {
    background: var(--card-bg);
    border-radius: 20px;
    padding: 18px 20px;
    box-shadow: 0 10px 30px rgba(0,0,0,.08);
    transition: transform var(--transition-fast) ease;
}
.ph-card:hover { transform: scale(1.02); }
.ph-card-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.ph-card-info { display: flex; align-items: center; gap: 10px; }
.ph-card-time { font-size: 26px; font-weight: 700; color: var(--text); margin: 0; }
.ph-card-label { color: var(--text-muted); font-size: 13px; margin: 0; }

.ph-icon-badge {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.ph-icon-badge svg { width: 18px; height: 18px; }
.ph-icon-badge.success { background: #e6f4ea; color: var(--success); }
.ph-icon-badge.warning { background: #fdf1e0; color: var(--warning); }
.ph-icon-badge.danger { background: #fdecea; color: var(--danger); }
.ph-icon-badge.muted { background: #eef0f2; color: var(--text-muted); }

.ph-pill {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 100px;
    font-size: 11px;
    font-weight: 600;
}
.ph-pill.success { background: #e6f4ea; color: var(--success); }
.ph-pill.warning { background: #fdf1e0; color: var(--warning); }
.ph-pill.danger { background: #fdecea; color: var(--danger); }
.ph-pill.muted { background: #eef0f2; color: var(--text-muted); }

.ph-btn {
    display: block;
    width: 100%;
    text-align: center;
    padding: 14px;
    border-radius: 16px;
    border: none;
    background: var(--pmi-red);
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: transform var(--transition-fast) ease, background var(--transition-fast) ease;
}
.ph-btn:hover { background: var(--pmi-red-dark); }
.ph-btn:active:not(:disabled) { transform: scale(0.98); }
.ph-btn:disabled { background: #e2e5e9; color: var(--text-muted); cursor: not-allowed; }
.ph-btn-outline {
    background: #fff;
    color: var(--pmi-red);
    border: 2px solid var(--pmi-red);
}
.ph-btn-outline:hover { background: #fdecea; }

.ph-section-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    margin: 4px 0 12px;
}

.ph-shortcuts {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}
.ph-shortcut {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 12px 6px;
    border-radius: 16px;
    background: var(--card-bg);
    box-shadow: 0 6px 18px rgba(0,0,0,.06);
    color: var(--text);
    text-decoration: none;
    transition: transform var(--transition-fast) ease, background var(--transition-fast) ease;
}
.ph-shortcut:hover { text-decoration: none; background: #fafafa; transform: scale(1.02); }
.ph-shortcut:active { transform: scale(0.98); }
.ph-shortcut span { font-size: 11px; text-align: center; color: var(--text); }

.ph-list-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 0;
    transition: opacity var(--transition-fast) ease;
}
a.ph-list-item:active { opacity: 0.7; }
.ph-list-item + .ph-list-item { border-top: 1px solid var(--border); }
.ph-list-item-body { flex: 1; min-width: 0; }
.ph-list-item-title { margin: 0; color: var(--text); font-size: 14px; }
.ph-list-item-sub { margin: 2px 0 0; color: var(--text-muted); font-size: 12px; }
.ph-list-item-trailing { text-align: right; flex-shrink: 0; }
.ph-list-item-trailing .value { font-weight: 600; color: var(--pmi-red); font-size: 13px; }

/* ---- Bottom navigation (mobile, role pegawai) ---- */
/* display:none sengaja dihapus — critical CSS di <head> yang render nav on first paint */
.bottom-nav { display: none; }

@media (max-width: 768px) {
    body.has-bottom-nav .content { padding: 16px 16px 100px; }

    .bottom-nav {
        display: flex;
        position: fixed;
        bottom: 14px;
        left: 14px;
        right: 14px;
        background: #fff;
        border-radius: 26px;
        box-shadow: 0 10px 32px rgba(0,0,0,.14);
        z-index: 900;
        align-items: center;
        justify-content: space-around;
        padding: 10px 6px calc(10px + env(safe-area-inset-bottom));
    }
    .bottom-nav a {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 3px;
        color: var(--text-muted);
        font-size: 11px;
        flex: 1;
        padding: 4px;
        position: relative;
        transition: transform var(--transition-fast) ease, color var(--transition-fast) ease;
    }
    .bottom-nav a:active { transform: scale(0.95); }
    .bottom-nav a svg { width: 22px; height: 22px; }
    .bottom-nav a.active { color: var(--pmi-red); }

    /* Dot indicator bawah icon — muncul dengan animasi pop */
    .bottom-nav a.active:not(.bottom-nav-main)::after {
        content: '';
        position: absolute;
        bottom: -2px;
        width: 4px;
        height: 4px;
        border-radius: 50%;
        background: var(--pmi-red);
        animation: nav-dot-pop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) both;
    }

    /* Icon aktif: bounce masuk saat halaman load */
    .bottom-nav a.active svg {
        animation: nav-icon-pop 0.38s cubic-bezier(0.34, 1.56, 0.64, 1) both;
    }

    @keyframes nav-icon-pop {
        from { transform: scale(0.65); opacity: 0.4; }
        to   { transform: scale(1);    opacity: 1; }
    }
    @keyframes nav-dot-pop {
        from { transform: scale(0); }
        to   { transform: scale(1); }
    }

    .bottom-nav a.bottom-nav-main {
        margin-top: -30px;
        gap: 3px;
        z-index: 1;
    }
    .bottom-nav a.bottom-nav-main .bottom-nav-main-icon {
        width: 56px;
        height: 56px;
        border-radius: 50%;
        background: var(--pmi-red);
        display: flex;
        align-items: center;
        justify-content: center;
        box-shadow: 0 6px 14px rgba(0,0,0,.2);
        transition: transform var(--transition-fast) ease;
    }
    .bottom-nav a.bottom-nav-main .bottom-nav-main-icon svg { width: 26px; height: 26px; color: #fff; }

    /* Tombol presensi aktif: pop masuk */
    .bottom-nav a.bottom-nav-main.active .bottom-nav-main-icon {
        animation: nav-main-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) both;
    }
    @keyframes nav-main-pop {
        from { transform: scale(0.8); }
        to   { transform: scale(1); }
    }

    .bottom-nav a.bottom-nav-main.is-shutter .bottom-nav-main-icon {
        background: #fff;
        border: 4px solid var(--pmi-red);
        box-shadow: 0 6px 16px rgba(0,0,0,.25);
        animation: shutter-pulse 1.4s ease-in-out infinite;
    }
    .bottom-nav a.bottom-nav-main.is-shutter .bottom-nav-main-icon svg { color: var(--pmi-red); }
    @keyframes shutter-pulse {
        0%, 100% { transform: scale(1); }
        50% { transform: scale(1.08); }
    }
}
