/* =====================================================================
   Charte Ideuzo (par defaut, avant personnalisation client par l'admin)
   - Couleur de marque : magenta  #C80078
   - Vert "at_work"     : #287050
   - Accent signature   : corail de l'underscore  #E84363
   - Sur l'espace utilisateur, --accent est remplace dynamiquement par
     la couleur du client definie par l'admin (voir app.js).
   ===================================================================== */
:root {
  /* Marque Ideuzo (couleurs exactes du logo) */
  --brand: #c80078;          /* magenta IDEUZO */
  --brand-strong: #a30062;   /* magenta fonce (hover) */
  --brand-soft: #fce8f2;     /* magenta tres clair (fonds) */
  --green: #287050;          /* vert "at_work" */
  --accent-2: #e84363;       /* corail de l'underscore */
  --accent-2-strong: #d5304f;

  /* Accent applicatif : par defaut = marque Ideuzo, surcharge cote client */
  --accent: var(--brand);
  --accent-ink: #ffffff;

  /* Encre & neutres (legere teinte chaude pour coller a l'univers Ideuzo) */
  --ink: #1c1326;
  --ink-2: #4a3f57;
  --muted: #6b6277; /* contraste AA sur fond clair (>= 4.5:1) pour les textes secondaires */
  --line: #ece7f0;
  --line-2: #d7cfe0;
  --bg: #f6f3f8;
  --panel: #ffffff;

  --danger: #dc2626;
  --ok: #15803d;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(28, 19, 38, .06), 0 14px 34px -16px rgba(28, 19, 38, .22);
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }

/* ---------- Topbar ---------- */
.topbar {
  display: flex; align-items: center; gap: 16px;
  height: 62px; padding: 0 24px;
  background: var(--panel);
  border-bottom: 3px solid transparent;
  border-image: linear-gradient(90deg, var(--brand) 0%, var(--brand) 55%, var(--accent-2) 100%) 1;
  position: sticky; top: 0; z-index: 20;
}
.topbar .brand {
  display: flex; align-items: center; gap: 12px;
  font-weight: 750; letter-spacing: -.02em; font-size: 17px; color: var(--ink);
  text-decoration: none;
}
.topbar .brand .logo { height: 32px; max-width: 200px; object-fit: contain; display: block; }
.topbar .brand .ctx {
  font-size: 14px; font-weight: 650; color: var(--muted);
  padding-left: 12px; margin-left: 2px; border-left: 1px solid var(--line-2);
}
.topbar .brand .ctx:empty { display: none; }
.topbar .spacer { flex: 1; }
.topbar .who { color: var(--muted); font-size: 13px; }

.wrap { max-width: 1120px; margin: 0 auto; padding: 28px 22px 90px; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--line); margin-bottom: 24px; }
.tab {
  appearance: none; border: 0; background: none; cursor: pointer;
  padding: 12px 16px; font: inherit; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px; transition: color .15s;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--ink); font-weight: 650; border-bottom-color: var(--accent); }

/* ---------- Focus clavier visible (accessibilite WCAG 2.4.7) ----------
   Indicateur de focus net pour la navigation au clavier sur les boutons,
   liens, onglets et la barre de recherche (qui n'avaient aucun anneau). */
