/* Barre du haut regroupée + adaptation mobile (chargé après style.css). */
header.topbar { flex-wrap: nowrap; gap: 14px; padding: 10px 20px; }
header.topbar .brand { flex: 0 0 auto; }
header.topbar .search-form { flex: 1 1 160px; min-width: 120px; max-width: 300px; }
header.topbar nav { display: flex; align-items: center; gap: 6px; margin-left: auto; min-width: 0; }
header.topbar nav a { margin-left: 0; white-space: nowrap; }
.nav-links { display: flex; align-items: center; gap: 4px; }
.nav-links a, .nav-menu summary { padding: 6px 10px; border-radius: 8px; }
.nav-links a:hover, .nav-links a.active, .nav-menu summary:hover, .nav-menu[open] summary { background: var(--card-hover); }
.nav-links a.active { box-shadow: inset 0 -2px 0 var(--blue); }
.nav-menu { position: relative; }
.nav-menu summary { list-style: none; cursor: pointer; color: var(--muted); font-size: 0.92rem; white-space: nowrap; user-select: none; }
.nav-menu summary::-webkit-details-marker { display: none; }
.nav-menu summary::after { content: "▾"; margin-left: 6px; font-size: .75em; }
.nav-menu.has-active summary { color: var(--text); box-shadow: inset 0 -2px 0 var(--blue); }
.nav-menu-list {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 300; min-width: 190px;
  display: flex; flex-direction: column; padding: 6px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 18px 50px #00000055;
}
.nav-menu-list a { padding: 8px 12px; border-radius: 8px; }
.nav-menu-list a:hover, .nav-menu-list a.active { background: var(--card-hover); }
.nav-tools { display: flex; align-items: center; gap: 8px; margin-left: 6px; padding-left: 10px; border-left: 1px solid var(--line); }
.nav-tools .notif-wrap { margin-left: 0; }
.nav-user { color: var(--muted); font-size: 0.88rem; white-space: nowrap; max-width: 160px; overflow: hidden; text-overflow: ellipsis; }
.nav-user a { color: inherit; }
.nav-toggle { display: none; margin-left: auto; font-size: 1.1rem; line-height: 1; }

/* Écrans moyens : la recherche passe sous forme compacte */
@media (max-width: 1280px) { .nav-user small { display: none; } header.topbar .search-form { max-width: 200px; } }
@media (max-width: 1100px) { header.topbar .brand-text { display: none; } }

/* Mobile / tablette : menu burger */
@media (max-width: 900px) {
  header.topbar { flex-wrap: wrap; padding: 10px 14px; }
  header.topbar .brand-text { display: flex; }
  header.topbar .search-form { order: 3; flex: 1 0 100%; max-width: none; }
  .nav-toggle { display: inline-block; }
  header.topbar nav { display: none; order: 4; flex: 1 0 100%; flex-direction: column; align-items: stretch; gap: 8px; margin: 0; }
  header.topbar nav.open { display: flex; max-height: calc(100vh - 140px); overflow-y: auto; }
  .nav-links { flex-direction: column; align-items: stretch; }
  .nav-links a, .nav-menu summary { padding: 10px 12px; }
  .nav-menu-list { position: static; box-shadow: none; border: 0; background: transparent; padding: 0 0 0 12px; }
  .nav-tools { margin: 0; padding: 10px 0 0; border-left: 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
  .nav-user { max-width: none; flex: 1; }
  .notif-panel { position: fixed; left: 8px; right: 8px; top: 64px; width: auto; max-width: none; }
}

/* Mise en page mobile des pages (Utilisateurs, Chatbot, Agent IA…) */
@media (max-width: 720px) {
  main, body.uns main { padding: 18px 12px 80px; }
  body.uns .card, .card { padding: 14px; }
  .card[style*="max-width"] { max-width: 100% !important; }
  h1 { font-size: 1.3rem; }
  .field[style*="min-width"] { min-width: 0 !important; flex: 1 1 100% !important; }
  form[style*="display:flex"] { flex-wrap: wrap; }
  form input[style*="max-width"], form select[style*="max-width"] { max-width: 100% !important; }
  .card { overflow-x: auto; }
  table { display: block; overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; }
  td[style*="max-width"] { max-width: none !important; }
  .chat-widget { right: 14px; bottom: 14px; }
  .chat-panel { position: fixed; right: 8px; left: 8px; bottom: 80px; width: auto; height: min(70vh, 520px); }
  .chat-msg { max-width: 92%; }
  .chat-input-row input, .chat-input-row textarea, input, select, textarea { font-size: 16px; }
  .agent-task-head { flex-wrap: wrap; }
  .agent-task-date { white-space: normal; }
  .job-log, pre { max-width: 100%; overflow-x: auto; }
}
