.chat-widget,
.chat-widget *,
.log-bubble .assistant-bubble,
.log-bubble .assistant-bubble *,
.reply-options-inline,
.reply-options-inline * {
  box-sizing: border-box;
}

.chat-widget,
.log-bubble .assistant-bubble,
.reply-options-inline {
  --panel: rgba(255, 252, 246, 0.92);
  --card: #ffffff;
  --text: #173320;
  --muted: #637166;
  --accent: #2d6a3f;
  --accent-strong: #1e4f2d;
  --accent-soft: #d8c38f;
  --border: rgba(45, 106, 63, 0.14);
  --shadow: 0 28px 60px rgba(23, 51, 32, 0.12);
  color: var(--text);
  font-family: "Segoe UI", system-ui, sans-serif;
}

.chat-widget {
  --screen-offset: 20px;
  --launcher-height: 50px;
  --launcher-gap: 6px;
  --chat-width: min(90vw, 1600px);
  --chat-height: calc(100vh - var(--screen-offset) - var(--launcher-height) - var(--launcher-gap));
  position: fixed;
  right: 10px;
  bottom: 2px;
  z-index: 1000;
}

.chat-launcher {
  display: inline-flex;
  position: relative;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 6px 12px 6px 6px;
  border: 0;
  border-radius: 999px;
  background:
    radial-gradient(circle at 18% 50%, rgba(196, 255, 188, 0.22), transparent 20%),
    linear-gradient(120deg, #11492a 0%, #1d6b3a 22%, #2e8f49 46%, #71bf52 64%, #2f944a 78%, #11492a 100%);
  background-size: 100% 100%, 220% 220%;
  color: #fff;
  box-shadow: 0 22px 48px rgba(23, 51, 32, 0.22);
  cursor: pointer;
  animation: launcher-flame 6.5s ease-in-out infinite;
}

@keyframes launcher-flame {
  0% {
    background-position: 0% 50%, 0% 50%;
    box-shadow: 0 22px 48px rgba(23, 51, 32, 0.22);
  }

  25% {
    background-position: 8% 48%, 38% 52%;
    box-shadow: 0 22px 52px rgba(32, 91, 47, 0.26);
  }

  50% {
    background-position: 14% 52%, 100% 50%;
    box-shadow: 0 24px 56px rgba(48, 111, 49, 0.28);
  }

  75% {
    background-position: 9% 49%, 68% 48%;
    box-shadow: 0 22px 52px rgba(32, 91, 47, 0.26);
  }

  100% {
    background-position: 0% 50%, 0% 50%;
    box-shadow: 0 22px 48px rgba(23, 51, 32, 0.22);
  }
}

@media (prefers-reduced-motion: reduce) {
  .chat-launcher {
    animation: none;
    background-size: 100% 100%, 160% 160%;
    background-position: 0% 50%, 42% 50%;
  }
}

.chat-close-floating {
  position: absolute;
  top: 2px;
  left: 0;
  width: 38px;
  height: 38px;
  display: none;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--accent-strong);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(23, 51, 32, 0.12);
  z-index: 3;
}

.chat-widget:not(.chat-widget--collapsed) .chat-close-floating {
  display: inline-flex;
}

.chat-widget:not(.chat-widget--collapsed) .chat-launcher {
  margin-left: 46px;
  width: calc(100% - 46px);
}

.chat-launcher__icon {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  font-size: 13px;
  font-weight: 800;
}

.chat-launcher__logo {
  width: 22px;
  height: 22px;
  object-fit: contain;
  display: block;
  position: relative;
  top: 1px;
}

