/* ============================================================
   AminiA — coque visuelle Grok / Grok Imagine
   Chargé après app.css. Ce fichier gagne le conflit de cascade.
   1. Jetons
   2. Cadre (sidebar + scène)
   3. Chat
   4. Imagine
   5. Bibliothèque, voix, compte
   6. Mobile
   7. Connexion et chargement
   ============================================================ */

:root {
  --bg: #000000;
  --bg-elev: #141414;
  --bg-elev-2: #1c1c1c;
  --bg-hover: rgba(255, 255, 255, 0.06);
  --bg-active: rgba(255, 255, 255, 0.1);
  --line: rgba(255, 255, 255, 0.1);
  --text: #f4f4f4;
  --muted: #8e8e8e;
  --faint: #5e5e5e;
  --bubble: #1f1f1f;
  --chip: #161616;
  --inverse: #ffffff;
  --inverse-text: #111111;
  --danger: #e07a72;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  --sidebar-w: 268px;
  --rail-w: 76px;
  --col: 760px;
  --composer: 740px;
  --tab-h: 58px;
  --top-h: 52px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --task-h: 0px;
  color-scheme: dark;
  font-family: Inter, "Segoe UI", system-ui, sans-serif;
}

html[data-theme="light"] {
  --bg: #ffffff;
  --bg-elev: #f4f4f5;
  --bg-elev-2: #e8e8ec;
  --bg-hover: rgba(0, 0, 0, 0.04);
  --bg-active: rgba(0, 0, 0, 0.07);
  --line: rgba(0, 0, 0, 0.08);
  --text: #111111;
  --muted: #66666c;
  --faint: #8a8a90;
  --bubble: #f2f2f4;
  --chip: #f4f4f5;
  --inverse: #111111;
  --inverse-text: #ffffff;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.08);
  color-scheme: light;
}

html, body {
  background: var(--bg);
  color: var(--text);
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 2px;
}

/* ---------- cadre ---------- */
.app {
  height: 100%;
  height: 100dvh;
  background: var(--bg);
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  overflow: hidden;
}
.app > .stage {
  grid-column: 2;
  grid-row: 1;
  min-width: 0;
  min-height: 0;
  background: var(--bg);
}
.stage { background: var(--bg); }
.tabbar,
.side-scrim { display: none; }

.side {
  grid-column: 1;
  grid-row: 1;
  width: auto;
  min-width: 0;
  min-height: 0;
  background: var(--bg);
  color: var(--text);
  border-right: 1px solid var(--line);
  padding: 10px 10px 8px;
  overflow: hidden;
}
.side-brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  padding: 4px 4px 2px;
}
.side-logo {
  font-size: 20px;
  font-weight: 650;
  letter-spacing: -0.045em;
  color: var(--text);
  padding: 6px 8px;
  border-radius: 10px;
}
.side-logo:hover { background: var(--bg-hover); }
.side-search {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 4px 6px;
  padding: 0 12px;
  height: 38px;
  border-radius: 999px;
  background: var(--bg-elev);
  border: 1px solid transparent;
  color: var(--muted);
}
.side-search:focus-within { border-color: var(--line); }
.side-search svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.7; flex: none; }
.side-search input {
  border: 0;
  background: transparent;
  color: var(--text);
  height: 36px;
  padding: 0;
  min-width: 0;
}
.side-search input:focus { border: 0; outline: none; }

.side-nav { display: grid; gap: 2px; padding: 2px 0 4px; }
.side .side-nav > button,
#rail-admin2 button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  border-radius: 12px;
  padding: 9px 12px;
  color: var(--text);
  background: transparent;
  font-size: 14.5px;
  font-weight: 500;
}
.side .side-nav > button svg { width: 18px; height: 18px; }
.side .side-nav > button:hover,
#rail-admin2 button:hover { background: var(--bg-hover); }
.side .side-nav > button.on { background: var(--bg-active); color: var(--text); }

.side-scroll { flex: 1; min-height: 0; min-width: 0; overflow: auto; }
.side-section-head,
.side-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: none;
  padding: 14px 12px 6px;
}
.hist-group {
  margin: 14px 12px 4px;
  color: var(--faint);
  font-size: 12px;
  font-weight: 600;
}
.side-label-row { display: flex; align-items: center; }
.side-label-row #new-chat.icon-btn {
  width: 32px;
  height: 32px;
  margin: 0 4px 0 0;
  padding: 0;
  background: transparent;
  color: var(--text);
  border-radius: 10px;
  font-weight: 400;
  font-size: 22px;
  text-align: center;
}
.side-label-row #new-chat.icon-btn:hover { background: var(--bg-hover); }
#hist-list { padding: 0 4px 12px; }
.conv {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  border-radius: 10px;
  color: var(--muted);
  font-size: 14px;
  padding: 8px 8px 8px 12px;
}
.conv > span { color: inherit; }
.conv.on,
.conv:hover { background: var(--bg-hover); color: var(--text); }
.conv:hover::after,
.conv.on::after { content: none; }
.conv-more { color: var(--muted); }
.conv-more:hover { background: var(--bg-elev-2); color: var(--text); }

