/* D·studio Tools — global floating chat widget (Cursor/Intercom-style).
 * FAB bottom-right on EVERY page; panel anchors to the corner and scales in.
 * Same glass/bevel/lavender family as the sidebar — all values from
 * colors_and_type.css tokens, never eyeballed. Injected via chat-widget.js. */

:root {
  --dcw-fab: 60px;           /* FAB diameter (matches Intercom/shadcn norm) */
  --dcw-gap: 22px;           /* offset from viewport corner */
  --dcw-w: 404px;            /* panel width */
  --dcw-h: 580px;            /* panel height (clamped on short screens) */
}

/* ── Launcher (FAB) ─────────────────────────────────────────────────────── */
.dcw-fab {
  position: fixed;
  right: var(--dcw-gap);
  bottom: var(--dcw-gap);
  z-index: 80;
  width: var(--dcw-fab);
  height: var(--dcw-fab);
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--ds-black, #000);
  /* lavender chrome bead — bevel + glow, NEVER a flat drop-shadow.
     Highlight stays tight at top-left so the periwinkle body dominates. */
  background:
    radial-gradient(125% 125% at 28% 20%, rgba(255,255,255,0.92) 0%, var(--ds-periwinkle, rgb(223,229,255)) 32%, var(--ds-periwinkle-deep, rgb(196,205,247)) 100%);
  box-shadow:
    inset 1px 1px 1px 0 rgba(255,255,255,0.7),
    inset 0 -2px 3px 0 var(--ds-peri-shade-30, rgba(40,46,86,0.30)),
    0 0 0 1px rgba(0,0,0,0.35),
    0 14px 34px -10px rgba(0,0,0,0.6),
    0 0 30px 0 var(--sds-glow-lavender, rgba(203,186,227,0.10));
  transition: transform .2s cubic-bezier(.34,1.56,.64,1), box-shadow .2s ease, opacity .18s ease;
}
.dcw-fab:hover {
  transform: translateY(-2px) scale(1.04);
  box-shadow:
    inset 1px 1px 1px 0 rgba(255,255,255,0.8),
    inset 0 -2px 3px 0 var(--ds-peri-shade-30, rgba(40,46,86,0.30)),
    0 0 0 1px rgba(0,0,0,0.35),
    0 18px 40px -10px rgba(0,0,0,0.62),
    0 0 46px 2px var(--ds-peri-70, rgba(223,229,255,0.45));
}
.dcw-fab:active { transform: translateY(0) scale(0.98); }
.dcw-fab svg { width: 25px; height: 25px; }
.dcw-fab .dcw-fab-close { display: none; }
.dcw-open .dcw-fab .dcw-fab-open { display: none; }
.dcw-open .dcw-fab .dcw-fab-close { display: block; }
.dcw-open .dcw-fab { transform: scale(0.92); }

/* status pip on the FAB (agent reachable / absent) */
.dcw-fab .dcw-pip {
  position: absolute; top: 2px; right: 2px;
  width: 13px; height: 13px; border-radius: 50%;
  border: 2.5px solid #0a0a0b;
  background: var(--ds-fg-faint, rgba(255,255,255,0.3));
  transition: background .3s ease;
}
.dcw-fab .dcw-pip.ok      { background: var(--ds-success, rgb(52,199,89)); }
.dcw-fab .dcw-pip.absent  { background: var(--ds-ember, rgb(250,115,5)); }
.dcw-fab .dcw-pip.checking{ background: var(--ds-periwinkle, rgb(223,229,255)); animation: dcw-pulse 1s ease-in-out infinite; }
@keyframes dcw-pulse { 0%,100%{opacity:.35;} 50%{opacity:1;} }

/* ── Panel ──────────────────────────────────────────────────────────────── */
.dcw-panel {
  position: fixed;
  right: var(--dcw-gap);
  bottom: calc(var(--dcw-gap) + var(--dcw-fab) + 14px);
  z-index: 79;
  width: var(--dcw-w);
  height: min(var(--dcw-h), calc(100vh - var(--dcw-gap) * 2 - var(--dcw-fab) - 14px));
  display: flex; flex-direction: column;
  border-radius: var(--ds-r-xl, 26px);
  overflow: hidden;
  font-family: var(--ds-font-sans, system-ui, sans-serif);
  /* glass chrome surface (sidebar family) */
  background: linear-gradient(180deg, rgba(22,22,24,0.86) 0%, rgba(14,14,16,0.82) 100%);
  -webkit-backdrop-filter: var(--sds-backdrop-blur, blur(18px));
  backdrop-filter: var(--sds-backdrop-blur, blur(18px));
  border: 1px solid var(--sds-border-thin, rgba(255,255,255,0.07));
  box-shadow:
    inset 1px 1px 1px 0 rgba(255,255,255,0.06),
    inset 0 -2px 2px 0 rgba(0,0,0,0.30),
    0 0 0 1px rgba(0,0,0,0.45),
    0 30px 70px -18px rgba(0,0,0,0.7),
    0 0 50px 0 var(--sds-glow-lavender, rgba(203,186,227,0.10));
  /* closed: scale in from the corner */
  transform-origin: bottom right;
  opacity: 0; transform: translateY(8px) scale(.96);
  pointer-events: none;
  transition: opacity .2s ease, transform .22s cubic-bezier(.34,1.3,.5,1);
}
.dcw-open .dcw-panel { opacity: 1; transform: none; pointer-events: auto; }

