/* PimsWork - components.css : composants (BEM-like, prefixe-less) */

/* ---------- Bouton ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: var(--tap); min-width: var(--tap); padding: 0 var(--space-4);
  border: 1px solid var(--border-strong); border-radius: var(--radius-md);
  background: var(--surface); color: var(--text);
  font-size: var(--text-sm); font-weight: var(--weight-medium); line-height: 1;
  text-decoration: none; white-space: nowrap; user-select: none;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.btn:hover { background: var(--surface-hover); }
.btn:active { background: var(--surface-active); transform: translateY(1px); }
.btn--primary { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.btn--primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn--ghost { background: transparent; border-color: transparent; }
.btn--ghost:hover { background: var(--surface-hover); }
.btn--danger { color: var(--err); border-color: var(--err); }
.btn--danger:hover { background: var(--err-bg); }
.btn--sm { font-size: var(--text-xs); padding: 0 var(--space-3); } /* la hauteur reste >= 44px */
.btn--icon { padding: 0; width: var(--tap); }
.btn--block { width: 100%; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.45; cursor: not-allowed; transform: none; }

/* ---------- Champs ---------- */
.field { display: flex; flex-direction: column; gap: var(--space-1); }
.field__label { font-size: var(--text-sm); font-weight: var(--weight-medium); }
.field__hint { font-size: var(--text-xs); color: var(--text-muted); }
.field__error { font-size: var(--text-xs); color: var(--err); }
.input, .select, .textarea {
  width: 100%; min-height: var(--tap); padding: var(--space-2) var(--space-3);
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--radius-md);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.textarea { min-height: 120px; resize: vertical; line-height: var(--leading-normal); }
.input::placeholder, .textarea::placeholder { color: var(--text-muted); opacity: 1; }
.input:hover, .select:hover, .textarea:hover { border-color: var(--text-muted); }
.input:focus-visible, .select:focus-visible, .textarea:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.input[aria-invalid="true"], .input--error { border-color: var(--err); }
.input:disabled, .select:disabled, .textarea:disabled { background: var(--surface-2); opacity: 0.6; cursor: not-allowed; }
.select {
  appearance: none; -webkit-appearance: none; padding-right: 2.25rem; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px; background-repeat: no-repeat;
}

/* Case a cocher / radio : la zone cliquable (label) fait >= 44px */
.check { display: inline-flex; align-items: center; gap: var(--space-3); min-height: var(--tap); cursor: pointer; }
.check__input {
  appearance: none; -webkit-appearance: none; flex: none; margin: 0;
  width: 22px; height: 22px; border: 1.5px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); display: grid; place-content: center; cursor: pointer;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.check__input[type="radio"] { border-radius: var(--radius-full); }
.check__input::after {
  content: ""; width: 11px; height: 6px; border: solid var(--on-primary); border-width: 0 0 2px 2px;
  transform: rotate(-45deg) scale(0); margin-top: -2px; transition: transform var(--dur-fast) var(--ease);
}
.check__input[type="radio"]::after { width: 8px; height: 8px; border: 0; border-radius: 0; background: var(--on-primary); margin: 0; transform: scale(0); }
.check__input:checked { background: var(--primary); border-color: var(--primary); }
.check__input:checked::after { transform: rotate(-45deg) scale(1); }
.check__input[type="radio"]:checked::after { transform: scale(1); }
.check__input:disabled { opacity: 0.45; cursor: not-allowed; }
.check__label { font-size: var(--text-md); }

