/* Dashboard chat panel — the conversation with Marcus.
   Spec: docs/superpowers/specs/2026-09-04-chat-panel-redesign-design.md
   A full-height sheet docked right, built from the dashboard's own tokens so
   it is correct in both themes. The page behind stays usable. */

#marcus-chat {
  position: fixed;
  inset: 0;
  z-index: 320;
  display: flex;
  align-items: stretch;
  justify-content: flex-end;
  padding: 16px;
  pointer-events: none;
}
#marcus-chat[hidden] { display: none; }

.mc-panel {
  pointer-events: auto;
  width: min(100%, 420px);
  height: 100%;
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-lg), 0 0 0 1px var(--border);
  overflow: hidden;
  position: relative;
  /* Mirrors the Mac panel: the sheet swings in from its trailing edge like
     a door — a slight y-axis rotation and scale anchored on the right, a
     short slide and a fade. Opening gets a soft overshoot; closing is
     quicker and fully damped so dismissal feels decisive. */
  --mc-off: perspective(1400px) rotateY(8deg) scale(.96) translateX(48px);
  transform-origin: right center;
  transform: var(--mc-off);
  opacity: 0;
  animation: mc-swing-in .46s cubic-bezier(.22, 1.18, .36, 1) forwards;
  will-change: transform, opacity;
}
.mc-panel.mc-closing {
  animation: mc-swing-out .28s cubic-bezier(.4, 0, .6, 1) forwards;
  pointer-events: none;
}
@keyframes mc-swing-in { to { transform: none; opacity: 1; } }
@keyframes mc-swing-out {
  from { transform: none; opacity: 1; }
  to { transform: var(--mc-off); opacity: 0; }
}
/* Content settles into the sheet a beat after it lands. */
.mc-header, .mc-list, .mc-composer {
  opacity: 0;
  transform: translateY(10px);
  animation: mc-reveal .32s ease-out .12s forwards;
}
@keyframes mc-reveal { to { opacity: 1; transform: none; } }
/* The faintest warm wash at the top, so the panel reads as lit, not painted. */
.mc-panel::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 140px;
  background: linear-gradient(180deg, var(--terracotta-soft), transparent);
  opacity: .4;
  pointer-events: none;
}

/* ── Header ───────────────────────────────────────────────────────────── */
.mc-header {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 20px 12px;
}
.mc-title {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 500;
  letter-spacing: -.01em;
  line-height: 1.1;
  color: var(--text);
}
.mc-status {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: .14px;
  color: var(--text-tertiary);
}
.mc-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
}
.mc-status.thinking .mc-status-dot {
  background: var(--amber);
  animation: mc-breathe 1.8s ease-in-out infinite;
}
@keyframes mc-breathe {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .4; transform: scale(.85); }
}
.mc-close {
  margin-left: auto;
  flex: none;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 999px;
  background: var(--surface-elevated);
  box-shadow: 0 0 0 1px var(--border);
  color: var(--text-secondary);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.mc-close:hover { background: var(--surface-hover); color: var(--text); }
.mc-close svg { width: 12px; height: 12px; }

/* ── Messages ─────────────────────────────────────────────────────────── */
.mc-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 8px 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.mc-empty { padding: 28px 4px 8px; }
.mc-empty-title {
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 500;
  letter-spacing: -.01em;
  color: var(--text);
}
.mc-empty-text {
  margin-top: 8px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-tertiary);
}

.mc-day {
  align-self: center;
  margin: 8px 0 4px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .02em;
  color: var(--text-secondary);
  background: var(--surface-elevated);
  box-shadow: 0 0 0 1px var(--border);
}

.mc-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 80%;
}
.mc-row.marcus { align-self: flex-start; align-items: flex-start; }
.mc-row.user { align-self: flex-end; align-items: flex-end; }

.mc-bubble {
  padding: 9px 13px 7px;
  border-radius: 18px;
  font-size: 14.5px;
  line-height: 1.5;
  letter-spacing: .1px;
  color: var(--text);
}
.mc-row.marcus .mc-bubble {
  background: var(--surface-elevated);
  box-shadow: 0 0 0 1px var(--border);
  border-bottom-left-radius: 6px;
}
.mc-row.user .mc-bubble {
  background: var(--accent-soft);
  border-bottom-right-radius: 6px;
}
.mc-bubble.pending { opacity: .6; }
.mc-row.marcus .mc-bubble.error {
  background: var(--danger-soft);
  box-shadow: 0 0 0 1px rgba(220, 38, 38, .18);
  font-size: 13.5px;
}

.mc-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.mc-text p { margin: 0; }
.mc-text p + p { margin-top: 8px; }
.mc-text ul { margin: 4px 0 0; padding-left: 18px; }
.mc-text li { margin: 2px 0; }
.mc-text code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: .9em;
  padding: 1px 5px;
  border-radius: 5px;
  background: rgba(28, 25, 23, .06);
}
.mc-text a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }

