/* Back-office et espace client OUTILLÉ. S'appuie sur tokens.css, base.css et components.css (mêmes couleurs,
   police, boutons, champs, pastilles). Pensé d'abord pour le téléphone : les tableaux deviennent des cartes,
   la navigation défile horizontalement, toutes les cibles font au moins 44 px. Aucun style en ligne (CSP). */

body.portal { min-height: 100vh; background: var(--paper); }
.p-container { width: min(100% - 2 * var(--gutter), 1120px); margin-inline: auto; }

/* ------------------------------------------------------------ En-tête et navigation */

.p-header { position: sticky; top: 0; z-index: 30; background: var(--white); border-bottom: 1px solid var(--line); }
.p-header__inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 60px; }
.p-header__brand { display: inline-flex; align-items: center; gap: 12px; min-height: var(--tap); text-decoration: none; min-width: 0; }
.p-header__brand img { width: 96px; height: auto; flex: none; }
.p-header__brand span {
  padding-left: 12px; border-left: 1px solid var(--line-strong);
  font-size: var(--fs-sm); font-weight: 800; color: var(--navy-80); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.p-nav { margin-bottom: -1px; overflow-x: auto; scrollbar-width: none; }
.p-nav::-webkit-scrollbar { display: none; }
.p-nav ul { display: flex; gap: 4px; }
.p-nav a {
  display: inline-flex; align-items: center; gap: 8px; min-height: 48px; padding: 0 12px;
  border-bottom: 3px solid transparent; color: var(--navy-80); font-size: var(--fs-sm); font-weight: 700; text-decoration: none; white-space: nowrap;
}
.p-nav a:hover { color: var(--navy); }
.p-nav a[aria-current='page'] { border-bottom-color: var(--mint); color: var(--navy); font-weight: 800; }
.p-nav .icon { width: 18px; height: 18px; }
.p-nav__count { min-width: 22px; padding: 1px 7px; border-radius: 999px; background: var(--navy); color: var(--white); font-size: 12px; font-weight: 800; text-align: center; }

.p-account { position: relative; }
.p-account summary {
  display: inline-flex; align-items: center; gap: 8px; min-height: var(--tap); padding: 0 12px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-pill); background: var(--white); cursor: pointer; list-style: none;
}
.p-account summary::-webkit-details-marker { display: none; }
.p-account summary .icon { width: 18px; height: 18px; }
.p-account__name { font-weight: 800; font-size: var(--fs-sm); }
.p-account__role { font-size: var(--fs-xs); color: var(--mute); }
.p-account__panel {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 40; display: grid; min-width: 240px; padding: 6px;
  border: 1px solid var(--line); border-radius: 16px; background: var(--white); box-shadow: var(--shadow);
  transform-origin: top right;
  transition: transform 160ms cubic-bezier(0.23, 1, 0.32, 1), opacity 160ms cubic-bezier(0.23, 1, 0.32, 1);
}
@starting-style { .p-account[open] .p-account__panel { transform: scale(0.96); opacity: 0; } }
.p-account__panel a, .p-account__panel button {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: var(--tap); padding: 0 12px;
  border: 0; border-radius: 10px; background: none; color: var(--navy); font: inherit; font-size: var(--fs-sm); font-weight: 700; text-align: left; text-decoration: none; cursor: pointer;
}
.p-account__panel a:hover, .p-account__panel button:hover { background: var(--navy-soft); }
.p-account__panel .icon { width: 18px; height: 18px; }
@media (max-width: 640px) {
  .p-account__name, .p-account__role { display: none; }
  .p-account summary { padding: 0 11px; }
}

/* ------------------------------------------------------------ Contenu */

.p-main { display: grid; gap: 20px; align-content: start; padding-block: 24px 64px; }
.p-main:focus { outline: none; }
.p-head { display: grid; gap: 10px; }
.p-head__row { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 20px; }
.p-head h1 { font-size: clamp(1.625rem, 1.3rem + 1.4vw, 2.25rem); overflow-wrap: anywhere; }
.p-head .lead { margin-top: 6px; max-width: 70ch; font-size: var(--fs-md); }
.p-head .eyebrow { margin-bottom: 6px; }
.p-head__actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.p-back { display: inline-flex; align-items: center; gap: 6px; justify-self: start; min-height: var(--tap); font-size: var(--fs-sm); font-weight: 700; text-decoration: none; color: var(--navy-80); }
.p-back:hover { color: var(--navy); text-decoration: underline; }
.p-back .icon { width: 18px; height: 18px; }

.p-grid { display: grid; gap: 20px; align-items: start; }
@media (min-width: 900px) { .p-grid { grid-template-columns: 1fr 1fr; } }

