<?php
session_start();
if(!isset($_SESSION['login'])){ header("Location: login.php"); exit(); }
if(isset($_SESSION['role'])){
    if($_SESSION['role']==='guru')               { header("Location: dashboard_guru.php");  exit(); }
    if(in_array($_SESSION['role'],['staff','tu'])){ header("Location: dashboard_staff.php"); exit(); }
}
include 'koneksi.php';

$total_siswa = mysqli_fetch_array(mysqli_query($conn,"SELECT COUNT(*) as t FROM siswa WHERE status_siswa='Aktif'"))['t'];
$total_surat = mysqli_fetch_array(mysqli_query($conn,"SELECT COUNT(*) as t FROM surat"))['t'];
$bulan_ini   = date('Y-m');
$total_spp   = mysqli_fetch_array(mysqli_query($conn,"SELECT COUNT(*) as t FROM spp WHERE DATE_FORMAT(tanggal_bayar,'%Y-%m')='$bulan_ini'"))['t'];
$spp_lunas   = mysqli_fetch_array(mysqli_query($conn,"SELECT COUNT(DISTINCT siswa_id) as t FROM spp WHERE status='Lunas' AND bulan='".date('F')."' AND tahun=".date('Y')))['t'];
$persen_bayar= $total_siswa>0 ? round(($spp_lunas/$total_siswa)*100) : 0;
$siswa_baru  = mysqli_fetch_array(mysqli_query($conn,"SELECT COUNT(*) as t FROM siswa WHERE DATE(tanggal_daftar)='".date('Y-m-d')."'"))['t'];

$user_name = $_SESSION['nama'] ?? 'Admin';
$user_role = $_SESSION['role'] ?? 'admin';
date_default_timezone_set('Asia/Jakarta');
$hour = (int)date('H');
$bulan_arr=['','Januari','Februari','Maret','April','Mei','Juni','Juli','Agustus','September','Oktober','November','Desember'];
$hari_arr=['','Senin','Selasa','Rabu','Kamis','Jumat','Sabtu','Minggu'];
if($hour>=5&&$hour<11)     { $salam='Selamat Pagi';  $ico='🌅'; $mood='Semangat memimpin hari ini!'; }
elseif($hour>=11&&$hour<15){ $salam='Selamat Siang'; $ico='☀️'; $mood='Tetap produktif dan bersemangat!'; }
elseif($hour>=15&&$hour<18){ $salam='Selamat Sore';  $ico='🌤️'; $mood='Hampir selesai, kerja bagus!'; }
else                        { $salam='Selamat Malam'; $ico='🌙'; $mood='Jangan lupa istirahat yang cukup!'; }

$tanggal_full = $hari_arr[(int)date('N')].', '.date('d').' '.$bulan_arr[(int)date('m')].' '.date('Y');
?>
<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>Dashboard Admin — MA As-Syafi'iyah 02</title>
<link rel="icon" href="assets/sekolah.png">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=DM+Serif+Display:ital@0;1&family=Outfit:wght@300;400;500;600;700;800;900&family=DM+Mono:wght@400;500&display=swap" rel="stylesheet">
<style>
:root{
    --ob:    #080C14;
    --ob-m:  #0E1520;
    --ob-l:  #141D2E;
    --ob-ll: #1C2840;
    --g:     #C9A84C;
    --g-l:   #E0C06A;
    --g-d:   #A8893A;
    --g-fg:  #FDF0C8;
    --bg:    #F7F5F2;
    --sf:    #FFFFFF;
    --sf2:   #FAFAF9;
    --tx:    #131820;
    --txm:   #5A6478;
    --txl:   #9BA4B5;
    --bd:    #E8E4DC;
    --bd-d:  #D4CCBF;
    --em:    #0C6B58;
    --sc:    #1D4ED8;
    --ru:    #9B1C1C;
    --am:    #B45309;
    --sh:    rgba(8,12,20,.06);
    --sh-m:  rgba(8,12,20,.1);
    --sh-s:  rgba(8,12,20,.18);
    --sw:    272px;
    --header-h: 0px; /* used for mobile top-bar height offset */
}

*,*::before,*::after{margin:0;padding:0;box-sizing:border-box}
html{scroll-behavior:smooth}
body{
    font-family:'Outfit',sans-serif;
    background:var(--bg);
    color:var(--tx);
    min-height:100vh;
    display:flex;
    -webkit-font-smoothing:antialiased;
}

