/* =============================================================================
   CRMIS - mise en page et composants. Couleurs : uniquement les variables de
   theme.css.
   ============================================================================= */

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }
.hidden { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* --- Boutons et champs ----------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  padding: .6rem 1rem; border-radius: 10px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); cursor: pointer; font-weight: 500;
  transition: background .15s ease, border-color .15s ease, transform .15s ease, box-shadow .15s ease;
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:focus-visible, .field input:focus-visible, .field select:focus-visible, .menu-item:focus-visible, .user-btn:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn-ghost { background: transparent; border-color: transparent; }

.field { margin-bottom: 1.25rem; }
.field label {
  display: block; font-size: .78rem; font-weight: 600; color: var(--text-2);
  margin-bottom: .45rem; text-transform: uppercase; letter-spacing: .05em;
}
.field input, .field select {
  width: 100%; padding: .8rem .95rem; border: 2px solid var(--border-strong); border-radius: 10px;
  background: var(--surface); transition: border-color .2s ease, box-shadow .2s ease;
}
.field input:focus, .field select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent);
}
.field .hint { font-size: .82rem; color: var(--muted); margin-top: .4rem; }

.msg-error {
  color: var(--danger); background: var(--danger-soft); border-left: 3px solid var(--danger);
  padding: .7rem .9rem; border-radius: 8px; font-size: .9rem; margin-top: 1rem;
}
.msg-ok {
  color: var(--accent-strong); background: var(--accent-soft); border-left: 3px solid var(--accent);
  padding: .7rem .9rem; border-radius: 8px; font-size: .9rem; margin-top: 1rem;
}

/* --- Badges d'environnement -------------------------------------------------- */
.env {
  display: inline-flex; align-items: center; gap: .35rem; font-size: .72rem; font-weight: 700;
  letter-spacing: .06em; text-transform: uppercase; padding: .2rem .55rem; border-radius: 999px;
  border: 1px solid currentColor; white-space: nowrap;
}
.env::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.env-dev { color: var(--env-dev); }
.env-test { color: var(--env-test); }
.env-prod { color: var(--env-prod); }
.env-off { color: var(--muted); }
.env-banner {
  position: fixed; top: 0; left: 0; right: 0; height: 4px; z-index: 50;
  background: repeating-linear-gradient(135deg, var(--env-test) 0 12px, transparent 12px 24px);
}
.env-banner.dev { background: repeating-linear-gradient(135deg, var(--env-dev) 0 12px, transparent 12px 24px); }

/* =============================================================================
   Connexion (inspiree de GS OnDuty)
   ============================================================================= */
.auth-scene { position: fixed; inset: 0; display: flex; overflow: hidden; background: var(--bg); }

.splash {
  position: absolute; inset: 0 auto 0 0; width: 100%; height: 100%; z-index: 2;
  display: flex; align-items: center; justify-content: center; background: var(--bg);
  transition: width 1s cubic-bezier(.4, 0, .2, 1), opacity .6s ease, transform .6s ease;
}
.splash::after {
  /* halo discret de la couleur principale */
  content: ""; position: absolute; width: 520px; height: 520px; border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--accent) 16%, transparent) 0%, transparent 70%);
  pointer-events: none;
}
.splash.slide-left { width: calc(50% - 15px); }
.splash.fade-out { opacity: 0; transform: scale(.96); }
.splash-content { position: relative; z-index: 1; text-align: center; padding: 1rem; }
.logo-orb {
  width: 148px; height: 148px; margin: 0 auto 2rem; border-radius: 50%;
  background: var(--surface); color: var(--accent); box-shadow: var(--shadow-lg);
  display: flex; align-items: center; justify-content: center;
  animation: float 3s ease-in-out infinite;
}
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-10px); } }
.app-title { font-size: 2.9rem; font-weight: 300; letter-spacing: -.02em; margin: 0 0 .35rem; }
.app-subtitle { font-size: 1.05rem; color: var(--text-2); margin: 0; }
.partners { display: flex; align-items: center; justify-content: center; gap: 1rem; margin-top: 1.6rem; }
.brand-logo { display: block; width: 190px; height: auto; border-radius: 8px; box-shadow: var(--shadow); }
.gs-medal {
  /* Grid System, realisateur : medaillon discret (logo noir, fond blanc dans les deux themes) */
  display: flex; align-items: center; justify-content: center; width: 48px; height: 48px; flex: none;
  border-radius: 50%; background: #ffffff; box-shadow: var(--shadow);
}
.gs-medal img { width: 34px; height: 34px; }
.progress-track { width: 200px; height: 3px; margin: 2rem auto 0; background: var(--surface-3); border-radius: 2px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--accent); border-radius: 2px; transition: width .1s linear; }