.side-foot {
  margin-top: auto;
  border-top: 1px solid var(--line);
  padding-top: 8px;
  text-align: left;
}
.user-chip { border-radius: 12px; margin: 0; padding: 6px; color: var(--text); }
.user-chip:hover { background: var(--bg-hover); }
.user-chip .avatar,
.avatar {
  background: var(--inverse);
  color: var(--inverse-text);
  font-weight: 700;
}
.user-meta strong { color: var(--text); font-weight: 560; }
.user-meta small,
#credit-pill { color: var(--muted); }
.legal {
  margin: 6px 8px 2px;
  color: var(--faint);
  font-size: 10px;
  line-height: 1.4;
  text-align: center;
}
.user-pop {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  color: var(--text);
}
.user-pop button { color: var(--text); }
.user-pop button:hover { background: var(--bg-hover); }

/* Rail replié, comme Grok */
@media (min-width: 961px) {
  .app.collapsed { grid-template-columns: var(--rail-w) minmax(0, 1fr); }
  .app.collapsed .side { overflow: visible; padding-left: 8px; padding-right: 8px; }
  .app.collapsed .side-search,
  .app.collapsed .side-scroll,
  .app.collapsed .legal,
  .app.collapsed .user-meta,
  .app.collapsed #rail-admin2 { display: none; }
  .app.collapsed .side-brand { flex-direction: column; align-items: center; gap: 6px; }
  .app.collapsed .side-logo {
    font-size: 0;
    width: 44px;
    height: 44px;
    padding: 0;
    display: grid;
    place-items: center;
  }
  .app.collapsed .side-logo::before {
    content: "ⵣ";
    font-size: 22px;
    line-height: 1;
  }
  .app.collapsed .side-nav > button {
    font-size: 0;
    justify-content: center;
    gap: 0;
    padding: 11px 0;
  }
  .app.collapsed .side-nav > button svg { width: 22px; height: 22px; }
  .app.collapsed .user-chip { justify-content: center; padding: 6px 0; }
  .app.collapsed .user-pop {
    left: calc(100% + 8px);
    right: auto;
    bottom: 0;
    width: 240px;
  }
  .app.collapsed .mobile-menu { display: none; }
}

/* ---------- chat ---------- */
#chat-view {
  background: var(--bg);
  position: relative;
}
#chat-view.home {
  justify-content: center;
  align-items: center;
  gap: 18px;
  padding: 24px 16px 56px;
}
#chat-view.home .chat-hero { padding: 0; text-align: center; }
#chat-view .chat-hero h2,
#chat-view.home .chat-hero h2 {
  margin: 0;
  font-family: Inter, "Segoe UI", sans-serif;
  font-size: clamp(28px, 4vw, 36px);
  font-weight: 520;
  letter-spacing: -0.04em;
  color: var(--text);
}
#chat-view .messages {
  width: min(var(--col), 100%);
  max-width: var(--col);
  margin: 0 auto;
  padding: 28px 16px 12px;
  gap: 22px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}
#chat-view .msg {
  width: 100%;
  max-width: 100%;
  margin: 0;
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 0;
  color: var(--text);
  box-shadow: none;
}
#chat-view .msg.user {
  align-self: flex-end;
  width: fit-content;
  max-width: min(82%, 540px);
  margin-left: auto;
  margin-right: 0;
  background: var(--bubble);
  border-radius: 22px;
  padding: 10px 16px;
}
#chat-view .msg.assistant {
  align-self: stretch;
  width: 100%;
  background: transparent;
  border: 0;
  padding: 2px 2px 0;
  border-radius: 0;
  white-space: normal;
}
#chat-view .msg .md { font-size: 15.5px; line-height: 1.65; color: var(--text); }
#chat-view .msg-actions button:hover,
#chat-view .msg-actions button.selected { background: var(--bg-elev-2); color: var(--text); }

#chat-view.home .chat-suggest,
.chat-suggest {
  display: none;
  width: min(var(--composer), calc(100% - 32px));
  margin: 0 auto;
}
#chat-view.home .chat-suggest { display: flex; }
.chat-suggest button {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13.5px;
}
.chat-suggest button:hover { background: var(--bg-hover); }
#chat-view .chat-disclaimer {
  color: var(--faint);
  max-width: var(--col);
}

