/* Website chat — dashboard messenger layout with JRE brand colors */
.chat-screen {
  --jre-chat-accent: var(--primary-color, #297c39);
  --jre-chat-accent-dark: #1e6b30;
  --jre-chat-accent-light: #ecfdf3;
  --jre-chat-thread-bg: #efeae2;
  --jre-chat-composer-bg: #f0f2f5;
  --jre-chat-page-bg: #eef6f0;
  --jre-chat-pattern: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23d4cdc4' fill-opacity='0.35'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
  background: var(--jre-chat-page-bg) !important;
}

.chat-screen .chat-screen-header {
  background: transparent;
  border-bottom: none;
  z-index: 2;
  padding: 14px 20px 8px;
}

.chat-screen .chat-screen-header h2 {
  font-size: 1.125rem;
  font-weight: 600;
  color: #0f172a;
}

.chat-screen .chat-screen-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 0 16px 16px;
  box-sizing: border-box;
}

.chat-screen .chat-layout.modern-chat-app {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 4px 24px rgba(15, 23, 42, 0.08);
  border: 1px solid #e2e8f0;
  align-items: stretch;
}

.chat-screen .modern-chat-sidebar {
  width: 360px;
  min-width: 300px;
  max-width: 100%;
  border-inline-end: 1px solid #e2e8f0;
  display: flex;
  flex-direction: column;
  background: #fff;
  flex-shrink: 0;
  z-index: 2;
  border-radius: 0;
}

.chat-screen .modern-chat-sidebar__header {
  padding: 20px 20px 12px;
  border-bottom: 1px solid #f1f5f9;
}

.chat-screen .modern-chat-sidebar__header h4 {
  margin: 0 0 4px;
  font-size: 1.25rem;
  font-weight: 700;
  color: #0f172a;
}

.chat-screen .modern-chat-sidebar__header p {
  margin: 0;
  font-size: 0.8125rem;
  color: #64748b;
}

.chat-screen .modern-chat-search {
  position: relative;
  padding: 12px 16px;
  border-bottom: 1px solid #f1f5f9;
}

.chat-screen .modern-chat-search i {
  position: absolute;
  left: 28px;
  top: 50%;
  transform: translateY(-50%);
  color: #94a3b8;
  font-size: 14px;
  pointer-events: none;
}

[dir="rtl"] .chat-screen .modern-chat-search i {
  left: auto;
  right: 28px;
}

.chat-screen .modern-chat-search input {
  width: 100%;
  border: none;
  background: #f1f5f9;
  border-radius: 999px;
  padding: 10px 16px 10px 40px;
  font-size: 0.875rem;
  color: #0f172a;
  outline: none;
  transition: background 0.15s ease, box-shadow 0.15s ease;
  box-sizing: border-box;
}

[dir="rtl"] .chat-screen .modern-chat-search input {
  padding: 10px 40px 10px 16px;
}

.chat-screen .modern-chat-search input:focus {
  background: #fff;
  box-shadow: 0 0 0 2px rgba(41, 124, 57, 0.25);
}

.chat-screen .modern-chat-list {
  flex: 1;
  overflow-y: auto;
  list-style: none;
  margin: 0;
  padding: 0;
}

.chat-screen .modern-chat-list__loading,
.chat-screen .modern-chat-list__empty {
  padding: 32px 20px;
  text-align: center;
  color: #64748b;
  font-size: 0.875rem;
}

.chat-screen .modern-chat-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  cursor: pointer;
  border-bottom: 1px solid #f8fafc;
  transition: background 0.15s ease;
  color: inherit;
}

.chat-screen .modern-chat-item:hover {
  background: #f8fafc;
}

.chat-screen .modern-chat-item.active {
  background: #fffbeb;
}

.chat-screen .modern-chat-item__avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--jre-chat-accent) 0%, #3cb453 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1rem;
  flex-shrink: 0;
  overflow: hidden;
  letter-spacing: 0.02em;
}

