/* =========================================================================
   form.css — Mise en page du formulaire
   ========================================================================= */
.form-page { background: #f2f6f2; }

/* --------------------------------------------------------------- Topbar */
.app-topbar {
  position: sticky;
  top: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 9px 20px;
  background: rgba(255, 255, 255, .97);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
}
.app-topbar .brand-logo { width: 34px; height: 34px; }
.app-topbar .brand-text strong { font-size: .9rem; }
.app-topbar .brand-text small { font-size: .7rem; }

.topbar-school {
  flex: 1;
  min-width: 0;
  font-weight: 700;
  color: var(--green);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-left: 18px;
  border-left: 1px solid var(--line);
}
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.topbar-actions .btn { min-height: 36px; padding: 7px 12px; font-size: .84rem; }

.save-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: .76rem;
  color: var(--muted);
  white-space: nowrap;
  margin-right: 4px;
}
.save-status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #9aa79e;
}
.save-status.saving::before { background: var(--gold); }
.save-status.saved::before { background: #2f9e5b; }
.save-status.error { color: var(--red); }
.save-status.error::before { background: var(--red); }

.count-badge {
  display: inline-flex;
  min-width: 18px;
  height: 18px;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  border-radius: 999px;
  background: #e6ece7;
  color: #3f5045;
  font-size: .68rem;
  font-weight: 800;
  margin-left: 4px;
}
.count-badge.has-errors { background: var(--red); color: #fff; }

.more-menu { position: relative; }
.more-menu > summary { list-style: none; cursor: pointer; }
.more-menu > summary::-webkit-details-marker { display: none; }
.more-menu[open] > summary { background: var(--green-50); }
.more-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  width: 272px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 11px;
  box-shadow: var(--shadow-lg);
  padding: 6px;
  z-index: 80;
}
.more-panel button {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 9px 11px;
  border-radius: 7px;
  font-size: .84rem;
  color: var(--ink);
  cursor: pointer;
}
.more-panel button:hover { background: var(--green-50); }
.more-panel button.danger { color: var(--red); }
.more-panel #btn-sync { color: var(--green); font-weight: 700; }
.sync-status {
  margin: 1px 11px 8px;
  font-size: .72rem;
  color: var(--muted);
  line-height: 1.35;
}
.sync-status.ok { color: #1f7a45; }
.sync-status.pending { color: #8a6200; }
.sync-status.error { color: var(--red); }
.more-panel hr { border: 0; border-top: 1px solid var(--line); margin: 6px 0; }

/* --------------------------------------------------------------- Layout */
.app-layout {
  max-width: 1500px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 252px minmax(0, 1fr);
  align-items: start;
}

.sidebar {
  position: sticky;
  top: 55px;
  height: calc(100vh - 55px);
  overflow-y: auto;
  padding: 22px 16px 28px 20px;
  border-right: 1px solid var(--line);
  background: rgba(247, 250, 247, .8);
}
.side-school {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 4px 6px 16px;
  border-bottom: 1px solid var(--line);
}
.side-kicker {
  font-size: .66rem;
  text-transform: uppercase;
  letter-spacing: .1em;
  font-weight: 800;
  color: var(--green-600);
}
.side-school strong {
  font-size: .94rem;
  color: var(--green);
  line-height: 1.3;
  overflow-wrap: anywhere;
}
.side-statut { font-size: .74rem; color: var(--muted); }

.side-nav { display: flex; flex-direction: column; gap: 2px; padding: 14px 0; }
.side-link {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 8px 8px;
  border-radius: 8px;
  color: #4b5b50;
  font-size: .8rem;
  line-height: 1.35;
  text-decoration: none;
  border: 1px solid transparent;
}
.side-link:hover { background: #fff; text-decoration: none; }
.side-link.active {
  background: #fff;
  border-color: #d5e4d9;
  color: var(--green);
  font-weight: 700;
  box-shadow: 0 1px 2px rgba(20, 83, 45, .05);
}
.side-num {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  border-radius: 6px;
  background: #e9efe9;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: .68rem;
  font-weight: 800;
}
.side-link.active .side-num { background: var(--green); color: #fff; }

.side-progress { padding: 14px 6px 0; border-top: 1px solid var(--line); }
.progress-head { display: flex; flex-direction: column; gap: 2px; margin-bottom: 8px; }
.progress-head span {
  font-size: .66rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  font-weight: 800;
  color: var(--green-600);
}
.progress-head strong { font-size: .72rem; color: var(--muted); font-weight: 600; }
.progress-track { height: 6px; border-radius: 999px; background: #e1e8e2; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--green); border-radius: 999px; transition: width .25s ease; }
.side-note { margin-top: 18px; padding: 10px 11px; border-radius: 9px; background: #eef4ef; color: #5f7065; font-size: .7rem; line-height: 1.45; }

.form-main { min-width: 0; padding: 26px 30px 70px; max-width: 1220px; }

.flash {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 120;
  background: var(--green);
  color: #fff;
  padding: 12px 18px;
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  font-size: .86rem;
  font-weight: 600;
  max-width: 360px;
}

.form-intro {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding: 6px 4px 22px;
}
.form-intro h1 { margin: 0 0 5px; color: var(--green); font-size: clamp(1.6rem, 2.6vw, 2.15rem); letter-spacing: -.02em; }
.form-intro p:last-child { margin: 0; color: var(--muted); font-size: .9rem; }
.intro-meta {
  flex: 0 0 auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 14px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  text-align: right;
}
.intro-meta span { font-size: .66rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; }
.intro-meta strong { color: var(--green); font-size: 1rem; }

/* ------------------------------------------------------------- Sections */
.form-section {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: 0 1px 2px rgba(20, 83, 45, .03);
  scroll-margin-top: 76px;
}
.section-heading {
  display: flex;
  align-items: flex-start;
  gap: 13px;
  padding-bottom: 16px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--line);
}
.page-number {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--green);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: .9rem;
}
.section-heading h2 { margin: 1px 0 3px; font-size: 1.22rem; color: var(--green); letter-spacing: -.01em; }
.section-heading p { margin: 0; color: var(--muted); font-size: .82rem; }

.section-blocks { display: flex; flex-direction: column; gap: 22px; }
.fields-block h3,
.table-block h3,
.summary-block h3 {
  margin: 0 0 12px;
  font-size: .94rem;
  color: var(--green);
  letter-spacing: .01em;
}
.fields-block + .fields-block { border-top: 1px dashed var(--line); padding-top: 18px; }

.field-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px 16px; }
.field-grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.field-grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.field-grid.cols-1 { grid-template-columns: 1fr; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field-label { font-size: .76rem; font-weight: 700; color: #405046; }
.req { color: var(--red); }
.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 8px 10px;
  font-size: .88rem;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.field textarea { resize: vertical; }
.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: 0;
  border-color: var(--green-600);
  box-shadow: 0 0 0 3px rgba(31, 122, 69, .13);
}
.field input.computed-field,
.field input[readonly] {
  background: #f1f5f2;
  color: #405046;
  cursor: default;
}
.field input.computed-field:focus,
.field input[readonly]:focus {
  border-color: var(--line-strong);
  box-shadow: none;
}
.field-hint { color: var(--muted); font-size: .72rem; line-height: 1.4; }
.field-check { justify-content: flex-start; padding-top: 4px; }
.check-line {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  font-size: .83rem;
  font-weight: 600;
  color: #405046;
  cursor: pointer;
}
.check-line input { width: 18px; height: 18px; min-height: 0; margin: 2px 0 0; accent-color: var(--green); }
.field-checks { gap: 8px; }
.check-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.check-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 7px 11px;
  background: #fff;
  font-size: .8rem;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.check-pill:hover { background: var(--green-50); }
.check-pill:has(input:checked) { background: var(--green-100); border-color: #94b8a0; color: var(--green); font-weight: 700; }
.check-pill input { width: 15px; height: 15px; min-height: 0; accent-color: var(--green); }

.block-hint { margin: 12px 0 0; color: var(--muted); font-size: .76rem; }

/* -------------------------------------------------------------- Tableaux */
.table-block { min-width: 0; }
.block-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.block-head h3 { margin: 0; }
.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  background: var(--green-100);
  color: var(--green);
  font-size: .66rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: 4px 8px;
}
.block-note { margin: 0 0 10px; color: var(--muted); font-size: .76rem; line-height: 1.45; }

.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}
.data-table {
  width: 100%;
  min-width: 640px;
  border-collapse: collapse;
  font-size: .9rem;
}
.data-table th,
.data-table td { border-bottom: 1px solid #e5ebe6; border-right: 1px solid #edf1ed; }
.data-table tr:last-child th,
.data-table tr:last-child td { border-bottom: 0; }
.data-table th:last-child,
.data-table td:last-child { border-right: 0; }
.data-table thead th {
  background: var(--green-50);
  color: #344a3b;
  font-size: .82rem;
  font-weight: 800;
  text-align: center;
  padding: 8px 5px;
  line-height: 1.25;
  vertical-align: middle;
  white-space: nowrap;
}
.data-table thead th.corner {
  text-align: left;
  padding-left: 10px;
  color: var(--green);
  background: #edf4ee;
}
.data-table .row-label {
  text-align: left;
  padding: 7px 10px;
  font-weight: 600;
  color: #3c4c42;
  background: #fcfdfc;
  line-height: 1.3;
}
.data-table .row-group {
  width: 104px;
  max-width: 120px;
  padding: 7px 8px;
  background: #f0f6f1;
  color: var(--green);
  font-size: .82rem;
  font-weight: 800;
  text-align: left;
  vertical-align: middle;
  line-height: 1.3;
}
.data-table .row-sub {
  text-align: left;
  padding: 6px 8px;
  font-weight: 500;
  color: #4a5a4f;
  background: #fcfdfc;
  font-size: .86rem;
}
.data-table .row-sub.indent { padding-left: 16px; }
.data-table td.num { padding: 2px 3px; text-align: center; vertical-align: middle; }
.data-table td.txt { padding: 2px 3px; text-align: left; vertical-align: middle; }
.data-table td.col-alt { background: var(--green-50); }
.data-table td.col-alt .cell-input { background: transparent; }
.data-table td.col-alt .cell-input:hover,
.data-table td.col-alt .cell-input:focus { background: #fff; }

/* Couleurs de colonnes : vert, bleu, rouge (formulaire uniquement). */
.data-table .col-font { color: var(--col-ink); }
.data-table .col-font-0 { --col-ink: #1f6b43; }
.data-table .col-font-1 { --col-ink: #1f4e79; }
.data-table .col-font-2 { --col-ink: #9b1c1c; }
.data-table td.col-font .cell-input { color: var(--col-ink); }
.data-table td.calc-cell.col-font,
.data-table td.calc.col-font { color: var(--col-ink); }
.data-table .row-num { width: 44px; text-align: center; font-weight: 800; color: var(--green); }
.data-table td.check-cell { padding: 1px 3px; text-align: center; }
.data-table .cell-check {
  width: 20px;
  height: 20px;
  accent-color: var(--green);
  cursor: pointer;
  vertical-align: middle;
}
.data-table-single { min-width: 1500px; }
.data-table-computed { min-width: 880px; }
.data-table-single thead th.corner { text-align: center; }
.data-table-single thead th { white-space: normal; }
.data-table td.txt .cell-input { text-align: left; }
.cell-input.cell-select {
  appearance: auto;
  -moz-appearance: auto;
  padding: 3px 4px;
  text-align: left;
}
.cell-input {
  width: 100%;
  min-width: 42px;
  height: 30px;
  border: 1px solid transparent;
  border-radius: 5px;
  background: #fbfdfb;
  text-align: center;
  padding: 3px 6px;
  font-size: .9rem;
  color: var(--ink);
  appearance: textfield;
  -moz-appearance: textfield;
}
.cell-input::-webkit-outer-spin-button,
.cell-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.cell-input:hover { border-color: #d7e2d9; }
.cell-input:focus {
  outline: 0;
  border-color: var(--green-600);
  background: #fff;
  box-shadow: 0 0 0 2px rgba(31, 122, 69, .14);
}
td.calc-cell,
td.calc {
  background: #f1f5f2;
  color: #405247;
  padding: 7px 6px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.row-computed th,
.row-computed td { background: #f7faf7; }
.row-computed .row-sub { font-weight: 700; color: #304638; }
.row-summary th,
.row-summary td {
  background: var(--green-100);
  font-weight: 800;
  color: var(--green);
  padding: 8px 6px;
}
.row-summary .row-label { background: var(--green-100); color: var(--green); }
.neg { color: var(--red) !important; background: #fdf1ef !important; }
.table-legend { margin: 7px 2px 0; color: #78887c; font-size: .69rem; }

/* -------------------------------------------------------------- Synthèse */
.summary-block {
  background: var(--green-50);
  border: 1px solid #d5e4d9;
  border-radius: 12px;
  padding: 18px;
}
.summary-block h3 { margin-bottom: 4px; }
.summary-block .block-note { margin-bottom: 14px; }
.synthesis-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
}
.synth-card {
  background: #fff;
  border: 1px solid #dce7de;
  border-radius: 10px;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  text-align: center;
}
.synth-value { font-size: 1.28rem; font-weight: 800; color: var(--green); line-height: 1.1; font-variant-numeric: tabular-nums; }
.synth-label { font-size: .66rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; }

/* ------------------------------------------------------------ Validation */
.validation-panel {
  margin-top: 20px;
  background: #fff;
  border: 1px solid #e8cf9a;
  border-radius: 14px;
  padding: 20px 22px;
  box-shadow: var(--shadow);
  scroll-margin-top: 80px;
}
.validation-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.validation-head h2 { margin: 0; font-size: 1.08rem; color: var(--green); }
.icon-btn {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 7px;
  width: 30px;
  height: 30px;
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
}
.icon-btn:hover { background: var(--green-50); }
.validation-ok { margin: 14px 0 0; color: var(--green-700); font-weight: 600; }
.validation-title { margin: 18px 0 8px; font-size: .86rem; text-transform: uppercase; letter-spacing: .07em; }
.validation-title.error { color: var(--red); }
.validation-title.warning { color: #9a6700; }
.validation-list { margin: 0; padding-left: 20px; display: grid; gap: 6px; }
.validation-list li { font-size: .83rem; color: #44544a; }
.validation-list a { color: inherit; }
.validation-list a:hover { color: var(--green); }
.warning-list li::marker { color: #d4a72c; }

/* --------------------------------------------------------------- Footer */
.form-footer {
  margin-top: 30px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 16px;
  color: var(--muted);
  font-size: .74rem;
}
.form-footer p { margin: 0; }
.form-footer .form-credit {
  display: inline-block;
  margin-top: 4px;
  color: var(--green-600);
  font-weight: 600;
  font-size: .72rem;
}

/* ------------------------------------------------------------ Responsive */
@media (max-width: 1180px) {
  .app-layout { grid-template-columns: 224px minmax(0, 1fr); }
  .form-main { padding: 22px 22px 60px; }
  .synthesis-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  .app-topbar { flex-wrap: wrap; gap: 8px 12px; padding: 9px 14px; }
  .topbar-school { order: 3; flex-basis: 100%; border-left: 0; padding-left: 0; font-size: .82rem; }
  .topbar-actions { margin-left: auto; }
  .save-status { display: none; }
  .app-layout { display: block; }
  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 14px 16px;
    background: #fff;
  }
  .side-school { padding: 0 0 12px; }
  .side-nav {
    flex-direction: row;
    overflow-x: auto;
    gap: 6px;
    padding: 10px 0;
    scrollbar-width: thin;
  }
  .side-link { flex: 0 0 auto; border: 1px solid var(--line); background: #fff; padding: 7px 10px; }
  .side-link .side-title { white-space: nowrap; }
  .side-progress { border-top: 0; padding: 4px 0 0; }
  .side-note { display: none; }
  .form-main { padding: 18px 14px 50px; }
  .form-intro { padding-bottom: 16px; }
  .field-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .field-grid.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .field-grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .data-table { min-width: 600px; }
}

@media (max-width: 640px) {
  .app-topbar .brand-text { display: none; }
  .topbar-actions .btn { padding: 7px 10px; }
  .more-panel { position: fixed; right: 10px; left: 10px; top: 58px; width: auto; }
  .form-section { padding: 16px; border-radius: 13px; }
  .section-heading { gap: 10px; }
  .section-heading h2 { font-size: 1.05rem; }
  .field-grid,
  .field-grid.cols-3,
  .field-grid.cols-4,
  .field-grid.cols-2 { grid-template-columns: 1fr; }
  .field[style] { grid-column: auto !important; }
  .synthesis-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-intro { align-items: flex-start; flex-direction: column; gap: 10px; }
  .intro-meta { text-align: left; }
  .form-footer { flex-direction: column; }
  .flash { left: 16px; right: 16px; bottom: 16px; max-width: none; }
}