#composer.dock {
  width: min(var(--composer), calc(100% - 32px));
  margin: 0 auto 14px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 28px;
  box-shadow: none;
  display: grid;
  gap: 2px;
  padding: 12px 12px 8px;
}
#chat-view.home #composer.dock { margin: 0; }
#composer.dock:focus-within { border-color: color-mix(in srgb, var(--text) 28%, transparent); }
#composer textarea,
#composer.dock textarea {
  color: var(--text);
  background: transparent;
  border: 0;
  font-size: 16px;
  padding: 6px 8px;
  outline: none;
}
#composer textarea::placeholder { color: var(--muted); }
#composer .chat-bar {
  display: flex;
  align-items: center;
  gap: 2px;
  min-height: 40px;
  flex-wrap: nowrap;
  overflow: visible;
}
#composer .chat-bar .icon-btn,
#composer .chat-bar .plus-btn,
#composer #send-btn,
#composer #stop-btn {
  width: 36px;
  height: 36px;
  min-width: 36px;
  border-radius: 50%;
  padding: 0;
  display: grid;
  place-items: center;
  color: var(--text);
  background: transparent;
}
#composer .chat-bar .icon-btn:hover,
#composer .chat-bar .plus-btn:hover { background: var(--bg-hover); }
#composer .chat-mode,
#composer #chat-talk {
  width: auto;
  height: 36px;
  min-width: 0;
  border-radius: 999px;
  padding: 0 10px;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
#composer .chat-mode:hover,
#composer #chat-talk:hover,
#composer .chat-mode[aria-expanded="true"] { background: var(--bg-hover); }
#composer .mode-wrap { margin-left: auto; }
#composer #send-btn,
#composer #stop-btn {
  background: var(--inverse);
  color: var(--inverse-text);
}
#composer #send-btn svg { stroke: var(--inverse-text); fill: none; }
#composer #stop-btn svg { fill: var(--inverse-text); stroke: none; }
#chat-mode-menu,
.menu-pop {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  color: var(--text);
  box-shadow: var(--shadow);
}
#chat-mode-menu button.on,
#chat-mode-menu button:hover { background: var(--bg-hover); }

/* ---------- Imagine ---------- */
#imagine-view.imagine {
  background: var(--bg);
  color: var(--text);
}
#imagine-view.imagine.home {
  align-items: center;
  justify-content: center;
  gap: 22px;
  padding-bottom: 24px;
}
#imagine-view .imagine-home {
  width: min(820px, calc(100% - 48px));
  display: flex;
  flex-direction: column;
  align-items: center;
}
#imagine-view .imagine-home h2 {
  margin: 0;
  font-family: Inter, "Segoe UI", sans-serif;
  font-size: clamp(28px, 4.2vw, 42px);
  font-weight: 520;
  letter-spacing: -0.045em;
  text-align: center;
  color: var(--text);
}
#imagine-view .style-row { margin-top: 16px; }
#imagine-view .style-chip {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
}
#imagine-view .style-chip.on,
#imagine-view .style-chip:hover {
  background: var(--inverse);
  color: var(--inverse-text);
  border-color: var(--inverse);
}

#imagine-form.composer {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 28px;
  box-shadow: var(--shadow);
  color: var(--text);
}
#imagine-view.imagine.home > #imagine-form {
  position: relative;
  left: auto;
  right: auto;
  bottom: auto;
  transform: none;
  width: min(820px, calc(100% - 48px));
  margin: 0;
}
#imagine-view.imagine.feed > #imagine-form,
#imagine-view.imagine.viewing > #imagine-form {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  width: min(820px, calc(100% - 32px));
  z-index: 5;
}
#imagine-form textarea,
#imagine-prompt {
  color: var(--text);
  background: transparent;
  font-size: 16px;
  min-width: 0;
}
#imagine-prompt::placeholder { color: var(--muted); }
#imagine-form .composer-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  flex-wrap: nowrap;
  min-width: 0;
}
#imagine-form .composer-scroll {
  display: flex;
  flex: 1 1 auto;
  align-items: center;
  gap: 6px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
#imagine-form .composer-scroll::-webkit-scrollbar { display: none; }
#imagine-form .opt-row,
#imagine-form #image-tools,
#imagine-form #video-tools {
  width: auto;
  flex: 0 0 auto;
  min-width: 0;
  gap: 6px;
  flex-wrap: nowrap;
}
#imagine-form #image-tools,
#imagine-form #video-tools,
#imagine-form #ratio-btn,
#imagine-form #mic-btn { order: 0; }
#kind-switch.mode-group {
  background: var(--chip);
  border: 1px solid var(--line);
  flex: none;
}
#kind-switch button {
  color: var(--muted);
  background: transparent;
  box-shadow: none;
}
#kind-switch button.on,
#kind-switch button[data-kind="image"].on,
#kind-switch button[data-kind="video"].on,
#kind-switch button[data-kind="animate"].on {
  background: var(--bg-elev-2);
  color: var(--text);
  box-shadow: none;
}
#imagine-form .ratio-pill,
#imagine-form .chip,
#imagine-form .count-select,
#imagine-form .vopts-btn {
  background: var(--chip);
  color: var(--text);
  border: 1px solid transparent;
}
#imagine-form .chip.on { background: var(--inverse); color: var(--inverse-text); }
#imagine-go,
#imagine-form #imagine-go {
  position: static;
  margin-left: 0;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 50%;
  background: var(--inverse);
  color: var(--inverse-text);
  flex: none;
}
#imagine-go svg { stroke: var(--inverse-text); fill: none; stroke-width: 1.8; }
#imagine-go:disabled { opacity: 0.4; }

