/* ============================================
   DESIGN TOKENS
   ============================================ */
:root {
    --color-primary: #2563eb;
    --color-primary-dark: #1d4ed8;
    --color-primary-light: #dbeafe;

    --color-success: #16a34a;
    --color-success-light: #dcfce7;
    --color-warning: #d97706;
    --color-warning-light: #fef3c7;
    --color-danger: #dc2626;
    --color-danger-light: #fee2e2;
    --color-info: #3b82f6;
    --color-info-light: #dbeafe;
    --color-neutral: #64748b;
    --color-neutral-light: #f1f5f9;

    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;

    --bg-page: #f8fafc;
    --bg-card: #ffffff;
    --border-color: #e2e8f0;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;

    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
    --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
    --shadow-lg: 0 10px 30px rgba(15, 23, 42, 0.12);

    --sidebar-width: 240px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-page);
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.5;
}

a { color: var(--color-primary); text-decoration: none; }
.text-muted { color: var(--text-muted); }
.text-right { text-align: right; }

/* ============================================
   LAYOUT: SIDEBAR + MAIN CONTENT
   ============================================ */
.app-layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    background: #0f172a;
    color: #e2e8f0;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
}

.sidebar-brand {
    padding: 24px 20px;
    font-size: 18px;
    font-weight: 700;
    color: #fff;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-nav { flex: 1; padding: 16px 0; overflow-y: auto; }

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    color: #cbd5e1;
    font-size: 14px;
    border-left: 3px solid transparent;
    transition: background 0.15s;
}
.sidebar-nav a:hover { background: rgba(255,255,255,0.05); color: #fff; }
.sidebar-nav a.active {
    background: rgba(37, 99, 235, 0.15);
    border-left-color: var(--color-primary);
    color: #fff;
    font-weight: 600;
}

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid rgba(255,255,255,0.08);
    font-size: 13px;
}
.sidebar-footer .btn-logout {
    display: block;
    text-align: center;
    padding: 8px;
    background: rgba(220, 38, 38, 0.15);
    color: #fca5a5;
    border-radius: var(--radius-sm);
    margin-top: 8px;
}

.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    padding: 28px 32px;
    width: calc(100% - var(--sidebar-width));
}

.topbar-mobile {
    display: none;
    align-items: center;
    justify-content: space-between;
    background: #0f172a;
    color: #fff;
    padding: 14px 16px;
    position: sticky;
    top: 0;
    z-index: 90;
}
.topbar-mobile button {
    background: none; border: none; color: #fff; font-size: 22px; cursor: pointer;
}

/* ============================================
   PAGE HEADER
   ============================================ */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 24px;
}
.page-header h1 { font-size: 22px; font-weight: 700; margin: 0; }
.header-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ============================================
   WIDGET CARDS (Dashboard)
   ============================================ */
.widget-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    margin-bottom: 24px;
}
.widget-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 24px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}
.widget-icon {
    width: 52px; height: 52px;
    border-radius: var(--radius-md);
    display: flex; align-items: center; justify-content: center;
    font-size: 24px;
    flex-shrink: 0;
}
.widget-blue .widget-icon   { background: var(--color-info-light); }
.widget-purple .widget-icon { background: #ede9fe; }
.widget-green .widget-icon  { background: var(--color-success-light); }
.widget-value { font-size: 26px; font-weight: 700; line-height: 1.2; }
.widget-label { color: var(--text-secondary); font-size: 13px; }

.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.live-dot {
    display: inline-block;
    width: 8px; height: 8px;
    background: var(--color-success);
    border-radius: 50%;
    margin-left: 6px;
    animation: pulse 1.5s infinite;
}
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* ============================================
   CARD (generic container)
   ============================================ */
.card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}
.card h3 { margin: 0 0 16px 0; font-size: 15px; font-weight: 600; }

/* ============================================
   FORMS & FILTER BAR
   ============================================ */
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text-secondary);
}
input[type="text"], input[type="date"], input[type="password"],
input[type="file"], select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 14px;
    background: #fff;
    color: var(--text-primary);
    font-family: inherit;
}
input:focus, select:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-light);
}

.filter-bar, .search-bar {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    flex-wrap: wrap;
    background: var(--bg-card);
    padding: 16px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    margin-bottom: 20px;
}
.filter-bar .form-group, .search-bar input { margin-bottom: 0; min-width: 160px; }
.search-bar { display: flex; }
.search-bar input { flex: 1; }

.export-bar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }

/* ============================================
   BUTTONS
   ============================================ */
button, .btn-primary, .btn-secondary {
    cursor: pointer;
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    border-radius: var(--radius-sm);
    border: none;
    padding: 10px 18px;
    transition: transform 0.05s, opacity 0.15s;
}
button:active { transform: scale(0.98); }

.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-block { width: 100%; }

.btn-secondary {
    background: #fff;
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}
.btn-secondary:hover { background: var(--color-neutral-light); }

.btn-icon {
    background: none;
    border: none;
    font-size: 16px;
    padding: 6px 8px;
    border-radius: var(--radius-sm);
}
.btn-icon:hover { background: var(--color-neutral-light); }
.btn-danger:hover { background: var(--color-danger-light); }

/* ============================================
   TABLES
   ============================================ */
