/* Plan de feu — reprend les jetons de la suite (ReFix, Com, Manager) pour que l'app
   ne depayse pas quand on y arrive depuis Manager. */
:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --panel-3: #262b36;
  --line: #2a2f3a;
  --text: #e8ebf0;
  --muted: #9aa3b2;
  --accent: #6c8cff;
  --ok: #3ecf8e;
  --warn: #f5a524;
  --ko: #f2555a;
  --radius: 10px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0; height: 100vh; overflow: hidden;
  background: var(--bg); color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* Outil de travail, pas une page a lire : un glisser un peu vif sur le plan ou une barre
   laterale (pour deplacer la vue, cliquer vite d'un onglet a l'autre) ne doit jamais se
   transformer en selection de texte ailleurs sur la page. Champs de saisie, contenu
   editable et tableau de materiel (on veut pouvoir copier un prix) restent sélectionnables. */
.app-shell { display: flex; height: 100vh; user-select: none; -webkit-user-select: none; }
input, textarea, [contenteditable], table.inv, table.inv * {
  user-select: text; -webkit-user-select: text;
}
.muted { color: var(--muted); margin: 0; }
.small { font-size: 12px; }

/* ---------- barre laterale gauche : plans + palette ---------- */
.sidebar {
  width: 290px; flex: 0 0 290px; background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 16px; border-bottom: 1px solid var(--line); }
.brand-icon {
  width: 38px; height: 38px; border-radius: 10px; flex: 0 0 38px;
  background: linear-gradient(135deg, var(--accent), #a06cff);
  display: grid; place-items: center; font-size: 19px;
}
.brand strong { display: block; }
.brand span { color: var(--muted); font-size: 12px; }

.side-tabs { display: flex; border-bottom: 1px solid var(--line); }
.side-tabs button {
  flex: 1; background: none; border: 0; border-bottom: 2px solid transparent;
  color: var(--muted); padding: 10px 4px; font: inherit; cursor: pointer;
}
.side-tabs button.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.side-pane { flex: 1; overflow-y: auto; padding: 14px; min-height: 0; }

.project-list { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 3px; }
.project-list button {
  width: 100%; text-align: left; background: none; border: 0; color: var(--muted);
  padding: 8px 10px; border-radius: 8px; font: inherit; cursor: pointer;
}
.project-list button:hover { background: var(--panel-2); color: var(--text); }
.project-list button.active { background: var(--panel-2); color: var(--text); font-weight: 600; }
.project-list small { display: block; color: var(--muted); font-size: 11px; font-weight: 400; }

/* ---------- palette de materiel ---------- */
.palette-search { margin-bottom: 10px; }
.palette-group { margin-bottom: 4px; border-bottom: 1px solid var(--line); }
.palette-title {
  margin: 0; padding: 8px 2px; font-size: 12px; text-transform: uppercase;
  letter-spacing: .06em; color: var(--muted); font-weight: 600;
  cursor: pointer; display: flex; align-items: center; gap: 6px; user-select: none;
}
.palette-title:hover { color: var(--text); }
.palette-caret { font-size: 10px; width: 10px; flex: 0 0 10px; color: var(--muted); }
.palette-body { padding-bottom: 10px; }
.palette-item {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 9px; margin-bottom: 4px; border-radius: 8px;
  background: var(--panel-2); border: 1px solid var(--line);
  cursor: grab; user-select: none;
}
.palette-item:hover { border-color: var(--accent); }
.palette-item:active { cursor: grabbing; }
.palette-item .pi-body { min-width: 0; flex: 1; }
.palette-item .pi-icon { font-size: 17px; flex: 0 0 auto; line-height: 1; }
.palette-item strong { display: block; font-size: 13px; font-weight: 600; }
.palette-item small { display: block; color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 9px; }
.palette-subgroup {
  margin: 8px 0 4px; font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); opacity: .8; font-weight: 600;
}
.palette-family { display: flex; flex-direction: column; gap: 4px; }