#imagine-view .imagine-feed {
  padding: 8px 16px calc(var(--dock-h, 148px) + 18px);
}
#feed-grid.feed-grid,
.feed-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}
@media (min-width: 1100px) {
  #feed-grid.feed-grid,
  .feed-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
.feed-card {
  width: 100%;
  border-radius: 16px;
  overflow: hidden;
  background: var(--chip);
  border: 1px solid var(--line);
}
.feed-card img,
.feed-card video {
  width: 100%;
  height: auto;
  max-height: 72vh;
  object-fit: contain;
  background: #000;
  display: block;
}
.prompt-pill {
  background: var(--bg-elev);
  color: var(--text);
  border-radius: 999px;
}
.suggest button {
  background: var(--bg-elev);
  color: var(--text);
}

#imagine-view .viewer {
  padding-bottom: calc(var(--dock-h, 148px) + 12px);
}
.viewer-media img,
.viewer-media video { border-radius: 12px; }
.viewer-actions > button {
  background: var(--bg-elev);
  color: var(--text);
  border-radius: 12px;
}
.viewer-actions > button.share {
  background: var(--inverse);
  color: var(--inverse-text);
}
.viewer-rail button { background: var(--chip); border-radius: 10px; }
.viewer-rail button.on { border-color: var(--text); }

/* ---------- bibliothèque, voix, compte ---------- */
.library,
.plans,
.pref-view,
.voice-stage { background: var(--bg); color: var(--text); }
.lib-bar { background: var(--bg); }
.lib-search {
  background: var(--bg-elev);
  border-radius: 999px;
  padding: 0 12px;
  border: 1px solid transparent;
}
.lib-filters button { background: transparent; color: var(--muted); }
.lib-filters button.on { background: var(--bg-active); color: var(--text); }
.lib-tile,
.lib-card .lib-tile { border-radius: 14px; }
#voice-view { min-width: 0; overflow: hidden; }
#voice-view .voice-stage { min-width: 0; width: 100%; max-width: 100%; overflow: hidden; }
#voice-type,
#voice-type.voice-composer {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 28px;
  width: min(760px, calc(100% - 32px));
  max-width: calc(100% - 32px);
  min-width: 0;
  box-sizing: border-box;
}
#voice-type.voice-composer .voice-type-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  min-width: 0;
  overflow: visible;
  flex-wrap: nowrap;
}
#voice-type.voice-composer .voice-scroll {
  display: flex;
  flex: 1 1 auto;
  align-items: center;
  gap: 8px;
  min-width: 0;
  overflow: visible;
}
#voice-type.voice-composer #voice-send {
  position: static;
  margin-left: 0;
  flex: none;
}
#voice-type .stt-lang { width: auto; max-width: 148px; }
#voice-type .voice-settings-wrap { flex: none; min-width: 0; }
#voice-type .voice-settings-toggle { max-width: 160px; }
#mic-btn svg,
#imagine-form .icon-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.voice-hero,
#voice-status { color: var(--text); }
.account-nav button.on { background: var(--bg-active); }
.pref-block,
.account-main.pref { color: var(--text); }
.top {
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  color: var(--text);
}
.top h1 {
  font-size: 15px;
  font-weight: 560;
  letter-spacing: -0.02em;
}
#side-toggle,
.top-new { color: var(--text); }
.top-new { display: none; }
.app[data-view="chat"] .top-new { display: grid; }

.upgrade-card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  color: var(--text);
}
.upgrade-card strong { color: var(--text); }
.upgrade-card button {
  background: var(--inverse);
  color: var(--inverse-text);
}