/* ── Header ─────────────────────────────────────────────────────────────── */
.dcw-head {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 11px;
  padding: 15px 16px;
  border-bottom: 1px solid var(--sds-border-thin, rgba(255,255,255,0.06));
}
.dcw-avatar {
  flex: 0 0 auto; width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--ds-black,#000);
  background: radial-gradient(120% 120% at 30% 22%, rgba(255,255,255,0.95) 0%, var(--ds-periwinkle, rgb(223,229,255)) 50%, var(--ds-periwinkle-deep, rgb(196,205,247)) 100%);
  box-shadow: inset 1px 1px 1px 0 rgba(255,255,255,0.6), inset 0 -2px 2px 0 var(--ds-peri-shade-25, rgba(40,46,86,0.25));
}
.dcw-avatar svg { width: 17px; height: 17px; }
.dcw-head-meta { flex: 1; min-width: 0; }
.dcw-head-title { font: 600 14.5px/1.2 var(--ds-font-sans); color: var(--ds-white,#fff); letter-spacing: -0.01em; }
.dcw-head-status { display: flex; align-items: center; gap: 6px; margin-top: 2px; font: 500 11.5px/1 var(--ds-font-sans); color: var(--ds-fg-subtle, rgba(255,255,255,0.55)); }
.dcw-head-status .dcw-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--ds-fg-faint, rgba(255,255,255,0.3)); }
.dcw-head-status .dcw-dot.ok { background: var(--ds-success, rgb(52,199,89)); box-shadow: 0 0 7px 0 rgba(52,199,89,0.6); }
.dcw-head-status .dcw-dot.absent { background: var(--ds-ember, rgb(250,115,5)); }
.dcw-head-status .dcw-dot.checking { background: var(--ds-periwinkle, rgb(223,229,255)); animation: dcw-pulse 1s ease-in-out infinite; }
.dcw-head-btn {
  flex: 0 0 auto; width: 30px; height: 30px; border: 0; cursor: pointer;
  display: flex; align-items: center; justify-content: center; border-radius: 9px;
  color: var(--ds-fg-subtle, rgba(255,255,255,0.6));
  background: var(--ds-w-03, rgba(255,255,255,0.03));
  border: 1px solid var(--sds-border-thin, rgba(255,255,255,0.06));
  transition: background .15s ease, color .15s ease;
}
.dcw-head-btn:hover { background: var(--ds-w-07, rgba(255,255,255,0.07)); color: var(--ds-white,#fff); }
.dcw-head-btn svg { width: 15px; height: 15px; }

/* ── Messages ───────────────────────────────────────────────────────────── */
.dcw-msgs {
  flex: 1; min-height: 0; overflow-y: auto;
  padding: 16px 16px 8px;
  display: flex; flex-direction: column; gap: 12px;
  scroll-behavior: smooth;
}
.dcw-msgs::-webkit-scrollbar { width: 5px; }
.dcw-msgs::-webkit-scrollbar-track { background: transparent; }
.dcw-msgs::-webkit-scrollbar-thumb { background: var(--ds-w-10, rgba(255,255,255,0.1)); border-radius: 3px; }

.dcw-msg { max-width: 85%; font: 400 13.5px/1.55 var(--ds-font-sans); word-break: break-word; }
.dcw-msg.user {
  align-self: flex-end;
  padding: 10px 14px; border-radius: 16px 16px 5px 16px;
  background: linear-gradient(180deg, var(--ds-peri-14, rgba(223,229,255,0.14)) 0%, var(--ds-peri-10, rgba(223,229,255,0.1)) 100%);
  border: 1px solid var(--ds-peri-14, rgba(223,229,255,0.14));
  color: var(--ds-white, #fff);
}
.dcw-msg.agent {
  align-self: flex-start;
  padding: 10px 14px; border-radius: 16px 16px 16px 5px;
  background: var(--ds-w-03, rgba(255,255,255,0.04));
  border: 1px solid var(--sds-border-thin, rgba(255,255,255,0.06));
  color: rgba(255,255,255,0.88);
}
.dcw-msg.err {
  align-self: flex-start;
  padding: 9px 13px; border-radius: 14px;
  background: rgba(255,90,90,0.07); border: 1px solid rgba(255,90,90,0.3);
  color: rgba(255,150,150,0.92);
  display: flex; flex-direction: column; align-items: flex-start; gap: 8px;
}
.dcw-retry {
  padding: 5px 11px; border-radius: var(--ds-r-pill, 100px); cursor: pointer;
  font: 500 11.5px/1 var(--ds-font-sans); color: rgba(255,150,150,0.92);
  background: rgba(255,90,90,0.1); border: 1px solid rgba(255,90,90,0.35);
  transition: background .15s ease;
}
.dcw-retry:hover { background: rgba(255,90,90,0.18); }

/* copy button on agent bubbles — appears on hover, tucked under the text */
.dcw-msg.agent { position: relative; }
.dcw-copy {
  display: block; margin-top: 6px; padding: 3px 9px; border-radius: 7px; cursor: pointer;
  font: 500 10.5px/1 var(--ds-font-sans); color: var(--ds-fg-faint, rgba(255,255,255,0.35));
  background: transparent; border: 1px solid transparent;
  opacity: 0; transition: opacity .15s ease, background .15s ease, color .15s ease;
}
.dcw-msg.agent:hover .dcw-copy { opacity: 1; }
.dcw-copy:hover {
  background: var(--ds-w-07, rgba(255,255,255,0.07)); color: rgba(255,255,255,0.85);
  border-color: var(--sds-border-thin, rgba(255,255,255,0.06));
}
/* markdown inside agent bubbles (self-hosted mini renderer) */
.dcw-msg.agent p { margin: 0 0 8px; }
.dcw-msg.agent p:last-child { margin-bottom: 0; }
.dcw-msg.agent strong { color: #fff; font-weight: 600; }
.dcw-msg.agent em { font-style: italic; }
.dcw-msg.agent a { color: var(--ds-periwinkle, rgb(223,229,255)); text-decoration: underline; text-underline-offset: 2px; }
.dcw-msg.agent ul, .dcw-msg.agent ol { margin: 4px 0 8px; padding-left: 18px; }
.dcw-msg.agent li { margin: 2px 0; }
.dcw-msg.agent code {
  font: 500 12px/1.4 var(--ds-font-mono, ui-monospace, Menlo, monospace);
  background: rgba(255,255,255,0.07); border: 1px solid var(--sds-border-thin, rgba(255,255,255,0.06));
  padding: 1px 5px; border-radius: 5px; color: #e6e1ef;
}
.dcw-msg.agent pre {
  margin: 6px 0; padding: 11px 12px; overflow-x: auto;
  background: #0e0e10; border: 1px solid var(--ds-w-10, rgba(255,255,255,0.09)); border-radius: 11px;
}
.dcw-msg.agent pre code { background: none; border: 0; padding: 0; font-size: 11.5px; color: #e6e1ef; }

/* thinking — three pulsing lavender dots */
.dcw-typing { align-self: flex-start; display: flex; gap: 4px; padding: 12px 14px; }
.dcw-typing span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--ds-periwinkle, rgb(223,229,255));
  animation: dcw-bounce 1.3s ease-in-out infinite;
}
.dcw-typing span:nth-child(2) { animation-delay: .18s; }
.dcw-typing span:nth-child(3) { animation-delay: .36s; }
@keyframes dcw-bounce { 0%,60%,100% { opacity:.3; transform: translateY(0); } 30% { opacity:1; transform: translateY(-4px); } }

/* ── Empty state (greeting + suggestion chips) ──────────────────────────── */
.dcw-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 20px 22px; gap: 6px; }
.dcw-empty-mark {
  width: 44px; height: 44px; border-radius: 50%; margin-bottom: 8px;
  display: flex; align-items: center; justify-content: center; color: var(--ds-black,#000);
  background: radial-gradient(120% 120% at 30% 22%, rgba(255,255,255,0.95) 0%, var(--ds-periwinkle, rgb(223,229,255)) 50%, var(--ds-periwinkle-deep, rgb(196,205,247)) 100%);
  box-shadow: inset 1px 1px 1px 0 rgba(255,255,255,0.6), 0 0 26px 0 var(--sds-glow-lavender, rgba(203,186,227,0.10));
}
.dcw-empty-mark svg { width: 22px; height: 22px; }
.dcw-empty-title { font: 600 16px/1.3 var(--ds-font-sans); color: var(--ds-white,#fff); letter-spacing: -0.01em; }
.dcw-empty-sub { font: 400 13px/1.55 var(--ds-font-sans); color: var(--ds-fg-subtle, rgba(255,255,255,0.55)); max-width: 270px; }

.dcw-chips { display: flex; flex-wrap: wrap; gap: 7px; justify-content: center; margin-top: 14px; }
.dcw-chip {
  padding: 8px 13px; border-radius: var(--ds-r-pill, 100px); cursor: pointer;
  font: 500 12.5px/1 var(--ds-font-sans); color: rgba(255,255,255,0.82);
  background: var(--ds-w-03, rgba(255,255,255,0.03));
  border: 1px solid var(--sds-border-thin, rgba(255,255,255,0.07));
  transition: background .15s ease, border-color .15s ease, color .15s ease, transform .12s ease;
}
.dcw-chip:hover { background: var(--ds-peri-10, rgba(223,229,255,0.1)); border-color: var(--ds-peri-14, rgba(223,229,255,0.14)); color: #fff; transform: translateY(-1px); }

/* ── Absent state (agent not running) ───────────────────────────────────── */
.dcw-absent { flex: 1; display: flex; flex-direction: column; justify-content: center; padding: 22px; gap: 13px; }
.dcw-absent-title { font: 600 15px/1.35 var(--ds-font-sans); color: var(--ds-white,#fff); }
.dcw-absent-sub { font: 400 13px/1.55 var(--ds-font-sans); color: var(--ds-fg-subtle, rgba(255,255,255,0.55)); }
.dcw-code {
  position: relative; background: #0e0e10; border: 1px solid var(--ds-w-10, rgba(255,255,255,0.09));
  border-radius: 11px; padding: 12px 42px 12px 12px;
}
.dcw-code pre { margin: 0; font: 400 11.5px/1.5 var(--ds-font-mono, Menlo, monospace); color: #e6e1ef; white-space: pre-wrap; word-break: break-word; }
.dcw-code-copy {
  position: absolute; top: 8px; right: 8px; padding: 5px 9px; border-radius: 7px; cursor: pointer;
  border: 1px solid var(--ds-w-10, rgba(255,255,255,0.12)); background: var(--ds-w-03, rgba(255,255,255,0.04));
  color: rgba(255,255,255,0.7); font: 500 10.5px/1 var(--ds-font-sans);
}
.dcw-code-copy:hover { background: var(--ds-w-07, rgba(255,255,255,0.07)); color: #fff; }

/* ── Composer ───────────────────────────────────────────────────────────── */
.dcw-composer { flex: 0 0 auto; display: flex; gap: 8px; align-items: flex-end; padding: 12px 14px 14px; border-top: 1px solid var(--sds-border-thin, rgba(255,255,255,0.06)); }
.dcw-input {
  flex: 1; resize: none; max-height: 120px; min-height: 22px; overflow-y: auto;
  background: var(--ds-w-03, rgba(255,255,255,0.04));
  border: 1px solid var(--ds-w-10, rgba(255,255,255,0.1)); border-radius: 16px;
  padding: 10px 14px; color: #fff; font: 400 13.5px/1.4 var(--ds-font-sans); outline: none;
  transition: border-color .15s ease, background .15s ease;
}
.dcw-input::placeholder { color: var(--ds-fg-faint, rgba(255,255,255,0.3)); }
.dcw-input:focus { border-color: var(--ds-peri-14, rgba(223,229,255,0.3)); background: var(--ds-peri-03, rgba(223,229,255,0.03)); }
.dcw-input:disabled { opacity: .5; cursor: not-allowed; }
.dcw-send {
  flex: 0 0 auto; width: 40px; height: 40px; border: 0; border-radius: 13px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; color: var(--ds-black,#000);
  background: var(--ds-periwinkle, rgb(223,229,255));
  box-shadow: inset 1px 1px 1px 0 rgba(255,255,255,0.5);
  transition: opacity .15s ease, transform .12s ease, box-shadow .15s ease;
}
.dcw-send:hover:not(:disabled) { box-shadow: inset 1px 1px 1px 0 rgba(255,255,255,0.5), 0 0 18px 0 var(--ds-peri-70, rgba(223,229,255,0.4)); }
.dcw-send:active:not(:disabled) { transform: scale(0.94); }
.dcw-send:disabled { opacity: .3; cursor: not-allowed; }
.dcw-send svg { width: 17px; height: 17px; }

/* ── Mobile: panel goes full-width sheet ────────────────────────────────── */
@media (max-width: 560px) {
  .dcw-panel {
    right: 10px; left: 10px; width: auto;
    bottom: calc(var(--dcw-gap) + var(--dcw-fab) + 12px);
    height: min(72vh, 600px);
  }
}
@media (prefers-reduced-motion: reduce) {
  .dcw-fab, .dcw-panel { transition: opacity .12s ease !important; }
  .dcw-fab:hover { transform: none; }
}
