:root {
  --tsg-blue: #0b3d91;
  --tsg-blue-dark: #072a66;
  --tsg-accent: #e8a33d;
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1c2530;
  --text-muted: #667085;
  --border: #dfe3e8;
  --danger: #c0392b;
  --success: #1e824c;
  --warning: #b8860b;
  --radius: 10px;

  --heading: var(--tsg-blue-dark);
  --surface-soft: #eef1f5;
  --surface-soft-hover: #e2e6eb;
  --surface-hover: #fafbfc;

  --status-gray-bg: #e5e9f0;   --status-gray-fg: #45526b;
  --status-blue-bg: #dbe9fb;   --status-blue-fg: #0b3d91;
  --status-amber-bg: #fdf0d5;  --status-amber-fg: #b8860b;
  --status-purple-bg: #e2d9f3; --status-purple-fg: #5b2d90;
  --status-green-bg: #d7f3e3;  --status-green-fg: #1e824c;
  --status-red-bg: #fadbd8;    --status-red-fg: #c0392b;
}

/* --- Mode sombre : basculé via la classe .theme-dark sur <html> (bouton dans la barre
   de navigation, js/theme.js), persisté en localStorage. Chaque jeton est redéfini
   explicitement ici plutôt que d'espérer qu'il "passe" tout seul. --- */
html.theme-dark {
  --bg: #12151a;
  --card: #1b1f27;
  --text: #e8eaed;
  --text-muted: #9aa3b2;
  --border: #2c313c;
  --danger: #f28b82;
  --success: #4fd18b;

  --heading: #8fb8ff;
  --surface-soft: #262b34;
  --surface-soft-hover: #303643;
  --surface-hover: #20242c;

  --status-gray-bg: #2a2e38;   --status-gray-fg: #aab2c5;
  --status-blue-bg: #1f3a5c;   --status-blue-fg: #8ab4f8;
  --status-amber-bg: #4a3a14;  --status-amber-fg: #e0b25c;
  --status-purple-bg: #3a2a52; --status-purple-fg: #c3a6e8;
  --status-green-bg: #1f3d2c;  --status-green-fg: #6fcf97;
  --status-red-bg: #4a2320;    --status-red-fg: #f0968a;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { color-scheme: light; }
html.theme-dark { color-scheme: dark; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: 70px;
  transition: background-color .15s, color .15s;
}

a { color: var(--tsg-blue); text-decoration: none; }
html.theme-dark a { color: var(--status-blue-fg); }

.topbar {
  background: var(--tsg-blue);
  color: white;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar .brand { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.topbar .brand .sub { font-size: 11px; opacity: .8; font-weight: 400; }
.topbar .brand-logo { height: 22px; width: auto; filter: brightness(0) invert(1); }
.topbar .user-info { font-size: 12px; text-align: right; display: flex; align-items: center; gap: 8px; }
.topbar button.logout {
  background: rgba(255,255,255,.15); color: white; border: none; border-radius: 6px;
  padding: 6px 10px; font-size: 12px; cursor: pointer;
}
.topbar button.theme-toggle {
  background: rgba(255,255,255,.15); color: white; border: none; border-radius: 6px;
  width: 30px; height: 30px; font-size: 15px; cursor: pointer; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
}

.offline-banner {
  background: var(--warning); color: white; text-align: center; font-size: 13px;
  padding: 6px; display: none;
}
.offline-banner.show { display: block; }

.container { max-width: 960px; margin: 0 auto; padding: 16px; }

.card {
  background: var(--card); border-radius: var(--radius); padding: 16px;
  margin-bottom: 16px; box-shadow: 0 1px 3px rgba(0,0,0,.06); border: 1px solid var(--border);
}

h1, h2, h3 { color: var(--heading); }
h2.section-title {
  font-size: 15px; text-transform: uppercase; letter-spacing: .03em;
  border-bottom: 2px solid var(--tsg-accent); padding-bottom: 6px; margin-top: 0;
}

label { display: block; font-size: 13px; font-weight: 600; margin: 10px 0 4px; color: var(--text); }
input, select, textarea {
  width: 100%; padding: 9px 10px; border: 1px solid var(--border); border-radius: 6px;
  font-size: 14px; background: var(--card); color: var(--text); font-family: inherit;
}
textarea { resize: vertical; min-height: 60px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--tsg-blue); box-shadow: 0 0 0 2px rgba(11,61,145,.15); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
@media (max-width: 560px) { .grid-2 { grid-template-columns: 1fr; } }

.checkbox-group { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 6px; }
.checkbox-group label {
  display: flex; align-items: center; gap: 6px; font-weight: 400; font-size: 13px;
  background: var(--surface-soft); padding: 6px 10px; border-radius: 20px; margin: 0; cursor: pointer;
}
.checkbox-group input { width: auto; }

button, .btn {
  display: inline-block; background: var(--tsg-blue); color: white; border: none;
  border-radius: 6px; padding: 10px 16px; font-size: 14px; font-weight: 600; cursor: pointer;
}
button.secondary, .btn.secondary { background: var(--surface-soft); color: var(--text); }
button.danger { background: var(--danger); }
button.small { padding: 6px 10px; font-size: 12px; }
button:disabled { opacity: .5; cursor: not-allowed; }

/* Boutons icône seule (actions CRUD répétées : modifier/supprimer/activer, lignes de tableau…) */
.btn-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; padding: 0; border-radius: 8px;
  background: var(--surface-soft); color: var(--text); border: none; cursor: pointer;
  font-size: 16px; line-height: 1; flex-shrink: 0;
}
.btn-icon:hover { background: var(--surface-soft-hover); }
.btn-icon.primary { background: var(--tsg-blue); color: white; }
.btn-icon.primary:hover { background: var(--tsg-blue-dark); }
.btn-icon.danger { background: var(--status-red-bg); color: var(--status-red-fg); }
.btn-icon.success { background: var(--status-green-bg); color: var(--status-green-fg); }
.btn-icon:disabled { opacity: .4; cursor: not-allowed; }
.btn-icon-group { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

.repeat-table { width: 100%; border-collapse: collapse; margin-top: 6px; }
.repeat-table th { text-align: left; font-size: 12px; color: var(--text-muted); padding: 4px; }
.repeat-table td { padding: 4px; vertical-align: top; }
.repeat-row-actions { text-align: center; width: 32px; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 11px; font-weight: 700; }
.badge.nouveau { background: var(--status-gray-bg); color: var(--status-gray-fg); }
.badge.programmee { background: var(--status-blue-bg); color: var(--status-blue-fg); }
.badge.en-cours { background: var(--status-amber-bg); color: var(--status-amber-fg); }
.badge.transformee { background: var(--status-purple-bg); color: var(--status-purple-fg); }
.badge.gagnee { background: var(--status-green-bg); color: var(--status-green-fg); }
.badge.perdue { background: var(--status-red-bg); color: var(--status-red-fg); }
.badge.archivee { background: var(--status-gray-bg); color: var(--text-muted); }

.list-item { display: flex; justify-content: space-between; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--border); cursor: pointer; }
.list-item:last-child { border-bottom: none; }
.list-item:hover { background: var(--surface-hover); }
.list-item .meta { font-size: 12px; color: var(--text-muted); }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
@media (max-width: 640px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }
.stat-tile { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; text-align: center; }
.stat-tile .num { font-size: 24px; font-weight: 800; color: var(--tsg-blue); }
html.theme-dark .stat-tile .num { color: var(--status-blue-fg); }
.stat-tile .lbl { font-size: 11px; color: var(--text-muted); text-transform: uppercase; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filters select, .filters input { width: auto; min-width: 140px; }

.pagination {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border);
}
.pagination button {
  background: var(--surface-soft); color: var(--text); padding: 6px 12px; font-size: 13px;
}
.pagination button:hover:not(:disabled) { background: var(--surface-soft-hover); }
.pagination .pagination-info { font-size: 12px; color: var(--text-muted); white-space: nowrap; }

.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; background: var(--card); border-top: 1px solid var(--border);
  display: flex; justify-content: space-around; padding: 6px 0; z-index: 20;
}
.bottom-nav a { flex: 1; text-align: center; font-size: 11px; color: var(--text-muted); padding: 6px 0; }
.bottom-nav a.active { color: var(--tsg-blue); font-weight: 700; }
html.theme-dark .bottom-nav a.active { color: var(--status-blue-fg); }
.bottom-nav .icon { font-size: 18px; display: block; }

.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 16px; }
.login-card { max-width: 380px; width: 100%; }
.login-card h1 { text-align: center; font-size: 20px; }
.login-card .logo { text-align: center; font-size: 40px; margin-bottom: 6px; }
.error-msg { color: var(--danger); font-size: 13px; margin-top: 8px; }
.hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.pill-status { font-size: 11px; padding: 2px 8px; border-radius: 10px; font-weight: 700; }
.pill-status.pending { background: var(--status-amber-bg); color: var(--status-amber-fg); }
.pill-status.synced { background: var(--status-green-bg); color: var(--status-green-fg); }
.pill-status.error { background: var(--status-red-bg); color: var(--status-red-fg); }

