/* 1. IMPORT FONT */
@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;600;700;800&display=swap');

/* 2. GLOBAL RESET & PALETTE
   Neutral slate grays for structure, ONE blue accent for things you interact with. */
:root {
    --ink:          #0f172a; /* all text & headings */
    --muted:        #64748b; /* secondary text */
    --primary:      #2563eb; /* the ONE accent color */
    --primary-dark: #1d4ed8; /* hover */
    --primary-soft: #eff6ff; /* very light accent background */
    --navy:         #0f172a; /* top bar */
    --navy-2:       #1e3a8a; /* top bar gradient end */
    --bg:           #f1f5f9; /* page background */
    --border:       #e2e8f0; /* borders & dividers */
    --surface:      #ffffff; /* cards & inputs */
    --shadow:       0 10px 30px rgba(15, 23, 42, 0.06);
}

* {
    box-sizing: border-box;
}

body {
    font-family: 'Cairo', sans-serif;
    background-color: var(--bg);
    color: var(--ink);
    direction: rtl;
    margin: 0;
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
}

/* 3. CONTAINERS (FITS PHONES PERFECTLY) */
.form-container, .result-container, .table-container {
    background-color: var(--surface);
    width: 100%;
    max-width: 700px;
    padding: 32px 28px;
    border-radius: 16px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    margin: 30px auto 20px auto;
}
.form-container.wide { max-width: 900px; }

/* Titles */
h2 {
    color: var(--ink);
    font-weight: 800;
    font-size: 24px;
    text-align: center;
    margin-top: 0;
    margin-bottom: 25px;
}
h2::after {
    content: "";
    display: block;
    width: 48px;
    height: 4px;
    background: var(--primary);
    border-radius: 4px;
    margin: 10px auto 0 auto;
}

/* 4. FORM FIELDS & LABELS */
.form-group {
    margin-bottom: 20px;
}

label {
    display: block;
    margin-bottom: 8px;
    font-weight: 700;
    color: var(--ink);
    font-size: 14px;
}

input[type="text"],
input[type="password"],
input[type="date"],
input[type="number"],
input[type="email"],
select {
    width: 100%;
    padding: 12px 14px;
    border: 2px solid var(--border);
    border-radius: 10px;
    font-family: 'Cairo', sans-serif;
    font-size: 16px;
    color: var(--ink);
    background-color: #f8fafc;
    transition: border-color 0.2s, box-shadow 0.2s, background-color 0.2s;
}

input[type="text"]:focus,
input[type="password"]:focus,
input[type="date"]:focus,
input[type="email"]:focus,
select:focus {
    outline: none;
    border-color: var(--primary);
    background-color: var(--surface);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12);
}

/* 5. UNIFIED BUTTONS */
button[type="submit"]:not(.btn):not(.choice),
.btn-menu,
.btn-primary {
    display: block;
    width: 100%;
    padding: 14px;
    background-color: var(--primary);
    color: var(--surface);
    border: none;
    border-radius: 10px;
    font-size: 16px;
    font-weight: 700;
    font-family: 'Cairo', sans-serif;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    box-sizing: border-box;
    margin-top: 10px;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.25);
    transition: background-color 0.2s, transform 0.2s;
}

button[type="submit"]:not(.btn):not(.choice):hover,
.btn-menu:hover,
.btn-primary:hover {
    background-color: var(--primary-dark);
    text-decoration: none;
}

/* Links */
a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
}
a:hover {
    text-decoration: underline;
}

/* Dividers */
hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 25px 0;
}

/* 6. TABLES */
table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 15px;
}

th, td {
    padding: 12px 10px;
    border-bottom: 1px solid var(--border);
    text-align: right;
    font-size: 14px;
}

th {
    font-weight: 700;
    color: #475569;
    background-color: #f1f5f9;
}

/* -------------------------------------------------- */
/* 📱 MOBILE SCREEN FIX (Strictly for phones)        */
/* -------------------------------------------------- */
@media screen and (max-width: 600px) {
    body {
        padding: 0 !important;
        background-color: var(--surface) !important;
    }

    .form-container, .result-container, .table-container {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding: 20px 15px !important;
        border-radius: 0 !important;
        border: none !important;
        box-shadow: none !important;
        min-height: 100vh;
        box-sizing: border-box;
    }

    h2 {
        font-size: 22px !important;
    }

    input[type="text"], input[type="date"], input[type="number"], select {
        font-size: 16px !important;
        padding: 14px !important;
    }
}