.auth-panel {
  position: absolute; top: 0; right: 0; width: calc(50% - 15px); height: 100%; z-index: 1;
  display: flex; flex-direction: column; justify-content: center; padding: 3rem 4rem;
  background: var(--surface); box-shadow: -4px 0 30px rgba(0, 0, 0, .10);
  transform: translateX(100%); visibility: hidden; opacity: 0;
  transition: transform 1s cubic-bezier(.4, 0, .2, 1), opacity 1s cubic-bezier(.4, 0, .2, 1), visibility 0s linear 1s;
}
.auth-panel.show {
  transform: translateX(0); visibility: visible; opacity: 1; z-index: 3;
  transition: transform 1s cubic-bezier(.4, 0, .2, 1), opacity 1s cubic-bezier(.4, 0, .2, 1), visibility 0s linear 0s;
}
.auth-panel h2 { font-size: 2rem; font-weight: 600; margin: 0 0 .4rem; }
.auth-panel .lead { color: var(--text-2); margin: 0 0 2.2rem; }
.auth-form { max-width: 400px; width: 100%; }
.btn-login {
  width: 100%; padding: 1rem; border: none; border-radius: 10px; margin-top: .4rem;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong)); color: var(--on-accent);
  font-weight: 650; text-transform: uppercase; letter-spacing: .05em; cursor: pointer;
  transition: transform .3s ease, box-shadow .3s ease, opacity .2s ease;
}
.btn-login:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px color-mix(in srgb, var(--accent) 35%, transparent);
}
.btn-login:disabled { opacity: .75; cursor: wait; }
.spinner-inline {
  display: inline-block; width: 20px; height: 20px; vertical-align: middle; border-radius: 50%;
  border: 2px solid color-mix(in srgb, var(--on-accent) 30%, transparent); border-top-color: var(--on-accent);
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.server-info { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin-top: .55rem; font-size: .82rem; color: var(--muted); }
.versions { margin-top: 2rem; font-size: .78rem; color: var(--muted); }

.success-overlay {
  position: absolute; inset: 0; z-index: 10; background: var(--bg);
  display: flex; align-items: center; justify-content: center; animation: fadeIn .5s ease;
}
.success-card { text-align: center; padding: 3rem; }
.checkmark { width: 80px; height: 80px; margin-bottom: 2rem; }
.checkmark circle, .checkmark path { stroke: var(--accent); fill: none; }
.checkmark-path { stroke-dasharray: 50; stroke-dashoffset: 50; animation: draw .6s ease-out .3s forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }
.success-card h2 { font-size: 2rem; font-weight: 300; margin: 0 0 .4rem; }
.success-card p { color: var(--text-2); margin: 0; }
.spinner-dots { display: flex; gap: 6px; justify-content: center; margin-top: 2rem; }
.spinner-dots span { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: bounce 1.4s ease-in-out infinite; }
.spinner-dots span:nth-child(2) { animation-delay: .2s; }
.spinner-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes bounce { 0%, 80%, 100% { transform: scale(.6); opacity: .4; } 40% { transform: scale(1); opacity: 1; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

@media (max-width: 820px) {
  .splash.slide-left { width: 100%; height: calc(34% - 10px); }
  .splash::after { display: none; }
  .logo-orb { width: 84px; height: 84px; margin-bottom: .8rem; }
  .logo-orb svg { width: 54px; height: 54px; }
  .app-title { font-size: 1.9rem; }
  .partners { margin-top: .8rem; gap: .7rem; }
  .brand-logo { width: 140px; }
  .gs-medal { width: 38px; height: 38px; }
  .gs-medal img { width: 27px; height: 27px; }
  .auth-panel { width: 100%; height: calc(66% - 10px); top: auto; bottom: 0; padding: 1.5rem 16px; transform: translateY(100%); overflow-y: auto; }
  .auth-panel.show { transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* =============================================================================
   Application
   ============================================================================= */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 1rem;
  padding: .65rem 1.5rem; background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .6rem; text-decoration: none; color: var(--text); }
.brand .crmis-mark { color: var(--accent); flex: none; }
.brand strong { font-size: 1.15rem; font-weight: 650; letter-spacing: -.01em; }
.nav { display: flex; gap: .25rem; margin-left: 1rem; }
.nav a, .nav span {
  padding: .45rem .8rem; border-radius: 8px; text-decoration: none; color: var(--text-2); font-weight: 500; font-size: .92rem;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent-strong); }
.nav span.soon { color: var(--muted); cursor: default; }
.nav span.soon small { font-size: .7rem; margin-left: .3rem; }
.topbar .spacer { flex: 1; }
.server-tag { display: flex; align-items: center; gap: .5rem; font-size: .8rem; color: var(--muted); }

.user-menu { position: relative; }
.user-btn {
  display: flex; align-items: center; gap: .6rem; padding: .3rem .6rem .3rem .3rem; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer;
}
.user-btn:hover { background: var(--surface-2); }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  background: var(--accent); color: var(--on-accent); font-weight: 700; font-size: .85rem;
}
.user-btn .who { text-align: left; line-height: 1.15; }
.user-btn .who small { display: block; color: var(--muted); font-size: .74rem; }
.menu {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 250px; padding: .4rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg);
  animation: menuIn .15s ease;
}
@keyframes menuIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.menu-head { padding: .6rem .7rem .7rem; border-bottom: 1px solid var(--border); margin-bottom: .3rem; }
.menu-head strong { display: block; }
.menu-head small { color: var(--muted); }
.menu-item {
  display: flex; align-items: center; gap: .6rem; width: 100%; padding: .6rem .7rem; border: 0; border-radius: 8px;
  background: none; text-align: left; cursor: pointer; color: var(--text);
}
.menu-item:hover:not(:disabled) { background: var(--surface-2); }
.menu-item:disabled { color: var(--muted); cursor: not-allowed; }
.menu-item .ic { width: 18px; text-align: center; opacity: .8; }
.menu-item small { margin-left: auto; font-size: .72rem; color: var(--muted); }
.menu-sep { height: 1px; background: var(--border); margin: .3rem 0; }

.page { max-width: 1320px; margin: 0 auto; padding: 1.8rem 1.5rem 3rem; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
.page-head h1 { font-size: 1.7rem; font-weight: 600; letter-spacing: -.01em; margin: 0; }
.page-head p { margin: .2rem 0 0; color: var(--text-2); }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow);
  padding: 1.25rem 1.35rem;
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin-bottom: .9rem; }
.card-head h2 { font-size: 1.02rem; font-weight: 600; margin: 0; }
.card-head p { font-size: .84rem; color: var(--muted); margin: .15rem 0 0; }
.card-tools { display: flex; gap: .4rem; }
.card-tools .btn { padding: .3rem .6rem; font-size: .8rem; border-radius: 8px; }

