/* Charte alignée sur darest.ai : Poppins, encre bleu nuit, bleu Darest, quadrillage léger */
@font-face { font-family: Poppins; font-weight: 400; font-display: swap; src: url(/fonts/poppins-latin-400-normal.woff2) format("woff2"); }
@font-face { font-family: Poppins; font-weight: 500; font-display: swap; src: url(/fonts/poppins-latin-500-normal.woff2) format("woff2"); }
@font-face { font-family: Poppins; font-weight: 600; font-display: swap; src: url(/fonts/poppins-latin-600-normal.woff2) format("woff2"); }
@font-face { font-family: Poppins; font-weight: 700; font-display: swap; src: url(/fonts/poppins-latin-700-normal.woff2) format("woff2"); }

:root {
  --ink: #0a0f30;
  --muted: rgba(10, 15, 48, .58);
  --line: rgba(10, 15, 48, .14);
  --line-soft: rgba(10, 15, 48, .08);
  --grid: rgba(10, 15, 48, .043);
  --accent: #3848f1;       /* boutons darest.ai */
  --kicker: #216ff3;       /* surtitres darest.ai */
  --panel: #ffffff;
  --user: #eef0fe;
  --danger: #c62828;
  --radius: 12px;
  font-family: Poppins, -apple-system, "Segoe UI", sans-serif;
  font-size: 15.5px;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; color: var(--ink); }
