/* SURICATE — feuille de style unique (charte GRETA CFA Loire, reprise de BUDGEO) */

:root {
  --primary: #E2600C;
  --primary-hover: #B94D08;
  --primary-light: #FDECDF;
  --ink: #2B2A28;
  --bg: #F4F1EE;
  --surface: #FFFFFF;
  --text: #262320;
  --muted: #6F6862;
  --border: #E3DDD6;

  /* Statuts d'échéance */
  --st-echue: #9B1C1C;
  --st-echue-bg: #FBE3E3;
  --st-critique: #C2410C;
  --st-critique-bg: #FDE7D8;
  --st-urgent: #A16207;
  --st-urgent-bg: #FEF3C7;
  --st-surveiller: #1D4ED8;
  --st-surveiller-bg: #E0EAFD;
  --st-valide: #15803D;
  --st-valide-bg: #DCF5E4;
  --st-neutre: #57534E;
  --st-neutre-bg: #ECE8E4;

  --radius: 8px;
  --shadow: 0 1px 3px rgba(43, 42, 40, 0.08), 0 1px 2px rgba(43, 42, 40, 0.04);
  font-size: 15px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
.lbl-legend { font-size: .85rem; font-weight: 600; color: var(--muted); margin-bottom: .35rem; }

html, body { margin: 0; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a { color: var(--primary-hover); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .75rem; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }

/* ------------------------------------------------------------ Bandeau */
.topbar {
  background: var(--ink);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0 1.5rem;
  min-height: 56px;
  flex-wrap: wrap;
}
.brand {
  display: flex;
  align-items: center;
  gap: .6rem;
  color: #fff;
  text-decoration: none;
  font-weight: 700;
  letter-spacing: .08em;
}
.brand svg, .brand img { width: 34px; height: 34px; flex: none; object-fit: contain; }
.brand .brand-e { color: var(--primary); }
.brand small { font-weight: 400; letter-spacing: 0; opacity: .7; font-size: .8rem; }

.nav { display: flex; gap: .25rem; flex-wrap: wrap; flex: 1; }
.nav a {
  color: #E8E3DE;
  text-decoration: none;
  padding: .45rem .75rem;
  border-radius: 6px;
  font-size: .93rem;
}
.nav a:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.nav a.active { background: var(--primary); color: #fff; }

.userbox { display: flex; align-items: center; gap: .75rem; font-size: .9rem; color: #E8E3DE; }
.userbox .role {
  font-size: .75rem;
  border: 1px solid rgba(255,255,255,.35);
  border-radius: 999px;
  padding: 0 .5rem;
}
.userbox button {
  background: transparent;
  border: 1px solid rgba(255,255,255,.35);
  color: #fff;
  border-radius: 6px;
  padding: .3rem .7rem;
  cursor: pointer;
  font: inherit;
  font-size: .85rem;
}
.userbox button:hover { background: rgba(255,255,255,.1); }

/* ------------------------------------------------------------ Mise en page */
main { max-width: 1200px; margin: 0 auto; padding: 1.5rem; }

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.page-head p { margin: .25rem 0 0; color: var(--muted); }
.page-head h1 { margin: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

/* ------------------------------------------------------------ Messages */
#messages {
  position: sticky;
  top: 0;
  z-index: 50;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.5rem;
}
.msg {
  margin-top: .75rem;
  padding: .7rem 1rem;
  border-radius: var(--radius);
  border: 1px solid;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  box-shadow: var(--shadow);
}
.msg button { background: none; border: 0; cursor: pointer; font-size: 1.1rem; line-height: 1; color: inherit; }
.msg.ok { background: var(--st-valide-bg); border-color: #A7E3BA; color: #14532D; }
.msg.error { background: var(--st-echue-bg); border-color: #F3B4B4; color: #7F1D1D; }
.msg.info { background: var(--primary-light); border-color: #F6C9A6; color: #7C2D06; }

/* ------------------------------------------------------------ Boutons & formulaires */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: .5rem .95rem;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
  font-size: .93rem;
  text-decoration: none;
}
.btn:hover { background: #FAF8F6; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.danger { color: var(--st-echue); border-color: #F3B4B4; }
.btn.danger:hover { background: var(--st-echue-bg); }
.btn.small { padding: .25rem .6rem; font-size: .85rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: .9rem 1rem;
}
.field { display: flex; flex-direction: column; gap: .3rem; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: .85rem; font-weight: 600; color: var(--muted); }
.field .hint { font-size: .8rem; color: var(--muted); }
input[type=text], input[type=search], input[type=email], input[type=password], input[type=number], select, textarea {
  font: inherit;
  padding: .5rem .65rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  width: 100%;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
  border-color: var(--primary);
}
.checkbox { display: flex; align-items: center; gap: .5rem; font-size: .93rem; }
.field label.checkbox { font-size: .93rem; font-weight: 400; color: var(--text); }
.checks { display: flex; flex-wrap: wrap; gap: .4rem 1.1rem; }
.form-actions { display: flex; gap: .6rem; justify-content: flex-end; margin-top: 1.1rem; }

/* ------------------------------------------------------------ Tableaux */
.table-wrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; font-size: .93rem; }
table.grid th {
  text-align: left;
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  border-bottom: 2px solid var(--border);
  padding: .55rem .6rem;
  white-space: nowrap;
}
table.grid td { border-bottom: 1px solid var(--border); padding: .55rem .6rem; vertical-align: top; }
table.grid tr:hover td { background: #FBF9F7; }
table.grid td.actions { white-space: nowrap; text-align: right; }
table.grid td.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { text-align: center; color: var(--muted); padding: 1.5rem !important; }
.muted { color: var(--muted); }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .88em; }

/* ------------------------------------------------------------ Badges */
.badge {
  display: inline-block;
  padding: .1rem .55rem;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge.admin { background: var(--primary-light); color: var(--primary-hover); }
.badge.lecture, .badge.off { background: var(--st-neutre-bg); color: var(--st-neutre); }
.badge.on { background: var(--st-valide-bg); color: var(--st-valide); }
.badge.echue { background: var(--st-echue-bg); color: var(--st-echue); }
.badge.critique { background: var(--st-critique-bg); color: var(--st-critique); }
.badge.urgent { background: var(--st-urgent-bg); color: var(--st-urgent); }
.badge.a_surveiller { background: var(--st-surveiller-bg); color: var(--st-surveiller); }
.badge.valide { background: var(--st-valide-bg); color: var(--st-valide); }
.badge.retiree, .badge.sans_echeance { background: var(--st-neutre-bg); color: var(--st-neutre); }

/* ------------------------------------------------------------ Accueil : tuiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .9rem; margin-bottom: 1.25rem; }
.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--st-neutre);
  border-radius: var(--radius);
  padding: .9rem 1rem;
  box-shadow: var(--shadow);
}
.tile .n { font-size: 1.9rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.tile .l { font-size: .85rem; color: var(--muted); }
.tile.echue { border-left-color: var(--st-echue); }
.tile.critique { border-left-color: var(--st-critique); }
.tile.urgent { border-left-color: var(--st-urgent); }
.tile.a_surveiller { border-left-color: var(--st-surveiller); }
.tile.valide { border-left-color: var(--st-valide); }

/* ------------------------------------------------------------ Filtres */
.small { font-size: .85rem; }
.toolbar { display: flex; justify-content: space-between; gap: .75rem; flex-wrap: wrap; margin-bottom: .5rem; }
.toolbar-right { display: flex; gap: .5rem; flex-wrap: wrap; }
.toolbar-right input[type=text] { min-width: 260px; }
.toolbar-right select, .toolbar-right input[type=text] { width: auto; }
.toolbar-right { align-items: center; }
.page-head select { width: auto; }
.chips { display: flex; gap: .4rem; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  padding: .3rem .75rem;
  font: inherit;
  font-size: .85rem;
  cursor: pointer;
  color: var(--text);
}
.chip span { color: var(--muted); font-variant-numeric: tabular-nums; margin-left: .15rem; }
.chip:hover { background: #FAF8F6; }
.chip.active { background: var(--ink); border-color: var(--ink); color: #fff; }
.chip.active span { color: #D6D0CA; }

/* ------------------------------------------------------------ Agréments (saisie et fiche) */
.fil { font-size: .85rem; color: var(--muted); margin-bottom: .35rem; }
.layout-aside { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 1.25rem; align-items: start; }
.layout-aside aside { position: sticky; top: 1rem; display: flex; flex-direction: column; gap: 1rem; }
.layout-aside aside .card { margin-bottom: 0; }
@media (max-width: 1000px) { .layout-aside { grid-template-columns: 1fr; } .layout-aside aside { position: static; } }
.sec-titre { display: flex; align-items: center; gap: .6rem; }
.sec-num {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 26px; height: 26px; border-radius: 50%; background: var(--primary); color: #fff; font-size: .8rem; font-weight: 700;
}
.req { color: var(--primary-hover); }
.choix { display: flex; flex-wrap: wrap; gap: .45rem 1.2rem; }
.bloc-fiche {
  background: #FBF9F7; border: 1px solid var(--border); border-radius: 8px; padding: .9rem 1rem;
  display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .75rem; font-size: .9rem;
}
.bloc-fiche .k, .infos .k { font-size: .78rem; color: var(--muted); }
.bloc-fiche .v, .infos .v { font-weight: 600; }
.infos { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem 1.5rem; }
@media (max-width: 800px) { .infos { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.recherche { position: relative; }
.suggestions {
  position: absolute; z-index: 20; left: 0; right: 0; top: 100%; margin-top: 4px; max-height: 320px; overflow-y: auto;
  background: #fff; border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 10px 30px rgba(0,0,0,.12);
  list-style: none; padding: .25rem; margin-left: 0;
}
.suggestions li button {
  display: block; width: 100%; text-align: left; border: 0; background: none; padding: .5rem .65rem; border-radius: 6px;
  font: inherit; font-size: .9rem; cursor: pointer; color: var(--text);
}
.suggestions li button:hover, .suggestions li button:focus { background: var(--primary-light); outline: none; }
.suggestions .meta { font-size: .78rem; color: var(--muted); }
.dropzone {
  border: 2px dashed #D9D2CA; border-radius: 8px; padding: 1.25rem; background: #FBF9F7;
  display: flex; flex-direction: column; align-items: center; gap: .3rem; text-align: center; cursor: pointer;
}
.dropzone.survol { border-color: var(--primary); background: var(--primary-light); }
.doc-ligne {
  display: grid; grid-template-columns: 56px minmax(0, 1fr) 180px 80px auto; gap: .6rem; align-items: center;
  padding: .55rem 0; border-bottom: 1px solid #EFEAE5; font-size: .9rem;
}
.doc-ligne:last-child { border-bottom: 0; }
.doc-ligne input, .doc-ligne select { height: 34px; padding: 0 .5rem; }
@media (max-width: 800px) { .doc-ligne { grid-template-columns: 50px minmax(0, 1fr) auto; } .doc-ligne .opt { display: none; } }
.ext { display: inline-block; padding: .1rem .4rem; border-radius: 4px; font-size: .72rem; font-weight: 700; text-align: center; }
.ext.pdf { background: #FDECDF; color: #B94D08; }
.ext.img { background: #DCF5E4; color: #15803D; }
.ext.office { background: #E0EAFD; color: #1D4ED8; }
.ext.ancien { background: var(--st-neutre-bg); color: var(--st-neutre); }
.gros-chiffre { font-size: 1.9rem; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.lignes-kv { display: flex; flex-direction: column; gap: .45rem; font-size: .88rem; }
.lignes-kv div { display: flex; justify-content: space-between; gap: .75rem; }
.alerte-carte { background: var(--primary-light); border-color: #F6C9A6; color: #7C2D06; }
.alerte-carte ul { margin: 0; padding-left: 1.1rem; font-size: .88rem; line-height: 1.5; }
.actions-barre { display: flex; justify-content: flex-end; gap: .6rem; flex-wrap: wrap; }
.note-import { background: var(--st-surveiller-bg); color: #1E3A8A; border: 1px solid #BFD3FB; border-radius: 8px; padding: .7rem .9rem; font-size: .88rem; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend { padding: 0; }
input:disabled, select:disabled, textarea:disabled { background: #F3F0ED; color: var(--muted); }
tr.cliquable { cursor: pointer; }
.journal { display: flex; flex-direction: column; gap: .6rem; font-size: .86rem; }
.journal .k { font-size: .76rem; color: var(--muted); }

/* ------------------------------------------------------------ Boîte de dialogue */
dialog {
  border: 0;
  border-radius: 10px;
  padding: 0;
  width: min(640px, calc(100vw - 2rem));
  box-shadow: 0 20px 50px rgba(0,0,0,.25);
  color: var(--text);
}
dialog::backdrop { background: rgba(43, 42, 40, .45); }
dialog header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
dialog header h2 { margin: 0; }
dialog header button { background: none; border: 0; font-size: 1.4rem; cursor: pointer; color: var(--muted); }
dialog form { padding: 1.25rem; }
dialog .dialog-error {
  display: none;
  margin-bottom: .9rem;
  padding: .6rem .8rem;
  border-radius: 6px;
  background: var(--st-echue-bg);
  color: #7F1D1D;
  font-size: .9rem;
}
dialog .dialog-error.show { display: block; }

/* ------------------------------------------------------------ Connexion */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background:
    radial-gradient(circle at 20% 10%, rgba(226, 96, 12, .10), transparent 45%),
    var(--bg);
}
.login-card {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(43, 42, 40, .08);
  padding: 2rem;
}
.login-card .logo { display: flex; align-items: center; gap: .75rem; margin-bottom: 1.5rem; }
.login-card .logo svg { width: 48px; height: 48px; }
.login-card .logo strong { display: block; font-size: 1.35rem; letter-spacing: .1em; color: var(--ink); }
.login-card .logo span { font-size: .85rem; color: var(--muted); }
.login-card .field { margin-bottom: 1rem; }
.login-card .btn { width: 100%; justify-content: center; padding: .65rem; }

body:not(.is-admin) .admin-only { display: none !important; }

@media (max-width: 1500px) {
  .topbar { gap: 1rem; }
  .nav a { padding: .45rem .6rem; font-size: .9rem; }
  .userbox { gap: .5rem; }
  .userbox .who { display: none; }
}

@media (max-width: 720px) {
  main { padding: 1rem; }
  .topbar { padding: .5rem 1rem; gap: .5rem; }
  .userbox .who { display: none; }
  .userbox { margin-left: auto; }
  .nav { order: 3; flex: 1 0 100%; flex-wrap: nowrap; overflow-x: auto; padding-bottom: .25rem; }
  .nav a { white-space: nowrap; }
}
