/* =====================================================
   SISTEM INFORMASI ABSENSI SEKOLAH
   Professional Clean Modern UI
   ===================================================== */

:root {
    --primary: #1e3a5f;
    --primary-light: #2c5282;
    --primary-dark: #0f2744;
    --accent: #3182ce;
    --success: #38a169;
    --warning: #d69e2e;
    --danger: #e53e3e;
    --info: #3182ce;
    --bg: #f7fafc;
    --bg-card: #ffffff;
    --text: #1a202c;
    --text-muted: #718096;
    --border: #e2e8f0;
    --sidebar-width: 260px;
    --topbar-height: 64px;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
    --font: 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; }
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

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

img { max-width: 100%; height: auto; }

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

.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: margin-left .25s ease;
}

.content-area {
    flex: 1;
    padding: 1.5rem;
    max-width: 1400px;
    width: 100%;
}

/* ========== Sidebar ========== */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--primary-dark);
    color: #fff;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transition: transform .25s ease;
    overflow-y: auto;
}

.sidebar-header {
    padding: 1.25rem 1rem;
    border-bottom: 1px solid rgba(255,255,255,.08);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: .75rem;
    min-width: 0;
}

.sidebar-logo {
    width: 42px;
    height: 42px;
    object-fit: contain;
    border-radius: 6px;
    background: #fff;
    padding: 2px;
}

.sidebar-logo-placeholder {
    width: 42px;
    height: 42px;
    background: var(--accent);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.2rem;
}

.sidebar-brand-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.brand-name {
    font-weight: 600;
    font-size: .9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.brand-sub {
    font-size: .7rem;
    opacity: .7;
}

.sidebar-close {
    display: none;
    background: none;
    border: none;
    color: #fff;
    font-size: 1.5rem;
    cursor: pointer;
    padding: .25rem;
}

.sidebar-nav {
    flex: 1;
    padding: .75rem 0;
    display: flex;
    flex-direction: column;
}

.nav-section { margin-bottom: .5rem; }
.nav-label {
    padding: .5rem 1.25rem .25rem;
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    opacity: .5;
    font-weight: 600;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .65rem 1.25rem;
    color: rgba(255,255,255,.8);
    text-decoration: none;
    font-size: .875rem;
    transition: background .15s, color .15s;
    border-left: 3px solid transparent;
}

.nav-item:hover {
    background: rgba(255,255,255,.08);
    color: #fff;
    text-decoration: none;
}

.nav-item.active {
    background: rgba(255,255,255,.12);
    color: #fff;
    border-left-color: var(--accent);
}

.nav-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    opacity: .9;
}

.nav-bottom {
    margin-top: auto;
    border-top: 1px solid rgba(255,255,255,.08);
    padding-top: .5rem;
}

.nav-logout { color: rgba(255,200,200,.85); }
.nav-logout:hover { color: #fc8181; background: rgba(229,62,62,.15); }

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 999;
}

/* ========== Topbar ========== */
.topbar {
    height: var(--topbar-height);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.menu-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text);
    padding: .35rem;
}

.page-title {
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--text);
}

.breadcrumb {
    font-size: .8rem;
    color: var(--text-muted);
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-menu {
    display: flex;
    align-items: center;
    gap: .75rem;
}

.user-info {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    line-height: 1.3;
}

.user-name { font-weight: 600; font-size: .875rem; }
.user-role { font-size: .75rem; color: var(--text-muted); }

.user-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    overflow: hidden;
}

.user-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.btn-logout {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .45rem .85rem;
    font-size: .825rem;
    font-weight: 500;
    color: #c53030;
    background: #fff5f5;
    border: 1px solid #feb2b2;
    border-radius: 6px;
    text-decoration: none;
    transition: background .15s, color .15s;
    white-space: nowrap;
    margin-left: .25rem;
}
.btn-logout:hover {
    background: #fed7d7;
    color: #9b2c2c;
    text-decoration: none;
}
.btn-logout svg {
    flex-shrink: 0;
}

