:root {
    --navy: #17365d;
    --blue: #2f5597;
    --light-blue: #eaf1fb;
    --border: #cbd5e1;
    --text: #172033;
    --muted: #64748b;
    --success: #14804a;
    --danger: #b42318;
    --warning: #9a6700;
    --surface: #ffffff;
    --background: #f4f7fb;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: Arial, Helvetica, sans-serif; color: var(--text); background: var(--background); }
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; }
.app-shell { min-height: 100vh; display: grid; grid-template-columns: 255px minmax(0, 1fr); }
.sidebar { background: linear-gradient(180deg, #17365d, #0f2745); color: white; padding: 20px 14px; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; z-index: 20; }
.brand { display: flex; gap: 12px; align-items: center; padding: 6px 8px 22px; border-bottom: 1px solid rgba(255,255,255,.15); }
.brand-mark, .login-logo { width: 52px; height: 52px; border-radius: 14px; background: white; color: var(--navy); display: grid; place-items: center; font-weight: 800; }
.brand strong { display: block; font-size: 14px; line-height: 1.25; }
.brand span { display: block; font-size: 12px; opacity: .75; margin-top: 4px; }
.sidebar nav { display: grid; gap: 6px; margin-top: 22px; }
.sidebar nav a { padding: 12px 14px; border-radius: 9px; color: rgba(255,255,255,.84); }
.sidebar nav a:hover, .sidebar nav a.active { background: rgba(255,255,255,.14); color: white; }
.sidebar-footer { margin-top: auto; display: grid; padding: 16px 8px 0; border-top: 1px solid rgba(255,255,255,.15); }
.sidebar-footer span { font-weight: 700; }
.sidebar-footer small { opacity: .7; margin: 3px 0 10px; }
.sidebar-footer a { color: #ffd3cf; font-size: 13px; }
.main-content { min-width: 0; }
.topbar { background: white; border-bottom: 1px solid var(--border); min-height: 78px; padding: 16px 28px; display: flex; align-items: center; gap: 14px; position: sticky; top: 0; z-index: 10; }
.topbar h1 { font-size: 23px; margin: 0; }
.topbar p { margin: 3px 0 0; color: var(--muted); }
.menu-button { display: none; border: 0; background: var(--light-blue); border-radius: 8px; padding: 9px 11px; cursor: pointer; }
.page-content { padding: 24px 28px 48px; }
.card { background: var(--surface); border: 1px solid #e3e8ef; border-radius: 14px; padding: 20px; box-shadow: 0 5px 20px rgba(15, 39, 69, .05); margin-bottom: 20px; }
.card-header { display: flex; justify-content: space-between; gap: 20px; align-items: start; margin-bottom: 18px; }
.card h2 { margin: 0 0 6px; font-size: 19px; }
.card p { margin: 0; color: var(--muted); }
.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat-card { background: white; border-radius: 14px; padding: 20px; border: 1px solid #e3e8ef; box-shadow: 0 5px 20px rgba(15,39,69,.05); }
.stat-card span, .stat-card small { display: block; color: var(--muted); }
.stat-card strong { display: block; font-size: 25px; margin: 8px 0 6px; color: var(--navy); }
.filter-bar { display: flex; gap: 14px; align-items: end; flex-wrap: wrap; }
.filter-bar label { min-width: 260px; flex: 1; }
label { display: grid; gap: 7px; font-weight: 700; font-size: 14px; }
input, select { width: 100%; min-height: 42px; border: 1px solid #bac5d3; border-radius: 8px; padding: 8px 11px; color: var(--text); background: white; }
input:focus, select:focus { outline: 3px solid rgba(47,85,151,.15); border-color: var(--blue); }
.button { border: 0; min-height: 42px; padding: 10px 16px; border-radius: 8px; cursor: pointer; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }
.button.primary { color: white; background: var(--blue); }
.button.secondary { color: var(--navy); background: var(--light-blue); border: 1px solid #b9cae3; }
.button.small { min-height: 34px; padding: 6px 11px; font-size: 13px; }
.button.full { width: 100%; }
.button:disabled { opacity: .6; cursor: wait; }
.button-row { display: flex; gap: 10px; }
.alert { padding: 12px 16px; margin: 18px 28px 0; border-radius: 8px; font-weight: 700; }
.alert-success { background: #eaf8f0; color: var(--success); }
.alert-danger { background: #fff0ee; color: var(--danger); }
.alert-warning { background: #fff7dc; color: var(--warning); }
.info-card { border-left: 5px solid var(--blue); }
.schedule-paper { padding: 25px; }
.schedule-heading { text-align: center; margin-bottom: 18px; }
.schedule-heading h2 { font-size: 24px; color: var(--navy); }
.schedule-heading p { margin: 4px 0; }
.schedule-heading h3 { margin: 9px 0; font-size: 20px; }
.locked-class { margin: 12px auto 0; max-width: 520px; padding: 10px; background: #fff4cc; border: 1px solid #e3c75b; border-radius: 8px; }
.locked-class span { font-size: 12px; color: var(--warning); margin-left: 8px; }
.table-wrap { width: 100%; overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
.schedule-table { min-width: 1050px; table-layout: fixed; }
.schedule-table th, .schedule-table td { border: 1px solid #4f5c6d; padding: 5px; text-align: center; vertical-align: middle; }
.schedule-table thead th { background: var(--navy); color: white; height: 54px; }
.schedule-table thead th:first-child { width: 145px; }
.schedule-table thead small { color: #dbe7f6; font-weight: 400; }
.schedule-table tbody th { background: #e8eef7; font-size: 14px; height: 68px; }
.schedule-table tbody th span { font-weight: 400; }
.schedule-table td input { border: 0; border-radius: 0; min-height: 58px; padding: 5px; text-align: center; background: #fffde9; }
.schedule-table td input:focus { outline: 3px solid rgba(47,85,151,.25); }
.save-bar { display: flex; justify-content: space-between; align-items: center; gap: 18px; margin-top: 18px; padding: 13px; border-radius: 9px; background: #eef3f9; }
.status-success { color: var(--success); font-weight: 700; }
.status-danger { color: var(--danger); font-weight: 700; }
.status-warning { color: var(--warning); font-weight: 700; }
.admin-table th, .admin-table td { padding: 11px 12px; border-bottom: 1px solid #dde4ec; text-align: left; }
.admin-table th { background: #eef3f9; color: var(--navy); }
.admin-table input { min-height: 36px; }
.badge { display: inline-flex; border-radius: 999px; padding: 5px 9px; font-size: 12px; font-weight: 700; }
.badge.success { color: var(--success); background: #e8f7ee; }
.badge.muted { color: #5b6675; background: #edf0f3; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.form-grid .wide { grid-column: 1 / -1; }
.narrow-card { max-width: 520px; }
.stack-form { display: grid; gap: 16px; }
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(circle at top, #315f9d, #0e2747 65%); }
.login-card { width: min(420px, 100%); background: white; padding: 30px; border-radius: 18px; box-shadow: 0 20px 60px rgba(0,0,0,.25); text-align: center; }
.login-logo { margin: 0 auto 15px; background: var(--navy); color: white; }
.login-card h1 { font-size: 22px; margin: 0; }
.login-card p { color: var(--muted); margin: 7px 0 22px; }
.login-card form { text-align: left; display: grid; gap: 15px; }
.login-card small { display: block; margin-top: 18px; color: var(--muted); }
.print-page { background: #e8edf4; padding: 20px; }
.print-toolbar { max-width: 1200px; margin: 0 auto 12px; display: flex; justify-content: flex-end; gap: 9px; }
.print-sheet { max-width: 1200px; min-height: 700px; margin: auto; padding: 28px; background: white; box-shadow: 0 5px 25px rgba(0,0,0,.12); }
.print-sheet header { text-align: center; }
.print-sheet h1 { color: var(--navy); margin: 0; font-size: 27px; }
.print-sheet h2 { margin: 10px 0; }
.print-sheet h3 { margin: 14px 0 20px; }
.print-table td { min-height: 70px; height: 70px; white-space: pre-wrap; overflow-wrap: anywhere; }
@media (max-width: 1000px) {
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .app-shell { grid-template-columns: 1fr; }
    .sidebar { position: fixed; left: -280px; transition: left .2s ease; width: 255px; }
    .sidebar.open { left: 0; }
    .menu-button { display: block; }
}
@media (max-width: 620px) {
    .page-content, .topbar { padding-left: 15px; padding-right: 15px; }
    .stats-grid { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: 1fr; }
    .form-grid .wide { grid-column: auto; }
    .alert { margin-left: 15px; margin-right: 15px; }
}
@page { size: A4 landscape; margin: 9mm; }
@media print {
    .no-print { display: none !important; }
    body, .print-page { background: white; padding: 0; }
    .print-sheet { box-shadow: none; max-width: none; min-height: 0; padding: 0; }
    .print-sheet h1 { font-size: 20pt; }
    .print-sheet h2 { font-size: 15pt; }
    .print-sheet h3 { font-size: 13pt; }
    .schedule-table { min-width: 0; font-size: 9pt; }
    .schedule-table th, .schedule-table td { padding: 3px; }
}

/* v3: Hindi/Punjabi Unicode and date-wise schedule history */
body, button, input, select, textarea {
    font-family: Arial, "Noto Sans Devanagari", "Noto Sans Gurmukhi", Mangal, Raavi, sans-serif;
}
textarea { font: inherit; }
.unicode-hindi { font-family: "Noto Sans Devanagari", Mangal, "Nirmala UI", Arial, sans-serif !important; }
.unicode-punjabi { font-family: "Noto Sans Gurmukhi", Raavi, "Nirmala UI", Arial, sans-serif !important; }
.schedule-table td textarea {
    width: 100%;
    min-height: 62px;
    resize: vertical;
    border: 0;
    border-radius: 0;
    padding: 6px;
    text-align: center;
    background: #fffde9;
    line-height: 1.35;
}
.schedule-table td textarea:focus { outline: 3px solid rgba(47,85,151,.25); }
.typing-help { margin: 0 0 16px; padding: 11px 14px; border: 1px solid #bfd0e6; border-radius: 10px; background: #eef5ff; }
kbd { display: inline-block; padding: 2px 6px; border: 1px solid #b9c3cf; border-bottom-width: 2px; border-radius: 4px; background: white; font-size: 12px; }
.date-range { color: var(--muted); font-weight: 700; }
.date-input-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-top: 12px; }
.checkbox-label { display: flex; align-items: center; gap: 9px; }
.checkbox-label input { width: auto; min-height: 0; }
.field-note { margin: 5px 0 0; color: var(--muted); }
.admin-table form { margin: 0; }
@media (max-width: 900px) { .date-input-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 520px) { .date-input-grid { grid-template-columns: 1fr; } }

/* v4: full update/delete management */
.button.danger { color: #fff; background: var(--danger); }
.button.danger:hover { filter: brightness(.92); }
.wrap-actions { flex-wrap: wrap; align-items: center; }
.edit-card { border-left: 5px solid var(--warning); }
.action-column { width: 92px; }
.action-cell { background: #fff5f4; }
.inline-edit-grid {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) 90px 110px 90px auto;
    gap: 10px;
    align-items: center;
}
.delete-inline { display: inline-flex; margin-top: 8px !important; }
.small-number { max-width: 90px; }
.checkbox-label.compact { display: flex; align-items: center; gap: 7px; font-weight: 700; white-space: nowrap; }
.checkbox-label.compact input { width: auto; min-height: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.user-edit-grid {
    display: grid;
    grid-template-columns: minmax(260px, 1.5fr) 150px 100px minmax(150px, .8fr) auto;
    gap: 10px;
    align-items: center;
}
.two-inputs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.user-table td { vertical-align: top; }
@media (max-width: 1100px) {
    .inline-edit-grid, .user-edit-grid { grid-template-columns: 1fr 1fr; }
    .two-inputs { grid-column: 1 / -1; }
}
@media (max-width: 620px) {
    .inline-edit-grid, .user-edit-grid, .two-inputs { grid-template-columns: 1fr; }
    .save-bar { align-items: flex-start; flex-direction: column; }
}
.date-edit-control { display: grid; grid-template-columns: minmax(130px, 1fr) auto; gap: 6px; }
.schedule-table textarea.dirty { background: #fff2bf; }

/* v5: restricted teacher role, assignments, staff CSV and audit activity */
.badge.info { background: #e9f2ff; color: #174a8b; border: 1px solid #bfd5f2; margin: 2px; }
.permission-note { margin: 0 0 18px; padding: 14px 16px; border: 1px solid #b9d4f4; border-left: 5px solid var(--blue); border-radius: 10px; background: #eef6ff; }
.permission-note p { margin: 7px 0 0; color: var(--muted); }
.empty-state { text-align: center; padding: 38px 22px; }
.empty-state h2 { color: var(--navy); }
.compact-subject-table { min-width: 650px; max-width: 1000px; margin: 0 auto; }
.staff-add-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.staff-edit-grid { display: grid; grid-template-columns: minmax(460px, 2.3fr) minmax(145px,.8fr) minmax(130px,.65fr) minmax(180px,.9fr) auto; gap: 10px; align-items: center; }
.staff-detail-inputs { display: grid; grid-template-columns: .65fr 1.2fr .8fr 1fr .75fr; gap: 7px; }
.role-status-cell { display: grid; gap: 8px; }
.text-link { color: var(--blue); text-decoration: underline; font-size: 13px; }
.import-errors { margin-top: 14px; padding: 10px 14px; background: #fff7e6; border: 1px solid #efd28e; border-radius: 8px; }
.import-errors summary { cursor: pointer; font-weight: 700; }
.assignment-edit-grid { display: grid; grid-template-columns: minmax(180px,1.1fr) minmax(180px,1fr) minmax(160px,.9fr) 100px auto; gap: 10px; align-items: center; }
.assignment-cards { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 14px; }
.assignment-card { border: 1px solid #dce4ee; border-radius: 12px; padding: 16px; background: #fbfdff; }
.assignment-card h3 { margin: 0 0 10px; color: var(--navy); }
.assignment-card .button { margin-top: 14px; }
.quick-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 16px; margin-bottom: 20px; }
.quick-card { background: white; border: 1px solid #dce4ee; border-radius: 13px; padding: 20px; box-shadow: 0 5px 18px rgba(15,39,69,.05); }
.quick-card strong, .quick-card span { display:block; }
.quick-card strong { color: var(--navy); margin-bottom: 7px; }
.quick-card span { color: var(--muted); line-height: 1.45; }
.activity-table { min-width: 1150px; }
.activity-value { white-space: pre-wrap; max-width: 260px; overflow-wrap: anywhere; }

@media (max-width: 1250px) {
    .staff-edit-grid { grid-template-columns: 1fr 1fr; }
    .staff-detail-inputs { grid-column: 1/-1; grid-template-columns: repeat(3,1fr); }
}
@media (max-width: 950px) {
    .staff-add-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
    .assignment-cards, .quick-grid { grid-template-columns: 1fr; }
    .assignment-edit-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 620px) {
    .staff-add-grid, .staff-edit-grid, .staff-detail-inputs, .assignment-edit-grid { grid-template-columns: 1fr; }
}


/* v5.2: staff and teacher search for large lists */
.staff-search-form,
.teacher-search-form {
    display: grid;
    grid-template-columns: minmax(300px, 2fr) minmax(135px, .65fr) minmax(135px, .65fr) minmax(105px, .45fr) auto auto;
    gap: 12px;
    align-items: end;
}
.teacher-search-form {
    grid-template-columns: minmax(320px, 1fr) auto auto;
    max-width: 900px;
}
.staff-search-main input,
.teacher-search-main input { min-width: 0; }
.staff-search-summary {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 10px 20px;
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid #e1e8f0;
    color: var(--muted);
}
.staff-search-summary strong { color: var(--navy); }
.pagination {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-top: 18px;
}
.page-link,
.page-ellipsis {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 38px;
    min-height: 38px;
    padding: 7px 11px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    color: var(--navy);
    font-weight: 700;
}
.page-link:hover { background: var(--light-blue); }
.page-link.active { background: var(--blue); border-color: var(--blue); color: #fff; }
.page-link.disabled { opacity: .45; pointer-events: none; }
.page-ellipsis { border-color: transparent; background: transparent; }
@media (max-width: 1050px) {
    .staff-search-form { grid-template-columns: 1fr 1fr; }
    .staff-search-main { grid-column: 1 / -1; }
    .teacher-search-form { grid-template-columns: 1fr auto auto; }
}
@media (max-width: 620px) {
    .staff-search-form,
    .teacher-search-form { grid-template-columns: 1fr; }
    .staff-search-main { grid-column: auto; }
    .staff-search-form .button,
    .teacher-search-form .button { width: 100%; }
}

/* v5.3: bulk teacher class/subject assignment matrix */
.selected-teacher-form { min-width: min(420px, 100%); }
.bulk-assignment-summary { display:flex; justify-content:space-between; gap:14px; flex-wrap:wrap; padding:12px 14px; margin-bottom:14px; border-radius:9px; background:#edf4ff; color:var(--navy); }
.bulk-assignment-toolbar { display:flex; align-items:end; gap:10px; flex-wrap:wrap; margin-bottom:14px; }
.bulk-class-search { min-width:260px; flex:1; }
.bulk-assignment-wrap { max-height:62vh; border:1px solid var(--border); border-radius:10px; }
.assignment-matrix { min-width:1220px; }
.assignment-matrix thead th { position:sticky; top:0; z-index:3; text-align:center; white-space:nowrap; }
.assignment-matrix th, .assignment-matrix td { text-align:center; vertical-align:middle; }
.assignment-matrix .sticky-class-column { position:sticky; left:0; z-index:2; min-width:190px; text-align:left; background:#eef3f9; box-shadow:2px 0 0 #d7e0ea; }
.assignment-matrix thead .sticky-class-column { z-index:5; background:#dce8f7; }
.assignment-matrix tbody tr:hover td, .assignment-matrix tbody tr:hover .sticky-class-column { background:#f7faff; }
.matrix-check { display:inline-flex; align-items:center; justify-content:center; gap:5px; cursor:pointer; font-weight:600; font-size:12px; min-width:42px; }
.matrix-check input { width:19px; min-height:19px; height:19px; padding:0; accent-color:var(--blue); }
.matrix-check span { display:none; }
.bulk-save-footer { display:flex; justify-content:space-between; align-items:center; gap:16px; flex-wrap:wrap; margin-top:14px; padding:14px; border-radius:9px; background:#fff8df; border:1px solid #ead486; }
.bulk-save-footer p { margin:0; }
@media (max-width: 760px) {
    .bulk-assignment-summary, .bulk-save-footer { align-items:stretch; flex-direction:column; }
    .bulk-assignment-toolbar .button { width:100%; }
    .selected-teacher-form { min-width:100%; }
}

/* Sidebar module icons */
.sidebar nav a { display:flex; align-items:center; gap:10px; }
.sidebar nav a .nav-icon {
    width:24px;
    min-width:24px;
    display:inline-flex;
    align-items:center;
    justify-content:center;
    font-size:17px;
    line-height:1;
}
.sidebar nav a.active .nav-icon { transform: scale(1.05); }

.copy-subject-card{margin:16px 0;padding:16px;border:1px solid #dfe3e8;border-radius:10px;background:#f8fafc;display:flex;align-items:center;justify-content:space-between;gap:18px}
.copy-subject-card p{margin:5px 0 0}
.copy-subject-card .filter-bar{margin:0;display:flex;align-items:end;gap:10px}
@media(max-width:800px){.copy-subject-card{display:block}.copy-subject-card .filter-bar{margin-top:12px;flex-wrap:wrap}}

/* Schedule JPG and WhatsApp export buttons */
.button.success { background:#198754; color:#fff; border-color:#198754; }
.button.whatsapp { background:#25D366; color:#fff; border-color:#25D366; }
.button.success:hover, .button.whatsapp:hover { filter:brightness(.94); }
.wrap-actions { align-items:center; }
@media (max-width: 900px) { .wrap-actions .button { flex:1 1 180px; } }
/* v14 bulk class subject copy */
.copy-subject-card{display:block}
.bulk-copy-form{margin-top:14px}
.bulk-copy-grid{display:grid;grid-template-columns:minmax(210px,.7fr) minmax(320px,1.5fr) auto;gap:16px;align-items:end}
.copy-target-toolbar{display:flex;align-items:center;gap:8px;flex-wrap:wrap;margin:7px 0}
.copy-target-list{display:grid;grid-template-columns:repeat(3,minmax(150px,1fr));gap:7px;max-height:190px;overflow:auto;padding:10px;border:1px solid var(--border);border-radius:8px;background:#fff}
.copy-target-item{display:flex;align-items:center;gap:7px;padding:7px 8px;border:1px solid #e5e7eb;border-radius:6px;background:#fafafa;cursor:pointer}
.copy-target-item:hover{background:#f3f6fa}
.copy-target-item.disabled{opacity:.5;cursor:not-allowed}
.copy-target-item input{margin:0}
.bulk-copy-submit{display:flex;align-items:end}
@media(max-width:1000px){.bulk-copy-grid{grid-template-columns:1fr}.copy-target-list{grid-template-columns:repeat(2,minmax(150px,1fr))}.bulk-copy-submit .button{width:100%}}
@media(max-width:560px){.copy-target-list{grid-template-columns:1fr}}
