/* =====================================================
   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;
}

/* ========== Student QR ========== */
.student-qr-section { margin-bottom: 1.25rem; }
.student-section-heading { display:flex; justify-content:space-between; align-items:flex-start; gap:1rem; margin-bottom:1rem; }
.student-section-heading h2 { font-size:1.05rem; margin:0; }
.student-section-heading p { color:var(--text-muted); font-size:.84rem; margin-top:.25rem; }
.student-qr-actions { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:.8rem; }
.qr-action { width:100%; min-width:0; min-height:66px; border:0; border-radius:12px; padding:.85rem 1rem; display:flex; align-items:center; justify-content:center; gap:.7rem; cursor:pointer; font-family:inherit; text-align:left; box-shadow:var(--shadow); }
.qr-action-primary { background:var(--primary); color:#fff; }
.qr-action-primary:hover { background:var(--primary-light); }
.qr-action-icon { width:30px; height:30px; flex:0 0 30px; display:flex; align-items:center; justify-content:center; }
.qr-action-icon svg { width:26px; height:26px; display:block; }
.qr-action strong { display:block; font-size:.95rem; letter-spacing:.01em; }
.qr-action small { display:block; margin-top:.12rem; font-size:.72rem; opacity:.82; }
.student-qr-security { margin-top:.85rem; padding:.75rem .9rem; border-radius:10px; background:#f7fafc; color:var(--text-muted); font-size:.76rem; text-align:center; }
.qr-modal { position:fixed; inset:0; z-index:2000; display:none; align-items:center; justify-content:center; padding:1rem; }
.qr-modal.is-open { display:flex; }
.qr-modal-backdrop { position:absolute; inset:0; background:rgba(15,23,42,.72); }
.qr-modal-dialog { position:relative; z-index:1; width:min(100%,420px); max-height:calc(100vh - 1rem); overflow:auto; overscroll-behavior:contain; }
.qr-modal-close { position:absolute; right:10px; top:10px; z-index:10; display:flex; align-items:center; justify-content:center; border:1px solid #e2e8f0; background:#fff; color:#334155; width:42px; height:42px; padding:0; border-radius:50%; font-family:Arial,sans-serif; font-size:1.65rem; font-weight:400; line-height:1; cursor:pointer; box-shadow:0 3px 12px rgba(15,23,42,.16); transition:transform .15s ease,background .15s ease,box-shadow .15s ease; }
.qr-modal-close:hover { background:#f8fafc; transform:scale(1.04); box-shadow:0 4px 14px rgba(15,23,42,.2); }
.qr-modal-close:active { transform:scale(.96); }
.qr-modal-close:focus-visible { outline:3px solid rgba(41,76,115,.28); outline-offset:2px; }
.qr-card-print { position:relative; background:#fff; border:3px solid #294c73; border-radius:18px; padding:3.35rem 1.1rem 1.15rem; text-align:center; box-shadow:0 15px 45px rgba(0,0,0,.25); }
.qr-school-logo { width:58px; height:58px; object-fit:contain; margin:0 auto .4rem; }
.qr-school-name { font-weight:800; color:#294c73; font-size:1rem; }
.qr-card-title { color:#718096; margin-top:.2rem; font-size:.85rem; }
.qr-avatar { width:68px; height:68px; border-radius:50%; background:#edf2f7; border:3px solid #e2e8f0; display:flex; align-items:center; justify-content:center; overflow:hidden; margin:.85rem auto .55rem; color:#294c73; font-size:1.9rem; font-weight:800; }
.qr-avatar img { width:100%; height:100%; object-fit:cover; }
.qr-card-print h3 { margin:0; font-size:1.18rem; overflow-wrap:anywhere; }
.qr-card-meta { color:#718096; margin-top:.12rem; font-size:.86rem; overflow-wrap:anywhere; }
.qr-mode-badge { display:inline-flex; margin:.85rem auto .6rem; padding:.4rem .85rem; border-radius:999px; background:#294c73; color:#fff; font-size:.76rem; font-weight:800; letter-spacing:.04em; }
.qr-modal-box { width:min(76vw,270px); aspect-ratio:1; margin:0 auto; padding:.4rem; background:#fff; display:flex; align-items:center; justify-content:center; }
.qr-modal-box img { display:block; width:100%; height:100%; object-fit:contain; image-rendering:pixelated; }
.qr-card-hint { color:#718096; font-size:.8rem; margin-top:.7rem; }

/* Mobile-first fixes: prevent desktop content from forcing horizontal scrolling. */
html, body { max-width:100%; overflow-x:hidden; }
.main-content, .content-area, .card, .card-body, .card-header { min-width:0; }

@media (max-width:576px){
    .student-identity-body, .principal-identity-body { padding:.9rem; gap:.8rem; }
    .student-identity-body > div:nth-child(2), .principal-identity-body > div:nth-child(2) { min-width:0; flex:1 1 calc(100% - 76px); }
    .student-identity-body h2 { font-size:1.05rem; overflow-wrap:anywhere; }
    .student-identity-body p { font-size:.78rem !important; overflow-wrap:anywhere; }
    .student-identity-action, .principal-identity-action { width:100%; margin-left:0 !important; }
    .student-identity-action .btn, .principal-identity-action .btn { width:100%; justify-content:center; }
    .student-qr-section { margin-bottom:1rem; }
    .student-section-heading { margin-bottom:.8rem; }
    .student-section-heading h2 { font-size:1rem; }
    .student-section-heading p { font-size:.76rem; line-height:1.45; }
    .student-qr-actions { grid-template-columns:1fr; gap:.6rem; }
    .qr-action { min-height:58px; padding:.75rem .9rem; }
    .student-qr-security { font-size:.72rem; line-height:1.45; }
    .qr-modal { padding:.35rem; align-items:center; }
    .qr-modal-dialog { width:100%; max-height:calc(100dvh - .7rem); }
    .qr-card-print { padding:3.25rem .75rem .9rem; border-width:2px; border-radius:15px; }
    .qr-modal-close { right:8px; top:8px; width:40px; height:40px; font-size:1.55rem; }
    .qr-school-logo { width:48px; height:48px; }
    .qr-school-name { font-size:.9rem; }
    .qr-card-title { font-size:.75rem; }
    .qr-avatar { width:58px; height:58px; font-size:1.6rem; margin:.65rem auto .45rem; }
    .qr-card-print h3 { font-size:1.05rem; }
    .qr-card-meta { font-size:.78rem; }
    .qr-mode-badge { margin:.65rem auto .45rem; font-size:.7rem; }
    .qr-modal-box { width:min(67vw,230px); }
    .qr-card-hint { font-size:.72rem; }
}
/* ========== 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: .8rem; width:100%; }
    .topbar { padding:0 .75rem; }
    .page-title { font-size:1rem; }
    .stats-grid { grid-template-columns:1fr 1fr; gap:.65rem; }
    .stat-card { min-width:0; padding:.85rem; }
    .stat-card .stat-value { font-size:1.35rem; }
    .stat-card .stat-label { font-size:.72rem; white-space:normal; }
    .card-header { flex-direction:column; align-items:flex-start; }
    .card-body { padding:1rem; }
    .form-row { grid-template-columns:1fr; }
}

/* Profile editor */
.profile-editor{display:flex;align-items:center;gap:1rem;margin-bottom:1rem;padding:1rem;background:#f7fafc;border-radius:10px;flex-wrap:wrap}
.profile-photo-preview{width:88px;height:88px;border-radius:50%;overflow:hidden;background:#edf2f7;border:2px solid #e2e8f0;display:flex;align-items:center;justify-content:center;color:#294c73;font-size:2rem;font-weight:800;flex:0 0 88px}
.profile-photo-preview img{width:100%;height:100%;object-fit:cover}
.form-help{display:block;color:var(--text-muted);font-size:.75rem;margin-top:.3rem}
@media(max-width:576px){.profile-editor{align-items:flex-start}.profile-editor>div:last-child{width:100%}}

/* Strong mobile containment for Android/iPhone */
@media (max-width: 576px) {
  html, body, .app-wrapper, .main-content, .content-area, .topbar, .topbar-left, .topbar-right { width:100%; max-width:100%; min-width:0; }
  .topbar { overflow:hidden; }
  .topbar-left { flex:1 1 auto; min-width:0; }
  .page-title-wrap { min-width:0; overflow:hidden; }
  .page-title { white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
  .content-area { overflow:hidden; }
  .card { width:100%; max-width:100%; overflow:hidden; }
  .student-identity-body { width:100%; overflow:hidden; }
  .student-identity-body > div:nth-child(2) { overflow:hidden; }
  .student-qr-actions { width:100%; }
  .qr-action { min-width:0; }
  .stats-grid { width:100%; }
  .filter-bar { width:100%; flex-wrap:wrap; }
  .filter-bar .form-control { max-width:100%; width:100% !important; }
  .table-responsive { width:100%; max-width:100%; overflow-x:auto; -webkit-overflow-scrolling:touch; }
}


/* ========== Teacher dashboard actions ========== */
.teacher-dashboard-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .9rem;
    margin-top: .25rem;
}
.teacher-action-btn {
    min-height: 82px;
    width: 100%;
    padding: 1rem 1.1rem;
    border-radius: 12px;
    border: 1px solid var(--primary);
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: .85rem;
    text-decoration: none;
    box-shadow: var(--shadow);
    transition: transform .15s ease, background .15s ease, box-shadow .15s ease;
}
.teacher-action-btn:hover {
    transform: translateY(-1px);
    text-decoration: none;
}
.teacher-action-primary {
    background: var(--primary);
    color: #fff;
}
.teacher-action-primary:hover {
    background: var(--primary-light);
    color: #fff;
}
.teacher-action-secondary {
    grid-column: 1 / -1;
    background: #fff;
    color: var(--primary);
    border-color: var(--primary);
}
.teacher-action-secondary:hover {
    background: #edf2f7;
    color: var(--primary);
}
.teacher-action-icon {
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.35rem;
    font-weight: 800;
    background: rgba(255,255,255,.16);
}
.teacher-action-secondary .teacher-action-icon {
    background: rgba(255,255,255,.16);
    color: #fff;
}
.teacher-action-icon svg {
    width: 25px;
    height: 25px;
    display: block;
}
.teacher-action-secondary .teacher-action-icon.attendance-icon {
    background: rgba(255,255,255,.16);
    color: #fff;
}
.teacher-action-btn strong {
    display: block;
    font-size: .98rem;
    letter-spacing: .02em;
}
.teacher-action-btn small {
    display: block;
    margin-top: .25rem;
    font-size: .78rem;
    font-weight: 400;
    line-height: 1.35;
    letter-spacing: 0;
    color: rgba(255,255,255,.78) !important;
    opacity: 1;
}
.teacher-action-secondary small {
    color: rgba(255,255,255,.78) !important;
}
.stat-label {
    color: var(--text-muted) !important;
    font-size: .72rem !important;
    font-weight: 600 !important;
    letter-spacing: .04em;
    text-transform: uppercase;
}
.stat-value {
    color: var(--text) !important;
}

@media (max-width: 576px) {
    .teacher-dashboard-actions {
        grid-template-columns: 1fr;
        gap: .7rem;
    }
    .teacher-action-secondary {
        grid-column: auto;
    }
    .teacher-action-btn {
        min-height: 70px;
        padding: .85rem .95rem;
    }
    .teacher-action-btn strong {
        font-size: .92rem;
    }
}

/* ========== Cleaner mobile logout ========== */
.btn-logout {
    min-width: 44px;
    min-height: 42px;
    justify-content: center;
    border-radius: 10px;
    padding: .5rem .7rem;
    font-weight: 700;
}
@media (max-width: 992px) {
    .btn-logout {
        width: 44px;
        height: 42px;
        padding: 0;
        margin-left: .15rem;
    }
    .btn-logout svg {
        width: 20px;
        height: 20px;
    }
}
@media (max-width: 576px) {
    .btn-logout {
        width: 42px;
        height: 42px;
        border-radius: 10px;
    }
}

/* ========== Topbar logout alignment fix ========== */
.topbar-right {
    margin-left: auto;
}

@media (max-width: 992px) {
    .topbar {
        padding-left: .75rem;
        padding-right: .25rem;
    }
    .topbar-right {
        flex: 0 0 auto;
        margin-left: auto;
    }
    .user-menu {
        gap: .4rem;
    }
    .btn-logout {
        margin-left: 0;
        margin-right: 0;
    }
}

@media (max-width: 576px) {
    .topbar {
        padding-left: .65rem;
        padding-right: .2rem;
    }
    .topbar-left {
        gap: .65rem;
    }
    .topbar-right {
        margin-left: auto;
    }
}

/* =====================================================
   FINAL TOPBAR / MOBILE LAYOUT SAFETY FIX
   Keeps menu/title on the left and user/logout on the right.
   ===================================================== */
.topbar {
    width: 100%;
    min-width: 0;
    flex: 0 0 auto;
}
.topbar-left {
    flex: 0 1 auto;
    min-width: 0;
}
.topbar-right {
    flex: 0 0 auto;
    margin-left: auto !important;
}
.user-menu {
    flex: 0 0 auto;
    min-width: 0;
}

@media (max-width: 992px) {
    .main-content {
        width: 100%;
        min-width: 0;
        margin-left: 0 !important;
    }
    .sidebar {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        width: min(260px, 86vw) !important;
        height: 100vh !important;
        transform: translateX(-110%) !important;
        z-index: 1000 !important;
        visibility: hidden;
    }
    .sidebar.open {
        transform: translateX(0) !important;
        visibility: visible;
    }
    .topbar {
        display: flex !important;
        width: 100% !important;
        height: var(--topbar-height);
        padding-left: .75rem;
        padding-right: .65rem;
        position: sticky;
        top: 0;
    }
    .topbar-left {
        display: flex !important;
        align-items: center;
        flex: 1 1 auto !important;
        min-width: 0;
    }
    .menu-toggle {
        display: flex !important;
        align-items: center;
        justify-content: center;
        flex: 0 0 40px;
        width: 40px;
        height: 40px;
    }
    .page-title-wrap {
        display: block !important;
        min-width: 0;
    }
    .topbar-right {
        display: flex !important;
        align-items: center;
        flex: 0 0 auto !important;
        margin-left: auto !important;
    }
    .user-menu {
        display: flex !important;
        align-items: center;
        gap: .45rem;
    }
    .user-info {
        display: none !important;
    }
}

@media (max-width: 576px) {
    .topbar {
        padding-left: .5rem;
        padding-right: .35rem;
    }
    .topbar-left {
        gap: .45rem;
    }
    .menu-toggle {
        flex-basis: 42px;
        width: 42px;
        height: 42px;
        padding: .35rem;
    }
    .topbar-right {
        margin-left: auto !important;
    }
    .user-avatar {
        width: 36px;
        height: 36px;
    }
    .btn-logout {
        width: 42px !important;
        min-width: 42px !important;
        height: 42px !important;
        min-height: 42px !important;
        padding: 0 !important;
        margin: 0 !important;
    }
}

/* FINAL MOBILE HEADER POSITION FIX
   Keep the left controls unchanged and anchor the account controls
   to the actual right edge of the phone viewport. */
@media (max-width: 992px) {
    .topbar {
        width: 100vw !important;
        max-width: 100vw !important;
        min-width: 100vw !important;
        position: sticky;
        left: 0;
        right: 0;
    }
    .topbar-right {
        margin-left: auto !important;
        margin-right: 0 !important;
        flex: 0 0 auto !important;
    }
}

@media (max-width: 576px) {
    .topbar {
        padding-left: .5rem !important;
        padding-right: .25rem !important;
    }
    .topbar-left {
        flex: 1 1 auto !important;
        min-width: 0 !important;
    }
    .topbar-right {
        flex: 0 0 auto !important;
        margin-left: auto !important;
        margin-right: 0 !important;
    }
    .user-menu {
        flex: 0 0 auto !important;
    }
}


/* =========================================================
   HEADER LAYOUT - FINAL MINIMAL FIX
   Do not alter sidebar/content. Keep left controls left and
   account controls at the far right.
   ========================================================= */
.topbar {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) auto !important;
    align-items: center !important;
    justify-content: initial !important;
    width: 100% !important;
    max-width: none !important;
    min-width: 0 !important;
    padding-left: 1.5rem !important;
    padding-right: 1.5rem !important;
}

.topbar-left {
    grid-column: 1 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: flex-start !important;
    min-width: 0 !important;
    width: auto !important;
    margin: 0 !important;
}

.topbar-right {
    grid-column: 2 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: flex-end !important;
    width: auto !important;
    min-width: max-content !important;
    margin: 0 !important;
}

.user-menu {
    display: flex !important;
    align-items: center !important;
    justify-content: flex-end !important;
    width: auto !important;
    min-width: max-content !important;
    margin: 0 !important;
}

@media (max-width: 992px) {
    .topbar {
        grid-template-columns: minmax(0, 1fr) auto !important;
        padding-left: .75rem !important;
        padding-right: .5rem !important;
        width: 100% !important;
        max-width: 100% !important;
    }
    .topbar-left {
        grid-column: 1 !important;
        flex: none !important;
        width: auto !important;
    }
    .topbar-right {
        grid-column: 2 !important;
        flex: none !important;
        width: auto !important;
        min-width: max-content !important;
    }
}

@media (max-width: 576px) {
    .topbar {
        padding-left: .5rem !important;
        padding-right: .25rem !important;
    }
    .topbar-left {
        gap: .45rem !important;
    }
    .topbar-right {
        min-width: max-content !important;
    }
}

/* Principal/teacher dashboard: fixed two-column statistic layout; percentage spans full width. */
.principal-stats-grid, .teacher-stats-grid { grid-template-columns:repeat(2,minmax(0,1fr)); }
.principal-stats-grid > .stat-card:last-child, .teacher-stats-grid > .stat-card:last-child { grid-column:1 / -1; align-items:center; text-align:center; }
.principal-stats-grid > .stat-card:last-child .stat-label, .principal-stats-grid > .stat-card:last-child .stat-value, .teacher-stats-grid > .stat-card:last-child .stat-label, .teacher-stats-grid > .stat-card:last-child .stat-value { width:100%; text-align:center; }
.qr-modal-tools{text-align:center;margin-bottom:.55rem;position:relative;z-index:4}

/* Student dashboard: six statistic cards arranged 3 + 3 on mobile/desktop. */
/* Student dashboard: all six statistics stay equal in a 3-column grid.
   Row 1 = Hadir / Izin / Sakit
   Row 2 = Alfa / PKL / Persentase Kehadiran */
.student-stats-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}
.student-stats-grid > .stat-card {
    width: auto;
    min-width: 0;
    justify-self: stretch;
    align-self: stretch;
}
.student-stats-grid > .student-attendance-percentage {
    grid-column: auto;
    width: auto;
    justify-self: stretch;
    align-items: flex-start;
    text-align: left;
}
.student-stats-grid > .student-attendance-percentage .stat-label,
.student-stats-grid > .student-attendance-percentage .stat-value {
    width: auto;
    text-align: left;
}
@media (max-width:576px){
    .student-stats-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: .55rem;
    }
    .student-stats-grid .stat-card {
        padding: .72rem .6rem;
        min-width: 0;
    }
    .student-stats-grid .stat-card .stat-label {
        font-size: .68rem;
        line-height: 1.25;
    }
    .student-stats-grid .stat-card .stat-value {
        font-size: 1.3rem;
    }
    .student-stats-grid > .student-attendance-percentage {
        grid-column: auto;
        align-items: flex-start;
        text-align: left;
    }
    .student-stats-grid > .student-attendance-percentage .stat-label,
    .student-stats-grid > .student-attendance-percentage .stat-value {
        text-align: left;
        width: auto;
    }
}

/* Dashboard action card uses the same primary blue as scanner cards. */
.teacher-action-secondary { background: var(--primary) !important; color:#fff !important; border-color:var(--primary) !important; }

.student-points-card .points-number { font-size:2rem; font-weight:800; color:var(--primary); }
.student-points-card .points-meta { color:var(--text-muted); font-size:.85rem; }

.order-actions { display:flex; gap:.3rem; align-items:center; }
.order-actions .btn { min-width:36px; padding:.45rem .55rem; }

.discipline-sp-0 { color:var(--success); }
.discipline-sp-1, .discipline-sp-2 { color:var(--warning); }
.discipline-sp-3 { color:var(--danger); }

/* PKL dashboard cards: teacher has 7 cards and principal has 9.
   Keep the final card full-width and centered on small screens, matching the student layout.
   Other pages/grids are untouched. */
@media (max-width: 576px) {
    .teacher-stats-grid > .stat-card:last-child,
    .principal-stats-grid > .stat-card:last-child {
        grid-column: 1 / -1;
        width: 100%;
        justify-self: stretch;
        align-items: center;
        text-align: center;
    }

    .teacher-stats-grid > .stat-card:last-child .stat-label,
    .teacher-stats-grid > .stat-card:last-child .stat-value,
    .principal-stats-grid > .stat-card:last-child .stat-label,
    .principal-stats-grid > .stat-card:last-child .stat-value {
        text-align: center;
        width: 100%;
    }
}

/* =====================================================
   Professional layer 2026-08-30
   ===================================================== */
:root {
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 2px rgba(15,23,42,.04), 0 1px 3px rgba(15,23,42,.06);
    --shadow-md: 0 4px 14px rgba(15,23,42,.08);
    --primary-soft: rgba(30,58,95,.06);
    --accent-soft: rgba(49,130,206,.12);
}
.card {
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    overflow: hidden;
}
.card-header {
    background: linear-gradient(180deg, #f8fafc 0%, #fff 100%);
}
.card-subtitle, .form-hint, .scanner-meta, .scanner-hint,
.stat-label, .brand-sub, .user-role, .empty-state-desc,
.section-title + .form-hint {
    color: var(--text-muted) !important;
}
.card-subtitle {
    font-size: .84rem;
    margin-top: .25rem;
    font-weight: 400;
}
.section-title {
    font-size: .95rem;
    font-weight: 600;
    margin: 0 0 .85rem;
    color: var(--text);
}
.stat-card {
    border-radius: var(--radius);
    position: relative;
    overflow: hidden;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}
.stat-card::before {
    content: "";
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--primary) 0%, var(--accent) 100%);
    opacity: .55;
}
.stat-card.stat-success::before { background: var(--success); opacity: .75; }
.stat-card.stat-warning::before { background: var(--warning); opacity: .75; }
.stat-card.stat-danger::before { background: var(--danger); opacity: .75; }
.stat-card.stat-info::before { background: var(--info); opacity: .75; }
.stat-card .stat-label {
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    font-weight: 600;
    color: var(--text-muted) !important;
}
.stat-card .stat-value {
    font-size: 1.85rem;
    font-weight: 700;
    letter-spacing: -.02em;
}
.btn-primary {
    background: linear-gradient(180deg, var(--primary-light) 0%, var(--primary) 100%);
    border-color: var(--primary);
}
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.sidebar {
    background: linear-gradient(180deg, #0f2744 0%, #132a48 55%, #0f2744 100%);
}
.nav-icon { width: 18px; height: 18px; }
.login-page {
    background: linear-gradient(160deg, #0f2744 0%, #1e3a5f 50%, #243b5c 100%);
}
.login-card { border-radius: 16px; box-shadow: var(--shadow-md); }
.scanner-result { display: none !important; }
.scanner-meta, .scanner-hint { color: var(--text-muted) !important; font-size: .875rem; }
.scanner-tabs { display:flex; gap:.5rem; flex-wrap:wrap; margin-bottom:1rem; }
.form-check { display:flex; align-items:flex-start; gap:.5rem; font-size:.875rem; color: var(--text); }
.form-check input { margin-top:.2rem; }
.option-box {
    padding: .85rem 1rem;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}
.logo-row { display:flex; align-items:center; gap:1.25rem; flex-wrap:wrap; }
.logo-preview { max-width:120px; max-height:120px; border:1px solid var(--border); border-radius:10px; padding:4px; background:#fff; }
.logo-placeholder { width:120px; height:120px; background:#edf2f7; border-radius:10px; display:flex; align-items:center; justify-content:center; color:var(--text-muted); font-size:.85rem; }
.mb-sm { margin-bottom:.75rem; }
.mb-md { margin-bottom:1rem; }
.mb-lg { margin-bottom:1.5rem; }
.inline-details summary { cursor:pointer; list-style:none; }
.details-form { margin-top:.75rem; padding:1rem; background:#f8fafc; border-radius:10px; border:1px solid var(--border); }
.empty-state-title { font-weight:600; color:var(--text); margin-bottom:.25rem; }
.empty-state-desc { font-size:.875rem; color:var(--text-muted) !important; }

/* Toast in-app */
.toast-stack {
    position: fixed; top: 1rem; left: 50%; transform: translateX(-50%);
    z-index: 9999; display: flex; flex-direction: column; gap: .6rem;
    width: min(92vw, 380px); pointer-events: none;
}
.toast {
    pointer-events: auto; display:flex; align-items:flex-start; gap:.75rem;
    padding: .9rem 1rem; border-radius: var(--radius); background:#fff;
    border:1px solid var(--border); box-shadow: var(--shadow-md);
    opacity:0; transform: translateY(-12px) scale(.98);
    transition: opacity .28s ease, transform .28s ease;
}
.toast.is-visible { opacity:1; transform: translateY(0) scale(1); }
.toast.is-leaving { opacity:0; transform: translateY(-8px) scale(.98); }
.toast-icon { flex:0 0 28px; width:28px; height:28px; border-radius:50%; display:flex; align-items:center; justify-content:center; }
.toast-icon svg { width:16px; height:16px; }
.toast-success .toast-icon { background:#c6f6d5; color:#22543d; }
.toast-error .toast-icon { background:#fed7d7; color:#742a2a; }
.toast-body { flex:1; min-width:0; }
.toast-title { font-weight:700; font-size:.9rem; color:var(--text); margin:0 0 .2rem; }
.toast-message { font-size:.82rem; color:var(--text-muted); line-height:1.4; }
.toast-meta { margin-top:.35rem; font-size:.8rem; color:var(--text); }
@media (max-width:576px) {
    .toast-stack { top:.65rem; width:min(94vw,360px); }
}
.text-muted-sm{color:var(--text-muted)!important;font-size:.875rem;}
.pct-cell{white-space:nowrap;font-variant-numeric:tabular-nums;}
/* Canonical icon sizing: the same icon geometry is reused in sidebar, dashboard and QR actions. */
.action-icon-svg, .qr-action-svg { width:24px; height:24px; display:block; flex:0 0 24px; }