/* ---------- mobile ---------- */
@media (max-width: 960px) {
  .app,
  .app.collapsed {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
  }
  .app > .stage {
    grid-column: 1;
    grid-row: 1;
    min-height: 0;
  }
  .tabbar {
    display: grid;
    grid-column: 1;
    grid-row: 2;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    height: calc(var(--tab-h) + var(--safe-b));
    padding: 4px 6px var(--safe-b);
    background: var(--bg);
    border-top: 1px solid var(--line);
    z-index: 30;
  }
  .tabbar button {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-width: 0;
    padding: 4px 2px;
    border-radius: 12px;
    background: transparent;
    color: var(--muted);
    font-size: 10px;
    font-weight: 560;
    letter-spacing: -0.01em;
  }
  .tabbar button svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
  }
  .tabbar button span {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .tabbar button.on { color: var(--text); }

  .side {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(320px, 88vw);
    z-index: 40;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    padding-top: calc(10px + var(--safe-t));
    padding-bottom: calc(8px + var(--safe-b));
    box-shadow: none;
    overflow: hidden;
  }
  .side.open {
    transform: none;
    box-shadow: 12px 0 40px rgba(0, 0, 0, 0.35);
  }
  .side.open + .side-scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 35;
    border: 0;
    padding: 0;
    background: rgba(0, 0, 0, 0.55);
  }
  .app.collapsed .side-search,
  .app.collapsed .side-scroll,
  .app.collapsed .legal,
  .app.collapsed .user-meta { display: revert; }
  .app.collapsed .side-nav > button {
    display: flex;
    font-size: 14.5px;
    justify-content: flex-start;
    gap: 10px;
    padding: 9px 12px;
  }
  .app.collapsed .side-logo {
    font-size: 20px;
    width: auto;
    height: auto;
    display: inline-flex;
  }
  .app.collapsed .side-logo::before { content: none; }
  .app.collapsed .side-brand { flex-direction: row; }
  .app.collapsed .user-chip { justify-content: flex-start; }

  .mobile-menu { display: none; }
  #workspace-top.top,
  .top {
    display: grid;
    grid-template-columns: 40px minmax(0, 1fr) 40px;
    align-items: center;
    height: calc(var(--top-h) + var(--safe-t));
    padding: var(--safe-t) 8px 0;
    gap: 4px;
  }
  .top h1 {
    grid-column: 2;
    text-align: center;
    font-size: 16px;
    font-weight: 600;
  }
  #side-toggle { display: grid; grid-column: 1; }
  .app[data-view="chat"] .top-new { grid-column: 3; justify-self: end; }
  #status-pills { display: none; }
  #side-toggle svg,
  .top-new svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
  }

  #chat-view.home {
    justify-content: center;
    padding: 12px 0 16px;
    gap: 14px;
  }
  #chat-view .chat-hero h2 { font-size: 26px; padding: 0 18px; }
  #chat-view .messages {
    width: 100%;
    padding: 12px 12px 8px;
  }
  #chat-view .msg.user { max-width: 88%; }
  #chat-view.home #composer.dock,
  #chat-view:not(.home) #composer.dock {
    width: calc(100% - 16px);
    margin: 0 auto 8px;
    border-radius: 22px;
  }
  #chat-view.home .chat-suggest { width: calc(100% - 20px); }
  #chat-view .chat-disclaimer { position: static; padding: 0 12px 6px; }
  #chat-view.home .chat-disclaimer { order: 5; }
  #composer #chat-talk span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  #composer #chat-talk { padding: 0; width: 36px; justify-content: center; }
  #composer .chat-bar { gap: 0; }
  @media (max-width: 420px) {
    #composer .chat-bar {
      overflow-x: auto;
      scrollbar-width: none;
    }
  }

  #imagine-view.imagine.home {
    justify-content: center;
    align-items: center;
    gap: 14px;
    padding: 8px 0 6px;
  }
  #imagine-view .imagine-home,
  #imagine-view.imagine.home > #imagine-form,
  #imagine-view.imagine.feed > #imagine-form,
  #imagine-view.imagine.viewing > #imagine-form {
    position: relative;
    left: auto;
    right: auto;
    bottom: auto;
    transform: none;
    width: calc(100% - 16px);
    margin: 0 auto 8px;
  }
  #imagine-view .imagine-home h2 { font-size: 26px; }
  #imagine-view .imagine-feed,
  #imagine-view .viewer {
    padding: 8px 8px 8px;
  }
  #imagine-view .viewer {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: "rail" "stage";
  }
  #feed-grid.feed-grid,
  .feed-grid { grid-template-columns: 1fr; gap: 8px; }
  #imagine-form { border-radius: 22px; }
  #imagine-form textarea,
  #imagine-prompt { width: 100%; display: block; }
  #imagine-form #prompt-collapse { display: none; }
  #imagine-form .composer-bar {
    overflow: visible;
    padding-right: 0;
  }
  #imagine-form #image-tools,
  #imagine-form #video-tools { display: contents; }
  #imagine-form .composer-scroll > * { order: 5; }
  #imagine-form #kind-switch { order: 1; padding: 2px; }
  #imagine-form #kind-switch button { padding: 4px 6px; font-size: 12px; }
  #imagine-form #composer-plus { order: 2; }
  #imagine-form #ratio-btn,
  #imagine-form #video-opts-btn { order: 3; }
  #imagine-form #mic-btn { order: 4; }
  #imagine-form #speed-btn,
  #imagine-form #quality-btn,
  #imagine-form #count-switch,
  #imagine-form #count-select { order: 6; }
  #imagine-form .composer-scroll {
    -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 16px), transparent);
    mask-image: linear-gradient(90deg, #000 calc(100% - 16px), transparent);
  }
  #imagine-prompt {
    min-height: 64px;
    overflow: hidden;
  }
  #imagine-form #imagine-go {
    position: static;
    right: auto;
    bottom: auto;
    margin: 0;
    box-shadow: none;
  }
  #video-opts-pop {
    position: fixed;
    left: 8px;
    right: 8px;
    bottom: calc(var(--tab-h) + var(--safe-b) + var(--task-h, 0px) + 12px);
    width: auto;
    max-height: min(52vh, 420px);
    overflow: auto;
    z-index: 46;
  }
  #voice-view .voice-top { display: none; }
  #voice-type.voice-composer {
    position: relative;
    width: calc(100% - 16px);
    max-width: calc(100% - 16px);
  }
  #voice-type.voice-composer .voice-scroll {
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 14px), transparent);
    mask-image: linear-gradient(90deg, #000 calc(100% - 14px), transparent);
  }
  #voice-type .voice-settings-wrap { margin-left: 0; }
  #voice-type #stt-lang {
    width: 74px;
    max-width: 74px;
    padding-left: 8px;
    padding-right: 18px;
  }
  #voice-type.voice-composer .voice-scroll::-webkit-scrollbar { display: none; }
  #voice-type.voice-composer #voice-send {
    position: static;
    right: auto;
    bottom: auto;
    margin: 0;
    box-shadow: none;
  }
  #voice-type #mic-mute-btn {
    width: 36px;
    min-width: 36px;
    height: 36px;
    padding: 0;
    font-size: 0;
    gap: 0;
    justify-content: center;
    overflow: hidden;
  }
  #voice-type #mic-mute-btn::after {
    content: "";
    width: 16px;
    height: 16px;
    background: currentColor;
    -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path fill='black' d='M12 14a3 3 0 0 0 3-3V5a3 3 0 0 0-6 0v6a3 3 0 0 0 3 3zm5.3-3a5.3 5.3 0 0 1-10.6 0H5a7 7 0 0 0 6 6.9V21h2v-3.1A7 7 0 0 0 19 11h-1.7z'/></svg>") center / contain no-repeat;
    mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path fill='black' d='M12 14a3 3 0 0 0 3-3V5a3 3 0 0 0-6 0v6a3 3 0 0 0 3 3zm5.3-3a5.3 5.3 0 0 1-10.6 0H5a7 7 0 0 0 6 6.9V21h2v-3.1A7 7 0 0 0 19 11h-1.7z'/></svg>") center / contain no-repeat;
  }
  #voice-type #mic-mute-btn.muted::after {
    -webkit-mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path fill='black' d='M5 4.2 3.6 5.6 8.1 10A5 5 0 0 0 7 11H5.2A7 7 0 0 0 11 17.9V20h2v-2.1c.5-.1 1-.3 1.4-.5l4 4 1.4-1.4L5 4.2zM15 11c0 .3 0 .6-.1.9l1.6 1.6A7 7 0 0 0 18.8 11H17a5 5 0 0 1-2 0zm-3-8a3 3 0 0 0-3 3v.2l6 6V6a3 3 0 0 0-3-3z'/></svg>");
    mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path fill='black' d='M5 4.2 3.6 5.6 8.1 10A5 5 0 0 0 7 11H5.2A7 7 0 0 0 11 17.9V20h2v-2.1c.5-.1 1-.3 1.4-.5l4 4 1.4-1.4L5 4.2zM15 11c0 .3 0 .6-.1.9l1.6 1.6A7 7 0 0 0 18.8 11H17a5 5 0 0 1-2 0zm-3-8a3 3 0 0 0-3 3v.2l6 6V6a3 3 0 0 0-3-3z'/></svg>");
  }
  .library .lib-bar { padding: 8px; }
  .lib-grid,
  .lib-grid.size-small,
  .lib-grid.size-medium,
  .lib-grid.size-large {
    padding-bottom: 18px;
  }
  .plans-wrap { margin-top: 12px; }
  .voice-top { display: none; }
  .voice-stage {
    padding: 8px 10px 8px;
    gap: 8px;
  }
  #voice-type { width: calc(100% - 4px); border-radius: 22px; }
  #voice-type .voice-settings-menu {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(var(--tab-h) + var(--safe-b) + var(--task-h, 0px) + 16px);
    width: auto;
    max-height: min(52vh, 420px);
    z-index: 46;
  }
  .agent-pop {
    bottom: calc(var(--tab-h) + var(--safe-b) + var(--task-h, 0px) + 76px);
    z-index: 32;
    max-height: min(58vh, 480px);
  }
  .toast {
    bottom: calc(var(--tab-h) + var(--safe-b) + var(--task-h, 0px) + 12px);
    z-index: 45;
  }
  .upgrade-card {
    left: 10px;
    right: 10px;
    bottom: calc(var(--tab-h) + var(--safe-b) + var(--task-h, 0px) + 10px);
    max-width: none;
  }
  .app.show-upgrade #chat-view:not(.home),
  .app.show-upgrade .voice-stage,
  .app.show-upgrade .imagine.home { padding-bottom: 8px; }
  .pref { width: min(640px, calc(100% - 20px)); margin-top: 8px; }
  .account-main.pref { padding-top: 8px; }
}

