/* =========================================================
   Kayron Junior School - design system (v3)
   Mobile first. Works on phones, tablets and desktops.
   ========================================================= */

:root {
    --navy: #0b2a55;
    --navy-2: #123a72;
    --sky: #00a8f0;
    --blue: #0a6cff;
    --blue-dark: #0852cc;
    --ink: #1c2433;
    --muted: #667085;
    --line: #dfe5ee;
    --bg: #f3f6fb;
    --card: #ffffff;
    --good: #12805c;
    --good-bg: #e7f6ef;
    --warn: #b76e00;
    --warn-bg: #fff4e0;
    --bad: #b42318;
    --bad-bg: #fdecea;
    --radius: 14px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 14px rgba(16, 24, 40, .05);
}

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

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    color: var(--ink);
    background: var(--bg);
}

h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; color: var(--navy); }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .75em; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
.muted { color: var(--muted); }
.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.empty { color: var(--muted); padding: 24px 0; text-align: center; }

/* ---------- App shell: top bar, menu, content ---------- */
.topbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 10px 16px;
    background: linear-gradient(90deg, var(--navy), var(--navy-2));
    color: #fff;
    box-shadow: 0 2px 10px rgba(0,0,0,.18);
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; font-size: 1rem; }
.brand:hover { text-decoration: none; }
.brand img { width: 40px; height: 40px; border-radius: 10px; background: #fff; object-fit: contain; }
.userbox { display: flex; align-items: center; gap: 12px; font-size: .9rem; }
.userbox .who { opacity: .85; }
.logout { color: #fff; border: 1px solid rgba(255,255,255,.5); padding: 6px 12px; border-radius: 999px; }
.logout:hover { background: rgba(255,255,255,.12); text-decoration: none; }

.shell { display: block; }
.nav {
    background: var(--card);
    border-bottom: 1px solid var(--line);
}
.nav-details summary {
    list-style: none; cursor: pointer;
    padding: 12px 16px; font-weight: 600; color: var(--navy);
}
.nav-details summary::-webkit-details-marker { display: none; }
.nav-details summary::after { content: "\25BE"; float: right; color: var(--muted); }
.nav-details[open] summary::after { content: "\25B4"; }
.nav-details ul {
    list-style: none; margin: 0; padding: 4px 8px 12px;
    display: grid; grid-template-columns: 1fr 1fr; gap: 6px;
}
.nav-details li a {
    display: block; padding: 10px 12px; border-radius: 10px;
    color: var(--ink); background: #f6f8fc; font-size: .95rem;
}
.nav-details li a.active { background: var(--blue); color: #fff; }
.nav-details li a:hover { text-decoration: none; background: #e9f0fb; }
.nav-details li a.active:hover { background: var(--blue-dark); }

.main { padding: 16px; max-width: 1180px; margin: 0 auto; width: 100%; }
.foot { text-align: center; color: var(--muted); font-size: .85rem; padding: 24px 16px; }

/* ---------- Dashboard ---------- */
.welcome { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.welcome h1 { margin: 0; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 16px; }
.stat {
    background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 14px 16px; border-left: 5px solid var(--navy);
}
.stat span { display: block; color: var(--muted); font-size: .85rem; }
.stat strong { display: block; font-size: 1.35rem; color: var(--navy); margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat.good { border-left-color: var(--good); }
.stat.warn { border-left-color: var(--warn); }

.card-block {
    background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 18px; margin-bottom: 16px;
}
.card-block h2 { margin-bottom: 12px; }

.actions { display: grid; grid-template-columns: 1fr; gap: 10px; }
.action {
    display: block; padding: 16px; border-radius: 12px;
    background: linear-gradient(135deg, #eef5ff, #f7fbff); border: 1px solid #d7e6fb; color: var(--ink);
}
.action strong { display: block; color: var(--navy); font-size: 1.05rem; }
.action span { color: var(--muted); font-size: .9rem; }
.action:hover { text-decoration: none; border-color: var(--blue); }

.class-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.class-tile {
    display: flex; flex-direction: column; align-items: flex-start;
    padding: 12px; border-radius: 12px; background: #f6f8fc; border: 1px solid var(--line); color: var(--ink);
}
.class-tile:hover { text-decoration: none; border-color: var(--blue); }
.class-tile .class-name { font-weight: 700; color: var(--navy); }
.class-tile strong { font-size: 1.4rem; color: var(--blue); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 10px; border: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; font-size: .95rem; background: var(--card); }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: #f6f8fc; color: var(--navy); font-weight: 700; font-size: .85rem; text-transform: uppercase; letter-spacing: .02em; }
tbody tr:nth-child(even) td { background: #fbfcfe; }
tfoot td { font-weight: 700; background: #eef3fb; border-top: 2px solid var(--navy-2); }
.report-table td.num, .report-table th.num { text-align: right; }

.class-view-table th, .class-view-table td { font-size: .9rem; }

/* ---------- Forms ---------- */
label { display: block; font-weight: 600; font-size: .92rem; color: var(--navy); margin: 12px 0 6px; }
input[type=text], input[type=password], input[type=email], input[type=number],
input[type=date], input[type=file], select, textarea {
    width: 100%; min-height: 46px; padding: 10px 12px;
    font: inherit; font-size: 16px; /* 16px stops iPhone zooming in */
    color: var(--ink); background: #fff;
    border: 1px solid #c9d3e2; border-radius: 10px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(10,108,255,.18); }
input[readonly] { background: #f2f4f7; color: var(--muted); }

button, .btn, .btn-primary, .btn-secondary, .term-btn, .class-view-btn, .edit-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    min-height: 46px; padding: 10px 18px; margin-top: 14px;
    font: inherit; font-weight: 600; font-size: 16px;
    color: #fff; background: var(--blue); border: 0; border-radius: 10px; cursor: pointer;
    text-decoration: none;
}
button:hover, .btn:hover, .btn-primary:hover, .term-btn:hover, .class-view-btn:hover { background: var(--blue-dark); text-decoration: none; }
.btn-secondary { background: #fff; color: var(--navy); border: 1px solid #c9d3e2; }
.btn-secondary:hover { background: #f6f8fc; color: var(--navy); }
.btn-primary { background: var(--blue); }
button[disabled] { opacity: .5; cursor: not-allowed; }
form button { width: 100%; }
.form-buttons button, .report-actions button, .report-actions a, .filters button, .search-form button, .view-form button { width: auto; }
.report-actions a, .report-actions button { margin: 0; }

.form-container, .form-wrapper, .payment-form, .search-form, .view-form, .update-container, .edit-container, .class-view-container {
    max-width: 720px; margin: 0 auto;
    background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px;
}
.form-container h1, .form-container h2, .edit-container h2, .class-view-container h2, .payment-form h2, .view-form h2, .search-form h2, .update-container h1 {
    margin-bottom: 14px;
}
.form-grid { display: grid; grid-template-columns: 1fr; gap: 0 16px; }
.form-group2 { min-width: 0; }
.form-group2 button, .form-group2 .btn { width: 100%; }
.form-group, .edit-form { margin-bottom: 4px; }
.edit-form label { margin-top: 12px; }
.form-select, .class-view-form-group { margin-bottom: 8px; }
.form-buttons { display: grid; grid-template-columns: 1fr; gap: 10px; margin-top: 8px; }
.form-buttons button { width: 100%; margin: 0; }
.term-btn { background: var(--navy-2); }
.term-btn:hover { background: var(--navy); }
.search-form, .view-form { display: flex; flex-direction: column; gap: 4px; }
.search-form form, .view-form form { display: flex; flex-direction: column; }
.search-form input, .view-form input { margin-bottom: 4px; }

.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; background: var(--card); padding: 14px; border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 14px; }
.filters label { margin: 0; flex: 1 1 160px; }
.filters button { width: auto; margin: 0; }

.payment-form label:first-of-type, .form-container label:first-of-type { margin-top: 0; }

/* ---------- Login ---------- */
.body {
    min-height: 100vh; margin: 0;
    display: flex; align-items: center; justify-content: center; padding: 16px;
    background: linear-gradient(160deg, #00b4ff 0%, #0093e0 55%, #0a6cff 100%);
}
.login-container {
    width: 100%; max-width: 420px;
    background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.25);
    backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
    border-radius: 20px; padding: 28px 22px; color: #fff; text-align: center;
    box-shadow: 0 12px 40px rgba(0,30,80,.25);
}
.login-container .logo img {
    width: 110px; height: 110px; object-fit: contain; border-radius: 22px; background: var(--navy);
    padding: 8px; box-shadow: 0 6px 18px rgba(0,0,0,.2);
}
.login-container h2 { color: #fff; margin: 14px 0 18px; font-size: 1.25rem; letter-spacing: .02em; text-transform: uppercase; }
.login-container .form-group { text-align: left; margin-bottom: 12px; }
.login-container label { color: #fff; margin: 0 0 6px; font-size: .9rem; text-transform: uppercase; letter-spacing: .03em; }
.login-container input { background: #fff; }
.login-container .btn {
    width: 100%; margin-top: 10px; background: var(--navy);
}
.login-container .btn:hover { background: #061d3d; }
.login-container .alert-message { margin-bottom: 12px; }

/* ---------- Alerts ---------- */
.alert-message, .alert, .success {
    padding: 12px 14px; border-radius: 10px; margin: 0 0 14px; font-weight: 500;
}
.alert-success, .success { background: var(--good-bg); color: var(--good); border: 1px solid #bfe6d4; }
.alert-error, .alert { background: var(--bad-bg); color: var(--bad); border: 1px solid #f5c2bd; }
.alert-message.alert-success { background: var(--good-bg); }

/* ---------- Profiles and info rows ---------- */
.container { display: grid; grid-template-columns: 1fr; gap: 14px; max-width: 1000px; margin: 0 auto; }
.left-card, .card {
    background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px;
}
.left-card { text-align: center; }
.left-card h2 { margin-bottom: 12px; }
.left-card > label { display: block; margin-top: 10px; font-weight: 700; color: var(--navy); font-size: 1rem; }
.student-profile img.photo, .student-profile img { width: 150px; height: 150px; object-fit: cover; border-radius: 14px; border: 1px solid var(--line); }
.no-photo {
    display: flex; align-items: center; justify-content: center;
    width: 150px; height: 150px; margin: 0 auto; border-radius: 14px;
    border: 1px dashed #b6c2d6; color: var(--muted); background: #f6f8fc;
}
.info-row {
    display: grid; grid-template-columns: 1fr; gap: 2px;
    padding: 10px 0; border-bottom: 1px solid var(--line);
}
.info-row:last-child { border-bottom: 0; }
.info-label { color: var(--muted); font-size: .85rem; }
.info-row label { margin: 0; font-weight: 600; color: var(--ink); }
.card h2 { border-bottom: 1px solid var(--line); padding-bottom: 8px; margin-bottom: 4px; }
.alert.alert-warn { background: var(--warn-bg); }

/* ---------- Class view ---------- */
.class-view-stats { display: flex; flex-wrap: wrap; gap: 10px; margin: 14px 0; }
.class-view-stats p { flex: 1 1 120px; margin: 0; background: #f6f8fc; border-radius: 10px; padding: 10px 12px; font-weight: 600; }
.class-view-stats span { color: var(--blue); font-size: 1.2rem; display: block; }

/* ---------- Reports ---------- */
.page-title { margin-bottom: 12px; }
.page-title h1 { margin-bottom: 2px; }
.tabs { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 12px; -webkit-overflow-scrolling: touch; }
.tab {
    flex: 0 0 auto; padding: 9px 14px; border-radius: 999px;
    background: var(--card); color: var(--navy); border: 1px solid var(--line); font-weight: 600; font-size: .92rem;
}
.tab:hover { text-decoration: none; border-color: var(--blue); }
.tab.active { background: var(--navy); color: #fff; border-color: var(--navy); }
.report-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.report-actions button, .report-actions a { margin-top: 0; }
.report-sheet { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.report-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px; border-bottom: 2px solid var(--navy); padding-bottom: 12px; margin-bottom: 16px; }
.report-school { color: var(--navy); font-size: 1.1rem; }
.report-meta { text-align: right; }
.report-meta h2 { margin: 0; }
.summary { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 16px; }
.sum-card { background: #f6f8fc; border-radius: 10px; padding: 12px; border-left: 4px solid var(--navy-2); }
.sum-card span { display: block; color: var(--muted); font-size: .82rem; }
.sum-card strong { font-size: 1.1rem; color: var(--navy); font-variant-numeric: tabular-nums; }
.report-foot { margin-top: 14px; font-size: .85rem; text-align: right; }

/* ---------- Receipt (printed) ---------- */
.receipt-body { background: #eef2f8; padding: 16px; }
.receipt-container {
    max-width: 680px; margin: 0 auto; background: #fff; padding: 26px; border-radius: 12px;
    box-shadow: var(--shadow);
}
.receipt-header { text-align: center; border-bottom: 2px solid var(--navy); padding-bottom: 12px; }
.receipt-header img { width: 70px; height: 70px; object-fit: contain; }
.receipt-header h1 { margin: 6px 0 2px; font-size: 1.3rem; }
.receipt-header p { margin: 0; color: var(--muted); font-size: .9rem; }
.receipt-title { text-align: center; font-weight: 800; font-size: 1.1rem; color: var(--navy); margin: 16px 0; text-transform: uppercase; letter-spacing: .04em; }
.info-section p { margin: 6px 0; }
.info-section span, .receipt-footer span { font-weight: 700; color: var(--navy); margin-right: 4px; }
.receipt-number { font-weight: 700; }
.payment-table { width: 100%; margin: 16px 0; border: 1px solid var(--line); }
.payment-table th { background: var(--navy); color: #fff; }
.payment-table td { font-size: 1rem; }
.receipt-footer { margin-top: 12px; font-size: .95rem; }
.stamp { border: 2px dashed #b6c2d6; color: var(--muted); text-align: center; padding: 18px; margin-top: 12px; border-radius: 10px; }
.receipt-results h3 { margin-top: 16px; }

/* ---------- Print ---------- */
@media print {
    body { background: #fff; }
    .topbar, .nav, .foot, .no-print, .back-link, .tabs, .filters, .report-actions { display: none !important; }
    .main { padding: 0; max-width: none; }
    .report-sheet, .card-block, .form-container, .card, .left-card { box-shadow: none; border: 0; }
    .table-wrap { border: 0; overflow: visible; }
    table { font-size: 11pt; }
    th { background: #eee !important; }
    tfoot td { background: #f2f2f2 !important; }
    .receipt-container { box-shadow: none; max-width: none; }
    .receipt-body { background: #fff; }
    a { color: #000; text-decoration: none; }
}

/* ---------- Wider screens ---------- */
@media (min-width: 640px) {
    .stats { grid-template-columns: repeat(3, 1fr); }
    .actions { grid-template-columns: repeat(3, 1fr); }
    .class-grid { grid-template-columns: repeat(4, 1fr); }
    .form-grid { grid-template-columns: 1fr 1fr; }
    .form-grid .form-group2:nth-child(-n+1) { grid-column: 1 / -1; }
    .form-buttons { grid-template-columns: repeat(3, 1fr); }
    .summary { grid-template-columns: repeat(4, 1fr); }
    .info-row { grid-template-columns: 220px 1fr; gap: 12px; align-items: baseline; }
    .container { grid-template-columns: 260px 1fr; align-items: start; }
    .container .card:last-child { grid-column: 2; }
}

@media (min-width: 900px) {
    .nav { background: var(--card); }
    .nav-details summary { display: none; }
    .nav-details { display: block; }
    .nav-details ul {
        display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 16px;
        max-width: 1180px; margin: 0 auto;
    }
    .nav-details li a { padding: 8px 12px; font-size: .9rem; }
    .main { padding: 22px 16px 28px; }
    .stats { grid-template-columns: repeat(6, 1fr); }
    .actions { grid-template-columns: repeat(3, 1fr); }
    .summary { grid-template-columns: repeat(4, 1fr); }
}

/* Mobile menu closed state when JavaScript is off: details is closed by default. */
.nav-details:not([open]) > ul { display: none; }
@media (min-width: 900px) {
    .nav-details:not([open]) > ul { display: flex; }
}

/* ---------- Old unused helpers, kept so nothing breaks ---------- */
.menu, .footer, .dash { display: none; }
.back-link { color: var(--blue); display: inline-block; margin: 14px 0; }

/* ---------- Import ---------- */
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .8rem; font-weight: 700; }
.badge.good { background: var(--good-bg); color: var(--good); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.problems { margin: 6px 0 0; padding-left: 18px; color: var(--bad); font-size: .88rem; }
.import-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 12px; }
.import-actions form { margin: 0; }
.import-actions button, .import-actions a { margin-top: 0; }
.radio-row { display: flex; flex-wrap: wrap; gap: 14px; }
label.radio { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; margin: 6px 0; }
label.radio input { width: auto; min-height: 0; }
.rules { padding-left: 20px; }
.rules li { margin-bottom: 8px; }
