/* =========================================================
   ABSENSI QR - Design System
   Mobile-first, PWA app-like feel, gradient accent theme
   ========================================================= */

:root {
    --primary: #4f46e5;
    --primary-dark: #3730a3;
    --primary-light: #818cf8;
    --gradient: linear-gradient(135deg, #4f46e5 0%, #7c3aed 50%, #a855f7 100%);
    --gradient-soft: linear-gradient(135deg, #eef2ff 0%, #f5f3ff 100%);
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;
    --purple: #a855f7;

    --bg: #f4f5fb;
    --surface: #ffffff;
    --surface-alt: #f8f9fd;
    --border: #e5e7f0;
    --text: #1e1f36;
    --text-muted: #6b7189;
    --text-soft: #9498ab;

    --radius: 16px;
    --radius-sm: 10px;
    --radius-lg: 22px;
    --shadow-sm: 0 1px 3px rgba(30, 31, 54, 0.06), 0 1px 2px rgba(30, 31, 54, 0.04);
    --shadow-md: 0 4px 16px rgba(30, 31, 54, 0.08);
    --shadow-lg: 0 12px 32px rgba(79, 70, 229, 0.14);
    --topbar-h: 60px;
    --bottomnav-h: 66px;
    --sidebar-w: 250px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #14151f;
        --surface: #1c1d2b;
        --surface-alt: #23243590;
        --border: #2c2d40;
        --text: #f1f2fb;
        --text-muted: #a3a6bd;
        --text-soft: #6f7288;
        --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
        --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.35);
    }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior-y: contain;
}
a { color: inherit; text-decoration: none; }
img { max-width: 100%; }
button { font-family: inherit; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }

/* ---------------- Layout: App Shell ---------------- */
.app-shell { display: flex; min-height: 100vh; }
.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.app-content {
    flex: 1;
    padding: 20px;
    max-width: 1100px;
    width: 100%;
    margin: 0 auto;
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
}

/* ---------------- Sidebar (Admin) ---------------- */
.sidebar {
    width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    transition: transform .25s ease;
}
.sidebar-brand {
    display: flex; align-items: center; gap: 10px;
    padding: 18px 20px;
    border-bottom: 1px solid var(--border);
}
.sidebar-brand .logo-badge {
    width: 40px; height: 40px; border-radius: 12px;
    background: var(--gradient);
    display: flex; align-items: center; justify-content: center;
    font-size: 20px; color: white; flex-shrink: 0;
    box-shadow: var(--shadow-md);
}
.sidebar-brand strong { font-size: 15px; display: block; line-height: 1.2; }
.sidebar-brand span { font-size: 11px; color: var(--text-muted); }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 14px 12px; }
.sidebar-nav .nav-label {
    font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
    color: var(--text-soft); padding: 12px 12px 6px;
    font-weight: 600;
}
.sidebar-nav a {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 12px; border-radius: var(--radius-sm);
    color: var(--text-muted); font-size: 14px; font-weight: 500;
    margin-bottom: 2px; transition: background .15s, color .15s;
}
.sidebar-nav a .ic { font-size: 17px; width: 22px; text-align: center; }
.sidebar-nav a:hover { background: var(--surface-alt); color: var(--text); }
.sidebar-nav a.active {
    background: var(--gradient); color: #fff;
    box-shadow: var(--shadow-md);
}
.sidebar-footer { padding: 14px; border-top: 1px solid var(--border); }

.app-main.with-sidebar { margin-left: var(--sidebar-w); }

.sidebar-overlay {
    display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 99;
}
.menu-toggle { display: none; }

@media (max-width: 900px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .app-main.with-sidebar { margin-left: 0; }
    .sidebar-overlay.open { display: block; }
    .menu-toggle { display: inline-flex; }
}