.table-responsive { overflow-x: auto; border-radius: var(--radius-md); border: 1px solid var(--border-color); }
table.table-data, table.table-log { width: 100%; border-collapse: collapse; background: #fff; min-width: 600px; }
table.table-data th, table.table-log th {
    background: var(--color-neutral-light);
    text-align: left;
    padding: 12px 16px;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-secondary);
    white-space: nowrap;
}
table.table-data td, table.table-log td {
    padding: 12px 16px;
    border-top: 1px solid var(--border-color);
    font-size: 14px;
}
table.table-data tbody tr:hover, table.table-log tbody tr:hover { background: #fafbfc; }
.empty-state { text-align: center; padding: 32px !important; color: var(--text-muted); }

/* ============================================
   STATUS BADGES & PILLS
   ============================================ */
.badge-status {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}
.badge-hadir { background: var(--color-success-light); color: var(--color-success); }
.badge-sakit { background: var(--color-warning-light); color: var(--color-warning); }
.badge-izin  { background: var(--color-info-light); color: var(--color-info); }
.badge-alpha, .badge-bolos { background: var(--color-danger-light); color: var(--color-danger); }

.badge-active { background: var(--color-success-light); color: var(--color-success); padding: 4px 10px; border-radius: 999px; font-size: 12px; }
.badge-inactive { background: var(--color-neutral-light); color: var(--text-muted); padding: 4px 10px; border-radius: 999px; font-size: 12px; }

/* Radio pill untuk absensi manual (toggle status) */
.status-toggle-group { display: flex; gap: 6px; flex-wrap: wrap; }
.status-pill {
    position: relative;
    padding: 6px 12px;
    border-radius: 999px;
    border: 1.5px solid var(--border-color);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.15s;
}
.status-pill input { position: absolute; opacity: 0; width: 0; height: 0; }
.status-pill:has(input:checked).status-hadir { background: var(--color-success); border-color: var(--color-success); color: #fff; }
.status-pill:has(input:checked).status-sakit { background: var(--color-warning); border-color: var(--color-warning); color: #fff; }
.status-pill:has(input:checked).status-izin  { background: var(--color-info); border-color: var(--color-info); color: #fff; }
.status-pill:has(input:checked).status-alpha,
.status-pill:has(input:checked).status-bolos { background: var(--color-danger); border-color: var(--color-danger); color: #fff; }

.input-keterangan { margin-top: 4px; min-width: 180px; }

/* ============================================
   ALERTS
   ============================================ */
.alert {
    padding: 14px 16px;
    border-radius: var(--radius-md);
    margin-bottom: 18px;
    font-size: 14px;
}
.alert-success { background: var(--color-success-light); color: #15803d; border: 1px solid #86efac; }
.alert-error   { background: var(--color-danger-light); color: #b91c1c; border: 1px solid #fca5a5; }
.alert-warning { background: var(--color-warning-light); color: #b45309; border: 1px solid #fcd34d; }

.error-list {
    background: var(--color-danger-light);
    padding: 12px 16px;
    border-radius: var(--radius-md);
    margin-bottom: 16px;
    font-size: 13px;
}
.error-list ul { margin: 8px 0 0 0; padding-left: 20px; max-height: 200px; overflow-y: auto; }

/* ============================================
   MODAL
   ============================================ */
.modal {
    display: none;
    position: fixed; inset: 0;
    background: rgba(15, 23, 42, 0.5);
    z-index: 200;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.modal.active { display: flex; }
.modal-content {
    background: #fff;
    border-radius: var(--radius-lg);
    padding: 24px;
    width: 100%;
    max-width: 440px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}
.modal-content h3 { margin-top: 0; }
.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
}
.modal-actions button[type="button"] {
    background: none; border: 1px solid var(--border-color); color: var(--text-secondary);
}

/* ============================================
   AUTH PAGE (Login)
   ============================================ */
.auth-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1e293b, #2563eb);
    padding: 20px;
}
.auth-card {
    background: #fff;
    border-radius: var(--radius-lg);
    padding: 36px 32px;
    width: 100%;
    max-width: 380px;
    box-shadow: var(--shadow-lg);
}
.auth-brand { text-align: center; margin-bottom: 24px; }
.auth-logo { font-size: 40px; margin-bottom: 8px; }
.auth-brand h1 { font-size: 20px; margin: 0 0 4px 0; }

.password-field { position: relative; }
.toggle-password {
    position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
    background: none; border: none; padding: 4px; font-size: 14px;
}
.captcha-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.captcha-row img { border-radius: var(--radius-sm); border: 1px solid var(--border-color); }
.btn-refresh-captcha { background: var(--color-neutral-light); border: 1px solid var(--border-color); border-radius: var(--radius-sm); padding: 8px 10px; }

/* ============================================
   RESPONSIVE — Tablet & Smartphone
   ============================================ */
@media (max-width: 900px) {
    .widget-grid { grid-template-columns: 1fr 1fr; }
    .dashboard-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        width: 250px;
    }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; width: 100%; padding: 20px 16px; }
    .topbar-mobile { display: flex; }
    .widget-grid { grid-template-columns: 1fr; }
    .page-header h1 { font-size: 19px; }
    .filter-bar, .search-bar { flex-direction: column; align-items: stretch; }
    .filter-bar .form-group, .search-bar input { min-width: 0; }
}

@media (max-width: 480px) {
    .widget-card { padding: 16px; }
    .widget-value { font-size: 22px; }
    .modal-content { padding: 18px; }
}

/* Overlay saat sidebar mobile terbuka, klik di luar untuk menutup */
.sidebar-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 95;
}
.sidebar-overlay.active { display: block; }
