.shc {
  --shc-btn: 56px;
  --shc-gap: var(--space-md, 1.5rem);
  position: fixed;
  right: var(--shc-gap);
  bottom: var(--shc-gap);
  z-index: 40;
  font-family: var(--font-ui);
  font-size: var(--text-base);
  line-height: 1.5;
  color: var(--color-ink);
}
.shc-btn {
  display: grid;
  place-items: center;
  width: var(--shc-btn);
  height: var(--shc-btn);
  margin-left: auto;
  padding: 0;
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--color-primary);
  color: var(--color-on-primary);
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  transition: background-color var(--dur-1) ease, transform var(--dur-2) var(--ease-out);
}
.shc-btn:hover { background: var(--color-primary-strong); }
.shc-btn:active { transform: scale(.96); }
.shc-btn:focus-visible,
.shc-close:focus-visible,
.shc-send:focus-visible { outline: none; box-shadow: var(--shadow-focus); }

.shc-panel {
  position: absolute;
  right: 0;
  bottom: calc(var(--shc-btn) + var(--space-sm));
  display: flex;
  flex-direction: column;
  width: min(380px, calc(100vw - 2 * var(--shc-gap)));
  height: min(560px, calc(100vh - var(--shc-btn) - 3 * var(--shc-gap)));
  height: min(560px, calc(100dvh - var(--shc-btn) - 3 * var(--shc-gap)));
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  transform-origin: bottom right;
  animation: shc-in var(--dur-3) var(--ease-out);
}
@keyframes shc-in { from { opacity: 0; transform: translateY(8px) scale(.98); } }

.shc-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-xs);
  padding: var(--space-xs) var(--space-xs) var(--space-xs) var(--space-sm);
  background: var(--color-primary);
  color: var(--color-on-primary);
}
.shc-title { margin: 0; font-weight: 700; font-size: var(--text-base); }
.shc-close {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: inherit;
  cursor: pointer;
}
.shc-close:hover { background: var(--color-primary-strong); }

.shc-log {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  padding: var(--space-sm);
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--color-background);
}
.shc-msg {
  max-width: 88%;
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-lg);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.shc-assistant {
  align-self: flex-start;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-bottom-left-radius: var(--radius-sm);
}
.shc-user {
  align-self: flex-end;
  background: var(--color-primary);
  color: var(--color-on-primary);
  border-bottom-right-radius: var(--radius-sm);
}
.shc-user a { color: inherit; }
.shc-assistant a, .shc-note a { color: var(--color-primary); }
.shc-note {
  align-self: stretch;
  max-width: none;
  padding: var(--space-2xs) var(--space-xs);
  font-size: var(--text-sm);
  color: var(--color-muted);
  text-align: center;
}

.shc-dots { display: inline-flex; gap: var(--space-1); padding: var(--space-2) 0; }
.shc-dots i {
  width: 7px;
  height: 7px;
  border-radius: var(--radius-pill);
  background: var(--color-border-strong);
  animation: shc-dot 1.2s infinite ease-in-out;
}
.shc-dots i:nth-child(2) { animation-delay: .15s; }
.shc-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes shc-dot { 0%, 80%, 100% { opacity: .3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

.shc-form {
  display: flex;
  align-items: flex-end;
  gap: var(--space-xs);
  padding: var(--space-xs);
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
}
.shc-trap { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }
.shc-input {
  flex: 1;
  min-height: 44px;
  max-height: 140px;
  padding: var(--space-xs) var(--space-sm);
  font: inherit;
  font-size: max(16px, var(--text-base));
  line-height: 1.4;
  color: var(--color-ink);
  background: var(--color-surface);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  resize: none;
}
.shc-input:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 1px var(--color-primary); }
.shc-send {
  display: grid;
  place-items: center;
  flex: none;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--color-primary);
  color: var(--color-on-primary);
  cursor: pointer;
}
.shc-send:hover { background: var(--color-primary-strong); }
.shc-send:disabled { opacity: .5; cursor: default; }

@media (max-width: 520px) {
  .shc { --shc-gap: var(--space-sm, 1rem); }
  .shc.is-open { inset: 0; }
  .shc.is-open .shc-btn { display: none; }
  .shc-panel {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
    border-radius: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .shc-panel, .shc-dots i { animation: none; }
  .shc-btn { transition: none; }
}

@media print { .shc { display: none; } }