.p-card { min-width: 0; padding: clamp(16px, 3vw, 24px); border: 1px solid var(--line); border-radius: 20px; background: var(--white); }
.p-card__head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; margin-bottom: 14px; }
.p-card__head h2 { font-size: 1.125rem; }
.p-card > .meta + * { margin-top: 12px; }

.p-flash { display: flex; align-items: flex-start; gap: 10px; padding: 12px 16px; border-radius: 14px; font-weight: 700; }
.p-flash .icon { width: 20px; height: 20px; flex: none; margin-top: 1px; }
.p-flash--success { background: var(--mint-soft); color: var(--mint-ink); border: 1px solid #bfe9cf; }
.p-flash--danger { background: var(--danger-bg); color: var(--danger); border: 1px solid #f2c4c0; }

.p-list { display: grid; }
.p-list li { display: grid; gap: 4px; padding-block: 12px; border-bottom: 1px solid var(--line); }
.p-list li:last-child { border-bottom: 0; }
.p-list li > .badge { justify-self: start; }

.p-items { display: grid; gap: 16px; }
.p-items > li { display: grid; gap: 8px; padding-bottom: 16px; border-bottom: 1px dashed var(--line); }
.p-items > li:last-child { padding-bottom: 0; border-bottom: 0; }
.p-items > li > .badge { justify-self: start; }
.p-items__head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 12px; }
.p-edit { display: inline-flex; align-items: center; gap: 6px; min-height: var(--tap); font-size: var(--fs-sm); font-weight: 700; }
.p-edit .icon { width: 16px; height: 16px; }
.event-item .p-edit { grid-column: 2; justify-self: start; }

.p-dl { display: grid; gap: 0; }
.p-dl > div { display: grid; gap: 2px; padding-block: 10px; border-bottom: 1px solid var(--line); }
.p-dl > div:last-child { border-bottom: 0; }
.p-dl dt { font-size: var(--fs-xs); font-weight: 800; color: var(--mute); text-transform: uppercase; letter-spacing: 0.06em; }
.p-dl dd { overflow-wrap: anywhere; white-space: pre-line; }
@media (min-width: 640px) { .p-dl > div { grid-template-columns: 200px 1fr; gap: 16px; } }

.p-quote { margin-top: 14px; padding: 14px 16px; border-left: 4px solid var(--mint); border-radius: 0 12px 12px 0; background: var(--paper); white-space: pre-line; overflow-wrap: anywhere; }

.p-actions, .p-row-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.p-inline { display: inline-flex; }
.p-danger-link a { display: inline-flex; align-items: center; gap: 8px; min-height: var(--tap); color: var(--danger); font-weight: 700; }
.p-danger-link .icon { width: 18px; height: 18px; }

.p-details { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; }
.p-details summary { display: inline-flex; align-items: center; gap: 8px; min-height: var(--tap); font-weight: 800; cursor: pointer; }
.p-details summary .icon { width: 18px; height: 18px; }
.p-details[open] summary { margin-bottom: 12px; }

.p-filters ul { display: flex; flex-wrap: wrap; gap: 8px; }
.p-filters a {
  display: inline-flex; align-items: center; min-height: var(--tap); padding: 0 16px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-pill); background: var(--white); font-size: var(--fs-sm); font-weight: 700; text-decoration: none;
}
.p-filters a[aria-current='page'] { border-color: var(--navy); background: var(--navy); color: var(--white); }

/* Formulaires */
.p-form { display: grid; gap: 18px; }
.p-form__grid { display: grid; gap: 16px; }
@media (min-width: 760px) { .p-card .p-form__grid { grid-template-columns: 1fr 1fr; } .p-form__grid .field--wide { grid-column: 1 / -1; } }
.p-grid .p-card .p-form__grid { grid-template-columns: 1fr; }
.p-form__actions { display: flex; flex-wrap: wrap; gap: 10px; }
.p-form .field textarea { min-height: 110px; }

/* Tableaux : lignes en cartes sur téléphone (le libellé vient de data-label). */
.p-table-wrap { overflow-x: auto; }
.p-table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.p-table th { padding: 10px 12px; border-bottom: 2px solid var(--line-strong); font-size: var(--fs-xs); font-weight: 800; color: var(--mute); text-align: left; text-transform: uppercase; letter-spacing: 0.06em; }
.p-table td { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: top; overflow-wrap: anywhere; }
@media (max-width: 760px) {
  .p-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .p-table, .p-table tbody, .p-table tr, .p-table td { display: block; }
  .p-table tr { padding: 12px 14px; margin-bottom: 10px; border: 1px solid var(--line); border-radius: 16px; background: var(--white); }
  .p-table td { display: grid; grid-template-columns: 9.5em 1fr; gap: 10px; padding: 6px 0; border: 0; }
  .p-table td::before { content: attr(data-label); font-size: var(--fs-xs); font-weight: 800; color: var(--mute); }
}

