/**
 * Dev by Franck MARIE
 *
 * Feuille de styles du dashboard : variables CSS, thèmes clair/sombre,
 * sidebar, cartes KPI, bandeau objectif, graphiques, tableaux, import,
 * footer, responsive et barre « retour en haut ».
 */
:root {
  --ui-scale: 0.72;
  color-scheme: light;
  --bg: #f0f2f7;
  --surface: #ffffff;
  --sidebar: #0f172a;
  --sidebar-text: #94a3b8;
  --sidebar-active: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --accent-border: #93c5fd;
  --success: #059669;
  --success-soft: #d1fae5;
  --warning: #d97706;
  --warning-soft: #fef3c7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --shadow: 0 1px 3px rgb(15 23 42 / 8%), 0 8px 24px rgb(15 23 42 / 6%);
  --radius: calc(14px * var(--ui-scale));
  --sidebar-width: calc(240px * var(--ui-scale));
  --sidebar-width-md: calc(220px * var(--ui-scale));
  --chart-height: calc(260px * var(--ui-scale));
  --chart-height-tall: calc(320px * var(--ui-scale));
  --chart-height-sm: calc(240px * var(--ui-scale));
  --chart-height-tall-sm: calc(280px * var(--ui-scale));
  --row-hover: #f8fafc;
  --row-current-month: #fffbeb;
  --row-current-month-hover: #fef3c7;
  --progress-track: #e2e8f0;
  --chart-grid: #e2e8f0;
  --chart-text: #64748b;
  --credit-accent: linear-gradient(180deg, #3b82f6 0%, #10b981 100%);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1120;
  --surface: #151d2e;
  --sidebar: #070b14;
  --sidebar-text: #94a3b8;
  --sidebar-active: #f1f5f9;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --border: #243044;
  --accent: #3b82f6;
  --accent-soft: #1e3a5f;
  --accent-border: #2563eb;
  --success: #10b981;
  --success-soft: rgb(16 185 129 / 15%);
  --warning: #f59e0b;
  --warning-soft: rgb(245 158 11 / 15%);
  --danger: #ef4444;
  --danger-soft: rgb(239 68 68 / 15%);
  --shadow: 0 1px 3px rgb(0 0 0 / 35%), 0 8px 24px rgb(0 0 0 / 25%);
  --row-hover: #1a2438;
  --row-current-month: rgb(245 158 11 / 12%);
  --row-current-month-hover: rgb(245 158 11 / 20%);
  --progress-track: #243044;
  --chart-grid: #334155;
  --chart-text: #94a3b8;
  --credit-accent: linear-gradient(180deg, #60a5fa 0%, #34d399 100%);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: calc(16px * var(--ui-scale));
}

body {
  margin: 0;
  font-family: "DM Sans", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  overflow-x: hidden;
}

.app {
  display: grid;
  grid-template-columns: minmax(0, var(--sidebar-width)) minmax(0, 1fr);
  min-height: 100vh;
  min-height: 100dvh;
}

.sidebar {
  background: var(--sidebar);
  color: var(--sidebar-text);
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  align-content: flex-start;
  min-width: 0;
  overflow-y: auto;
}

.sidebar-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: calc(10px * var(--ui-scale));
  padding: 0.55rem 0.85rem;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow);
  flex-shrink: 0;
}

.sidebar-toggle__icon {
  width: 1.1rem;
  height: 1.1rem;
  display: grid;
  place-items: center;
}

.sidebar-backdrop {
  display: none;
}

.back-to-top {
  position: fixed;
  right: max(1.25rem, env(safe-area-inset-right));
  bottom: max(1.25rem, env(safe-area-inset-bottom));
  z-index: 85;
  width: 2.75rem;
  height: 2.75rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  display: grid;
  place-items: center;
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transform: translateY(0.75rem) scale(0.92);
  transition:
    opacity 0.2s ease,
    visibility 0.2s ease,
    transform 0.2s ease,
    background 0.15s ease,
    color 0.15s ease;
}