/* ---------------- Topbar ---------------- */
.topbar {
    height: var(--topbar-h);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 18px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 40;
    padding-top: env(safe-area-inset-top);
}
.topbar-title { font-size: 16px; font-weight: 700; }
.topbar-left { display: flex; align-items: center; gap: 12px; }
.icon-btn {
    width: 38px; height: 38px; border-radius: 10px;
    border: 1px solid var(--border); background: var(--surface);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; font-size: 16px; color: var(--text);
}
.avatar-chip {
    display: flex; align-items: center; gap: 8px;
    padding: 4px 10px 4px 4px; border-radius: 999px;
    background: var(--surface-alt); cursor: pointer;
    border: 1px solid var(--border);
}
.avatar-circle {
    width: 30px; height: 30px; border-radius: 50%;
    background: var(--gradient); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 700;
}

/* ---------------- Guru mobile app shell ---------------- */
.guru-shell { max-width: 480px; margin: 0 auto; min-height: 100vh; position: relative; background: var(--bg); }
.guru-header {
    background: var(--gradient);
    color: #fff;
    padding: calc(18px + env(safe-area-inset-top)) 20px 22px;
    border-radius: 0 0 26px 26px;
    box-shadow: var(--shadow-lg);
    position: relative;
    overflow: hidden;
}
.guru-header::before {
    content: ''; position: absolute; width: 200px; height: 200px;
    background: rgba(255,255,255,.08); border-radius: 50%;
    top: -100px; right: -60px;
}
.guru-header::after {
    content: ''; position: absolute; width: 140px; height: 140px;
    background: rgba(255,255,255,.06); border-radius: 50%;
    bottom: -80px; left: -40px;
}
.guru-header-top { display: flex; justify-content: space-between; align-items: center; position: relative; z-index: 1; }
.guru-greeting { font-size: 13px; opacity: .85; }
.guru-name { font-size: 19px; font-weight: 700; margin-top: 2px; }
.guru-content { padding: 18px 16px calc(90px + env(safe-area-inset-bottom)); }

.bottom-nav {
    position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
    width: 100%; max-width: 480px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: flex; justify-content: space-around; align-items: center;
    height: var(--bottomnav-h);
    padding-bottom: env(safe-area-inset-bottom);
    box-shadow: 0 -4px 20px rgba(0,0,0,.06);
    z-index: 50;
}
.bottom-nav a {
    display: flex; flex-direction: column; align-items: center; gap: 3px;
    color: var(--text-soft); font-size: 11px; font-weight: 600;
    flex: 1; padding: 6px 0;
}
.bottom-nav a .ic { font-size: 21px; }
.bottom-nav a.active { color: var(--primary); }
.bottom-nav a.scan-fab {
    position: relative; top: -22px;
}
.bottom-nav a.scan-fab .ic-wrap {
    width: 52px; height: 52px; border-radius: 50%;
    background: var(--gradient); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 24px; box-shadow: var(--shadow-lg);
    border: 4px solid var(--surface);
}

/* ---------------- Cards ---------------- */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    padding: 18px;
}
.card + .card { margin-top: 16px; }
.card-title { font-size: 15px; font-weight: 700; margin: 0 0 12px; display: flex; align-items: center; gap: 8px; }

.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 640px) { .stat-grid { grid-template-columns: repeat(4, 1fr); } }
.stat-card {
    background: var(--surface); border-radius: var(--radius);
    border: 1px solid var(--border); padding: 16px;
    box-shadow: var(--shadow-sm);
}
.stat-card .stat-ic {
    width: 38px; height: 38px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px; margin-bottom: 10px;
}
.stat-card .stat-val { font-size: 24px; font-weight: 800; line-height: 1; }
.stat-card .stat-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.gradient-card {
    background: var(--gradient); color: #fff; border-radius: var(--radius-lg);
    padding: 20px; box-shadow: var(--shadow-lg); position: relative; overflow: hidden;
}