.tiles { display: grid; grid-template-columns: 1.35fr 1fr 1fr 1fr; gap: 1rem; margin-bottom: 1rem; }
.tile .label { font-size: .86rem; color: var(--text-2); }
.tile .value { font-size: 2rem; font-weight: 650; letter-spacing: -.02em; line-height: 1.15; margin-top: .25rem; }
.tile.hero .value { font-size: 3.2rem; color: var(--text); }
.tile .sub { font-size: .82rem; color: var(--muted); margin-top: .35rem; }
.tile .bar { height: 8px; border-radius: 999px; background: var(--accent-soft); margin-top: .7rem; overflow: hidden; }
.tile .bar > span { display: block; height: 100%; border-radius: 999px; background: var(--accent); }

.grid-main { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); gap: 1rem; }
.grid-main > .col { display: grid; gap: 1rem; align-content: start; }

/* --- Graphiques -------------------------------------------------------------- */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; }
.chart .axis-line { stroke: var(--axis); stroke-width: 1; }
.chart text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart text.end-label { fill: var(--text-2); font-size: 11.5px; font-weight: 600; }
.chart .series-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { stroke: var(--surface); stroke-width: 2; }
.chart .crosshair { stroke: var(--axis); stroke-width: 1; }
.chart .bar-rect { transition: opacity .15s ease; }
.chart .bar-rect.dim { opacity: .45; }
.chart text.bar-value { fill: var(--text-2); font-size: 12px; font-weight: 600; }
.chart text.bar-label { fill: var(--text-2); font-size: 12px; }
.tooltip {
  position: absolute; pointer-events: none; z-index: 5; min-width: 150px; padding: .55rem .7rem;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 10px; box-shadow: var(--shadow-lg);
  font-size: .82rem; transform: translate(-50%, calc(-100% - 12px)); white-space: nowrap;
}
.tooltip strong { display: block; margin-bottom: .25rem; }
.tooltip .row { display: flex; align-items: center; gap: .45rem; }
.tooltip .row b { margin-left: auto; padding-left: 1rem; font-variant-numeric: tabular-nums; }
.legend { display: flex; flex-wrap: wrap; gap: .4rem 1rem; margin-top: .7rem; font-size: .84rem; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: .4rem; }
.key { display: inline-block; width: 14px; height: 3px; border-radius: 2px; }
.key-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; }

