:root {
  /* --orange = couleur d'accent principale (le nom est conserve pour compatibilite).
     Couleur par defaut : bleu. */
  --orange: #2e86de;
  --accent-soft: #eaf4fd;
  --accent-ink: #1b5d96;
  --ink: #1a1a1a;
  --muted: #6b7280;
  --line: #e5e7eb;
  --bg: #f6f7f9;
  --ok: #0a7d2c;
  --err: #c0392b;
}

/* Themes de couleur (selectionnables depuis Admin > Parametres). */
:root[data-theme="orange"] {
  --orange: #ff7900;
  --accent-soft: #fff7ed;
  --accent-ink: #9a3412;
}
:root[data-theme="bleu-nuit"] {
  --orange: #1e3a5f;
  --accent-soft: #eef2f7;
  --accent-ink: #1e3a5f;
}
:root[data-theme="bleu-clair"] {
  --orange: #2e86de;
  --accent-soft: #eaf4fd;
  --accent-ink: #1b5d96;
}
:root[data-theme="rouge"] {
  --orange: #d62828;
  --accent-soft: #fdeaea;
  --accent-ink: #8c1d1d;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
header {
  background: #fff;
  border-bottom: 3px solid var(--orange);
  padding: 16px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  position: sticky;
  top: 0;
  z-index: 100;
}
header h1 { margin: 0; font-size: 20px; }
.company { color: var(--muted); font-size: 12px; text-align: right; }
.tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 24px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 57px;
  z-index: 99;
}
.tabs-list {
  display: flex;
  gap: 0;
  flex: 1;
  flex-wrap: wrap; /* Option 1 : repli sur 2 lignes si manque de place */
  overflow-x: visible;
  align-items: stretch;
}
.tabs-list > button,
.tab-group-btn {
  background: none;
  border: none;
  padding: 12px 16px;
  font-size: 14px;
  cursor: pointer;
  color: var(--muted);
  border-bottom: 3px solid transparent;
  white-space: nowrap;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 4px;
}
.tabs-list > button.active,
.tab-group-btn.group-active {
  color: var(--ink);
  border-bottom-color: var(--orange);
  font-weight: 600;
}
.tabs-list > button:hover,
.tab-group-btn:hover { color: var(--ink); background: var(--accent-soft); }

/* ── Groupes de navigation ─────────────────────────────────────────────── */
.tab-group { position: relative; display: flex; }
.tab-arrow  { font-size: 10px; transition: transform .15s; display: inline-block; }
.tab-group.open .tab-arrow { transform: rotate(180deg); }
.tab-group-btn.group-active .tab-arrow { color: var(--orange); }

.tab-group-menu {
  /* Toujours rendu en flex — évite le bug Firefox display:none→flex.
     Pas de transition : Firefox rate les clics si pointer-events change
     pendant une transition CSS (opacity/visibility). */
  display: flex;
  flex-direction: column;
  position: absolute;
  top: calc(100% + 3px);
  left: 0;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0,0,0,.1);
  z-index: 300;
  min-width: 180px;
  padding: 4px 0;
  visibility: hidden;
  pointer-events: none;
}
.tab-group.open .tab-group-menu {
  visibility: visible;
  pointer-events: auto;
}

