:root {
  --ink: #17212f;
  --muted: #667085;
  --line: #e4e1d8;
  --paper: #f6f4ef;
  --card: #ffffff;
  --accent: #1d4e89;
  --accent-ink: #ffffff;
  --accent-soft: #e8eef7;
  --ok: #1f7a4d;   --ok-soft: #e4f3ea;
  --warn: #9a6200; --warn-soft: #fbf1dc;
  --err: #b42318;  --err-soft: #fdecea;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(23,33,47,.05), 0 2px 8px rgba(23,33,47,.04);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 15px/1.55 "Public Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .88em; background: #f0eee8; padding: 1px 5px; border-radius: 4px; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .6em; }
h1 { font-size: 1.75rem; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; font-weight: 650; }
h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin-top: 1.2em; }
.display { font-family: "Fraunces", Georgia, serif; font-weight: 600; font-size: 2.1rem; letter-spacing: -.02em; }
.wrap { max-width: 1160px; margin: 0 auto; padding: 0 16px; }
.main { padding-top: 28px; padding-bottom: 40px; min-height: calc(100vh - 140px); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.count { font-weight: 500; font-size: 1.1rem; }
.eyebrow { margin: 0 0 4px; font-size: .78rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); }
.footer { color: var(--muted); font-size: .8rem; padding-top: 18px; padding-bottom: 28px; border-top: 1px solid var(--line); }

