.cmw-widget {
  --cmw-primary: #2f6feb;
  --cmw-header-bg: #0f172a;
  --cmw-header-text: #f8fafc;
  --cmw-widget-bg: #e9eef8;
  --cmw-card-bg: #ffffff;
  --cmw-user-bubble-bg: #2f6feb;
  --cmw-user-bubble-text: #ffffff;
  --cmw-operator-bubble-bg: #f3f4f6;
  --cmw-operator-bubble-text: #111827;
  --cmw-assistant-bubble-bg: #ede9fe;
  --cmw-assistant-bubble-text: #312e81;
  --cmw-radius: 18px;
  --cmw-font-body: "Manrope", "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  --cmw-font-accent: "Unbounded", "Manrope", sans-serif;
  width: 100%;
  max-width: 440px;
  margin: 0;
  font-family: var(--cmw-font-body);
  box-sizing: border-box;
}

.cmw-widget *,
.cmw-widget *::before,
.cmw-widget *::after {
  box-sizing: border-box;
}

.cmw-widget-host,
.cmw-widget,
.cmw-widget__card {
  box-shadow: none !important;
}

.elementor-widget-cmw_chat_widget > .elementor-widget-container {
  box-shadow: none !important;
}

.cmw-widget__card {
  background: var(--cmw-widget-bg);
  border-radius: var(--cmw-radius);
  border: 1px solid rgba(15, 23, 42, 0.14);
  box-shadow: none;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  height: clamp(500px, 72vh, 680px);
}

.cmw-widget__header {
  background: var(--cmw-header-bg);
  color: var(--cmw-header-text);
  padding: 14px 16px;
  flex: 0 0 auto;
}

.cmw-widget__title {
  margin: 0;
  font-family: var(--cmw-font-accent);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.25;
}