/* Repris des anciennes maquettes : étapes de projet, rendez-vous, documents, chiffres clés */
.stage { display: grid; gap: 8px; }
.stage__label { font-size: var(--fs-sm); color: var(--navy-80); }
.stage-track { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
.stage-track li { height: 8px; border-radius: 999px; border: 1.5px solid var(--line-strong); background: var(--white); }
.stage-track li.is-done { background: var(--navy); border-color: var(--navy); }
.stage-track li.is-current { background: var(--mint); border-color: var(--navy); }

.event-list { display: grid; gap: 12px; }
.event-item { display: grid; grid-template-columns: 56px minmax(0, 1fr); gap: 4px 12px; align-items: center; }
.event-item__date { display: grid; justify-items: center; padding: 6px 0; border-radius: 12px; background: var(--mint-soft); line-height: 1.1; }
.event-item__date span { font-size: 11px; font-weight: 700; text-transform: uppercase; color: var(--navy-60); }
.event-item__date strong { font-size: 1.25rem; }
.event-item__title { font-weight: 800; }
.event-item .meta .icon { width: 14px; height: 14px; vertical-align: -2px; margin-right: 2px; }

.doc-list { display: grid; gap: 8px; }
.doc-row { display: grid; grid-template-columns: 40px minmax(0, 1fr); gap: 8px 12px; align-items: center; padding: 12px; border: 1px solid var(--line); border-radius: 14px; background: var(--white); }
.doc-row__icon { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; background: var(--navy-soft); }
.doc-row__icon .icon { width: 20px; height: 20px; }
.doc-row__main { min-width: 0; }
.doc-row__title { font-weight: 800; overflow-wrap: anywhere; }
.doc-row > .btn, .doc-row > .p-row-actions { grid-column: 2; justify-self: start; }
@media (min-width: 640px) {
  .doc-row { grid-template-columns: 40px minmax(0, 1fr) auto; }
  .doc-row > .btn, .doc-row > .p-row-actions { grid-column: auto; }
}

.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.kpis > div { padding: 16px 18px; border: 1px solid var(--line); border-radius: 18px; background: var(--white); }
.kpis dt { font-size: var(--fs-xs); font-weight: 700; color: var(--mute); }
.kpis dd { margin-top: 4px; font-size: clamp(1.75rem, 1.4rem + 1.4vw, 2.5rem); font-weight: 800; letter-spacing: -0.03em; }
.kpis dd a { color: inherit; text-decoration: none; }
.kpis dd a:hover { text-decoration: underline; }
@media (min-width: 760px) { .kpis { grid-template-columns: repeat(4, 1fr); } }

/* ------------------------------------------------------------ Pages d'accès (connexion, liens, erreurs) */

.p-access { display: grid; place-items: center; gap: 16px; min-height: calc(100vh - 40px); padding: 32px var(--gutter); }
.p-access__card { display: grid; gap: 16px; width: min(100%, 460px); padding: clamp(22px, 5vw, 36px); border: 1px solid var(--line); border-radius: 24px; background: var(--white); box-shadow: var(--shadow); }
.p-access__card h1 { font-size: clamp(1.5rem, 1.3rem + 1vw, 2rem); }
.p-access__logo { justify-self: start; display: inline-flex; }
.p-access__logo img { width: 120px; height: auto; }
.p-access__links a { font-weight: 700; }
.p-access__foot { font-size: var(--fs-sm); color: var(--mute); }
.p-form--narrow { gap: 14px; }

.p-personas { display: grid; gap: 8px; }
.p-persona {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; min-height: 56px; padding: 10px 14px;
  border: 1px solid var(--line-strong); border-radius: 14px; background: var(--white); color: var(--navy); font: inherit; text-align: left; cursor: pointer;
  transition: border-color 150ms ease, transform 160ms cubic-bezier(0.23, 1, 0.32, 1);
}
.p-persona > span { display: grid; }
.p-persona .icon { width: 20px; height: 20px; flex: none; }
.p-persona:hover { border-color: var(--navy); }
.p-persona:active { transform: scale(0.98); }

.p-footer { padding-block: 24px; border-top: 1px solid var(--line); background: var(--white); font-size: var(--fs-sm); color: var(--mute); }

@media (prefers-reduced-motion: reduce) {
  @starting-style { .p-account[open] .p-account__panel { transform: none; } }
  .p-persona:active { transform: none; }
}
