/* ============================================================
   JARVIS WORKSPACE - charge en dernier, surcharge ciblee.
   Tokens existants uniquement (--ink, --line, --accent...).
   ============================================================ */

/* ---------- sidebar repliable ---------- */
.rail { position: relative; transition: width .24s cubic-bezier(.2,.8,.2,1), padding .24s cubic-bezier(.2,.8,.2,1); }
.rail-toggle {
  position: absolute; top: 14px; right: 12px; z-index: 2;
  width: 32px; height: 32px; display: grid; place-items: center;
  border: 1px solid transparent; border-radius: 9px; background: transparent; color: var(--text-faint); cursor: pointer;
}
.rail-toggle svg { width: 18px; height: 18px; }
.rail-toggle:hover { color: var(--text); border-color: var(--line-soft); background: var(--ink-raised); }
.rail-link { position: relative; white-space: nowrap; }
.rail-label { overflow: hidden; text-overflow: ellipsis; }

@media (min-width: 821px) {
  html[data-rail="collapsed"] { --rail: 72px; }
  html[data-rail="collapsed"] body .rail { padding: 58px 10px 16px; overflow-x: hidden; }
  html[data-rail="collapsed"] body .rail-toggle { right: 50%; transform: translateX(50%); }
  html[data-rail="collapsed"] body .rail-mark { margin-bottom: 26px; }
  html[data-rail="collapsed"] body .rail-mark > span:not(.brand-orb),
  html[data-rail="collapsed"] body .rail-mark small,
  html[data-rail="collapsed"] body .rail-label,
  html[data-rail="collapsed"] body .who-name,
  html[data-rail="collapsed"] body .rail-foot { display: none; }
  html[data-rail="collapsed"] body .brand-orb { width: 48px; height: 48px; margin: 0; }
  html[data-rail="collapsed"] body .rail-link { justify-content: center; padding: 13px 0; gap: 0; }
  html[data-rail="collapsed"] body .rail-badge { position: absolute; top: 5px; right: 7px; min-width: 16px; height: 16px; font-size: 9px; }
  html[data-rail="collapsed"] body .rail .who { flex-direction: column; align-items: center; }
  html[data-rail="collapsed"] body .who-btn { padding: 4px; justify-content: center; }
}

/* ---------- Command Center (desktop) ---------- */
.ws { display: none; }

@media (min-width: 901px) {
  body[data-view="chat"] { --thread-w: clamp(340px, 28vw, 440px); }
  html[data-thread="hidden"] body[data-view="chat"] { --thread-w: 0px; }

  body[data-view="chat"] .ws {
    display: block; position: absolute; top: 86px; left: 0; right: var(--thread-w); bottom: 0;
    transition: right .24s cubic-bezier(.2,.8,.2,1);
  }
  body[data-view="chat"] .scroll {
    position: absolute; top: 86px; right: 0; bottom: 0; width: var(--thread-w);
    padding: 22px 20px 28px; border-left: 1px solid var(--line-soft); background: var(--ink);
  }
  html[data-thread="hidden"] body[data-view="chat"] .scroll { display: none; }
  body[data-view="chat"] .thread { max-width: none; gap: 20px; }
  body[data-view="chat"] .turn-you, body[data-view="chat"] .turn-jarvis { max-width: 100%; font-size: 13.5px; }
  body[data-view="chat"] .dock {
    left: var(--rail); right: var(--thread-w); background: none; padding: 8px 28px 20px;
    transition: right .24s cubic-bezier(.2,.8,.2,1);
  }
  body[data-view="chat"] .dock-inner { max-width: 680px; }

  .ws-canvas { position: absolute; inset: 0 0 88px 0; }
  .ws-core {
    position: absolute; left: 50%; top: 50%; transform: translate(-50%, -52%);
    display: flex; flex-direction: column; align-items: center; gap: 12px; z-index: 1;
    max-width: min(460px, 80%); text-align: center; pointer-events: none;
  }
  .ws-core .orb-host { pointer-events: auto; }
  .ws-core .orb { width: clamp(180px, 27vmin, 300px); height: clamp(180px, 27vmin, 300px); cursor: pointer; }
  .ws-core.has-windows .orb { width: clamp(140px, 18vmin, 200px); height: clamp(140px, 18vmin, 200px); }
  .ws-windows { position: absolute; inset: 0; z-index: 2; pointer-events: none; }
  .ws-win { pointer-events: auto; }
  .ws-tray { position: absolute; left: 20px; right: 20px; bottom: 6px; z-index: 3; }
}

