:root { --bg: #f5f6f8; --fg: #1f2328; --accent: #0f6cbd; --muted: #656d76; }
* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, sans-serif; background: var(--bg); color: var(--fg); }
header { display: flex; align-items: center; gap: 1rem; padding: .75rem 1.5rem; background: var(--accent); color: #fff; }
header h1 { font-size: 1.2rem; margin: 0; }
.badge { font-size: .75rem; padding: .15rem .5rem; border: 1px solid #fff; border-radius: 1rem; }
main { max-width: 960px; margin: 2rem auto; padding: 0 1rem; }
.card { background: #fff; border-radius: 8px; padding: 1.5rem; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.muted { color: var(--muted); }
form { display: grid; gap: .75rem; margin-top: 1rem; }
label { display: grid; gap: .25rem; font-weight: 600; font-size: .9rem; }
input { padding: .5rem; border: 1px solid #d0d7de; border-radius: 6px; font: inherit; font-weight: normal; }
button { padding: .6rem 1rem; border: 0; border-radius: 6px; background: var(--accent); color: #fff; font: inherit; cursor: pointer; justify-self: start; }
button:disabled { opacity: .6; cursor: wait; }
code { background: #eef1f4; padding: .1rem .3rem; border-radius: 4px; }
.error { color: #b42318; }
.warn { color: #9a6700; }
table.perms { border-collapse: collapse; width: 100%; font-size: .9rem; }
table.perms th, table.perms td { text-align: left; padding: .3rem .5rem; border-bottom: 1px solid #eaeef2; }
table.perms tr.bad td { color: #b42318; font-weight: 600; }
ul.groups { list-style: none; padding: 0; }
ul.groups li { display: flex; align-items: center; gap: .75rem; padding: .4rem 0; border-bottom: 1px solid #eaeef2; }
ul.groups button { padding: .3rem .7rem; }
a.button { display: inline-block; padding: .6rem 1rem; border-radius: 6px; background: var(--accent); color: #fff; text-decoration: none; }
header .user { margin-left: auto; display: flex; align-items: center; gap: .75rem; }
header .user button, header .user button.secondary { background: transparent; color: #fff; border: 1px solid #fff; padding: .3rem .7rem; }
main.wide { max-width: 1280px; margin: 1rem auto; }
.chat { display: grid; grid-template-columns: 260px 1fr; gap: 1rem; height: calc(100vh - 6rem); }
.sidebar { display: flex; flex-direction: column; gap: .75rem; background: #fff; border-radius: 8px; padding: .75rem; box-shadow: 0 1px 3px rgba(0,0,0,.08); min-height: 0; }
.sidebar > button { justify-self: stretch; width: 100%; }
ul.conversations { list-style: none; padding: 0; margin: 0; overflow-y: auto; flex: 1; }
ul.conversations li { display: flex; align-items: center; gap: .25rem; padding: .45rem .5rem; border-radius: 6px; cursor: pointer; font-size: .9rem; }
ul.conversations li:hover { background: #f0f3f6; }
ul.conversations li.active { background: #e3edf8; font-weight: 600; }
ul.conversations .title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
ul.conversations .delete { background: transparent; color: var(--muted); padding: 0 .4rem; font-size: 1.1rem; }
.perm-badge { width: 100%; font-size: .85rem; }
.perm-badge.ok { background: #1a7f37; }
.perm-badge.bad { background: #b42318; }
.small { font-size: .8rem; margin: .25rem 0 0; }
.thread { display: flex; flex-direction: column; min-height: 0; background: #fff; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.turns { flex: 1; overflow-y: auto; padding: 1rem 1.25rem; }
.empty { max-width: 640px; margin: 3rem auto; text-align: center; }
.msg { display: flex; margin: .6rem 0; }
.msg.user { justify-content: flex-end; }
.msg .bubble { max-width: 85%; padding: .6rem .9rem; border-radius: 10px; line-height: 1.45; overflow-wrap: anywhere; }
.msg.user .bubble { background: var(--accent); color: #fff; }
.msg.assistant .bubble { background: #f6f8fa; border: 1px solid #eaeef2; width: 85%; }
.answer p { margin: .4rem 0; }
.answer h4 { margin: .6rem 0 .3rem; }
pre { background: #1f2328; color: #e6edf3; padding: .6rem .8rem; border-radius: 6px; overflow-x: auto; font-size: .85rem; margin: .4rem 0; }
pre code { background: none; padding: 0; color: inherit; }
.status { font-weight: 600; padding: .3rem .6rem; border-radius: 6px; margin-bottom: .4rem; }
.status-blocked, .status-error, .status-refused { background: #fdecea; color: #b42318; }
.status-incomplete { background: #fff8c5; color: #9a6700; }
.proposal { border: 1px solid #d4a72c; background: #fffbea; border-radius: 8px; padding: .6rem .8rem; margin: .6rem 0; }
.proposal .tag { background: #9a6700; color: #fff; font-size: .75rem; padding: .1rem .45rem; border-radius: 1rem; }
.code-label { display: flex; justify-content: space-between; align-items: center; font-size: .8rem; font-weight: 600; margin-top: .4rem; }
.code-label .copy { padding: .15rem .5rem; font-size: .75rem; }
.perm-request { border: 1px solid #0f6cbd; background: #eef5fc; border-radius: 8px; padding: .6rem .8rem; margin: .6rem 0; }
details.calls { margin-top: .5rem; font-size: .85rem; }
details.calls li.bad { color: #b42318; }
.thinking { font-style: italic; }
.ask { display: flex; gap: .5rem; padding: .75rem; border-top: 1px solid #eaeef2; margin: 0; align-items: flex-end; }
.ask textarea { flex: 1; padding: .5rem; border: 1px solid #d0d7de; border-radius: 6px; font: inherit; resize: vertical; }
dialog { border: 0; border-radius: 8px; max-width: 720px; width: 90%; box-shadow: 0 8px 30px rgba(0,0,0,.25); }
button.secondary { background: #eef1f4; color: var(--fg); }
.sidebar > button.secondary { width: 100%; }
dialog form { margin-top: .75rem; }
dialog .row { display: flex; gap: .5rem; }
p.ok { color: #1a7f37; }
.card .row { display: flex; gap: .5rem; }
.login form .row { margin-top: .5rem; }
[hidden] { display: none !important; }

.ask .attach { padding: .55rem .7rem; font-size: 1.1rem; }
.files { display: flex; flex-wrap: wrap; gap: .4rem; padding: .5rem .75rem 0; border-top: 1px solid #eaeef2; }
.file-chip { display: inline-flex; align-items: center; gap: .35rem; font-size: .82rem; padding: .25rem .6rem; border-radius: 1rem; background: #eef5fc; border: 1px solid #c9dcf0; max-width: 100%; }
.file-chip.generated { background: #eefaf1; border-color: #b7e2c4; }
.file-chip a { color: var(--fg); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 22rem; }
.files-note { margin: .35rem .75rem 0; font-size: .82rem; }
.files-note.ok { color: #1a7f37; }
.generated-files { border: 1px solid #b7e2c4; background: #eefaf1; border-radius: 8px; padding: .5rem .8rem; margin: .6rem 0; font-size: .9rem; }
.generated-files ul { margin: .3rem 0 0; padding-left: 1rem; list-style: none; }
.thread.dragging { outline: 3px dashed var(--accent); outline-offset: -6px; }

/* Comptes locaux (O365ADMIN-1) */
.row.spread { justify-content: space-between; align-items: center; }
table.accounts { width: 100%; border-collapse: collapse; margin: .5rem 0 1rem; }
table.accounts th, table.accounts td { text-align: left; padding: .45rem .5rem; border-bottom: 1px solid #e3e7eb; vertical-align: middle; }
table.accounts tr.disabled td { color: #8a949e; }
table.accounts td.actions { display: flex; flex-wrap: wrap; gap: .35rem; }
table.accounts td.actions button { padding: .3rem .6rem; }
table.accounts .badge { border-color: var(--accent); color: var(--accent); }

/* O365ADMIN-3 : conversations partagées (auteur, lecture seule), connexion Microsoft, site bloqué. */
ul.conversations .conv-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
ul.conversations .owner { font-size: .75rem; color: var(--muted); font-weight: normal; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
ul.conversations li.readonly .title { font-style: italic; }
.readonly-note { margin: .5rem 0 0; padding: .6rem .8rem; border-radius: 6px; background: #f3f0e6; border: 1px solid #e3dcc2; font-size: .9rem; }
a.button { display: inline-block; padding: .55rem 1rem; border-radius: 6px; background: #0b5cad; color: #fff; text-decoration: none; font-weight: 600; }
a.button:hover { background: #094b8d; }
.card.login { text-align: center; }
h2.blocked { color: #b42318; }

/* Réglages de l'IA (O365ADMIN-4) */
#ai-settings { margin-bottom: 1rem; }
fieldset { border: 1px solid #d0d7de; border-radius: 6px; padding: .5rem .75rem; display: grid; gap: .35rem; }
legend { font-weight: 600; font-size: .9rem; padding: 0 .25rem; }
label.choice { display: flex; align-items: center; gap: .5rem; font-weight: normal; cursor: pointer; }
.choices-row { display: flex; flex-wrap: wrap; gap: .25rem 1.25rem; }
#ai-result.ok { color: #1a7f37; }
.card .row { align-items: center; }

/* Étape en cours de l'IA (O365ADMIN-4) */
.progress-live { display: inline-flex; align-items: center; gap: .5rem; }
.spinner { width: .85rem; height: .85rem; border: 2px solid #d0d7de; border-top-color: var(--accent); border-radius: 50%;
  animation: spin .9s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }
#ai-token-form { margin-top: 1rem; }
#ai-token-result.ok { color: #1a7f37; }
#ai-token-result.error { color: #b42318; }

/* Affichage adaptatif : téléphone, tablette, bureau (O365ADMIN-6) */
html { -webkit-text-size-adjust: 100%; }
body { min-height: 100vh; min-height: 100dvh; }
header { flex-wrap: wrap; row-gap: .4rem; padding-top: max(.75rem, env(safe-area-inset-top));
  padding-left: max(1.5rem, env(safe-area-inset-left)); padding-right: max(1.5rem, env(safe-area-inset-right)); }
header .user { flex-wrap: wrap; justify-content: flex-end; min-width: 0; }
header .user > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 16rem; }
img, video, svg { max-width: 100%; }
input, textarea, select { max-width: 100%; }
.chat { height: calc(100vh - 6rem); height: calc(100dvh - 6rem); }
.thread { min-width: 0; }
.thread-bar { display: none; }
.sidebar-backdrop { display: none; }
.answer table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; }
.answer th, .answer td { border: 1px solid #eaeef2; padding: .25rem .5rem; text-align: left; }
.table-scroll, table.perms, table.accounts { display: block; overflow-x: auto; }
.code-block { min-width: 0; }
.card { overflow-wrap: anywhere; }
dialog { max-height: 90vh; max-height: 90dvh; overflow-y: auto; }

@media (max-width: 760px) {
  header { gap: .5rem; padding: .5rem max(.75rem, env(safe-area-inset-right)) .5rem max(.75rem, env(safe-area-inset-left));
    padding-top: max(.5rem, env(safe-area-inset-top)); }
  header h1 { font-size: 1.05rem; }
  header .user { gap: .4rem; margin-left: auto; }
  header .user > span:first-child { max-width: 9rem; }
  header .user .badge { display: none; }
  header .user button, header .user button.secondary { padding: .25rem .55rem; font-size: .85rem; }
  main { margin: 1rem auto; padding: 0 .75rem; }
  main.wide { margin: 0; padding: 0; max-width: none; }
  .card { padding: 1rem; }
  .card .row, dialog .row { flex-wrap: wrap; }
  /* Le fil occupe tout l'écran sous l'en-tête ; la liste devient un panneau latéral. */
  body:has(main.wide) { display: flex; flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden; }
  body:has(main.wide) main.wide { flex: 1; min-height: 0; }
  .chat { display: block; height: 100%; }
  .thread { height: 100%; border-radius: 0; box-shadow: none; }
  .thread-bar { display: flex; align-items: center; gap: .5rem; padding: .4rem .6rem; border-bottom: 1px solid #eaeef2; }
  .thread-bar button { padding: .35rem .7rem; font-size: .9rem; flex: none; }
  .thread-title { flex: 1; min-width: 0; font-weight: 600; font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .sidebar { position: fixed; top: 0; bottom: 0; left: 0; z-index: 20; width: min(85vw, 320px); border-radius: 0;
    padding: max(.75rem, env(safe-area-inset-top)) .75rem max(.75rem, env(safe-area-inset-bottom)) max(.75rem, env(safe-area-inset-left));
    transform: translateX(-105%); transition: transform .2s ease; box-shadow: 0 0 24px rgba(0,0,0,.25); }
  .sidebar.open { transform: none; }
  .sidebar-backdrop:not([hidden]) { display: block; position: fixed; inset: 0; z-index: 15; background: rgba(0,0,0,.35); }
  ul.conversations li { padding: .65rem .5rem; }
  ul.conversations .delete { padding: .2rem .6rem; }
  .turns { padding: .75rem; }
  .empty { margin: 1.5rem auto; }
  .msg .bubble { max-width: 92%; }
  .msg.assistant .bubble { width: 100%; max-width: 100%; }
  .ask { padding: .5rem; padding-bottom: max(.5rem, env(safe-area-inset-bottom)); gap: .4rem; }
  .ask textarea { min-height: 2.75rem; resize: none; }
  .ask button[type="submit"] { padding: .6rem .8rem; }
  /* 16 px : évite le zoom automatique d'iOS sur les champs. */
  input, textarea, select { font-size: 16px; }
  .file-chip a { max-width: 12rem; }
  dialog { width: calc(100% - 1.5rem); padding: 1rem; }
  .choices-row { flex-direction: column; }
}
@media (max-width: 760px) and (prefers-reduced-motion: reduce) { .sidebar { transition: none; } }
@media (max-width: 420px) {
  header .badge { display: none; }
  header .user > span:first-child { display: none; }
}

/* Application installable (O365ADMIN-6) */
header h1 { display: inline-flex; align-items: center; gap: .5rem; }
header h1 .logo { width: 1.5rem; height: 1.5rem; border-radius: 4px; flex: none; }
@media (max-width: 760px) { header h1 .logo { width: 1.3rem; height: 1.3rem; } }
header button.install { background: #fff; color: var(--accent); padding: .25rem .7rem; font-size: .85rem; font-weight: 600; }
/* En-tête : icônes seules sur petit téléphone, pour tenir sur une ligne (O365ADMIN-6). */
header .user button .icon { display: none; }
@media (max-width: 480px) {
  header .user button .icon { display: block; }
  header .user button .label { display: none; }
  header .user button, header .user button.secondary { display: inline-flex; align-items: center; justify-content: center; min-width: 2.25rem; min-height: 2.25rem; padding: .2rem .45rem; }
  header button.install { padding: .2rem .5rem; }
}
/* Téléphone à l'horizontale : peu de hauteur, la zone de saisie est réduite au profit du fil. */
@media (max-height: 500px) and (max-width: 1024px) {
  header { padding-top: .35rem; padding-bottom: .35rem; }
  .thread-bar { padding: .25rem .6rem; }
  .ask textarea { height: 2.6rem; min-height: 2.6rem; resize: none; }
  .ask { padding-top: .35rem; padding-bottom: max(.35rem, env(safe-area-inset-bottom)); }
}
/* Choix de la langue (O365ADMIN-7) : drapeau + nom ; sur mobile, drapeau seul dans l'en-tête (le menu garde les noms). */
.lang-picker { position: relative; display: inline-flex; }
header .lang-picker .lang-button { display: inline-flex; align-items: center; gap: .45rem; background: transparent; color: #fff; border: 1px solid #fff; padding: .3rem .7rem; }
.lang-picker .flag { display: block; flex: none; border-radius: 2px; box-shadow: 0 0 0 1px rgba(0, 0, 0, .15); }
.lang-picker .lang-button::after { content: ""; border: 4px solid transparent; border-top-color: currentColor; margin-top: 4px; }
.lang-menu { position: absolute; right: 0; top: calc(100% + 4px); z-index: 50; margin: 0; padding: .25rem; list-style: none; min-width: 10rem;
  background: #fff; color: var(--fg); border-radius: 6px; box-shadow: 0 6px 20px rgba(0, 0, 0, .18); }
.lang-menu li { display: flex; align-items: center; gap: .6rem; padding: .5rem .7rem; border-radius: 4px; cursor: pointer; white-space: nowrap; }
.lang-menu li:hover, .lang-menu li:focus { background: #eef1f4; outline: none; }
.lang-menu li[aria-selected="true"] { font-weight: 600; }
@media (max-width: 760px) {
  header .lang-picker .lang-button { padding: .25rem .55rem; font-size: .85rem; }
  header .lang-picker .lang-name { display: none; }
}
@media (max-width: 480px) {
  header .lang-picker .lang-button { min-width: 2.25rem; min-height: 2.25rem; padding: .2rem .45rem; justify-content: center; gap: .3rem; }
}