.chat-screen .modern-chat-item__body {
  flex: 1;
  min-width: 0;
}

.chat-screen .modern-chat-item__top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 2px;
}

.chat-screen .modern-chat-item__name {
  font-weight: 600;
  font-size: 0.9375rem;
  color: #0f172a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-screen .modern-chat-item__time {
  font-size: 0.75rem;
  color: #94a3b8;
  flex-shrink: 0;
}

.chat-screen .modern-chat-item__property {
  font-size: 0.75rem;
  color: var(--jre-chat-accent);
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-screen .modern-chat-item__client {
  font-size: 0.75rem;
  color: var(--jre-chat-accent);
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-screen .modern-chat-item__preview {
  font-size: 0.8125rem;
  color: #64748b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
}

.chat-screen .modern-chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--jre-chat-thread-bg);
  background-image: var(--jre-chat-pattern);
  position: relative;
  border-radius: 0;
  overflow: hidden;
  padding: 0;
  margin: 0;
  width: auto;
  height: auto;
  transform: none;
}

.chat-screen .modern-chat-frame-wrap {
  flex: 1 1 auto;
  display: none;
  flex-direction: column;
  min-height: 0;
  width: 100%;
  align-self: stretch;
}

.chat-screen .modern-chat-frame-wrap.active {
  display: flex;
}

.chat-screen .modern-chat-page.embedded {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  height: 100%;
  min-height: 0;
  width: 100%;
  align-self: stretch;
  background: var(--jre-chat-thread-bg);
  background-image: var(--jre-chat-pattern);
  overflow: hidden;
}

.chat-screen .modern-chat-page__header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 20px;
  background: var(--jre-chat-accent);
  color: #fff;
  flex: 0 0 auto;
  z-index: 30;
  border: none;
  border-bottom: none;
  width: 100%;
  box-sizing: border-box;
  margin: 0;
  border-radius: 0;
}

.chat-screen .modern-chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #64748b;
  padding: 40px;
  text-align: center;
  background: var(--jre-chat-thread-bg);
  background-image: var(--jre-chat-pattern);
}

.chat-screen .modern-chat-empty i {
  font-size: 5rem;
  color: #cbd5e1;
  margin-bottom: 20px;
  line-height: 1;
}

.chat-screen .modern-chat-empty h5 {
  color: #334155;
  margin: 0 0 8px;
  font-size: 1.125rem;
  font-weight: 600;
}

.chat-screen .modern-chat-empty p {
  margin: 0;
  font-size: 0.875rem;
  max-width: 320px;
  line-height: 1.5;
  color: #64748b;
}

.chat-screen .modern-chat-page__back {
  color: #fff;
  font-size: 1.25rem;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 8px;
  opacity: 0.9;
  line-height: 1;
}

.chat-screen .modern-chat-page__back:hover {
  opacity: 1;
}

.chat-screen .modern-chat-page__header-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1rem;
  flex-shrink: 0;
  overflow: hidden;
}

.chat-screen .modern-chat-page__header-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.chat-screen .modern-chat-page__header-info {
  flex: 1;
  min-width: 0;
}