/* ---------- vue par pont / perche (onglet Ponts) ---------- */
.rig-group { margin-bottom: 16px; }
.rig-title {
  margin: 0 0 8px; padding-bottom: 6px; border-bottom: 1px solid var(--line);
  font-size: 13px; font-weight: 600; cursor: pointer; display: flex; align-items: center;
  justify-content: space-between; gap: 6px;
}
.rig-title:hover { color: var(--accent); }
.rig-weight { font-size: 11px; font-weight: 400; color: var(--muted); white-space: nowrap; }
.rig-weight.over { color: var(--ko); font-weight: 600; }
.rig-item {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px; margin: 0 0 3px 10px;
  border-left: 2px solid var(--line); background: var(--panel-2); border-radius: 0 8px 8px 0;
  cursor: pointer;
}
.rig-item:hover { border-left-color: var(--accent); }
.rig-item .pi-body { flex: 1; min-width: 0; }
.rig-item strong { display: block; font-size: 12.5px; font-weight: 600; }
.rig-item small { display: block; color: var(--muted); font-size: 11px; }
.rig-attach { margin: 6px 0 0 10px; }
.rig-attach select { font-size: 12px; color: var(--muted); }

/* ---------- zone centrale ---------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.topbar h1 { margin: 0; font-size: 17px; outline: none; flex: 0 1 auto; }
.topbar h1:focus { border-bottom: 1px dashed var(--accent); }
.spacer { flex: 1; }
.topbar-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.canvas-wrap { flex: 1; position: relative; overflow: hidden; background: #0b0d12; min-height: 0; }
/* Le plan est un outil de travail, pas du texte a lire : un glisser rapide (pour deplacer
   la vue, aligner un projecteur) ne doit jamais se transformer en selection de texte. */
#plan { width: 100%; height: 100%; display: block; touch-action: none; user-select: none; -webkit-user-select: none; }

/* Projecteur « allume » : alimente, pilote, sans erreur — confirmation positive plutot
   qu'une simple absence de pastille rouge. Le halo pulse doucement, l'icone brille. */
.device-glow {
  fill: #ffd666; opacity: .22; filter: blur(3px);
  animation: device-glow-pulse 2.2s ease-in-out infinite;
}
.device-lit { animation: device-lit-pulse 2.2s ease-in-out infinite; }
@keyframes device-glow-pulse {
  0%, 100% { opacity: .16; }
  50% { opacity: .32; }
}
@keyframes device-lit-pulse {
  0%, 100% { filter: drop-shadow(0 0 2px rgba(255, 214, 102, .8)); }
  50% { filter: drop-shadow(0 0 6px rgba(255, 214, 102, 1)); }
}
.canvas-hint {
  position: absolute; left: 12px; bottom: 12px; pointer-events: none;
  background: rgba(15,17,21,.85); border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 10px; font-size: 12px; color: var(--muted);
}
/* Filtres d'affichage (masquer tout le son / toute la lumiere…) : un plan charge devient
   vite illisible avec tout superpose. Chaque puce est un toggle independant par categorie. */
.layer-filters {
  position: absolute; left: 12px; top: 12px; display: flex; gap: 6px; flex-wrap: wrap;
  max-width: calc(100% - 24px);
}
.layer-filter {
  display: flex; align-items: center; gap: 5px; cursor: pointer; user-select: none;
  background: rgba(15,17,21,.85); border: 1px solid var(--line); border-radius: 999px;
  padding: 5px 11px 5px 9px; font-size: 12px; color: var(--muted); transition: opacity .15s;
}
.layer-filter.active { color: var(--text); border-color: var(--accent); }
.layer-filter:not(.active) { opacity: .5; }
.layer-filter:hover { opacity: 1; }
.link-mode-banner {
  position: absolute; left: 50%; top: 12px; transform: translateX(-50%);
  background: var(--accent); color: #0b0d12; font-weight: 600;
  padding: 7px 14px; border-radius: 999px; font-size: 13px;
}

