:root {
  --bg: #0f1117;
  --surface: #181b24;
  --surface2: #1e2230;
  --border: #2a3042;
  --text: #e8eaef;
  --muted: #8b92a8;
  --accent: #d62828;
  --accent-glow: rgba(214, 40, 40, 0.25);
  --ok: #22c55e;
  --warn: #f59e0b;
  --radius: 12px;
  --font: 'DM Sans', system-ui, sans-serif;
  --mono: 'JetBrains Mono', monospace;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text); min-height: 100vh; }
.screen { display: none; min-height: 100vh; }
.screen.active { display: flex; }

#screen-login {
  align-items: center; justify-content: center;
  background: radial-gradient(ellipse 80% 60% at 50% 0%, rgba(214,40,40,0.12), transparent), var(--bg);
}
.login-wrap { max-width: 420px; padding: 24px; text-align: center; width: 100%; }
.logo-mark {
  width: 56px; height: 56px; margin: 0 auto 16px;
  background: linear-gradient(135deg, var(--accent), #9d0208);
  border-radius: 14px; font-size: 1.75rem; font-weight: 700; color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 32px var(--accent-glow);
}
.login-brand h1 { font-size: 1.5rem; }
.tagline { color: var(--muted); font-size: 0.9rem; margin-top: 4px; }
.login-card {
  margin-top: 28px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 28px; text-align: left;
}
.login-card label { display: block; font-size: 0.72rem; font-weight: 600; color: var(--muted); text-transform: uppercase; margin: 12px 0 6px; }
.login-card label:first-of-type { margin-top: 0; }
.login-card input { width: 100%; padding: 10px 12px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-family: inherit; }
.mfa-hint { margin-top: 12px; font-size: 0.82rem; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.badge-demo { background: rgba(124,58,237,0.2); color: #a78bfa; font-size: 0.65rem; font-weight: 700; padding: 2px 8px; border-radius: 99px; }
.btn-primary { width: 100%; margin-top: 18px; padding: 12px; background: var(--accent); color: #fff; border: none; border-radius: 8px; font-weight: 600; font-family: inherit; cursor: pointer; }
.btn-primary:hover { box-shadow: 0 6px 24px var(--accent-glow); }
.btn-primary.sm { width: auto; margin-top: 0; padding: 8px 16px; font-size: 0.85rem; }
.btn-ghost { padding: 8px 14px; background: transparent; border: 1px solid var(--border); border-radius: 8px; color: var(--muted); font-family: inherit; cursor: pointer; }
.exclude-note { margin-top: 16px; font-size: 0.78rem; color: var(--muted); }
.demo-banner { margin-top: 12px; font-size: 0.8rem; color: var(--warn); }

#screen-app { flex-direction: row; }
.sidebar { width: 240px; background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 20px 12px; flex-shrink: 0; }
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 8px 10px 24px; }
.logo-mark.sm { width: 36px; height: 36px; font-size: 1rem; background: linear-gradient(135deg, var(--accent), #9d0208); border-radius: 10px; color: #fff; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.sidebar-brand strong { display: block; font-size: 0.95rem; }
.sidebar-brand span { font-size: 0.68rem; color: var(--muted); }
.sidebar-nav { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: none; border: none; border-radius: 8px; color: var(--muted); font-family: inherit; font-size: 0.88rem; cursor: pointer; width: 100%; text-align: left; }
.nav-item svg { width: 18px; height: 18px; }
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: rgba(214,40,40,0.15); color: #fff; }
.sidebar-note {
  font-size: 0.72rem; color: var(--muted); line-height: 1.45;
  padding: 12px 10px; margin-top: 8px; border-top: 1px solid var(--border);
}
.sidebar-note strong { color: #5eead4; }
.app-tag { font-weight: 400; text-transform: none; letter-spacing: 0; color: #5eead4; font-size: 0.68rem; }
.app-card.app-rh:not(.denied) { border-color: rgba(20, 184, 166, 0.4); }
.app-card.app-rh:not(.denied) .app-icon { background: rgba(20, 184, 166, 0.15); }
.app-card.app-equipe:not(.denied) { border-color: rgba(129, 140, 248, 0.4); }
.app-card.app-equipe:not(.denied) .app-icon { background: rgba(99, 102, 241, 0.15); }
.app-card.app-backup:not(.denied) { border-color: rgba(245, 158, 11, 0.4); }
.app-card.app-backup:not(.denied) .app-icon { background: rgba(245, 158, 11, 0.15); }
.health-card.err .health-dot { background: #ef4444; }
.sidebar-user { display: flex; align-items: center; gap: 10px; padding: 12px; border-top: 1px solid var(--border); margin-top: auto; }
.sidebar-user strong { display: block; font-size: 0.82rem; }
.sidebar-user span { font-size: 0.72rem; color: var(--muted); }
.avatar { width: 40px; height: 40px; border-radius: 10px; background: linear-gradient(135deg, #3b82f6, #1d4ed8); display: flex; align-items: center; justify-content: center; font-size: 0.75rem; font-weight: 700; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; overflow: auto; }
.topbar { display: flex; justify-content: space-between; padding: 24px 28px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; gap: 12px; }
.topbar h2 { font-size: 1.35rem; }
.topbar p { font-size: 0.85rem; color: var(--muted); margin-top: 2px; }

.view { display: none; padding: 24px 28px 40px; }
.view.active { display: block; }

.distribute-strip {
  background: rgba(214,40,40,0.1); border: 1px solid rgba(214,40,40,0.3);
  border-radius: 10px; padding: 12px 16px; font-size: 0.85rem; margin-bottom: 20px;
}
.distribute-strip strong { color: #fca5a5; }

.preview-switch { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; font-size: 0.85rem; color: var(--muted); margin-bottom: 8px; }
.pill { padding: 6px 14px; border-radius: 99px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); font-family: inherit; font-size: 0.78rem; cursor: pointer; }
.pill.active { border-color: var(--accent); color: #fff; background: rgba(214,40,40,0.2); }
.preview-hint { font-size: 0.82rem; color: var(--muted); font-style: italic; margin-bottom: 20px; }

.section-label { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 24px 0 12px; }
.section-label:first-of-type { margin-top: 0; }

.app-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }

.app-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; cursor: pointer; transition: transform 0.2s, border-color 0.2s, opacity 0.2s;
  position: relative;
}
/* LED état app (vert / orange / rouge) */
.app-led {
  position: absolute; top: 12px; left: 12px;
  width: 10px; height: 10px; border-radius: 50%;
  background: #64748b;
  box-shadow: 0 0 0 2px rgba(0,0,0,0.25);
}
.app-led--online { background: #22c55e; box-shadow: 0 0 8px rgba(34,197,94,0.6); }
.app-led--degraded { background: #eab308; box-shadow: 0 0 8px rgba(234,179,8,0.55); }
.app-led--offline { background: #ef4444; box-shadow: 0 0 8px rgba(239,68,68,0.6); animation: app-led-pulse 1.4s ease-in-out infinite; }
.app-led--unknown { background: #64748b; }
@keyframes app-led-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}
.app-card:hover:not(.denied) { border-color: var(--accent); transform: translateY(-2px); box-shadow: 0 8px 24px rgba(0,0,0,0.35); }

/* Non autorisé : présent mais plus clair */
.app-card.denied {
  opacity: 0.38;
  background: var(--surface2);
  border-color: var(--border);
  cursor: not-allowed;
  filter: saturate(0.35);
}
.app-card.denied::after {
  content: 'Non autorisé';
  position: absolute; top: 10px; right: 10px;
  font-size: 0.58rem; font-weight: 700; text-transform: uppercase;
  color: var(--muted); background: var(--bg); padding: 2px 6px; border-radius: 4px;
}
.app-card.denied:hover { transform: none; border-color: var(--border); box-shadow: none; }

.app-card.external { opacity: 0.28; border-style: dashed; cursor: default; }
.app-card.external::after { content: 'Hors périmètre'; position: absolute; top: 10px; right: 10px; font-size: 0.58rem; color: var(--muted); }

.app-icon {
  width: 44px; height: 44px; border-radius: 10px; background: var(--surface2);
  display: flex; align-items: center; justify-content: center; font-size: 1.35rem; margin-bottom: 12px;
  border: 1px solid var(--border);
}
.app-card:not(.denied):not(.external) .app-icon {
  background: color-mix(in srgb, var(--accent, #d62828) 15%, var(--surface2));
}

.app-card h3 { font-size: 0.92rem; font-weight: 600; }
.app-card p { font-size: 0.75rem; color: var(--muted); margin-top: 4px; line-height: 1.35; }
.app-port { position: absolute; bottom: 14px; right: 14px; font-family: var(--mono); font-size: 0.6rem; color: var(--muted); }
.perm-badge { display: inline-block; margin-top: 10px; font-size: 0.65rem; font-weight: 600; padding: 3px 8px; border-radius: 6px; }
.perm-badge.modif { background: rgba(34,197,94,0.15); color: var(--ok); }
.perm-badge.read { background: rgba(59,130,246,0.15); color: #60a5fa; }
.perm-badge.admin { background: rgba(214,40,40,0.2); color: #f87171; }
.chip { display: inline-block; margin-top: 10px; font-size: 0.62rem; font-weight: 700; text-transform: uppercase; color: var(--muted); }

.toolbar { display: flex; gap: 12px; margin-bottom: 20px; }
.search-input { padding: 8px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-family: inherit; max-width: 240px; }
.team-layout { display: grid; grid-template-columns: 240px 1fr; gap: 20px; }
.team-list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.team-row { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--border); cursor: pointer; }
.team-row:hover, .team-row.selected { background: rgba(214,40,40,0.08); }
.team-row strong { display: block; font-size: 0.85rem; }
.team-row span { font-size: 0.72rem; color: var(--muted); }
.perm-panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; }
.perm-table { width: 100%; margin-top: 14px; border-collapse: collapse; font-size: 0.82rem; }
.perm-table th, .perm-table td { padding: 10px; border-bottom: 1px solid var(--border); text-align: center; }
.perm-table th:first-child, .perm-table td:first-child { text-align: left; }
.muted { color: var(--muted); font-size: 0.85rem; }

.rh-tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.rh-tab { padding: 8px 16px; border: 1px solid var(--border); background: var(--surface); border-radius: 8px; color: var(--muted); font-family: inherit; cursor: pointer; }
.rh-tab.active { border-color: var(--accent); color: #fff; }
.rh-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.rh-card.wide { width: 100%; }
.hours-table { width: 100%; font-size: 0.85rem; border-collapse: collapse; margin-top: 10px; }
.hours-table th, .hours-table td { padding: 10px; border-bottom: 1px solid var(--border); text-align: left; }

.health-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.health-summary { grid-column: 1 / -1; padding: 12px 16px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); margin-bottom: 4px; }
.health-summary--ok { border-color: rgba(34,197,94,0.4); }
.health-summary--bad { border-color: rgba(239,68,68,0.45); background: rgba(239,68,68,0.08); }
.health-summary .bad { color: #f87171; font-weight: 700; }
.health-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 4px; }
.health-card.online { border-color: rgba(34,197,94,0.35); }
.health-card.offline { border-color: rgba(239,68,68,0.4); }
.health-card.degraded { border-color: rgba(234,179,8,0.4); }
.health-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--ok); margin-bottom: 4px; }
.health-dot--online { background: #22c55e; box-shadow: 0 0 6px rgba(34,197,94,0.5); }
.health-dot--offline { background: #ef4444; box-shadow: 0 0 6px rgba(239,68,68,0.5); }
.health-dot--degraded { background: #eab308; }
.health-st { font-size: 0.75rem; color: var(--muted); }
.health-err { font-size: 0.7rem; color: #f87171; }

@media (max-width: 900px) {
  #screen-app { flex-direction: column; }
  .sidebar { width: 100%; }
  .team-layout { grid-template-columns: 1fr; }
}