:root {
  --im-launcher-edge: 16px;
  --im-launcher-bottom: 16px;
  --im-launcher-gap: 10px;
  --im-jarvis-launcher-size: 52px;
}

.jarvis-assistant-btn {
  position: fixed;
  right: var(--im-launcher-edge);
  bottom: var(--im-launcher-bottom);
  z-index: 9001;
  width: var(--im-jarvis-launcher-size);
  height: var(--im-jarvis-launcher-size);
  border: 1px solid rgba(255, 255, 255, .16);
  border-radius: 17px;
  background: linear-gradient(145deg, #202228, #08090b);
  color: #fff;
  box-shadow: 0 14px 40px rgba(0, 0, 0, .35);
  font: 700 17px/1 var(--font-sans, sans-serif);
  cursor: pointer;
  transition: opacity .14s ease, transform .14s ease, visibility 0s linear;
}

.jarvis-assistant-btn:hover { transform: translateY(-2px); }
.jarvis-assistant-btn[hidden] { display: none !important; }

/* The two launchers share one row only while collapsed. Once Messages expands,
   its panel owns this corner; leaving Jarvis above it covers chat rows/actions. */
body:has(#imTeamChatDock.is-open) .jarvis-assistant-btn {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px) scale(.94);
}

.jarvis-assistant-panel {
  position: fixed;
  right: var(--im-launcher-edge);
  bottom: calc(var(--im-launcher-bottom) + var(--im-jarvis-launcher-size) + 12px);
  z-index: 9000;
  display: none;
  flex-direction: column;
  width: min(430px, calc(100vw - 28px));
  height: min(680px, calc(100vh - 106px));
  overflow: hidden;
  border: 1px solid var(--border, #2a2c31);
  border-radius: 20px;
  background: var(--surface, #111216);
  box-shadow: 0 24px 80px rgba(0, 0, 0, .48);
  color: var(--text, #f4f4f2);
}

.jarvis-assistant-panel.open { display: flex; }

.ka-header {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border, #2a2c31);
}

.ka-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 12px;
  background: #f4f0e7;
  color: #101114;
  font-weight: 800;
}

.ka-title { font-size: 14px; font-weight: 750; }
.ka-subtitle { margin-top: 2px; color: var(--text-muted, #94969d); font-size: 11px; }
.ka-header-spacer { flex: 1; }

.ka-header button {
  border: 0;
  background: transparent;
  color: var(--text-muted, #94969d);
  cursor: pointer;
  font: inherit;
}

.ka-panel-session-row {
  display: flex;
  gap: 7px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border, #2a2c31);
  background: var(--surface-2, #17181c);
}

.ka-panel-session-row select {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border, #303238);
  border-radius: 9px;
  outline: none;
  background: var(--surface, #111216);
  color: var(--text, #f4f4f2);
  padding: 7px 9px;
  font: 600 11px/1.2 var(--font-sans, sans-serif);
}

.ka-panel-session-row button {
  border: 0;
  background: transparent;
  color: var(--text-muted, #94969d);
  cursor: pointer;
}

.ka-messages {
  flex: 1;
  overflow: auto;
  padding: 16px;
}

.ka-empty {
  padding: 24px 14px;
  text-align: center;
  color: var(--text-muted, #94969d);
  font-size: 12px;
  line-height: 1.55;
}

.ka-quick {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 7px;
  margin-top: 16px;
}

.ka-quick button,
.ka-action button {
  border: 1px solid var(--border, #303238);
  border-radius: 999px;
  background: var(--surface-2, #1a1b20);
  color: var(--text, #f4f4f2);
  padding: 7px 10px;
  font: 600 11px/1.2 var(--font-sans, sans-serif);
  cursor: pointer;
}

.ka-msg { display: flex; margin: 0 0 12px; }
.ka-msg.user { justify-content: flex-end; }
.ka-msg.assistant, .ka-msg.system { justify-content: flex-start; }

.ka-bubble {
  max-width: 88%;
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--surface-2, #1b1c21);
  font-size: 13px;
  line-height: 1.52;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.ka-msg.user .ka-bubble {
  background: #ede9df;
  color: #151619;
  border-bottom-right-radius: 5px;
}

.ka-msg.assistant .ka-bubble { border-bottom-left-radius: 5px; }
.ka-msg.system .ka-bubble { color: var(--text-muted, #94969d); font-size: 11px; }
.ka-typing { opacity: .72; animation: ka-pulse 1.2s ease-in-out infinite; }
@keyframes ka-pulse { 50% { opacity: .34; } }

.ka-action {
  margin: 8px 0 14px;
  padding: 11px;
  border: 1px solid rgba(224, 186, 105, .32);
  border-radius: 13px;
  background: rgba(224, 186, 105, .07);
}

.ka-action-title { font-size: 12px; font-weight: 750; }
.ka-action-detail {
  max-height: 120px;
  overflow: auto;
  margin: 6px 0 9px;
  color: var(--text-muted, #a4a6ad);
  font-size: 11px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.ka-action button {
  border-color: rgba(224, 186, 105, .5);
  background: #e0ba69;
  color: #17140d;
}

.ka-action button:disabled { cursor: default; opacity: .55; }

.ka-files {
  display: none;
  gap: 6px;
  overflow-x: auto;
  padding: 8px 12px 0;
}

.ka-files.has-files { display: flex; }
.ka-file {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 7px;
  max-width: 210px;
  padding: 6px 8px;
  border: 1px solid var(--border, #303238);
  border-radius: 9px;
  color: var(--text-muted, #a4a6ad);
  font-size: 10px;
}

.ka-file span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ka-file button { border: 0; background: transparent; color: inherit; cursor: pointer; }

.ka-composer {
  padding: 10px 12px 12px;
  border-top: 1px solid var(--border, #2a2c31);
}

.ka-input-row { display: flex; align-items: flex-end; gap: 8px; }
.ka-attach, .ka-send {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border, #303238);
  border-radius: 11px;
  background: var(--surface-2, #1b1c21);
  color: var(--text, #f4f4f2);
  cursor: pointer;
}

.ka-send { background: #ede9df; color: #151619; font-weight: 800; }
.ka-send:disabled { opacity: .45; cursor: default; }

.ka-input {
  flex: 1;
  min-height: 36px;
  max-height: 110px;
  resize: none;
  border: 1px solid var(--border, #303238);
  border-radius: 11px;
  outline: none;
  background: var(--surface-2, #1b1c21);
  color: var(--text, #f4f4f2);
  padding: 9px 11px;
  font: 13px/1.4 var(--font-sans, sans-serif);
}

.ka-footnote {
  margin-top: 7px;
  color: var(--text-dim, #70727a);
  text-align: center;
  font-size: 9px;
}

.jarvis-workspace {
  display: grid;
  grid-template-columns: minmax(210px, 270px) minmax(0, 1fr);
  height: calc(100dvh - 112px);
  min-height: 620px;
  overflow: hidden;
  border: 1px solid var(--border, #2a2c31);
  border-radius: 18px;
  background: var(--surface, #111216);
  color: var(--text, #f4f4f2);
  box-shadow: 0 22px 70px rgba(0, 0, 0, .2);
}

.jarvis-workspace:fullscreen,
.jarvis-workspace.ka-fullscreen-fallback {
  width: 100vw;
  height: 100dvh;
  min-height: 0;
  border: 0;
  border-radius: 0;
  background: var(--surface, #111216);
}

.jarvis-workspace.ka-fullscreen-fallback {
  position: fixed;
  inset: 0;
  z-index: 10020;
}

.ka-session-sidebar {
  min-width: 0;
  overflow: hidden;
  border-right: 1px solid var(--border, #2a2c31);
  background: var(--surface-2, #17181c);
}

.ka-session-sidebar-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 20px 16px 15px;
  border-bottom: 1px solid var(--border, #2a2c31);
}

.ka-workspace-eyebrow {
  color: var(--text-muted, #94969d);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.ka-session-sidebar h1 {
  margin: 4px 0 0;
  font-size: 18px;
  line-height: 1.2;
}

.ka-new-session,
.ka-workspace-header button {
  border: 1px solid var(--border, #303238);
  border-radius: 10px;
  background: var(--surface, #111216);
  color: var(--text, #f4f4f2);
  padding: 8px 10px;
  font: 650 11px/1 var(--font-sans, sans-serif);
  cursor: pointer;
}

.ka-session-list {
  height: calc(100% - 76px);
  overflow: auto;
  padding: 9px;
}

.ka-session-item {
  display: flex;
  align-items: center;
  gap: 3px;
  margin-bottom: 5px;
  border: 1px solid transparent;
  border-radius: 12px;
}

.ka-session-item.active {
  border-color: var(--border, #303238);
  background: var(--surface, #111216);
}

.ka-session-switch {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--text, #f4f4f2);
  padding: 10px;
  text-align: left;
  cursor: pointer;
}

.ka-session-switch span,
.ka-session-switch small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ka-session-switch span { font-size: 12px; font-weight: 650; }
.ka-session-switch small {
  margin-top: 4px;
  color: var(--text-muted, #94969d);
  font-size: 9px;
}

.ka-session-close,
.ka-session-rename {
  width: 28px;
  height: 28px;
  border: 0;
  background: transparent;
  color: var(--text-muted, #94969d);
  cursor: pointer;
}

.ka-session-rename { font-size: 13px; }
.ka-session-close:disabled { cursor: default; opacity: .35; }

.ka-workspace-chat {
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
}

.ka-workspace-header {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border, #2a2c31);
}

.jarvis-workspace .ka-messages {
  padding: 24px clamp(18px, 5vw, 72px);
}

.jarvis-workspace .ka-bubble { max-width: min(78%, 760px); }
.jarvis-workspace .ka-files { padding-right: clamp(18px, 5vw, 72px); padding-left: clamp(18px, 5vw, 72px); }
.jarvis-workspace .ka-composer { padding: 14px clamp(18px, 5vw, 72px) 17px; }
.jarvis-workspace .ka-input { max-height: 180px; }

@media (max-width: 680px) {
  :root {
    --im-launcher-edge: 10px;
    --im-launcher-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  }
}

@media (prefers-reduced-motion: reduce) {
  .jarvis-assistant-btn { transition: none; }
}

@media (max-width: 640px) {
  .jarvis-assistant-panel {
    width: calc(100vw - 20px);
    height: calc(100dvh - 88px - env(safe-area-inset-bottom, 0px));
  }

  .jarvis-workspace {
    grid-template-columns: 1fr;
    height: calc(100dvh - 92px);
    min-height: 0;
  }

  .ka-session-sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--border, #2a2c31);
  }

  .ka-session-sidebar-header { padding: 10px 12px; }
  .ka-session-sidebar h1 { display: none; }
  .ka-session-list {
    display: flex;
    height: auto;
    gap: 5px;
    overflow-x: auto;
    padding: 7px 9px;
  }
  .ka-session-item { flex: 0 0 min(180px, 58vw); margin: 0; }
  .ka-session-close { display: none; }
  .ka-workspace-header { padding: 10px 12px; }
  .jarvis-workspace .ka-messages { padding: 15px 12px; }
  .jarvis-workspace .ka-files,
  .jarvis-workspace .ka-composer { padding-right: 12px; padding-left: 12px; }
}