/* ---------- panneau de droite ---------- */
.inspector {
  width: 330px; flex: 0 0 330px; background: var(--panel);
  border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0;
}
.insp-pane { flex: 1; overflow-y: auto; padding: 14px; min-height: 0; }
.insp-foot { border-top: 1px solid var(--line); padding: 10px 14px; font-size: 12px; color: var(--muted); }

.card { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 12px; }
.card h2 { margin: 0 0 8px; font-size: 14px; }
.card h3 { margin: 12px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }

/* ---------- formulaires ---------- */
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
label.inline { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 13px; }
label.inline input { width: auto; }
input, select, textarea {
  background: var(--panel-3); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 9px; font: inherit; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.form { display: flex; flex-direction: column; gap: 10px; }

/* ---------- boutons ---------- */
.btn {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 12px; font: inherit; cursor: pointer; white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #0b0d12; font-weight: 600; }
.btn-ghost { background: none; }
.btn-small { padding: 4px 9px; font-size: 12px; }
.btn-block { width: 100%; }
.btn-danger { border-color: var(--ko); color: var(--ko); }

/* ---------- diagnostic ---------- */
.diag-summary { display: flex; gap: 8px; align-items: center; }
.pill {
  border-radius: 999px; padding: 3px 10px; font-size: 12px; font-weight: 600;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--muted);
}
.pill.ko { border-color: var(--ko); color: var(--ko); }
.pill.warn { border-color: var(--warn); color: var(--warn); }
.pill.ok { border-color: var(--ok); color: var(--ok); }

.issue-list { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.issue {
  border: 1px solid var(--line); border-left-width: 3px; border-radius: 8px;
  padding: 8px 10px; background: var(--panel-2); cursor: pointer; font-size: 13px;
}
.issue:hover { border-color: var(--accent); }
.issue.error { border-left-color: var(--ko); }
.issue.warning { border-left-color: var(--warn); }
.issue strong { display: block; }
.issue small { color: var(--muted); }

/* ---------- ports & liaisons ---------- */
.port-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.port {
  display: flex; align-items: flex-start; gap: 8px;
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; background: var(--panel-3);
}
.port .dot { margin-top: 3px; }
.port .pbody { flex: 1; min-width: 0; }
.port strong { display: block; font-size: 12.5px; font-weight: 600; }
.port small { display: block; color: var(--muted); font-size: 11px; }
.port.missing { border-color: var(--ko); }

/* Multipaire / bloc a plusieurs embases : une case par embase, pleine = occupee. */
.patch-grid { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 6px; }
.patch-slot {
  width: 13px; height: 13px; border-radius: 3px; flex: 0 0 13px;
  border: 1px solid var(--line); background: var(--panel-2);
}
.patch-slot.occupied { border-color: transparent; }
.patch-slot.occupied:hover { outline: 2px solid var(--ko); outline-offset: 1px; }

/* ---------- statut d'un appareil (puissance, connexions) ---------- */
.status-line { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

/* ---------- inventaire ---------- */
table.inv { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.inv th, table.inv td { padding: 6px 5px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.inv th { color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
table.inv td.num, table.inv th.num { text-align: right; white-space: nowrap; }
table.inv tr.bought td { color: var(--muted); }
table.inv tr.bought td:first-child { text-decoration: line-through; }
.inv-total { display: flex; justify-content: space-between; padding: 8px 5px; font-weight: 600; border-top: 2px solid var(--line); }

/* ---------- messages ---------- */
.flash {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  padding: 9px 16px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel-2); z-index: 50; box-shadow: 0 8px 24px rgba(0,0,0,.45);
}
.flash-ok { border-color: var(--ok); }
.flash-error { border-color: var(--ko); }
.flash-warn { border-color: var(--warn); }

/* ---------- ecran de refus ---------- */
.login-shell { display: grid; place-items: center; height: 100vh; }
.login-card { max-width: 420px; text-align: center; padding: 30px; }
.login-card h1 { margin: 0 0 10px; }
.login-card a { color: var(--accent); }
