/* APP SHELL */
.app-body {
  margin: 0;
  min-height: 100vh;
  background: #eaf0f6;
  color: var(--ink);
  font-family: var(--font);
}

.app-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: linear-gradient(180deg, #0b2a4a 0%, #123a63 100%);
  color: #fff;
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.sidebar .logo { color: #fff; }
.sidebar .logo span { color: #90caf9; }
.side-nav { display: grid; gap: 0.35rem; }
.side-nav button {
  text-align: left;
  background: transparent;
  border: 0;
  color: rgba(255,255,255,0.78);
  padding: 0.7rem 0.85rem;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
}
.side-nav button:hover,
.side-nav button.is-on {
  background: rgba(255,255,255,0.12);
  color: #fff;
}
.side-foot {
  margin-top: auto;
  font-size: 0.78rem;
  opacity: 0.7;
}

.main {
  padding: 1.25rem 1.4rem 2rem;
  overflow-x: auto;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.1rem;
}
.topbar h1 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.7rem;
  color: var(--navy);
}
.topbar p { margin: 0.2rem 0 0; color: var(--muted); font-size: 0.9rem; }
.top-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.panel-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 1rem;
}
.panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.panel-h {
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}
.panel-h h2 {
  margin: 0;
  font-size: 0.95rem;
  color: var(--navy);
  letter-spacing: 0.02em;
}
.panel-b { padding: 0.9rem 1rem 1.1rem; }

.kpis {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.65rem;
  margin-bottom: 1rem;
}
.kpis .kpi { padding: 0.85rem 0.6rem; }

.table-wrap { overflow-x: auto; }
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}
table.data th,
table.data td {
  text-align: left;
  padding: 0.65rem 0.5rem;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
table.data th {
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
}
table.data tr:hover td { background: #f7fbff; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
}
.badge-soldé { background: #e8f7ef; color: var(--green); }
.badge-partiel { background: #fff4e5; color: var(--amber); }
.badge-impayé { background: #fdecea; color: var(--red); }

.form-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.65rem;
  margin-bottom: 0.75rem;
}
.form-row label {
  display: grid;
  gap: 0.25rem;
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 600;
}
.form-row input,
.form-row select {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
  background: #fff;
  color: var(--ink);
}
.form-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.stat-list { display: grid; gap: 0.55rem; }
.stat-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.65rem 0.75rem;
  background: var(--sky);
  border-radius: 12px;
}
.stat-item strong { color: var(--navy); }
.money-big {
  font-family: var(--display);
  font-size: 1.6rem;
  color: var(--navy);
  margin: 0.2rem 0 0.8rem;
}
.finance-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.7rem;
}
.finance-card {
  background: var(--sky);
  border-radius: 14px;
  padding: 1rem;
}
.finance-card.green { background: var(--mint); }
.finance-card.red { background: #fdecea; }
.finance-card span { display: block; font-size: 0.75rem; color: var(--muted); text-transform: uppercase; }
.finance-card strong { font-size: 1.15rem; color: var(--navy); }

.hidden { display: none !important; }
.view { animation: fade 0.25s ease; }
@keyframes fade {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  background: var(--navy);
  color: #fff;
  padding: 0.7rem 1rem;
  border-radius: 12px;
  opacity: 0;
  transform: translateY(8px);
  transition: 0.2s;
  z-index: 50;
}
.toast.on { opacity: 1; transform: none; }

.login-gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  overflow: auto;
  background:
    radial-gradient(600px 300px at 20% 0%, #cfe3f8, transparent),
    #eaf0f6;
}
.login-gate.hidden {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
}
.login-card {
  width: min(420px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 1.4rem 1.35rem 1.5rem;
  box-shadow: var(--shadow);
  display: grid;
  gap: 0.75rem;
}
.login-card h1 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.55rem;
  color: var(--navy);
}
.login-card > p { margin: 0; color: var(--muted); font-size: 0.92rem; }
.login-card label {
  display: grid;
  gap: 0.3rem;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--muted);
}
.login-card input {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.65rem 0.75rem;
  color: var(--ink);
}
.login-err { color: var(--red); font-size: 0.88rem; margin: 0; }
.login-hint {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
}
.login-hint code {
  background: var(--sky);
  padding: 0.05rem 0.3rem;
  border-radius: 4px;
}
.whoami {
  margin: 0;
  font-size: 0.78rem;
  opacity: 0.8;
  line-height: 1.3;
  white-space: pre-line;
}
.module-badge {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}
.mod-pill {
  font-size: 0.68rem;
  background: rgba(255,255,255,0.14);
  border: 1px solid rgba(255,255,255,0.2);
  padding: 0.2rem 0.45rem;
  border-radius: 999px;
}
.bulletin-stack { display: grid; gap: 1rem; }

.emploi-table {
  min-width: 720px;
  border-collapse: collapse;
}
.emploi-table th,
.emploi-table td {
  vertical-align: middle;
  text-align: center;
  font-size: 0.82rem;
}
.emploi-table thead th {
  background: var(--sky);
  color: var(--navy);
  font-weight: 800;
  white-space: nowrap;
}
.emploi-slot {
  white-space: nowrap;
  font-weight: 800;
  color: var(--navy);
  background: #f7fafc;
  width: 4.5rem;
}
.emploi-cell {
  width: 100%;
  min-width: 92px;
  padding: 0.4rem 0.35rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  text-align: center;
  font: inherit;
  background: #fff;
}
.emploi-cell:focus {
  outline: 2px solid rgba(21, 101, 192, 0.35);
  border-color: #1565c0;
}
.emploi-readonly span {
  display: inline-block;
  padding: 0.25rem 0.4rem;
  background: var(--sky);
  border-radius: 6px;
  font-weight: 700;
  color: var(--navy);
}
.emploi-readonly em {
  color: var(--muted);
  font-style: normal;
}

@media print {
  .sidebar, .topbar, .login-gate, .toast, .dir-callout, #syncStatus { display: none !important; }
  .app-shell { display: block; }
  .main { padding: 0; overflow: visible; }
  .panel { box-shadow: none; border: none; }
  .bulletin-sheet { break-inside: avoid; box-shadow: none; }
  .emploi-cell { border: none; padding: 0.2rem; }
}


.dir-callout {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.85rem;
  background: linear-gradient(135deg, #0b2a4a, #1565c0);
  color: #fff;
  border-radius: 16px;
  padding: 1rem 1.15rem;
  margin-bottom: 1rem;
}
.dir-callout p { margin: 0.25rem 0 0; opacity: 0.9; font-size: 0.9rem; max-width: 46ch; }
.dir-callout .btn-primary {
  background: #fff;
  color: var(--navy);
  box-shadow: none;
}

.mini-form {
  display: grid;
  gap: 0.45rem;
  padding: 0.85rem;
  background: var(--sky);
  border-radius: 12px;
  border: 1px solid var(--line);
}
.mini-form strong { color: var(--navy); font-size: 0.9rem; }
.mini-form label {
  display: grid;
  gap: 0.2rem;
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 700;
}
.mini-form input,
.mini-form select {
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}
.class-list { display: grid; gap: 0.5rem; }
.class-chip {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  gap: 0.15rem 0.75rem;
  text-align: left;
  padding: 0.75rem 0.85rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--sky);
  cursor: pointer;
  color: var(--ink);
}
.class-chip strong { grid-column: 1; color: var(--navy); }
.class-chip span { grid-column: 1; font-size: 0.8rem; color: var(--muted); }
.class-chip em { grid-row: 1 / span 2; grid-column: 2; align-self: center; font-style: normal; color: var(--blue); font-size: 0.8rem; font-weight: 700; }
.class-chip:hover { border-color: var(--blue-bright); background: #fff; }

.grade-table th small { font-weight: 600; color: var(--muted); text-transform: none; letter-spacing: 0; }
.grade-input {
  width: 64px;
  padding: 0.35rem 0.3rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  text-align: center;
}
.grade-input:focus { outline: 2px solid rgba(30,136,229,0.35); border-color: var(--blue-bright); }

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; flex-wrap: wrap; align-items: center; }
  .side-nav { grid-auto-flow: column; grid-auto-columns: max-content; overflow-x: auto; width: 100%; }
  .side-foot { width: 100%; }
  .panel-grid, .kpis, .finance-grid, .form-row { grid-template-columns: 1fr; }
}