/* ══ SIDEBAR ══ */
.sb{
    position:fixed;top:0;left:0;bottom:0;
    width:var(--sw);
    background:var(--ob);
    display:flex;flex-direction:column;
    z-index:200;overflow:hidden;
    transition:transform .3s cubic-bezier(.4,0,.2,1);
}
.sb::before{
    content:'';position:absolute;inset:0;pointer-events:none;
    background-image:
        linear-gradient(rgba(201,168,76,.04) 1px,transparent 1px),
        linear-gradient(90deg,rgba(201,168,76,.04) 1px,transparent 1px);
    background-size:32px 32px;
}
.sb::after{
    content:'';position:absolute;top:-60px;left:50%;
    transform:translateX(-50%);
    width:200px;height:120px;
    background:radial-gradient(ellipse,rgba(201,168,76,.18) 0%,transparent 70%);
    pointer-events:none;
}
.sb-brand{
    padding:1.75rem 1.5rem 1.5rem;
    display:flex;align-items:center;gap:.875rem;
    border-bottom:1px solid rgba(201,168,76,.1);
    position:relative;z-index:1;flex-shrink:0;
}
.sb-logo{
    width:48px;height:48px;border-radius:14px;
    background:linear-gradient(135deg,var(--ob-ll),var(--ob-l));
    border:1.5px solid var(--g-d);
    display:flex;align-items:center;justify-content:center;
    overflow:hidden;flex-shrink:0;
    box-shadow:0 0 0 3px rgba(201,168,76,.15),0 8px 20px rgba(0,0,0,.3);
}
.sb-logo img{width:34px;height:34px;object-fit:contain}
.sb-name{font-family:'DM Serif Display',serif;font-size:.95rem;color:var(--g-fg);line-height:1.2;}
.sb-short{font-size:.62rem;font-weight:600;letter-spacing:.14em;text-transform:uppercase;color:rgba(255,255,255,.35);margin-top:.1rem;}
.sb-nav{flex:1;padding:1rem 0;overflow-y:auto;position:relative;z-index:1}
.sb-nav::-webkit-scrollbar{width:0}
.sb-sec-lbl{
    font-size:.6rem;font-weight:700;letter-spacing:.18em;
    text-transform:uppercase;color:rgba(255,255,255,.25);
    padding:1rem 1.5rem .5rem;
}
.nav-a{
    display:flex;align-items:center;gap:.875rem;
    padding:.75rem 1.5rem;
    color:rgba(255,255,255,.5);
    text-decoration:none;font-size:.875rem;font-weight:500;
    position:relative;transition:color .22s;cursor:pointer;
}
.nav-a::before{
    content:'';position:absolute;inset:0;
    background:linear-gradient(90deg,transparent,rgba(201,168,76,.07),transparent);
    transform:translateX(-100%);transition:transform .5s ease;pointer-events:none;
}
.nav-a::after{
    content:'';position:absolute;left:0;top:50%;
    transform:translateY(-50%);width:3px;height:0;
    background:var(--g);border-radius:0 3px 3px 0;
    transition:height .22s cubic-bezier(.34,1.56,.64,1);
}
.nav-a:hover,.nav-a.on{color:var(--g-l);background:rgba(201,168,76,.06);}
.nav-a:hover::before,.nav-a.on::before{transform:translateX(100%)}
.nav-a:hover::after,.nav-a.on::after{height:70%}
.nav-ico{
    width:32px;height:32px;border-radius:9px;
    background:rgba(255,255,255,.05);
    display:flex;align-items:center;justify-content:center;
    font-size:1.05rem;flex-shrink:0;
    transition:all .25s cubic-bezier(.34,1.56,.64,1);
}
.nav-a:hover .nav-ico,.nav-a.on .nav-ico{background:rgba(201,168,76,.15);transform:scale(1.15) rotate(-5deg);}
.sb-foot{
    padding:1.25rem 1.5rem;
    border-top:1px solid rgba(201,168,76,.1);
    flex-shrink:0;position:relative;z-index:1;
}
.sb-user{
    display:flex;align-items:center;gap:.75rem;
    padding:.875rem 1rem;
    background:rgba(255,255,255,.04);
    border:1px solid rgba(255,255,255,.07);
    border-radius:12px;margin-bottom:.875rem;
}
.sb-uav{
    width:36px;height:36px;border-radius:50%;
    background:linear-gradient(135deg,var(--g-d),var(--g));
    display:flex;align-items:center;justify-content:center;
    font-size:1.1rem;flex-shrink:0;
    overflow:hidden;border:1.5px solid rgba(201,168,76,.4);
}
.sb-uav img{width:36px;height:36px;object-fit:cover}
.sb-uname{font-size:.825rem;font-weight:700;color:rgba(255,255,255,.85);line-height:1.2}
.sb-urole{
    display:inline-block;margin-top:.15rem;
    font-size:.58rem;font-weight:700;letter-spacing:.1em;text-transform:uppercase;
    padding:.1rem .5rem;border-radius:50px;
    background:rgba(201,168,76,.2);color:var(--g-l);border:1px solid rgba(201,168,76,.25);
}
.logout-btn{
    display:flex;align-items:center;justify-content:center;gap:.625rem;
    width:100%;padding:.75rem;
    background:linear-gradient(135deg,rgba(155,28,28,.7),rgba(185,28,28,.6));
    color:rgba(255,255,255,.9);border:none;border-radius:10px;
    font-size:.78rem;font-weight:700;letter-spacing:.06em;text-transform:uppercase;
    font-family:'Outfit',sans-serif;text-decoration:none;cursor:pointer;
    border:1px solid rgba(255,255,255,.08);transition:all .25s;
}
.logout-btn:hover{background:linear-gradient(135deg,#9B1C1C,#B91C1C);transform:translateY(-2px);box-shadow:0 6px 20px rgba(155,28,28,.35);}

/* ══ SIDEBAR OVERLAY (mobile) ══ */
.sb-overlay{
    display:none;position:fixed;inset:0;z-index:199;
    background:rgba(8,12,20,.55);backdrop-filter:blur(2px);
    opacity:0;pointer-events:none;transition:opacity .3s;
}
.sb-overlay.show{opacity:1;pointer-events:all;}

/* ══ LOADER ══ */
.loader{
    position:fixed;inset:0;z-index:9999;background:var(--ob);
    display:flex;flex-direction:column;align-items:center;justify-content:center;gap:2rem;
    transition:opacity .7s ease,visibility .7s ease;
}
.loader.gone{opacity:0;visibility:hidden}
.loader-ring{width:100px;height:100px;position:relative;}
.loader-ring::before,.loader-ring::after{content:'';position:absolute;border-radius:50%;}
.loader-ring::before{inset:0;border:2px solid rgba(201,168,76,.15);}
.loader-ring::after{inset:4px;border:2px solid transparent;border-top-color:var(--g);animation:spin 1s linear infinite;}
.loader-inner{position:absolute;inset:18px;background:var(--ob-l);border-radius:50%;display:flex;align-items:center;justify-content:center;overflow:hidden;border:1px solid rgba(201,168,76,.2);}
.loader-inner img{width:38px;height:38px;object-fit:contain}
.loader-txt{font-family:'DM Serif Display',serif;font-size:1.25rem;color:rgba(255,255,255,.6);letter-spacing:.05em;}
.loader-dots{display:flex;gap:.5rem;margin-top:-.5rem}
.loader-dot{width:6px;height:6px;border-radius:50%;background:var(--g);animation:ldot .8s ease-in-out infinite;}
.loader-dot:nth-child(2){animation-delay:.15s}.loader-dot:nth-child(3){animation-delay:.3s}
@keyframes spin{to{transform:rotate(360deg)}}
@keyframes ldot{0%,80%,100%{transform:scale(.6);opacity:.4}40%{transform:scale(1);opacity:1}}

/* ══ TOPBAR (mobile only) ══ */
.topbar{
    display:none;
    position:fixed;top:0;left:0;right:0;height:60px;
    background:var(--ob);border-bottom:1px solid rgba(201,168,76,.12);
    z-index:198;padding:0 1rem;
    align-items:center;justify-content:space-between;
    box-shadow:0 2px 16px rgba(0,0,0,.25);
}
.topbar-brand{display:flex;align-items:center;gap:.625rem;}
.topbar-logo{width:34px;height:34px;border-radius:9px;background:var(--ob-l);border:1.5px solid var(--g-d);display:flex;align-items:center;justify-content:center;overflow:hidden;}
.topbar-logo img{width:24px;height:24px;object-fit:contain}
.topbar-name{font-family:'DM Serif Display',serif;font-size:.85rem;color:var(--g-fg);}
.mob-toggle{
    width:42px;height:42px;
    background:rgba(201,168,76,.1);border:1.5px solid rgba(201,168,76,.2);
    border-radius:10px;display:flex;align-items:center;justify-content:center;
    font-size:1.15rem;cursor:pointer;transition:background .2s;flex-shrink:0;
}
.mob-toggle:hover{background:rgba(201,168,76,.18);}

/* ══ MAIN ══ */
.main{margin-left:var(--sw);flex:1;min-height:100vh;display:flex;flex-direction:column}
.wrap{max-width:1400px;margin:0 auto;padding:2rem 2.5rem;flex:1;width:100%}

/* ══ HERO ══ */
.hero{
    position:relative;overflow:hidden;border-radius:24px;
    margin-bottom:1.75rem;background:var(--ob);
    min-height:220px;display:flex;align-items:stretch;
    box-shadow:0 20px 60px rgba(8,12,20,.2);
    animation:fadeUp .7s cubic-bezier(.16,1,.3,1) both;
}
.hero-mesh{position:absolute;inset:0;pointer-events:none;overflow:hidden;}
.hero-mesh::before{content:'';position:absolute;width:600px;height:600px;top:-200px;right:-100px;background:radial-gradient(circle,rgba(201,168,76,.12) 0%,transparent 60%);animation:meshDrift 12s ease-in-out infinite;}
.hero-mesh::after{content:'';position:absolute;width:400px;height:400px;bottom:-150px;left:100px;background:radial-gradient(circle,rgba(29,78,216,.1) 0%,transparent 60%);animation:meshDrift 9s ease-in-out infinite reverse;}
@keyframes meshDrift{0%,100%{transform:translate(0,0)}50%{transform:translate(30px,-20px)}}
.hero-lines{position:absolute;inset:0;pointer-events:none;overflow:hidden;}
.hero-lines::before{content:'';position:absolute;width:120%;height:1px;top:35%;left:-10%;background:linear-gradient(90deg,transparent,rgba(201,168,76,.12),transparent);transform:rotate(-8deg);}
.hero-lines::after{content:'';position:absolute;width:120%;height:1px;top:65%;left:-10%;background:linear-gradient(90deg,transparent,rgba(201,168,76,.08),transparent);transform:rotate(-8deg);}
.hero-content{
    position:relative;z-index:2;
    display:flex;align-items:center;justify-content:space-between;
    padding:2.25rem 2.75rem;width:100%;gap:2rem;flex-wrap:wrap;
}
.hero-eyebrow{
    display:inline-flex;align-items:center;gap:.5rem;
    padding:.35rem 1rem;background:rgba(201,168,76,.12);
    border:1px solid rgba(201,168,76,.2);border-radius:50px;
    font-size:.68rem;font-weight:700;letter-spacing:.14em;text-transform:uppercase;
    color:var(--g-l);margin-bottom:1.125rem;
}
.hero-name{font-family:'DM Serif Display',serif;font-size:2.375rem;color:#FFF;line-height:1.1;letter-spacing:-.01em;margin-bottom:.5rem;}
.hero-name span{color:var(--g-l);font-style:italic}
.hero-sub{font-size:.9rem;font-weight:400;color:rgba(255,255,255,.5);margin-bottom:1.5rem;}
.hero-meta{display:flex;align-items:center;gap:1.5rem;flex-wrap:wrap;}
.hero-meta-item{display:flex;align-items:center;gap:.5rem;font-size:.78rem;font-weight:500;color:rgba(255,255,255,.45);}
.hero-meta-item strong{color:rgba(255,255,255,.7);font-weight:600}
.hero-r{display:flex;gap:1rem;flex-shrink:0;}
.hero-stat{
    background:rgba(255,255,255,.05);border:1px solid rgba(255,255,255,.08);
    border-radius:16px;padding:1.25rem 1.625rem;text-align:center;min-width:110px;
    backdrop-filter:blur(10px);transition:all .3s ease;position:relative;overflow:hidden;
}
.hero-stat::before{content:'';position:absolute;top:0;left:0;right:0;height:2px;background:linear-gradient(90deg,transparent,var(--g),transparent);opacity:0;transition:opacity .3s;}
.hero-stat:hover{background:rgba(255,255,255,.09);transform:translateY(-4px);}
.hero-stat:hover::before{opacity:1}
.hero-stat-n{font-family:'DM Mono',monospace;font-size:2.25rem;font-weight:500;color:white;line-height:1;margin-bottom:.35rem;}
.hero-stat-l{font-size:.6rem;font-weight:700;letter-spacing:.12em;text-transform:uppercase;color:rgba(255,255,255,.4);}

/* ══ STAT CARDS ══ */
.srow{display:grid;grid-template-columns:repeat(4,1fr);gap:1.25rem;margin-bottom:1.75rem;}
.sc{
    background:var(--sf);border-radius:20px;border:1px solid var(--bd);
    padding:1.625rem 1.75rem;position:relative;overflow:hidden;
    box-shadow:0 2px 12px var(--sh);
    transition:all .35s cubic-bezier(.34,1.56,.64,1);
    animation:fadeUp .6s ease-out backwards;cursor:default;
}
.sc:hover{transform:translateY(-8px) scale(1.02);box-shadow:0 20px 48px var(--sh-s);border-color:var(--bd-d);}
.sc:nth-child(1){animation-delay:.08s}.sc:nth-child(2){animation-delay:.14s}
.sc:nth-child(3){animation-delay:.2s}.sc:nth-child(4){animation-delay:.26s}
.sc::after{content:'';position:absolute;top:0;left:0;right:0;height:50%;background:linear-gradient(180deg,rgba(255,255,255,.6) 0%,transparent 100%);border-radius:20px 20px 0 0;pointer-events:none;}
.sc::before{content:'';position:absolute;top:0;left:0;right:0;height:4px;border-radius:20px 20px 0 0;transition:height .3s;}
.sc:hover::before{height:6px}
.sc.c1::before{background:linear-gradient(90deg,#1D4ED8,#3B82F6)}
.sc.c2::before{background:linear-gradient(90deg,#9B1C1C,#DC2626)}
.sc.c3::before{background:linear-gradient(90deg,#0C6B58,#10B981)}
.sc.c4::before{background:linear-gradient(90deg,#B45309,#F59E0B)}
.sc-top{display:flex;justify-content:space-between;align-items:flex-start;margin-bottom:1.25rem;position:relative;z-index:1}
.sc-lbl{font-size:.65rem;font-weight:700;letter-spacing:.1em;text-transform:uppercase;color:var(--txl);}
.sc-ico{width:48px;height:48px;border-radius:14px;display:flex;align-items:center;justify-content:center;font-size:1.5rem;transition:all .3s cubic-bezier(.34,1.56,.64,1);}
.sc:hover .sc-ico{transform:rotate(-10deg) scale(1.15)}
.sc.c1 .sc-ico{background:linear-gradient(135deg,#DBEAFE,#BFDBFE)}
.sc.c2 .sc-ico{background:linear-gradient(135deg,#FEE2E2,#FECACA)}
.sc.c3 .sc-ico{background:linear-gradient(135deg,#D1FAE5,#A7F3D0)}
.sc.c4 .sc-ico{background:linear-gradient(135deg,#FEF3C7,#FDE68A)}
.sc-val{font-family:'DM Serif Display',serif;font-size:2.75rem;color:var(--tx);line-height:1;margin-bottom:.375rem;position:relative;z-index:1;}
.sc-cap{font-size:.8rem;font-weight:500;color:var(--txm);position:relative;z-index:1;}

/* ══ SECTION HEADER ══ */
.sec-hdr{display:flex;align-items:center;gap:1rem;margin-bottom:1.125rem;}
.sec-orn{width:4px;height:28px;background:linear-gradient(180deg,var(--g),var(--g-d));border-radius:50px;flex-shrink:0;}
.sec-title{font-family:'DM Serif Display',serif;font-size:1.375rem;color:var(--tx);}
.sec-sub{font-size:.8rem;font-weight:500;color:var(--txl);margin-left:auto}

/* ══ MENU GRID ══ */
.menu-grid{
    display:grid;
    grid-template-columns:repeat(4,1fr);
    gap:.875rem;
    margin-bottom:2rem;
}

.mcard{
    background:var(--sf);
    border-radius:14px;
    border:1px solid var(--bd);
    padding:1.125rem 1rem 1rem;
    text-decoration:none;color:var(--tx);
    box-shadow:0 2px 10px var(--sh);
    position:relative;overflow:hidden;
    transition:all .32s cubic-bezier(.34,1.56,.64,1);
    display:flex;flex-direction:column;
    animation:fadeUp .6s ease-out backwards;
}
.mcard::before{
    content:'';position:absolute;top:0;left:0;right:0;
    height:3px;border-radius:14px 14px 0 0;transition:height .3s;
}
.mcard:hover::before{height:5px}
.mcard::after{
    content:'';position:absolute;inset:0;
    background:linear-gradient(135deg,rgba(255,255,255,0) 40%,rgba(255,255,255,.38) 50%,rgba(255,255,255,0) 60%);
    transform:translateX(-200%) skewX(-15deg);transition:transform .55s ease;pointer-events:none;
}
.mcard:hover::after{transform:translateX(300%) skewX(-15deg)}
.mcard:hover{transform:translateY(-6px) scale(1.012);box-shadow:0 18px 40px var(--sh-s);border-color:var(--bd-d);}

.mc1::before{background:linear-gradient(90deg,#4F46E5,#7C3AED)}
.mc2::before{background:linear-gradient(90deg,#0C6B58,#059669)}
.mc3::before{background:linear-gradient(90deg,#1D4ED8,#0EA5E9)}
.mc4::before{background:linear-gradient(90deg,#F97316,#EF4444)}
.mc5::before{background:linear-gradient(90deg,#7C3AED,#EC4899)}
.mc6::before{background:linear-gradient(90deg,#EC4899,#F43F5E)}
.mc7::before{background:linear-gradient(90deg,#F59E0B,#D97706)}
.mc8::before{background:linear-gradient(90deg,#0C6B58,#0EA5E9)}
.mc9::before{background:linear-gradient(90deg,#DC2626,#F97316)}

.mcard:nth-child(1){animation-delay:.07s}.mcard:nth-child(2){animation-delay:.11s}
.mcard:nth-child(3){animation-delay:.15s}.mcard:nth-child(4){animation-delay:.19s}
.mcard:nth-child(5){animation-delay:.23s}.mcard:nth-child(6){animation-delay:.27s}
.mcard:nth-child(7){animation-delay:.31s}.mcard:nth-child(8){animation-delay:.35s}
.mcard:nth-child(9){animation-delay:.39s}

.mcard-ico{
    width:40px;height:40px;border-radius:11px;
    display:flex;align-items:center;justify-content:center;
    font-size:1.35rem;
    margin-bottom:.75rem;
    border:1.5px solid var(--bd);background:var(--sf2);
    transition:all .35s cubic-bezier(.34,1.56,.64,1);
    position:relative;z-index:1;flex-shrink:0;
}
.mcard:hover .mcard-ico{transform:scale(1.18) rotate(-8deg);border-color:transparent;}
.mc1:hover .mcard-ico{background:linear-gradient(135deg,#EEF2FF,#E0E7FF)}
.mc2:hover .mcard-ico{background:linear-gradient(135deg,#ECFDF5,#D1FAE5)}
.mc3:hover .mcard-ico{background:linear-gradient(135deg,#EFF6FF,#DBEAFE)}
.mc4:hover .mcard-ico{background:linear-gradient(135deg,#FFF7ED,#FFEDD5)}
.mc5:hover .mcard-ico{background:linear-gradient(135deg,#F5F3FF,#EDE9FE)}
.mc6:hover .mcard-ico{background:linear-gradient(135deg,#FFF1F2,#FFE4E6)}
.mc7:hover .mcard-ico{background:linear-gradient(135deg,#FFFBEB,#FEF3C7)}
.mc8:hover .mcard-ico{background:linear-gradient(135deg,#F0FDFA,#CCFBF1)}
.mc9:hover .mcard-ico{background:linear-gradient(135deg,#FEF2F2,#FEE2E2)}

.mcard-name{
    font-family:'DM Serif Display',serif;
    font-size:.95rem;color:var(--tx);
    margin-bottom:.3rem;
    position:relative;z-index:1;transition:color .2s;
    line-height:1.25;
}
.mcard:hover .mcard-name{color:var(--ob)}

.mcard-desc{
    font-size:.75rem;font-weight:400;color:var(--txm);
    line-height:1.5;flex:1;
    position:relative;z-index:1;
    display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;
}

.mcard-cta{
    display:inline-flex;align-items:center;gap:.375rem;
    margin-top:.75rem;
    padding:.35rem .9rem;border-radius:50px;
    font-size:.7rem;font-weight:700;letter-spacing:.04em;
    background:var(--sf2);border:1.5px solid var(--bd);color:var(--txm);
    transition:all .25s cubic-bezier(.34,1.56,.64,1);
    align-self:flex-start;position:relative;z-index:1;
}
.mcard:hover .mcard-cta{padding-right:1.25rem;border-color:transparent;color:white;}
.mc1:hover .mcard-cta{background:linear-gradient(135deg,#4F46E5,#7C3AED);box-shadow:0 3px 12px rgba(79,70,229,.3)}
.mc2:hover .mcard-cta{background:linear-gradient(135deg,#0C6B58,#059669);box-shadow:0 3px 12px rgba(12,107,88,.3)}
.mc3:hover .mcard-cta{background:linear-gradient(135deg,#1D4ED8,#0EA5E9);box-shadow:0 3px 12px rgba(29,78,216,.3)}
.mc4:hover .mcard-cta{background:linear-gradient(135deg,#F97316,#EF4444);box-shadow:0 3px 12px rgba(249,115,22,.3)}
.mc5:hover .mcard-cta{background:linear-gradient(135deg,#7C3AED,#EC4899);box-shadow:0 3px 12px rgba(124,58,237,.3)}
.mc6:hover .mcard-cta{background:linear-gradient(135deg,#EC4899,#F43F5E);box-shadow:0 3px 12px rgba(236,72,153,.3)}
.mc7:hover .mcard-cta{background:linear-gradient(135deg,#F59E0B,#D97706);box-shadow:0 3px 12px rgba(245,158,11,.3)}
.mc8:hover .mcard-cta{background:linear-gradient(135deg,#0C6B58,#0EA5E9);box-shadow:0 3px 12px rgba(14,165,233,.3)}
.mc9:hover .mcard-cta{background:linear-gradient(135deg,#DC2626,#F97316);box-shadow:0 3px 12px rgba(220,38,38,.3)}

/* ══ FOOTER ══ */
.foot-zone{
    background:var(--sf);border-radius:20px;border:1px solid var(--bd);
    padding:2rem 2.5rem;display:flex;align-items:center;
    justify-content:space-between;gap:1.5rem;flex-wrap:wrap;
    box-shadow:0 2px 12px var(--sh);margin-bottom:2rem;
    animation:fadeUp .6s .5s ease-out backwards;
}
.foot-info{display:flex;align-items:center;gap:1rem}
.foot-seal{width:52px;height:52px;border-radius:50%;background:var(--ob);border:2px solid var(--g-d);display:flex;align-items:center;justify-content:center;overflow:hidden;flex-shrink:0;box-shadow:0 4px 12px rgba(0,0,0,.15);}
.foot-seal img{width:34px;height:34px;object-fit:contain}
.foot-txt-title{font-family:'DM Serif Display',serif;font-size:1rem;color:var(--tx);margin-bottom:.1rem;}
.foot-txt-sub{font-size:.75rem;font-weight:500;color:var(--txl)}
.foot-acts{display:flex;gap:.875rem;align-items:center}
.btn-logout{
    display:flex;align-items:center;gap:.625rem;padding:.8rem 1.75rem;
    background:linear-gradient(135deg,#9B1C1C,#B91C1C);color:white;border:none;border-radius:12px;
    font-size:.825rem;font-weight:700;letter-spacing:.04em;
    font-family:'Outfit',sans-serif;text-decoration:none;cursor:pointer;
    box-shadow:0 4px 16px rgba(155,28,28,.25);transition:all .28s cubic-bezier(.34,1.56,.64,1);
}
.btn-logout:hover{transform:translateY(-3px);box-shadow:0 8px 24px rgba(155,28,28,.35);}
.foot-copy{font-size:.72rem;font-weight:500;color:var(--txl);letter-spacing:.04em;}

@keyframes fadeUp{from{opacity:0;transform:translateY(24px)}to{opacity:1;transform:translateY(0)}}

/* ══════════════════════════════════════
   RESPONSIVE BREAKPOINTS
══════════════════════════════════════ */

/* ── Large Desktop (1280–1400) ── */
@media(max-width:1400px){
    .wrap{padding:1.75rem 2rem}
}

/* ── Medium Desktop / Tablet Landscape (1024–1280) ── */
@media(max-width:1280px){
    .srow{grid-template-columns:1fr 1fr}
    .menu-grid{grid-template-columns:repeat(3,1fr)}
}

/* ── Small Desktop (900–1024) ── */
@media(max-width:1024px){
    :root{--sw:240px}
    .menu-grid{grid-template-columns:repeat(3,1fr)}
    .hero-name{font-size:2rem}
    .hero-content{padding:2rem}
    .hero-stat{min-width:95px;padding:1rem 1.25rem}
    .hero-stat-n{font-size:1.875rem}
}

/* ── Tablet Portrait (768–900) ── */
@media(max-width:900px){
    .menu-grid{grid-template-columns:repeat(2,1fr)}
    .srow{grid-template-columns:1fr 1fr}
    .hero-r{gap:.75rem}
}

/* ── Mobile / Tablet (≤768) — Sidebar becomes drawer ── */
@media(max-width:768px){
    /* Show topbar, hide old toggle */
    .topbar{display:flex}
    .sb-overlay{display:block}

    /* Sidebar becomes off-canvas drawer */
    .sb{transform:translateX(-100%)}
    .sb.open{transform:translateX(0)}

    /* Push main below topbar */
    .main{margin-left:0;padding-top:60px}
    .wrap{padding:1.25rem 1rem}

    /* Hero adjustments */
    .hero{border-radius:18px;min-height:auto}
    .hero-content{
        padding:1.5rem;flex-direction:column;
        align-items:flex-start;gap:1.25rem;
    }
    .hero-name{font-size:1.75rem}
    .hero-sub{margin-bottom:.75rem}
    .hero-meta{gap:.875rem}
    .hero-r{
        width:100%;display:grid;
        grid-template-columns:repeat(3,1fr);gap:.625rem;
    }
    .hero-stat{min-width:unset;padding:.875rem .75rem;}
    .hero-stat-n{font-size:1.625rem}

    /* Stat cards — 2 col */
    .srow{grid-template-columns:1fr 1fr;gap:.875rem}
    .sc{padding:1.25rem 1.25rem}
    .sc-val{font-size:2.25rem}
    .sc-ico{width:40px;height:40px;font-size:1.25rem}

    /* Menu grid — 2 col */
    .menu-grid{grid-template-columns:repeat(2,1fr);gap:.75rem}

    /* Section header */
    .sec-sub{display:none}

    /* Footer */
    .foot-zone{padding:1.5rem;flex-direction:column;align-items:flex-start;gap:1.25rem}
    .foot-acts{width:100%;justify-content:space-between}
    .btn-logout{padding:.75rem 1.25rem;font-size:.78rem}
}

/* ── Small Mobile (≤480) ── */
@media(max-width:480px){
    .wrap{padding:1rem .875rem}

    /* Hero */
    .hero{border-radius:16px}
    .hero-content{padding:1.25rem}
    .hero-name{font-size:1.5rem}
    .hero-eyebrow{font-size:.6rem;padding:.3rem .75rem}
    .hero-meta-item{font-size:.72rem}
    /* Keep 3 stat boxes in a row but smaller */
    .hero-r{gap:.5rem}
    .hero-stat{padding:.75rem .5rem}
    .hero-stat-n{font-size:1.375rem}
    .hero-stat-l{font-size:.52rem}

    /* Stat cards — 2 col, tighter */
    .srow{grid-template-columns:1fr 1fr;gap:.625rem}
    .sc{padding:1rem}
    .sc-val{font-size:2rem}
    .sc-ico{width:36px;height:36px;font-size:1.1rem;border-radius:10px}
    .sc-top{margin-bottom:.875rem}

    /* Menu — 2 col */
    .menu-grid{grid-template-columns:1fr 1fr;gap:.625rem}
    .mcard{padding:.875rem .875rem .875rem}
    .mcard-ico{width:36px;height:36px;font-size:1.2rem;border-radius:9px;margin-bottom:.5rem}
    .mcard-name{font-size:.88rem}
    .mcard-desc{font-size:.7rem;-webkit-line-clamp:2}
    .mcard-cta{font-size:.65rem;padding:.3rem .75rem;margin-top:.5rem}

    /* Footer */
    .foot-zone{padding:1.25rem;border-radius:16px}
    .foot-txt-title{font-size:.9rem}
}

/* ── Very small (≤360) — single col menu ── */
@media(max-width:360px){
    .menu-grid{grid-template-columns:1fr}
    .srow{grid-template-columns:1fr 1fr}
    .hero-r{grid-template-columns:repeat(3,1fr)}
}
</style>
</head>
<body>

<!-- Loader -->
<div class="loader" id="ldr">
    <div class="loader-ring">
        <div class="loader-inner">
            <img src="assets/sekolah.png" alt="" onerror="this.parentNode.innerHTML='🏛'">
        </div>
    </div>
    <div class="loader-txt">Memuat Dashboard</div>
    <div class="loader-dots">
        <div class="loader-dot"></div>
        <div class="loader-dot"></div>
        <div class="loader-dot"></div>
    </div>
</div>

<!-- Topbar (mobile) -->
<div class="topbar">
    <div class="topbar-brand">
        <div class="topbar-logo">
            <img src="assets/sekolah.png" alt="" onerror="this.parentNode.innerHTML='🏛'">
        </div>
        <div class="topbar-name">MA As-Syafi'iyah 02</div>
    </div>
    <div class="mob-toggle" id="menuToggle">☰</div>
</div>

<!-- Sidebar overlay (mobile backdrop) -->
<div class="sb-overlay" id="sbOverlay"></div>

<!-- SIDEBAR -->
<aside class="sb" id="sidebar">
    <div class="sb-brand">
        <div class="sb-logo">
            <img src="assets/sekolah.png" alt="" onerror="this.parentNode.innerHTML='🏛'">
        </div>
        <div class="sb-brand-tx">
            <div class="sb-name">MA As-Syafi'iyah 02</div>
            <div class="sb-short">Portal Akademik</div>
        </div>
    </div>

    <nav class="sb-nav">
        <div class="sb-sec-lbl">Dashboard</div>
        <a href="#" class="nav-a on">
            <div class="nav-ico">📊</div>Overview
        </a>

        <div class="sb-sec-lbl">Manajemen Data</div>
        <a href="surat.php" class="nav-a"><div class="nav-ico">📄</div>Arsip Surat</a>
        <a href="siswa.php" class="nav-a"><div class="nav-ico">👨‍🎓</div>Buku Induk Siswa</a>
        <a href="guru.php" class="nav-a"><div class="nav-ico">👨‍🏫</div>Data Guru</a>
        <a href="kelas.php" class="nav-a"><div class="nav-ico">🏫</div>Data Kelas</a>
        <a href="mata_pelajaran.php" class="nav-a"><div class="nav-ico">📚</div>Mata Pelajaran</a>

        <div class="sb-sec-lbl">Akademik</div>
        <a href="absensi.php" class="nav-a"><div class="nav-ico">✅</div>Absensi Siswa</a>
        <a href="nilai.php" class="nav-a"><div class="nav-ico">📝</div>Nilai Siswa</a>

        <div class="sb-sec-lbl">Keuangan</div>
        <a href="spp.php" class="nav-a"><div class="nav-ico">💰</div>Pembayaran SPP</a>

        <div class="sb-sec-lbl">Laporan</div>
        <a href="laporan.php" class="nav-a"><div class="nav-ico">📈</div>Statistik</a>

        <?php if($user_role==='admin'): ?>
        <div class="sb-sec-lbl">Sistem</div>
        <a href="user.php" class="nav-a"><div class="nav-ico">🔐</div>Manajemen User</a>
        <a href="pengaturan.php" class="nav-a"><div class="nav-ico">⚙️</div>Pengaturan</a>
        <?php endif; ?>
    </nav>

    <div class="sb-foot">
        <div class="sb-user">
            <div class="sb-uav">
                <?php if(!empty($_SESSION['foto'])&&file_exists($_SESSION['foto'])): ?>
                <img src="<?=htmlspecialchars($_SESSION['foto'])?>" alt="">
                <?php else: ?>👤<?php endif; ?>
            </div>
            <div>
                <div class="sb-uname"><?=htmlspecialchars($user_name)?></div>
                <span class="sb-urole"><?=strtoupper($user_role)?></span>
            </div>
        </div>
        <a href="logout.php" class="logout-btn" onclick="return confirm('Yakin ingin keluar?')">
            🚪 &nbsp;Keluar dari Sistem
        </a>
    </div>
</aside>

<!-- MAIN -->
<div class="main">
<div class="wrap">

    <!-- HERO -->
    <header class="hero">
        <div class="hero-mesh"></div>
        <div class="hero-lines"></div>
        <div class="hero-content">
            <div class="hero-l">
                <div class="hero-eyebrow"><?=$ico?> <?=$salam?> · Admin Panel</div>
                <h1 class="hero-name">
                    Halo, <span><?=htmlspecialchars($user_name)?></span> 👋
                </h1>
                <p class="hero-sub"><?=$mood?></p>
                <div class="hero-meta">
                    <div class="hero-meta-item">📅 <strong><?=$tanggal_full?></strong></div>
                    <div class="hero-meta-item">🏫 <strong>MA As-Syafi'iyah 02 Bekasi</strong></div>
                </div>
            </div>
            <div class="hero-r">
                <div class="hero-stat">
                    <div class="hero-stat-n"><?=$total_siswa?></div>
                    <div class="hero-stat-l">Siswa Aktif</div>
                </div>
                <div class="hero-stat">
                    <div class="hero-stat-n"><?=$persen_bayar?>%</div>
                    <div class="hero-stat-l">SPP Lunas</div>
                </div>
                <div class="hero-stat">
                    <div class="hero-stat-n"><?=$total_surat?></div>
                    <div class="hero-stat-l">Total Surat</div>
                </div>
            </div>
        </div>
    </header>

    <!-- STAT CARDS -->
    <div class="srow">
        <div class="sc c1">
            <div class="sc-top">
                <div class="sc-lbl">Siswa Aktif</div>
                <div class="sc-ico">👥</div>
            </div>
            <div class="sc-val"><?=$total_siswa?></div>
            <div class="sc-cap">Terdaftar di sistem</div>
        </div>
        <div class="sc c2">
            <div class="sc-top">
                <div class="sc-lbl">Arsip Surat</div>
                <div class="sc-ico">📬</div>
            </div>
            <div class="sc-val"><?=$total_surat?></div>
            <div class="sc-cap">Dokumen tersimpan</div>
        </div>
        <div class="sc c3">
            <div class="sc-top">
                <div class="sc-lbl">SPP Lunas</div>
                <div class="sc-ico">💳</div>
            </div>
            <div class="sc-val"><?=$persen_bayar?>%</div>
            <div class="sc-cap">Bulan <?=$bulan_arr[(int)date('m')]?> <?=date('Y')?></div>
        </div>
        <div class="sc c4">
            <div class="sc-top">
                <div class="sc-lbl">Siswa Baru</div>
                <div class="sc-ico">⭐</div>
            </div>
            <div class="sc-val"><?=$siswa_baru?></div>
            <div class="sc-cap">Daftar hari ini</div>
        </div>
    </div>

    <!-- MENU SECTION -->
    <div class="sec-hdr">
        <div class="sec-orn"></div>
        <div class="sec-title">Menu Utama</div>
        <div class="sec-sub">Pilih modul yang ingin dikelola</div>
    </div>

    <div class="menu-grid">
        <a href="surat.php" class="mcard mc1">
            <div class="mcard-ico">📬</div>
            <div class="mcard-name">Arsip Surat</div>
            <div class="mcard-desc">Kelola surat masuk & keluar, pantau status dokumen, dan arsipkan persuratan sekolah</div>
            <div class="mcard-cta">Buka →</div>
        </a>
        <a href="spp.php" class="mcard mc2">
            <div class="mcard-ico">💰</div>
            <div class="mcard-name">Pembayaran SPP</div>
            <div class="mcard-desc">Pantau dan catat pembayaran SPP siswa secara real-time dengan laporan lengkap</div>
            <div class="mcard-cta">Buka →</div>
        </a>
        <a href="siswa.php" class="mcard mc3">
            <div class="mcard-ico">👨‍🎓</div>
            <div class="mcard-name">Buku Induk Siswa</div>
            <div class="mcard-desc">Kelola biodata, data orang tua, dan informasi akademik seluruh siswa sekolah</div>
            <div class="mcard-cta">Buka →</div>
        </a>
        <a href="absensi.php" class="mcard mc4">
            <div class="mcard-ico">✅</div>
            <div class="mcard-name">Absensi Siswa</div>
            <div class="mcard-desc">Catat dan pantau kehadiran siswa setiap hari dengan sistem absensi terintegrasi</div>
            <div class="mcard-cta">Buka →</div>
        </a>
        <a href="kelas.php" class="mcard mc5">
            <div class="mcard-ico">🏫</div>
            <div class="mcard-name">Data Kelas</div>
            <div class="mcard-desc">Kelola kelas, wali kelas, dan pembagian siswa per kelas secara mudah</div>
            <div class="mcard-cta">Buka →</div>
        </a>
        <a href="mata_pelajaran.php" class="mcard mc6">
            <div class="mcard-ico">📚</div>
            <div class="mcard-name">Mata Pelajaran</div>
            <div class="mcard-desc">Atur daftar mata pelajaran, kurikulum, KKM, dan jadwal pelajaran sekolah</div>
            <div class="mcard-cta">Buka →</div>
        </a>
        <a href="nilai.php" class="mcard mc7">
            <div class="mcard-ico">📝</div>
            <div class="mcard-name">Nilai Siswa</div>
            <div class="mcard-desc">Input, kelola, dan cetak nilai akademik setiap semester dengan cepat dan praktis</div>
            <div class="mcard-cta">Buka →</div>
        </a>
        <a href="laporan.php" class="mcard mc8">
            <div class="mcard-ico">📊</div>
            <div class="mcard-name">Laporan & Statistik</div>
            <div class="mcard-desc">Lihat laporan lengkap, grafik, dan statistik dari seluruh aktivitas sistem</div>
            <div class="mcard-cta">Buka →</div>
        </a>
        <?php if($user_role==='admin'): ?>
        <a href="user.php" class="mcard mc9">
            <div class="mcard-ico">🔐</div>
            <div class="mcard-name">Manajemen Pengguna</div>
            <div class="mcard-desc">Kelola username, password & hak akses Admin, Guru dan Staff TU sistem</div>
            <div class="mcard-cta">Buka →</div>
        </a>
        <?php endif; ?>
    </div>

    <!-- FOOTER ZONE -->
    <div class="foot-zone">
        <div class="foot-info">
            <div class="foot-seal">
                <img src="assets/sekolah.png" alt="" onerror="this.parentNode.innerHTML='🏛'">
            </div>
            <div>
                <div class="foot-txt-title">MA As-Syafi'iyah 02 Bekasi</div>
                <div class="foot-txt-sub">Sistem Informasi Akademik &nbsp;·&nbsp; <?=date('Y')?></div>
            </div>
        </div>
        <div class="foot-acts">
            <div class="foot-copy">Dibuat dengan ❤️ dan ☕</div>
            <a href="logout.php" class="btn-logout" onclick="return confirm('Yakin ingin keluar?')">
                🚪 Keluar
            </a>
        </div>
    </div>

</div><!-- /wrap -->
</div><!-- /main -->

<script>
// ── Loader ──
window.addEventListener('load', () => {
    setTimeout(() => document.getElementById('ldr').classList.add('gone'), 700);
});

// ── Sidebar toggle (mobile) ──
const sidebar   = document.getElementById('sidebar');
const overlay   = document.getElementById('sbOverlay');
const menuToggle = document.getElementById('menuToggle');

function openSidebar() {
    sidebar.classList.add('open');
    overlay.classList.add('show');
    menuToggle.textContent = '✕';
}
function closeSidebar() {
    sidebar.classList.remove('open');
    overlay.classList.remove('show');
    menuToggle.textContent = '☰';
}

menuToggle.addEventListener('click', () => {
    sidebar.classList.contains('open') ? closeSidebar() : openSidebar();
});

// Close on overlay click
overlay.addEventListener('click', closeSidebar);

// Close when a nav link is tapped on mobile
sidebar.querySelectorAll('.nav-a').forEach(link => {
    link.addEventListener('click', () => {
        if (window.innerWidth <= 768) closeSidebar();
    });
});

// Close on resize back to desktop
window.addEventListener('resize', () => {
    if (window.innerWidth > 768) closeSidebar();
});
</script>
</body>
</html>