/* Shell chrome — pi must not touch this file. */
body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif; }
#site { min-height: 100vh; padding-right: 380px; }
#shell { display: contents; }

/* Desktop: chat lives in a fixed right rail, always visible. */
.pi-shell {
  position: fixed; top: 0; right: 0; bottom: 0; width: 380px;
  border-left: 1px solid #d2d2d7; background: #f5f5f7;
  display: flex; flex-direction: column;
  z-index: 10;
}

/* FAB and backdrop are desktop-hidden — only the bottom sheet flow uses them. */
.pi-fab, .pi-backdrop, .pi-sheet-close { display: none; }

/* Mobile: shell becomes a bottom sheet behind a floating action button. */
@media (max-width: 768px) {
  #site { padding-right: 0; }

  .pi-shell {
    top: auto; left: 0; right: 0; bottom: 0;
    width: 100%;
    height: 85vh;
    border-left: none;
    border-top: 1px solid #d2d2d7;
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -8px 28px rgba(0, 0, 0, 0.18);
    transform: translateY(100%);
    transition: transform 220ms cubic-bezier(0.32, 0.72, 0, 1);
    z-index: 30;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }
  .pi-shell.open { transform: translateY(0); }

  /* Sheet grabber — purely cosmetic affordance. */
  .pi-shell::before {
    content: "";
    position: absolute; top: 6px; left: 50%;
    width: 36px; height: 4px;
    margin-left: -18px;
    background: #c7c7cc;
    border-radius: 999px;
  }

  .pi-fab {
    display: flex; align-items: center; justify-content: center;
    position: fixed;
    right: 18px;
    bottom: calc(18px + env(safe-area-inset-bottom, 0));
    width: 56px; height: 56px;
    border-radius: 999px;
    background: #007aff; color: white;
    border: none;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
    cursor: pointer;
    z-index: 25;
    transition: transform 160ms ease, opacity 160ms ease;
  }
  .pi-fab:active { transform: scale(0.94); }
  .pi-fab.hidden { opacity: 0; pointer-events: none; transform: scale(0.6); }
  .pi-fab svg { width: 26px; height: 26px; }

  .pi-backdrop {
    display: block;
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.35);
    opacity: 0;
    pointer-events: none;
    transition: opacity 220ms ease;
    z-index: 20;
  }
  .pi-backdrop.open { opacity: 1; pointer-events: auto; }

  .pi-sheet-close {
    display: inline-flex; align-items: center; justify-content: center;
    font: inherit; font-size: 16px; line-height: 1;
    background: transparent; border: none;
    color: #6e6e73;
    width: 28px; height: 28px;
    border-radius: 999px;
    cursor: pointer;
    padding: 0;
  }
  .pi-sheet-close:active { background: rgba(0,0,0,0.06); }

  /* Give the grabber some breathing room above the header. */
  .pi-header { padding-top: 16px; }
}

/* iMessage-style chat */
.pi-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.6rem 0.9rem;
  background: rgba(245, 245, 247, 0.85);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid #d2d2d7;
  font-size: 13px;
}
.pi-header strong { font-weight: 600; }
.pi-header .status { color: #8e8e93; }
.pi-header button {
  font: inherit; font-size: 11px;
  background: transparent; border: 1px solid #d2d2d7;
  border-radius: 999px; padding: 2px 8px;
  color: #1d1d1f; cursor: pointer;
}

.pi-thread {
  flex: 1; overflow-y: auto;
  padding: 0.75rem 0.75rem 0.5rem;
  display: flex; flex-direction: column; gap: 2px;
}

.pi-banner {
  font-size: 11.5px;
  color: #ff3b30;
  text-align: center;
  padding: 4px 0;
  background: rgba(255, 59, 48, 0.08);
  border-bottom: 1px solid rgba(255, 59, 48, 0.2);
}

.pi-row {
  display: flex; max-width: 85%;
}
.pi-row.user      { align-self: flex-end; }
.pi-row.assistant { align-self: flex-start; }
.pi-row.system    { align-self: center; max-width: 100%; }

.pi-row + .pi-row.user      { margin-top: 6px; }
.pi-row + .pi-row.assistant { margin-top: 6px; }

.pi-bubble {
  font-size: 14.5px;
  line-height: 1.35;
  padding: 7px 12px;
  border-radius: 18px;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.pi-row.user .pi-bubble {
  background: #007aff; color: white;
  border-bottom-right-radius: 4px;
}
.pi-row.assistant .pi-bubble {
  background: #e9e9eb; color: #1d1d1f;
  border-bottom-left-radius: 4px;
}
.pi-row.system .pi-bubble {
  background: transparent;
  color: #8e8e93;
  font-size: 11.5px;
  text-align: center;
  padding: 4px 10px;
}
.pi-row.system.error .pi-bubble {
  color: #ff3b30;
}

/* Tool calls inside an assistant bubble */
.pi-tools {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.pi-tools li { display: block; }

.pi-tool-row {
  font: inherit;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11.5px;
  line-height: 1.3;
  width: 100%;
  background: transparent;
  border: none;
  text-align: left;
  padding: 2px 4px;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  gap: 6px;
  align-items: baseline;
  color: #3a3a3c;
}
.pi-tool-row:hover { background: rgba(0,0,0,0.04); }
.pi-tool-chev {
  color: #8e8e93;
  flex: 0 0 auto;
  width: 10px;
}
.pi-tool-name {
  color: #6e6e73;
  font-weight: 600;
  flex: 0 0 auto;
}
.pi-tool-arg {
  color: #1d1d1f;
  word-break: break-all;
  white-space: pre-wrap;
  flex: 1 1 auto;
  text-align: left;
}
.pi-tool-err {
  color: #ff3b30;
  font-weight: 600;
  flex: 0 0 auto;
}
.pi-tool-detail {
  margin: 4px 4px 6px 18px;
  padding: 6px 8px;
  background: rgba(0,0,0,0.04);
  border-radius: 6px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11px;
}
.pi-tool-section-label {
  color: #8e8e93;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 2px;
  margin-top: 4px;
}
.pi-tool-section-label:first-child { margin-top: 0; }
.pi-tool-detail pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 180px;
  overflow-y: auto;
  color: #1d1d1f;
}
.pi-tool-err-pre { color: #ff3b30 !important; }

.pi-text { white-space: pre-wrap; }
.pi-tools + .pi-text { margin-top: 6px; }
.pi-text-pending { opacity: 0.7; }
.pi-text-meta { color: #8e8e93; font-style: italic; font-size: 12px; }

/* When the bubble has only tool calls (no text yet), tone the bg down */
.pi-bubble:has(.pi-tools:first-child:last-child) {
  background: #f2f2f4;
}

.pi-debug {
  max-height: 200px; overflow-y: auto;
  background: #1c1c1e; color: #30d158;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11px;
  padding: 0.5rem 0.75rem;
  border-top: 1px solid #d2d2d7;
}

.pi-composer {
  display: flex; gap: 0.5rem; align-items: center;
  padding: 0.6rem 0.75rem 0.85rem;
  border-top: 1px solid #d2d2d7;
  background: #f5f5f7;
}
.pi-composer input {
  flex: 1;
  font: inherit; font-size: 14.5px;
  padding: 8px 14px;
  border: 1px solid #d2d2d7;
  border-radius: 999px;
  background: white;
  outline: none;
}
.pi-composer input:focus { border-color: #007aff; }
.pi-composer button {
  font: inherit; font-size: 14px; font-weight: 600;
  background: #007aff; color: white;
  border: none; border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
}
.pi-composer button:disabled { background: #c7c7cc; cursor: not-allowed; }