.mc-time {
  display: block;
  text-align: right;
  margin-top: 3px;
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: .02em;
  color: var(--text-tertiary);
}
.mc-caption {
  padding: 0 4px;
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: .04em;
  color: var(--text-tertiary);
}
.mc-caption.nudge { color: var(--terracotta); }
.mc-caption.failed { color: var(--danger); }

.mc-voice {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.mc-voice svg { width: 14px; height: 14px; flex: none; }
.mc-transcript {
  margin-top: 5px;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--text-secondary);
}

.mc-typing {
  display: inline-flex;
  gap: 4px;
  padding: 5px 0 4px;
}
.mc-typing i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-tertiary);
  animation: mc-dot 1.2s ease-in-out infinite;
}
.mc-typing i:nth-child(2) { animation-delay: .2s; }
.mc-typing i:nth-child(3) { animation-delay: .4s; }
@keyframes mc-dot {
  0%, 60%, 100% { opacity: .25; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-2px); }
}

/* ── Composer ─────────────────────────────────────────────────────────── */
.mc-composer {
  border-top: 1px solid var(--border);
  padding: 10px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.mc-notice {
  padding: 0 4px;
  font-size: 12px;
  letter-spacing: .12px;
  color: var(--warning);
}
.mc-notice.error { color: var(--danger); }
.mc-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
.mc-icon-btn {
  flex: none;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 999px;
  background: var(--surface-elevated);
  box-shadow: 0 0 0 1px var(--border);
  color: var(--text-secondary);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.mc-icon-btn:hover { background: var(--surface-hover); color: var(--text); }
.mc-icon-btn:disabled { opacity: .45; cursor: default; }
.mc-icon-btn svg { width: 14px; height: 14px; }

.mc-field {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 5px 5px 5px 12px;
  border-radius: 999px;
  background: var(--surface-elevated);
  box-shadow: 0 0 0 1px var(--border);
  transition: box-shadow var(--transition);
}
.mc-field:focus-within { box-shadow: 0 0 0 1px var(--border-strong), 0 0 0 3px var(--accent-soft); }
.mc-field textarea {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  letter-spacing: .14px;
  color: var(--text);
  max-height: 110px;
  padding: 5px 0;
}
.mc-field textarea::placeholder { color: var(--text-tertiary); }
.mc-send {
  flex: none;
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: var(--bg);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.mc-send[hidden] { display: none; }
.mc-send:disabled { opacity: .45; cursor: default; }
.mc-send svg { width: 12px; height: 12px; }

/* Recording state replaces the field. */
.mc-rec {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  border-radius: 999px;
  background: var(--surface-elevated);
  box-shadow: 0 0 0 1px var(--border);
}
.mc-rec-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
  animation: mc-pulse 1.2s ease-in-out infinite;
}
@keyframes mc-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .45; }
}
.mc-rec-time {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}
.mc-rec-hint { font-size: 13px; color: var(--text-tertiary); }
.mc-send.rec { width: 34px; height: 34px; }

@media (prefers-reduced-motion: reduce) {
  .mc-panel { animation: mc-fade .16s ease-in-out forwards; transform: none; }
  .mc-panel.mc-closing { animation: mc-fade .16s ease-in-out reverse forwards; }
  .mc-header, .mc-list, .mc-composer { animation: none; opacity: 1; transform: none; }
  .mc-status.thinking .mc-status-dot { animation: none; }
  .mc-typing i { animation: none; opacity: .6; }
  .mc-rec-dot { animation: none; }
}
@keyframes mc-fade { from { opacity: 0; } to { opacity: 1; } }

@media (prefers-color-scheme: dark) {
  .mc-text code { background: rgba(255, 252, 247, .08); }
}

/* ── AI-bar entry point ────────────────────────────────────────────────── */
/* Text-only pill, same as the Mac toolbar: warms to the signature tint
   while Marcus is composing a reply, sits slightly pressed while open. */
.ai-bar-chat {
  margin-left: auto;
  flex: none;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: .13px;
  color: var(--text);
  background: var(--surface-elevated);
  cursor: pointer;
  transition: background .16s ease, transform .16s ease, border-color .16s ease;
}
.ai-bar-chat:hover { background: var(--surface-hover); }
.ai-bar-chat.is-open { transform: scale(.97); background: var(--surface-elevated); }
.ai-bar-chat.is-thinking {
  background: var(--terracotta-soft);
  border-color: transparent;
  box-shadow: 0 0 0 1px var(--terracotta-soft);
}

@media (max-width: 640px) {
  #marcus-chat { padding: 0; align-items: flex-end; justify-content: center; }
  .mc-panel {
    width: 100%;
    height: 92vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    /* Bottom sheet on phones: rise up instead of swinging in from the side. */
    --mc-off: translateY(28px) scale(.98);
    transform-origin: center bottom;
  }
  .mc-row { max-width: 86%; }
}