.chat-screen .modern-chat-page__header-info h5 {
  margin: 0 0 2px;
  font-size: 1rem;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-screen .modern-chat-page__header-info span {
  font-size: 0.75rem;
  opacity: 0.85;
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-screen .modern-chat-thread {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 16px 20px;
  background: var(--jre-chat-thread-bg);
  background-image: var(--jre-chat-pattern);
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  box-sizing: border-box;
  margin: 0;
  align-self: stretch;
}

.chat-screen .modern-chat-row {
  display: flex;
  max-width: 75%;
  margin-bottom: 2px;
}

.chat-screen .modern-chat-row--sent {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.chat-screen .modern-chat-row--received {
  align-self: flex-start;
}

.chat-screen .modern-chat-bubble {
  padding: 8px 12px 6px;
  border-radius: 12px;
  position: relative;
  word-wrap: break-word;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.06);
  align-self: auto;
}

.chat-screen .modern-chat-row--received .modern-chat-bubble {
  background: #fff;
  border-radius: 0 12px 12px 12px;
  color: #111b21;
}

.chat-screen .modern-chat-row--sent .modern-chat-bubble {
  background: #d9fdd3;
  border-radius: 12px 0 12px 12px;
  color: #111b21;
}

[dir="rtl"] .chat-screen .modern-chat-row--received .modern-chat-bubble {
  border-radius: 12px 0 12px 12px;
}

[dir="rtl"] .chat-screen .modern-chat-row--sent .modern-chat-bubble {
  border-radius: 0 12px 12px 12px;
}

.chat-screen .modern-chat-bubble__content {
  font-size: 0.9375rem;
  line-height: 1.45;
  white-space: pre-wrap;
}

.chat-screen .modern-chat-bubble__image {
  line-height: 0;
  margin-top: 2px;
}

.chat-screen .modern-chat-bubble__image img,
.chat-screen .modern-chat-bubble .message-bubble-media--image {
  width: 240px;
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  display: block;
  object-fit: cover;
}

.chat-screen .modern-chat-bubble__meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 4px;
}

.chat-screen .modern-chat-bubble__time,
.chat-screen .modern-chat-bubble .message-timestamp {
  font-size: 0.6875rem;
  color: #667781;
  line-height: 1;
}

.chat-screen .modern-chat-bubble .message-bubble-media--pdf {
  font-weight: 600;
  color: #0369a1;
  text-decoration: none;
}

.chat-screen .modern-chat-bubble .message-bubble-media--pdf:hover {
  text-decoration: underline;
}

.chat-screen .modern-chat-bubble .message-bubble-media--audio {
  width: 100%;
  min-width: 280px;
  max-width: 100%;
  height: 52px;
  display: block;
}

.chat-screen .modern-chat-bubble__audio-wrap {
  min-width: min(320px, 90vw);
  width: 100%;
  padding: 4px 2px;
}

.chat-screen .modern-chat-row:has(.message-bubble-media--audio) {
  max-width: 92%;
}

.chat-screen .modern-chat-composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 16px;
  background: var(--jre-chat-composer-bg);
  flex: 0 0 auto;
  flex-shrink: 0;
  border-top: 1px solid #e2e8f0;
  width: 100%;
  box-sizing: border-box;
  margin: 0;
  align-self: stretch;
  position: static;
  min-height: auto;
}

.chat-screen .modern-chat-composer__tools {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
  position: relative;
}

.chat-screen .modern-chat-composer__btn {
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  border-radius: 50%;
  color: #54656f;
  font-size: 1.15rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, color 0.15s ease;
  flex-shrink: 0;
}

.chat-screen .modern-chat-composer__btn:hover {
  background: rgba(0, 0, 0, 0.05);
  color: var(--jre-chat-accent);
}

.chat-screen .modern-chat-composer__input-wrap {
  flex: 1;
  background: #fff;
  border-radius: 24px;
  padding: 4px 16px;
  display: flex;
  align-items: center;
  min-width: 0;
}

.chat-screen .modern-chat-composer__input-wrap #message-input {
  flex: 1;
  border: none !important;
  outline: none;
  padding: 8px 0 !important;
  font-size: 0.9375rem;
  line-height: 1.4;
  background: transparent !important;
  min-width: 0;
  border-radius: 0 !important;
  box-shadow: none !important;
}

.chat-screen .modern-chat-composer__send {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: var(--jre-chat-accent);
  color: #fff;
  font-size: 1.1rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s ease, transform 0.1s ease;
}

.chat-screen .modern-chat-composer__send:hover {
  background: var(--jre-chat-accent-dark);
}

.chat-screen .modern-chat-composer__send:active {
  transform: scale(0.96);
}

.chat-screen .modern-chat-composer__btn.chat-input-action-btn:not(.modern-chat-composer__send) {
  background: transparent !important;
  color: #54656f !important;
  width: 40px !important;
  height: 40px !important;
  min-width: 40px !important;
  min-height: 40px !important;
}

