/* Stickers V1: hand-drawn notebook sticker button, 4-column bottom drawer, in-place naming, and bubble-free message sticker segments. */
.sticker-toggle {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
  transition:
    background-color 140ms var(--ease-out, ease-out),
    transform 100ms var(--ease-out, ease-out);
}

.sticker-toggle svg {
  width: 22px;
  height: 22px;
}

.sticker-toggle[aria-expanded="true"] {
  background: color-mix(in srgb, var(--sage, #dfe8df) 65%, transparent);
  color: var(--ink, #393d42);
}

.sticker-toggle:focus-visible {
  outline: 2px solid var(--ink, #655846);
  outline-offset: 2px;
}

@media (hover: hover) and (pointer: fine) {
  .sticker-toggle:hover {
    background: color-mix(in srgb, var(--sage, #dfe8df) 45%, transparent);
  }
}

.sticker-drawer {
  margin-top: 6px;
  padding: 10px;
  border: 1px solid var(--rule, #cdc4b7);
  border-radius: 18px 16px 20px 15px;
  background: var(--paper, #fbf8f0);
  max-height: min(calc(var(--app-vh, 100dvh) * 0.36), 256px);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  box-sizing: border-box;
  animation: sticker-drawer-enter 180ms cubic-bezier(0.22, 1, 0.36, 1);
}

.sticker-drawer[hidden],
.composer.voice-mode .sticker-drawer {
  display: none !important;
}

@keyframes sticker-drawer-enter {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.sticker-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px 8px;
  align-items: start;
}

.sticker-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-width: 0;
}

.sticker-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
}

.sticker-pick,
.sticker-add-box {
  position: relative;
  width: 100%;
  height: 100%;
  min-width: 44px;
  min-height: 44px;
  aspect-ratio: 1 / 1;
  padding: 6px;
  border: 1px solid color-mix(in srgb, var(--rule, #cdc4b7) 72%, transparent);
  border-radius: 13px 11px 14px 10px;
  background: color-mix(in srgb, var(--paper, #fbf8f0) 80%, #ffffff);
  display: grid;
  place-items: center;
  cursor: pointer;
  box-sizing: border-box;
  touch-action: manipulation;
  transition:
    transform 110ms var(--ease-out, ease-out),
    border-color 140ms var(--ease-out, ease-out),
    background-color 140ms var(--ease-out, ease-out);
}

.sticker-add-box {
  border: 1.35px dashed var(--muted, #85887e);
  background: transparent;
  color: var(--muted, #747971);
}

.sticker-add-icon {
  display: grid;
  place-items: center;
}

.sticker-add-icon svg {
  width: 24px;
  height: 24px;
}

.sticker-file-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.sticker-add-caption {
  font-size: 11px;
  line-height: 1.25;
  color: var(--muted, #747971);
  text-align: center;
  min-height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.sticker-pick:active,
.sticker-add-box:active {
  transform: scale(0.96);
}

.sticker-pick:focus-visible,
.sticker-add-box:focus-within {
  outline: 2px solid var(--ink, #655846);
  outline-offset: 2px;
}

.sticker-thumb {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
}

.sticker-delete {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 22px;
  height: 22px;
  min-width: 22px;
  min-height: 22px;
  padding: 0;
  border: 1px solid color-mix(in srgb, var(--rule, #cdc4b7) 75%, transparent);
  border-radius: 50%;
  background: color-mix(in srgb, var(--paper, #fbf8f0) 92%, #ffffff);
  color: var(--muted, #747971);
  display: grid;
  place-items: center;
  cursor: pointer;
  opacity: 0.78;
  transition: opacity 140ms ease, color 140ms ease;
}

.sticker-delete svg {
  width: 12px;
  height: 12px;
}

.sticker-delete:hover,
.sticker-delete:focus-visible {
  opacity: 1;
  color: var(--danger, #9b6267);
}

.sticker-name-wrap {
  width: 100%;
  min-width: 0;
  display: flex;
  justify-content: center;
}

.sticker-name-btn {
  width: 100%;
  min-height: 20px;
  padding: 1px 4px;
  border: 0;
  border-bottom: 1px dashed transparent;
  border-radius: 4px;
  background: transparent;
  color: var(--ink, #393d42);
  font: inherit;
  font-size: 11px;
  line-height: 1.25;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: text;
}

.sticker-name-btn.is-unnamed {
  color: var(--muted, #8a8175);
  opacity: 0.78;
}

.sticker-name-btn:hover,
.sticker-name-btn:focus-visible {
  border-bottom-color: var(--rule, #cdc4b7);
  outline: none;
}

.sticker-name-input {
  width: 100%;
  min-width: 0;
  height: 22px;
  padding: 1px 4px;
  border: 1px solid var(--rule, #cdc4b7);
  border-radius: 5px;
  background: #ffffff;
  color: var(--ink, #393d42);
  font: inherit;
  font-size: 11px;
  line-height: 1.2;
  text-align: center;
  box-sizing: border-box;
}

.sticker-name-input:focus {
  outline: 1.5px solid var(--ink, #655846);
  outline-offset: 0;
}

/* Message multi-segment layout: user text bubbles + bubble-free stickers; assistant bubble-free text + stickers. */
.message.user .message-text.has-sticker-segments {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  background: transparent !important;
  padding: 0 !important;
  border-radius: 0 !important;
  width: 100%;
  white-space: normal;
}

.message.user .user-bubble-segment {
  display: inline-block;
  background: var(--blue, #e3e9ef);
  padding: 0.62em 1em;
  border-radius: 1.3em 1.3em 1.18em 1.3em;
  text-align: left;
  width: fit-content;
  max-width: 100%;
  min-width: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  box-sizing: border-box;
}

.message.assistant .message-text.has-sticker-segments {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  min-width: 0;
  white-space: normal;
}

.message.assistant .assistant-text-segment {
  width: 100%;
  min-width: 0;
  background: transparent;
  padding: 0;
  border: 0;
  white-space: normal;
  overflow-wrap: anywhere;
}

.message-sticker-segment {
  margin: 2px 0;
  padding: 0;
  border: 0;
  background: transparent !important;
  display: block;
  width: fit-content;
  max-width: 100%;
  line-height: 0;
}

.message.user .message-sticker-segment {
  align-self: flex-end;
}

.message.assistant .message-sticker-segment {
  align-self: flex-start;
}

.message-sticker-image {
  display: block;
  width: auto;
  height: auto;
  max-width: clamp(96px, 28vw, 136px);
  max-height: clamp(96px, 28vw, 136px);
  object-fit: contain;
  border-radius: 8px;
  background: transparent;
}

.message-sticker-fallback {
  display: inline-block;
  padding: 4px 10px;
  border: 1px dashed var(--rule, #cdc4b7);
  border-radius: 10px 8px 11px 9px;
  background: transparent;
  color: var(--muted, #747971);
  font-size: 12.5px;
  line-height: 1.4;
}

@media (prefers-reduced-motion: reduce) {
  .sticker-drawer,
  .sticker-toggle,
  .sticker-pick,
  .sticker-add-box {
    animation: none;
    transition: none;
  }
  .sticker-pick:active,
  .sticker-add-box:active {
    transform: none;
  }
}

html[data-reduced="true"] .sticker-drawer,
html[data-reduced="true"] .sticker-toggle,
html[data-reduced="true"] .sticker-pick,
html[data-reduced="true"] .sticker-add-box {
  animation: none;
  transition: none;
}