/* ========== Cards ========== */
.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    margin-bottom: 1.25rem;
}

.card-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: .75rem;
}

.card-title {
    font-size: 1rem;
    font-weight: 600;
}

.card-body { padding: 1.25rem; }

/* ========== Stats Cards ========== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 1.15rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: .35rem;
}

.stat-card .stat-label {
    font-size: .8rem;
    color: var(--text-muted);
    font-weight: 500;
}

.stat-card .stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--primary);
    line-height: 1.2;
}

.stat-card.stat-success .stat-value { color: var(--success); }
.stat-card.stat-warning .stat-value { color: var(--warning); }
.stat-card.stat-danger .stat-value { color: var(--danger); }
.stat-card.stat-info .stat-value { color: var(--info); }

/* ========== Tables ========== */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: .875rem;
}

.table th, .table td {
    padding: .75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.table th {
    background: #f8fafc;
    font-weight: 600;
    color: var(--text-muted);
    font-size: .8rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    white-space: nowrap;
}

.table tbody tr:hover { background: #f8fafc; }

.table .actions {
    display: flex;
    gap: .4rem;
    flex-wrap: wrap;
}

/* ========== Badges ========== */
.badge {
    display: inline-block;
    padding: .2rem .55rem;
    border-radius: 4px;
    font-size: .75rem;
    font-weight: 600;
    line-height: 1.3;
}

.badge-success { background: #c6f6d5; color: #22543d; }
.badge-warning { background: #fefcbf; color: #744210; }
.badge-danger { background: #fed7d7; color: #742a2a; }
.badge-info { background: #bee3f8; color: #2a4365; }
.badge-secondary { background: #e2e8f0; color: #4a5568; }

/* ========== Buttons ========== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    padding: .55rem 1rem;
    font-size: .875rem;
    font-weight: 500;
    border-radius: 6px;
    border: 1px solid transparent;
    cursor: pointer;
    transition: background .15s, border-color .15s, box-shadow .15s;
    text-decoration: none;
    line-height: 1.4;
    white-space: nowrap;
}

.btn:hover { text-decoration: none; }

.btn-primary {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.btn-primary:hover { background: var(--primary-light); border-color: var(--primary-light); color: #fff; }

.btn-success {
    background: var(--success);
    color: #fff;
    border-color: var(--success);
}
.btn-success:hover { background: #2f855a; color: #fff; }

.btn-danger {
    background: var(--danger);
    color: #fff;
    border-color: var(--danger);
}
.btn-danger:hover { background: #c53030; color: #fff; }

.btn-outline {
    background: transparent;
    color: var(--primary);
    border-color: var(--border);
}
.btn-outline:hover { background: #edf2f7; color: var(--primary); }

.btn-sm {
    padding: .35rem .65rem;
    font-size: .8rem;
}

.btn-block { width: 100%; }

/* ========== Forms ========== */
.form-group {
    margin-bottom: 1rem;
}

.form-label {
    display: block;
    margin-bottom: .35rem;
    font-weight: 500;
    font-size: .875rem;
    color: var(--text);
}

.form-control {
    width: 100%;
    padding: .55rem .75rem;
    font-size: .875rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fff;
    color: var(--text);
    transition: border-color .15s, box-shadow .15s;
    font-family: inherit;
}

.form-control:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(49,130,206,.15);
}

.form-control:disabled { background: #edf2f7; cursor: not-allowed; }

select.form-control {
    appearance: auto;
}

textarea.form-control {
    min-height: 90px;
    resize: vertical;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.form-hint {
    font-size: .8rem;
    color: var(--text-muted);
    margin-top: .25rem;
}

.form-error {
    color: var(--danger);
    font-size: .8rem;
    margin-top: .25rem;
}

/* ========== Alerts / Flash ========== */
.alert {
    padding: .85rem 1.1rem;
    border-radius: var(--radius);
    margin-bottom: 1.25rem;
    font-size: .875rem;
    border: 1px solid transparent;
}

.alert-success { background: #c6f6d5; color: #22543d; border-color: #9ae6b4; }
.alert-error, .alert-danger { background: #fed7d7; color: #742a2a; border-color: #feb2b2; }
.alert-warning { background: #fefcbf; color: #744210; border-color: #f6e05e; }
.alert-info { background: #bee3f8; color: #2a4365; border-color: #90cdf4; }

/* ========== Modal ========== */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal-overlay.show { display: flex; }

.modal {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    width: 100%;
    max-width: 520px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-title { font-size: 1.05rem; font-weight: 600; }

.modal-close {
    background: none;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    color: var(--text-muted);
    line-height: 1;
}

.modal-body { padding: 1.25rem; }
.modal-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: .5rem;
}

/* ========== Login Page ========== */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0f2744 0%, #1e3a5f 50%, #2c5282 100%);
    padding: 1.5rem;
}

.login-card {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 20px 40px rgba(0,0,0,.2);
    width: 100%;
    max-width: 400px;
    padding: 2rem;
}

.login-header {
    text-align: center;
    margin-bottom: 1.75rem;
}

.login-logo {
    width: 72px;
    height: 72px;
    object-fit: contain;
    margin-bottom: .75rem;
}

.login-logo-placeholder {
    width: 72px;
    height: 72px;
    background: var(--primary);
    color: #fff;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    font-weight: 700;
    margin-bottom: .75rem;
}

.login-school-name {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--primary-dark);
    margin-bottom: .25rem;
}

.login-subtitle {
    font-size: .875rem;
    color: var(--text-muted);
}

/* ========== Scanner ========== */
.scanner-container {
    max-width: 480px;
    margin: 0 auto;
}

.scanner-viewport {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    background: #000;
    border-radius: var(--radius);
    overflow: hidden;
}

.scanner-viewport video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.scanner-result {
    margin-top: 1rem;
    padding: 1rem;
    background: #f0fff4;
    border: 1px solid #9ae6b4;
    border-radius: var(--radius);
    display: none;
}

.scanner-result.show { display: block; }
.scanner-result.error {
    background: #fff5f5;
    border-color: #feb2b2;
}

/* ========== Pagination ========== */
.pagination {
    display: flex;
    gap: .35rem;
    flex-wrap: wrap;
    margin-top: 1rem;
}

.pagination a, .pagination span {
    padding: .4rem .7rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: .85rem;
    color: var(--text);
    text-decoration: none;
}

.pagination a:hover { background: #edf2f7; }
.pagination .active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

/* ========== Filter bar ========== */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: .75rem;
    margin-bottom: 1rem;
    align-items: flex-end;
}

.filter-bar .form-group { margin-bottom: 0; }

/* ========== Empty state ========== */
.empty-state {
    text-align: center;
    padding: 2.5rem 1rem;
    color: var(--text-muted);
}

/* ========== Print ========== */
@media print {
    .sidebar, .topbar, .menu-toggle, .btn, .filter-bar, .no-print { display: none !important; }
    .main-content { margin-left: 0 !important; }
    .content-area { padding: 0; }
    .card { box-shadow: none; border: 1px solid #ccc; }
}

/* ========== Responsive ========== */
@media (max-width: 992px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .sidebar-close { display: block; }
    .sidebar-overlay.show { display: block; }
    .main-content { margin-left: 0; }
    .menu-toggle { display: block; }
    .user-info { display: none; }
    .btn-logout-text { display: none; }
    .btn-logout { padding: .45rem .55rem; }
}

@media (max-width: 576px) {
    .content-area { padding: 1rem; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .stat-card .stat-value { font-size: 1.4rem; }
    .card-header { flex-direction: column; align-items: flex-start; }
    .form-row { grid-template-columns: 1fr; }
}
