:root {
  --cw-main: #5e59ff;
  --cw-text: #101828;
  --cw-muted: #7b8499;
  --cw-border: #e4e8f0;
}

.cw-chat,
.cw-chat * { box-sizing: border-box; }
.cw-chat { font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif; color: var(--cw-text); }
.cw-chat [hidden] { display: none !important; }

.cw-launcher {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 9999;
  width: 60px;
  height: 60px;
  border: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--cw-main);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 12px 30px rgba(94, 89, 255, .32);
}

.cw-launcher svg,
.cw-form svg {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.cw-launcher svg { width: 27px; stroke-width: 1.8; }

.cw-panel {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 9999;
  width: 380px;
  height: 560px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 48px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--cw-border);
  border-radius: 20px;
  background: #fff;
  box-shadow: 0 20px 60px rgba(16, 24, 40, .18);
}

.cw-header {
  min-height: 74px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 11px;
  border-bottom: 1px solid var(--cw-border);
}

.cw-avatar {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--cw-main);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}

.cw-info { min-width: 0; flex: 1; }
.cw-info strong { display: block; font-size: 14px; }
.cw-info span {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 4px;
  color: var(--cw-muted);
  font-size: 10px;
}
.cw-info i { width: 7px; height: 7px; border-radius: 50%; background: #20c77a; }

.cw-close {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: #667085;
  cursor: pointer;
  font-size: 24px;
}
.cw-close:hover { background: #f4f5f7; }

.cw-messages {
  min-height: 0;
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 18px 16px;
  background: #fafbfc;
}

.cw-message { width: fit-content; max-width: 82%; margin-bottom: 14px; }
.cw-message p {
  margin: 0;
  padding: 11px 13px;
  border: 1px solid #dde3ed;
  border-radius: 16px 16px 16px 6px;
  background: #fff;
  font-size: 13px;
  line-height: 1.5;
}
.cw-message small { display: block; margin-top: 4px; color: #98a2b3; font-size: 9px; }
.cw-me { margin-left: auto; }
.cw-me p { border: 0; border-radius: 16px 16px 6px 16px; background: var(--cw-main); color: #fff; }
.cw-me small { text-align: right; }

.cw-quick { display: flex; flex-wrap: wrap; gap: 7px; margin: 2px 0 16px; }
.cw-quick button {
  padding: 7px 10px;
  border: 1px solid #d9d7ff;
  border-radius: 999px;
  background: #fff;
  color: var(--cw-main);
  cursor: pointer;
  font: inherit;
  font-size: 11px;
}
.cw-quick button:hover { background: #f4f3ff; }

.cw-form {
  padding: 12px;
  display: flex;
  gap: 8px;
  border-top: 1px solid var(--cw-border);
  background: #fff;
}

.cw-form input {
  min-width: 0;
  flex: 1;
  height: 44px;
  padding: 0 14px;
  border: 1px solid var(--cw-border);
  border-radius: 14px;
  outline: 0;
  font: inherit;
  font-size: 12px;
}
.cw-form input:focus { border-color: var(--cw-main); }

.cw-form button {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  border: 0;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: var(--cw-main);
  color: #fff;
  cursor: pointer;
}
.cw-form svg { width: 19px; stroke-width: 1.7; }

@media (max-width: 600px) {
  .cw-launcher {
    right: 16px;
    bottom: calc(16px + env(safe-area-inset-bottom));
    width: 56px;
    height: 56px;
    touch-action: manipulation;
  }

  .cw-panel {
    top: 8px;
    right: 8px;
    bottom: calc(8px + env(safe-area-inset-bottom));
    left: 8px;
    width: auto;
    height: auto;
    max-width: none;
    max-height: none;
    border-radius: 18px;
  }

  .cw-header {
    min-height: 66px;
    padding: 10px 12px;
    gap: 9px;
  }

  .cw-avatar {
    width: 38px;
    height: 38px;
    flex-basis: 38px;
  }

  .cw-info strong { font-size: 14px; }
  .cw-info span {
    margin-top: 2px;
    font-size: 10px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .cw-close {
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
    touch-action: manipulation;
  }

  .cw-messages {
    padding: 14px 12px;
  }

  .cw-message {
    max-width: 88%;
    margin-bottom: 12px;
  }

  .cw-message p {
    padding: 10px 12px;
    font-size: 13px;
    line-height: 1.45;
  }

  .cw-quick {
    flex-wrap: nowrap;
    gap: 8px;
    margin: 2px -12px 14px;
    padding: 0 12px 2px;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .cw-quick::-webkit-scrollbar { display: none; }

  .cw-quick button {
    flex: 0 0 auto;
    min-height: 36px;
    padding: 8px 12px;
    font-size: 12px;
    touch-action: manipulation;
  }

  .cw-form {
    padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
    gap: 7px;
  }

  .cw-form input {
    height: 46px;
    padding: 0 13px;
    border-radius: 13px;
    font-size: 16px; /* Prevents iOS auto-zoom on focus */
  }

  .cw-form button {
    width: 46px;
    height: 46px;
    flex-basis: 46px;
    border-radius: 13px;
    touch-action: manipulation;
  }
}

@media (max-width: 360px) {
  .cw-panel {
    top: 4px;
    right: 4px;
    left: 4px;
    bottom: calc(4px + env(safe-area-inset-bottom));
    border-radius: 15px;
  }

  .cw-info span { max-width: 205px; }
  .cw-messages { padding: 12px 10px; }
  .cw-quick { margin-left: -10px; margin-right: -10px; padding-left: 10px; padding-right: 10px; }
}