/* ================================================== */
/* NAVIGATION: top menu (sections) + sidebar (sub menu) */
/* ================================================== */
.topbar {
    position: fixed; top: 0; left: 0; right: 0; height: 64px;
    background: linear-gradient(90deg, var(--navy), var(--navy-2));
    color: #fff;
    display: flex; align-items: center; gap: 18px;
    padding: 0 22px; z-index: 900;
    box-shadow: 0 4px 16px rgba(15, 23, 42, 0.18);
}
.topbar a { text-decoration: none; }
.topbar a:hover { text-decoration: none; }

.topbar .brand { display: flex; align-items: center; gap: 12px; color: #fff; font-weight: 800; font-size: 18px; white-space: nowrap; }
.topbar .brand img { height: 42px; width: auto; background: #fff; border-radius: 10px; padding: 3px; }

.topnav { display: flex; align-items: center; gap: 6px; margin-right: 10px; }
.topnav a {
    color: rgba(255, 255, 255, 0.82);
    padding: 9px 18px; border-radius: 999px;
    font-weight: 700; font-size: 15px; white-space: nowrap;
    transition: background-color 0.2s, color 0.2s;
}
.topnav a:hover { background: rgba(255, 255, 255, 0.14); color: #fff; }
.topnav a.active { background: #fff; color: var(--navy-2); }

.topbar-user { margin-inline-start: auto; display: flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 600; }
.user-chip { background: rgba(255, 255, 255, 0.14); padding: 7px 14px; border-radius: 999px; white-space: nowrap; color: #fff; cursor: pointer; transition: background-color 0.2s; }
.user-chip:hover { background: rgba(255, 255, 255, 0.24); }
.topbar .logout-link { background: #ef4444; color: #fff; padding: 7px 16px; border-radius: 999px; font-size: 13px; font-weight: 700; }
.topbar .logout-link:hover { background: #dc2626; }

.menu-toggle { display: none; background: rgba(255, 255, 255, 0.14); border: none; color: #fff; font-size: 22px; width: 40px; height: 40px; border-radius: 10px; cursor: pointer; }

.sidebar {
    position: fixed; top: 64px; right: 0; bottom: 0; width: 240px;
    background: var(--surface); border-left: 1px solid var(--border);
    padding: 22px 14px; overflow-y: auto; z-index: 800;
    display: flex; flex-direction: column; gap: 6px;
}
.side-title { font-size: 13px; font-weight: 800; color: var(--muted); padding: 0 12px 10px 12px; letter-spacing: 0.3px; }
.sidebar a {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 14px; border-radius: 12px;
    color: #334155; font-weight: 700; font-size: 15px; text-decoration: none;
    transition: background-color 0.2s, color 0.2s;
}
.sidebar a span { font-size: 18px; }
.sidebar a:hover { background: var(--primary-soft); color: var(--primary); text-decoration: none; }
.sidebar a.active { background: #dbeafe; color: var(--primary-dark); box-shadow: inset -4px 0 0 var(--primary); }

body.has-nav { padding: 84px 20px 20px 20px !important; }
body.has-nav.with-side { padding-right: 260px !important; }

/* Tablet & phone: menu wraps to a second row, sidebar becomes a drawer */
@media screen and (max-width: 900px) {
    .topbar { height: auto; flex-wrap: wrap; padding: 8px 14px; gap: 8px; }
    .topnav { order: 3; width: 100%; margin: 0; overflow-x: auto; padding-bottom: 4px; }
    .topnav a { padding: 8px 14px; font-size: 14px; }
    .menu-toggle { display: block; }
    .sidebar { top: 112px; transform: translateX(100%); transition: transform 0.2s; box-shadow: none; }
    .sidebar.open { transform: none; box-shadow: -8px 0 24px rgba(15, 23, 42, 0.18); }
    body.has-nav, body.has-nav.with-side { padding: 118px 0 0 0 !important; }
}
@media screen and (max-width: 600px) {
    .user-chip { display: none; }
    .topbar .brand { font-size: 16px; }
}
@media print {
    .topbar, .sidebar { display: none !important; }
    body.has-nav, body.has-nav.with-side { padding: 0 !important; }
}

/* ===== DASHBOARD CARDS (index.php) ===== */
.dash-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-top: 20px; }
.dash-card {
    display: flex; flex-direction: column; align-items: center; gap: 10px;
    padding: 28px 16px; background: var(--surface);
    border: 1px solid var(--border); border-radius: 16px;
    color: var(--ink); font-weight: 700; font-size: 17px; text-decoration: none;
    transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
}
.dash-card .ic { font-size: 36px; }
.dash-card:hover { transform: translateY(-4px); box-shadow: 0 12px 28px rgba(37, 99, 235, 0.15); border-color: var(--primary); text-decoration: none; }

/* ===== STUDENT STATUS BADGE ===== */
.badge { display: inline-block; padding: 2px 12px; border-radius: 999px; font-size: 13px; font-weight: 700; }
.badge-active { background: #dcfce7; color: #166534; }
.badge-inactive { background: #fee2e2; color: #991b1b; }

/* ================================================== */
/* PLATFORM: shared page building blocks              */
/* ================================================== */
.page { width: 100%; max-width: 1150px; margin: 0 auto; }
.page.narrow { max-width: 720px; }
.page.wide { max-width: 1400px; }
body.plain { justify-content: center; min-height: 100vh; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); padding: 28px; margin-bottom: 22px; }
.card h2 { margin-bottom: 20px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.card-head h2 { margin: 0; text-align: right; }
.card-head h2::after { margin: 10px 0 0 auto; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 18px; border-radius: 10px; border: none; cursor: pointer; font-family: 'Cairo', sans-serif; font-weight: 700; font-size: 15px; text-decoration: none; background: var(--primary); color: #fff; transition: background-color .2s; }
.btn:hover { background: var(--primary-dark); text-decoration: none; }
.btn-success { background: #16a34a; } .btn-success:hover { background: #15803d; }
.btn-muted { background: #64748b; } .btn-muted:hover { background: #475569; }
.btn-danger { background: #dc2626; } .btn-danger:hover { background: #b91c1c; }
.btn-light { background: var(--primary-soft); color: var(--primary); } .btn-light:hover { background: #dbeafe; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

.alert { padding: 14px 18px; border-radius: 12px; margin-bottom: 18px; font-weight: 700; }
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert-info { background: var(--primary-soft); color: #1e3a8a; border: 1px solid #bfdbfe; }

.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 18px; }
.form-grid .full { grid-column: 1 / -1; }
.money-input { display: flex; direction: ltr; }
.money-input input { border-radius: 10px 0 0 10px !important; text-align: right; }
.money-input span { background: #e2e8f0; border: 2px solid #e2e8f0; border-radius: 0 10px 10px 0; padding: 0 14px; display: flex; align-items: center; font-weight: 700; color: #475569; }
input[type="file"] { font-family: 'Cairo', sans-serif; }
input[readonly] { background: #e9eef5 !important; }
.form-section { font-size: 15px; font-weight: 800; color: var(--muted); margin: 6px 0 14px 0; padding-bottom: 6px; border-bottom: 1px solid var(--border); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 18px; text-align: center; border-top: 4px solid var(--primary); }
.stat-card.green { border-top-color: #16a34a; } .stat-card.red { border-top-color: #dc2626; } .stat-card.amber { border-top-color: #d97706; }
.stat-card .label { color: var(--muted); font-weight: 700; font-size: 14px; }
.stat-card .value { font-size: 26px; font-weight: 800; margin-top: 4px; }
.stat-card.green .value { color: #16a34a; } .stat-card.red .value { color: #dc2626; }

.table-wrap { overflow-x: auto; }
table.data th { white-space: nowrap; }
table.data tr[data-row]:hover { background: #f8fafc; }
.balance-red { color: #dc2626; font-weight: 800; } .balance-green { color: #16a34a; font-weight: 800; } .balance-orange { color: #d97706; font-weight: 800; }
.search-input { width: 100%; padding: 14px 18px; border: 2px solid var(--border); border-radius: 12px; font-family: 'Cairo', sans-serif; font-size: 17px; margin-bottom: 8px; }
.search-input:focus { outline: none; border-color: var(--primary); }

.info-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 22px; }
.info-item { background: #f8fafc; border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.info-item .k { font-size: 13px; color: var(--muted); font-weight: 700; }
.info-item .v { font-size: 16px; font-weight: 800; margin-top: 2px; }
.avatar { width: 84px; height: 84px; border-radius: 50%; object-fit: cover; background: #e0e7ff; color: #3730a3; display: inline-flex; align-items: center; justify-content: center; font-weight: 800; font-size: 32px; flex-shrink: 0; }
.profile-top { display: flex; gap: 18px; align-items: center; }

.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(15,