/* ---------- Badge / chip categorie (gris + lettre/icone, jamais la couleur seule) ---------- */
.chip {
  display: inline-flex; align-items: center; gap: var(--space-1);
  min-height: 24px; padding: 2px var(--space-3) 2px 3px;
  border-radius: var(--radius-full); border: 1px solid var(--border-strong);
  background: var(--cat-1-bg); color: var(--cat-1-fg);
  font-size: var(--text-xs); font-weight: var(--weight-medium); line-height: 1.2;
  max-width: 100%; min-width: 0; overflow-wrap: anywhere; /* un nom très long passe à la ligne au lieu de faire défiler la page */
}
.chip__icon { flex: none;
  display: inline-grid; place-content: center; width: 18px; height: 18px; border-radius: 0;
  background: var(--cat-1-fg); color: var(--cat-1-bg); font-size: 10px; font-weight: var(--weight-semibold);
}
.chip--cat-1 { --c-bg: var(--cat-1-bg); --c-fg: var(--cat-1-fg); }
.chip--cat-2 { --c-bg: var(--cat-2-bg); --c-fg: var(--cat-2-fg); }
.chip--cat-3 { --c-bg: var(--cat-3-bg); --c-fg: var(--cat-3-fg); }
.chip--cat-4 { --c-bg: var(--cat-4-bg); --c-fg: var(--cat-4-fg); }
.chip--cat-5 { --c-bg: var(--cat-5-bg); --c-fg: var(--cat-5-fg); }
.chip[class*="chip--cat-"] { background: var(--c-bg); color: var(--c-fg); }
.chip[class*="chip--cat-"] .chip__icon { background: var(--c-fg); color: var(--c-bg); }
.chip--dashed { border-style: dashed; }   /* motif : categorie 2/4 possible en pointille */
.chip--outline { background: transparent; color: var(--text); }
button.chip { cursor: pointer; min-height: var(--tap); padding-inline: var(--space-3); font-size: var(--text-sm); }
.badge {
  display: inline-block; min-width: 1.5em; padding: 1px 7px; text-align: center;
  background: var(--primary); color: var(--on-primary); border-radius: var(--radius-full);
  font-size: var(--text-xs); font-weight: var(--weight-semibold);
}
.badge--ok { background: var(--ok-bg); color: var(--ok); }
.badge--err { background: var(--err-bg); color: var(--err); }

/* ---------- Carte tache ---------- */
.task {
  display: grid; grid-template-columns: auto 1fr auto; align-items: start; gap: var(--space-3);
  padding: var(--space-3) var(--space-4); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm);
  transition: box-shadow var(--dur-base) var(--ease), border-color var(--dur-base) var(--ease);
}
.task:hover { box-shadow: var(--shadow-md); border-color: var(--border-strong); }
.task__body { min-width: 0; padding-block: var(--space-2); }
.task__title { font-weight: var(--weight-medium); overflow-wrap: anywhere; }
.task__meta { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); margin-top: var(--space-1); font-size: var(--text-xs); color: var(--text-muted); }
.task__actions { display: flex; gap: var(--space-1); }
.task--done .task__title { text-decoration: line-through; color: var(--text-muted); }
.task--done { background: var(--surface-2); box-shadow: none; }
.task--urgent { border-left: 4px solid var(--text); }
.task--urgent .task__title { font-weight: var(--weight-semibold); }

/* ---------- Liste ---------- */
.list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: var(--space-2); }
.list--flush { gap: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.list--flush .list__item + .list__item { border-top: 1px solid var(--border); }
.list__item { display: flex; align-items: center; gap: var(--space-3); min-height: var(--tap); padding: var(--space-2) var(--space-4); }
.list__item--link { color: inherit; text-decoration: none; }
.list__item--link:hover { background: var(--surface-hover); }
.list__title { flex: 1; min-width: 0; font-weight: var(--weight-medium); }
.list__sub { font-size: var(--text-sm); color: var(--text-muted); }
.list__heading { font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.06em; font-weight: var(--weight-semibold); color: var(--text-muted); margin: var(--space-5) 0 var(--space-2); }

/* ---------- Modale / drawer ----------
   Utiliser <dialog class="modal"> (showModal()) ou <div class="modal" role="dialog" aria-modal="true"> */
.modal {
  position: fixed; inset: 0; z-index: var(--z-modal); margin: auto;
  width: min(92vw, 520px); max-height: 88vh; max-height: 88dvh; padding: 0; overflow: hidden;
  display: flex; flex-direction: column;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
}
.modal:not([open]):is(dialog) { display: none; }
.modal::backdrop { background: var(--overlay); }
.modal__backdrop { position: fixed; inset: 0; z-index: var(--z-overlay); background: var(--overlay); }
.modal__header { flex: none; display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--border); }
.modal__title { font-size: var(--text-lg); }
.modal__body { padding: var(--space-5); overflow-y: auto; overscroll-behavior: contain; flex: 1 1 auto; min-height: 0; }
.modal__footer { flex: none; display: flex; justify-content: flex-end; gap: var(--space-2); padding: var(--space-4) var(--space-5); border-top: 1px solid var(--border); background: var(--surface-2); }
/* Drawer : bas d'ecran sur mobile, panneau a droite des 640px */
.modal--drawer { inset: 0; width: 100%; max-width: 100vw; height: 100vh; height: 100dvh; max-height: none; margin: 0; border-radius: 0; animation: slide-up var(--dur-slow) var(--ease); }
@media (min-width: 640px) {
  .modal--drawer { inset: 0 0 0 auto; width: 420px; max-height: none; height: 100%; border-radius: 0; animation: slide-left var(--dur-slow) var(--ease); }
}
/* encoche / barre d'accueil : uniquement le tiroir (collé aux bords de l'écran) ; écrit APRÈS les paddings des blocs, sinon le raccourci `padding` les écrase */
.modal--drawer .modal__header { padding-top: max(var(--space-4), env(safe-area-inset-top)); }
.modal--drawer .modal__body, .modal--drawer .modal__footer { padding-bottom: max(var(--space-5), env(safe-area-inset-bottom)); }
@keyframes slide-up { from { transform: translateY(100%); } }
@keyframes slide-left { from { transform: translateX(100%); } }

