.order-chat-button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 48px;
  padding: 12px 16px;
  margin: 16px 0;
  border: 1px solid var(--accent);
  border-radius: 12px;
  background: #fff;
  color: var(--accent);
  font: inherit;
  font-weight: 600;
}
.order-chat-dialog {
  width: min(520px, calc(100vw - 32px));
  max-width: 520px;
  max-height: calc(100dvh - 32px);
  height: min(760px, calc(100dvh - 32px));
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 18px;
  color: var(--ink);
  background: #fff;
  font-family: Arial, Helvetica, sans-serif;
  overflow: hidden;
}
.order-chat-dialog[open] {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.order-chat-dialog::backdrop {
  background: #18202b66;
}
.chat-heading {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  flex-shrink: 0;
}
.chat-heading small {
  color: var(--muted);
  font-size: 13px;
}
.chat-heading h2 {
  margin: 4px 0 0;
  font-size: 21px;
  line-height: 1.3;
}
.chat-close {
  font: inherit;
  font-size: 28px;
  line-height: 1;
  min-width: 44px;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 10px;
}
.chat-order-summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 14px;
  flex-shrink: 0;
}
.chat-order-summary span {
  color: var(--muted);
}
.chat-notice {
  font-size: 14px;
  line-height: 1.5;
  color: #234d78;
  background: #edf4ff;
  border-radius: 10px;
  padding: 12px;
  margin: 0;
  flex-shrink: 0;
}
.chat-connection {
  font-size: 13px;
  font-weight: 600;
  margin: 0;
  color: var(--muted);
}
.chat-messages {
  min-height: 80px;
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 8px 2px;
  overscroll-behavior: contain;
}
.chat-empty {
  font-size: 14px;
  color: var(--muted);
  text-align: center;
  margin: auto;
}
.chat-bubble {
  max-width: 88%;
  padding: 12px 14px;
  border-radius: 14px 14px 14px 3px;
  background: #f3f4f5;
  align-self: flex-start;
  overflow-wrap: anywhere;
  flex-shrink: 0;
}
.chat-bubble.chat-own {
  background: #fff0e4;
  align-self: flex-end;
  border-radius: 14px 14px 3px 14px;
}
.chat-bubble strong {
  font-size: 12px;
  color: var(--muted);
}
.chat-bubble p {
  margin: 6px 0;
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  white-space: pre-wrap;
}
.chat-bubble small {
  display: block;
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
}
.chat-error {
  color: #a03737;
  font-size: 14px;
  line-height: 1.5;
  margin: 0;
}
.chat-error:empty {
  display: none;
}
.chat-compose {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  flex-shrink: 0;
}
.chat-compose label {
  grid-column: 1 / -1;
  margin: 0;
  font-size: 14px;
}
.chat-compose textarea {
  width: 100%;
  min-width: 0;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  font: inherit;
  font-size: 16px;
  resize: none;
  height: 64px;
}
.chat-compose button {
  padding: 12px 16px;
  min-height: 48px;
  border-radius: 12px;
  background: var(--accent);
  color: white;
  font-size: 15px;
}
.chat-actions {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  flex-shrink: 0;
}
.chat-actions button {
  color: var(--muted);
  text-decoration: underline;
  font-size: 13px;
  padding: 4px 0;
  min-height: 36px;
}
@media (max-width: 600px) {
  body .order-chat-dialog {
    width: 100%;
    max-width: 100%;
    max-height: 100dvh;
    height: 100dvh;
    margin: 0;
    border-radius: 0;
    border: 0;
    padding: max(16px, env(safe-area-inset-top)) 16px
      max(16px, env(safe-area-inset-bottom));
  }
}
@media (max-height: 600px) {
  .chat-order-summary {
    display: none;
  }
  .chat-notice {
    padding: 6px 10px;
  }
  .order-chat-dialog[open] {
    gap: 6px;
  }
}
/* Rujukan chat: konteks pesanan, mesej lapang dan penghantaran satu sentuhan. */
body .order-chat-dialog {
  padding: 16px;
  font-family: Arial, Helvetica, sans-serif;
}
.chat-heading {
  flex-direction: row-reverse;
  justify-content: end;
  gap: 12px;
}
.chat-heading > div {
  display: flex;
  flex-direction: column-reverse;
  flex: 1;
  text-align: center;
  padding-right: 44px;
}
body .chat-heading h2 {
  font-size: 20px;
  margin: 0 0 4px;
}
.chat-close {
  border: 0;
  font-size: 25px;
  background: transparent;
}
.chat-order-summary {
  justify-content: start;
  font-size: 14px;
  padding: 12px;
  border-radius: 12px;
}
body .chat-order-summary .chat-thumbnail {
  width: 54px;
  height: 54px;
  border-radius: 7px;
  flex-shrink: 0;
}
.chat-order-summary > div {
  min-width: 0;
}
.chat-order-summary strong > span {
  color: #137038;
}
.chat-order-summary small {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
}
.chat-notice {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  font-size: 12px;
}
.chat-notice > span {
  color: #0875e1;
  font-size: 21px;
}
.chat-connection {
  font-size: 11px;
  font-weight: 400;
}
.chat-messages {
  gap: 24px;
  padding: 8px 0 20px;
}
.chat-bubble {
  background: transparent;
  padding: 0;
  max-width: 85%;
}
.chat-bubble.chat-own {
  background: transparent;
}
.chat-bubble > strong {
  font-size: 11px;
  font-weight: 400;
}
body .chat-bubble p {
  font-size: 14px;
  background: #f2f2f3;
  border-radius: 16px;
  padding: 12px 14px;
  margin: 4px 0;
}
body .chat-bubble.chat-own p {
  background: #fff0e6;
}
.chat-bubble small {
  font-size: 11px;
  padding-inline: 10px;
}
.chat-bubble.chat-own small {
  text-align: right;
}
.chat-compose {
  gap: 10px;
  align-items: end;
  padding-top: 12px;
}
.chat-compose label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}
body .chat-compose textarea {
  height: 48px;
  min-height: 48px;
  border-radius: 24px;
  padding: 12px 16px;
  font-size: 16px;
}
.chat-compose button {
  border-radius: 50%;
  width: 48px;
  height: 48px;
  min-height: 48px;
  padding: 12px;
}
.chat-actions {
  justify-content: end;
  gap: 12px;
}
.chat-actions button {
  font-size: 11px;
  min-height: 28px;
}
@media (max-width: 600px) {
  body .order-chat-dialog {
    padding: max(16px, env(safe-area-inset-top)) 14px
      max(10px, env(safe-area-inset-bottom));
  }
}

