/* Realtime chat — modern, RTL-aware (logical properties) */
.aw-chat-panel,
.aw-chat-messages {
  --aw-chat-accent: var(--primary, var(--accent, #0b5ed7));
  --aw-chat-surface: #fff;
  --aw-chat-muted: var(--text-secondary, #64748b);
  --aw-chat-border: color-mix(in srgb, var(--border-color, #e2e8f0) 90%, transparent);
}

.aw-chat-panel {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-height: 28rem;
  max-height: min(70vh, 42rem);
}

.aw-chat-messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 1.1rem 1.15rem;
  border: 1px solid var(--aw-chat-border);
  border-radius: 1rem;
  background:
    radial-gradient(120% 80% at 100% 0%, rgba(11, 94, 215, 0.06), transparent 55%),
    linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  scroll-behavior: smooth;
}

.aw-chat-load-older {
  align-self: center;
  margin-block: 0.15rem;
  border-radius: 999px;
  font-size: 0.8rem;
}

.aw-chat-row {
  display: flex;
  width: 100%;
}

.aw-chat-row--mine {
  justify-content: flex-end;
}

.aw-chat-row--theirs {
  justify-content: flex-start;
}

/* Maintenance role layout: physical sides (not flipped by RTL dir). */
.aw-chat-row--customer {
  justify-content: right;
}

.aw-chat-row--technician {
  justify-content: left;
}

.aw-chat-row--neutral {
  justify-content: center;
}

.aw-chat-bubble {
  max-width: min(78%, 36rem);
  padding: 0.75rem 0.95rem;
  border-radius: 1rem;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05), 0 8px 20px rgba(15, 23, 42, 0.04);
  word-break: break-word;
  overflow-wrap: anywhere;
  animation: aw-chat-in 0.18s ease-out;
}

@keyframes aw-chat-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.aw-chat-bubble--mine,
.aw-chat-bubble--customer {
  background: linear-gradient(
    160deg,
    var(--aw-chat-accent, #0b5ed7),
    color-mix(in srgb, var(--aw-chat-accent, #0b5ed7) 82%, #0a3d91)
  );
  color: #fff;
  border-bottom-right-radius: 0.28rem;
}

.aw-chat-bubble--mine .aw-chat-text,
.aw-chat-bubble--mine .aw-chat-meta,
.aw-chat-bubble--mine .aw-chat-sender,
.aw-chat-bubble--customer .aw-chat-text,
.aw-chat-bubble--customer .aw-chat-meta,
.aw-chat-bubble--customer .aw-chat-sender {
  color: inherit;
}

.aw-chat-bubble--theirs,
.aw-chat-bubble--technician {
  background: var(--aw-chat-surface, #fff);
  color: var(--text-primary, #0f172a);
  border: 1px solid var(--aw-chat-border, #e2e8f0);
  border-bottom-left-radius: 0.28rem;
}

.aw-chat-bubble--neutral {
  max-width: min(88%, 28rem);
  background: color-mix(in srgb, var(--aw-chat-border, #e2e8f0) 55%, #fff);
  color: var(--aw-chat-muted, #64748b);
  border: 1px solid var(--aw-chat-border, #e2e8f0);
  text-align: center;
  box-shadow: none;
  font-size: 0.88rem;
}

.aw-chat-text {
  white-space: pre-wrap;
  line-height: 1.5;
  font-size: 0.95rem;
}

.aw-chat-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-block-start: 0.5rem;
}

.aw-chat-attachment {
  max-width: 100%;
}

.aw-chat-attachment-thumb {
  display: block;
  max-width: min(100%, 15rem);
  max-height: 12rem;
  border-radius: 0.65rem;
  object-fit: cover;
  cursor: zoom-in;
  background: rgba(15, 23, 42, 0.06);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.aw-chat-attachment-thumb:hover {
  transform: scale(1.01);
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.12);
}

.aw-chat-file-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.75rem;
  border-radius: 0.65rem;
  font-size: 0.82rem;
  text-decoration: none;
  border: 1px solid rgba(15, 23, 42, 0.08);
  background: rgba(255, 255, 255, 0.92);
  color: inherit;
  max-width: 100%;
}

.aw-chat-file-chip:hover {
  filter: brightness(0.98);
}

.aw-chat-bubble--mine .aw-chat-file-chip,
.aw-chat-bubble--customer .aw-chat-file-chip {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.28);
  color: #fff;
}

.aw-chat-meta {
  margin-block-start: 0.4rem;
  font-size: 0.7rem;
  letter-spacing: 0.01em;
  opacity: 0.78;
}

.aw-chat-row--customer .aw-chat-meta {
  text-align: right;
}

.aw-chat-row--technician .aw-chat-meta {
  text-align: left;
}

.aw-chat-status-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  min-height: 1.25rem;
  font-size: 0.85rem;
  color: var(--aw-chat-muted);
}

.aw-chat-composer {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 0.85rem;
  border: 1px solid var(--aw-chat-border);
  border-radius: 1rem;
  background: var(--aw-chat-surface);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.aw-chat-composer textarea,
.aw-chat-composer .form-control {
  border-radius: 0.75rem;
  resize: vertical;
  min-height: 2.75rem;
}

.aw-chat-composer-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.aw-chat-attach-input {
  max-width: 16rem;
  font-size: 0.85rem;
}

/* TEMP: hide attach UI while ChatSettings:AttachmentsEnabled=false (Storage plan). Do not delete Storage JS. */
html:not(.aw-chat-attachments-enabled) .aw-chat-attach-input,
html:not(.aw-chat-attachments-enabled) .aw-sc-attach-label,
html:not(.aw-chat-attachments-enabled) .aw-chat-pending-files {
  display: none !important;
}

.aw-chat-pending-files {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  font-size: 0.8rem;
  color: var(--aw-chat-muted);
}

.aw-chat-pending-chip {
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
}

.aw-chat-readonly {
  padding: 0.65rem 0.85rem;
  border-radius: 0.75rem;
  background: #fff7ed;
  border: 1px solid #fed7aa;
  color: #9a3412;
  font-size: 0.9rem;
}

.aw-chat-lightbox {
  position: fixed;
  inset: 0;
  z-index: 1080;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.84);
  padding: 1.5rem;
  backdrop-filter: blur(2px);
}

.aw-chat-lightbox[hidden] {
  display: none !important;
}

.aw-chat-lightbox img {
  max-width: min(96vw, 56rem);
  max-height: 88vh;
  border-radius: 0.5rem;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.4);
}

.aw-chat-lightbox-close {
  position: absolute;
  top: 1rem;
  inset-inline-end: 1rem;
  border: 0;
  background: transparent;
  color: #fff;
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
}

@media (max-width: 640px) {
  .aw-chat-panel {
    min-height: 22rem;
    max-height: 65vh;
  }

  .aw-chat-bubble {
    max-width: 88%;
  }
}
