/* ============================================================
   School Management System — Complete Stylesheet
   Version: 4.0 (consolidated sidebar + page toolbars)
   ============================================================ */

:root {
  --primary: #b71c1c;
  --primary-dark: #7f0000;
  --accent: #e67e22;
  --bg: #f0f2f5;
  --card: #ffffff;
  --text: #2c3e50;
  --text-light: #7f8c8d;
  --border: #dfe4ea;
  --sidebar-bg: #1e2a38;
  --sidebar-hover: #2c3e50;
  --success: #27ae60;
  --warning: #e67e22;
  --danger: #c0392b;
  --info: #2980b9;
  --radius: 6px;
  --shadow: 0 2px 8px rgba(0,0,0,.06);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

.app { display: flex; min-height: 100vh; }

/* SIDEBAR */
.sidebar {
  width: 250px;
  background: var(--sidebar-bg);
  color: #ecf0f1;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  overflow-y: auto;
  z-index: 200;
  transition: transform .28s cubic-bezier(.4,0,.2,1);
  -webkit-overflow-scrolling: touch;
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: #445; border-radius: 3px; }

.sidebar .brand {
  padding: 20px 18px;
  font-size: .92rem;
  font-weight: 700;
  letter-spacing: 1.2px;
  color: #fff;
  text-transform: uppercase;
  background: rgba(0,0,0,.18);
  border-bottom: 1px solid rgba(255,255,255,.05);
  word-break: break-word;
}

.sidebar nav { padding: 8px 0; }

.sidebar nav > a {
  display: flex;
  align-items: center;
  padding: 11px 18px;
  color: #bdc3c7;
  text-decoration: none;
  font-size: .88rem;
  font-weight: 500;
  border-left: 3px solid transparent;
  transition: all .15s;
  -webkit-tap-highlight-color: transparent;
}
.sidebar nav > a span {
  margin-right: 10px;
  font-size: 1rem;
  width: 20px;
  display: inline-block;
  text-align: center;
  flex-shrink: 0;
}
.sidebar nav > a:hover {
  background: var(--sidebar-hover);
  color: #fff;
  border-left-color: var(--accent);
}
.sidebar nav > a.active {
  background: var(--sidebar-hover);
  color: #fff;
  border-left-color: var(--accent);
  font-weight: 600;
}

.sidebar .logout-link {
  margin-top: 20px;
  border-top: 1px solid rgba(255,255,255,.08);
  color: #f0b8a0;
}

/* Collapsible groups */
.nav-group > .nav-group-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 18px;
  color: #bdc3c7;
  font-size: .88rem;
  font-weight: 500;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: all .15s;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.nav-group > .nav-group-toggle > span:first-child {
  margin-right: 10px;
  font-size: 1rem;
  width: 20px;
  display: inline-block;
  text-align: center;
  flex-shrink: 0;
}
.nav-group > .nav-group-toggle:hover {
  background: var(--sidebar-hover);
  color: #fff;
}
.nav-group.open > .nav-group-toggle {
  background: #16212e;
  color: #fff;
  border-left-color: var(--accent);
}
.nav-group .arrow {
  font-size: .7rem;
  transition: transform .2s;
  color: #7f8c8d;
  margin-left: auto;
}
.nav-group.open .arrow { transform: rotate(180deg); }

.nav-group .nav-submenu {
  max-height: 0;
  overflow: hidden;
  transition: max-height .3s ease;
  background: #16212e;
}
.nav-group.open .nav-submenu { max-height: 1000px; }

.nav-group .nav-submenu a.sub-link {
  display: flex;
  align-items: center;
  padding: 9px 18px 9px 46px;
  color: #9aa8b6;
  font-size: .82rem;
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: all .15s;
  -webkit-tap-highlight-color: transparent;
}
.nav-group .nav-submenu a.sub-link span {
  margin-right: 8px;
  width: 16px;
  text-align: center;
  flex-shrink: 0;
}
.nav-group .nav-submenu a.sub-link:hover {
  background: var(--sidebar-hover);
  color: #fff;
}
.nav-group .nav-submenu a.sub-link.active {
  color: #fff;
  border-left-color: var(--accent);
  background: var(--sidebar-hover);
  font-weight: 600;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 190;
  opacity: 0;
  visibility: hidden;
  transition: opacity .25s ease, visibility .25s ease;
}
.sidebar-backdrop.show {
  opacity: 1;
  visibility: visible;
}

/* MAIN */
.main {
  flex: 1;
  margin-left: 250px;
  min-height: 100vh;
  background: var(--bg);
  transition: margin-left .28s ease;
}

/* TOPBAR */
.topbar {
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 60%, var(--accent) 100%);
  padding: 14px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 2px 8px rgba(0,0,0,.08);
  position: sticky;
  top: 0;
  z-index: 100;
}
.topbar h2 {
  color: #fff;
  font-size: 1.05rem;
  font-weight: 600;
  margin: 0;
  flex: 1;
  margin-left: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar .user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #fff;
  font-size: .9rem;
}
.topbar .user-info .badge {
  background: rgba(255,255,255,.25);
  color: #fff;
}
.menu-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 1.6rem;
  color: #fff;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
  border-radius: 4px;
}
.menu-toggle:hover,
.menu-toggle:active { background: rgba(255,255,255,.15); }