.tab-group-menu button {
  background: none;
  border: none;
  padding: 10px 16px;
  font-size: 14px;
  cursor: pointer;
  color: var(--muted);
  text-align: left;
  white-space: nowrap;
  border-left: 3px solid transparent;
}
.tab-group-menu button:hover { background: var(--accent-soft); color: var(--ink); }
.tab-group-menu button.active {
  color: var(--ink);
  border-left-color: var(--orange);
  background: var(--accent-soft);
  font-weight: 600;
}
/* Hamburger — caché sur desktop */
.hamburger { display: none; }
.tab-current-label { display: none; }
main { padding: 24px; max-width: 1000px; margin: 0 auto; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
h2 { font-size: 16px; margin: 24px 0 12px; }
h3 { font-size: 13px; margin: 16px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.card { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 16px; }
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 4px; }
input, select {
  font-size: 14px; padding: 8px; border: 1px solid var(--line);
  border-radius: 6px; color: var(--ink); background: #fff;
}
table.lines { width: 100%; border-collapse: collapse; margin-top: 8px; }
table.lines th { text-align: left; font-size: 11px; color: var(--muted); padding: 4px; }
table.lines td { padding: 2px 4px; }
table.lines input, table.lines select { width: 100%; }
button {
  background: var(--orange); color: #fff; border: none; border-radius: 6px;
  padding: 10px 16px; font-size: 14px; cursor: pointer; font-weight: 600;
}
button:hover { filter: brightness(.95); }
button.ghost { background: #fff; color: var(--orange); border: 1px solid var(--orange); margin-top: 8px; }
button.del { background: #fff; color: var(--err); border: 1px solid var(--line); padding: 6px 10px; font-weight: 400; }
.actions { margin-top: 16px; display: flex; gap: 8px; }
.balance { font-size: 13px; margin: 8px 0 0; }
.balance.ok { color: var(--ok); }
.balance.err { color: var(--err); }
.list { display: flex; flex-direction: column; gap: 8px; }
.item {
  background: #fff; border: 1px solid var(--line); border-radius: 8px;
  padding: 12px 16px; display: flex; justify-content: space-between; align-items: center; gap: 12px;
}
.item .meta { font-size: 12px; color: var(--muted); }
.item .amount { font-weight: 600; }
.item a { color: var(--orange); text-decoration: none; font-size: 13px; }
pre.fec {
  background: #1a1a1a; color: #e5e7eb; padding: 12px; border-radius: 8px;
  overflow-x: auto; font-size: 11px; line-height: 1.5; white-space: pre;
}
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 8px;
  font-size: 14px; opacity: 0; transition: opacity .2s; pointer-events: none; max-width: 90%;
}
.toast.show { opacity: 1; }
.toast.err { background: var(--err); }
.fec-meta { font-size: 13px; margin: 12px 0; color: var(--muted); }
.subtabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 8px; }
.subtabs button {
  background: none; border: none; padding: 10px 14px; font-size: 13px;
  cursor: pointer; color: var(--muted); border-bottom: 3px solid transparent; font-weight: 500;
}
.subtabs button.active { color: var(--ink); border-bottom-color: var(--orange); font-weight: 600; }
.subtab-panel { display: none; }
.subtab-panel.active { display: block; }
.item .row-actions { display: flex; gap: 6px; }
.item button.mini { padding: 6px 10px; font-size: 12px; font-weight: 500; }
button.mini { padding: 6px 10px; font-size: 12px; font-weight: 500; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 11px; font-weight: 600; }
.badge.ok { background: #dcfce7; color: var(--ok); }
.badge.err { background: #fee2e2; color: var(--err); }
.logo-box { display: flex; align-items: center; gap: 16px; min-height: 60px; }
#logo-preview { max-height: 80px; max-width: 240px; display: none; border: 1px solid var(--line); border-radius: 6px; padding: 4px; background: #fff; }
.file-label { display: inline-block; cursor: pointer; }
/* Fenetre modale (choix du compte de reglement) */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center; z-index: 1000;
}
.modal {
  background: #fff; border-radius: 8px; padding: 20px;
  width: min(440px, 92vw); box-shadow: 0 10px 30px rgba(0,0,0,.2);
}
.modal h3 { margin: 0 0 12px; }
.modal label { display: block; font-size: 14px; }
.modal select { width: 100%; margin-top: 6px; }

/* Ecran de connexion */
.login-screen {
  position: fixed; inset: 0; background: var(--bg);
  display: flex; align-items: center; justify-content: center; z-index: 2000; padding: 16px;
}
.login-card {
  background: #fff; border: 1px solid var(--line); border-top: 4px solid var(--orange);
  border-radius: 10px; padding: 28px; width: min(380px, 94vw);
  box-shadow: 0 10px 30px rgba(0,0,0,.08); display: flex; flex-direction: column; gap: 12px;
}
.login-card h1 { margin: 0; font-size: 22px; }
.login-card label { font-size: 13px; }
.login-card .actions { margin-top: 4px; }
.login-card button { width: 100%; }

/* En-tete : infos societe + utilisateur connecte */
.header-right { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; justify-content: flex-end; }
.user-box { display: flex; align-items: center; gap: 10px; }
.user-info { font-size: 12px; color: var(--ink); text-align: right; line-height: 1.3; }
.user-info .role { color: var(--muted); }

/* Masquage selon le role.
   - Les elements [data-admin-only] ne s'affichent que pour l'administrateur.
   - En consultation (lecture seule), tous les elements [data-write] sont caches. */
body:not(.role-admin) [data-admin-only] { display: none !important; }
body.role-consultation [data-write] { display: none !important; }
/* Bandeau d'information en lecture seule */
#readonly-banner {
  display: none; background: var(--accent-soft); border-bottom: 1px solid var(--orange);
  color: var(--accent-ink); padding: 8px 24px; font-size: 13px; text-align: center;
}
body.role-consultation #readonly-banner { display: block; }

/* Bascule Liste / Tableau */
.view-toggle { display: flex; gap: 0; margin-bottom: 12px; }
.view-toggle .seg {
  background: #fff; color: var(--muted); border: 1px solid var(--line);
  padding: 6px 14px; font-size: 13px; font-weight: 500; cursor: pointer;
}
.view-toggle .seg:first-child { border-radius: 6px 0 0 6px; }
.view-toggle .seg:last-child { border-radius: 0 6px 6px 0; border-left: none; }
.view-toggle .seg.active { background: var(--orange); color: #fff; border-color: var(--orange); }

/* Tableau de donnees triable */
table.data-table { width: 100%; border-collapse: collapse; background: #fff;
  border: 1px solid var(--line); border-radius: 8px; overflow: hidden; font-size: 13px; }
table.data-table th {
  text-align: left; padding: 10px 12px; background: #fafafa; color: var(--muted);
  font-size: 12px; text-transform: uppercase; letter-spacing: .03em; border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
table.data-table th.sortable { cursor: pointer; user-select: none; }
table.data-table th.sortable:hover { color: var(--ink); }
table.data-table th.sortable::after { content: " \2195"; opacity: .35; }
table.data-table th.sortable.asc::after { content: " \2191"; opacity: 1; color: var(--orange); }
table.data-table th.sortable.desc::after { content: " \2193"; opacity: 1; color: var(--orange); }
table.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data-table tbody tr:last-child td { border-bottom: none; }
table.data-table tbody tr:hover { background: #fcfcfc; }
table.data-table .amount { font-weight: 600; }

/* Bouton stylé comme un lien (login screen) */
.link-btn {
  background: none; border: none; color: var(--orange); font-size: 13px;
  cursor: pointer; padding: 0; font-weight: 500; text-decoration: underline;
  text-underline-offset: 2px;
}
.link-btn:hover { filter: brightness(.85); }

/* ── Hamburger (icône 3 traits) ───────────────────────────────────────────── */
.hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 10px 4px;
  min-height: 44px;
  min-width: 36px;
  flex-shrink: 0;
}
.hamburger span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--ink);
  border-radius: 2px;
  transition: transform .2s, opacity .2s;
}
.tabs.open .hamburger span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.tabs.open .hamburger span:nth-child(2) { opacity: 0; }
.tabs.open .hamburger span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ── Responsive ≤ 900px ───────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .hamburger { display: flex; }
  .tab-current-label {
    display: block;
    flex: 1;
    font-size: 15px;
    font-weight: 600;
    color: var(--ink);
    padding: 12px 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .tabs { flex-wrap: wrap; padding: 0 12px; }
  .tabs-list {
    display: none;
    flex: 0 0 100%;
    flex-direction: column;
    width: 100%;
    border-top: 1px solid var(--line);
    padding: 6px 0;
    gap: 0;
    overflow-x: visible;
  }
  .tabs.open .tabs-list { display: flex; }
  .tabs-list > button,
  .tab-group-btn {
    padding: 13px 16px;
    text-align: left;
    border-bottom: none;
    border-left: 3px solid transparent;
    font-size: 15px;
    white-space: normal;
    flex-shrink: unset;
    width: 100%;
    justify-content: space-between;
  }
  .tabs-list > button.active,
  .tab-group-btn.group-active {
    border-bottom: none;
    border-left-color: var(--orange);
    background: var(--accent-soft);
    color: var(--ink);
  }
  /* Groupes : accordéon sur mobile (in-flow → pas de bug Firefox display) */
  .tab-group { flex-direction: column; position: static; }
  .tab-group-menu {
    display: none;
    visibility: visible;
    pointer-events: auto;
    opacity: 1;
    position: static;
    box-shadow: none;
    border: none;
    border-radius: 0;
    border-left: 3px solid var(--line);
    padding: 0;
    margin-left: 16px;
    min-width: unset;
    transition: none;
  }
  .tab-group.open .tab-group-menu { display: flex; }
  .tab-group-menu button {
    font-size: 14px;
    padding: 11px 16px;
    border-left: none;
  }
  .tab-group-menu button.active {
    background: var(--accent-soft);
    color: var(--ink);
    font-weight: 600;
  }
  header { padding: 12px 16px; }
  header h1 { font-size: 16px; }
  .header-right { gap: 8px; }
  .company { display: none; }
  main { padding: 16px 12px; }
  .subtabs { flex-wrap: wrap; }
  .subtabs button { padding: 8px 10px; font-size: 12px; }
}

@media (max-width: 640px) {
  .grid { grid-template-columns: 1fr; }
  table.data-table { font-size: 12px; }
  table.data-table th, table.data-table td { padding: 8px 6px; }
  .ghost.mini { font-size: 12px; padding: 6px 10px; }
  .db-grid { grid-template-columns: 1fr 1fr; }
  .item { flex-direction: column; align-items: flex-start; }
  .item > div:last-child { align-items: flex-start !important; }
}

/* ── Tableau de bord ─────────────────────────────────────────────────────── */
.db-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.db-kpi {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.db-kpi .db-label { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.db-kpi .db-value { font-size: 26px; font-weight: 700; line-height: 1.1; }
.db-kpi .db-sub   { font-size: 12px; color: var(--muted); }
.db-kpi.positive .db-value { color: #1a7a3c; }
.db-kpi.negative .db-value { color: var(--err); }
.db-kpi.neutral  .db-value { color: var(--ink); }
.db-kpi.warning  .db-value { color: #b45309; }

.db-section { margin-bottom: 28px; }
.db-section h3 {
  font-size: 13px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); margin: 0 0 10px; padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
}
.db-bar-wrap { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.db-bar-label { font-size: 12px; width: 140px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.db-bar { flex: 1; height: 10px; background: var(--line); border-radius: 5px; overflow: hidden; }
.db-bar-fill { height: 100%; border-radius: 5px; transition: width .4s; }
.db-bar-amount { font-size: 12px; font-weight: 600; width: 90px; text-align: right; white-space: nowrap; }

.db-refresh { float: right; font-size: 12px; color: var(--muted); cursor: pointer; }
.db-refresh:hover { color: var(--ink); }

/* ── Notes de frais / Analytique / DAS2 ─────────────────────────────────── */

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 10px;
  font-size: 11px; font-weight: 600; text-transform: uppercase;
}
.badge-orange { background: #fff3cd; color: #b45309; }
.badge-blue   { background: #dbeafe; color: #1d4ed8; }
.badge-green  { background: #d1fae5; color: #065f46; }
.badge-gray   { background: #f1f5f9; color: #64748b; }

.data-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 8px; }
.data-table th { background: var(--accent-soft); color: var(--muted); font-size: 11px;
  text-transform: uppercase; letter-spacing: .04em; padding: 8px 10px; text-align: left; }
.data-table td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.data-table tbody tr:hover { background: var(--accent-soft); }
.data-table .right { text-align: right; }
.data-table .total-row td { font-weight: 600; background: var(--accent-soft); border-top: 2px solid var(--line); }
.data-table .danger { color: #dc2626; }

.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }

.actions-cell { white-space: nowrap; }
.small { padding: 4px 10px !important; font-size: 12px !important; }
.danger { border-color: #dc2626 !important; color: #dc2626 !important; }
.danger:hover { background: #fef2f2 !important; }
.danger-btn { background: #dc2626 !important; color: #fff !important; border-color: #dc2626 !important; }

/* Champ mot de passe avec œil */
.field-wrap { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.field-wrap label { font-weight: 500; }
.password-wrap { display: flex; }
.password-wrap input { flex: 1; border-radius: 6px 0 0 6px; margin: 0; }
.btn-eye { flex: 0 0 36px; width: 36px !important; background: #f8f9fa; border: 1px solid var(--line); border-left: none; border-radius: 0 6px 6px 0; cursor: pointer; color: #94a3b8; display: flex; align-items: center; justify-content: center; padding: 0; font-size: 14px; }
.btn-eye:hover { background: #f0f1f3; color: var(--orange); }
.danger-btn:hover { background: #b91c1c !important; }

/* Bandeau cookie RGPD */
.cookie-banner {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 1000;
  background: #1e293b; color: #f1f5f9;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 14px 20px; font-size: 13px; line-height: 1.5;
  box-shadow: 0 -4px 20px rgba(0,0,0,.2);
}
.cookie-banner code { background: rgba(255,255,255,.15); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.cookie-banner-text { flex: 1; min-width: 200px; }
.cookie-accept {
  background: var(--orange); color: #fff; border: none;
  padding: 8px 20px; border-radius: 8px; font-size: 13px; font-weight: 600;
  cursor: pointer; white-space: nowrap; flex-shrink: 0;
}
.cookie-accept:hover { opacity: .9; }

/* Panels RGPD internes */
/* ── Saisie assistée ─────────────────────────────────────────────── */
.sa-nav-btn {
  background: var(--orange) !important;
  color: #fff !important;
  border-radius: 6px;
  font-weight: 600;
  padding: 8px 14px !important;
  margin: 4px 8px 4px 4px;
  border-bottom: none !important;
  transition: opacity .15s;
}
.sa-nav-btn:hover { opacity: .85; }
.sa-nav-btn.active { opacity: .85; }

.sa-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.sa-tile {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  padding: 16px;
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  text-align: left;
  transition: border-color .15s, box-shadow .15s;
  font-size: 13px;
  color: var(--ink);
}
.sa-tile:hover { border-color: var(--orange); box-shadow: 0 2px 8px rgba(0,0,0,.08); }
.sa-tile.active { border-color: var(--orange); background: var(--accent-soft); }
.sa-tile strong { font-size: 14px; }
.sa-tile span:last-child { color: var(--muted); font-size: 12px; }

.sa-icon {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 700;
}
.sa-icon-green  { background: #dcfce7; color: #166534; }
.sa-icon-red    { background: #fee2e2; color: #991b1b; }
.sa-icon-purple { background: #f3e8ff; color: #6b21a8; }
.sa-icon-orange { background: #ffedd5; color: #9a3412; }
.sa-icon-blue   { background: #dbeafe; color: #1e40af; }
.sa-icon-teal   { background: #ccfbf1; color: #0f766e; }
.sa-icon-gray   { background: #f3f4f6; color: #374151; }

.sa-form-panel {
  background: #fff;
  border: 2px solid var(--orange);
  border-radius: 10px;
  padding: 24px;
  margin-bottom: 24px;
}
.sa-form-panel h3 {
  margin: 0 0 16px;
  font-size: 16px;
  color: var(--accent-ink);
}
.sa-form-panel .grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.sa-form-panel label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 500; }
.sa-form-panel input,
.sa-form-panel select,
.sa-form-panel textarea {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px;
  font-size: 13px; width: 100%;
}
.sa-form-panel .sa-hint {
  grid-column: 1 / -1;
  background: var(--accent-soft);
  border-left: 3px solid var(--orange);
  padding: 8px 12px;
  font-size: 12px;
  color: var(--accent-ink);
  border-radius: 0 4px 4px 0;
}
.sa-form-panel .actions { margin-top: 16px; display: flex; gap: 8px; }

@media (max-width: 600px) {
  .sa-form-panel .grid { grid-template-columns: 1fr; }
  .sa-grid { grid-template-columns: 1fr 1fr; }
}

.rgpd-panel { }
.rgpd-alert-item {
  display: flex; align-items: flex-start; gap: 12px;
  background: #fff7ed; border: 1px solid #fed7aa; border-radius: 8px;
  padding: 10px 14px; margin-bottom: 8px; font-size: 13px;
}
.rgpd-alert-item .alert-icon { font-size: 16px; flex-shrink: 0; }
.rgpd-alert-item .alert-body { flex: 1; }
.rgpd-alert-item .alert-action { flex-shrink: 0; }
