:root {
  --accent: #7058DC;
  --paper: #EEF1F5;
  --surface: #FFFFFF;
  --surface-2: #F6F8FA;
  --ink: #2E2663;          /* bleu nuit FDME */
  --muted: #5F5B7D;
  /* Couleurs de la charte FDME */
  --fdme-navy: #2E2663;
  --fdme-pink: #E669CE;
  --fdme-violet: #8169E6;
  --fdme-cyan: #58C0D0;
  --line: #D9DEE7;
  --line-strong: #C3CAD6;
  --ok: #1E9A62;
  --down: #D33A3A;
  --shadow: 0 1px 2px rgba(24, 34, 58, .06), 0 4px 14px rgba(24, 34, 58, .05);
  --radius: 10px;
  --accent-soft: color-mix(in srgb, var(--accent) 14%, transparent);
  --accent-ink: color-mix(in srgb, var(--accent) 82%, #000);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #13112A; --surface: #1C1938; --surface-2: #242046; --ink: #ECEAF7; --muted: #A29EC0;
    --line: #2F2B55; --line-strong: #423C70; --shadow: 0 1px 2px rgba(0,0,0,.3);
    --accent-ink: color-mix(in srgb, var(--accent) 70%, #fff); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #13112A; --surface: #1C1938; --surface-2: #242046; --ink: #ECEAF7; --muted: #A29EC0;
  --line: #2F2B55; --line-strong: #423C70; --shadow: 0 1px 2px rgba(0,0,0,.3);
  --accent-ink: color-mix(in srgb, var(--accent) 70%, #fff); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.45 "Figtree", system-ui, sans-serif;
  min-height: 100vh;
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent-ink); }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Barre du haut ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 520px) minmax(0, 1fr);
  align-items: center; gap: 16px;
  padding: 12px 24px;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
/* Liseré aux couleurs FDME sous la barre du haut */
.topbar::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 3px;
  background: linear-gradient(90deg, var(--fdme-pink), var(--fdme-violet) 50%, var(--fdme-cyan));
}
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: var(--ink); min-width: 0; }
.brand img { height: 34px; width: auto; max-width: 120px; object-fit: contain; }
.brand .fdme-logo { height: 40px; max-width: none; flex: none; }
.brand .brand-mark { height: 30px; width: 30px; flex: none; }
.brand-sep { width: 1px; height: 30px; background: var(--line-strong); flex: none; margin: 0 2px; }
/* Logo FDME : version bleu nuit en thème clair, version blanche en thème sombre */
.fdme-logo-dark { display: none; }
:root[data-theme="dark"] .fdme-logo-light { display: none; }
:root[data-theme="dark"] .fdme-logo-dark { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .fdme-logo-light { display: none; }
  :root:not([data-theme="light"]) .fdme-logo-dark { display: block; }
}
#brand-title { font-size: 21px; font-weight: 700; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.search {
  display: flex; align-items: center; gap: 10px;
  height: 42px; padding: 0 10px 0 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 21px;
  box-shadow: var(--shadow); cursor: text;
}
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search svg { width: 18px; height: 18px; color: var(--muted); flex: none; }
.search input { flex: 1; min-width: 0; border: 0; background: none; outline: none; height: 100%; }
.search input::-webkit-search-cancel-button { display: none; }
kbd {
  font: 600 12px/1 "Figtree", sans-serif; color: var(--muted);
  border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 6px; padding: 4px 7px;
}
.search:focus-within kbd { visibility: hidden; }

.actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.icon-btn {
  width: 38px; height: 38px; display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: 50%; background: var(--surface); cursor: pointer; color: var(--muted);
}
.icon-btn:hover { color: var(--ink); border-color: var(--line-strong); }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.health {
  display: inline-flex; align-items: center; gap: 7px; padding: 0 12px; height: 30px;
  font-size: 13px; font-weight: 600; color: var(--muted);
  border-radius: 15px; background: var(--surface); border: 1px solid var(--line);
}
.health::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.health.bad { color: var(--down); border-color: color-mix(in srgb, var(--down) 40%, var(--line)); }
.health.bad::before { background: var(--down); }