.chat-launcher__copy {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.chat-launcher__title {
  font-size: 13px;
  font-weight: 800;
  line-height: 1.1;
}

.chat-launcher__subtitle {
  margin-top: 2px;
  font-size: 11px;
  opacity: 0.88;
}

.chat-card {
  display: flex;
  flex-direction: column;
  position: relative;
  width: var(--chat-width);
  height: var(--chat-height);
  margin-top: 6px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
  overflow: hidden;
}

.chat-widget--expanded .chat-card {
  width: var(--chat-width, min(560px, calc(100vw - 20px)));
  height: var(--chat-height, min(78vh, 720px));
}

.chat-widget--expanded {
  --chat-width: min(90vw, 1600px);
  --chat-height: calc(100vh - var(--screen-offset) - var(--launcher-height) - var(--launcher-gap));
}

.chat-widget--collapsed .chat-card {
  display: none;
}

.chat-widget:not(.chat-widget--collapsed) .chat-launcher {
  box-shadow: 0 12px 24px rgba(23, 51, 32, 0.12);
}

.chat-header {
  display: none;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  background:
    radial-gradient(circle at top right, rgba(216, 195, 143, 0.45), transparent 28%),
    linear-gradient(135deg, rgba(45, 106, 63, 0.12), rgba(45, 106, 63, 0));
}

.chat-header:focus-visible {
  outline: 2px solid rgba(45, 106, 63, 0.28);
  outline-offset: -2px;
}

.chat-header__actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.chat-title {
  font-size: 14px;
  font-weight: 800;
}

.chat-brand {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 2px;
}

.chat-brand__logo {
  width: 18px;
  height: 18px;
  object-fit: contain;
  display: block;
}

.chat-brand__label {
  font-size: 10px;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.chat-subtitle {
  margin-top: 2px;
  color: var(--muted);
  font-size: 10px;
}

.ghost-button,
.quick-chip,
.send-button {
  font: inherit;
}

.ghost-button {
  min-height: 28px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.85);
  color: var(--accent-strong);
  cursor: pointer;
  font-size: 12px;
}

.chat-messages {
  flex: 1;
  padding: 6px 6px 2px;
  overflow-y: auto;
  min-height: 0;
}

.message {
  display: flex;
  width: 100%;
  margin-bottom: 6px;
}

.message.user {
  justify-content: flex-start;
}

.bubble {
  width: 100%;
  max-width: none;
  padding: 6px 8px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.45;
  white-space: pre-wrap;
  text-align: left;
  overflow-wrap: anywhere;
}

.bubble-paragraph {
  margin: 0 0 4px;
}

.bubble-paragraph:last-child {
  margin-bottom: 0;
}

.bubble-list {
  margin: 0 0 4px;
  padding-left: 12px;
}

.bubble-list:last-child {
  margin-bottom: 0;
}

.bubble-list li + li {
  margin-top: 2px;
}

.bubble-table-wrap {
  margin-top: 6px;
  overflow-x: auto;
  border: 1px solid rgba(45, 106, 63, 0.14);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.92);
  max-width: 100%;
}

.bubble-table {
  width: 100%;
  min-width: 520px;
  border-collapse: collapse;
  font-size: 13px;
  line-height: 1.4;
}

.bubble-table th,
.bubble-table td {
  padding: 7px 8px;
  border-bottom: 1px solid rgba(45, 106, 63, 0.1);
  text-align: left;
  vertical-align: top;
  white-space: normal;
  overflow-wrap: anywhere;
}

.bubble-table th {
  position: sticky;
  top: 0;
  background: #eef4ed;
  color: var(--accent-strong);
  font-weight: 800;
}

.bubble-table tbody tr:last-child td {
  border-bottom: 0;
}

.bubble-table td:first-child,
.bubble-table th:first-child {
  min-width: 220px;
}

.inline-link {
  color: var(--accent-strong);
  text-decoration: underline;
  text-underline-offset: 2px;
  overflow-wrap: anywhere;
}

.bubble-table th:nth-child(n + 2),
.bubble-table td:nth-child(n + 2) {
  white-space: nowrap;
  width: 1%;
}

.bubble-table__total-row td {
  font-weight: 800;
  background: rgba(45, 106, 63, 0.05);
}

.estimate-panel {
  margin-top: 6px;
}

.estimate-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.estimate-toolbar__title {
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 800;
}