/* ==========================================================================
   Fasa 3: Antara Muka Chat Moden (Sepanduk Pesanan Terapung & Bubble Terracotta)
   ========================================================================== */
body .order-chat-dialog {
  background: #faf6f0;
  font-family:
    'Plus Jakarta Sans',
    'DM Sans',
    -apple-system,
    BlinkMacSystemFont,
    'SF Pro Text',
    'Segoe UI',
    sans-serif;
  border-radius: 24px;
}
.chat-order-summary {
  background: #ffffff;
  border: 1px solid #eae3da;
  border-radius: 16px;
  padding: 12px 14px;
  box-shadow: 0 6px 18px rgba(28, 20, 16, 0.06);
}
.chat-notice {
  background: #eef4ff;
  border: 1px solid #d5e4ff;
  border-radius: 12px;
}
body .chat-bubble p {
  background: #ffffff;
  border: 1px solid #eae3da;
  border-radius: 18px 18px 18px 4px;
  box-shadow: 0 2px 8px rgba(28, 20, 16, 0.04);
  color: #1c1410;
}
body .chat-bubble.chat-own p {
  background: linear-gradient(135deg, #d1532b 0%, #b63d18 100%);
  border-color: transparent;
  border-radius: 18px 18px 4px 18px;
  color: #ffffff;
  box-shadow: 0 6px 16px rgba(200, 75, 36, 0.22);
}
body .chat-compose textarea {
  background: #ffffff;
  border: 1px solid #dfd7cc;
  box-shadow: 0 2px 10px rgba(28, 20, 16, 0.04);
}
.chat-compose button {
  background: linear-gradient(135deg, #d1532b 0%, #b63d18 100%);
  box-shadow: 0 6px 14px rgba(200, 75, 36, 0.25);
}
.chat-quick-replies {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 2px 2px;
  flex-shrink: 0;
  scrollbar-width: none;
}
.chat-quick-replies::-webkit-scrollbar {
  display: none;
}
.chat-quick-chip {
  flex-shrink: 0;
  padding: 7px 13px;
  border-radius: 999px;
  background: #ffffff;
  border: 1px solid #dfd7cc;
  color: #1c1410;
  font-size: 12px;
  font-weight: 600;
  box-shadow: 0 2px 6px rgba(28, 20, 16, 0.04);
  transition:
    background-color 0.15s ease,
    border-color 0.15s ease,
    color 0.15s ease;
}
.chat-quick-chip:hover,
.chat-quick-chip:active {
  background: #fff0e8;
  border-color: #c84b24;
  color: #c84b24;
}

/* Notifications share one accessible inbox on the shop and admin pages. */
.chat-notifications {
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  bottom: calc(84px + env(safe-area-inset-bottom));
  z-index: 90;
  font-family: inherit;
}
.chat-notifications[hidden],
.chat-new-message[hidden] {
  display: none;
}
.chat-inbox-toggle {
  display: flex;
  gap: 8px;
  align-items: center;
  min-height: 44px;
  padding: 10px 14px;
  border-radius: 24px;
  border: 1px solid #ddd2c9;
  background: #fff;
  color: #503526;
  box-shadow: 0 4px 16px #301b1420;
  font: inherit;
  cursor: pointer;
}
.chat-inbox-count {
  display: grid;
  place-items: center;
  min-width: 24px;
  height: 24px;
  padding: 0 5px;
  border-radius: 20px;
  background: #eee9e4;
  font-size: 12px;
}
.has-unread .chat-inbox-count {
  background: #b63d18;
  color: #fff;
}
.chat-inbox-dialog {
  box-sizing: border-box;
  width: min(440px, calc(100vw - 28px));
  max-height: calc(100dvh - 48px);
  padding: 20px;
  border: 1px solid #dfd7cc;
  border-radius: 20px;
  background: #fff;
  color: #1c1410;
  overflow: auto;
  font-family: inherit;
}
.chat-inbox-dialog::backdrop {
  background: #18202b66;
}
.chat-inbox-dialog header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.chat-inbox-dialog h2 {
  margin: 0;
  font-size: 20px;
}
.chat-inbox-close,
.chat-banner-dismiss {
  min-width: 44px;
  min-height: 44px;
  border: 0;
  background: transparent;
  color: #503526;
  font-size: 26px;
  cursor: pointer;
}
.chat-push-description,
.chat-push-status {
  font-size: 14px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}
.chat-push-status {
  color: #665a51;
}
.chat-push-enable,
.chat-push-disable {
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid #b63d18;
  background: #b63d18;
  color: #fff;
  min-height: 44px;
  font: inherit;
  cursor: pointer;
}
.chat-push-disable {
  background: #fff;
  color: #8b3419;
}
.chat-inbox-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}
.chat-inbox-item {
  display: grid;
  gap: 6px;
  width: 100%;
  text-align: left;
  border: 1px solid #e8dfd6;
  border-radius: 12px;
  background: #fff9f3;
  padding: 14px;
  color: #1c1410;
  font: inherit;
  cursor: pointer;
}
.chat-inbox-item span,
.chat-inbox-item small,
.chat-inbox-empty {
  font-size: 14px;
  line-height: 1.5;
}
.chat-inbox-item small {
  color: #a53b18;
}
.chat-new-message {
  position: absolute;
  bottom: 58px;
  right: 0;
  display: flex;
  width: min(340px, calc(100vw - 32px));
  border: 1px solid #dfd7cc;
  border-radius: 16px;
  background: white;
  box-shadow: 0 5px 24px #301b1420;
}
.chat-new-message > button:first-child {
  display: grid;
  gap: 6px;
  flex: 1;
  padding: 14px;
  border: 0;
  background: transparent;
  text-align: left;
  color: #1c1410;
  font: inherit;
  cursor: pointer;
}
.chat-new-message span {
  font-size: 13px;
  color: #8b3419;
}
.chat-inbox-dialog button[hidden] {
  display: none;
}

.chat-inbox-network {
  font-size: 14px;
  line-height: 1.5;
  color: #8b3419;
  overflow-wrap: anywhere;
}
.chat-inbox-network:empty {
  display: none;
}
.chat-inbox-retry {
  padding: 10px 14px;
  min-height: 44px;
  border: 1px solid #dfd7cc;
  border-radius: 10px;
  background: #fff;
  color: #503526;
  font: inherit;
  cursor: pointer;
}

/* Only processed thumbnails are previewed and sent in the chat. */
.chat-compose {
  grid-template-columns: auto minmax(0, 1fr) auto;
}
.chat-compose .chat-image-input {
  display: none;
}
.chat-compose .chat-attach {
  background: #fff;
  color: #a53c1c;
  border: 1px solid #dfd7cc;
  box-shadow: none;
  display: grid;
  place-items: center;
}
.chat-image-preview {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 1px solid #dfd7cc;
  border-radius: 12px;
  background: #fff;
}
.chat-image-preview[hidden] {
  display: none;
}
.chat-image-preview img {
  width: 64px;
  height: 64px;
  object-fit: contain;
  border-radius: 6px;
  background: #f5f1eb;
  flex-shrink: 0;
}
.chat-image-preview > div {
  min-width: 0;
  flex: 1;
}
.chat-image-preview strong,
.chat-image-preview small {
  display: block;
  font-size: 12px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}
.chat-image-preview small {
  color: #665a51;
  font-size: 11px;
  margin-top: 4px;
}
.chat-compose .chat-image-remove {
  background: transparent;
  color: #503526;
  box-shadow: none;
  border: 0;
  font-size: 24px;
  flex-shrink: 0;
}
.chat-bubble .chat-message-image {
  display: block;
  max-width: min(240px, 100%);
  height: auto;
  max-height: 240px;
  object-fit: contain;
  margin: 6px 0;
  border: 1px solid #dfd7cc;
  border-radius: 12px;
  background: #fff;
}
.chat-bubble.chat-own .chat-message-image {
  margin-left: auto;
}
@media (max-width: 360px) {
  .chat-compose {
    gap: 6px;
  }
  .chat-compose button {
    width: 44px;
    height: 44px;
    min-height: 44px;
    padding: 10px;
  }
}

.chat-image-status {
  margin: 0;
  color: #665a51;
  font-size: 13px;
  line-height: 1.5;
}
.chat-image-status:empty {
  display: none;
}

/* Keep the image action visible on buyer and seller screens, including phones. */
.chat-compose .chat-attach {
  width: 60px;
  height: 48px;
  min-height: 48px;
  padding: 5px 6px;
  border-radius: 12px;
  gap: 2px;
}
.chat-attach span {
  font-size: 10px;
  line-height: 1;
  font-weight: 600;
}

body .chat-image-open {
  display: block;
  max-width: 100%;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: #665a51;
  text-align: left;
  cursor: zoom-in;
  box-shadow: none;
}
.chat-own .chat-image-open {
  margin-left: auto;
}
.chat-image-open span {
  display: block;
  padding: 0 6px 6px;
  font-size: 11px;
}
body .chat-image-viewer {
  box-sizing: border-box;
  width: min(960px, 100vw);
  max-width: 100vw;
  height: min(900px, 100dvh);
  max-height: 100dvh;
  margin: auto;
  padding: 16px;
  border: 0;
  border-radius: 16px;
  background: #faf6f0;
  color: #241c17;
  font:
    14px/1.5 Arial,
    sans-serif;
  overflow: hidden;
}
.chat-image-viewer[open] {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.chat-image-viewer::backdrop {
  background: #17120feb;
}
.chat-image-viewer header,
.chat-image-viewer footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-shrink: 0;
}
body .chat-image-viewer button {
  min-width: 44px;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid #dfd7cc;
  border-radius: 10px;
  background: #fff;
  color: #a53c1c;
  font: inherit;
  cursor: pointer;
}
.chat-image-viewer button:disabled {
  opacity: 0.4;
  cursor: default;
}
.chat-image-viewer button:focus-visible,
.chat-image-open:focus-visible {
  outline: 3px solid #a53c1c;
  outline-offset: 2px;
}
.chat-image-viewport {
  flex: 1;
  min-height: 0;
  overflow: auto;
  background: #e9e2d8;
  border-radius: 10px;
  overscroll-behavior: contain;
}
.chat-image-canvas {
  display: grid;
  place-items: center;
}
body .chat-image-viewer img {
  display: block;
  max-width: none;
  max-height: none;
  object-fit: contain;
}
.chat-image-viewer p {
  margin: 0;
  font-size: 12px;
  flex-shrink: 0;
}
@media (max-width: 600px) {
  body .chat-image-viewer {
    width: 100vw;
    height: 100dvh;
    border-radius: 0;
    padding: max(12px, env(safe-area-inset-top)) 12px
      max(12px, env(safe-area-inset-bottom));
  }
}

/* The customer inbox lives in the bottom navigation; admin keeps its launcher. */
.chat-notifications.has-nav-inbox > .chat-inbox-toggle {
  display: none;
}