.chat-screen .modern-chat-composer__send.chat-input-action-btn {
  background: var(--jre-chat-accent) !important;
  color: #fff !important;
  width: 44px !important;
  height: 44px !important;
  min-width: 44px !important;
  min-height: 44px !important;
}

.chat-screen .modern-chat-composer .message-attachment-input,
.chat-screen #message-input-form .message-attachment-input {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
  opacity: 0 !important;
}

.chat-screen .modern-chat-thread .chat-placeholder {
  margin: auto;
  text-align: center;
  color: #64748b;
  padding: 24px;
  white-space: pre-line;
  font-size: 0.9375rem;
}

.chat-screen .modern-chat-thread .chat-placeholder span {
  display: block;
  margin-top: 8px;
  font-size: 0.8125rem;
  color: #94a3b8;
}

.chat-screen .no-chats-container {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem;
  color: #64748b;
  background: var(--jre-chat-thread-bg);
  background-image: var(--jre-chat-pattern);
}

.chat-screen .no-chats-icon {
  font-size: 4rem;
  margin-bottom: 1rem;
  color: #cbd5e1;
}

.chat-screen .no-chats-text h3 {
  font-size: 1.25rem;
  margin-bottom: 0.5rem;
  color: #334155;
}

.chat-screen .error-container {
  padding: 24px;
  text-align: center;
  color: #64748b;
}

/* Override legacy styles.css chat rules inside the modal (visual only — layout per breakpoint below) */
.chat-screen .chat-main.modern-chat-main {
  background: var(--jre-chat-thread-bg);
  background-image: var(--jre-chat-pattern);
}

.chat-screen #message-area.modern-chat-thread {
  flex-grow: 1;
  padding: 16px 20px !important;
  gap: 4px !important;
}

.chat-screen .modern-chat-bubble {
  max-width: none;
  display: block;
  min-width: 0;
  padding-bottom: 6px;
}

.chat-screen .modern-chat-bubble .message-timestamp {
  position: static;
  bottom: auto;
  right: auto;
  left: auto;
  color: #667781 !important;
}

.chat-screen .message-bubble.sent {
  background: #d9fdd3;
  color: #111b21;
  align-self: auto;
  border-radius: 12px 0 12px 12px;
  margin-left: 0;
  margin-right: 0;
}

.chat-screen .message-bubble.received {
  background: #fff;
  color: #111b21;
  align-self: auto;
  border-radius: 0 12px 12px 12px;
  margin-left: 0;
  margin-right: 0;
}

.chat-screen #message-input-form.modern-chat-composer {
  position: static !important;
  min-height: auto !important;
  border-top: 1px solid #e2e8f0;
  padding: 12px 16px !important;
  flex-direction: row;
  align-items: flex-end;
  overflow: visible;
}

.chat-screen .modern-chat-composer-wrap {
  flex: 0 0 auto;
  position: relative;
  z-index: 40;
  background: var(--jre-chat-composer-bg);
  border-top: 1px solid #e2e8f0;
  overflow: visible;
}

.chat-screen .modern-chat-attach-wrap {
  position: relative;
}

.chat-screen .modern-chat-attach-menu {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  padding: 6px 0;
  min-width: 150px;
  z-index: 50;
  border: 1px solid #e2e8f0;
}

.chat-screen .modern-chat-attach-menu button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 16px;
  border: none;
  background: none;
  text-align: start;
  font-size: 0.875rem;
  color: #334155;
  cursor: pointer;
}

.chat-screen .modern-chat-attach-menu button:hover {
  background: #f8fafc;
}

.chat-screen .modern-chat-record-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.chat-screen .modern-chat-record-tooltip {
  display: none;
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: #334155;
  color: #fff;
  font-size: 0.75rem;
  line-height: 1.2;
  padding: 6px 10px;
  border-radius: 6px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 50;
}