/* ----- Barre supérieure ----- */
.topbar { background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.topbar-inner { display: flex; align-items: center; gap: 24px; height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--ink); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand-mark, .login-mark {
  display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 8px;
  background: var(--accent); color: #fff; font-family: "Fraunces", Georgia, serif; font-size: 1.05rem;
}
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { color: var(--muted); padding: 7px 12px; border-radius: 7px; font-weight: 500; white-space: nowrap; }
.nav a:hover { background: var(--paper); color: var(--ink); text-decoration: none; }
.nav a.active { color: var(--accent); background: var(--accent-soft); }
.pill { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--err); color: #fff; font-size: .72rem; text-align: center; line-height: 18px; }
.user { display: flex; align-items: center; gap: 10px; }
.user-name { font-size: .88rem; color: var(--muted); max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-toggle { display: none; background: none; border: 1px solid var(--line); border-radius: 7px; font-size: 1.1rem; padding: 4px 10px; cursor: pointer; }

/* ----- Boutons ----- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--accent); color: var(--accent-ink); border: 1px solid var(--accent);
  padding: 9px 16px; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn:hover { filter: brightness(1.08); text-decoration: none; }
.btn:disabled { opacity: .6; cursor: wait; }
.btn-sm { padding: 5px 11px; font-size: .84rem; }
.btn-ghost { background: var(--card); color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { background: var(--paper); filter: none; }
.btn-danger-ghost { background: transparent; color: var(--err); border-color: transparent; }
.btn-danger-ghost:hover { background: var(--err-soft); filter: none; }
.btn-google { background: #fff; color: #1f1f1f; border: 1px solid #dadce0; padding: 11px 20px; width: 100%; margin-top: 8px; }
.btn-google:hover { background: #f8f9fa; filter: none; }

/* ----- Mise en page ----- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { margin: 0; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 20px; box-shadow: var(--shadow); }
.card.flush { padding: 0; overflow: hidden; }
.card.flush > .empty { padding: 28px 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-2 > .card { margin-bottom: 20px; }
.grid-top { align-items: start; }
.grid-side { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 20px; align-items: start; }
.side p { margin-top: 0; }
.side h3:first-child { margin-top: 0; }
.crumbs { margin: 0 0 8px; font-size: .9rem; }
.empty { color: var(--muted); margin: 0; }
.section-title { margin: 26px 0 12px; font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }

/* ----- Statistiques ----- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 20px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; display: flex; flex-direction: column; }
.stat-num { font-family: "Fraunces", Georgia, serif; font-size: 2rem; line-height: 1.1; }
.stat-label { color: var(--muted); font-size: .85rem; }
.stat-alert { border-color: #f3c7c2; background: var(--err-soft); }
.stat-alert .stat-num { color: var(--err); }

/* ----- Tableaux et listes ----- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; padding: 10px 14px; background: #faf9f6; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.card:not(.flush) .table th:first-child, .card:not(.flush) .table td:first-child { padding-left: 0; }
.table .num { text-align: right; }
.table-click tbody tr { cursor: pointer; }
.table-click tbody tr:hover { background: #faf9f6; }
.row-muted td { opacity: .55; }
.actions { display: flex; gap: 6px; justify-content: flex-end; align-items: center; flex-wrap: wrap; }
.actions form { margin: 0; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--line); }
.card:not(.flush) .list li { padding-left: 0; padding-right: 0; }
.list li:last-child { border-bottom: 0; }
.list li > a { display: flex; flex-direction: column; color: var(--ink); min-width: 0; }
.list li > a:hover { text-decoration: none; }
.list li > a:hover .list-title { color: var(--accent); }
.list-title { font-weight: 600; }
.list.compact li { padding: 6px 0; font-size: .88rem; }

/* ----- Badges ----- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: .75rem; font-weight: 600; white-space: nowrap; background: #eee; color: #444; }
.badge-envoye, .badge-resolue { background: var(--ok-soft); color: var(--ok); }
.badge-en_attente { background: #eeece6; color: var(--muted); }
.badge-echec, .badge-rejetee { background: var(--err-soft); color: var(--err); }
.badge-ouverte { background: var(--warn-soft); color: var(--warn); }
.badge-en_cours, .badge-new { background: var(--accent-soft); color: var(--accent); }
.error-text { color: var(--err); }
.chip { display: inline-block; margin: 0 6px 6px 0; padding: 3px 8px; background: var(--paper); border-radius: 6px; }

/* ----- Formulaires ----- */
label { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: .88rem; margin-bottom: 14px; }
label.inline { flex-direction: row; align-items: center; gap: 8px; margin: 0; }
input:not([type=radio]):not([type=checkbox]):not([type=file]), select, textarea {
  font: inherit; font-weight: 400; color: var(--ink); background: #fff;
  border: 1px solid #d5d2c8; border-radius: 8px; padding: 9px 11px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { resize: vertical; line-height: 1.5; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
.form-grid .full, .form-grid .form-actions { grid-column: 1 / -1; }
.form-grid.compact { grid-template-columns: 1fr 1fr; margin-top: 12px; }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.form-actions.spread { justify-content: space-between; }
.inline-form { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 0 0 12px; }
.inline-form select { width: auto; min-width: 260px; }
.filters { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.filters input[type=search] { flex: 1; min-width: 220px; }
.filters select { width: auto; }
details summary { cursor: pointer; }
details.import { padding: 14px 20px; }
details.import[open] summary { margin-bottom: 14px; }
details.missing { padding: 12px 20px; border-bottom: 1px solid var(--line); background: var(--warn-soft); }
details.missing summary { color: var(--warn); font-weight: 600; font-size: .9rem; }
.radios { border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px 4px; margin: 4px 0 16px; }
.radios legend { font-weight: 600; font-size: .88rem; padding: 0 4px; }
.radios label { flex-direction: row; align-items: flex-start; gap: 8px; font-weight: 400; margin-bottom: 8px; }
.radios input { margin-top: 4px; }

/* ----- Dépôt de fichiers ----- */
.dropzone { display: flex; flex-direction: column; gap: 12px; align-items: flex-start; }
.drop {
  width: 100%; border: 2px dashed #cfcbbf; border-radius: var(--radius); padding: 26px 16px; text-align: center;
  align-items: center; cursor: pointer; position: relative; background: #fbfaf7; margin: 0; transition: .15s;
}
.drop.is-over, .drop:hover { border-color: var(--accent); background: var(--accent-soft); }
.drop input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.drop-title { font-size: 1rem; }
.drop-files { color: var(--accent); font-weight: 500; }

/* ----- Progression ----- */
.progress-box { margin-top: 18px; }
.progress { height: 10px; background: #eeece6; border-radius: 6px; overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.error-list { color: var(--err); padding-left: 18px; max-height: 200px; overflow: auto; }

/* ----- Alertes ----- */
.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; border: 1px solid; font-size: .92rem; }
.alert-success { background: var(--ok-soft); border-color: #bfe3cd; color: #14532d; }
.alert-error { background: var(--err-soft); border-color: #f3c7c2; color: #7a1a12; }
.alert-info { background: var(--accent-soft); border-color: #c9d7ea; color: #163e6c; }

/* ----- Connexion ----- */
.login { display: grid; place-items: center; min-height: 70vh; }
.login-card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 36px 32px; max-width: 420px; width: 100%; box-shadow: 0 8px 30px rgba(23,33,47,.07); }
.login-mark { width: 44px; height: 44px; font-size: 1.4rem; border-radius: 11px; margin-bottom: 18px; }
.login-card h1 { margin-bottom: .4em; }
.dev-login { margin-top: 26px; padding-top: 18px; border-top: 1px dashed var(--line); }
.warn { color: var(--warn); font-size: .82rem; background: var(--warn-soft); padding: 8px 10px; border-radius: 6px; }

/* ----- Bulletins (étudiant) ----- */
.cards { display: grid; gap: 12px; }
.bcard { display: flex; gap: 16px; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.bcard-icon { flex: none; width: 46px; height: 56px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-size: .72rem; font-weight: 700; letter-spacing: .05em; border: 1px solid #c9d7ea; }
.bcard-body { flex: 1; min-width: 0; }
.bcard-body h3 { text-transform: none; letter-spacing: 0; color: var(--ink); font-size: 1.05rem; margin: 0 0 2px; }
.bcard-body p { margin: 0; }
.bcard-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

/* ----- Fil de réclamation ----- */
.thread { display: flex; flex-direction: column; gap: 12px; margin-bottom: 18px; }
.msg { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; max-width: 85%; }
.msg header { margin-bottom: 6px; }
.msg-mine { align-self: flex-end; background: var(--accent-soft); border-color: #c9d7ea; }
.msg-body { white-space: normal; overflow-wrap: anywhere; }
.reply textarea { min-height: 110px; }

.pager { display: flex; gap: 4px; flex-wrap: wrap; }
.pager a { padding: 5px 11px; border: 1px solid var(--line); border-radius: 6px; background: var(--card); }
.pager a.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 9px 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; font-weight: 500; }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); }
.tabs a:hover { text-decoration: none; color: var(--ink); }

/* ----- Mobile ----- */
@media (max-width: 860px) {
  .grid-2, .grid-side { grid-template-columns: 1fr; }
  .stats { grid-template-columns: 1fr 1fr; }
  .menu-toggle { display: block; margin-left: auto; }
  .topbar-inner { flex-wrap: wrap; height: auto; min-height: 60px; gap: 0 12px; }
  .nav, .user { display: none; width: 100%; }
  .nav-open .nav { display: flex; flex-direction: column; padding: 6px 0; }
  .nav-open .user { display: flex; justify-content: space-between; padding: 10px 0 14px; border-top: 1px solid var(--line); }
  .bcard { flex-wrap: wrap; }
  .bcard-actions { width: 100%; justify-content: flex-start; }
  .msg { max-width: 100%; }
}
@media (max-width: 560px) {
  h1 { font-size: 1.45rem; }
  .form-grid, .form-grid.compact { grid-template-columns: 1fr; }
  .inline-form select { min-width: 0; width: 100%; }
  .login-card { padding: 28px 20px; }
}

/* Cellules d'actions : rester dans le flux du tableau */
td.actions { display: table-cell; white-space: nowrap; text-align: right; }
td.actions > * { display: inline-block; vertical-align: middle; margin-left: 4px; }

/* ----- Synchronisation Workspace ----- */
.sync-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; }
.sync-card h2 { margin-bottom: .4em; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 12px 0 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.sync-stats { list-style: none; padding: 0; margin: 8px 0 0; display: grid; gap: 4px; }
.sync-stats b { font-weight: 700; }
.sync-errors { margin-top: 10px; }
.sync-errors summary { color: var(--err); font-weight: 600; }
@media (max-width: 860px) { .sync-grid { grid-template-columns: 1fr; } }