.estimate-copy-button {
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid rgba(45, 106, 63, 0.16);
  border-radius: 999px;
  background: rgba(45, 106, 63, 0.08);
  color: var(--accent-strong);
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.estimate-disclaimer {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.message.assistant .bubble {
  background: var(--card);
  border: 1px solid var(--border);
  border-top-left-radius: 6px;
  box-shadow: 0 12px 24px rgba(23, 51, 32, 0.06);
}

.assistant-options {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.assistant-option {
  padding: 7px 10px;
  border: 1px solid rgba(45, 106, 63, 0.18);
  border-radius: 999px;
  background: rgba(45, 106, 63, 0.08);
  color: var(--accent-strong);
  font: inherit;
  font-size: 12px;
  line-height: 1.25;
  text-align: left;
  cursor: pointer;
}

.assistant-option:hover {
  background: rgba(45, 106, 63, 0.14);
}

.message.user .bubble {
  color: #fff;
  background: linear-gradient(135deg, var(--accent), #3b8051);
  border-top-right-radius: 6px;
}

.product-grid {
  display: grid;
  gap: 4px;
  margin-top: 6px;
}

.chat-widget--expanded .product-grid {
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
}

.product-card {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 6px;
  align-items: center;
  padding: 4px 6px;
  border: 1px solid rgba(45, 106, 63, 0.14);
  border-radius: 8px;
  background:
    radial-gradient(circle at top right, rgba(216, 195, 143, 0.28), transparent 35%),
    #f9f8f3;
  text-align: left;
  color: inherit;
  text-decoration: none;
}

.product-card:hover {
  border-color: rgba(45, 106, 63, 0.22);
  background:
    radial-gradient(circle at top right, rgba(216, 195, 143, 0.34), transparent 35%),
    #f7f5ee;
}

.product-card__content {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.product-card__image-link {
  display: block;
  border-radius: 6px;
  overflow: hidden;
  background: #eef3ea;
  width: 44px;
  height: 44px;
}

.product-card__image-link--placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.product-card__image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.product-card__eyebrow {
  margin-bottom: 1px;
  color: var(--accent);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.product-card__title {
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.product-card__description {
  margin: 1px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.product-card__reviews {
  margin: 1px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.product-card__availability {
  margin: 1px 0 0;
  font-size: 11px;
  line-height: 1.25;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.product-card__availability--stock {
  color: #2d6a3f;
}

.product-card__availability--few {
  color: #9a6700;
}

.product-card__availability--order,
.product-card__availability--empty {
  color: #8f3b2f;
}

.product-card__price {
  margin: 1px 0 0;
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.product-card__price--loading {
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
}

.product-card__button {
  display: none !important;
}

@media (max-width: 560px) {
  .product-card {
    grid-template-columns: 44px minmax(0, 1fr);
  }
}

.quick-panel {
  padding: 0 6px 2px;
}

.quick-panel--collapsed .quick-actions {
  display: none;
}

.quick-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 28px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--accent-strong);
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.quick-toggle__icon {
  font-size: 14px;
  line-height: 1;
}

.quick-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  padding-top: 0;
  max-height: 84px;
  overflow-y: auto;
}

.quick-chip {
  min-height: 24px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.84);
  color: var(--accent-strong);
  cursor: pointer;
  font-size: 12px;
  line-height: 1.3;
  text-align: left;
}

.reply-options-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.reply-chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.84);
  color: var(--accent-strong);
  font-size: 12px;
  line-height: 1.3;
}

.chat-form {
  display: grid;
  grid-template-columns: 1fr 42px 84px;
  gap: 4px;
  padding: 0 6px 4px;
}

.chat-input {
  width: 100%;
  resize: vertical;
  min-height: 36px;
  max-height: 84px;
  padding: 6px 9px;
  border: 1px solid rgba(45, 106, 63, 0.18);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  line-height: 1.4;
}

.send-button {
  border: 0;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #fff;
  cursor: pointer;
  font-weight: 700;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.send-button__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  line-height: 1;
  transform-origin: center;
}

.send-button--loading .send-button__icon {
  animation: chat-send-spin 0.8s linear infinite;
}

.voice-button {
  border: 1px solid rgba(45, 106, 63, 0.2);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.96);
  color: var(--accent-strong);
  cursor: pointer;
  font-weight: 700;
  font-size: 11px;
}

.voice-button[hidden] {
  display: none;
}

.voice-button--listening {
  background: linear-gradient(135deg, rgba(45, 106, 63, 0.14), rgba(45, 106, 63, 0.22));
  box-shadow: inset 0 0 0 1px rgba(45, 106, 63, 0.12);
}

.voice-button:disabled {
  opacity: 0.55;
  cursor: default;
}

.send-button:disabled {
  opacity: 0.7;
  cursor: wait;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@keyframes chat-send-spin {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}

.chat-resizer {
  position: absolute;
  right: 4px;
  bottom: 4px;
  width: 16px;
  height: 16px;
  cursor: nwse-resize;
  border-right: 2px solid rgba(45, 106, 63, 0.32);
  border-bottom: 2px solid rgba(45, 106, 63, 0.32);
  border-bottom-right-radius: 8px;
}

.chat-resizer::before,
.chat-resizer::after {
  content: "";
  position: absolute;
  right: 2px;
  bottom: 2px;
  width: 8px;
  height: 1px;
  background: rgba(45, 106, 63, 0.32);
  transform: rotate(-45deg);
  transform-origin: right center;
}

.chat-resizer::after {
  right: 5px;
  bottom: 5px;
}

body.chat-resizing {
  cursor: nwse-resize;
  user-select: none;
}

@media (max-width: 800px) {
  .app-shell {
    width: min(100% - 20px, 1120px);
    padding-top: 20px;
  }

  .debug-panel {
    padding: 14px;
    border-radius: 18px;
  }

  .debug-panel__head {
    flex-direction: column;
  }

  .debug-grid,
  .debug-grid--auth,
  .debug-preview {
    grid-template-columns: 1fr;
  }

  .chat-widget {
    --screen-offset: 16px;
    --launcher-height: 50px;
    --launcher-gap: 6px;
    right: 8px;
    left: 8px;
    bottom: 2px;
  }

  .chat-launcher {
    width: 100%;
    justify-content: center;
  }

  .chat-close-floating {
    top: 4px;
    left: 0;
  }

  .chat-widget:not(.chat-widget--collapsed) .chat-launcher {
    margin-left: 44px;
    width: calc(100% - 44px);
  }

  .chat-card {
    width: 100%;
    height: calc(100vh - var(--screen-offset) - var(--launcher-height) - var(--launcher-gap));
    border-radius: 16px;
  }

  .chat-widget--expanded .chat-card {
    width: 100%;
    height: calc(100vh - var(--screen-offset) - var(--launcher-height) - var(--launcher-gap));
  }

  .chat-widget {
    --chat-width: 100%;
    --chat-height: calc(100vh - var(--screen-offset) - var(--launcher-height) - var(--launcher-gap));
  }

  .chat-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .chat-form {
    grid-template-columns: 1fr 44px 92px;
    grid-template-areas:
      "input input input"
      "voice . send";
    gap: 6px;
    padding: 0 8px 8px;
  }

  .quick-panel {
    padding-right: 8px;
    padding-left: 8px;
  }

  .quick-actions {
    grid-template-columns: 1fr;
    max-height: 116px;
    gap: 6px;
  }

  .bubble {
    max-width: 100%;
    font-size: 13px;
    line-height: 1.42;
  }

  .chat-widget--expanded .product-grid {
    grid-template-columns: 1fr;
  }

  .chat-messages {
    padding: 8px 8px 4px;
  }

  .chat-input {
    grid-area: input;
    min-height: 72px;
    max-height: 124px;
    padding: 8px 10px;
    font-size: 14px;
    line-height: 1.4;
  }

  .voice-button {
    grid-area: voice;
    min-height: 40px;
    font-size: 11px;
  }

  .send-button {
    grid-area: send;
    min-height: 40px;
    font-size: 12px;
  }

  .quick-chip,
  .reply-chip {
    min-height: 32px;
    padding: 6px 10px;
    font-size: 12px;
    line-height: 1.25;
  }

  .product-card {
    grid-template-columns: 56px minmax(0, 1fr);
    gap: 8px;
    padding: 8px;
  }

  .product-card__image-link {
    width: 56px;
    height: 56px;
  }

  .product-card__title {
    font-size: 12px;
    line-height: 1.2;
  }

  .product-card__description,
  .product-card__reviews,
  .product-card__availability,
  .product-card__price {
    font-size: 10px;
    line-height: 1.25;
  }

  .chat-resizer {
    display: none;
  }
}

@media (max-width: 560px) {
  .chat-widget {
    right: 6px;
    left: 6px;
    bottom: 4px;
  }

  .chat-launcher {
    min-height: 46px;
    padding-right: 10px;
  }

  .chat-launcher__title {
    font-size: 11px;
  }

  .chat-launcher__subtitle {
    font-size: 9px;
  }

  .chat-widget:not(.chat-widget--collapsed) .chat-launcher {
    margin-left: 40px;
    width: calc(100% - 40px);
  }

  .chat-close-floating {
    width: 34px;
    height: 34px;
    font-size: 20px;
  }

  .chat-card {
    border-radius: 14px;
  }
}