.chat-screen .modern-chat-record-wrap:hover .modern-chat-record-tooltip {
  display: block;
}

.chat-screen .modern-chat-record-wrap.is-recording .modern-chat-record-tooltip,
.chat-screen .modern-chat-record-wrap.is-recording:hover .modern-chat-record-tooltip {
  display: none !important;
}

.chat-screen .modern-chat-composer__btn.recording {
  color: #dc3545;
  background: rgba(220, 53, 69, 0.1);
}

.chat-screen .modern-chat-voice-indicator {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  display: none;
  padding: 8px 12px;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
  z-index: 50;
  pointer-events: none;
}

.chat-screen .modern-chat-voice-indicator:not([hidden]) {
  display: block;
}

.chat-screen .modern-chat-voice-indicator canvas {
  width: 180px;
  height: 35px;
  display: block;
}

/* Desktop: side-by-side messenger */
@media (min-width: 769px) {
  .chat-screen .chat-sidebar.modern-chat-sidebar {
    position: static !important;
    transform: none !important;
    width: 360px;
  }

  .chat-screen.active .chat-main.modern-chat-main {
    position: static !important;
    transform: none !important;
    width: auto !important;
    flex: 1;
    inset: auto !important;
    height: auto !important;
    visibility: visible !important;
    pointer-events: auto !important;
  }

  .chat-screen:not(.active) .chat-main.modern-chat-main {
    visibility: hidden !important;
    pointer-events: none !important;
  }

  .chat-screen .modern-chat-page__back {
    display: none;
  }

  .chat-screen .chat-layout.chat-view-active .chat-sidebar {
    transform: none !important;
  }

  .chat-screen .chat-layout.chat-view-active .chat-main {
    transform: none !important;
  }
}

/* Mobile: slide between list and thread */
@media (max-width: 768px) {
  .chat-screen .chat-screen-body {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    padding: 0;
  }

  .chat-screen .chat-layout.modern-chat-app {
    position: relative;
    isolation: isolate;
    flex: 1;
    min-height: 0;
    height: 100%;
    border-radius: 0;
    border: none;
    box-shadow: none;
  }

  .chat-screen .chat-screen-body {
    padding: 0;
  }

  .chat-screen .chat-layout.modern-chat-app {
    border-radius: 12px;
  }

  .chat-screen .modern-chat-sidebar {
    border-radius: 0;
  }

  .chat-screen .modern-chat-main {
    border-radius: 0;
  }

  .chat-screen .chat-main.modern-chat-main {
    width: 100%;
    position: absolute !important;
    inset: 0 !important;
    top: 0 !important;
    left: 0 !important;
    height: 100% !important;
    transform: translateX(100%) !important;
    transition: transform 0.3s ease-in-out;
    border-radius: 12px;
    z-index: 3;
  }

  [dir="rtl"] .chat-screen .chat-main.modern-chat-main {
    transform: translateX(-100%) !important;
  }

  .chat-screen .chat-layout:not(.chat-view-active) .chat-main.modern-chat-main {
    visibility: hidden;
    pointer-events: none;
  }

  .chat-screen .chat-layout.chat-view-active .chat-main.modern-chat-main {
    visibility: visible;
    pointer-events: auto;
  }

  .chat-screen .chat-sidebar.modern-chat-sidebar {
    width: 100%;
    position: absolute !important;
    inset: 0 !important;
    transition: transform 0.3s ease-in-out;
    transform: translateX(0) !important;
    border-radius: 12px;
    z-index: 2;
  }

  .chat-screen .chat-layout.chat-view-active .chat-sidebar {
    transform: translateX(-100%) !important;
  }

  [dir="rtl"] .chat-screen .chat-layout.chat-view-active .chat-sidebar {
    transform: translateX(100%) !important;
  }

  .chat-screen .chat-layout.chat-view-active .chat-main {
    transform: translateX(0) !important;
  }

  .chat-screen .modern-chat-page__back {
    display: inline-flex;
  }
}