table.data { width: 100%; border-collapse: collapse; font-size: .86rem; }
table.data th, table.data td { padding: .45rem .5rem; border-bottom: 1px solid var(--border); text-align: right; font-variant-numeric: tabular-nums; }
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data th { color: var(--text-2); font-weight: 600; }

/* --- Dernieres modifications ------------------------------------------------- */
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: grid; grid-template-columns: 34px 1fr auto; gap: .7rem; align-items: start; padding: .65rem 0; border-bottom: 1px solid var(--border); }
.feed li:last-child { border-bottom: 0; }
.feed .op {
  width: 30px; height: 30px; border-radius: 9px; display: flex; align-items: center; justify-content: center;
  font-size: .8rem; font-weight: 700; background: var(--surface-2); color: var(--text-2);
}
.feed .op.create { background: var(--accent-soft); color: var(--accent-strong); }
.feed .op.delete { background: var(--danger-soft); color: var(--danger); }
.feed .what { font-size: .9rem; }
.feed .what strong { font-weight: 600; }
.feed .meta { font-size: .78rem; color: var(--muted); }
.feed time { font-size: .76rem; color: var(--muted); white-space: nowrap; }
.feed .what { display: flex; flex-wrap: wrap; align-items: baseline; gap: .15rem .5rem; }
.feed .code { font-size: .78rem; color: var(--text-2); font-variant-numeric: tabular-nums; }
.feed .tag {
  font-size: .72rem; font-weight: 600; padding: .05rem .45rem; border-radius: 999px;
  background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border);
}
.feed .tag.create { background: var(--accent-soft); color: var(--accent-strong); border-color: transparent; }
.feed .tag.delete { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.feed .avatar {
  width: 30px; height: 30px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: .72rem; font-weight: 700; background: var(--accent-soft); color: var(--accent-strong);
}

.empty { color: var(--muted); font-size: .9rem; padding: 1rem 0; }
.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; border-radius: 8px; }
@keyframes shimmer { to { background-position: -200% 0; } }

.footer { text-align: center; font-size: .76rem; color: var(--muted); padding: 1rem; }

/* --- Fenetre modale ---------------------------------------------------------- */
dialog.modal {
  border: 1px solid var(--border); border-radius: 16px; padding: 0; width: min(560px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
}
dialog.modal::backdrop { background: rgba(5, 10, 7, .45); backdrop-filter: blur(2px); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 1.1rem 1.35rem; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 1.15rem; margin: 0; }
.modal-body { padding: 1.2rem 1.35rem 1.4rem; }
.modal-body h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-2); margin: 1.4rem 0 .7rem; }
.modal-body h3:first-child { margin-top: 0; }
.seg { display: inline-flex; padding: 3px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); }
.seg button { border: 0; background: none; padding: .45rem .9rem; border-radius: 8px; cursor: pointer; color: var(--text-2); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); font-weight: 600; }
.swatches { display: flex; gap: .6rem; flex-wrap: wrap; }
.swatch {
  width: 38px; height: 38px; border-radius: 50%; border: 2px solid var(--surface); cursor: pointer;
  box-shadow: 0 0 0 1px var(--border-strong); position: relative;
}
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--text); }
.swatch-name { font-size: .78rem; color: var(--muted); margin-top: .5rem; }

/* --- Responsive -------------------------------------------------------------- */
@media (max-width: 1100px) {
  .tiles { grid-template-columns: 1fr 1fr; }
  .grid-main { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .topbar { padding: .55rem 16px; gap: .5rem; }
  .nav, .server-tag .ver, .user-btn .who { display: none; }
  .page { padding: 1.2rem 16px 2rem; }
  .tiles { grid-template-columns: 1fr; }
  .tile.hero .value { font-size: 2.6rem; }
}
