.onool-ai {
  --ai-primary: #a83b43;
  --ai-primary-dark: #7f2c33;
  --ai-primary-soft: #fdebec;
  --ai-ink: #47292c;
  --ai-soft: #fff7f7;
  --ai-top-offset: 148px;
  position: fixed;
  z-index: 9990;
  top: var(--ai-top-offset);
  right: max(18px, env(safe-area-inset-right));
  bottom: auto;
  display: flex;
  flex-direction: column-reverse;
  align-items: flex-end;
  font-family: Pretendard, "Apple SD Gothic Neo", "Noto Sans KR", Arial, sans-serif;
}

body.admin-bar .onool-ai { --ai-top-offset: 180px; }

.onool-ai button,
.onool-ai textarea { font: inherit; }

.onool-ai-launcher {
  width: 62px;
  height: 62px;
  display: grid;
  place-items: center;
  margin-left: auto;
  padding: 0;
  color: var(--ai-primary);
  border: 1px solid rgba(168, 59, 67, .16);
  border-radius: 50%;
  background: var(--ai-primary-soft);
  box-shadow: 0 12px 32px rgba(107, 40, 46, .2);
  transition: transform .18s ease, background .18s ease, color .18s ease;
}

.onool-ai-launcher:hover,
.onool-ai-launcher:focus-visible { color: #fff; background: var(--ai-primary); transform: translateY(-2px); outline: 3px solid rgba(168,59,67,.16); outline-offset: 3px; }
.onool-ai-launcher svg { width: 29px; height: 29px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.onool-ai-launcher > span { font-size: 32px; font-weight: 300; line-height: 1; }

.onool-ai-panel {
  width: min(410px, calc(100vw - 28px));
  height: min(650px, calc(100dvh - var(--ai-top-offset) - 92px));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto auto;
  margin-top: 13px;
  overflow: hidden;
  color: var(--ai-ink);
  border: 1px solid rgba(168, 59, 67, .14);
  border-radius: 22px;
  background: #fff;
  box-shadow: 0 22px 70px rgba(91, 40, 44, .2);
  animation: onool-ai-enter .2s ease-out;
}

.aaa-ai-chat-frame {
  width: min(410px, calc(100vw - 28px));
  height: min(650px, calc(100dvh - var(--ai-top-offset) - 92px));
  margin-top: 13px;
  overflow: hidden;
  border: 1px solid rgba(168, 59, 67, .14);
  border-radius: 22px;
  background: #fff;
  box-shadow: 0 22px 70px rgba(91, 40, 44, .2);
  animation: onool-ai-enter .2s ease-out;
}

.aaa-ai-chat-frame[hidden] { display: none; }
.aaa-ai-chat-frame iframe { width: 100%; height: 100%; display: block; border: 0; background: #fff; }

body:has(.onool-ai-embed-page) { margin: 0; overflow: hidden; background: #fff; }
body:has(.onool-ai-embed-page) > :not(.onool-ai) { display: none !important; }
.onool-ai-embed-page { display: none !important; }
.onool-ai--embedded { position: fixed; z-index: 1; inset: 0; display: block; }
.onool-ai--embedded .onool-ai-panel { width: 100%; height: 100dvh; margin: 0; border: 0; border-radius: 0; box-shadow: none; animation: none; }

@keyframes onool-ai-enter { from { opacity: 0; transform: translateY(12px) scale(.98); } }

.onool-ai-header {
  min-height: 76px;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 13px 13px 13px 16px;
  color: var(--ai-primary);
  background: var(--ai-primary-soft);
}

.onool-ai-avatar { width: 44px; height: 44px; flex: 0 0 44px; display: grid; place-items: center; color: var(--ai-primary); border-radius: 50%; background: #fff; box-shadow: inset 0 0 0 1px rgba(168,59,67,.12); }
.onool-ai-avatar svg { width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.onool-ai-title { min-width: 0; display: grid; flex: 1; gap: 3px; }
.onool-ai-title__heading { display: flex; align-items: center; gap: 7px; }
.onool-ai-title strong { font-size: 15px; font-weight: 800; letter-spacing: -.025em; }
.onool-ai-beta { padding: 2px 6px; color: #fff; border-radius: 999px; background: var(--ai-primary); font-size: 9px; font-weight: 850; letter-spacing: .04em; line-height: 1.3; text-transform: uppercase; }
.onool-ai-title small { display: flex; align-items: center; gap: 6px; color: var(--ai-primary-dark); font-size: 11px; }
.onool-ai-title i { width: 7px; height: 7px; border-radius: 50%; background: #d66f76; box-shadow: 0 0 0 3px rgba(214,111,118,.15); }
.onool-ai-header__action { width: 32px; height: 38px; display: grid; place-items: center; flex: 0 0 32px; padding: 0; color: rgba(168,59,67,.84); border: 0; background: transparent; font-size: 25px; font-weight: 300; line-height: 1; }
.onool-ai-header__action:hover,
.onool-ai-header__action:focus-visible { color: var(--ai-primary-dark); outline: 1px solid rgba(168,59,67,.42); border-radius: 8px; }

.onool-ai-messages { min-height: 0; display: flex; flex-direction: column; gap: 10px; overflow-y: auto; padding: 18px 16px 14px; background: var(--ai-soft); scroll-behavior: smooth; }
.onool-ai-message { display: flex; }
.onool-ai-message p { max-width: 86%; margin: 0; padding: 11px 13px; border-radius: 16px; font-size: 13px; letter-spacing: -.015em; line-height: 1.58; white-space: pre-wrap; overflow-wrap: anywhere; }
.onool-ai-message--assistant { justify-content: flex-start; }
.onool-ai-message--assistant p,
.onool-ai-message--assistant .onool-ai-typing { color: var(--ai-ink); border: 1px solid rgba(168,59,67,.09); border-bottom-left-radius: 5px; background: #fff; box-shadow: 0 3px 12px rgba(107,40,46,.05); }
.onool-ai-message--user { justify-content: flex-end; }
.onool-ai-message--user p { color: #fff; border-bottom-right-radius: 5px; background: var(--ai-primary); }

.onool-ai-typing { display: flex; gap: 4px; padding: 14px 16px; border-radius: 16px; }
.onool-ai-typing i { width: 6px; height: 6px; border-radius: 50%; background: #c69398; animation: onool-ai-dot 1.15s infinite ease-in-out; }
.onool-ai-typing i:nth-child(2) { animation-delay: .15s; }
.onool-ai-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes onool-ai-dot { 0%, 60%, 100% { opacity: .42; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

.onool-ai-products { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-top: 2px; }
.onool-ai-product { min-width: 0; display: grid; grid-template-columns: 55px minmax(0,1fr); gap: 9px; align-items: center; padding: 7px; color: var(--ai-ink); border: 1px solid rgba(168,59,67,.1); border-radius: 12px; background: #fff; transition: border-color .15s ease, transform .15s ease; }
.onool-ai-product:hover,
.onool-ai-product:focus-visible { border-color: var(--ai-primary); outline: 0; transform: translateY(-1px); }
.onool-ai-product img,
.onool-ai-product__image { width: 55px; height: 55px; display: block; object-fit: cover; border-radius: 8px; background: var(--ai-primary-soft); }
.onool-ai-product__copy { min-width: 0; display: grid; gap: 5px; }
.onool-ai-product__copy strong { display: -webkit-box; overflow: hidden; font-size: 11px; font-weight: 750; line-height: 1.35; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.onool-ai-product__copy > span { display: flex; flex-wrap: wrap; gap: 4px; color: var(--ai-primary); font-size: 11px; font-weight: 800; }
.onool-ai-product del { color: #b89da0; font-size: 9px; font-weight: 500; }

.onool-ai-quick { display: flex; gap: 6px; overflow-x: auto; padding: 10px 12px 8px; border-top: 1px solid rgba(168,59,67,.08); background: #fff; scrollbar-width: none; }
.onool-ai-quick::-webkit-scrollbar { display: none; }
.onool-ai-quick button { min-height: 30px; flex: 0 0 auto; padding: 5px 10px; color: var(--ai-primary); border: 1px solid rgba(168,59,67,.28); border-radius: 999px; background: var(--ai-primary-soft); font-size: 10px; font-weight: 720; }
.onool-ai-quick button:hover,
.onool-ai-quick button:focus-visible { color: #fff; border-color: var(--ai-primary); background: var(--ai-primary); outline: 0; }
.onool-ai-quick button:disabled { opacity: .45; cursor: wait; }

.onool-ai-form { display: grid; grid-template-columns: minmax(0, 1fr) 43px; gap: 8px; align-items: end; padding: 3px 12px 10px; background: #fff; }
.onool-ai-form textarea { width: 100%; min-height: 43px; max-height: 102px; resize: none; padding: 11px 13px; color: var(--ai-ink); border: 1px solid rgba(168,59,67,.2); border-radius: 12px; background: #fff; font-size: 13px; line-height: 1.45; }
.onool-ai-form textarea:focus { border-color: var(--ai-primary); outline: 3px solid rgba(168,59,67,.1); }
.onool-ai-form button { width: 43px; height: 43px; display: grid; place-items: center; padding: 0; color: #fff; border: 0; border-radius: 12px; background: var(--ai-primary); }
.onool-ai-form button:hover,
.onool-ai-form button:focus-visible { background: var(--ai-primary-dark); outline: 3px solid rgba(168,59,67,.14); }
.onool-ai-form button:disabled { opacity: .38; cursor: default; }
.onool-ai-form svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.onool-ai-footer { min-height: 28px; display: flex; justify-content: center; align-items: center; gap: 8px; padding: 0 12px 8px; color: #927b7e; background: #fff; font-size: 9px; }
.onool-ai-footer a,
.onool-ai-footer button { padding: 0; color: var(--ai-primary); border: 0; background: transparent; font-size: inherit; font-weight: 750; text-decoration: underline; text-underline-offset: 2px; }
.onool-ai-footer button:disabled { opacity: .45; cursor: wait; }

@media (max-width: 700px) {
  .onool-ai { --ai-top-offset: calc(76px + env(safe-area-inset-top)); right: 12px; }
  body.admin-bar .onool-ai { --ai-top-offset: calc(122px + env(safe-area-inset-top)); }
  .onool-ai-launcher { width: 56px; height: 56px; }
  .onool-ai-panel,
  .aaa-ai-chat-frame { width: calc(100vw - 24px); height: min(620px, calc(100dvh - var(--ai-top-offset) - 142px)); margin-top: 10px; border-radius: 19px; }
  .onool-ai--embedded .onool-ai-panel { width: 100%; height: 100dvh; margin: 0; border-radius: 0; }
  .onool-ai-products { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .onool-ai-panel,
  .onool-ai-typing i { animation: none; }
  .onool-ai-messages { scroll-behavior: auto; }
}