a:focus-visible, button:focus-visible, .tab:focus-visible,
[role="tab"]:focus-visible, .search-bar input:focus-visible,
[tabindex]:focus-visible, input[type=checkbox]:focus-visible {
  outline: 2.5px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------- Panels ---------- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel + .panel { margin-top: 18px; }
.panel-head { display: flex; align-items: center; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.panel-head h2 { margin: 0; font-size: 15px; font-weight: 700; letter-spacing: -.01em; }
.panel-head .spacer { flex: 1; }
.panel-body { padding: 18px; }
.section-title { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--brand); font-weight: 700; margin: 0 0 10px; }

/* ---------- Forms ---------- */
label { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 6px; font-weight: 600; }
input[type=text], input[type=password], input[type=number], input[type=email], select, textarea {
  width: 100%; padding: 9px 11px; font: inherit; color: var(--ink);
  background: #fff; border: 1px solid var(--line-2); border-radius: 9px;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
input[type=color] { width: 46px; height: 38px; padding: 2px; border: 1px solid var(--line-2); border-radius: 9px; background: #fff; cursor: pointer; }
textarea { min-height: 70px; resize: vertical; }
.field { margin-bottom: 14px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > .field { flex: 1; min-width: 160px; }

/* ---------- Buttons ---------- */
.btn {
  appearance: none; cursor: pointer; font: inherit; font-weight: 650;
  padding: 9px 16px; border-radius: 9px; border: 1px solid transparent;
  background: var(--accent); color: var(--accent-ink);
  display: inline-flex; align-items: center; gap: 7px; transition: filter .15s, transform .05s, box-shadow .15s;
}
.btn:hover { filter: brightness(.94); box-shadow: 0 6px 16px -8px color-mix(in srgb, var(--accent) 70%, transparent); }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: #fff; color: var(--ink); border-color: var(--line-2); box-shadow: none; }
.btn.ghost:hover { background: var(--brand-soft); border-color: var(--accent); color: var(--brand-strong); filter: none; }
.btn.danger { background: #fff; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--line-2)); box-shadow: none; }
.btn.danger:hover { background: color-mix(in srgb, var(--danger) 8%, #fff); filter: none; }
.btn.sm { padding: 6px 11px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
tbody tr:hover { background: var(--brand-soft); }
td.num, th.num { text-align: right; font-family: var(--mono); }
td.id { font-family: var(--mono); color: var(--muted); font-size: 13px; }
.actions-cell { text-align: right; white-space: nowrap; }

/* ---------- Divers ---------- */
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; background: #eef0f3; color: var(--ink-2); }
.pill.ok { background: #e1f5ee; color: var(--green); }
.pill.off { background: #fee2e2; color: var(--danger); }
.pill.wait { background: #fef3c7; color: #b45309; }
.status-sel { width: auto; padding: 5px 9px; font-size: 13px; border-radius: 8px; }
.date-group { font-size: 14px; font-weight: 700; color: var(--ink-2); text-transform: capitalize; margin: 22px 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.date-group:first-child { margin-top: 4px; }
.search-row:last-child { border-bottom: 0 !important; }
.search-row:hover { background: var(--brand-soft); }

/* Recherche globale (loupe + overlay) */
#searchToggle { padding: 6px 9px; }
#searchToggle svg { display: block; }
#searchOverlay { position: fixed; inset: 0; background: rgba(28,19,38,.42); z-index: 60; display: flex; align-items: flex-start; justify-content: center; padding: 72px 16px; }
.search-panel { width: 100%; max-width: 680px; background: #fff; border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; max-height: 76vh; display: flex; flex-direction: column; }
.search-bar { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.search-bar input { flex: 1; border: 0; outline: none; font-size: 16px; background: none; padding: 0; }
.search-bar .x { cursor: pointer; border: 0; background: none; font-size: 22px; color: var(--muted); line-height: 1; }
#searchResults { overflow: auto; padding: 4px 14px 14px; }
@keyframes flashHighlight { 0% { box-shadow: 0 0 0 3px var(--accent); } 100% { box-shadow: 0 0 0 0 transparent; } }
.flash { animation: flashHighlight 1.8s ease-out; border-radius: var(--radius); }
.muted { color: var(--muted); }
.amount { font-family: var(--mono); font-weight: 700; }
.empty { text-align: center; color: var(--muted); padding: 38px 12px; }
.hidden { display: none !important; }
.grid-2 { display: grid; grid-template-columns: 1.3fr 1fr; gap: 18px; align-items: start; }
@media (max-width: 820px) { .grid-2 { grid-template-columns: 1fr; } }

/* arbre catalogue */
.tree-job { border: 1px solid var(--line); border-radius: 10px; margin-bottom: 12px; overflow: hidden; }
.tree-job > .tree-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; background: linear-gradient(0deg, #fff, var(--brand-soft)); border-bottom: 1px solid var(--line); }
.tree-job > .tree-head strong { font-size: 14px; }
.tree-products { padding: 8px 14px 14px; }
.tree-product { border-top: 1px dashed var(--line); padding: 10px 0; }
.tree-product:first-child { border-top: 0; }
.price-chip { display: inline-flex; align-items: center; gap: 8px; background: #fff; border: 1px solid var(--line-2); border-radius: 999px; padding: 4px 6px 4px 12px; margin: 4px 6px 4px 0; font-size: 13px; transition: border-color .15s; }
.price-chip:hover { border-color: var(--accent); }
.price-chip .x { cursor: pointer; color: var(--muted); border: 0; background: none; font-size: 15px; line-height: 1; padding: 2px 5px; border-radius: 50%; }
.price-chip .x:hover { background: #fee2e2; color: var(--danger); }

/* Groupes d'un produit (catalogue) */
.prod-groups { display: inline-flex; flex-wrap: wrap; gap: 3px; align-items: center; }
.grp-chip { display: inline-block; background: var(--brand-soft); color: var(--brand-strong); border-radius: 999px; padding: 1px 8px; font-size: 11px; font-weight: 600; }
.grp-checks { display: flex; flex-direction: column; gap: 4px; max-height: 180px; overflow-y: auto; border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; }

/* selecteur d'acces */
.access-job { border: 1px solid var(--line); border-radius: 10px; margin-bottom: 10px; }
.access-job summary { cursor: pointer; padding: 10px 14px; font-weight: 650; background: var(--brand-soft); border-radius: 10px; list-style: none; display: flex; align-items: center; gap: 8px; }
.access-job summary::-webkit-details-marker { display: none; }
.access-job summary .count { margin-left: auto; font-size: 12px; color: var(--brand-strong); font-weight: 700; }
.access-body { padding: 6px 14px 12px; }
.check-line { display: flex; align-items: center; gap: 9px; padding: 5px 0; font-size: 14px; }
.check-line input { width: auto; accent-color: var(--brand); }
.check-line .lbl-amount { margin-left: auto; font-family: var(--mono); color: var(--ink-2); }
.prod-group { padding: 6px 0; }
.prod-group > .prod-name { font-size: 13px; font-weight: 650; color: var(--ink-2); margin-bottom: 2px; }

/* toast */
#toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 11px; opacity: 0; transition: all .2s; z-index: 100; box-shadow: var(--shadow); max-width: 90vw; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { background: var(--danger); }

/* modal */
.modal-back { position: fixed; inset: 0; background: rgba(28,19,38,.5); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 50; overflow: auto; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 720px; box-shadow: var(--shadow); }
.modal-head { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 16px; font-weight: 700; }
.modal-head .x { margin-left: auto; cursor: pointer; border: 0; background: none; font-size: 22px; color: var(--muted); line-height: 1; }
.modal-body { padding: 20px; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; padding: 14px 20px; border-top: 1px solid var(--line); }

/* ---------- Login (identite Ideuzo) ---------- */
.login-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px;
  background:
    radial-gradient(900px 520px at 85% -10%, color-mix(in srgb, var(--brand) 30%, transparent), transparent 70%),
    radial-gradient(820px 480px at -10% 110%, color-mix(in srgb, var(--accent-2) 38%, transparent), transparent 70%),
    var(--bg);
}
.login-card {
  position: relative; width: 100%; max-width: 384px; background: #fff;
  border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); padding: 32px 30px;
  overflow: hidden;
}
.login-card::before {
  content: ""; position: absolute; top: 0; left: 0; right: 0; height: 5px;
  background: linear-gradient(90deg, var(--brand), var(--accent-2));
}
.login-logo { display: block; height: 40px; margin: 4px 0 18px; }
.login-card h1 { font-size: 20px; margin: 6px 0 4px; letter-spacing: -.02em; font-weight: 800; }
.login-card p.sub { margin: 0 0 22px; color: var(--muted); font-size: 14px; }
.login-card .btn { width: 100%; justify-content: center; margin-top: 6px; }
.err-msg { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 18px; }

/* ---------- Builder (espace utilisateur) ---------- */
.builder-line { display: grid; grid-template-columns: 1fr 1fr 1fr 90px 40px; gap: 10px; align-items: end; padding: 12px; border: 1px solid var(--line); border-radius: 11px; margin-bottom: 10px; }
.builder-line .field { margin: 0; }
.builder-line .rm { align-self: end; }
@media (max-width: 720px) { .builder-line { grid-template-columns: 1fr 1fr; } }
.cart-total { display: flex; align-items: baseline; gap: 10px; justify-content: flex-end; padding-top: 12px; border-top: 2px solid var(--line); margin-top: 6px; }
.cart-total .amount { font-size: 20px; color: var(--accent); }

/* ---------- Tableau de bord (stats) ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 6px; }
.kpi { background: var(--brand-soft); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.kpi-val { font-size: 26px; font-weight: 750; color: var(--ink); letter-spacing: -.02em; line-height: 1.1; }
.kpi-label { font-size: 12px; color: var(--ink-2); margin-top: 3px; }
.kpi-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }
.stat-pills { display: flex; gap: 8px; flex-wrap: wrap; margin: 16px 0 0; }
.stat-h { font-size: 14px; margin: 24px 0 10px; color: var(--ink); font-weight: 700; }
.bars { display: flex; flex-direction: column; gap: 7px; }
.bar-row { display: grid; grid-template-columns: minmax(120px, 240px) 1fr auto; gap: 12px; align-items: center; }
.bar-label { font-size: 13px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { background: var(--brand-soft); border-radius: 6px; height: 18px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--brand), var(--accent-2)); border-radius: 6px; min-width: 3px; }
.bar-val { font-size: 13px; color: var(--ink); font-variant-numeric: tabular-nums; white-space: nowrap; }
.stat-table { width: 100%; }

/* Repondants / non-repondants (deux colonnes) */
.resp-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.resp-col { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.resp-head { display: flex; align-items: center; gap: 8px; padding: 9px 14px; font-size: 13px; font-weight: 700; border-bottom: 1px solid var(--line); }
.resp-head.ok { background: #e1f5ee; color: var(--green); }
.resp-head.wait { background: #fef3c7; color: #b45309; }
.resp-head .resp-n { margin-left: auto; background: rgba(0, 0, 0, .08); border-radius: 999px; padding: 1px 9px; font-size: 12px; }
.resp-list { list-style: none; margin: 0; padding: 0; max-height: 280px; overflow-y: auto; }
.resp-item { display: flex; align-items: center; gap: 8px; padding: 8px 14px; font-size: 13px; border-bottom: 1px solid var(--line); }
.resp-item:last-child { border-bottom: 0; }
.resp-link { flex: 1; min-width: 0; text-align: left; appearance: none; border: 0; background: none; cursor: pointer; font: inherit; color: var(--ink); padding: 0; border-radius: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.resp-link:hover { color: var(--brand-strong); text-decoration: underline; }
.resp-badge { margin-left: auto; background: var(--brand-soft); color: var(--brand-strong); border-radius: 999px; padding: 1px 9px; font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; }
.resp-export { margin-left: 10px; font-size: 12px; font-weight: 600; color: var(--brand-strong); text-decoration: none; padding: 2px 9px; border: 1px solid var(--line-2); border-radius: 7px; background: #fff; white-space: nowrap; }
.resp-export:hover { background: var(--brand-soft); border-color: var(--brand); }

@media (max-width: 720px) {
  .bar-row { grid-template-columns: minmax(90px, 140px) 1fr auto; gap: 8px; }
  .bar-val .muted { display: none; }
  .resp-cols { grid-template-columns: 1fr; }
}