.back-to-top svg {
  width: 1.15rem;
  height: 1.15rem;
}

.back-to-top:hover {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}

.back-to-top:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.back-to-top.is-visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

@media (prefers-reduced-motion: reduce) {
  .back-to-top {
    transition: opacity 0.2s ease, visibility 0.2s ease;
  }

  .objective-banner__inner,
  .objective-banner__pct,
  .objective-banner__legend,
  .objective-banner__footer {
    animation: none !important;
  }

  .objective-banner__inner.is-entering .objective-progress__bar {
    transition: width 0.2s ease;
  }

  .kpi-card.kpi-card--enter {
    animation: none !important;
  }
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 0.5rem;
}

.brand-icon {
  width: calc(42px * var(--ui-scale));
  height: calc(42px * var(--ui-scale));
  border-radius: calc(12px * var(--ui-scale));
  flex-shrink: 0;
  display: block;
  object-fit: contain;
}

.brand h1 {
  margin: 0;
  font-size: 1rem;
  color: var(--sidebar-active);
  font-weight: 600;
}

.brand p {
  margin: 0;
  font-size: 0.78rem;
}

.year-nav {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding-top: 0.4rem;
  margin-top: -0.75rem;
}

.year-btn {
  border: none;
  background: transparent;
  color: var(--sidebar-text);
  text-align: left;
  padding: 0.65rem 0.85rem;
  border-radius: calc(10px * var(--ui-scale));
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.year-btn:hover {
  background: rgb(255 255 255 / 8%);
  color: var(--sidebar-active);
}

.year-btn.active {
  background: rgb(37 99 235 / 25%);
  color: #93c5fd;
  font-weight: 600;
}

.extra-nav {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding-top: 0.4rem;
  margin-top: -0.15rem;
  border-top: 1px solid rgb(255 255 255 / 10%);
}

.nav-btn {
  border: none;
  background: transparent;
  color: var(--sidebar-text);
  text-align: left;
  padding: 0.65rem 0.85rem;
  border-radius: calc(10px * var(--ui-scale));
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.nav-btn:hover {
  background: rgb(255 255 255 / 8%);
  color: var(--sidebar-active);
}

.nav-btn.active {
  background: rgb(217 119 6 / 22%);
  color: #fcd34d;
  font-weight: 600;
}

.import-panel:not(.hidden) {
  padding-top: 0.75rem;
  padding-bottom: 0.2rem;
  margin-top: -0.75rem;
  border-top: 1px solid rgb(255 255 255 / 10%);
}

.import-panel {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.import-panel__title {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--sidebar-active);
}

.import-panel__hint {
  margin: 0;
  font-size: 0.72rem;
  line-height: 1.4;
  opacity: 0.85;
}

.import-panel__actions {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.import-btn {
  border: none;
  border-radius: calc(10px * var(--ui-scale));
  padding: 0.55rem 0.75rem;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  background: #2563eb;
  color: #fff;
  transition: background 0.15s, opacity 0.15s;
}

.import-btn:hover:not(:disabled) {
  background: #1d4ed8;
}

.import-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.import-btn--ghost {
  background: rgb(255 255 255 / 8%);
  color: var(--sidebar-active);
}

.import-btn--ghost:hover:not(:disabled) {
  background: rgb(255 255 255 / 14%);
}

.import-panel__filename {
  margin: 0;
  font-size: 0.72rem;
  color: #cbd5e1;
  word-break: break-all;
  min-height: 0;
}

.import-panel__filename:empty {
  display: none;
}

.import-status {
  margin: 0;
  font-size: 0.72rem;
  line-height: 1.4;
}

.import-status--success {
  color: #86efac;
}

.import-status--error {
  color: #fca5a5;
}

.import-status--pending {
  color: #fcd34d;
}

.sidebar-credit {
  padding: 0.55rem 0.5rem 1rem;
  margin-top: 0.15rem;
  margin-bottom: 0;
  border-bottom: 1px solid rgb(255 255 255 / 10%);
  align-self: stretch;
  width: 100%;
}

.sidebar-credit__body {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.16rem;
  padding-left: calc(0.5rem + 2px);
  max-width: 100%;
  width: fit-content;
}

.sidebar-credit__accent {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  width: 2px;
  border-radius: 999px;
  background: var(--credit-accent);
  opacity: 0.9;
}

.sidebar-credit__label {
  font-size: 0.6rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--sidebar-text);
  opacity: 0.65;
  line-height: 1;
}

.sidebar-credit__name {
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--sidebar-active);
  letter-spacing: 0.04em;
  line-height: 1;
}

.sidebar-footer {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  align-items: flex-start;
  width: 100%;
  margin-top: -0.75rem;
  padding-top: 0.45rem;
  border-top: 1px solid rgb(255 255 255 / 10%);
}

.import-panel:not(.hidden) + .sidebar-footer {
  margin-top: -0.35rem;
  padding-top: 0.3rem;
}

.sidebar-update {
  margin: 0;
  padding: 0 0.5rem;
  font-size: 0.72rem;
  line-height: 1.45;
  color: var(--sidebar-text);
  opacity: 0.8;
  text-align: left;
  width: 100%;
}

.main {
  display: flex;
  flex-direction: column;
  padding: 1.75rem 2rem 1.75rem;
  overflow-x: hidden;
  min-width: 0;
  min-height: 100vh;
  min-height: 100dvh;
}

.site-footer {
  margin-top: max(2.75rem, auto);
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: center;
}

.site-footer__credit {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
  width: fit-content;
  text-align: left;
}

.site-footer__copy {
  display: inline-flex;
  align-items: baseline;
  gap: 0.35rem;
}

.site-footer__accent {
  width: 2px;
  height: 1.05rem;
  border-radius: 999px;
  background: var(--credit-accent);
  opacity: 0.9;
  flex-shrink: 0;
}

.site-footer__label {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
  line-height: 1;
}

.site-footer__name {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.04em;
  line-height: 1;
}

.page-header__top {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  flex: 1;
  min-width: 0;
}

.page-header__intro {
  min-width: 0;
  flex: 1;
}

.page-header {
  margin-bottom: 1.75rem;
  display: flex;
  flex-wrap: nowrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
}

.page-header__right {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: flex-end;
  justify-content: flex-end;
  gap: 0.75rem;
  flex-shrink: 0;
  margin-left: auto;
}

.theme-switch {
  display: inline-flex;
  gap: 0.15rem;
  padding: 0.2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow);
}