@media (max-width: 700px) {
  #feed-grid.feed-grid,
  .feed-grid { grid-template-columns: 1fr; }
}
@media (min-width: 701px) and (max-width: 960px) {
  #feed-grid.feed-grid,
  .feed-grid { grid-template-columns: 1fr 1fr; }
}

/* ---------- connexion ---------- */
.gate {
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
}
.gate-card { width: min(380px, calc(100% - 32px)); text-align: center; }
.mark {
  font-size: 34px;
  font-weight: 650;
  letter-spacing: -0.045em;
  color: var(--text);
}
.mark::before {
  content: "";
  display: block;
  width: 56px;
  height: 56px;
  margin: 0 auto 14px;
  border-radius: 16px;
  background: #0a0a0a url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23ffffff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 4 v16 M12 9 L5 3 M12 9 L19 3 M12 15 L5 21 M12 15 L19 21'/%3E%3C/svg%3E") center / 58% no-repeat;
}
.gate-form { text-align: left; }
.gate-form .lede { text-align: center; color: var(--muted); }
.gate-form label { color: var(--muted); }
.gate-form input {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
}
.gate-form input:focus { border-color: color-mix(in srgb, var(--text) 35%, transparent); }
.gate-tabs button#show-login.on,
.gate-form button[type="submit"],
button[type="submit"].primary {
  background: var(--inverse);
  color: var(--inverse-text);
}
#boot-loader { background: var(--bg); }
.art-plane,
.art-knife { animation: none; opacity: 0; }
.art-yaz { width: 56px; stroke: var(--text); }
.boot-word { font-weight: 700; letter-spacing: -0.05em; color: var(--text); }
.boot-word::after { display: none; }
.boot-text { color: var(--muted); }