.attachment-item { display: flex; align-items: center; justify-content: space-between; padding: 6px 0; font-size: 13px; border-bottom: 1px solid var(--border); }

.toast {
  position: fixed; bottom: 76px; left: 50%; transform: translateX(-50%);
  background: var(--tsg-blue-dark); color: white; padding: 10px 18px; border-radius: 20px;
  font-size: 13px; z-index: 50; opacity: 0; transition: opacity .3s;
}
.toast.show { opacity: 1; }

.empty-state { text-align: center; color: var(--text-muted); padding: 30px 10px; }

/* --- Graphiques (SVG inline, sans dépendance externe — voir js/charts.js) --- */
.viz-root {
  --chart-series-1: var(--tsg-blue);
  --chart-series-1-wash: rgba(11, 61, 145, .1);
  --chart-grid: var(--border);
  --chart-text-muted: var(--text-muted);
  --chart-surface: var(--card);
}
html.theme-dark .viz-root {
  --chart-series-1: #5b96e0;
  --chart-series-1-wash: rgba(91, 150, 224, .18);
}
.chart-wrap { position: relative; width: 100%; }
.chart-wrap svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart-hit { cursor: pointer; }
.chart-hit:hover + .chart-dot, .chart-dot.hover { r: 6; }
.chart-bar { fill: var(--chart-series-1); transition: fill .1s; }
.chart-bar:hover { fill: var(--tsg-blue-dark); }
.chart-tooltip {
  position: absolute; pointer-events: none; z-index: 10;
  background: var(--tsg-blue-dark); color: white; padding: 6px 10px; border-radius: 6px;
  font-size: 12px; line-height: 1.4; white-space: nowrap; opacity: 0; transform: translate(-50%, -100%);
  transition: opacity .1s; box-shadow: 0 4px 12px rgba(0,0,0,.2);
}
.chart-tooltip.show { opacity: 1; }
.chart-tooltip .tt-value { font-weight: 700; font-size: 13px; }
.chart-tooltip .tt-label { opacity: .85; }