body {
  background-color: #fff;
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 46px 46px;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.error { color: var(--danger); min-height: 1.2em; margin: 0; font-size: 14px; }
.kicker { color: var(--kicker); font-size: 11.5px; font-weight: 600; letter-spacing: 1.5px; text-transform: uppercase; }

button { font: inherit; cursor: pointer; border-radius: 28px; border: 1px solid transparent; padding: 11px 24px; }
button.primary { background: var(--accent); color: #f7f7f7; font-weight: 500; font-size: 15px; }
button.primary:hover { filter: brightness(1.07); }
button.primary:disabled { opacity: .5; cursor: default; }
button.danger { background: var(--danger); color: #fff; font-weight: 500; }
button.ghost { background: #fff; border-color: var(--line); color: var(--ink); }
button.ghost:hover { border-color: var(--accent); color: var(--accent); }
button.link { background: none; border: 0; padding: 0; color: var(--muted); text-decoration: underline; border-radius: 0; }
button.icon { padding: 6px 12px; border-radius: 10px; }

.logo { height: 40px; width: auto; display: block; }
.brand { display: flex; align-items: center; gap: 10px; }

/* Connexion */
.login { min-height: 100%; display: grid; place-items: center; padding: 20px; }
.card { width: min(440px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 36px 40px; display: grid; gap: 16px; }
.card h1 { font-size: 30px; line-height: 1.15; letter-spacing: -1px; font-weight: 700; margin: 0; }
.card .logo { height: 52px; margin-bottom: 6px; }
label { display: grid; gap: 6px; font-size: 13.5px; color: var(--muted); font-weight: 500; }
input, textarea { font: inherit; color: var(--ink); background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 11px 14px; outline: none; }
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(56, 72, 241, .12); }
.foot { text-align: center; font-size: 12px; color: var(--muted); margin-top: 18px; }
.foot a { color: var(--accent); }

/* Layout */
.app { display: grid; grid-template-columns: 258px 1fr; height: 100%; }
.app.with-artifact { grid-template-columns: 258px minmax(380px, 1fr) minmax(420px, 1.1fr); }
.sidebar { background: #fff; border-right: 1px solid var(--line-soft); padding: 26px 16px 16px; display: flex; flex-direction: column; gap: 14px; overflow-y: auto; }
.sidebar .logo { margin: 0 4px 10px; align-self: flex-start; height: 44px; width: auto; }
.sidebar #newChat { border-radius: 10px; padding: 9px 12px; font-size: 14px; white-space: nowrap; }
.section-label { font-size: 11px; text-transform: uppercase; letter-spacing: 1.5px; color: var(--muted); font-weight: 600; margin: 8px 4px 0; }
#presets { display: grid; gap: 2px; counter-reset: ex; }
.preset { text-align: left; background: transparent; padding: 9px 10px; border-radius: 8px; color: var(--ink); font-size: 14px; border-bottom: 1px solid var(--line-soft); }
.preset::before { counter-increment: ex; content: counter(ex) ". "; color: var(--kicker); font-weight: 600; }
.preset:hover { background: var(--user); }
.preset.active { background: var(--user); color: var(--accent); font-weight: 500; }
.preset .m { display: block; font-size: 11.5px; color: var(--muted); margin-top: 2px; font-weight: 400; }
.sidebar-foot { margin-top: auto; display: grid; gap: 8px; border-top: 1px solid var(--line-soft); padding-top: 12px; }
.me { display: flex; justify-content: space-between; align-items: center; font-size: 14px; font-weight: 500; }

.main { display: flex; flex-direction: column; min-width: 0; height: 100%; overflow: hidden; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 18px 28px 14px; border-bottom: 1px solid var(--line-soft); background: rgba(255, 255, 255, .85); backdrop-filter: blur(6px); }
#menu { display: none; }
.preset-name { font-weight: 700; font-size: 19px; letter-spacing: -.4px; }
.badge { white-space: nowrap; margin-left: auto; background: #fff4d6; color: #6b4b00; font-size: 12px; padding: 4px 10px; border-radius: 99px; font-weight: 500; }

.messages { flex: 1; min-height: 0; overflow-y: auto; padding: 28px 24px 10px; }
.msg { max-width: 780px; margin: 0 auto 20px; line-height: 1.6; }
.msg.user .bubble { background: var(--user); border: 1px solid rgba(56, 72, 241, .12); border-radius: var(--radius); padding: 10px 16px; white-space: pre-wrap; margin-left: auto; width: fit-content; max-width: 85%; }
.msg.assistant .bubble { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 20px; }
.msg.assistant .bubble > :first-child { margin-top: 0; }
.msg.assistant .bubble > :last-child { margin-bottom: 0; }
.msg .meta { font-size: 12px; color: var(--muted); margin-top: 6px; }
.msg.error .bubble { color: var(--danger); }
.bubble h1, .bubble h2, .bubble h3 { letter-spacing: -.4px; line-height: 1.25; }
.bubble pre { background: var(--ink); color: #e8eaff; padding: 14px 16px; border-radius: 10px; overflow-x: auto; position: relative; }
.bubble code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 13.5px; }
.bubble :not(pre) > code { background: var(--user); padding: 1px 6px; border-radius: 5px; }
.bubble a { color: var(--accent); }
.bubble table { border-collapse: collapse; }
.bubble th, .bubble td { border: 1px solid var(--line); padding: 6px 10px; }
.copy { position: absolute; top: 8px; right: 8px; font-size: 12px; padding: 3px 10px; background: rgba(255, 255, 255, .12); color: #e8eaff; border-radius: 6px; }
.typing:empty::after, .typing::after { content: "▍"; animation: blink 1s steps(1) infinite; color: var(--accent); }
@keyframes blink { 50% { opacity: 0; } }

.empty { max-width: 640px; margin: 9vh auto 0; }
.empty h2 { font-weight: 700; font-size: 34px; line-height: 1.15; letter-spacing: -1.1px; margin: 8px 0; }
.starter { margin-top: 22px; background: #fff; border: 1px solid var(--line); color: var(--ink); text-align: left; max-width: 100%; border-radius: var(--radius); padding: 18px 22px; }
.starter:hover { border-color: var(--accent); }

.composer { max-width: 828px; width: 100%; margin: 0 auto; padding: 12px 24px 4px; }
.composer .box { background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 10px 10px 8px 14px; box-shadow: 0 2px 14px rgba(10, 15, 48, .06); }
.composer .box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(56, 72, 241, .10); }
.composer textarea { width: 100%; border: 0; padding: 4px 2px; resize: none; max-height: 40vh; line-height: 1.5; box-shadow: none !important; background: transparent; }
.tools { display: flex; align-items: center; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.tools .spacer { flex: 1; }
.tool { background: #fff; border: 1px solid var(--line); color: var(--ink); border-radius: 99px; padding: 5px 12px; font-size: 13px; }
.tool:hover { border-color: var(--accent); color: var(--accent); }
.tool[aria-pressed="true"] { background: var(--user); border-color: var(--accent); color: var(--accent); font-weight: 500; }
.tools .primary, .tools .danger { padding: 8px 20px; }
.disclaimer { text-align: center; margin: 4px 0 12px; }
.attachments { display: flex; flex-wrap: wrap; gap: 6px; max-width: 828px; width: 100%; margin: 0 auto; padding: 0 24px; }
.attachments:empty { display: none; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: #fff; border: 1px solid var(--line); border-radius: 99px; padding: 4px 6px 4px 12px; font-size: 13px; max-width: 280px; }
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip.loading { opacity: .6; }
.chip.loading::after { content: "…"; margin-right: 6px; }
.chip button { border: 0; background: var(--user); border-radius: 99px; padding: 0 7px; font-size: 13px; line-height: 20px; color: var(--muted); }
.msg.user .files { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; margin-bottom: 6px; }
.msg.user .files .chip { padding: 4px 12px; background: var(--user); border-color: rgba(56, 72, 241, .18); }
.dropzone { position: fixed; inset: 12px; border: 2px dashed var(--accent); border-radius: 18px; background: rgba(238, 240, 254, .92); display: grid; place-items: center; font-size: 22px; font-weight: 600; color: var(--accent); z-index: 50; pointer-events: none; }

@media (max-width: 800px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 22% 0 0; z-index: 10; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 0 0 40px rgba(10, 15, 48, .25); }
  #menu { display: inline-block; }
  .topbar { padding: 12px 16px; }
  .preset-name { font-size: 16px; }
  .empty h2 { font-size: 26px; }
  .card { padding: 28px 24px; }
}

/* Historique */
#history { display: grid; gap: 1px; min-width: 0; }
.sidebar { min-width: 0; }
.hist { display: flex; align-items: center; border-radius: 8px; min-width: 0; }
.hist:hover, .hist.active { background: var(--user); }
.hist-open { flex: 1; min-width: 0; text-align: left; background: none; border: 0; border-radius: 8px; padding: 7px 10px; font-size: 13.5px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hist.active .hist-open { color: var(--accent); font-weight: 500; }
.hist-del { visibility: hidden; background: none; border: 0; padding: 2px 8px; color: var(--muted); border-radius: 6px; }
.hist:hover .hist-del { visibility: visible; }
.hist-del:hover { color: var(--danger); }
.titles { min-width: 0; }
.titles .preset-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Accueil */
.caps { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px; margin-top: 18px; }
.caps .starter { margin-top: 0; font-size: 14px; }

/* Cartes artefact dans la conversation */
.art-card { display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; margin: 10px 0; color: var(--ink); }
.art-card:hover { border-color: var(--accent); }
.art-ico { width: 40px; height: 40px; border-radius: 10px; background: var(--user); color: var(--accent); display: grid; place-items: center; font-size: 20px; flex: none; }
.art-txt { display: grid; flex: 1; min-width: 0; }
.art-txt b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.art-txt small { color: var(--muted); font-size: 12.5px; }
.art-go { color: var(--accent); font-weight: 500; font-size: 14px; }
.art-card.building { cursor: default; }
.art-card.building .art-ico { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .4; } }

/* Sources web */
.sources { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 8px; }
.sources a { font-size: 12.5px; background: #fff; border: 1px solid var(--line); border-radius: 99px; padding: 2px 10px; color: var(--accent); text-decoration: none; }
.sources a:hover { border-color: var(--accent); }

/* Panneau artefact */
.artifact-panel { display: flex; flex-direction: column; border-left: 1px solid var(--line-soft); background: #fff; min-width: 0; height: 100%; }
.artifact-panel.full { position: fixed; inset: 0; z-index: 40; border: 0; }
.artifact-head { display: flex; align-items: center; gap: 6px; padding: 12px 14px; border-bottom: 1px solid var(--line-soft); }
.artifact-title { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seg { display: inline-flex; background: var(--user); border-radius: 99px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 5px 12px; font-size: 13px; color: var(--muted); border-radius: 99px; }
.seg button.on { background: #fff; color: var(--ink); font-weight: 500; box-shadow: 0 1px 3px rgba(10, 15, 48, .12); }
.artifact-panel iframe { flex: 1; width: 100%; border: 0; background: #fff; }
.artifact-code { flex: 1; margin: 0; overflow: auto; background: var(--ink); color: #e8eaff; padding: 16px; font-size: 13px; }

@media (max-width: 800px) {
  .app.with-artifact { grid-template-columns: 1fr; }
  .artifact-panel { position: fixed; inset: 0; z-index: 30; }
  .tool { padding: 5px 10px; }
}