/* ---------- noyau: orbe, etat, activite ---------- */
.ws-core .orb-host { position: relative; border-radius: 50%; }
.ws-core .orb-host::before {
  content: ""; position: absolute; inset: 6%; border-radius: 50%;
  border: 1px solid transparent; opacity: 0; pointer-events: none;
  transition: opacity .4s ease;
}
.ws-core.is-working .orb-host::before {
  opacity: 1;
  border-top-color: var(--accent); border-right-color: color-mix(in srgb, var(--accent) 35%, transparent);
  animation: ws-orbit 2.8s linear infinite;
}
@keyframes ws-orbit { to { transform: rotate(360deg); } }
.ws-status { font-size: 13px; color: var(--text-dim); letter-spacing: -.005em; min-height: 18px; }
.ws-reply { width: min(460px, 100%); pointer-events: auto; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.ws-reply[hidden], body.voice-on .ws-reply { display: none; }
.ws-reply-text {
  max-height: 22vh; overflow: auto; font-size: 14px; line-height: 1.55; color: var(--text); text-align: center;
  scrollbar-width: none; mask-image: linear-gradient(to bottom, transparent 0, #000 18px);
}
.ws-reply-text::-webkit-scrollbar { display: none; }
.ws-reply-text p { margin: 0 0 6px; }
.ws-reply-open { font: inherit; font-size: 11.5px; color: var(--text-faint); background: none; border: 0; padding: 4px 8px; border-radius: 7px; cursor: pointer; }
.ws-reply-open:hover { color: var(--text); background: var(--ink-raised); }
body.voice-on .ws-status { display: none; }
.ws-core .stage-state, .ws-core .stage-tools, .ws-core .stage-text { display: none; }
body.voice-on .ws-core .stage-state, body.voice-on .ws-core .stage-text { display: block; }
body.voice-on .ws-core .stage-tools.is-on, body.voice-on .ws-core .stage-tools.is-off { display: inline-flex; }
.ws-core .stage-text { font-size: 15px; max-height: 14vh; }

/* La scene vocale devient un bandeau quand l'orbe vit dans le workspace. */
body[data-view="chat"] .stage {
  top: auto; left: var(--rail); right: var(--thread-w, 0px); bottom: 0; height: auto;
  background: none; backdrop-filter: none; -webkit-backdrop-filter: none;
  pointer-events: none; grid-template-rows: auto; padding: 0 20px 18px; z-index: 60;
}
body[data-view="chat"] .stage .stage-core { display: none; }
body[data-view="chat"] .stage .stage-foot { pointer-events: auto; padding-top: 0; }
body[data-view="chat"] .stage .stage-log { max-height: 6vh; font-size: 11px; }

/* ---------- fenetres ---------- */
.ws-win {
  position: absolute; width: var(--ws-w, 260px); max-height: calc(100% - 16px);
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--ink-raised); color: var(--text);
  border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 22px 60px rgba(0, 0, 0, .34), 0 2px 8px rgba(0, 0, 0, .18);
}
/* Largeur fixee a la creation (--ws-w): une fenetre ne grandit pas vers l'orbe en changeant d'etat. */
.ws-win.is-big { width: min(560px, calc(100% - 32px)); }
.ws-win.is-focused { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.ws-win.is-dragging { box-shadow: 0 30px 80px rgba(0, 0, 0, .45); user-select: none; }
.ws-win[hidden] { display: none; }

.ws-win-bar {
  display: flex; align-items: center; gap: 8px; padding: 9px 8px 9px 12px;
  border-bottom: 1px solid var(--line-soft); cursor: grab; touch-action: none; user-select: none;
}
.ws-win.is-dragging .ws-win-bar { cursor: grabbing; }
.ws-win-title { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.ws-win-title small { display: flex; align-items: center; gap: 7px; font-size: 10.5px; color: var(--text-faint); min-width: 0; }
.ws-kicker { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ws-win-title b { font-size: 12.5px; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ws-state { font-size: 9px; letter-spacing: .06em; color: var(--text-faint); padding: 2px 6px; border-radius: 5px; background: var(--ink-high); flex: none; }
.ws-btn {
  width: 26px; height: 26px; display: grid; place-items: center; flex: none;
  border: 0; border-radius: 7px; background: transparent; color: var(--text-faint); cursor: pointer;
}
.ws-btn svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.ws-btn:hover { background: var(--ink-high); color: var(--text); }

.ws-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-faint); flex: none; }
[data-status="RUNNING"] .ws-dot, [data-status="RUNNING"].ws-dot, .ws-chip[data-status="RUNNING"] .ws-dot { background: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
[data-status="DONE"] .ws-dot { background: var(--ok); }
[data-status="FAILED"] .ws-dot, [data-status="INTERRUPTED"] .ws-dot { background: var(--bad); }
[data-status="WAITING"] .ws-dot, [data-status="QUEUED"] .ws-dot { background: var(--warn); }
.ws-win[data-status="RUNNING"] .ws-state { color: var(--accent); }
.ws-win[data-status="DONE"] .ws-state, .ws-state[data-s="DONE"] { color: var(--ok); }
.ws-win[data-status="FAILED"] .ws-state, .ws-win[data-status="INTERRUPTED"] .ws-state, .ws-state[data-s="FAILED"], .ws-state[data-s="INTERRUPTED"] { color: var(--bad); }
.ws-win[data-status="WAITING"] .ws-state { color: var(--warn); }

.ws-progress { height: 2px; background: transparent; flex: none; overflow: hidden; }
.ws-win[data-status="RUNNING"] .ws-progress {
  background: linear-gradient(90deg, transparent 0%, var(--accent) 45%, transparent 90%);
  background-size: 40% 100%; background-repeat: no-repeat;
  animation: ws-sweep 1.6s ease-in-out infinite;
}
@keyframes ws-sweep { from { background-position: -40% 0; } to { background-position: 140% 0; } }

.ws-win-body { overflow: auto; min-height: 0; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.ws-figure { margin: 0; border-radius: 10px; overflow: hidden; background: var(--ink-high); }
.ws-figure img { display: block; width: 100%; height: auto; max-height: 60vh; object-fit: contain; }
.ws-win.is-big .ws-figure img { max-height: calc(100vh - 300px); }
.ws-figure.is-preview img { filter: blur(6px) saturate(.9); transform: scale(1.03); }
.ws-placeholder { aspect-ratio: 2 / 3; border-radius: 10px; background: var(--ink-high); }
.ws-win[data-status="RUNNING"] .ws-placeholder { animation: ws-breathe 2.2s ease-in-out infinite; }
@keyframes ws-breathe { 50% { opacity: .55; } }
.ws-wait { font-size: 12px; color: var(--text-dim); line-height: 1.5; margin: 0; }
.ws-text { font-size: 13px; line-height: 1.6; color: var(--text); max-height: 46vh; overflow: auto; }
.ws-text p { margin: 0 0 10px; }
.ws-error p { margin: 0 0 10px; font-size: 12.5px; line-height: 1.55; color: var(--text); }
.ws-note { margin: 0; font-size: 11px; color: var(--text-faint); line-height: 1.5; overflow-wrap: anywhere; }
.ws-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.ws-link-btn {
  font: inherit; font-size: 11.5px; color: var(--text-dim); text-decoration: none;
  padding: 6px 10px; border-radius: 8px; border: 1px solid var(--line-soft); background: transparent; cursor: pointer;
}
.ws-link-btn:hover { color: var(--text); border-color: var(--line); background: var(--ink-high); }
.ws-link-btn.is-primary { color: var(--accent-ink); background: var(--accent); border-color: transparent; }
.ws-meta { margin-left: auto; font-size: 10.5px; color: var(--text-faint); }
.ws-win.is-active-artifact .ws-figure { outline: 2px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: -2px; }

/* ---------- barre du bas: missions, fil, fenetres reduites ---------- */
.ws-tray { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; pointer-events: none; }
.ws-tray > * { pointer-events: auto; }
.ws-tray-btn, .ws-chip {
  font: inherit; font-size: 11.5px; color: var(--text-dim); display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 11px; border-radius: 9px; border: 1px solid var(--line-soft); background: var(--ink-raised); cursor: pointer;
}
.ws-tray-btn:hover, .ws-chip:hover { color: var(--text); border-color: var(--line); }
.ws-thread-btn { margin-left: auto; order: 3; }
.ws-tray-wins { display: flex; gap: 6px; flex-wrap: wrap; order: 2; }
.ws-chip { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ws-count { min-width: 17px; height: 17px; border-radius: 9px; background: var(--accent); color: var(--accent-ink); font-size: 10px; display: inline-grid; place-items: center; padding: 0 4px; }
.ws-count[hidden] { display: none; }
.ws-list {
  position: absolute; left: 0; bottom: 44px; width: min(360px, 100%); max-height: 50vh; overflow: auto;
  padding: 10px; border-radius: 12px; border: 1px solid var(--line); background: var(--ink-raised);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .35); z-index: 5;
}
.ws-list[hidden] { display: none; }
.ws-list-mission { padding: 8px 6px; border-bottom: 1px solid var(--line-soft); }
.ws-list-mission:last-child { border-bottom: 0; }
.ws-list-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.ws-list-head b { font-size: 12.5px; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ws-list-task {
  width: 100%; display: flex; align-items: center; gap: 8px; text-align: left; font: inherit; font-size: 12px;
  color: var(--text-dim); padding: 7px 6px; border: 0; border-radius: 8px; background: transparent; cursor: pointer;
}
.ws-list-task:hover { background: var(--ink-high); color: var(--text); }
.ws-list-task small { margin-left: auto; font-size: 10.5px; color: var(--text-faint); }
.ws-empty { font-size: 12px; color: var(--text-faint); margin: 6px; }
.tool.ws-link { cursor: pointer; border: 0; font: inherit; }

/* ---------- mobile et tablette: bandeau au-dessus du fil ---------- */
@media (max-width: 900px) {
  body[data-view="chat"] .ws {
    display: block; position: relative; flex: 0 0 auto; max-height: 64dvh; overflow-y: auto;
    padding: 8px 14px 6px; border-bottom: 1px solid var(--line-soft);
  }
  .ws-canvas { display: flex; flex-direction: column; align-items: center; gap: 8px; }
  .ws-core { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; }
  .ws-core .orb { width: 112px; height: 112px; cursor: pointer; }
  .ws-windows { width: 100%; display: flex; gap: 10px; overflow-x: auto; scroll-snap-type: x mandatory; padding: 2px 0 6px; }
  .ws-windows:empty { display: none; }
  .ws-win { position: relative; flex: 0 0 min(86vw, 340px); width: auto; max-height: 56dvh; scroll-snap-align: start; box-shadow: none; }
  .ws-win[data-kind] { width: auto; }
  .ws-win.is-big { flex-basis: 92vw; }
  .ws-win-bar { cursor: default; }
  .ws-tray { width: 100%; position: relative; }
  .ws-thread-btn { display: none; }
  body[data-view="chat"] .stage { left: 0; right: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .ws-core.is-working .orb-host::before, .ws-win[data-status="RUNNING"] .ws-progress, .ws-win[data-status="RUNNING"] .ws-placeholder { animation: none !important; }
  .ws-win[data-status="RUNNING"] .ws-progress { background: var(--accent); opacity: .5; }
}

/* ---------- logo: petite orbe animee, bouton retour a JARVIS ---------- */
.rail-mark { cursor: pointer; border-radius: 12px; }
.rail-mark:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
.brand-orb { display: block; width: 76px; height: 76px; flex: none; margin: -8px 0 -6px; border-radius: 50%; transition: transform .2s ease; }
.brand-orb canvas { display: block; width: 100%; height: 100%; }
.rail-mark:hover .brand-orb { transform: scale(1.06); }
/* Pendant la voix, la scene ne recouvre jamais la navigation: le logo reste
   le retour vers JARVIS, sans couper la session. */
@media (min-width: 821px) { body.voice-on .stage { left: var(--rail); } }

/* ---------- horloges Paris / Miami ---------- */
.clocks { display: inline-flex; align-items: center; gap: 12px; font-size: 11px; color: var(--text-dim); font-variant-numeric: tabular-nums; white-space: nowrap; }
.clock b { font-weight: 600; color: var(--text); margin-left: 4px; }
@media (max-width: 540px) { .clocks { gap: 8px; font-size: 10px; } }
