.chat-widget {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 900;
  font-family: var(--font-body, "Outfit", system-ui, sans-serif);
}

body:has(.order-bar:not(.hidden)) .chat-widget {
  bottom: calc(4.75rem + env(safe-area-inset-bottom, 0px));
}

.chat-widget-toggle {
  position: relative;
  width: 3.25rem;
  height: 3.25rem;
  border: none;
  border-radius: 50%;
  background: var(--espresso, #1a1209);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(26, 18, 9, 0.22);
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-widget-toggle svg {
  width: 1.35rem;
  height: 1.35rem;
}

.chat-widget-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 1.1rem;
  height: 1.1rem;
  padding: 0 0.25rem;
  border-radius: 999px;
  background: #c0392b;
  color: #fff;
  font-size: 0.65rem;
  font-weight: 600;
  line-height: 1.1rem;
  text-align: center;
}

.chat-widget-badge.hidden {
  display: none;
}

.chat-widget-panel {
  position: absolute;
  right: 0;
  bottom: calc(100% + 0.75rem);
  width: min(360px, calc(100vw - 2rem));
  height: min(480px, calc(100vh - 6rem));
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 16px 48px rgba(26, 18, 9, 0.18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid rgba(26, 18, 9, 0.08);
}

.chat-widget-panel.hidden {
  display: none;
}

.chat-panel {
  display: flex;
  flex-direction: column;
  min-height: 320px;
  background: #fff;
  border: 1px solid var(--border, rgba(26, 18, 9, 0.12));
  border-radius: var(--radius, 12px);
  overflow: hidden;
}

.chat-panel--floating {
  flex: 1;
  min-height: 0;
  border: none;
  border-radius: 0;
}

.chat-panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid rgba(26, 18, 9, 0.08);
  background: var(--cream, #f7f2ea);
}

.chat-panel-header-text {
  min-width: 0;
  flex: 1;
}

.chat-panel-header h2,
.chat-panel-header h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.chat-panel-header p {
  margin: 0.2rem 0 0;
  font-size: 0.8rem;
  color: var(--mocha, #6b5d4f);
}

.chat-panel-minimize {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 1px solid rgba(26, 18, 9, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.65);
  color: var(--espresso, #1a1209);
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.chat-panel-minimize:hover {
  background: #fff;
  border-color: rgba(26, 18, 9, 0.2);
}

.chat-panel-minimize svg {
  width: 1rem;
  height: 1rem;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  background: #faf8f5;
}

.chat-messages--empty {
  justify-content: center;
  align-items: center;
  color: var(--mocha, #6b5d4f);
  font-size: 0.9rem;
  text-align: center;
}

.chat-bubble {
  max-width: 85%;
  padding: 0.55rem 0.75rem;
  border-radius: 12px;
  font-size: 0.9rem;
  line-height: 1.45;
  word-break: break-word;
}

.chat-bubble--customer {
  align-self: flex-end;
  background: var(--espresso, #1a1209);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chat-bubble--owner {
  align-self: flex-start;
  background: #fff;
  color: var(--espresso, #1a1209);
  border: 1px solid rgba(26, 18, 9, 0.1);
  border-bottom-left-radius: 4px;
}

.chat-bubble-time {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.68rem;
  opacity: 0.65;
}

.chat-bubble-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 0.55rem;
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
  background: var(--caramel, #c9a66b);
  color: var(--espresso, #1a1209);
  font-size: 0.78rem;
  font-weight: 600;
  text-decoration: none;
}

.chat-bubble-action:hover {
  opacity: 0.92;
}

.chat-bubble--owner .chat-bubble-action {
  background: #fff;
  color: var(--espresso, #1a1209);
  border: 1px solid rgba(26, 18, 9, 0.12);
}

.chat-bubble-text {
  margin: 0;
  white-space: pre-wrap;
}

.chat-bubble-image-link {
  display: block;
  margin-top: 0.35rem;
}

.chat-bubble-image {
  display: block;
  max-width: 100%;
  max-height: 180px;
  border-radius: 10px;
  object-fit: cover;
}

.chat-bubble--customer .chat-bubble-image {
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.chat-order-tags {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  margin-top: 0.45rem;
}

.chat-order-tag,
.owner-chat-order-tag {
  display: block;
  padding: 0.45rem 0.6rem;
  border-radius: 10px;
  text-decoration: none;
  color: inherit;
}

.chat-order-tag-head,
.owner-chat-order-tag-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.chat-order-tag-number,
.owner-chat-order-tag-number {
  font-size: 0.78rem;
  font-weight: 700;
}

.chat-order-tag-status,
.owner-chat-order-tag-status {
  font-size: 0.66rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0.12rem 0.4rem;
  border-radius: 999px;
}

.chat-order-tag-items,
.owner-chat-order-tag-items {
  margin: 0.28rem 0 0;
  font-size: 0.74rem;
  line-height: 1.35;
  opacity: 0.92;
}

.chat-order-tag-meta,
.owner-chat-order-tag-meta {
  margin: 0.18rem 0 0;
  font-size: 0.68rem;
  opacity: 0.78;
}

.chat-bubble--customer .chat-order-tag {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.chat-bubble--owner .chat-order-tag {
  background: rgba(201, 166, 107, 0.12);
  border: 1px solid rgba(201, 166, 107, 0.22);
  color: var(--espresso, #1a1209);
}

.owner-chat-bubble--owner .owner-chat-order-tag {
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.16);
}

.owner-chat-bubble--customer .owner-chat-order-tag {
  background: rgba(201, 166, 107, 0.14);
  border: 1px solid rgba(201, 166, 107, 0.22);
  color: var(--text, #2d2116);
}

.chat-mention-status--in_queue,
.chat-order-tag-status--in_queue,
.owner-chat-order-tag-status--in_queue {
  background: rgba(59, 130, 246, 0.16);
  color: #1d4ed8;
}

.chat-mention-status--preparing,
.chat-order-tag-status--preparing,
.owner-chat-order-tag-status--preparing {
  background: rgba(245, 158, 11, 0.18);
  color: #b45309;
}

.chat-mention-status--for_serve,
.chat-order-tag-status--for_serve,
.owner-chat-order-tag-status--for_serve {
  background: rgba(34, 197, 94, 0.16);
  color: #15803d;
}

.chat-mention-status--awaiting_payment,
.chat-order-tag-status--awaiting_payment,
.owner-chat-order-tag-status--awaiting_payment {
  background: rgba(168, 85, 247, 0.14);
  color: #7e22ce;
}

.chat-mention-status--completed,
.chat-order-tag-status--completed,
.owner-chat-order-tag-status--completed {
  background: rgba(26, 107, 60, 0.14);
  color: #166534;
}

.chat-mention-status--cancelled,
.chat-order-tag-status--cancelled,
.owner-chat-order-tag-status--cancelled {
  background: rgba(127, 29, 29, 0.12);
  color: #991b1b;
}

.owner-chat-bubble-text {
  margin: 0;
  white-space: pre-wrap;
}

.owner-chat-bubble-image-link {
  display: block;
  margin-top: 0.35rem;
}

.owner-chat-bubble-image {
  display: block;
  max-width: 100%;
  max-height: 220px;
  border-radius: 10px;
  object-fit: cover;
}

.owner-chat-order-tags {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  margin-top: 0.45rem;
}

.owner-chat-order-tag {
  display: block;
  padding: 0.45rem 0.6rem;
  border-radius: 10px;
  text-decoration: none;
  color: inherit;
}

.chat-compose-wrap {
  border-top: 1px solid rgba(26, 18, 9, 0.08);
  background: #fff;
}

.chat-compose-preview {
  position: relative;
  margin: 0.65rem 0.75rem 0;
  width: fit-content;
}

.chat-compose-preview.hidden {
  display: none;
}

.chat-compose-preview img {
  display: block;
  max-width: 120px;
  max-height: 90px;
  border-radius: 10px;
  object-fit: cover;
  border: 1px solid rgba(26, 18, 9, 0.12);
}

.chat-compose-preview-remove {
  position: absolute;
  top: -0.35rem;
  right: -0.35rem;
  width: 1.35rem;
  height: 1.35rem;
  border: none;
  border-radius: 50%;
  background: #1a1209;
  color: #fff;
  font-size: 0.95rem;
  line-height: 1;
  cursor: pointer;
}

.chat-compose-toolbar {
  display: flex;
  gap: 0.35rem;
  padding: 0.55rem 0.75rem 0;
}

.chat-compose-tool {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border: 1px solid rgba(26, 18, 9, 0.12);
  border-radius: 8px;
  background: #faf8f5;
  color: var(--espresso, #1a1209);
  cursor: pointer;
}

.chat-compose-tool svg {
  width: 1.05rem;
  height: 1.05rem;
}

.chat-compose-tool:hover:not(:disabled) {
  background: #fff;
  border-color: rgba(26, 18, 9, 0.2);
}

.chat-compose-tool:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.chat-mention-menu {
  list-style: none;
  margin: 0 0.75rem;
  padding: 0.35rem;
  max-height: 240px;
  overflow-y: auto;
  border: 1px solid rgba(26, 18, 9, 0.12);
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 8px 24px rgba(26, 18, 9, 0.12);
}

.chat-mention-menu.hidden {
  display: none;
}

.chat-mention-item {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.18rem;
  width: 100%;
  padding: 0.55rem 0.65rem;
  border: none;
  border-radius: 10px;
  background: transparent;
  text-align: left;
  font: inherit;
  cursor: pointer;
}

.chat-mention-item.is-active,
.chat-mention-item:hover {
  background: rgba(201, 166, 107, 0.16);
}

.chat-mention-item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
}

.chat-mention-number {
  font-weight: 700;
  font-size: 0.86rem;
}

.chat-mention-status {
  font-size: 0.66rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0.12rem 0.4rem;
  border-radius: 999px;
}

.chat-mention-items {
  font-size: 0.76rem;
  line-height: 1.35;
  color: var(--espresso, #1a1209);
}

.chat-mention-meta {
  font-size: 0.7rem;
  color: var(--mocha, #6b5d4f);
}

.chat-compose {
  display: flex;
  gap: 0.5rem;
  padding: 0.55rem 0.75rem 0.75rem;
  background: #fff;
}

.chat-compose input {
  flex: 1;
  padding: 0.55rem 0.75rem;
  border: 1px solid rgba(26, 18, 9, 0.15);
  border-radius: 999px;
  font: inherit;
  font-size: 0.9rem;
}

.chat-compose input:focus {
  outline: 2px solid var(--caramel, #c9a66b);
  outline-offset: 1px;
}

.chat-compose button {
  padding: 0.55rem 1rem;
  border: none;
  border-radius: 999px;
  background: var(--espresso, #1a1209);
  color: #fff;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}

.chat-compose button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.chat-error {
  margin: 0;
  padding: 0.5rem 0.75rem;
  font-size: 0.8rem;
  color: #a93226;
  background: #fdecea;
}

@media (max-width: 480px) {
  .chat-widget {
    right: 1rem;
    bottom: 1rem;
  }

  .chat-widget-panel {
    width: calc(100vw - 2rem);
    height: min(78vh, 480px);
  }
}
