/* =========================================================
   Variables
   ========================================================= */
:root {
  /* Couleurs (thème sombre) */
  --bg: #0b1020;
  --panel: #11162a;
  --panel-2: #0f1426;
  --text: #e8ecf3;
  --muted: #8a92a3;
  --border: #202944;
  --primary: #4f7cff;
  --danger: #ef4444;
  --chip: #1b2444;

  /* Layout */
  --wrap-max: 1680px;   /* largeur max page */
  --gap: 18px;          /* écart entre colonnes et blocs */
  --recap-w-md: 800px;  /* largeur récap ≥ 1024px */
  --recap-w-lg: 400px;  /* largeur récap ≥ 1400px */
}

/* Thème clair – variables */
:root[data-theme="light"] {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --panel-2: #f8f9fe;
  --text: #0f172a;
  --muted: #63708a;
  --border: #dbe0f0;
  --primary: #355EEF;
  --danger: #d83a3a;
  --chip: #ecf0ff;
}

/* =========================================================
   Base
   ========================================================= */
* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at top, rgba(56, 189, 248, 0.22), transparent 55%),
    radial-gradient(circle at bottom, rgba(15, 23, 42, 0.9), #020617);
  background-attachment: fixed;
  font: 14px/1.45 system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
}

/* Thème clair – fond simple */
:root[data-theme="light"] body {
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg) 100%);
  background-attachment: scroll;
}

/* =========================================================
   Layout & typographie
   ========================================================= */
.wrap {
  max-width: min(var(--wrap-max), 95vw); /* plein écran mais capé */
  margin: 0 auto;
  padding: 24px;
}

@media (max-width: 768px) {
  .wrap {
    padding: 16px;
  }
}

@media (max-width: 480px) {
  .wrap {
    padding: 12px;
  }
}

.header {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
}

.header h1 {
  margin: 0 0 6px 0;
  font-size: 20px;
}

.muted {
  color: var(--muted);
}

.row {
  display: flex;
  align-items: center;
}

.row.wrap {
  flex-wrap: wrap;
}

.gap > * {
  margin-right: 8px;
}

.gap > *:last-child {
  margin-right: 0;
}

.title {
  font-weight: 700;
  margin-bottom: 10px;
}

.nowrap {
  white-space: nowrap;
}

.tabnums {
  font-variant-numeric: tabular-nums;
}

/* Grille principale */
.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--gap);
}

@media (min-width: 1024px) {
  .grid {
    grid-template-columns: minmax(0, 1fr) var(--recap-w-md);
  }
}

@media (min-width: 1400px) {
  .grid {
    grid-template-columns: minmax(0, 1fr) var(--recap-w-lg);
  }
}

/* =========================================================
   Cartes & blocs
   ========================================================= */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 20px;
}

.card.center {
  text-align: center;
  padding: 28px;
}

.sticky {
  position: sticky;
  top: 16px;
}

@media (max-width: 1023px) {
  .sticky {
    position: static;
    top: auto;
  }
}

/* Badges / résumé */
.chip {
  display: inline-block;
  background: var(--chip);
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.summary-line {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 6px 0 10px 0;
}

/* =========================================================
   Boutons
   ========================================================= */
.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
  line-height: 1;
  transition: .15s ease;
}

.btn:hover {
  filter: brightness(1.06);
}

.btn.primary {
  background: var(--primary);
  border-color: transparent;
  color: #fff;
}

/* Thème clair – bouton primaire */
:root[data-theme="light"] .btn.primary {
  color: #fff;
}

.btn.danger {
  background: #2a1010;
  border-color: #3a1a1a;
  color: #ffb3b3;
}

/* Thème clair – bouton danger */
:root[data-theme="light"] .btn.danger {
  background: #ffecec;
  color: #9b1c1c;
  border-color: #ffd0d0;
}

.btn.ghost {
  background: transparent;
}

@media (max-width: 600px) {
  .btn {
    padding: 10px 12px;
    border-radius: 12px;
  }
}

/* =========================================================
   Champs & formulaires
   ========================================================= */
.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field > span {
  font-size: 12px;
  color: var(--muted);
}

.field.small {
  width: 120px;
}

.field.grow {
  flex: 1;
  min-width: 220px;
}

input,
select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 10px;
  border-radius: 10px;
  outline: none;
  height: 36px;
  min-width: 0;
}

input:focus,
select:focus {
  border-color: #3a4b7d;
}

.form-line {
  align-items: flex-end;
}

.form-line .btn {
  height: 36px;
  display: inline-flex;
  align-items: center;
}

@media (max-width: 900px) {
  .form-line {
    flex-wrap: wrap;
    gap: 10px;
  }

  .field.small {
    width: 100px;
  }

  .field.grow {
    min-width: 160px;
  }
}

/* =========================================================
   Tabs modules
   ========================================================= */
.tabs-list {
  display: flex;
  gap: 8px;
  flex-wrap: nowrap;
  margin-bottom: 12px;
  overflow: auto;
  padding-bottom: 4px;
}

.tabs-list::-webkit-scrollbar {
  height: 8px;
}

.tabs-list::-webkit-scrollbar-thumb {
  background: #1c2544;
  border-radius: 8px;
}

/* Thème clair – scrollbar tabs */
:root[data-theme="light"] .tabs-list::-webkit-scrollbar-thumb {
  background: #cfd6ff;
}

.tab {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  cursor: pointer;
  max-width: 260px;
  height: 32px;
}

.tab.active {
  background: #1a2344;
  border-color: #2a3a66;
}

/* Thème clair – tab active */
:root[data-theme="light"] .tab.active {
  background: #eaf0ff;
  border-color: #cfe0ff;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.tab .ellipsis{
  color: var(--text);      /* texte principal, pas muted */
  font-size: 13px;
  font-weight: 500;
}

