@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* =====================
   VARIABLES
===================== */
:root {
    --primary:        #4f46e5;
    --primary-d:      #4338ca;
    --primary-light:  #eef2ff;
    --success:        #059669;
    --success-light:  #d1fae5;
    --danger:         #dc2626;
    --danger-light:   #fee2e2;
    --warning:        #d97706;
    --warning-light:  #fef3c7;
    --info:           #0284c7;
    --info-light:     #e0f2fe;

    --bg:       #f8fafc;
    --white:    #ffffff;
    --shadow:   0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
    --shadow-md:0 4px 16px rgba(0,0,0,.1);

    --gray-50:  #f8fafc;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-500: #64748b;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-800: #1e293b;
    --gray-900: #0f172a;

    --sidebar-bg:     #1e1b4b;
    --sidebar-hover:  rgba(255,255,255,.07);
    --sidebar-active: rgba(99,102,241,.25);
    --sidebar-text:   rgba(255,255,255,.65);
    --sidebar-width:  240px;

    --radius-sm: 6px;
    --radius:    10px;
    --radius-lg: 14px;
}

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

body {
    font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--gray-900);
    min-height: 100vh;
    font-size: 14px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

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

/* =====================
   ADMIN LAYOUT — SIDEBAR
===================== */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* --- Sidebar --- */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 200;
}

.sidebar-brand {
    padding: 18px 16px;
    border-bottom: 1px solid rgba(255,255,255,.08);
    display: flex;
    align-items: center;
    gap: 10px;
}
.sidebar-brand .brand-icon {
    width: 34px; height: 34px;
    background: var(--primary);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 17px;
    flex-shrink: 0;
}
.sidebar-brand .brand-name {
    color: white;
    font-weight: 700;
    font-size: 14.5px;
}