/* ---------- bots et connexions ---------- */
#bots-view,
#links-view,
#project-view {
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
}
.mod-page {
  flex: 1;
  min-height: 0;
  overflow: auto;
  width: min(920px, 100%);
  margin: 0 auto;
  padding: 28px 20px 48px;
}
.mod-head h2 {
  margin: 0;
  font-size: clamp(28px, 4vw, 40px);
  font-weight: 560;
  letter-spacing: -0.045em;
}
.mod-lead {
  margin: 8px 0 0;
  color: var(--muted);
  max-width: 62ch;
}
.mod-page h3 {
  margin: 22px 0 10px;
  font-size: 15px;
  font-weight: 600;
}
.mod-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 10px;
  margin-top: 18px;
}
.mod-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  margin: 0;
  padding: 14px;
  text-align: left;
  color: var(--text);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 16px;
}
.mod-card.on { border-color: color-mix(in srgb, var(--text) 55%, transparent); }
.mod-card div { min-width: 0; flex: 1; display: grid; gap: 3px; }
.mod-card strong { font-size: 15px; }
.mod-card small { color: var(--muted); line-height: 1.35; }
.mod-mark {
  width: 40px;
  height: 40px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: var(--bg-elev-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
}
.mod-switch {
  flex: none;
  margin-left: auto;
  border-radius: 999px;
  padding: 6px 10px;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
  font-size: 12px;
}
.mod-switch.on,
.mod-filters button.on {
  background: var(--inverse);
  color: var(--inverse-text);
  border-color: transparent;
}
.mod-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}
.mod-filters button {
  border-radius: 999px;
  padding: 7px 12px;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}
.mod-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.mod-actions button,
.link-sheet button[type="submit"] { width: auto; }
.link-sheet {
  display: grid;
  gap: 10px;
  margin-top: 16px;
  padding: 16px;
  border-radius: 16px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
}
.link-sheet p { margin: 0; color: var(--muted); }
.mod-picks {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.mod-picks label {
  display: flex;
  align-items: center;
  gap: 6px;
  width: auto;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 13px;
}
.mod-picks input { width: auto; }
.bot-chip {
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mod-ext {
  color: var(--text);
  font-size: 13px;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.mod-uri {
  margin: 0;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--muted);
  font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  word-break: break-all;
  user-select: all;
}
.bot-id {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  margin-top: 16px;
}
.bot-id .mod-mark {
  width: 56px;
  height: 56px;
  font-size: 18px;
}
.bot-id h2 {
  margin: 0;
  font-size: clamp(28px, 4vw, 40px);
  letter-spacing: -0.045em;
}
.bot-id p { margin: 4px 0 0; }
.bot-back { width: auto; color: var(--muted); }
.bot-list { display: grid; gap: 8px; margin-top: 14px; }
.bot-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border-radius: 14px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
}
.bot-row > div { display: grid; gap: 3px; flex: 1; min-width: 0; }
.bot-row small { color: var(--muted); }
.bot-row button { width: auto; margin-left: auto; }
.bot-threads { display: grid; gap: 8px; }
.bot-threads button {
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
}
.conv-bot {
  flex: none;
  margin-right: 8px;
  color: var(--muted);
  font-style: normal;
  font-size: 12px;
}
#hero-sub {
  margin: 8px auto 0;
  max-width: 46ch;
  color: var(--muted);
  font-size: 15px;
}
.bot-card div { cursor: pointer; }
@media (max-width: 960px) {
  .mod-page { padding: 16px 12px 24px; }
  .mod-grid { grid-template-columns: 1fr; margin-top: 12px; }
  .mod-card { align-items: center; }
}