/* ---------- Barre d'édition ---------- */
.editbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 10px 24px; background: var(--accent-soft); border-bottom: 1px solid color-mix(in srgb, var(--accent) 35%, var(--line));
}
.editbar p { margin: 0; font-size: 14px; }
.editbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Boutons ---------- */
.btn {
  height: 36px; padding: 0 14px; border-radius: 8px; cursor: pointer; white-space: nowrap;
  border: 1px solid var(--line-strong); background: var(--surface); font-weight: 600; font-size: 14px;
}
.btn:hover { border-color: var(--muted); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); }
.btn-danger { color: var(--down); }
.btn-danger:hover { border-color: var(--down); }

/* ---------- Mise en page ---------- */
.layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 40px;
  max-width: 1680px; margin: 0 auto; padding: 28px 24px 64px;
}
.layout.no-side { grid-template-columns: minmax(0, 1fr); }
.main-col { display: flex; flex-direction: column; gap: 34px; min-width: 0; }
.side-col { display: flex; flex-direction: column; gap: 30px; }

/* ---------- Sections ---------- */
.group-head { display: flex; align-items: center; gap: 10px; margin: 0 0 14px; }
.group-title { margin: 0; font-size: 17px; font-weight: 700; letter-spacing: -.005em; }
.group-toggle {
  display: inline-flex; align-items: center; gap: 8px; border: 0; background: none; padding: 0; cursor: pointer; text-align: left;
  font: inherit;
}
.group-toggle svg { width: 16px; height: 16px; color: var(--muted); transition: transform .15s; }
.group.collapsed .group-toggle svg { transform: rotate(-90deg); }
.group.collapsed .tiles, .group.collapsed .cards { display: none; }
.count { font-size: 13px; font-weight: 600; color: var(--muted); }
.group-head .rule { flex: 1; height: 1px; background: var(--line); }
.group-edit { display: none; }
.editing .group-edit { display: inline-flex; gap: 4px; }
.mini-btn {
  width: 30px; height: 30px; display: grid; place-items: center; cursor: pointer;
  border: 1px solid var(--line); border-radius: 7px; background: var(--surface); color: var(--muted);
}
.mini-btn:hover { color: var(--ink); border-color: var(--line-strong); }
.mini-btn:disabled { opacity: .35; cursor: default; }
.mini-btn svg { width: 15px; height: 15px; }