.theme-switch__btn {
  border: none;
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  width: 2rem;
  height: 2rem;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.theme-switch__btn svg {
  width: 0.95rem;
  height: 0.95rem;
}

.theme-switch__btn:hover {
  color: var(--text);
  background: var(--row-hover);
}

.theme-switch__btn.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.page-header h2 {
  margin: 0 0 0.25rem;
  font-size: clamp(1.25rem, 2.5vw, 1.65rem);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.filters {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.75rem 1rem;
  align-items: flex-end;
}

.filters label {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.filter-select {
  border: 1px solid var(--border);
  border-radius: calc(10px * var(--ui-scale));
  padding: 0.55rem 0.75rem;
  font: inherit;
  font-size: 0.9rem;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  min-width: 11rem;
  max-width: 100%;
}

.chart-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.chart-card-header h3 {
  margin: 0;
}

.metric-toggle {
  display: flex;
  gap: 0.35rem;
}

.metric-toggle button {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  border-radius: 999px;
  padding: 0.3rem 0.65rem;
  font: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
}

.metric-toggle button.active {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: var(--accent);
}

.loading,
.error {
  padding: 2rem;
  text-align: center;
  color: var(--muted);
}

.error {
  color: var(--danger);
  background: var(--danger-soft);
  border-radius: var(--radius);
}

.hidden {
  display: none !important;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem;
  margin-bottom: 1rem;
  align-items: stretch;
}

@media (min-width: 961px) {
  .kpi-grid {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 11rem), 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
  }
}

.kpi-card,
.global-ca-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 0.75rem 0.65rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.kpi-card {
  border-left: calc(4px * var(--ui-scale)) solid var(--border);
}

.global-ca-card {
  border-top: calc(4px * var(--ui-scale)) solid var(--border);
}

@media (min-width: 961px) {
  .kpi-card,
  .global-ca-card {
    padding: 1.15rem 1.25rem;
    min-height: 8.5rem;
  }
}

.kpi-card .label,
.global-ca-card .label {
  font-size: 0.65rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-weight: 600;
  line-height: 1.2;
  white-space: pre-line;
  height: auto;
  min-height: 2.35em;
  max-height: 2.5em;
  overflow: hidden;
  flex-shrink: 0;
}

@media (min-width: 961px) {
  .kpi-card .label,
  .global-ca-card .label {
    font-size: 0.78rem;
    letter-spacing: 0.04em;
    line-height: 1.25;
    height: 2.5em;
    min-height: 0;
    max-height: none;
  }
}

.kpi-card .value,
.global-ca-card .value {
  font-size: clamp(1rem, 4.2vw, 1.25rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.1;
  overflow-wrap: anywhere;
  margin: 0.3rem 0;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

@media (min-width: 961px) {
  .kpi-card .value,
  .global-ca-card .value {
    font-size: clamp(1.35rem, 4vw, 1.75rem);
    margin: 0.45rem 0;
  }
}

.kpi-card .detail,
.global-ca-card .detail {
  font-size: 0.68rem;
  color: var(--muted);
  line-height: 1.25;
  white-space: pre-line;
  height: auto;
  min-height: 2.1em;
  max-height: 2.5em;
  overflow: hidden;
  margin-top: auto;
  flex-shrink: 0;
}

@media (min-width: 961px) {
  .kpi-card .detail,
  .global-ca-card .detail {
    font-size: 0.82rem;
    line-height: 1.3;
    height: 2.6em;
    min-height: 0;
    max-height: none;
  }
}

.kpi-card.kpi-card--enter {
  animation: kpi-card-enter 0.55s cubic-bezier(0.22, 1, 0.36, 1) both;
  animation-delay: var(--kpi-enter-delay, 0s);
}

@keyframes kpi-card-enter {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.kpi-card.accent { border-left: calc(4px * var(--ui-scale)) solid var(--accent); }
.kpi-card.success { border-left: calc(4px * var(--ui-scale)) solid var(--success); }
.kpi-card.warning { border-left: calc(4px * var(--ui-scale)) solid var(--warning); }
.kpi-card.danger { border-left: calc(4px * var(--ui-scale)) solid var(--danger); }

.objective-banner {
  margin-bottom: 1.5rem;
}

.objective-banner__inner {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  border-left: calc(4px * var(--ui-scale)) solid var(--warning);
}

.objective-banner:not(.hidden) .objective-banner__inner.is-entering {
  animation: objective-banner-enter 0.65s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.objective-banner:not(.hidden) .objective-banner__inner.is-entering .objective-banner__pct {
  animation: objective-pct-pop 0.55s cubic-bezier(0.22, 1, 0.36, 1) 0.2s both;
}

.objective-banner:not(.hidden) .objective-banner__inner.is-entering .objective-banner__legend,
.objective-banner:not(.hidden) .objective-banner__inner.is-entering .objective-banner__footer {
  animation: objective-fade-up 0.5s ease 0.12s both;
}

@keyframes objective-banner-enter {
  from {
    opacity: 0;
    transform: translateY(-14px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes objective-pct-pop {
  from {
    opacity: 0;
    transform: scale(0.82);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes objective-fade-up {
  from {
    opacity: 0;
    transform: translateY(6px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.objective-banner__inner.accent {
  border-left-color: var(--accent);
}

.objective-banner__inner.success {
  border-left-color: var(--success);
}

.objective-banner__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.85rem;
}

.objective-banner__title {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.objective-banner__sep {
  margin: 0 0.35rem;
  color: var(--muted);
}

.objective-banner__pct {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--accent);
  line-height: 1;
}

.objective-banner__inner.success .objective-banner__pct {
  color: var(--success);
}

.objective-progress {
  height: calc(10px * var(--ui-scale));
  background: var(--progress-track);
  border-radius: 999px;
  overflow: hidden;
}

.objective-progress__track {
  display: flex;
  height: 100%;
  width: 100%;
}

.objective-progress__bar {
  height: 100%;
  flex-shrink: 0;
  width: 0;
  transition: width 0.35s ease;
}

.objective-banner__inner.is-entering .objective-progress__bar {
  transition: width 1s cubic-bezier(0.22, 1, 0.36, 1);
}

.objective-progress__bar--achieved {
  background: linear-gradient(90deg, #2563eb, #3b82f6);
}

.objective-progress__bar--month {
  background: linear-gradient(90deg, #d97706, #fbbf24);
}

.objective-banner__legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  align-items: center;
  font-size: 0.95rem;
  color: var(--text);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.legend-item::before {
  content: "";
  width: calc(10px * var(--ui-scale));
  height: calc(10px * var(--ui-scale));
  border-radius: calc(3px * var(--ui-scale));
  flex-shrink: 0;
}

.legend-item--achieved::before {
  background: #2563eb;
}

.legend-item--month::before {
  background: #d97706;
}

.objective-banner__inner.success .objective-progress__bar--achieved {
  background: linear-gradient(90deg, #059669, #10b981);
}

.objective-banner__footer {
  margin-top: 0.65rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.objective-banner__done {
  color: var(--success);
  font-weight: 600;
}

.charts-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 22rem), 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.global-summary {
  margin-bottom: 1rem;
}

.global-summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem;
  align-items: stretch;
}

@media (min-width: 961px) {
  .global-summary-grid {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr));
    gap: 1rem;
  }
}

.global-ca-card.accent { border-top-color: var(--accent); }
.global-ca-card.success { border-top-color: var(--success); }
.global-ca-card.warning { border-top-color: var(--warning); }
.global-ca-card.danger { border-top-color: var(--danger); }

.global-ca-card.total {
  grid-column: span 1;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.chart-card h3,
.table-card h3 {
  margin: 0 0 1rem;
  font-size: 0.95rem;
  font-weight: 600;
}

.chart-card--wide {
  grid-column: 1 / -1;
}

.chart-wrap {
  position: relative;
  height: var(--chart-height);
}

.chart-wrap--tall {
  height: var(--chart-height-tall);
}

.table-card {
  margin-top: 0.5rem;
}

.audit-panel {
  margin-top: 0.5rem;
}

.audit-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.35rem;
}

.audit-panel__header h3 {
  margin: 0;
}

.audit-panel__hint {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.88rem;
}

.audit-panel__status {
  margin: 0 0 0.75rem;
  color: var(--muted);
  font-size: 0.88rem;
}

.audit-panel__empty {
  margin: 1rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.audit-table td:nth-child(1) {
  white-space: nowrap;
}

.audit-table td:nth-child(5) {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82rem;
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  min-width: 36rem;
  border-collapse: collapse;
  font-size: 0.88rem;
}

th,
td {
  padding: 0.65rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

th.sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

th.sortable:hover {
  color: var(--accent);
}

th.sort-asc::after,
th.sort-desc::after {
  display: inline-block;
  margin-left: 0.35em;
  font-size: 0.65rem;
  opacity: 0.85;
}

th.sort-asc::after {
  content: "\25B2";
}

th.sort-desc::after {
  content: "\25BC";
}

tbody tr:hover {
  background: var(--row-hover);
}

tbody tr.row--current-month {
  background: var(--row-current-month);
}

tbody tr.row--current-month:hover {
  background: var(--row-current-month-hover);
}

@keyframes backlog-etat-blink {
  0%, 100% {
    background-color: rgb(239 68 68 / 14%);
  }

  50% {
    background-color: rgb(239 68 68 / 32%);
  }
}

tbody tr.row--etat-alert {
  animation: backlog-etat-blink 1.4s ease-in-out infinite;
}

tbody tr.row--etat-alert:hover {
  animation: backlog-etat-blink 1.4s ease-in-out infinite;
}

td.backlog-etat--alert {
  color: #ef4444;
  font-weight: 700;
}

tbody tr.row--etat-facturer {
  background-color: rgb(16 185 129 / 16%);
}

tbody tr.row--etat-facturer:hover {
  background-color: rgb(16 185 129 / 24%);
}

td.backlog-etat--facturer {
  color: var(--success);
  font-weight: 700;
}

@media (prefers-reduced-motion: reduce) {
  tbody tr.row--etat-alert {
    animation: none;
    background-color: rgb(239 68 68 / 20%);
  }

  tbody tr.row--etat-alert:hover {
    background-color: rgb(239 68 68 / 26%);
  }
}

td.num {
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

@media (max-width: 1280px) {
  .app {
    grid-template-columns: minmax(0, var(--sidebar-width-md)) minmax(0, 1fr);
  }

  .main {
    padding: 1.5rem 1.25rem 1.5rem;
  }
}

@media (max-width: 1024px) {
  .charts-row {
    grid-template-columns: 1fr;
  }

  .objective-banner__legend {
    font-size: 0.88rem;
  }
}

@media (max-width: 960px) {
  .app {
    grid-template-columns: minmax(0, 1fr);
  }

  .sidebar-toggle {
    display: inline-flex;
  }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgb(0 0 0 / 50%);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
    z-index: 90;
    border: none;
    padding: 0;
    cursor: pointer;
  }

  body.sidebar-open .sidebar-backdrop {
    opacity: 1;
    visibility: visible;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(88vw, 18rem);
    max-width: 100%;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 0 0 40px rgb(0 0 0 / 35%);
    padding-top: max(1.5rem, env(safe-area-inset-top));
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
  }

  body.sidebar-open {
    overflow: hidden;
  }

  .main {
    padding: 1rem 1rem 1.25rem;
    padding-top: max(1rem, env(safe-area-inset-top));
  }

  .page-header {
    flex-direction: column;
    flex-wrap: wrap;
    align-items: stretch;
  }

  .page-header__top {
    width: 100%;
  }

  .page-header__right {
    width: 100%;
    margin-left: 0;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: flex-end;
  }
}

@media (max-width: 640px) {
  .page-header__top {
    align-items: center;
  }

  .filters {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-select {
    width: 100%;
    min-width: 0;
  }

  .objective-banner__inner {
    padding: 1rem 1.1rem;
  }

  .objective-banner__header {
    flex-direction: column;
    align-items: flex-start;
  }

  .objective-banner__pct {
    font-size: 1.45rem;
  }

  .card {
    padding: 1rem;
  }

  .chart-wrap {
    height: min(52vw, var(--chart-height-sm));
  }

  .chart-wrap--tall {
    height: min(68vw, var(--chart-height-tall-sm));
  }

  table {
    min-width: 32rem;
    font-size: 0.82rem;
  }

  th,
  td {
    padding: 0.55rem 0.5rem;
  }
}

@media (max-width: 480px) {
  .main {
    padding: 0.85rem 0.85rem 1rem;
  }

  .kpi-grid,
  .global-summary-grid {
    gap: 0.5rem;
  }

  .kpi-card,
  .global-ca-card {
    padding: 0.6rem 0.5rem;
    border-radius: calc(var(--radius) * 0.85);
  }

  .kpi-card .label,
  .global-ca-card .label {
    font-size: 0.62rem;
    min-height: 2.2em;
  }

  .kpi-card .value,
  .global-ca-card .value {
    font-size: clamp(0.9rem, 4.5vw, 1.1rem);
    margin: 0.2rem 0;
  }

  .kpi-card .detail,
  .global-ca-card .detail {
    font-size: 0.64rem;
    min-height: 1.95em;
  }

  #sidebarToggleLabel {
    display: none;
  }

  .subtitle {
    font-size: 0.88rem;
  }

  .metric-toggle {
    flex-wrap: wrap;
  }

  .import-panel__actions {
    flex-direction: column;
  }

  table {
    min-width: 28rem;
    font-size: 0.78rem;
  }
}

/* Téléphone en mode « site bureau » : viewport > 960 px mais écran tactile */
@media (hover: none) and (pointer: coarse) and (min-width: 961px) and (max-width: 1280px) {
  .kpi-grid,
  .global-summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.65rem;
    margin-bottom: 1rem;
  }

  .kpi-card,
  .global-ca-card {
    padding: 0.75rem 0.65rem;
    min-height: 0;
  }
}

@media (min-width: 961px) {
  body.sidebar-open .sidebar {
    transform: none;
  }
}

.login-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background:
    radial-gradient(circle at top, rgb(37 99 235 / 12%), transparent 55%),
    var(--bg);
}

.login-card__credit {
  display: flex;
  justify-content: center;
  margin-top: 0.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

.login-card__credit-body {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.16rem;
  padding-left: calc(0.5rem + 2px);
  width: fit-content;
}

.login-card__credit-accent {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  width: 2px;
  border-radius: 999px;
  background: var(--credit-accent);
  opacity: 0.9;
}

.login-card__credit-label {
  font-size: 0.6rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--muted);
  opacity: 0.65;
  line-height: 1;
}

.login-card__credit-name {
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.04em;
  line-height: 1;
}

.login-card {
  width: min(100%, calc(24rem / var(--ui-scale)));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: calc(18px * var(--ui-scale));
  box-shadow: var(--shadow);
  padding: calc(2rem / var(--ui-scale));
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.login-card__brand {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.login-card__icon-wrap {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: calc(56px * var(--ui-scale));
  height: calc(56px * var(--ui-scale));
  background: #fff;
  border-radius: calc(12px * var(--ui-scale));
  box-shadow: 0 4px 16px rgb(15 23 42 / 10%);
}

.login-card__icon {
  width: calc(40px * var(--ui-scale));
  height: calc(40px * var(--ui-scale));
  object-fit: contain;
  display: block;
}

.login-card__title {
  margin: 0;
  font-size: 1.45rem;
  color: var(--text);
}

.login-card__subtitle {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.login-form__field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.login-form__field label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
}

.login-form__field input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: calc(10px * var(--ui-scale));
  background: var(--bg);
  color: var(--text);
  padding: 0.7rem 0.85rem;
  font: inherit;
}

.login-form__field input:focus {
  outline: 2px solid var(--accent-border);
  outline-offset: 1px;
}

.login-form__error {
  margin: 0;
  color: var(--danger);
  font-size: 0.88rem;
}

.login-form__submit {
  border: none;
  border-radius: calc(10px * var(--ui-scale));
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  padding: 0.75rem 1rem;
  cursor: pointer;
}

.login-form__submit:disabled {
  opacity: 0.7;
  cursor: wait;
}

.login-divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.login-divider::before,
.login-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.login-form__authentik {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: calc(10px * var(--ui-scale));
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  padding: 0.75rem 1rem;
  text-decoration: none;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.login-form__authentik:hover {
  border-color: #fd4b2d;
  background: rgb(253 75 45 / 8%);
}

.login-form__authentik-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.35rem;
  height: 1.35rem;
  border-radius: 0.35rem;
  background: #fd4b2d;
  color: #fff;
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1;
}

.sidebar-action {
  width: 100%;
  margin-top: 0.5rem;
  border: 1px solid rgb(148 163 184 / 25%);
  background: transparent;
  color: var(--sidebar-text);
  border-radius: calc(10px * var(--ui-scale));
  padding: 0.55rem 0.75rem;
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
  text-align: center;
}

.sidebar-action:first-of-type {
  margin-top: 0.75rem;
}

.sidebar-action:hover,
.sidebar-action.active {
  color: var(--sidebar-active);
  border-color: rgb(148 163 184 / 45%);
}