/* ---------- tâches en cours ---------- */
.task-head { padding-top: 8px; }
.task-count {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--inverse);
  color: var(--inverse-text);
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0;
  line-height: 18px;
  text-align: center;
}
.task-count:empty { display: none; }
.task-side,
.task-panel {
  display: grid;
  gap: 6px;
  min-width: 0;
}
.task-side {
  max-height: 220px;
  margin: 0 6px 8px;
  overflow: auto;
}
.task-empty,
.task-kicker {
  margin: 0;
  padding: 0 8px;
  color: var(--muted);
  font-size: 12.5px;
}
.task-kicker {
  padding-top: 4px;
  color: var(--faint);
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.task-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.task-open {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 2px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-elev);
  color: var(--text);
  text-align: left;
}
.task-open strong,
.task-open small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.task-open strong { font-size: 13px; font-weight: 560; }
.task-open small { color: var(--muted); font-size: 12px; }
.task-row.running .task-open strong { color: var(--text); }
.task-stop {
  flex: none;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  font-size: 12px;
}
.task-meter {
  height: 2px;
  overflow: hidden;
  border-radius: 99px;
  background: var(--line);
}
.task-meter > span {
  display: block;
  height: 100%;
  background: var(--text);
}
.task-strip {
  flex: none;
  display: flex;
  flex-direction: column;
  width: 100%;
  border-top: 1px solid var(--line);
  background: var(--bg);
  z-index: 4;
}
.task-strip.idle { display: none; }
.task-strip-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 16px;
  color: var(--text);
  font-size: 13px;
  text-align: left;
}
.task-dot {
  width: 8px;
  height: 8px;
  flex: none;
  border-radius: 50%;
  background: var(--faint);
}
.task-strip.live .task-dot {
  background: var(--text);
  animation: task-pulse 1.2s ease-in-out infinite;
}
.task-panel {
  max-height: 240px;
  padding: 0 12px 10px;
  overflow: auto;
}
@keyframes task-pulse {
  50% { opacity: 0.35; }
}
@media (max-width: 960px) {
  .task-strip.idle { display: flex; }
  .task-strip-btn { padding: 8px 12px; }
}
@media (prefers-reduced-motion: reduce) {
  .task-strip.live .task-dot { animation: none; }
}

.lib-views {
  display: flex;
  flex: none;
  gap: 2px;
  max-width: 100%;
  padding: 3px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-elev);
}
.lib-views button {
  border-radius: 999px;
  padding: 6px 12px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 560;
  white-space: nowrap;
}
.lib-views button.on {
  background: var(--inverse);
  color: var(--inverse-text);
}
.lib-grid.lib-list,
.lib-grid.lib-list.size-small,
.lib-grid.lib-list.size-medium,
.lib-grid.lib-list.size-large {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 12px;
  padding-left: 12px;
}
.lib-file {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--bg-elev);
}
.lib-file.on { border-color: color-mix(in srgb, var(--text) 55%, transparent); }
.lib-file-main {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: var(--text);
  text-align: left;
}
.lib-file-thumb {
  position: relative;
  width: 52px;
  height: 52px;
  flex: none;
  overflow: hidden;
  border-radius: 10px;
  background: #0b0b0b;
}
.lib-file-thumb img,
.lib-file-thumb video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.lib-file-thumb .dur-badge { right: 3px; bottom: 3px; font-size: 10px; padding: 1px 4px; }
.lib-file-text { display: grid; gap: 2px; min-width: 0; }
.lib-file-text strong,
.lib-file-text small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lib-file-text strong { font-size: 14px; font-weight: 560; }
.lib-file-text small { color: var(--muted); font-size: 12px; }
.lib-file-actions { display: flex; flex: none; gap: 2px; }
.lib-file-actions button {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  color: var(--text);
}
.lib-file .tick { position: static; flex: none; }
.project-files { display: grid; gap: 10px; margin-top: 4px; }
.project-files .mod-lead { margin: 0; }
.project-tree {
  max-height: min(560px, calc(100dvh - 240px));
  overflow: auto;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--bg-elev);
}
.project-files > button {
  width: auto;
  justify-self: start;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
}
.project-repo {
  width: 100%;
  max-width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-elev);
  color: var(--text);
}
.project-crumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 4px;
  background: var(--bg-elev);
}
.project-crumbs button {
  width: auto;
  padding: 4px 8px;
  border-radius: 999px;
  color: var(--muted);
  background: transparent;
}
.project-tree .bot-list { margin-top: 0; }
.project-file {
  width: 100%;
  text-align: left;
  color: var(--text);
  min-width: 0;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
}
.project-file:hover { background: color-mix(in srgb, var(--text) 6%, transparent); }
.project-file strong,
.project-file small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.project-file small { color: var(--muted); }
@media (max-width: 960px) {
  .lib-views { order: 4; flex-basis: 100%; }
  .lib-grid.lib-list,
  .lib-grid.lib-list.size-small,
  .lib-grid.lib-list.size-medium,
  .lib-grid.lib-list.size-large { padding-left: 8px; padding-right: 8px; }
}

.hidden { display: none !important; }
