/* ==========================================================================
   Composants réutilisables
   ========================================================================== */

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  height: var(--control-h); padding: 0 14px; border-radius: var(--r-md);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font-weight: var(--fw-medium); font-size: 13.5px; white-space: nowrap; text-decoration: none;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: #F4F6F9; color: var(--text); }
.btn-primary { background: var(--action-600); border-color: var(--action-600); color: #fff; }
.btn-primary:hover { background: var(--action-700); color: #fff; }
.btn-dark { background: var(--brand-900); border-color: var(--brand-900); color: #fff; }
.btn-dark:hover { background: var(--brand-700); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-3); }
.btn-danger { color: var(--danger-fg); border-color: #F1C4C0; }
.btn-danger:hover { background: #FEF3F2; color: var(--danger-fg); }
.btn-danger-solid { background: var(--danger-solid); border-color: var(--danger-solid); color: #fff; }
.btn-danger-solid:hover { background: #A72C26; color: #fff; }
.btn-sm { height: var(--control-h-sm); padding: 0 10px; font-size: 13px; }
.btn-touch { height: var(--control-h-touch); font-size: 15px; border-radius: var(--r-xl); padding: 0 18px; }
.btn-block { width: 100%; }
.btn-icon { width: 36px; height: 36px; padding: 0; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn.is-loading { pointer-events: none; opacity: .8; }
.spinner { width: 15px; height: 15px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.link { border: 0; background: none; padding: 0; color: var(--link); font-weight: var(--fw-medium); font-size: 13px; text-align: left; }
.link:hover { text-decoration: underline; }

/* ---------- Badges, étiquettes ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 9px;
  border-radius: var(--r-full); font-size: var(--fs-sm); font-weight: 560; white-space: nowrap; justify-self: start;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.b-neutral { background: var(--neutral-bg); color: var(--neutral-fg); }
.b-info { background: var(--info-bg); color: var(--info-fg); }
.b-success { background: var(--success-bg); color: var(--success-fg); }
.b-warning { background: var(--warning-bg); color: var(--warning-fg); }
.b-danger { background: var(--danger-bg); color: var(--danger-fg); }
.tag {
  display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 8px; border-radius: var(--r-sm);
  font-size: 12px; font-weight: 560; background: #F3F5F8; color: var(--text-2); border: 1px solid var(--border); white-space: nowrap; justify-self: start;
}
.demo {
  display: inline-flex; align-items: center; height: 20px; padding: 0 7px; border: 1px dashed #8D99A8; border-radius: var(--r-xs);
  font-size: 11px; font-weight: 650; letter-spacing: .04em; text-transform: uppercase; color: var(--neutral-fg); background: #fff; white-space: nowrap;
}
.soon { margin-left: auto; font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: var(--r-full); background: var(--neutral-bg); color: #556070; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: #E3EBF7; color: var(--brand-900); font-weight: 650; font-size: 12px; display: grid; place-items: center; flex: none; }
.avatar-lg { width: 52px; height: 52px; font-size: 17px; border-radius: var(--r-xl); }

/* ---------- Panneaux ---------- */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-1); min-width: 0; }
.panel-h { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: 14px 18px; border-bottom: 1px solid var(--border-soft); flex-wrap: wrap; }
.panel-h h2, .panel-h h3 { font-size: var(--fs-md); font-weight: var(--fw-semibold); color: #14202E; }
.panel-sub { font-size: var(--fs-sm); color: var(--text-muted); margin-top: 2px; }
.panel-b { padding: 16px 18px; }
.panel-f { padding: 10px 18px; border-top: 1px solid var(--border-soft); font-size: var(--fs-sm); color: var(--text-muted); display: flex; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap; }

/* ---------- Indicateurs ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-1); overflow: hidden; }
.kpi { padding: 16px 20px 15px; border-right: 1px solid var(--border-soft); display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.kpi:last-child { border-right: 0; }
.kpi-l { font-size: 13px; color: var(--neutral-fg); font-weight: var(--fw-medium); display: flex; gap: 6px; align-items: center; }
.kpi-v { font-size: var(--fs-kpi); font-weight: var(--fw-bold); letter-spacing: -.02em; font-variant-numeric: tabular-nums; color: var(--brand-900); line-height: 1.2; }
.kpi-s { font-size: var(--fs-sm); color: var(--text-muted); }
.kpi-s.warn { color: var(--warning-fg); font-weight: var(--fw-medium); }

/* ---------- Contrôle segmenté, puces ---------- */
.seg { display: inline-flex; flex-wrap: wrap; background: #EAEEF3; border-radius: var(--r-md); padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 0 12px; height: 32px; border-radius: var(--r-sm); font-size: 13px; font-weight: var(--fw-medium); color: var(--text-2); }
.seg button[aria-pressed="true"] { background: #fff; color: var(--brand-900); box-shadow: 0 1px 2px rgba(16, 24, 40, .1); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { height: 30px; padding: 0 10px; border: 1px solid #DCE1E8; border-radius: var(--r-full); background: #fff; font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--text-2); display: inline-flex; align-items: center; gap: 6px; }
.chip b { font-weight: 650; color: var(--brand-900); }
.chip[aria-pressed="true"] { background: var(--brand-900); border-color: var(--brand-900); color: #fff; }
.chip[aria-pressed="true"] b { color: #fff; }

/* ---------- Tableaux (grilles accessibles) ---------- */
.table-wrap { overflow-x: auto; }
.table { min-width: 820px; }
.table.sm { min-width: 560px; }
.thr, .tr { display: grid; align-items: center; column-gap: 14px; padding: 0 18px; }
.thr { height: 38px; background: var(--surface-2); border-bottom: 1px solid var(--border); font-size: 12px; font-weight: 600; color: var(--text-muted); white-space: nowrap; }
.tr { width: 100%; border: 0; border-bottom: 1px solid var(--border-soft); background: #fff; text-align: left; min-height: 52px; padding-top: 8px; padding-bottom: 8px; font-size: 13.5px; }
a.tr, button.tr { cursor: pointer; color: inherit; text-decoration: none; }
a.tr:hover, button.tr:hover { background: #F7F9FC; color: inherit; }
.tr:last-child { border-bottom: 0; }
.cell { display: flex; flex-direction: column; min-width: 0; }
.ref { font-variant-numeric: tabular-nums; font-weight: 620; color: var(--brand-900); white-space: nowrap; }

/* ---------- Listes ---------- */
.li { display: flex; align-items: center; gap: var(--sp-3); padding: 11px 18px; border: 0; border-bottom: 1px solid var(--border-soft); background: #fff; width: 100%; text-align: left; color: inherit; text-decoration: none; }
a.li:hover, button.li:hover { background: #F7F9FC; color: inherit; }
.li:last-child { border-bottom: 0; }
.li-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.li-t { font-weight: 580; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.li-s { font-size: var(--fs-sm); color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ic { width: 34px; height: 34px; border-radius: var(--r-md); background: var(--surface-3); color: var(--text-2); display: grid; place-items: center; flex: none; }
.when { width: 78px; flex: none; display: flex; flex-direction: column; }
.when b { font-size: var(--fs-sm); font-weight: 650; color: var(--brand-900); }
.when span { font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.dl { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 10px 16px; font-size: 13.5px; margin: 0; }
.dl dt { color: var(--text-muted); }
.dl dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.timeline { display: flex; flex-direction: column; }
.timeline-it { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border-soft); font-size: var(--fs-sm); }
.timeline-it:last-child { border-bottom: 0; }
.timeline-d { width: 92px; flex: none; color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* ---------- Onglets ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); overflow-x: auto; padding: 0 18px; }
.tabs [role="tab"] { border: 0; background: none; padding: 12px 12px 11px; font-weight: 560; color: var(--text-muted); border-bottom: 2px solid transparent; white-space: nowrap; display: inline-flex; gap: 6px; align-items: center; }
.tabs [role="tab"]:hover { color: var(--text); }
.tabs [role="tab"][aria-selected="true"] { color: #1450C8; border-bottom-color: var(--action-600); }
.tab-count { font-size: var(--fs-xs); font-weight: 650; background: var(--neutral-bg); color: var(--neutral-fg); border-radius: var(--r-full); padding: 1px 7px; }

/* ---------- Formulaires ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.label { font-size: 13px; font-weight: 560; color: #2F3A47; }
.req { color: var(--danger-fg); }
.input { height: 40px; border: 1px solid var(--border-strong); border-radius: var(--r-md); padding: 0 12px; background: #fff; width: 100%; min-width: 0; outline: 0; }
textarea.input { height: auto; min-height: 76px; padding: 9px 12px; resize: vertical; line-height: 1.45; }
select.input { padding-right: 8px; }
.input:focus { border-color: var(--action-600); box-shadow: var(--focus-ring); }
.input[aria-invalid="true"] { border-color: #D92D20; background: #FFFBFA; }
.input[readonly] { background: #F6F8FA; color: var(--text-2); }
.input-sm { height: 36px; padding: 0 10px; }
.field-error { font-size: var(--fs-sm); color: var(--danger-fg); font-weight: 500; }
.hint { font-size: var(--fs-sm); color: var(--text-muted); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px 16px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--border-soft); }
.toolbar select.input { width: auto; height: 36px; padding: 0 10px; }
.search { display: flex; align-items: center; gap: 8px; height: 38px; padding: 0 12px; border: 1px solid #DCE1E8; border-radius: var(--r-md); background: var(--surface-2); color: var(--text-muted); width: 300px; max-width: 100%; }
.toolbar .search { width: 250px; height: 36px; background: #fff; }
.search input { border: 0; outline: 0; background: transparent; flex: 1; min-width: 0; color: var(--text); }
.search:focus-within { border-color: var(--action-600); box-shadow: var(--focus-ring); background: #fff; }
.checkbox { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; }

/* ---------- Messages ---------- */
.banner { display: flex; gap: 12px; align-items: flex-start; padding: 12px 16px; border-radius: 9px; border: 1px solid; font-size: 13.5px; }
.banner .i { margin-top: 1px; }
.banner-info { background: #F0F5FF; border-color: var(--info-border); color: #1D3F8A; }
.banner-warning { background: #FFF7ED; border-color: var(--warning-border); color: #7A3E06; }
.banner-danger { background: #FEF3F2; border-color: var(--danger-border); color: #912018; }
.banner-success { background: #ECF7F0; border-color: var(--success-border); color: #14583A; }
.banner-demo { background: var(--surface-2); border-color: #CBD3DD; border-style: dashed; color: var(--text-2); }

/* ---------- États ---------- */
.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; padding: 44px 24px; }
.empty .ic { width: 46px; height: 46px; border-radius: var(--r-xl); margin-bottom: 4px; }
.empty h2, .empty h3 { font-size: 15.5px; font-weight: var(--fw-semibold); }
.empty p { max-width: 460px; color: var(--text-muted); font-size: 13.5px; }
.skeleton { height: 11px; border-radius: 6px; background: linear-gradient(90deg, #ECEFF3, #F5F7FA, #ECEFF3); background-size: 200% 100%; animation: shimmer 1.2s infinite linear; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- Menus ---------- */
.menu-wrap { position: relative; }
.menu { position: absolute; top: calc(100% + 6px); right: 0; min-width: 230px; background: #fff; border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-menu); padding: 6px; z-index: 40; }
.menu.left { left: 0; right: auto; }
.menu[hidden] { display: none; }
.menu [role="menuitem"], .menu .menu-item { display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: none; padding: 0 10px; height: 38px; border-radius: var(--r-sm); text-align: left; font-size: 13.5px; color: var(--text); text-decoration: none; }
.menu [role="menuitem"]:hover, .menu [role="menuitem"]:focus { background: #F3F6FA; outline: 0; }
.menu .menu-sep { height: 1px; background: var(--border-soft); margin: 6px 4px; }
.menu .menu-title { font-size: 11px; color: var(--text-faint); padding: 6px 10px 4px; font-weight: 650; text-transform: uppercase; letter-spacing: .06em; }
.menu .danger { color: var(--danger-fg); }
.menu-scroll { max-height: 280px; overflow-y: auto; }

/* ---------- Modales ---------- */
.overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px 24px; z-index: 50; overflow-y: auto; }
.modal { background: #fff; border-radius: var(--r-xl); width: 580px; max-width: 100%; box-shadow: var(--shadow-modal); }
.modal.lg { width: min(920px, 100%); }
.modal.lg .modal-b { max-height: min(70vh, 720px); overflow: auto; }
.invoice-line { border: 1px solid var(--border); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.missing-list { margin: 0; padding-left: 1.1rem; display: flex; flex-direction: column; gap: 8px; }
.modal.sm { width: 460px; }
.modal-h { padding: 20px 22px 4px; display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.modal-h h2 { font-size: var(--fs-lg); font-weight: 660; color: #14202E; }
.modal-b { padding: 12px 22px 8px; display: flex; flex-direction: column; gap: 14px; }
.modal-f { padding: 16px 22px 20px; display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ---------- Notifications ---------- */
.toasts { position: fixed; right: 24px; bottom: 24px; z-index: 70; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.toast { background: var(--brand-900); color: #fff; border-radius: var(--r-lg); padding: 12px 16px; display: flex; gap: 10px; align-items: center; box-shadow: 0 12px 32px rgba(15, 23, 42, .3); max-width: 440px; font-size: 13.5px; }
.toast .i { color: #7FD4A6; }
.toast.error { background: #7A1A12; }
.toast.error .i { color: #FFB4AB; }

/* ---------- Divers ---------- */
.bar { height: 6px; background: #E3E8EF; border-radius: var(--r-full); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--action-600); border-radius: var(--r-full); }
.bar.full > i { background: var(--warning-fg); }
.swatch { width: 34px; height: 34px; border-radius: var(--r-md); border: 2px solid #fff; box-shadow: 0 0 0 1px var(--border-strong); }
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--brand-900); }
.dropzone { border: 1.5px dashed #B7C3D3; border-radius: var(--r-lg); padding: 22px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px; background: var(--surface-2); }
.next-box { display: flex; gap: 14px; align-items: flex-start; padding: 16px 18px; background: #F4F8FF; border: 1px solid #CFE0FC; border-radius: var(--r-lg); flex-wrap: wrap; }
.next-box.warn { background: #FFF9F0; border-color: #F3D9B5; }
.next-box .ic { background: #fff; border: 1px solid #CFE0FC; color: var(--info-fg); }
.perm-y { color: var(--success-fg); font-weight: 600; font-size: var(--fs-sm); }
.perm-r { color: var(--info-fg); font-weight: 550; font-size: var(--fs-sm); }
.perm-n { color: #6B7684; font-size: var(--fs-sm); }