/* ---------- Tuiles ---------- */
.tiles {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(97px, 1fr)); gap: 10px;
  list-style: none; margin: 0; padding: 0; min-height: 40px;
}
.tile {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  width: 100%; height: 96px; padding: 11px 6px 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  text-decoration: none; color: var(--ink); cursor: pointer;
}
.tile:hover { border-color: var(--line-strong); box-shadow: var(--shadow); }
.tile:hover .tile-name { color: var(--accent-ink); }
.tile.active { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.tile-name {
  font-size: 12px; font-weight: 600; line-height: 1.25; text-align: center;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.ico { width: 40px; height: 40px; flex: none; display: grid; place-items: center; }
.ico img { width: 100%; height: 100%; object-fit: contain; }
.mono {
  width: 100%; height: 100%; border-radius: 10px; display: grid; place-items: center;
  font-weight: 700; font-size: 15px; letter-spacing: .02em; color: #fff;
}
/* Tuiles à l'échelle 90 % (logo 36 px, sigle 14 px) */
.tile .ico { width: 36px; height: 36px; }
.tile .mono { font-size: 14px; border-radius: 9px; }
.dot { position: absolute; top: 8px; right: 8px; width: 8px; height: 8px; border-radius: 50%; background: var(--line-strong); }
.dot.up { background: var(--ok); }
.dot.down { background: var(--down); box-shadow: 0 0 0 3px color-mix(in srgb, var(--down) 22%, transparent); }

.add-tile {
  border-style: dashed; border-color: var(--line-strong); background: transparent; color: var(--muted);
  font-size: 13px; font-weight: 600;
}
.add-tile svg { width: 22px; height: 22px; }
.add-tile:hover { color: var(--accent-ink); border-color: var(--accent); box-shadow: none; }

/* ---------- Grandes cartes (colonne de droite) ---------- */
.cards { display: flex; flex-direction: column; gap: 10px; list-style: none; margin: 0; padding: 0; min-height: 40px; }
.card {
  position: relative; display: flex; align-items: center; gap: 14px; width: 100%; min-height: 76px; padding: 12px 14px 12px 16px;
  background: var(--surface); border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: var(--radius);
  text-decoration: none; color: var(--ink); cursor: pointer;
}
.card:hover { box-shadow: var(--shadow); border-color: var(--line-strong); border-left-color: var(--accent); }
.card.active { box-shadow: 0 0 0 3px var(--accent-soft); }
.card .txt { flex: 1; min-width: 0; }
.card .card-name { font-weight: 700; font-size: 15px; }
.card .card-desc { font-size: 13px; color: var(--muted); margin-top: 2px; }
.card .ico { width: 44px; height: 44px; }
.card .dot { top: 10px; right: 10px; }
.card.add-tile { border-left-width: 1px; justify-content: center; min-height: 52px; }

/* ---------- Glisser-déposer ---------- */
.editing .tile, .editing .card { cursor: grab; }
.dragging { opacity: .35; }
.drop-before::before, .drop-after::after {
  content: ""; position: absolute; background: var(--accent); border-radius: 2px;
}
.tile.drop-before::before { left: -8px; top: 8px; bottom: 8px; width: 3px; }
.tile.drop-after::after { right: -8px; top: 8px; bottom: 8px; width: 3px; }
.card.drop-before::before { left: 8px; right: 8px; top: -7px; height: 3px; }
.card.drop-after::after { left: 8px; right: 8px; bottom: -7px; height: 3px; }
.drop-zone { outline: 2px dashed var(--accent); outline-offset: 6px; border-radius: var(--radius); }

.empty-search { text-align: center; color: var(--muted); margin: -20px 0 40px; }

/* ---------- Fenêtres ---------- */
.dlg {
  width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 48px);
  padding: 0; border: 1px solid var(--line); border-radius: 14px;
  background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.dlg-sm { width: min(420px, calc(100vw - 32px)); }
.dlg::backdrop { background: rgba(14, 20, 32, .45); }
.dlg form { padding: 22px 24px; display: flex; flex-direction: column; gap: 14px; }
.dlg h2 { margin: 0 0 4px; font-size: 19px; }
.field { display: flex; flex-direction: column; gap: 6px; border: 0; margin: 0; padding: 0; min-width: 0; }
.field > span, .field legend { font-size: 13px; font-weight: 600; color: var(--muted); padding: 0; }
.field em { font-style: normal; font-weight: 400; }
.field small { color: var(--muted); font-size: 12.5px; }
.field input:not([type=checkbox]):not([type=radio]):not([type=color]), .field select {
  height: 38px; padding: 0 11px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface-2); width: 100%;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field input[type=color] { width: 54px; height: 38px; padding: 2px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface-2); }
.check { display: flex; align-items: center; gap: 9px; font-size: 14px; cursor: pointer; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; }
fieldset.field .check { margin-top: 4px; }
.row { display: flex; align-items: center; gap: 8px; }
.grow { flex: 1; min-width: 0; }
.link-head { display: flex; align-items: flex-end; gap: 14px; }
.icon-preview {
  width: 64px; height: 64px; flex: none; display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2);
}
.icon-preview .ico { width: 40px; height: 40px; }
.logo-preview { height: 38px; min-width: 38px; display: grid; place-items: center; }
.logo-preview img { max-height: 38px; max-width: 110px; }
.dlg-actions { display: flex; align-items: center; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.form-error { margin: 0; color: var(--down); font-size: 14px; font-weight: 600; }
code { font-size: 12.5px; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; border: 1px solid var(--line); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50;
  padding: 10px 16px; border-radius: 10px; background: var(--ink); color: var(--paper);
  font-size: 14px; font-weight: 600; box-shadow: 0 8px 30px rgba(0,0,0,.2);
}
.toast.error { background: var(--down); color: #fff; }

/* ---------- Écran privé ---------- */
.locked .layout, .locked .search, .locked #edit-btn, .locked .health { visibility: hidden; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .side-col { order: -1; }
  .side-col .cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
}
@media (max-width: 720px) {
  .topbar { grid-template-columns: minmax(0, 1fr) auto; padding: 10px 16px; gap: 10px; }
  .search { grid-column: 1 / -1; grid-row: 2; }
  .health { display: none; }
  .brand .fdme-logo, .brand-sep { display: none !important; }
  .layout { padding: 20px 16px 48px; gap: 28px; }
  .editbar { padding: 10px 16px; }
  .tiles { grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 8px; }
  .tile { height: 94px; }
  kbd { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