/* PAGE BANNER */
.page-banner {
  background: linear-gradient(90deg, #f1c40f, #f39c12);
  color: #2c3e50;
  text-align: center;
  font-weight: 700;
  font-size: 1rem;
  padding: 14px;
  margin: 20px 24px 0;
  border-radius: 4px;
  letter-spacing: 1px;
  text-transform: uppercase;
}

/* CARDS */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin: 20px 24px;
}
.card h3 {
  color: var(--primary);
  font-size: 1rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 2px solid #f4f4f4;
}

/* GRIDS */
.grid { display: grid; gap: 16px; margin: 20px 24px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }

.stat-card {
  background: linear-gradient(135deg, #fff, #fff5f5);
  border-left: 4px solid var(--primary);
  padding: 18px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.stat-card .label {
  color: var(--text-light);
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 600;
}
.stat-card .value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--primary);
  margin-top: 4px;
}

/* FORMS */
label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
  font-size: .82rem;
  color: var(--text);
}
input, select, textarea {
  width: 100%;
  padding: 9px 12px;
  border: 2px solid var(--border);
  border-radius: 4px;
  font-size: .9rem;
  font-family: inherit;
  background: #fff;
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(183,28,28,.08);
}
input[readonly] { background: #f8f8f8; color: #555; }
.form-row { margin-bottom: 14px; }

/* BUTTONS */
.btn {
  display: inline-block;
  padding: 9px 16px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: .85rem;
  font-weight: 600;
  text-decoration: none;
  text-align: center;
  transition: background .15s;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: var(--primary-dark); }
.btn-sm { padding: 5px 10px; font-size: .75rem; }
.btn-primary   { background: var(--primary); }
.btn-secondary { background: #7f8c8d; }
.btn-success   { background: var(--success); }
.btn-warning   { background: var(--warning); }
.btn-danger    { background: var(--danger); }
.btn-info      { background: var(--info); }
.btn-success:hover { background: #1e8449; }
.btn-warning:hover { background: #ca6f1e; }
.btn-danger:hover  { background: #a93226; }
.btn-info:hover    { background: #1a5276; }

/* TABLES */
.table-wrap {
  overflow-x: auto;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: #fff;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: .87rem;
}
table thead {
  background: linear-gradient(90deg, var(--primary-dark), var(--primary), var(--accent));
  color: #fff;
}
table thead th {
  padding: 11px 14px;
  text-align: left;
  font-weight: 600;
  font-size: .75rem;
  letter-spacing: .8px;
  text-transform: uppercase;
  white-space: nowrap;
}
table tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid #f0f0f0;
}
table tbody tr:nth-child(even) td { background: #fafafa; }
table tbody tr:hover td { background: #fff5f0; }

/* BADGES */
.badge {
  display: inline-block;
  padding: 4px 9px;
  border-radius: 12px;
  font-size: .72rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge-success { background: #e8f5e9; color: #1e8449; }
.badge-warning { background: #fff3e0; color: #ca6f1e; }
.badge-danger  { background: #ffebee; color: #c0392b; }
.badge-info    { background: #e3f2fd; color: #1a5276; }

/* ALERTS */
.alert-success, .alert-error, .alert-info, .alert-warning {
  padding: 12px 16px;
  border-radius: 4px;
  margin: 16px 24px;
  font-size: .9rem;
  border-left: 4px solid;
}
.alert-success { background: #e8f5e9; color: #1e8449; border-color: var(--success); }
.alert-error   { background: #ffebee; color: #c0392b; border-color: var(--danger); }
.alert-info    { background: #e3f2fd; color: #1a5276; border-color: var(--info); }
.alert-warning { background: #fff3e0; color: #ca6f1e; border-color: var(--warning); }

.muted { color: var(--text-light); font-size: .85rem; }

/* ============================================================
   PAGE TOOLBARS — Students / Finance / Exams
============================================================ */
.fin-toolbar,
.exam-toolbar,
.stu-toolbar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(105px, 1fr));
  gap: 10px;
  margin: 16px 24px;
  padding: 14px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,.06);
}

.fin-tool-btn,
.exam-tool-btn,
.stu-tool-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px 6px;
  background: #f8f9fc;
  border: 1px solid #e0e8f1;
  border-radius: 6px;
  text-decoration: none;
  color: #2c3e50;
  font-size: .74rem;
  font-weight: 600;
  text-align: center;
  transition: all .15s;
  -webkit-tap-highlight-color: transparent;
  min-height: 78px;
  line-height: 1.3;
}
.fin-tool-btn span,
.exam-tool-btn span,
.stu-tool-btn span {
  font-size: 1.4rem;
  margin-bottom: 4px;
  line-height: 1;
}

.fin-tool-btn { border-left: 3px solid #b71c1c; }
.exam-tool-btn { border-left: 3px solid #1e5b96; }
.stu-tool-btn  { border-left: 3px solid #27ae60; }

.fin-tool-btn:hover,
.exam-tool-btn:hover,
.stu-tool-btn:hover {
  color: #fff;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,.15);
}
.fin-tool-btn:hover { background: #b71c1c; border-color: #b71c1c; }
.exam-tool-btn:hover { background: #1e5b96; border-color: #1e5b96; }
.stu-tool-btn:hover  { background: #27ae60; border-color: #27ae60; }

@media (max-width: 900px) {
  .fin-toolbar, .exam-toolbar, .stu-toolbar {
    grid-template-columns: repeat(3, 1fr);
    margin: 12px;
    padding: 10px;
    gap: 8px;
  }
  .fin-tool-btn, .exam-tool-btn, .stu-tool-btn {
    padding: 10px 4px;
    font-size: .68rem;
    min-height: 68px;
  }
  .fin-tool-btn span, .exam-tool-btn span, .stu-tool-btn span {
    font-size: 1.2rem;
  }
}

/* ============================================================
   STUDENTS — Filters, tables, add form
============================================================ */
.stu-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin: 16px 24px;
}
.stu-kpi {
  border-radius: 6px;
  padding: 14px 16px;
  color: #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,.08);
}
.stu-kpi .k-label {
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  opacity: .92;
  font-weight: 600;
}
.stu-kpi .k-value {
  font-size: 1.35rem;
  font-weight: 700;
  margin-top: 4px;
}
.stu-kpi.blue   { background: linear-gradient(135deg,#2980b9,#1a5276); }
.stu-kpi.green  { background: linear-gradient(135deg,#27ae60,#1e8449); }
.stu-kpi.orange { background: linear-gradient(135deg,#e67e22,#ca6f1e); }
.stu-kpi.purple { background: linear-gradient(135deg,#5b6cff,#3a4edc); }

.stu-panel {
  background: #fff;
  border-radius: 6px;
  box-shadow: 0 2px 6px rgba(0,0,0,.06);
  margin: 0 24px 16px;
  overflow: hidden;
}
.stu-panel > summary {
  padding: 12px 18px;
  cursor: pointer;
  font-weight: 600;
  font-size: .95rem;
  color: #fff;
  background: #2c3e50;
  list-style: none;
  user-select: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.stu-panel > summary::-webkit-details-marker { display: none; }
.stu-panel > summary::after {
  content: '▾';
  font-size: 1.1rem;
  transition: transform .2s;
}
.stu-panel[open] > summary::after { transform: rotate(180deg); }
.stu-panel.blue  > summary { background: linear-gradient(90deg,#2980b9,#1a5276); }
.stu-panel.green > summary { background: linear-gradient(90deg,#27ae60,#1e8449); }
.stu-panel .panel-body {
  padding: 18px;
  border-top: 1px solid #eee;
}

.stu-filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
}
.stu-filter-grid .wide { grid-column: span 2; }
.stu-filter-grid label {
  font-size: .7rem;
  text-transform: uppercase;
  color: #666;
  letter-spacing: .5px;
  font-weight: 600;
  display: block;
  margin-bottom: 4px;
}
.stu-filter-grid input,
.stu-filter-grid select {
  padding: 8px 10px;
  font-size: .85rem;
  width: 100%;
  border: 2px solid #e0e0e0;
  border-radius: 4px;
  background: #fff;
}

.stu-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid #eee;
}
.stu-actions .left  { display: flex; gap: 8px; flex-wrap: wrap; }
.stu-actions .right { display: flex; gap: 8px; flex-wrap: wrap; }

.stu-form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 14px;
}
.stu-form-grid .full { grid-column: 1 / -1; }

.stu-table tbody tr { cursor: pointer; transition: background .12s; }
.stu-table tbody tr:hover td { background: #eaf3fb !important; }
.stu-name-link {
  text-decoration: none;
  color: inherit;
  display: block;
}
.stu-name-link:hover strong { color: #1e5b96; }
.stu-name-link small {
  display: block;
  color: #7f8c8d;
  font-size: .72rem;
  margin-top: 2px;
}
.stu-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg,#2980b9,#1a5276);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: .78rem;
  margin-right: 10px;
  flex-shrink: 0;
  overflow: hidden;
}
.stu-avatar img {
  width: 100%; height: 100%;
  border-radius: 50%;
  object-fit: cover;
}

.stu-actions-cell {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* ============================================================
   FINANCE / PAYMENTS
============================================================ */
.tab-bar {
  display: flex; gap: 4px; margin: 16px 24px 0;
  background: #eef2f7; border-radius: 6px; padding: 4px;
  flex-wrap: wrap;
}
.tab-bar a {
  padding: 10px 18px; border-radius: 4px;
  text-decoration: none; font-weight: 600; font-size: .9rem;
  color: #555; transition: .15s;
}
.tab-bar a:hover { background: #dfe6ee; }
.tab-bar a.active {
  background: #1e5b96; color: #fff;
  box-shadow: 0 2px 6px rgba(30,91,150,.3);
}

/* ============================================================
   MOBILE
============================================================ */
@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-100%);
    width: 260px;
    z-index: 200;
    box-shadow: 4px 0 24px rgba(0,0,0,.25);
  }
  .sidebar.open { transform: translateX(0); }
  .menu-toggle { display: inline-block; }
  .sidebar-backdrop.show { display: block; }

  .main { margin-left: 0 !important; width: 100%; }

  .topbar { padding: 12px 14px; gap: 10px; }
  .topbar h2 { font-size: .95rem; margin-left: 6px; }
  .topbar .user-info { font-size: .8rem; gap: 6px; }
  .topbar .user-info .badge { display: none; }

  .card, .grid,
  .alert-success, .alert-error, .alert-info, .alert-warning,
  .stu-panel, .stu-kpi-grid,
  .fin-toolbar, .exam-toolbar, .stu-toolbar {
    margin-left: 12px;
    margin-right: 12px;
  }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }

  .page-banner { margin: 12px; font-size: .88rem; padding: 12px; }

  .sidebar nav > a,
  .nav-group > .nav-group-toggle {
    padding: 13px 18px;
    font-size: .92rem;
  }
  .nav-group .nav-submenu a.sub-link {
    padding: 11px 18px 11px 46px;
    font-size: .86rem;
  }

  body.sidebar-open { overflow: hidden; }
}

@media (min-width: 901px) {
  .sidebar { transform: translateX(0) !important; }
  .sidebar-backdrop { display: none !important; }
  .menu-toggle { display: none !important; }
}

/* PRINT */
@media print {
  @page { size: A4 portrait; margin: 12mm; }
  html, body { background: #fff !important; margin: 0 !important; padding: 0 !important; font-size: 11px; }

  .sidebar, .sidebar-backdrop, .topbar, .menu-toggle,
  .no-print, #offline-banner, .receipt-actions,
  .stu-actions, .fin-toolbar, .exam-toolbar, .stu-toolbar,
  .tab-bar, .filter-actions, .pagination { display: none !important; }

  .main { margin-left: 0 !important; padding: 0 !important; background: #fff !important; }

  .card {
    box-shadow: none !important;
    border: none !important;
    padding: 0 !important;
    margin: 0 0 8mm 0 !important;
    page-break-inside: avoid;
  }

  table { font-size: 10.5px; }
  table thead {
    background: #333 !important;
    color: #fff !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  a { color: #2c3e50 !important; text-decoration: none !important; }

  .a4-sheet {
    width: 186mm !important;
    min-height: auto !important;
    padding: 0 !important;
    margin: 0 !important;
    box-shadow: none !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}