.sidebar-nav {
    flex: 1;
    padding: 10px 8px;
    overflow-y: auto;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: 8px;
    color: var(--sidebar-text);
    font-size: 13.5px;
    font-weight: 500;
    transition: background .15s, color .15s;
    margin-bottom: 2px;
    cursor: pointer;
    text-decoration: none;
}
.menu-item:hover { background: var(--sidebar-hover); color: white; text-decoration: none; }
.menu-item.active { background: var(--sidebar-active); color: white; }
.menu-item .menu-icon {
    width: 18px; height: 18px;
    flex-shrink: 0;
}
.menu-item.active .menu-icon { color: #a5b4fc; }

.sidebar-bottom {
    padding: 8px;
    border-top: 1px solid rgba(255,255,255,.08);
}
.sidebar-bottom .user-info {
    padding: 6px 12px 10px;
    font-size: 12px;
    color: rgba(255,255,255,.35);
}
.sidebar-bottom .user-info strong { color: rgba(255,255,255,.6); }
.menu-item.logout { color: #fca5a5; }
.menu-item.logout:hover { background: rgba(239,68,68,.15); color: #fca5a5; }

/* --- Main content --- */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.page-body {
    padding: 24px 28px;
    flex: 1;
}

/* =====================
   LEGACY COMPAT
===================== */
.wrapper { max-width: 480px; margin: 0 auto; padding: 16px; }
.wrapper-wide { max-width: 100%; }

/* =====================
   CARDS
===================== */
.card {
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 20px 24px;
    margin-bottom: 16px;
    border: 1px solid var(--gray-200);
    transition: box-shadow .2s;
}
.card:hover { box-shadow: var(--shadow-md); }

/* Stat cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 14px;
    margin-bottom: 24px;
}
.stat-card {
    background: white;
    border-radius: var(--radius-lg);
    padding: 16px 18px;
    box-shadow: var(--shadow);
    border: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    gap: 14px;
    transition: box-shadow .2s, transform .2s;
}
.stat-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.stat-icon {
    width: 44px; height: 44px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}
.stat-icon.blue   { background: #eef2ff; }
.stat-icon.green  { background: #d1fae5; }
.stat-icon.yellow { background: #fef3c7; }
.stat-icon.red    { background: #fee2e2; }
.stat-icon.gray   { background: var(--gray-100); }
.stat-value { font-size: 26px; font-weight: 700; color: var(--gray-900); line-height: 1; }
.stat-label { font-size: 12px; color: var(--gray-500); margin-top: 3px; }

/* =====================
   TYPOGRAPHY
===================== */
h1 { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
h2 { font-size: 16px; font-weight: 600; margin-bottom: 12px; color: var(--gray-800); }
h3 { font-size: 14px; font-weight: 600; }
.text-muted   { color: var(--gray-500); font-size: 13px; }
.text-danger  { color: var(--danger); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-center  { text-align: center; }

/* =====================
   FORM
===================== */
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--gray-600);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: .3px;
}
.form-control {
    width: 100%;
    padding: 9px 12px;
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: border-color .2s, box-shadow .2s;
    background: var(--white);
    color: var(--gray-900);
}
.form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99,102,241,.12);
}
.form-control::placeholder { color: var(--gray-400); }
select.form-control { cursor: pointer; }

/* =====================
   BUTTONS
===================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 18px;
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    font-weight: 600;
    font-family: inherit;
    border: 1.5px solid transparent;
    cursor: pointer;
    transition: all .15s;
    text-decoration: none;
    white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary  { background: var(--primary);  color: white; border-color: var(--primary); }
.btn-primary:hover  { background: var(--primary-d); border-color: var(--primary-d); color: white; }
.btn-success  { background: var(--success); color: white; border-color: var(--success); }
.btn-success:hover  { background: #047857; color: white; }
.btn-danger   { background: var(--danger);  color: white; border-color: var(--danger); }
.btn-warning  { background: var(--warning); color: white; border-color: var(--warning); }
.btn-outline  { background: transparent; border-color: var(--gray-200); color: var(--gray-600); }
.btn-outline:hover { background: var(--gray-50); border-color: var(--gray-300); color: var(--gray-700); }
.btn-sm  { padding: 5px 12px; font-size: 12.5px; }
.btn-lg  { padding: 13px 28px; font-size: 15px; width: 100%; }

/* =====================
   TABLE
===================== */
.table-wrap { overflow-x: auto; border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
    background: var(--gray-50);
    padding: 10px 14px;
    text-align: left;
    font-size: 11px;
    font-weight: 700;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: .6px;
    border-bottom: 1.5px solid var(--gray-200);
    white-space: nowrap;
}
tbody td { padding: 12px 14px; border-bottom: 1px solid var(--gray-100); vertical-align: middle; }
tbody tr:hover { background: #fafbff; }
tbody tr:last-child td { border-bottom: none; }

/* =====================
   BADGE
===================== */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 3px 10px;
    border-radius: 99px;
    font-size: 11.5px;
    font-weight: 600;
}
.badge-success { background: var(--success-light); color: #065f46; }
.badge-danger  { background: var(--danger-light);  color: #991b1b; }
.badge-warning { background: var(--warning-light); color: #92400e; }
.badge-info    { background: var(--info-light);    color: #075985; }
.badge-gray    { background: var(--gray-100);      color: var(--gray-600); }

/* =====================
   ALERT
===================== */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    margin-bottom: 16px;
    border-left: 3px solid transparent;
}
.alert-danger  { background: var(--danger-light);  border-color: var(--danger);  color: #991b1b; }
.alert-success { background: var(--success-light); border-color: var(--success); color: #065f46; }
.alert-warning { background: var(--warning-light); border-color: var(--warning); color: #92400e; }
.alert-info    { background: var(--info-light);    border-color: var(--info);    color: #075985; }

/* =====================
   STUDENT EXAM UI
===================== */
.exam-header {
    background: linear-gradient(135deg, var(--primary) 0%, #7c3aed 100%);
    color: white;
    padding: 20px;
    border-radius: var(--radius-lg);
    margin-bottom: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    box-shadow: 0 4px 20px rgba(79,70,229,.3);
}
.exam-header .saldo-label { font-size: 11px; opacity: .75; text-transform: uppercase; letter-spacing: .5px; }
.exam-header .saldo-value { font-size: 28px; font-weight: 700; }
.exam-header .timer-box { text-align: right; }
.exam-header .timer-label { font-size: 11px; opacity: .75; text-transform: uppercase; letter-spacing: .5px; }
.exam-header .timer-value {
    font-size: 28px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    font-family: 'Courier New', monospace;
}
.timer-value.danger { color: #fca5a5; }

.scan-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    padding: 16px 0;
}
#qr-reader {
    width: 100%;
    max-width: 300px;
    border-radius: 12px;
    overflow: hidden;
    border: 3px solid var(--primary);
    box-shadow: 0 4px 16px rgba(79,70,229,.2);
}
#qr-reader video { border-radius: 9px; }

.scan-result {
    width: 100%;
    padding: 14px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    display: none;
}
.scan-result.show { display: block; }

.tx-list { list-style: none; }
.tx-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--gray-100);
    font-size: 13px;
}
.tx-item:last-child { border-bottom: none; }
.tx-item .tx-name { color: var(--gray-700); }
.tx-item .tx-amount { font-weight: 700; color: var(--danger); }

/* =====================
   MONITOR GRID
===================== */
.monitor-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 14px;
}
.monitor-card {
    background: white;
    border-radius: var(--radius-lg);
    padding: 16px;
    box-shadow: var(--shadow);
    border: 1px solid var(--gray-200);
    border-left: 4px solid var(--gray-200);
    transition: all .3s;
}
.monitor-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.monitor-card.berjalan  { border-left-color: var(--primary); }
.monitor-card.selesai   { border-left-color: var(--success); }
.monitor-card.timeout   { border-left-color: var(--danger);  }
.monitor-card .mc-name  { font-weight: 700; font-size: 14.5px; color: var(--gray-900); }
.monitor-card .mc-np    { font-size: 12px; color: var(--gray-400); }
.monitor-card .mc-saldo { font-size: 20px; font-weight: 700; margin: 8px 0 4px; }
.monitor-card .mc-timer { font-size: 13px; color: var(--gray-600); font-family: monospace; }
.monitor-card .mc-last  { font-size: 12px; color: var(--gray-400); margin-top: 6px; }

/* =====================
   LOGIN PAGE
===================== */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1e1b4b 0%, var(--primary) 60%, #7c3aed 100%);
    padding: 16px;
    position: relative;
    overflow: hidden;
}
.login-page::before {
    content: '';
    position: absolute;
    width: 500px; height: 500px;
    background: rgba(255,255,255,.04);
    border-radius: 50%;
    top: -200px; right: -100px;
}
.login-page::after {
    content: '';
    position: absolute;
    width: 400px; height: 400px;
    background: rgba(255,255,255,.04);
    border-radius: 50%;
    bottom: -100px; left: -100px;
}
.login-box {
    background: white;
    border-radius: 20px;
    padding: 40px 36px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 24px 80px rgba(0,0,0,.3);
    position: relative;
    z-index: 1;
}
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo .logo-icon {
    width: 56px; height: 56px;
    background: linear-gradient(135deg, var(--primary), #7c3aed);
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
    margin: 0 auto 14px;
    box-shadow: 0 8px 20px rgba(79,70,229,.35);
}
.login-logo h1 { font-size: 20px; color: var(--gray-900); font-weight: 700; }
.login-logo p  { font-size: 13px; color: var(--gray-400); margin-top: 4px; }

/* =====================
   QR PRINT
===================== */
@media print {
    body { background: white; }
    .sidebar, .no-print { display: none !important; }
    .main-content { margin-left: 0 !important; }
    .qr-print-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
    .qr-print-item { text-align: center; page-break-inside: avoid; padding: 12px; border: 1px solid #ddd; border-radius: 8px; }
}

/* =====================
   UTILITIES
===================== */
.flex         { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.flex-center  { display: flex; align-items: center; }
.gap-8  { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.mt-8   { margin-top: 8px; }
.mt-16  { margin-top: 16px; }
.mb-16  { margin-bottom: 16px; }
.w-full { width: 100%; }
.hidden { display: none; }

.spinner {
    display: inline-block;
    width: 16px; height: 16px;
    border: 2px solid rgba(255,255,255,.4);
    border-top-color: white;
    border-radius: 50%;
    animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* =====================
   RESPONSIVE
===================== */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .main-content { margin-left: 0; }
    .page-body { padding: 16px; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