/* ---------- Onglets ---------- */
.tabs { display: flex; gap: var(--space-1); border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tabs__tab {
  flex: none; min-height: var(--tap); padding: 0 var(--space-4); background: none; border: 0;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  color: var(--text-muted); font-size: var(--text-sm); font-weight: var(--weight-medium);
  transition: color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.tabs__tab:hover { color: var(--text); }
.tabs__tab[aria-selected="true"], .tabs__tab--active { color: var(--text); border-bottom-color: var(--text); font-weight: var(--weight-semibold); }
.tabs__panel { padding-top: var(--space-4); }
.tabs__panel[hidden] { display: none; }

/* ---------- Toast ---------- */
.toasts { position: fixed; top: auto; width: auto; height: auto; margin: 0; padding: 0; border: 0; background: transparent; color: inherit; overflow: visible; /* neutralise la feuille de style navigateur des [popover] */ z-index: var(--z-toast); left: var(--space-4); right: var(--space-4); bottom: calc(var(--bottombar-h) + var(--space-4) + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: var(--space-2); pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: var(--space-3); min-height: var(--tap);
  padding: var(--space-2) var(--space-4); background: var(--primary); color: var(--on-primary);
  border-radius: var(--radius-md); box-shadow: var(--shadow-lg); font-size: var(--text-sm);
  animation: toast-in var(--dur-base) var(--ease);
}
.toast__action { margin-left: auto; background: none; border: 0; color: inherit; font-weight: var(--weight-semibold); text-decoration: underline; min-height: var(--tap); padding: 0 var(--space-2); }
.toast--ok { background: var(--ok-bg); color: var(--ok); border: 1px solid var(--ok); }
.toast--err { background: var(--err-bg); color: var(--err); border: 1px solid var(--err); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
@media (min-width: 640px) { .toasts { left: auto; width: 360px; right: var(--space-5); } }
@media (min-width: 1024px) { .toasts { bottom: var(--space-5); } }

/* ---------- Barre de filtres ---------- */
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); padding: var(--space-3); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.filters__search { flex: 1 1 100%; }
.filters__group { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.filters__chip { min-height: var(--tap); padding: 0 var(--space-4); border: 1px solid var(--border-strong); border-radius: var(--radius-full); background: transparent; font-size: var(--text-sm); }
.filters__chip:hover { background: var(--surface-hover); }
.filters__chip[aria-pressed="true"] { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.filters__reset { margin-left: auto; }
@media (min-width: 640px) { .filters__search { flex: 1 1 220px; } }

/* ---------- Minuteur de session ---------- */
.timer { display: flex; flex-direction: column; align-items: center; gap: var(--space-4); padding: var(--space-5); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); text-align: center; }
.timer__label { font-size: var(--text-sm); color: var(--text-muted); }
.timer__display { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: clamp(2.5rem, 12vw, 4rem); font-weight: var(--weight-semibold); letter-spacing: -0.03em; line-height: 1; }
.timer__progress { width: 100%; height: 6px; border-radius: var(--radius-full); background: var(--surface-active); overflow: hidden; }
.timer__bar { height: 100%; width: var(--progress, 0%); background: var(--primary); border-radius: inherit; transition: width 1s linear; }
.timer__controls { display: flex; gap: var(--space-2); }
.timer--running .timer__display { color: var(--text); }
.timer--paused .timer__display { color: var(--text-muted); }
.timer--compact { flex-direction: row; padding: var(--space-2) var(--space-4); }
.timer--compact .timer__display { font-size: var(--text-xl); }

/* ---------- Tableau ---------- */
.table-wrap { position: relative; /* contient les .sr-only absolus (sinon ils élargissent la page) */ overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); }
.table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.table__caption { padding: var(--space-3) var(--space-4); text-align: left; font-weight: var(--weight-semibold); }
.table th, .table td { padding: var(--space-3) var(--space-4); text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); font-weight: var(--weight-semibold); background: var(--surface-2); white-space: nowrap; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-hover); }
.table__num { text-align: right !important; font-variant-numeric: tabular-nums; }

/* ---------- Empty state ---------- */
.empty { display: flex; flex-direction: column; align-items: center; gap: var(--space-3); padding: var(--space-7) var(--space-5); text-align: center; border: 1px dashed var(--border-strong); border-radius: var(--radius-lg); color: var(--text-muted); }
.empty__icon { width: 48px; height: 48px; stroke: currentColor; fill: none; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.empty__title { font-size: var(--text-lg); font-weight: var(--weight-semibold); color: var(--text); }
.empty__text { max-width: 36ch; font-size: var(--text-sm); }

/* ---------- Carte generique ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); padding: var(--space-4) var(--space-5); }

/* ---------- Responsive (voir DESIGN.md > Responsive) ---------- */
@media (max-width: 639px) {
  .modal__header, .modal__body, .modal__footer { padding-inline: var(--space-4); }
  .modal__footer { flex-wrap: wrap; }
  .modal__footer .btn { flex: 1 1 auto; }
  /* filtres : une ligne defilante plutot qu'un mur de pastilles */
  .filters__group { flex-wrap: nowrap; overflow-x: auto; max-width: 100%; scrollbar-width: none; flex: 1 1 100%; }
  .filters__group::-webkit-scrollbar { display: none; }
  .filters__chip, .filters .select { flex: none; }
  .filters .select { flex: 1 1 130px; }
  .toast { padding-inline: var(--space-3); }
  /* tableau Pro -> cartes */
  .table--pro thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .table--pro, .table--pro tbody, .table--pro tr, .table--pro td { display: block; width: 100%; }
  .table--pro tr { padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--border); }
  .table--pro tbody tr:last-child { border-bottom: 0; }
  .table--pro td { display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); padding: var(--space-1) 0; border: 0; min-height: 32px; }
  .table--pro td:first-child { font-size: var(--text-md); padding-bottom: var(--space-2); }
  .table--pro td:first-child a { display: inline-flex; align-items: center; min-height: var(--tap); }
  .table--pro td:nth-child(2)::before { content: "Tâches ouvertes"; }
  .table--pro td:nth-child(3)::before { content: "Temps total"; }
  .table--pro td:nth-child(4)::before { content: "À facturer"; }
  .table--pro td:not(:first-child)::before { color: var(--text-muted); font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.05em; }
}
@media (max-width: 359px) {
  .btn { padding-inline: var(--space-3); }
  .app__content { padding-inline: var(--space-3); }
}
@media (hover: none) { .task:hover { box-shadow: var(--shadow-sm); } }
/* paysage mobile : drawer en panneau, barre basse compacte */
@media (max-height: 500px) and (orientation: landscape) {
  .modal { max-height: 100dvh; }
  .modal--drawer { inset: 0 0 0 auto; width: min(420px, 100vw); }
}
