/* Compta APE Paul de Salvandy — palette et typographie du site de l'APE */
@font-face { font-family: 'DM Sans'; src: url('/fonts/dm-sans-latin.woff2') format('woff2'); font-weight: 100 1000; font-display: swap; }
@font-face { font-family: 'Fredoka'; src: url('/fonts/fredoka-latin.woff2') format('woff2'); font-weight: 300 700; font-display: swap; }

:root {
  --sauge: #7A9E6D; --vert: #5B7B50; --vert-fonce: #3A5234; --creme: #FDF8F2; --creme-2: #F6EFE6;
  --miel: #F2D06B; --miel-pale: #FBF0C9; --corail: #E58A7A; --corail-fonce: #B04A3A; --corail-pale: #FBE3DD;
  --bleu: #8FB6C8; --bleu-pale: #E3EFF4; --sauge-pale: #E7F0E2;
  --texte: #24301F; --texte-2: #5B6B52; --bord: #E6DFD3; --blanc: #FFFFFF;
  --rayon: 14px; --ombre: 0 1px 2px rgba(36, 48, 31, .06), 0 4px 16px rgba(36, 48, 31, .06);
  --display: 'Fredoka', system-ui, sans-serif; --sans: 'DM Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 15px/1.45 var(--sans); color: var(--texte); background: var(--creme); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--vert); }
h1, h2, h3 { font-family: var(--display); font-weight: 600; letter-spacing: .005em; margin: 0; }
h1 { font-size: 24px; } h2 { font-size: 19px; } h3 { font-size: 16px; }
.muted { color: var(--texte-2); } .small { font-size: 13px; } .nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.credit { color: var(--vert); } .debit { color: var(--texte); }
.hidden { display: none !important; }
[hidden] { display: none !important; }

/* Boutons et champs */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--bord); background: var(--blanc);
  border-radius: 999px; padding: 8px 16px; cursor: pointer; font-weight: 600; font-size: 14px; text-decoration: none; color: var(--texte); min-height: 38px; }