.ellipsis {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Mini progress dans les tabs */
.tab .mini-pbar {
  flex: 0 0 56px;
  height: 6px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255, 255, 255, .12);
  margin-left: 8px;
}

:root[data-theme="light"] .tab .mini-pbar {
  background: rgba(0, 0, 0, .08);
}

.tab .mini-pbar > span {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--primary);
  transition: width .35s ease;
}

.tab .mini-pbar > span.warn {
  background: #f59e0b;
}

.tab .mini-pbar > span.dang {
  background: #ef4444;
}

/* =========================================================
   Tableau des entrées
   ========================================================= */
.table-wrap {
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow-x: auto;    /* toujours scrollable si nécessaire */
  overflow-y: visible; /* ne coupe jamais le badge en bas */
  padding-bottom: 6px;
}

.table-wrap table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
  min-width: 1060px; /* largeur minimale */
}

thead th {
  position: sticky;
  top: 0;
  background: #11172e;
  border-bottom: 1px solid var(--border);
  text-align: left;
  padding: 10px;
}

/* Thème clair – en-têtes */
:root[data-theme="light"] thead th {
  background: #f3f6ff;
}

td {
  padding: 8px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  vertical-align: middle;
  min-width: 0;
}

/* Thème clair – cellules */
:root[data-theme="light"] td {
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

tfoot td {
  background: var(--panel-2);
}

.right {
  text-align: right;
}

.center {
  text-align: center;
}

.divider {
  height: 1px;
  background: var(--border);
  margin: 12px 0;
}

/* Largeurs colonnes tableau */
.table-wrap th:nth-child(1),
.table-wrap td:nth-child(1) {
  width: 150px; /* Date */
}

.table-wrap th:nth-child(2),
.table-wrap td:nth-child(2),
.table-wrap th:nth-child(3),
.table-wrap td:nth-child(3) {
  width: 110px; /* Début / Fin */
}

.table-wrap th:nth-child(4),
.table-wrap td:nth-child(4) {
  width: 90px; /* Pause */
}

.table-wrap th:nth-child(5),
.table-wrap td:nth-child(5) {
  width: 150px; /* Durée */
}

.table-wrap th:nth-child(7),
.table-wrap td:nth-child(7) {
  width: 220px; /* Actions */
}

.table-wrap td input {
  width: 100%;
  min-width: 0;
}

.table-wrap td:nth-child(7) .row {
  flex-wrap: wrap;
  gap: 8px;
}

/* =========================================================
   Récapitulatif
   ========================================================= */
.kv-line {
  display: grid;
  grid-template-columns: minmax(0, 1fr) max-content;
  align-items: center;
  column-gap: 14px;
  row-gap: 4px;
  padding: 10px 0;
  border-bottom: 1px dashed rgba(0, 0, 0, .06);
}

.kv-line:last-child {
  border-bottom: 0;
}

.kv-left {
  min-width: 0;
}

.kv-left .ellipsis {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: normal;
  line-height: 1.25;
}

.kv-right {
  justify-self: end;
  white-space: nowrap;
  padding-left: 8px;
  min-width: 96px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Thème clair – séparateurs récap */
:root[data-theme="light"] .kv-line {
  border-bottom: 1px dashed rgba(0, 0, 0, .08);
}

/* =========================================================
   Progression module
   ========================================================= */
.progress-wrap {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel-2);
  padding: 12px;
  margin: 6px 0 12px 0;
}

.progress-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  font-variant-numeric: tabular-nums;
}

.progress-kpis {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 13px;
}

.progress-kpis .pill {
  background: var(--chip);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 8px;
  color: var(--text);
}

.progress {
  position: relative;
  width: 100%;
  height: 12px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255, 255, 255, .08);
}

/* Thème clair – fond barre */
:root[data-theme="light"] .progress {
  background: rgba(0, 0, 0, .08);
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary), #6ea0ff);
  transition: width .35s ease;
}

/* Couleur par seuils */
.progress-bar.is-warning {
  background: linear-gradient(90deg, #f59e0b, #fbbf24);
}

.progress-bar.is-danger {
  background: linear-gradient(90deg, #ef4444, #f97373);
}

/* Étiquette flottante (xx %) */
.progress-label {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  right: 8px;
  font-size: 12px;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .5);
  pointer-events: none;
}

/* Marqueur objectif (100 %) */
.progress-goal {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: #fff;
  opacity: .7;
}

.progress-goal::after {
  content: "100%";
  position: absolute;
  top: -18px;
  left: -18px;
  font-size: 10px;
  color: var(--muted);
}

/* Dépassement : bande rouge qui s’affiche après 100 % */
.progress-over {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 100%;
  width: 0%;
  background: linear-gradient(90deg, #ef4444, #b91c1c);
  opacity: .9;
}

/* =========================================================
   Interrupteur thème
   ========================================================= */
.theme-toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  width: 58px;
  height: 28px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--border);
}

.theme-toggle input {
  display: none;
}

.theme-toggle .slider {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 999px;
  display: block;
}

.theme-toggle .slider::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  transition: transform .25s ease;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .25);
}

.theme-toggle .icon {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  font-size: 14px;
  pointer-events: none;
  opacity: .9;
}

.theme-toggle .sun {
  left: 8px;
}

.theme-toggle .moon {
  right: 8px;
}

.theme-toggle input:checked + .slider::after {
  transform: translateX(30px);
}

/* Thème clair – interrupteur */
:root[data-theme="light"] .theme-toggle .slider::after {
  background: #fff;
}

/* =========================================================
   Feuille “Nouveau module”
   ========================================================= */
.sheet {
  display: none;
  margin-top: 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel-2);
  padding: 12px;
}

.sheet.is-open {
  display: block;
}