:root {
  --ink: #111111;
  --ink-soft: #3a3a3a;
  --muted: #757575;
  --border: #d8d8d8;
  --border-strong: #b0b0b0;
  --bg: #f5f5f5;
  --card-bg: #ffffff;
  --hover: #f0f0f0;
  --radius: 6px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.1);
  --danger: #b3261e;
  --danger-dark: #8c1d17;
}

* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: "Segoe UI", Arial, Helvetica, sans-serif;
  background:
    radial-gradient(circle at 1px 1px, rgba(0,0,0,0.035) 1px, transparent 0) 0 0 / 22px 22px,
    var(--bg);
  color: var(--ink);
  min-height: 100vh;
  opacity: 1;
  transition: opacity 0.15s ease;
}

html.page-enter body,
html.page-leave body {
  opacity: 0;
}

/* Scoped to the dashboard only (not body — making body itself a flex
   container broke every other page: .container's margin:0 auto triggers
   flexbox auto-margin sizing, which shrinks it to its content's width
   instead of stretching to the viewport, dragging the whole page as wide
   as the widest table regardless of min-width fixes). */
.page-flex {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

*:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.topbar {
  background: var(--ink);
  color: #fff;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-shrink: 0;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.topbar-logo {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid rgba(255, 255, 255, 0.18);
  flex-shrink: 0;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
}

.topbar h1 {
  font-size: 1.05rem;
  margin: 0;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar .school-info {
  font-size: 0.85rem;
  opacity: 0.75;
}

.skeleton-text {
  display: inline-block;
  min-width: 160px;
  height: 1em;
  border-radius: 4px;
  background: linear-gradient(90deg, rgba(255,255,255,0.12) 25%, rgba(255,255,255,0.25) 37%, rgba(255,255,255,0.12) 63%);
  background-size: 400% 100%;
  animation: skeleton-shimmer 1.4s ease infinite;
}

@keyframes skeleton-shimmer {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}

@keyframes fade-in-up {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.fade-in-up {
  animation: fade-in-up 0.35s ease both;
}

@keyframes shake {
  10%, 90% { transform: translateX(-1px); }
  20%, 80% { transform: translateX(2px); }
  30%, 50%, 70% { transform: translateX(-4px); }
  40%, 60% { transform: translateX(4px); }
}

.alert.show {
  animation: shake 0.4s ease;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease, border-color 0.15s ease;
}

.btn-primary { background: var(--ink); color: #fff; }
.btn-primary:hover { background: var(--ink-soft); }
.btn-secondary { background: #fff; color: var(--ink); border: 1px solid var(--border-strong); }
.btn-secondary:hover { background: var(--hover); }
.btn-ghost { background: transparent; color: #fff; border: 1px solid rgba(255,255,255,0.4); }
.btn-ghost:hover { background: rgba(255,255,255,0.15); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn:active:not(:disabled) { transform: translateY(1px); }

.btn-spinner {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.35);
  border-top-color: #fff;
  animation: spin 0.7s linear infinite;
}

.btn-secondary .btn-spinner {
  border: 2px solid rgba(0,0,0,0.15);
  border-top-color: var(--ink);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 32px 20px 60px;
}

.container-wide {
  max-width: 1360px;
}

.center-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-page-header {
  margin-bottom: 28px;
}

.login-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px;
  width: 100%;
  max-width: 340px;
  box-shadow: var(--shadow-md);
}

.login-logo {
  display: block;
  width: 60px;
  height: 60px;
  object-fit: cover;
  border-radius: 14px;
  box-shadow: var(--shadow-md);
  margin: 0 auto 24px;
}

.nmc-logo-bg {
  display: block;
  width: 128px;
  height: 128px;
  border-radius: 50%;
  object-fit: cover;
  box-shadow: var(--shadow-md);
}

.field {
  margin-bottom: 18px;
}

.field label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 6px;
}

.field input, .field select {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-family: inherit;
  background: #fff;
  color: var(--ink);
}

.field input:focus, .field select:focus {
  outline: none;
  border-color: var(--ink);
}

.field .hint {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 5px;
}

.alert {
  padding: 11px 14px;
  border-radius: var(--radius);
  font-size: 0.87rem;
  margin-bottom: 16px;
  display: none;
  border: 1px solid var(--border-strong);
  background: var(--hover);
  color: var(--ink);
}

.alert.show { display: block; }
.alert-error { border-left: 3px solid var(--ink); }
.alert-success { border-left: 3px solid var(--ink); }

.full-width { width: 100%; }

.page-title {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--ink);
  margin: 0;
}

.page-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}

.hero {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
}

.hero-inner {
  width: 100%;
  max-width: 760px;
}

.hero-inner-wide {
  max-width: 1020px;
}

.hero-kicker {
  text-align: center;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 22px;
}

.cards-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 20px;
}

.cards-grid > .class-card,
.cards-grid > .add-division-card {
  flex: 1 1 260px;
  max-width: 300px;
}

.class-card {
  position: relative;
  overflow: hidden;
  background: var(--card-bg);
  border-radius: 14px;
  padding: 32px 28px 64px;
  cursor: pointer;
  border: 1px solid var(--border);
  transition: border-color 0.15s ease, box-shadow 0.2s ease, transform 0.2s ease;
  text-decoration: none;
  color: inherit;
  display: block;
}

.class-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--ink);
  transform: translateY(-4px);
}