.btn:hover { border-color: var(--sauge); }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .chip:focus-visible, .op:focus-visible { outline: 3px solid rgba(122, 158, 109, .45); outline-offset: 1px; }
.btn.primary { background: var(--vert); border-color: var(--vert); color: var(--blanc); }
.btn.primary:hover { background: var(--vert-fonce); }
.btn.danger { color: var(--corail-fonce); border-color: var(--corail-pale); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { padding: 5px 12px; min-height: 30px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn svg { width: 17px; height: 17px; flex: none; }
input[type=text], input[type=password], input[type=search], input[type=date], input[type=number], select, textarea {
  width: 100%; border: 1px solid var(--bord); border-radius: 10px; background: var(--blanc); padding: 8px 11px; min-height: 38px; }
textarea { min-height: 70px; resize: vertical; }
label.field { display: grid; gap: 4px; font-size: 13px; font-weight: 600; color: var(--texte-2); }
label.check { display: flex; gap: 8px; align-items: center; cursor: pointer; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; } .row.between { justify-content: space-between; }
.stack { display: grid; gap: 12px; } .stack.lg { gap: 20px; }

/* Structure */
.topbar { position: sticky; top: 0; z-index: 20; background: rgba(253, 248, 242, .94); backdrop-filter: blur(8px); border-bottom: 1px solid var(--bord); }
.topbar-inner { max-width: 1280px; margin: 0 auto; display: flex; align-items: center; gap: 14px; padding: 10px 18px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--texte); }
.brand img { width: 34px; height: 34px; border-radius: 50%; }
.brand b { font-family: var(--display); font-weight: 600; font-size: 18px; white-space: nowrap; }
.brand span { display: block; font-size: 12px; color: var(--texte-2); line-height: 1.1; }
.topbar .exercice { width: auto; min-width: 150px; font-weight: 600; }
.nav { display: flex; gap: 4px; margin-left: 12px; }
.nav a { padding: 7px 13px; border-radius: 999px; text-decoration: none; color: var(--texte-2); font-weight: 600; font-size: 14px; display: inline-flex; gap: 6px; align-items: center; }
.nav a:hover { background: var(--creme-2); color: var(--texte); }
.nav a.active { background: var(--sauge-pale); color: var(--vert-fonce); }
.nav .badge { background: var(--corail); color: var(--blanc); border-radius: 999px; font-size: 11px; padding: 0 6px; min-width: 18px; text-align: center; line-height: 18px; }
.spacer { flex: 1; }
main { max-width: 1280px; margin: 0 auto; padding: 22px 18px 90px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head p { margin: 4px 0 0; }

.card { background: var(--blanc); border: 1px solid var(--bord); border-radius: var(--rayon); box-shadow: var(--ombre); padding: 18px; }
.card.flat { box-shadow: none; }
.grid { display: grid; gap: 14px; }
.grid.kpi { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); align-items: start; }
.kpi .label { font-size: 13px; color: var(--texte-2); font-weight: 600; }
.kpi .value { font-family: var(--display); font-size: 27px; font-weight: 600; margin-top: 2px; }
.kpi .hint { font-size: 13px; color: var(--texte-2); margin-top: 4px; }
.action-card { display: flex; align-items: center; gap: 14px; text-decoration: none; color: var(--texte); cursor: pointer; }
.action-card:hover { border-color: var(--sauge); }
.action-card .big { font-family: var(--display); font-size: 30px; font-weight: 600; min-width: 46px; text-align: center; }
.action-card.warn .big { color: var(--corail-fonce); } .action-card.ok .big { color: var(--vert); }

.pill { display: inline-flex; align-items: center; gap: 4px; border-radius: 999px; padding: 1px 9px; font-size: 12px; font-weight: 600; line-height: 20px; white-space: nowrap; }
.pill.a_justifier { background: var(--corail-pale); color: var(--corail-fonce); }
.pill.justifie { background: var(--sauge-pale); color: var(--vert-fonce); }
.pill.dispense { background: var(--bleu-pale); color: #2F5D72; }
.pill.cat { background: var(--creme-2); color: var(--texte-2); font-weight: 500; }
.pill.cat.none { background: var(--miel-pale); color: #7A5C00; }
.pill.event { background: var(--bleu-pale); color: #2F5D72; font-weight: 500; }
.pill.auto { background: var(--miel-pale); color: #7A5C00; font-weight: 500; }
.pill.ok { background: var(--sauge-pale); color: var(--vert-fonce); }
.pill.ko { background: var(--corail-pale); color: var(--corail-fonce); }

/* Opérations */
.ops-layout { display: grid; grid-template-columns: minmax(0, 1fr) 430px; gap: 16px; align-items: start; }
.ops-layout.no-detail { grid-template-columns: minmax(0, 1fr); }
.filters { display: grid; gap: 10px; margin-bottom: 12px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--bord); background: var(--blanc); border-radius: 999px; padding: 6px 13px; cursor: pointer; font-weight: 600; font-size: 13px; color: var(--texte-2); }
.chip b { color: var(--texte); margin-left: 3px; }
.chip.active { background: var(--vert); border-color: var(--vert); color: var(--blanc); }
.chip.active b { color: var(--blanc); }
.filters .selects { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.filters .more summary { display: none; }
.filters .more summary::-webkit-details-marker { display: none; }
.ops-layout:not(.no-detail) .filters .selects { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.ex-label { font-size: 13px; color: var(--texte-2); font-weight: 600; }
.op-list { background: var(--blanc); border: 1px solid var(--bord); border-radius: var(--rayon); overflow: hidden; box-shadow: var(--ombre); }
.op { display: grid; grid-template-columns: 54px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 11px 14px; border-bottom: 1px solid var(--bord); cursor: pointer; background: var(--blanc); width: 100%; text-align: left; border-left: 0; border-right: 0; border-top: 0; }
.op:last-child { border-bottom: 0; }
.op:hover { background: #FFFCF7; }
.op.selected { background: var(--sauge-pale); }
.op .d { font-size: 13px; color: var(--texte-2); font-weight: 600; line-height: 1.2; }
.op .d small { display: block; font-weight: 500; font-size: 11px; }
.op .l { min-width: 0; }
.op .l .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; word-break: break-word; }
.op .l .m { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 4px; }
.op .r { text-align: right; display: grid; gap: 4px; justify-items: end; }
.op .r .a { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.empty { padding: 40px 20px; text-align: center; color: var(--texte-2); }

.detail { position: sticky; top: 76px; max-height: calc(100vh - 92px); overflow: auto; align-content: start; }
.detail .amount { font-family: var(--display); font-size: 30px; font-weight: 600; }
.detail .label-full { font-weight: 600; word-break: break-word; }
.detail-close { display: none; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--texte-2); font-weight: 700; margin: 0 0 6px; }
.justif-box { border-radius: 12px; padding: 12px; display: grid; gap: 10px; }
.justif-box.a_justifier { background: var(--corail-pale); }
.justif-box.justifie { background: var(--sauge-pale); }
.justif-box.dispense { background: var(--bleu-pale); }
.pieces { display: grid; gap: 8px; }
.piece { display: grid; grid-template-columns: 52px minmax(0, 1fr) auto; gap: 10px; align-items: center; background: var(--blanc); border: 1px solid var(--bord); border-radius: 10px; padding: 6px; }
.thumb { width: 52px; height: 52px; border-radius: 8px; object-fit: cover; background: var(--creme-2); display: grid; place-items: center; font-size: 11px; font-weight: 700; color: var(--texte-2); overflow: hidden; }
.thumb { text-decoration: none; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.piece .n { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.detail-nav { display: flex; justify-content: space-between; gap: 8px; border-top: 1px solid var(--bord); padding-top: 12px; }

/* Dépôt de fichiers */
.drop { border: 2px dashed var(--sauge); border-radius: var(--rayon); background: var(--blanc); padding: 30px 20px; text-align: center; cursor: pointer; transition: background .15s; }
.drop:hover, .drop.over { background: var(--sauge-pale); }
.drop b { font-family: var(--display); font-size: 18px; font-weight: 600; display: block; margin-bottom: 4px; }
.drop.busy { opacity: .6; pointer-events: none; }

/* Tableaux */
table.t { width: 100%; border-collapse: collapse; }
table.t th, table.t td { padding: 8px 10px; border-bottom: 1px solid var(--bord); text-align: left; vertical-align: middle; }
table.t th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--texte-2); font-weight: 700; background: var(--creme); }
table.t td.num, table.t th.num { width: 1%; padding-left: 18px; }
table.t tfoot td { font-weight: 700; border-top: 2px solid var(--texte); border-bottom: 0; }
table.t tr.dup td { color: var(--texte-2); background: #FBF8F3; }
.table-wrap { overflow-x: auto; border: 1px solid var(--bord); border-radius: var(--rayon); background: var(--blanc); }
.table-wrap table.t th:first-child, .table-wrap table.t td:first-child { padding-left: 14px; }

.notice { border-radius: 12px; padding: 10px 14px; background: var(--miel-pale); color: #5E4700; font-size: 14px; }
.notice.ok { background: var(--sauge-pale); color: var(--vert-fonce); }
.notice.ko { background: var(--corail-pale); color: var(--corail-fonce); }

/* Connexion */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login .card { width: min(380px, 100%); display: grid; gap: 14px; text-align: center; padding: 28px; }
.login img { width: 84px; height: 84px; margin: 0 auto; border-radius: 50%; }

/* Messages et boîte de dialogue */
#toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 100; width: min(460px, calc(100% - 24px)); }
.toast { background: var(--texte); color: var(--blanc); border-radius: 12px; padding: 11px 16px; box-shadow: var(--ombre); font-size: 14px; animation: up .2s ease-out; }
.toast.error { background: var(--corail-fonce); }
@keyframes up { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
dialog { border: 0; border-radius: 18px; padding: 0; width: min(520px, calc(100% - 24px)); box-shadow: 0 10px 40px rgba(0, 0, 0, .2); color: var(--texte); }
dialog::backdrop { background: rgba(36, 48, 31, .35); }
dialog .body { padding: 22px; display: grid; gap: 14px; }
dialog .foot { padding: 14px 22px; background: var(--creme); display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.picker { max-height: 320px; overflow: auto; border: 1px solid var(--bord); border-radius: 10px; }
.picker button { display: grid; grid-template-columns: 50px 1fr auto; gap: 8px; width: 100%; padding: 8px 10px; border: 0; border-bottom: 1px solid var(--bord); background: var(--blanc); text-align: left; cursor: pointer; font-size: 13px; }
.picker button:hover { background: var(--sauge-pale); }

.bottom-nav { display: none; }
.mobile-only { display: none !important; }

@media (max-width: 1080px) {
  .ops-layout { grid-template-columns: minmax(0, 1fr); }
  .detail { position: fixed; inset: 0; z-index: 40; max-height: none; border-radius: 0; border: 0; padding-bottom: 90px; }
  .detail-close { display: inline-flex; }
  .filters .selects { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  body { font-size: 15px; }
  .nav { display: none; }
  .mobile-only { display: inline-flex !important; }
  .topbar-inner { padding: 8px 12px; gap: 8px; }
  .brand span { display: none; }
  .brand b { font-size: 16px; }
  .topbar .exercice { min-width: 0; max-width: 130px; }
  main { padding: 14px 12px 96px; }
  h1 { font-size: 21px; }
  .card { padding: 14px; }
  .op { grid-template-columns: 44px minmax(0, 1fr) auto; gap: 9px; padding: 10px 11px; }
  .bottom-nav { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
    background: var(--blanc); border-top: 1px solid var(--bord); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
  .bottom-nav a { display: grid; justify-items: center; gap: 2px; text-decoration: none; color: var(--texte-2); font-size: 11px; font-weight: 600; padding: 4px 0; position: relative; }
  .bottom-nav a svg { width: 22px; height: 22px; }
  .bottom-nav a.active { color: var(--vert-fonce); }
  .bottom-nav .badge { position: absolute; top: 0; left: calc(50% + 6px); background: var(--corail); color: var(--blanc); border-radius: 999px; font-size: 10px; padding: 0 5px; line-height: 16px; }
  .grid.two { grid-template-columns: minmax(0, 1fr); }
  .hide-mobile { display: none !important; }
  .home .todo { order: -1; } .home .page-head { order: -2; }
  .chips { flex-wrap: nowrap; overflow-x: auto; margin: 0 -12px; padding: 0 12px 2px; scrollbar-width: none; }
  .chip { flex: none; }
  .filters .more summary { display: inline-flex; cursor: pointer; font-weight: 600; font-size: 13px; color: var(--vert); padding: 2px 0; }
  .filters .more[open] summary { margin-bottom: 8px; }
  .page-head .row .btn { padding: 7px 13px; font-size: 13px; min-height: 34px; }
}
@media print {
  .topbar, .bottom-nav, .no-print, #toasts { display: none !important; }
  body { background: var(--blanc); } main { padding: 0; max-width: none; }
  .card { box-shadow: none; break-inside: avoid; }
}