/* ---------------- Buttons ---------------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 11px 18px; border-radius: var(--radius-sm);
    border: none; font-size: 14px; font-weight: 600; cursor: pointer;
    transition: transform .12s ease, box-shadow .12s ease, opacity .12s ease;
    text-align: center; white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--gradient); color: #fff; box-shadow: var(--shadow-md); }
.btn-outline { background: transparent; color: var(--primary); border: 1.5px solid var(--primary); }
.btn-secondary { background: var(--surface-alt); color: var(--text); border: 1px solid var(--border); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-block { width: 100%; }
.btn-sm { padding: 7px 12px; font-size: 12.5px; }
.btn-icon { width: 38px; height: 38px; padding: 0; border-radius: 10px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ---------------- Forms ---------------- */
.form-group { margin-bottom: 16px; }
label.form-label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text); }
.form-control, select.form-control, textarea.form-control {
    width: 100%; padding: 11px 14px; border-radius: var(--radius-sm);
    border: 1.5px solid var(--border); background: var(--surface);
    font-size: 14.5px; color: var(--text); transition: border-color .15s;
}
.form-control:focus { outline: none; border-color: var(--primary); }
.input-icon-wrap { position: relative; }
.input-icon-wrap .form-control { padding-left: 42px; }
.input-icon-wrap .field-ic { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--text-soft); }

