:root {
  --bg: #f4f6f5; --panel: #ffffff; --text: #1d2a25; --muted: #66756f; --border: #dde4e1;
  --primary: #137a5b; --primary-2: #0f6149; --primary-soft: #e3f2ec; --accent: #c98a1b;
  --danger: #c0392b; --danger-soft: #fbeaea; --warn-soft: #fff4dc; --info-soft: #e8f0fb;
  --radius: 10px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  --font: 'Cairo', 'Segoe UI', Tahoma, system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font-family: var(--font); font-size: 14px; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); }

/* ---- Layout ---- */
.layout { display: flex; min-height: 100vh; }
.sidebar { width: 236px; background: #10382c; color: #d8ebe4; flex-shrink: 0; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { padding: 18px 16px; font-weight: 700; font-size: 15px; line-height: 1.4; color: #fff; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand small { display: block; font-weight: 400; color: #9cc5b6; font-size: 12px; }
.branch-box { padding: 10px 14px; border-bottom: 1px solid rgba(255,255,255,.08); }
.branch-box label { display: block; font-size: 11px; color: #9cc5b6; margin-bottom: 4px; }
.branch-box select { width: 100%; background: #174a3a; color: #fff; border-color: #2b6652; font-weight: 600; }
.phone-url { display: flex; gap: 16px; align-items: center; margin: 12px 0; flex-wrap: wrap; }
.phone-url .qr { width: 150px; height: 150px; background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 4px; }
.phone-url .qr svg { width: 100%; height: 100%; }
.big-url { font-size: 20px; font-weight: 700; color: var(--primary-2); word-break: break-all; }
.scope-form h4 { font-size: 13px; margin: 14px 0 4px; }
.perm-table td, .perm-table th { padding: 6px 10px; }
.perm-table .perm-group td { background: #f0f6f3; font-weight: 700; color: var(--primary-2); }
.perm-table input[type=checkbox] { width: 17px; height: 17px; }
.nav { padding: 8px; flex: 1; overflow: auto; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; color: #d8ebe4; text-decoration: none; border-radius: 8px; margin-bottom: 2px; }
.nav a:hover { background: rgba(255,255,255,.07); }
.nav a.active { background: var(--primary); color: #fff; }
.nav svg { width: 18px; height: 18px; flex-shrink: 0; }
.side-foot { padding: 12px; border-top: 1px solid rgba(255,255,255,.08); display: flex; gap: 8px; flex-wrap: wrap; align-items: center; font-size: 12px; }
.side-foot button { background: rgba(255,255,255,.1); border: 0; color: #fff; padding: 5px 10px; border-radius: 6px; cursor: pointer; }
.main { flex: 1; min-width: 0; padding: 22px 26px 60px; }
.topbar { display: none; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { font-size: 22px; margin: 0; }

/* ---- Composants ---- */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; }
.card h2 { font-size: 15px; margin: 0 0 12px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar .grow { flex: 1; }
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: #fff; padding: 7px 13px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #b8c6c0; background: #fafcfb; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-2); }
.btn.danger { color: var(--danger); }
.btn.danger.solid { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.sm { padding: 3px 8px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn svg { width: 16px; height: 16px; }
input[type=text], input[type=search], input[type=number], input[type=date], input[type=password], select, textarea {
  border: 1px solid var(--border); background: #fff; border-radius: 8px; padding: 7px 10px; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
textarea { width: 100%; min-height: 70px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12px; color: var(--muted); font-weight: 600; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 20px; font-size: 12px; background: var(--primary-soft); color: var(--primary-2); white-space: nowrap; }
.badge.left { background: var(--danger-soft); color: var(--danger); }
.badge.suspended { background: var(--warn-soft); color: #8a5a00; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: #f0f4f2; border: 1px solid var(--border); border-radius: 20px; padding: 3px 4px 3px 10px; margin: 3px; font-size: 13px; }
[dir=rtl] .chip { padding: 3px 10px 3px 4px; }
.chip button { border: 0; background: transparent; cursor: pointer; color: var(--muted); padding: 0 4px; font-size: 13px; }
.chip button:hover { color: var(--text); }
.chip .sub { color: var(--muted); font-size: 11px; }

/* ---- Tables ---- */
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; max-height: calc(100vh - 230px); }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 7px 10px; border-bottom: 1px solid #edf1ef; text-align: start; vertical-align: middle; }
th { background: #f7faf9; font-size: 12px; color: var(--muted); font-weight: 700; position: sticky; top: 0; z-index: 1; white-space: nowrap; }
tbody tr:hover { background: #fafdfc; }
.table-wrap td { white-space: nowrap; }
td.num, th.num { text-align: end; font-variant-numeric: tabular-nums; }
td.actions { white-space: nowrap; text-align: end; }
tfoot td { font-weight: 700; background: #f7faf9; position: sticky; bottom: 0; }
.row-left td { color: #9aa6a1; }
.empty { padding: 30px; text-align: center; color: var(--muted); }

/* ---- Grille cotisations ---- */
.grid td.cell { text-align: center; cursor: pointer; min-width: 54px; padding: 4px; user-select: none; }
.grid td.cell:hover { outline: 2px solid var(--primary); outline-offset: -2px; }
.grid td.cell.paid { background: #e3f4ec; color: #0f6149; font-weight: 600; }
.grid td.cell.partial { background: var(--warn-soft); color: #8a5a00; font-weight: 600; }
.grid td.cell.absent { background: var(--danger-soft); color: var(--danger); }
.grid td.cell.other { background: var(--info-soft); color: #2c5aa0; font-size: 11px; }
.grid th.mcol { text-align: center; }
.grid td.name { white-space: nowrap; position: sticky; inset-inline-start: 0; background: #fff; z-index: 0; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.legend span::before { content: ''; display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-inline-end: 5px; vertical-align: -2px; background: var(--c); }

/* ---- Dashboard ---- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .l { color: var(--muted); font-size: 12px; font-weight: 600; }
.kpi .v { font-size: 24px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .v.pos { color: var(--primary); } .kpi .v.neg { color: var(--danger); }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.cols .card { margin-bottom: 0; }
.bars .bar-row { display: grid; grid-template-columns: minmax(90px, 140px) 1fr auto; gap: 8px; align-items: center; margin: 6px 0; font-size: 13px; }
.bars .track { background: #eef3f1; height: 10px; border-radius: 5px; overflow: hidden; }
.bars .fill { height: 100%; background: var(--primary); border-radius: 5px; }
.bars .fill.exp { background: var(--accent); }
.chart svg { width: 100%; height: auto; display: block; }
.chart text { font-family: var(--font); font-size: 11px; fill: var(--muted); }

/* ---- Modal ---- */
.modal-back { position: fixed; inset: 0; background: rgba(16, 30, 25, .45); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 50; overflow: auto; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 760px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.modal.sm { max-width: 420px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 18px; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.x { border: 0; background: transparent; font-size: 22px; cursor: pointer; color: var(--muted); line-height: 1; }

#toast { position: fixed; bottom: 20px; inset-inline-start: 50%; transform: translateX(-50%); z-index: 100; }
[dir=rtl] #toast { transform: translateX(50%); }
#toast div { background: #1d2a25; color: #fff; padding: 10px 18px; border-radius: 8px; margin-top: 8px; box-shadow: 0 4px 14px rgba(0,0,0,.25); }
#toast div.err { background: var(--danger); }

/* ---- Login ---- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; background: linear-gradient(160deg, #10382c, #137a5b); }
.login { background: #fff; border-radius: 14px; padding: 28px; width: 100%; max-width: 380px; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.login h1 { font-size: 20px; margin: 0 0 4px; }
.login .field { margin-top: 12px; }
.login input { width: 100%; }

/* ---- Import ---- */
.dropzone { border: 2px dashed #b9cbc3; border-radius: var(--radius); padding: 26px; text-align: center; background: #fafdfc; }
.dropzone.over { background: var(--primary-soft); border-color: var(--primary); }
.map-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.map-grid .field select { width: 100%; }
.preview td, .preview th { font-size: 12px; padding: 4px 8px; white-space: nowrap; }
.result { background: var(--primary-soft); border-radius: var(--radius); padding: 14px 16px; }
.result li { margin: 3px 0; }
.steps .card { border-inline-start: 4px solid var(--primary); }
.radio-list label { display: flex; gap: 8px; align-items: center; padding: 6px 0; cursor: pointer; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; flex-wrap: wrap; }
.tabs button { border: 0; background: transparent; padding: 8px 14px; cursor: pointer; border-bottom: 2px solid transparent; color: var(--muted); font-weight: 600; }
.tabs button.active { color: var(--primary); border-color: var(--primary); }

.detail-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px 16px; margin-bottom: 14px; }
.detail-grid div b { display: block; font-size: 11px; color: var(--muted); }

/* ---- Responsive ---- */
@media (max-width: 860px) {
  .layout { display: block; }
  .sidebar { position: fixed; inset-block: 0; inset-inline-start: 0; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  [dir=rtl] .sidebar { transform: translateX(100%); }
  .sidebar.open { transform: none !important; }
  .topbar { display: flex; align-items: center; gap: 10px; background: #10382c; color: #fff; padding: 10px 16px; position: sticky; top: 0; z-index: 30; }
  .topbar button { background: transparent; border: 0; color: #fff; font-size: 22px; cursor: pointer; }
  .main { padding: 16px; }
  .table-wrap { max-height: none; }
}

@media print {
  .sidebar, .topbar, .toolbar, .page-head .btn, td.actions, th.actions, .no-print { display: none !important; }
  .main { padding: 0; }
  .table-wrap { max-height: none; overflow: visible; border: 0; }
  body { background: #fff; }
  .card { box-shadow: none; border: 0; padding: 0; }
}

/* ---- Mes classes (saisie des notes) ---- */
.class-com { font-size: 14px; color: var(--muted); margin: 18px 0 8px; }
.class-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.class-card { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; text-align: start; padding: 18px 16px; border-radius: 12px; border: 1px solid var(--border); background: #fff; box-shadow: var(--shadow); cursor: pointer; border-inline-start: 5px solid var(--primary); }
.class-card:hover { background: var(--primary-soft); }
.cc-name { font-size: 17px; font-weight: 700; }
.cc-count { color: var(--muted); font-size: 13px; }
.entry-stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin-bottom: 12px; }
.entry-stats .es { background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; text-align: center; }
.entry-stats .es b { display: block; font-size: 18px; }
.entry-stats .es span { font-size: 11px; color: var(--muted); }
.entry-stats .progress { grid-column: 1 / -1; height: 6px; background: #e6eeea; border-radius: 3px; overflow: hidden; }
.entry-stats .progress div { height: 100%; background: var(--primary); transition: width .2s; }
.entry-list { background: #fff; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; margin-bottom: 80px; }
.entry-row { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid #edf1ef; }
.entry-row.done { background: #f3faf6; }
.er-num { width: 26px; color: var(--muted); font-size: 12px; text-align: center; }
.er-name { flex: 1; font-size: 15px; }
.er-input { width: 84px; font-size: 20px; text-align: center; padding: 8px 6px; border: 2px solid var(--border); border-radius: 10px; font-variant-numeric: tabular-nums; }
.er-input:focus { border-color: var(--primary); outline: none; background: #fbfffd; }
.er-input.bad { border-color: var(--danger); background: var(--danger-soft); }
.er-abs { width: 42px; height: 42px; border-radius: 10px; border: 1px solid var(--border); background: #fff; font-size: 17px; cursor: pointer; color: var(--danger); }
.er-abs:hover { background: var(--danger-soft); }
.entry-bar { position: sticky; bottom: 0; display: flex; align-items: center; justify-content: flex-end; gap: 12px; padding: 12px 0; background: linear-gradient(transparent, var(--bg) 30%); }
.btn.big { padding: 12px 26px; font-size: 16px; border-radius: 10px; }
@media (max-width: 600px) {
  .entry-stats { grid-template-columns: repeat(3, 1fr); }
  .entry-stats .es:nth-child(4), .entry-stats .es:nth-child(5) { display: none; }
  .er-input { width: 72px; font-size: 22px; }
  .entry-bar .btn.big { flex: 1; justify-content: center; }
  .class-cards { grid-template-columns: 1fr 1fr; }
}
