/* Espace salarié Captain Prod : charte et composants (mobile d'abord). */
:root {
  --cp-yellow: #f3b500;
  --cp-yellow-soft: #fff4d6;
  --cp-blue: #1f3c46;
  --cp-blue-soft: #cfd9dd;
  --cp-muted: #5a7581;
  --cp-bg: #f5f5f5;
  --cp-bg-2: #e6e6e6;
  --cp-border: #d1d1d1;
  --cp-border-soft: #f0f0f0;
  --cp-white: #ffffff;
  --cp-danger: #b91c1c;
  --cp-danger-bg: #fee2e2;
  --cp-ok: #065f46;
  --cp-ok-bg: #d1fae5;
  --cp-font: 'Raleway', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --cp-font-head: 'Montserrat', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --cp-radius: 14px;
  --cp-nav-h: 78px;
}
* { box-sizing: border-box; }
html { font-size: 100%; height: 100%; }
body.cp-app {
  margin: 0;
  min-height: 100%;
  background: var(--cp-bg);
  color: var(--cp-blue);
  font-family: var(--cp-font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
body.cp-app a { color: var(--cp-blue); }
body.cp-app h1, body.cp-app h2, body.cp-app h3, body.cp-app h4, .cp-head { font-family: var(--cp-font-head); font-weight: 700; margin: 0; }

/* Structure */
.cp-shell { max-width: 720px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; position: relative; background: var(--cp-bg); }
@media (min-width: 900px) { .cp-shell { box-shadow: 0 0 0 1px var(--cp-border); min-height: 100vh; } }
.cp-header { background: var(--cp-blue); color: var(--cp-white); padding: calc(18px + env(safe-area-inset-top)) 20px 18px; display: flex; align-items: center; gap: 14px; }
.cp-header--tall { flex-direction: column; align-items: stretch; gap: 14px; }
body.cp-app .cp-header a:not(.cp-btn):not(.cp-chip) { color: var(--cp-white); }
body.cp-app .cp-header a.cp-btn--light { color: var(--cp-yellow); }
.cp-header .cp-title { font-family: var(--cp-font-head); font-weight: 700; font-size: 21px; line-height: 1.2; }
.cp-header .cp-sub { font-size: 13px; color: var(--cp-blue-soft); }
.cp-logo { width: 42px; height: 38px; object-fit: contain; }
.cp-avatar { width: 44px; height: 44px; border-radius: 50%; background: var(--cp-yellow); color: var(--cp-blue); display: inline-flex; align-items: center; justify-content: center; font-family: var(--cp-font-head); font-weight: 700; font-size: 16px; text-decoration: none; flex: 0 0 auto; }
.cp-main { flex: 1 1 auto; padding: 16px 16px calc(var(--cp-nav-h) + 24px); display: flex; flex-direction: column; gap: 16px; }
.cp-banner { background: var(--cp-yellow); color: var(--cp-blue); padding: 10px 16px; font-size: 13px; font-weight: 600; display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.cp-banner a { color: var(--cp-blue); font-weight: 700; }

/* Navigation basse */
.cp-nav { position: fixed; left: 0; right: 0; bottom: 0; margin: 0 auto; max-width: 720px; background: var(--cp-white); border-top: 1px solid var(--cp-border); display: grid; grid-template-columns: repeat(var(--cp-nav-cols, 4), minmax(0, 1fr)); gap: 4px; padding: 8px 8px calc(10px + env(safe-area-inset-bottom)); z-index: 20; }
.cp-nav a { min-height: 48px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; text-decoration: none; color: var(--cp-muted); font-size: 11px; font-weight: 500; border-radius: 10px; }
.cp-nav a svg { width: 22px; height: 22px; }
.cp-nav a.is-active { color: var(--cp-blue); font-weight: 600; background: var(--cp-yellow-soft); }

/* Sections et cartes */
.cp-section { display: flex; flex-direction: column; gap: 8px; }
.cp-section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.cp-section-title { font-family: var(--cp-font-head); font-weight: 700; font-size: 13px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--cp-muted); margin: 0; }
.cp-card { background: var(--cp-white); border: 1px solid var(--cp-border); border-radius: var(--cp-radius); padding: 16px; }
.cp-card--flush { padding: 0; overflow: hidden; }
.cp-card--warn { background: var(--cp-yellow-soft); border-color: var(--cp-yellow); }
.cp-card--danger { background: var(--cp-danger-bg); border-color: #fca5a5; }
.cp-card-head { padding: 12px 16px; border-bottom: 1px solid var(--cp-bg-2); display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.cp-card-head h2 { font-size: 15px; }
.cp-card-sub { padding: 9px 16px; background: #fbfbfb; border-bottom: 1px solid var(--cp-bg-2); font-size: 12px; font-weight: 600; color: var(--cp-muted); }

/* Listes */
.cp-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.cp-row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; min-height: 52px; text-decoration: none; color: var(--cp-blue); border-bottom: 1px solid var(--cp-border-soft); background: var(--cp-white); }
.cp-row:last-child { border-bottom: 0; }
.cp-row--link:hover { background: #fafafa; }
.cp-row .cp-row-body { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.cp-row .cp-row-title { font-weight: 600; font-size: 14px; }
.cp-row .cp-row-meta { font-size: 12px; color: var(--cp-muted); }
.cp-row .cp-row-end { font-size: 12px; color: var(--cp-muted); white-space: nowrap; }
.cp-chevron { font-size: 20px; color: var(--cp-muted); line-height: 1; }
.cp-muted { color: var(--cp-muted); }
.cp-small { font-size: 12px; }
.cp-empty { padding: 28px 16px; text-align: center; color: var(--cp-muted); font-size: 14px; }

/* Badges, pastilles de date */
.cp-badge { display: inline-flex; align-items: center; font-family: var(--cp-font-head); font-weight: 700; font-size: 11px; border-radius: 6px; padding: 4px 6px; min-width: 32px; justify-content: center; }
.cp-badge--bs { background: var(--cp-blue); color: var(--cp-white); }
.cp-badge--aem { background: var(--cp-yellow); color: var(--cp-blue); }
.cp-badge--ce { background: var(--cp-bg-2); color: var(--cp-blue); }
.cp-badge--contrat { background: var(--cp-muted); color: var(--cp-white); }
.cp-badge--archive { background: #ffffff; color: var(--cp-muted); border: 1px solid var(--cp-border); }
.cp-pill { display: inline-block; font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 10px; background: var(--cp-bg-2); color: var(--cp-blue); }
.cp-pill--warn { background: var(--cp-yellow-soft); }
.cp-pill--ok { background: var(--cp-ok-bg); color: var(--cp-ok); }
.cp-pill--danger { background: var(--cp-danger-bg); color: var(--cp-danger); }
.cp-pill--mute { background: #ffffff; border: 1px solid var(--cp-border); color: var(--cp-muted); }
.cp-date { border-radius: 10px; padding: 8px 10px; text-align: center; min-width: 50px; background: var(--cp-blue); color: var(--cp-white); flex: 0 0 auto; }
.cp-date--past { background: var(--cp-bg-2); color: var(--cp-blue); }
.cp-date .d { font-family: var(--cp-font-head); font-weight: 800; font-size: 19px; line-height: 1; }
.cp-date .m { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; }

/* Boutons */
.cp-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 46px; padding: 0 16px; border-radius: 12px; border: 1px solid transparent; font-family: var(--cp-font); font-weight: 600; font-size: 14px; text-decoration: none; cursor: pointer; background: var(--cp-white); color: var(--cp-blue); }
.cp-btn--primary { background: var(--cp-yellow); border-color: var(--cp-yellow); font-family: var(--cp-font-head); font-weight: 700; }
.cp-btn--outline { border-color: var(--cp-blue); }
.cp-btn--ghost { border-color: var(--cp-border); }
.cp-btn--light { border-color: var(--cp-yellow); color: var(--cp-yellow); background: transparent; }
.cp-btn--sm { min-height: 38px; padding: 0 12px; font-size: 12px; border-radius: 10px; }
.cp-btn--block { width: 100%; }
.cp-btn[disabled], .cp-btn.is-disabled { opacity: 0.55; pointer-events: none; }
.cp-btn svg { width: 16px; height: 16px; }

/* Chips de filtre et segments */
.cp-chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.cp-chips::-webkit-scrollbar { display: none; }
/* body.cp-app devant : la règle générale « body.cp-app a » (bleu) l'emporterait sinon sur la couleur des puces */
.cp-chip, body.cp-app .cp-chip { flex: 0 0 auto; min-height: 36px; padding: 0 14px; border-radius: 18px; border: 1px solid var(--cp-blue-soft); background: transparent; color: var(--cp-white); font-size: 13px; font-weight: 600; text-decoration: none; display: inline-flex; align-items: center; white-space: nowrap; }
.cp-chip.is-active, body.cp-app .cp-chip.is-active { background: var(--cp-yellow); border-color: var(--cp-yellow); color: var(--cp-blue); }
.cp-segment { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); background: var(--cp-bg-2); border-radius: 12px; padding: 4px; }
.cp-segment a { min-height: 40px; display: flex; align-items: center; justify-content: center; border-radius: 9px; font-size: 14px; font-weight: 600; text-decoration: none; color: var(--cp-blue); }
.cp-segment a.is-active { background: var(--cp-white); }
.cp-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.cp-stat { background: rgba(255,255,255,0.08); border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; }
.cp-stat .v { font-family: var(--cp-font-head); font-weight: 800; font-size: 20px; line-height: 1; }
.cp-stat .l { font-size: 11px; color: var(--cp-blue-soft); }

/* Formulaires */
.cp-field { display: flex; flex-direction: column; gap: 6px; }
.cp-label { font-size: 12px; font-weight: 600; color: var(--cp-muted); }
.cp-input, .cp-select, .cp-textarea { width: 100%; min-height: 46px; border: 1px solid var(--cp-border); border-radius: 10px; padding: 0 12px; font-family: var(--cp-font); font-size: 15px; color: var(--cp-blue); background: var(--cp-white); }
.cp-textarea { padding: 10px 12px; min-height: 90px; }
.cp-input:focus, .cp-select:focus, .cp-textarea:focus { outline: 2px solid var(--cp-yellow); outline-offset: 1px; border-color: var(--cp-yellow); }
.cp-input.is-invalid { border-color: #dc2626; }
.cp-help { font-size: 12px; color: var(--cp-muted); line-height: 1.4; }
.cp-error { font-size: 12px; color: var(--cp-danger); line-height: 1.4; }
.cp-check { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; font-size: 14px; border-bottom: 1px solid var(--cp-border-soft); padding: 0 16px; }
.cp-check:last-child { border-bottom: 0; }
.cp-check input { width: 22px; height: 22px; accent-color: var(--cp-blue); flex: 0 0 auto; }
.cp-grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
dl.cp-dl { margin: 0; display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 0 12px; font-size: 14px; padding: 4px 16px; }
dl.cp-dl dt { color: var(--cp-muted); padding: 9px 0; }
dl.cp-dl dd { margin: 0; padding: 9px 0; line-height: 1.4; overflow-wrap: anywhere; }
.cp-flash { padding: 12px 16px; border-radius: 12px; font-size: 14px; font-weight: 500; }
.cp-flash--ok { background: var(--cp-ok-bg); color: var(--cp-ok); }
.cp-flash--error { background: var(--cp-danger-bg); color: var(--cp-danger); }
.cp-flash--info { background: var(--cp-yellow-soft); color: var(--cp-blue); }

/* Compteur 507 h */
.cp-gauge { display: flex; gap: 16px; align-items: center; }
.cp-gauge svg { flex: 0 0 auto; }
.cp-gauge-body { display: flex; flex-direction: column; gap: 5px; }

/* Page de connexion */
body.cp-login { background: var(--cp-blue); color: var(--cp-white); font-family: var(--cp-font); margin: 0; min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.cp-login-box { width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 24px; }
.cp-login-brand { display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; }
.cp-login-brand img { width: 84px; height: 76px; object-fit: contain; }
.cp-login-brand h1 { font-family: var(--cp-font-head); font-weight: 800; font-size: 26px; line-height: 1.15; color: var(--cp-white); }
.cp-login-brand p { margin: 0; font-size: 14px; color: var(--cp-blue-soft); max-width: 320px; }
.cp-login-card { background: var(--cp-white); color: var(--cp-blue); border-radius: 20px; padding: 22px 20px; display: flex; flex-direction: column; gap: 14px; }
.cp-login-card h2 { font-size: 17px; }
.cp-login-foot { text-align: center; font-size: 12px; color: var(--cp-blue-soft); line-height: 1.5; }
.cp-login-foot a { color: var(--cp-yellow); }
.cp-link-btn { background: none; border: 0; padding: 0; color: var(--cp-muted); text-decoration: underline; font: inherit; font-size: 13px; cursor: pointer; }

/* ---- Bureau (≥ 900 px) : menu latéral, contenu large sur deux colonnes ---- */
/* Mobile : la marque et le bloc utilisateur n'existent que dans la barre latérale bureau (spécificité > .cp-nav a) */
.cp-nav a.cp-nav-brand, .cp-nav .cp-nav-user { display: none; }
@media (min-width: 900px) {
  .cp-shell { max-width: none; margin: 0; display: grid; grid-template-columns: 240px minmax(0, 1fr); grid-template-rows: auto auto 1fr; box-shadow: none; }
  .cp-banner { grid-column: 1 / -1; grid-row: 1; }
  .cp-header { grid-column: 2; grid-row: 2; margin: 28px 32px 0; border-radius: var(--cp-radius); padding: 22px 26px; max-width: 1100px; width: calc(100% - 64px); }
  .cp-header .cp-title { font-size: 24px; }
  .cp-main { grid-column: 2; grid-row: 3; padding: 20px 32px 48px; max-width: 1164px; width: 100%; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; align-content: start; align-items: start; }
  .cp-main > .cp-flash, .cp-main > p, .cp-main > form, .cp-main > .cp-segment, .cp-main > .cp-span, .cp-main > script, .cp-main > .cp-empty { grid-column: 1 / -1; }
  .cp-main > form.cp-card { max-width: 720px; }
  .cp-nav { grid-column: 1; grid-row: 1 / -1; position: sticky; top: 0; height: 100vh; max-width: none; margin: 0; display: flex; flex-direction: column; gap: 2px; padding: 20px 14px; background: var(--cp-blue); border-top: 0; border-right: 1px solid rgba(255,255,255,0.08); overflow-y: auto; }
  body.cp-app .cp-nav a { flex-direction: row; justify-content: flex-start; gap: 10px; min-height: 42px; padding: 0 12px; border-radius: 10px; color: var(--cp-white); font-size: 14px; }
  .cp-nav a svg { width: 18px; height: 18px; }
  body.cp-app .cp-nav a.is-active { background: var(--cp-yellow); color: var(--cp-blue); font-weight: 600; }
  body.cp-app .cp-nav a:not(.is-active):hover { background: rgba(255,255,255,0.08); }
  body.cp-app .cp-nav-brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px 18px; color: var(--cp-white); text-decoration: none; }
  .cp-nav-brand img { width: 36px; height: 33px; object-fit: contain; }
  .cp-nav-brand span { font-family: var(--cp-font-head); font-weight: 700; font-size: 15px; line-height: 1.1; }
  .cp-nav-user { display: flex; align-items: center; gap: 10px; margin-top: auto; padding: 14px 6px 4px; border-top: 1px solid rgba(255,255,255,0.12); color: var(--cp-white); }
  .cp-nav-user .cp-avatar { width: 36px; height: 36px; font-size: 13px; }
  .cp-nav-user .n { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .cp-nav-user .r { font-size: 11px; color: #8fa3ab; }
  body.cp-app .cp-nav-user a.l { font-size: 12px; color: #8fa3ab; text-decoration: underline; }
  .cp-header .cp-avatar { display: none; }
  .cp-stats { max-width: 560px; }
  .cp-gauge svg { width: 150px; height: 150px; }
}

/* ---- Notes de frais (v6) ---- */
.cp-upload-btns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.cp-upload-btn { position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 52px; border: 1px dashed var(--cp-blue); border-radius: 12px; background: var(--cp-white); color: var(--cp-blue); font-weight: 600; font-size: 13px; cursor: pointer; padding: 0 10px; text-align: center; }
.cp-upload-btn input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }
.cp-upload-btn.has-file { border-style: solid; background: var(--cp-yellow-soft); border-color: var(--cp-yellow); }
.cp-preview { display: none; align-items: center; gap: 10px; font-size: 13px; color: var(--cp-muted); }
.cp-preview.is-on { display: flex; }
.cp-thumb { width: 52px; height: 52px; border-radius: 8px; object-fit: cover; border: 1px solid var(--cp-border); background: var(--cp-bg-2); flex: 0 0 auto; }
.cp-thumb--pdf { display: inline-flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; color: var(--cp-muted); }
.cp-amount { font-family: var(--cp-font-head); font-weight: 700; font-size: 15px; white-space: nowrap; }
.cp-icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--cp-border); background: var(--cp-white); color: var(--cp-muted); cursor: pointer; padding: 0; flex: 0 0 auto; }
.cp-icon-btn--danger:hover { border-color: #fca5a5; color: var(--cp-danger); background: var(--cp-danger-bg); }
.cp-total-row { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; font-weight: 700; background: #fbfbfb; }
.cp-timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.cp-timeline li { display: flex; gap: 12px; align-items: flex-start; padding: 10px 16px; border-bottom: 1px solid var(--cp-border-soft); font-size: 13px; }
.cp-timeline li:last-child { border-bottom: 0; }
.cp-timeline .dot { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--cp-border); background: var(--cp-white); margin-top: 3px; flex: 0 0 auto; }
.cp-timeline li.is-done .dot { background: var(--cp-blue); border-color: var(--cp-blue); }
.cp-timeline li.is-current .dot { background: var(--cp-yellow); border-color: var(--cp-yellow); }
.cp-timeline .t { font-weight: 600; }
.cp-timeline .m { color: var(--cp-muted); font-size: 12px; }
@media (min-width: 900px) { body.cp-app .cp-span-ndf { grid-column: 1 / -1; } }
/* Note de frais (brouillon) : cartes de saisie alignées sur la largeur de la liste */
@media (min-width: 900px) { .cp-main > form.cp-card.cp-ndf-col, .cp-main > form.cp-card.cp-ndf-wide { max-width: none; } }
@media (min-width: 1200px) { .cp-main > form.cp-card.cp-ndf-col { grid-column: auto; align-self: stretch; } .cp-ndf-col > button[type=submit] { margin-top: auto; } }
/* Analyse automatique du justificatif : panneau d'attente */
.cp-ocr-wait { display: flex; align-items: center; gap: 14px; padding: 16px; border-radius: 12px; background: var(--cp-yellow-soft); border: 1px solid var(--cp-yellow); }
.cp-ocr-wait .t { font-weight: 700; font-size: 14px; }
.cp-ocr-wait .m { font-size: 12px; color: var(--cp-muted); margin-top: 2px; }
.cp-spinner { width: 26px; height: 26px; border-radius: 50%; border: 3px solid rgba(31,60,70,0.15); border-top-color: var(--cp-blue); animation: cp-spin 0.8s linear infinite; flex: 0 0 auto; }
@keyframes cp-spin { to { transform: rotate(360deg); } }
/* Installation de l'application (PWA) */
.cp-install { display: flex; align-items: center; gap: 12px; background: var(--cp-yellow-soft); border-color: var(--cp-yellow); }
@media (min-width: 900px) { body.cp-app .cp-install { grid-column: 1 / -1; } }
.cp-push-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--cp-border-soft); }
.cp-push-row:last-child { border-bottom: 0; }
.cp-switch { position: relative; width: 46px; height: 28px; border-radius: 14px; background: var(--cp-border); border: 0; cursor: pointer; flex: 0 0 auto; transition: background .15s; }
.cp-switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: left .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.cp-switch.is-on { background: var(--cp-blue); }
.cp-switch.is-on::after { left: 21px; }
.cp-switch:disabled { opacity: .5; cursor: default; }