/* ---------------- Table ---------------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }
table.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; background: var(--surface); }
table.data-table th {
    background: var(--surface-alt); text-align: left; padding: 12px 14px;
    font-weight: 700; color: var(--text-muted); white-space: nowrap;
    border-bottom: 1px solid var(--border);
}
table.data-table td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data-table tr:last-child td { border-bottom: none; }
table.data-table tr:hover td { background: var(--surface-alt); }

/* ---------------- Badges ---------------- */
.badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 4px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 700;
}
.badge-success { background: #d1fae5; color: #065f46; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-info { background: #dbeafe; color: #1e40af; }
.badge-purple { background: #f3e8ff; color: #6b21a8; }
.badge-secondary { background: var(--surface-alt); color: var(--text-muted); }
@media (prefers-color-scheme: dark) {
    .badge-success { background: #06402730; color: #34d399; }
    .badge-warning { background: #45340730; color: #fbbf24; }
    .badge-danger { background: #45191930; color: #f87171; }
    .badge-info { background: #1e3a5f30; color: #60a5fa; }
    .badge-purple { background: #3b174f30; color: #d8b4fe; }
}

/* ---------------- Modal ---------------- */
.modal-backdrop {
    position: fixed; inset: 0; background: rgba(15,15,25,.5);
    display: none; align-items: flex-end; justify-content: center;
    z-index: 200; backdrop-filter: blur(2px);
}
.modal-backdrop.open { display: flex; }
@media (min-width: 640px) { .modal-backdrop { align-items: center; } }
.modal-box {
    background: var(--surface); border-radius: 20px 20px 0 0;
    width: 100%; max-width: 480px; max-height: 88vh; overflow-y: auto;
    padding: 22px; box-shadow: var(--shadow-lg);
    animation: slideUp .22s ease;
}
@media (min-width: 640px) { .modal-box { border-radius: var(--radius-lg); } }
@keyframes slideUp { from { transform: translateY(30px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal-header h3 { margin: 0; font-size: 17px; }

/* ---------------- Login page ---------------- */
.login-wrap {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: var(--gradient); padding: 20px; position: relative; overflow: hidden;
}
.login-wrap::before, .login-wrap::after {
    content: ''; position: absolute; border-radius: 50%; background: rgba(255,255,255,.08);
}
.login-wrap::before { width: 320px; height: 320px; top: -120px; left: -100px; }
.login-wrap::after { width: 260px; height: 260px; bottom: -100px; right: -80px; }
.login-card {
    background: var(--surface); border-radius: 24px; padding: 32px 26px;
    width: 100%; max-width: 380px; box-shadow: 0 24px 60px rgba(0,0,0,.25);
    position: relative; z-index: 1;
}
.login-logo {
    width: 64px; height: 64px; border-radius: 18px; background: var(--gradient);
    display: flex; align-items: center; justify-content: center; font-size: 30px; color: #fff;
    margin: 0 auto 16px; box-shadow: var(--shadow-lg);
}
.login-tabs { display: flex; background: var(--surface-alt); border-radius: 12px; padding: 4px; margin-bottom: 22px; }
.login-tabs a {
    flex: 1; text-align: center; padding: 9px; border-radius: 9px; font-size: 13.5px; font-weight: 600;
    color: var(--text-muted);
}
.login-tabs a.active { background: var(--surface); color: var(--primary); box-shadow: var(--shadow-sm); }

/* ---------------- Scanner page ---------------- */
#qr-reader { border-radius: var(--radius-lg) !important; overflow: hidden; border: none !important; }
#qr-reader video { border-radius: var(--radius-lg); }
.scan-frame-wrap { position: relative; border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow-lg); }
.scan-result-toast {
    position: fixed; top: calc(16px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%) translateY(-30px);
    background: var(--success); color: #fff; padding: 12px 20px; border-radius: 999px;
    font-weight: 700; font-size: 14px; box-shadow: var(--shadow-lg); z-index: 300;
    transition: transform .3s ease, opacity .3s ease, visibility .3s; display: flex; align-items: center; gap: 8px;
    max-width: 90vw; opacity: 0; visibility: hidden; pointer-events: none;
}
.scan-result-toast.show { transform: translateX(-50%) translateY(0); opacity: 1; visibility: visible; }
.scan-result-toast.err { background: var(--danger); }

.scan-list-item {
    display: flex; align-items: center; gap: 10px; padding: 10px 0;
    border-bottom: 1px solid var(--border);
}
.scan-list-item:last-child { border-bottom: none; }
.scan-list-item .num-circle {
    width: 32px; height: 32px; border-radius: 50%; background: var(--gradient-soft); color: var(--primary);
    display: flex; align-items: center; justify-content: center; font-size: 12.5px; font-weight: 700; flex-shrink: 0;
}

/* ---------------- Utility ---------------- */
.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.gap-8 { gap: 8px; } .gap-12 { gap: 12px; } .gap-16 { gap: 16px; }
.mt-8{margin-top:8px;} .mt-12{margin-top:12px;} .mt-16{margin-top:16px;} .mt-24{margin-top:24px;}
.mb-8{margin-bottom:8px;} .mb-12{margin-bottom:12px;} .mb-16{margin-bottom:16px;}
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 12.5px; }
.text-center { text-align: center; }
.w-full { width: 100%; }
.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); }
.empty-state .ic { font-size: 42px; margin-bottom: 10px; opacity: .5; }
.toast-container { position: fixed; top: calc(14px + env(safe-area-inset-top)); right: 14px; z-index: 500; display: flex; flex-direction: column; gap: 8px; }
.toast {
    background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-lg);
    border-radius: 12px; padding: 12px 16px; font-size: 13.5px; font-weight: 600;
    display: flex; align-items: center; gap: 10px; min-width: 220px;
    animation: slideIn .2s ease;
}
@keyframes slideIn { from { opacity: 0; transform: translateX(20px);} to { opacity: 1; transform: translateX(0);} }
.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }

.install-banner {
    position: fixed; bottom: 14px; left: 14px; right: 14px; max-width: 460px; margin: 0 auto;
    background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg); border: 1px solid var(--border);
    padding: 14px 16px; display: flex; align-items: center; gap: 12px; z-index: 400;
}

.chip-select { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-select label {
    padding: 8px 14px; border-radius: 999px; border: 1.5px solid var(--border);
    font-size: 13px; font-weight: 600; cursor: pointer; color: var(--text-muted);
}
.chip-select input { display: none; }
.chip-select input:checked + span { color: #fff; }
.chip-select label:has(input:checked) { background: var(--gradient); border-color: transparent; color: #fff; }

.print-only { display: none; }
@media print {
    .no-print { display: none !important; }
    .print-only { display: block !important; }
    body { background: #fff; }
}