.class-card:active {
  transform: translateY(-1px);
}

.class-card-watermark {
  position: absolute;
  top: -28px;
  right: -8px;
  font-size: 7.5rem;
  font-weight: 800;
  line-height: 1;
  color: rgba(0, 0, 0, 0.04);
  pointer-events: none;
  user-select: none;
}

.class-card .icon {
  position: relative;
  z-index: 1;
  width: 52px;
  height: 52px;
  border-radius: 12px;
  background: var(--ink);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.3rem;
  margin-bottom: 16px;
  transition: transform 0.2s ease;
}

.class-card:hover .icon {
  transform: scale(1.08);
}

.class-card h2 {
  position: relative;
  z-index: 1;
  margin: 0 0 16px;
  font-size: 1.2rem;
  color: var(--ink);
}

.class-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.progress-track {
  position: relative;
  z-index: 1;
  height: 6px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--ink);
  border-radius: inherit;
  transition: width 0.7s cubic-bezier(0.22, 1, 0.36, 1);
}

.class-card .progress-line {
  position: relative;
  z-index: 1;
  margin-top: 10px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
}

.class-card-arrow {
  position: absolute;
  z-index: 1;
  bottom: 22px;
  right: 24px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  color: var(--muted);
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

.class-card:hover .class-card-arrow {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
  transform: translateX(3px);
}

.class-card-delete {
  position: absolute;
  z-index: 2;
  top: 14px;
  right: 14px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid transparent;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.class-card-delete:hover {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.add-division-card {
  background: transparent;
  border: 1px dashed var(--border-strong);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-family: inherit;
  min-height: 180px;
  cursor: pointer;
}

.add-division-card:hover {
  border-color: var(--ink);
  border-style: solid;
  background: var(--card-bg);
}

.add-division-card:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.add-division-plus {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  color: var(--muted);
  margin-bottom: 12px;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.add-division-card:hover .add-division-plus {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

.add-division-card h2 {
  margin: 0 0 4px;
  font-size: 1.1rem;
}

.add-division-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.page-footer {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 18px;
  color: var(--muted);
  font-size: 0.78rem;
  border-top: 1px solid var(--border);
}

.footer-logo {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  object-fit: cover;
}

.footer-logo-nmc {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  object-fit: cover;
}

.footer-divider {
  width: 1px;
  height: 14px;
  background: var(--border);
}

.breadcrumb {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 10px;
}

.breadcrumb a { color: var(--ink); }
.breadcrumb a:hover { text-decoration: underline; }

.panel {
  background: var(--card-bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
  margin-bottom: 24px;
}

.panel-header {
  padding: 16px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fafafa;
}

.panel-header h3 {
  margin: 0;
  font-size: 1rem;
}

.panel-body { padding: 22px; }

.division-accordion {
  display: flex;
  flex-direction: column;
}

.division-item {
  border-bottom: 1px solid var(--border);
}

.division-item:last-child {
  border-bottom: none;
}

.division-item-header {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 18px 22px;
  background: #fff;
  border: none;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  transition: background 0.15s ease;
}

.division-item-header:hover {
  background: var(--hover);
}

.division-item.open .division-item-header {
  background: var(--ink);
  color: #fff;
}

.division-item-name {
  font-size: 1rem;
  font-weight: 700;
  flex: 1;
}

.division-item-count {
  font-size: 0.85rem;
  color: var(--muted);
  margin-right: 16px;
}

.division-item.open .division-item-count {
  color: rgba(255, 255, 255, 0.75);
}

.division-item-chevron {
  font-size: 0.8rem;
  color: var(--muted);
  transition: transform 0.15s ease;
}

.division-item.open .division-item-chevron {
  color: #fff;
  transform: rotate(-180deg);
}

.division-item-body:empty {
  display: none;
}

.division-item-body {
  padding: 22px;
  background: #fafafa;
  border-top: 1px solid var(--border);
  animation: fade-in-down 0.2s ease both;
}

@keyframes fade-in-down {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

.sheet-scroll {
  overflow-x: auto;
}

table.sheet-table {
  min-width: 800px;
  table-layout: fixed;
}

table.sheet-table .col-index {
  width: 40px;
  text-align: center;
  color: var(--muted);
}

table.sheet-table .col-gender {
  width: 100px;
}

table.sheet-table .col-marks {
  width: 95px;
}

table.sheet-table .col-action {
  width: 150px;
  text-align: right;
  overflow: visible;
}

table.sheet-table th, table.sheet-table td {
  overflow: hidden;
  text-overflow: ellipsis;
}

table.sheet-table tr.edit-row {
  background: var(--hover);
}

table.sheet-table tr.edit-row td {
  padding: 8px 10px;
}

table.sheet-table input,
table.sheet-table select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  font-size: 0.88rem;
  font-family: inherit;
  background: #fff;
  color: var(--ink);
}

table.sheet-table input:focus,
table.sheet-table select:focus {
  outline: none;
  border-color: var(--ink);
}

table.sheet-table input.invalid,
table.sheet-table select.invalid {
  border-color: var(--ink);
  border-width: 2px;
  background: #f2f2f2;
}

.row-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: nowrap;
  gap: 8px;
}

.row-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.row-actions .btn-sm {
  flex: 0 0 auto;
  white-space: nowrap;
}

.row-icon-btn:hover {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

.row-icon-btn.danger:hover {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.teacher-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 0.92rem;
}

.teacher-label {
  color: var(--muted);
  font-size: 0.85rem;
}

.teacher-row-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.btn-sm {
  padding: 7px 14px;
  font-size: 0.85rem;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

table.data-table th, table.data-table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

table.data-table th {
  background: #fafafa;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

table.data-table tr:last-child td { border-bottom: none; }
table.data-table tr:hover { background: var(--hover); }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  background: var(--ink);
  color: #fff;
}

.link-btn {
  background: none;
  border: none;
  color: var(--ink);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0;
  text-decoration: underline;
}

.link-btn:hover { color: var(--ink-soft); }

.link-btn-danger { color: var(--danger); }
.link-btn-danger:hover { color: var(--danger-dark); }

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
}

.completion-banner {
  background: var(--hover);
  border: 1px solid var(--border-strong);
  color: var(--ink);
  border-radius: var(--radius);
  padding: 20px 22px;
  text-align: center;
  font-weight: 600;
  margin-bottom: 24px;
  animation: fade-in-up 0.35s ease both;
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  text-align: center;
}

.stat-value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.2;
}

.stat-label {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.table-toolbar {
  padding: 14px 22px;
  border-bottom: 1px solid var(--border);
  background: #fafafa;
}

.search-input {
  width: 100%;
  max-width: 320px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.88rem;
  font-family: inherit;
  background: #fff;
  color: var(--ink);
}

.search-input:focus {
  outline: none;
  border-color: var(--ink);
}

@keyframes row-saved-flash {
  0% { background: #e4e4e4; }
  100% { background: transparent; }
}

table.data-table tr.just-saved {
  animation: row-saved-flash 1s ease;
}

@media (max-width: 560px) {
  .login-card { padding: 28px 22px; }
  .container { padding: 20px 14px 50px; }
  .topbar { flex-wrap: wrap; gap: 10px; padding: 12px 16px; }
  .topbar-brand { min-width: 0; flex: 1 1 auto; }
  .topbar h1 { font-size: 0.92rem; }
  .topbar-right { flex-wrap: wrap; gap: 10px; }
  .topbar .school-info { display: none; }
}

.danger-zone {
  border-color: var(--danger);
}

.danger-zone .panel-header {
  background: #fdf1f0;
  border-bottom-color: var(--danger);
}

.danger-zone .panel-header h3 {
  color: var(--danger-dark);
}

.danger-text {
  color: var(--ink-soft);
  font-size: 0.88rem;
  line-height: 1.5;
  margin: 0 0 16px;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger-dark);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}

.modal-overlay[hidden] {
  display: none;
}

.modal {
  background: var(--card-bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  padding: 28px;
  width: 100%;
  max-width: 400px;
  animation: fade-in-up 0.2s ease both;
}

.modal h3 {
  margin: 0 0 10px;
  font-size: 1.1rem;
}

.modal-message {
  color: var(--muted);
  font-size: 0.92rem;
  margin: 0 0 4px;
  white-space: pre-line;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
}