.cmw-widget__modes {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.cmw-widget__mode-btn {
  border: 1px solid rgba(248, 250, 252, 0.35);
  background: transparent;
  color: var(--cmw-header-text);
  border-radius: 999px;
  padding: 6px 12px;
  font-family: var(--cmw-font-accent);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: -0.01em;
  cursor: pointer;
}

.cmw-widget__mode-btn.is-active {
  background: rgba(248, 250, 252, 0.16);
  border-color: rgba(248, 250, 252, 0.8);
}

.cmw-widget__visit {
  margin: 4px 0 0;
  opacity: 0.75;
  font-size: 12px;
}

.cmw-widget__panel {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}

.cmw-widget__messages {
  background: var(--cmw-card-bg);
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 14px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.cmw-widget__message {
  display: flex;
  flex-direction: column;
  max-width: 84%;
  gap: 4px;
}

.cmw-widget__message--visitor {
  align-self: flex-end;
}

.cmw-widget__message--operator {
  align-self: flex-start;
}

.cmw-widget__message--assistant {
  align-self: flex-start;
}

.cmw-widget__message--pending {
  opacity: 0.92;
}

.cmw-widget__message--typing {
  align-self: flex-start;
}

.cmw-widget__message--system {
  align-self: center;
  max-width: 92%;
}

.cmw-widget__bubble {
  border-radius: 14px;
  padding: 10px 12px;
  font-size: 14px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.cmw-widget__bubble b,
.cmw-widget__bubble strong {
  font-family: var(--cmw-font-accent);
  font-weight: 600;
  letter-spacing: -0.01em;
}

.cmw-widget__message--visitor .cmw-widget__bubble {
  background: var(--cmw-user-bubble-bg);
  color: var(--cmw-user-bubble-text);
  border-bottom-right-radius: 4px;
}

.cmw-widget__message--operator .cmw-widget__bubble {
  background: var(--cmw-operator-bubble-bg);
  color: var(--cmw-operator-bubble-text);
  border: 1px solid rgba(15, 23, 42, 0.12);
  border-bottom-left-radius: 4px;
}

.cmw-widget__message--assistant .cmw-widget__bubble {
  background: var(--cmw-assistant-bubble-bg);
  color: var(--cmw-assistant-bubble-text);
  border: 1px solid rgba(99, 102, 241, 0.22);
  border-bottom-left-radius: 4px;
}

.cmw-widget__bubble--typing {
  opacity: 0.85;
  font-style: italic;
}

.cmw-widget__message--system .cmw-widget__bubble {
  background: rgba(37, 99, 235, 0.08);
  border: 1px dashed rgba(37, 99, 235, 0.28);
  color: #1e3a8a;
}

.cmw-widget__meta {
  font-size: 11px;
  color: #64748b;
  padding: 0 4px;
}

.cmw-widget__message--visitor .cmw-widget__meta {
  text-align: right;
}

.cmw-widget__quick {
  display: flex;
  gap: 6px;
  flex-wrap: nowrap;
  overflow-x: auto;
  background: var(--cmw-card-bg);
  padding: 8px 10px;
  border-top: 1px solid rgba(15, 23, 42, 0.08);
  flex: 0 0 auto;
}

.cmw-widget__quick-btn {
  border: 1px solid rgba(47, 111, 235, 0.35);
  background: rgba(47, 111, 235, 0.08);
  color: #1e3a8a;
  border-radius: 999px;
  padding: 5px 10px;
  font-family: var(--cmw-font-accent);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: -0.01em;
  cursor: pointer;
  white-space: nowrap;
}

.cmw-widget__quick-btn:hover {
  background: rgba(47, 111, 235, 0.15);
}

.cmw-widget__quick-btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.cmw-widget__page-factory {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 10px;
  background: var(--cmw-card-bg);
  border-top: 1px solid rgba(15, 23, 42, 0.08);
  flex: 0 0 auto;
}

.cmw-widget__page-factory[hidden] {
  display: none;
}

.cmw-widget__page-factory-title,
.cmw-widget__page-factory label:first-of-type,
.cmw-widget__page-factory-submit {
  grid-column: 1 / -1;
}

.cmw-widget__page-factory-title {
  color: #0f172a;
  font-family: var(--cmw-font-accent);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.cmw-widget__page-factory label {
  display: grid;
  gap: 4px;
  min-width: 0;
  color: #475569;
  font-size: 11px;
}

.cmw-widget__page-factory input,
.cmw-widget__page-factory select {
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
  border: 1px solid rgba(15, 23, 42, 0.2);
  border-radius: 8px;
  background: #fff;
  color: #0f172a;
  padding: 7px 8px;
  font: inherit;
  font-size: 12px;
}

.cmw-widget__page-factory-submit {
  border: 0;
  border-radius: 9px;
  background: var(--cmw-primary);
  color: #fff;
  padding: 8px 10px;
  font-family: var(--cmw-font-accent);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: -0.01em;
  cursor: pointer;
}

.cmw-widget__page-factory-submit:disabled {
  opacity: 0.55;
  cursor: default;
}

.cmw-widget__input {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--cmw-card-bg);
  padding: 10px;
  border-top: 1px solid rgba(15, 23, 42, 0.08);
  flex: 0 0 auto;
}

.cmw-widget__media-btn {
  width: 36px;
  height: 36px;
  border: 1px solid rgba(15, 23, 42, 0.16);
  border-radius: 999px;
  background: #fff;
  color: #0f172a;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 36px;
  font-size: 16px;
}

.cmw-widget__media-btn:hover {
  border-color: rgba(47, 111, 235, 0.55);
  color: #1e3a8a;
}

.cmw-widget__media-btn.is-recording {
  background: #fee2e2;
  color: #991b1b;
  border-color: #fca5a5;
}

.cmw-widget__input textarea {
  flex: 1 1 auto;
  min-height: 40px;
  max-height: 96px;
  border: 1px solid rgba(15, 23, 42, 0.2);
  border-radius: 12px;
  padding: 9px 11px;
  resize: none;
  font-size: 14px;
  line-height: 1.35;
  outline: none;
  overflow-y: auto;
}

.cmw-widget__input textarea:focus {
  border-color: var(--cmw-primary);
  box-shadow: 0 0 0 2px rgba(47, 111, 235, 0.15);
}

.cmw-widget__send {
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 50%;
  background: var(--cmw-primary);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex: 0 0 42px;
}

.cmw-widget.is-sending .cmw-widget__send,
.cmw-widget.is-sending .cmw-widget__media-btn {
  opacity: 0.6;
}

.cmw-widget__send:hover {
  filter: brightness(0.94);
}

.cmw-widget__send svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.cmw-widget__attach {
  margin-top: 8px;
}

.cmw-widget__attach--photo {
  display: inline-block;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid rgba(15, 23, 42, 0.14);
}

.cmw-widget__attach--photo img {
  display: block;
  max-width: 220px;
  width: 100%;
  height: auto;
}

.cmw-widget__attach--voice {
  width: 220px;
  max-width: 100%;
}

/* Mobile: even open inside Elementor column (no overflow / clipped chrome) */
.cmw-widget-host {
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.elementor-widget-cmw_chat_widget,
.elementor-widget-cmw_chat_widget > .elementor-widget-container {
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

@media (max-width: 768px) {
  .cmw-widget {
    width: 100%;
    max-width: 100%;
    margin-inline: auto;
  }

  .cmw-widget__card {
    width: 100%;
    max-width: 100%;
    height: min(70svh, 560px);
    height: min(70dvh, 560px);
    max-height: calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 24px);
  }

  .cmw-widget__panel,
  .cmw-widget__messages {
    min-height: 0;
  }
}

@media (max-width: 640px) {
  .cmw-widget__header {
    padding: 12px 14px;
  }

  .cmw-widget__title {
    font-size: 15px;
  }

  .cmw-widget__card {
    height: min(72svh, 540px);
    height: min(72dvh, 540px);
    max-height: calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 16px);
    border-radius: max(12px, calc(var(--cmw-radius) - 4px));
  }

  .cmw-widget__messages {
    padding: 12px 10px 6px;
  }

  .cmw-widget__message {
    max-width: 90%;
  }

  .cmw-widget__bubble {
    font-size: 13px;
    padding: 9px 11px;
  }

  .cmw-widget__quick {
    gap: 8px;
    padding: 8px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .cmw-widget__quick::-webkit-scrollbar {
    display: none;
  }

  .cmw-widget__quick-btn {
    padding: 7px 12px;
    font-size: 11px;
  }

  .cmw-widget__page-factory {
    grid-template-columns: 1fr;
  }

  .cmw-widget__input {
    padding: 8px;
    gap: 6px;
    flex: 0 0 auto;
  }

  .cmw-widget__input textarea {
    font-size: 16px; /* iOS: avoid focus zoom */
    min-height: 44px;
  }

  .cmw-widget__media-btn,
  .cmw-widget__send {
    width: 44px;
    height: 44px;
    flex-basis: 44px;
  }

  .cmw-widget__attach--photo img,
  .cmw-widget__attach--voice {
    max-width: min(220px, 70vw);
  }
}

@media (max-width: 380px) {
  .cmw-widget__modes {
    flex-wrap: wrap;
  }

  .cmw-widget__title {
    font-size: 14px;
  }

  .cmw-widget__card {
    height: min(74svh, 520px);
    height: min(74dvh, 520px);
  }
}
