:root {
  --bg-color: #212121;
  --sidebar-bg: #212121;
  --item-hover: #2c2c2c;
  --item-active: #8774e1;
  --text-primary: #ffffff;
  --text-secondary: #aaaaaa;
  --accent: #8774e1;
  --message-in: #212121;
  --message-out: #8774e1;
  --border-color: #1c1c1c;
  --input-bg: #2c2c2c;
  --scrollbar-track: transparent;
  --scrollbar-thumb: rgba(255, 255, 255, 0.1);
}

:root.light-mode {
  --bg-color: #ffffff;
  --sidebar-bg: #f5f5f5;
  --item-hover: #e0e0e0;
  --item-active: #8774e1;
  --text-primary: #000000;
  --text-secondary: #666666;
  --accent: #8774e1;
  --message-in: #ffffff;
  --message-out: #8774e1;
  --border-color: #e0e0e0;
  --input-bg: #f0f0f0;
  --scrollbar-track: #f5f5f5;
  --scrollbar-thumb: #cccccc;
}

:root.light-mode {
  --bg-color: #ffffff;
  --sidebar-bg: #f5f5f5;
  --item-hover: #e0e0e0;
  --item-active: #8774e1;
  --text-primary: #000000;
  --text-secondary: #666666;
  --accent: #8774e1;
  --message-in: #ffffff;
  --message-out: #8774e1;
  /* Keep accent for outgoing, maybe lighter? */
  --border-color: #e0e0e0;
  --input-bg: #f0f0f0;
  --scrollbar-track: #f5f5f5;
  --scrollbar-thumb: #cccccc;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Roboto', "Segoe UI", "Inter", Arial, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
}

/* App Layout */
.app-container {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* Login Overlay */
.login-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #0f172a;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.login-card {
  background: #1e293b;
  padding: 40px;
  border-radius: 16px;
  width: 100%;
  max-width: 400px;
  text-align: center;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.login-card h2 {
  margin-bottom: 24px;
}

.input-group {
  margin-bottom: 16px;
}

.input-group input {
  width: 100%;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(0, 0, 0, 0.2);
  color: white;
  font-size: 16px;
  outline: none;
}

.input-group input:focus {
  border-color: var(--accent);
}

.btn-primary {
  background: var(--accent);
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 16px;
  width: 100%;
  font-weight: 500;
}

.btn-primary:hover {
  filter: brightness(1.1);
}

.login-footer {
  margin-top: 20px;
  font-size: 14px;
}

.login-footer a {
  color: var(--text-secondary);
}

/* Sidebar */
.sidebar {
  width: 420px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  height: 56px;
}

.menu-icon {
  color: #707579;
  cursor: pointer;
}

.search-bar {
  flex: 1;
  background: var(--input-bg);
  border-radius: 22px;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.search-icon {
  color: #707579;
  font-size: 20px;
}

.search-bar input {
  background: transparent;
  border: none;
  color: var(--text-primary);
  width: 100%;
  outline: none;
  font-size: 15px;
}

/* ... existing styles ... */

.light-mode .main-chat {
  background-image: url("data:image/svg+xml,%3Csvg width='100' height='100' viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M11 18c3.866 0 7-3.134 7-7s-3.134-7-7-7-7 3.134-7 7 3.134 7 7 7zm48 25c3.866 0 7-3.134 7-7s-3.134-7-7-7-7 3.134-7 7 3.134 7 7 7zm-43-7c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zm63 31c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zM34 90c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zm56-76c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zM12 86c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 1.79 4 4 4zm28-65c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 1.79 4 4 4zm23-11c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 2.24 5 5 5zm-6 60c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 1.79 4 4 1.79 4 4 1.79 4 4 1.79 4 4 4zm29 22c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 2.24 5 5 2.24 5 5 2.24 5 5 2.24 5 5 2.24 5 5 2.24 5 5 2.24 5 5 2.24 5 5 2.24 5 5 2.24 5 5 2.24 5 5 2.24 5 5 2.24 5 5 zm-9-21c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM60 91c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM35 41c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM12 60c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2z' fill='%23cccccc' fill-opacity='0.4' fill-rule='evenodd'/%3E%3C/svg%3E");
  background-color: #f0f2f5;
}

.search-bar input::placeholder {
  color: #707579;
}

.sidebar-tabs {
  display: flex;
  padding: 0 10px;
  margin-bottom: 4px;
}

.tab {
  padding: 10px 16px;
  color: #707579;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
}

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.chat-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
}

.chat-item {
  display: flex;
  padding: 10px 16px;
  gap: 12px;
  cursor: pointer;
  border-radius: 12px;
  margin: 2px 8px;
  transition: background 0.1s;
}

.chat-item:hover {
  background: var(--item-hover);
}

.chat-item.active {
  background: var(--accent);
}

.chat-item.active .chat-title,
.chat-item.active .chat-last-message,
.chat-item.active .chat-time,
.chat-item.active .chat-meta {
  color: white;
}

.chat-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, #a777e3, #6e52c2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 600;
  color: white;
  flex-shrink: 0;
  text-transform: uppercase;
}

.chat-content-text {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.chat-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 4px;
}

.chat-title {
  font-weight: 500;
  font-size: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-primary);
}

.chat-time {
  font-size: 12px;
  color: #707579;
  white-space: nowrap;
}

.chat-bottom {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
}

.chat-last-message {
  color: #707579;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  max-width: 100%;
}

.badge {
  background: #8774e1;
  color: white;
  border-radius: 12px;
  padding: 0 6px;
  height: 20px;
  min-width: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
}

.unread-indicator {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: #3b82f6;
  display: inline-block;
  margin-left: 8px;
  box-shadow: 0 0 8px rgba(59, 130, 246, 0.8);
  flex-shrink: 0;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.light-mode .unread-indicator {
  background-color: #2563eb;
  box-shadow: 0 0 4px rgba(37, 99, 235, 0.3);
  border: none;
}

.chat-item.active .badge {
  background: white;
  color: var(--accent);
}

/* Main Area */
.main-chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  background-image: url("data:image/svg+xml,%3Csvg width='100' height='100' viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M11 18c3.866 0 7-3.134 7-7s-3.134-7-7-7-7 3.134-7 7 3.134 7 7 7zm48 25c3.866 0 7-3.134 7-7s-3.134-7-7-7-7 3.134-7 7 3.134 7 7 7zm-43-7c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zm63 31c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zM34 90c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zm56-76c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zM12 86c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm28-65c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm23-11c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm-6 60c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 1.79 4 4 1.79 4 4 1.79 4 4 1.79 4 4 1.79 4 4 4zm29 22c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 2.24 5 5 2.24 5 5 2.24 5 5 2.24 5 5 2.24 5 5 2.24 5 5 2.24 5 5 2.24 5 5 2.24 5 5 2.24 5 5 2.24 5 5 2.24 5 5 2.24 5 5 2.24 5 5 2.24 5 5 2.24 5 5 2.24 5 5 2.24 5 5 2.24 5 5 2.24 5 5 2.24 5 5zm-9-21c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM60 91c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM35 41c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM12 60c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2z' fill='%232c2c2c' fill-opacity='0.4' fill-rule='evenodd'/%3E%3C/svg%3E");
  background-color: #0f0f0f;
  position: relative;
}

.chat-header {
  height: 56px;
  background: var(--bg-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid var(--border-color);
  z-index: 10;
}

.chat-header-info {
  display: flex;
  flex-direction: column;
}

.chat-header-title {
  font-weight: 500;
  font-size: 16px;
}

.chat-header-status {
  font-size: 13px;
  color: #707579;
}

.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #707579;
}

.message-search {
  width: min(320px, 38vw);
  min-height: 40px;
  padding: 0 6px 0 12px;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--input-bg);
}
.message-search[hidden] { display: none; }
.message-search > .material-icons { color: var(--text-secondary); font-size: 19px; }
.message-search input {
  min-width: 0;
  flex: 1;
  border: 0;
  outline: 0;
  color: var(--text-primary);
  background: transparent;
  font: inherit;
  font-size: 14px;
}
.message-search-close {
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 9px;
  display: grid;
  place-items: center;
  color: var(--text-secondary);
  background: transparent;
  cursor: pointer;
}
.message-search-close:hover { color: var(--text-primary); background: var(--item-hover); }
.message-search-close .material-icons { font-size: 18px; }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 10px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scroll-behavior: smooth;
  transition: opacity .16s ease;
}

.chat-messages.is-loading { opacity: .72; }

.conversation-skeleton {
  width: 100%;
  padding: 14px 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.conversation-skeleton span {
  width: min(340px, 66%);
  height: 54px;
  border-radius: 14px;
  background: linear-gradient(100deg, var(--message-in) 25%, var(--item-hover) 42%, var(--message-in) 60%);
  background-size: 260% 100%;
  animation: conversationSkeleton 1.25s ease-in-out infinite;
}
.conversation-skeleton span:nth-child(even) { width: min(290px, 58%); align-self: flex-end; }
.conversation-skeleton span:nth-child(3) { width: min(410px, 72%); }
@keyframes conversationSkeleton { to { background-position-x: -130%; } }

.date-divider {
  align-self: stretch;
  display: flex;
  justify-content: center;
  margin: 7px 0 3px;
  pointer-events: none;
}
.date-divider span,
.sticky-date {
  padding: 5px 11px;
  border: 1px solid color-mix(in srgb, var(--border-color) 75%, transparent);
  border-radius: 999px;
  color: var(--text-primary);
  background: color-mix(in srgb, var(--surface-raised) 88%, transparent);
  box-shadow: 0 2px 9px rgba(0, 0, 0, .12);
  backdrop-filter: blur(8px);
  font-size: 12px;
  font-weight: 650;
}
.sticky-date {
  position: absolute;
  z-index: 8;
  top: 72px;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
  transition: opacity .14s ease;
}
.sticky-date[hidden] { display: none; }

.empty-state {
  align-self: center;
  margin-top: auto;
  margin-bottom: auto;
  background: rgba(0, 0, 0, 0.4);
  padding: 8px 16px;
  border-radius: 16px;
  color: white;
  font-size: 14px;
}

/* Messages */
.message {
  max-width: 480px;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--message-in);
  color: white;
  /* Default Dark Mode */
  align-self: flex-start;
  position: relative;
  font-size: 15px;
  line-height: 1.4;
  word-wrap: break-word;
  /* Ensure text wraps */
  word-break: break-word;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.message.animate-in {
  animation: messageSlideIn .16s ease-out;
}

@keyframes messageSlideIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }

  to {
    transform: translateY(0);
  }
}

.light-mode .message {
  color: black;
}

.message--outgoing {
  align-self: flex-end;
  background: var(--message-out);
}

.light-mode .message--outgoing {
  color: white;
  /* Keep white for outgoing */
}

.message__text {
  margin-bottom: 2px;
}

.message-special {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-width: 210px;
  max-width: 360px;
  padding: 4px 2px 7px;
}

.message-special > .material-icons {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, .16);
}

.message-special > div,
.message-special__contact > div {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.message-special span,
.message-special a,
.message-special small {
  display: block;
  font-size: 12px;
  color: inherit;
  opacity: .78;
}

.message-special__action {
  margin-top: 5px;
  font-weight: 700;
  opacity: 1 !important;
  text-decoration: none;
}

.message-special__contact {
  display: flex;
  gap: 9px;
  align-items: center;
  padding: 3px 0;
}

.message-special__contact + .message-special__contact {
  margin-top: 5px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, .18);
}

.message-special__contact .material-icons {
  font-size: 25px;
}

.message-special--poll {
  display: block;
}

.message-special__poll-title {
  display: flex !important;
  flex-direction: row !important;
  gap: 7px;
  align-items: center;
  margin-bottom: 7px;
}

.message-special__poll-option {
  display: flex !important;
  flex-direction: row !important;
  gap: 7px;
  align-items: center;
  padding: 3px 0;
  font-size: 13px;
}

.message-special__poll-option > span {
  width: 12px;
  height: 12px;
  border: 2px solid currentColor;
  border-radius: 50%;
  opacity: .65;
}

.message-special--dice {
  min-width: 90px;
  align-items: center;
}

.message-special--dice strong {
  font-size: 30px;
}

.message-special--service,
.message-special--unsupported {
  min-width: 180px;
  align-items: center;
  padding-bottom: 4px;
}

.light-mode .message--incoming .message-special > .material-icons {
  background: rgba(0, 0, 0, .08);
}

.message__time {
  float: right;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.6);
  margin-left: 8px;
  margin-top: 6px;
  vertical-align: bottom;
}

.light-mode .message__time {
  color: rgba(0, 0, 0, 0.4);
}

.light-mode .message--outgoing .message__time {
  color: rgba(255, 255, 255, 0.7);
}

/* Input Area */
.chat-input-area {
  background: var(--bg-color);
  padding: 8px 16px 12px 16px;
  display: flex;
  align-items: flex-end;
  gap: 12px;
}

.icon-btn {
  background: none;
  border: none;
  color: #707579;
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  transition: background 0.2s;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.05);
  color: #8774e1;
}

.send-btn {
  color: #8774e1;
}

#message-input {
  flex: 1;
  background: var(--bg-color);
  border: none;
  padding: 12px 0;
  color: var(--text-primary);
  font-size: 16px;
  resize: none;
  outline: none;
}

#message-input::placeholder {
  color: #707579;
}

/* Scrollbars */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
}

::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 3px;
}

/* Media styles */
.message__media {
  max-width: 100%;
  margin-bottom: 8px;
  border-radius: 8px;
}

.message__media--audio {
  width: clamp(260px, 34vw, 380px);
  max-width: calc(100vw - 430px);
  min-width: 240px;
}
.message__audio {
  width: 100%;
  min-height: 42px;
  display: block;
}

.message__media--image {
  max-width: 100%;
  max-height: 300px;
  /* Limit height */
  object-fit: cover;
  border-radius: 8px;
  cursor: pointer;
}

.message__media--document {
  color: white;
  text-decoration: none;
  background: rgba(0, 0, 0, 0.2);
  padding: 8px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.message-error {
  color: #ff6b6b;
  font-size: 12px;
  margin-top: 4px;
}

.media-download-button {
  border: 0;
  border-radius: 9px;
  padding: 7px 11px;
  color: #fff;
  background: var(--accent);
  cursor: pointer;
  font: inherit;
  font-size: 13px;
}
.media-download-button--loading { display: inline-flex; align-items: center; gap: 6px; }
.media-download-button--loading .material-icons { font-size: 16px; }
.media-download-button:disabled { cursor: wait; opacity: .7; }
.media-download-button--loading:disabled { opacity: 1; }
.message--outgoing .media-download-button {
  color: var(--accent);
  background: rgba(255, 255, 255, .96);
  border: 1px solid rgba(255, 255, 255, .72);
  box-shadow: 0 2px 8px rgba(0, 0, 0, .16);
}
.message--outgoing .media-download-button:hover { background: #fff; }
/* Upload Preview */
.upload-preview {
  background: var(--bg-color);
  padding: 8px 16px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 10px;
}
.upload-preview[hidden] { display: none; }
.upload-preview-list { display: flex; flex-wrap: wrap; gap: 7px; min-width: 0; flex: 1; }
.upload-preview-content {
  max-width: 280px;
  background: var(--accent-soft);
  border: 1px solid rgba(var(--accent-rgb), .45);
  border-radius: 10px;
  padding: 7px 9px;
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--text-primary);
  font-size: 13px;
}
.upload-preview-content .upload-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-preview-content .upload-size { color: var(--text-secondary); font-size: 11px; white-space: nowrap; }
.close-preview { cursor: pointer; font-size: 17px; color: var(--text-secondary); }
.close-preview:hover { color: #ef4444; }
.clear-all-uploads { border: 0; background: transparent; color: var(--accent); cursor: pointer; font-weight: 600; }

.emoji-picker {
  position: absolute;
  z-index: 30;
  left: 56px;
  bottom: calc(100% + 10px);
  width: min(340px, calc(100vw - 32px));
  max-height: 250px;
  overflow-y: auto;
  padding: 10px;
  border: 1px solid var(--border-color);
  border-radius: 16px;
  background: var(--surface-raised);
  box-shadow: 0 14px 40px rgba(0, 0, 0, .28);
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 3px;
}
.emoji-picker[hidden] { display: none; }
.emoji-option {
  border: 0;
  border-radius: 8px;
  padding: 5px 2px;
  background: transparent;
  font-size: 22px;
  cursor: pointer;
}
.emoji-option:hover, .emoji-option:focus-visible { background: var(--accent-soft); outline: none; }
.chat-input-area { position: relative; }

.quick-reply-shell {
  position: absolute;
  right: 14px;
  bottom: calc(100% + 10px);
  z-index: 45;
  width: min(610px, calc(100% - 28px));
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  gap: 8px;
  animation: quick-reply-enter .16s ease-out;
}
.quick-reply-shell[hidden] { display: none; }
.quick-reply-menu {
  flex: 0 1 540px;
  min-width: 0;
  max-height: 207px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 6px;
  border: 1px solid var(--border-color);
  border-radius: 17px;
  background: var(--surface-raised);
  box-shadow: 0 16px 44px rgba(0, 0, 0, .3);
}
.quick-reply-option {
  width: 100%;
  min-height: 61px;
  border: 0;
  border-radius: 12px;
  padding: 9px 11px;
  background: transparent;
  color: var(--text-primary);
  display: grid;
  gap: 3px;
  text-align: left;
  cursor: pointer;
}
.quick-reply-option + .quick-reply-option { margin-top: 3px; }
.quick-reply-option:hover,
.quick-reply-option.is-active { background: var(--accent-soft); }
.quick-reply-option:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.quick-reply-option strong { color: var(--accent); font-size: 14px; }
.quick-reply-option span {
  overflow: hidden;
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.quick-reply-empty { padding: 15px 13px; color: var(--text-secondary); font-size: 13px; }
.quick-reply-settings-button {
  flex: 0 0 48px;
  width: 48px;
  height: 48px;
  border: 1px solid var(--border-color);
  border-radius: 16px;
  background: var(--surface-raised);
  color: var(--text-secondary);
  box-shadow: 0 12px 34px rgba(0, 0, 0, .26);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.quick-reply-settings-button:hover,
.quick-reply-settings-button:focus-visible { color: var(--accent); background: var(--accent-soft); outline: none; }
@keyframes quick-reply-enter { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

.app-modal__card--quick-replies { width: min(610px, 100%); max-height: min(760px, calc(100vh - 36px)); overflow-y: auto; }
.quick-reply-settings-list { display: grid; gap: 8px; max-height: 340px; overflow-y: auto; }
.quick-reply-settings-empty { padding: 26px 14px; border: 1px dashed var(--border-color); border-radius: 14px; color: var(--text-secondary); text-align: center; }
.quick-reply-settings-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 11px 12px; border: 1px solid var(--border-color); border-radius: 14px; background: var(--input-bg); }
.quick-reply-settings-item.is-confirming { border-color: rgba(239, 68, 85, .52); background: rgba(239, 68, 85, .08); }
.quick-reply-settings-copy { min-width: 0; display: grid; gap: 4px; }
.quick-reply-settings-copy strong { color: var(--accent); font-size: 14px; }
.quick-reply-settings-copy span { color: var(--text-secondary); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quick-reply-settings-actions { display: flex; gap: 4px; }
.quick-reply-item-button { width: 36px; height: 36px; border: 0; border-radius: 11px; display: grid; place-items: center; background: transparent; color: var(--text-secondary); cursor: pointer; }
.quick-reply-item-button:hover { color: var(--accent); background: var(--accent-soft); }
.quick-reply-item-button--delete:hover { color: #ef4455; background: rgba(239, 68, 85, .12); }
.quick-reply-item-button .material-icons { font-size: 19px; }
.quick-reply-add-button { min-height: 45px; border: 1px dashed color-mix(in srgb, var(--accent) 55%, var(--border-color)); border-radius: 13px; background: var(--accent-soft); color: var(--accent); display: flex; align-items: center; justify-content: center; gap: 7px; font-weight: 600; cursor: pointer; }
.quick-reply-add-button:hover { filter: brightness(1.08); }
.quick-reply-editor { padding-top: 14px; border-top: 1px solid var(--border-color); display: grid; gap: 13px; }
.quick-reply-editor[hidden] { display: none; }
.quick-reply-editor-title { color: var(--text-primary); font-size: 16px; font-weight: 700; }
.quick-reply-form-error { padding: 9px 11px; border-radius: 10px; color: #ff7b88; background: rgba(239, 68, 85, .1); font-size: 13px; }
.quick-reply-form-error[hidden] { display: none; }

@media (max-width: 640px) {
  .quick-reply-shell { right: 8px; width: calc(100% - 16px); }
  .quick-reply-settings-button { flex-basis: 44px; width: 44px; height: 44px; border-radius: 14px; }
}
/* Ensure form buttons line up */
.chat-input-area .icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Notifications */
#notification-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  pointer-events: none;
}

.notification-toast {
  background: #2c2c2c;
  /* card bg */
  color: white;
  padding: 12px 16px;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  min-width: 300px;
  max-width: 400px;
  pointer-events: auto;
  animation: slideIn 0.3s ease-out forwards;
  display: flex;
  flex-direction: column;
  gap: 4px;
  border: 1px solid #333;
}

.notification-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.notification-title {
  font-weight: 700;
  font-size: 14px;
  color: white;
}

.notification-close {
  cursor: pointer;
  color: #aeaeae;
  font-size: 18px;
  line-height: 14px;
  padding-left: 10px;
}

.notification-close:hover {
  color: white;
}

.notification-body {
  font-size: 13px;
  color: #aeaeae;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(20px);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes fadeOut {
  to {
    opacity: 0;
    transform: translateX(20px);
  }
}

/* Media Viewer Modal */
.media-viewer {
  display: none;
  position: fixed;
  z-index: 2000;
  padding-top: 50px;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background-color: rgba(0, 0, 0, 0.9);
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

.media-viewer-content {
  margin: auto;
  display: block;
  max-width: 90%;
  max-height: 90vh;
  animation-name: zoom;
  animation-duration: 0.3s;
}

@keyframes zoom {
  from {
    transform: scale(0)
  }

  to {
    transform: scale(1)
  }
}

.media-viewer-close {
  position: absolute;
  top: 15px;
  right: 35px;
  color: #f1f1f1;
  font-size: 40px;
  font-weight: bold;
  transition: 0.3s;
  cursor: pointer;
  z-index: 2001;
}

.media-viewer-close:hover,
.media-viewer-close:focus {
  color: #bbb;
  text-decoration: none;
  cursor: pointer;
}
/* Omnichannel workspace refresh */
:root {
  --accent: #229ed9;
  --accent-rgb: 34, 158, 217;
  --accent-soft: rgba(34, 158, 217, 0.14);
  --item-active: #229ed9;
  --message-out: #229ed9;
  --surface-raised: #282828;
  --warning-bg: rgba(245, 158, 11, 0.12);
  --warning-text: #fbbf24;
  --transition-theme: 320ms cubic-bezier(.2,.8,.2,1);
}

:root[data-messenger="all"] {
  --accent: #5266d5;
  --accent-rgb: 82, 102, 213;
  --accent-soft: rgba(82, 102, 213, 0.14);
  --item-active: #5266d5;
  --message-out: #5266d5;
}

:root[data-messenger="max"] {
  --accent: #7c5cff;
  --accent-rgb: 124, 92, 255;
  --accent-soft: rgba(124, 92, 255, 0.15);
  --item-active: #7c5cff;
  --message-out: #7c5cff;
}

:root[data-messenger="whatsapp"] {
  --accent: #25d366;
  --accent-rgb: 37, 211, 102;
  --accent-soft: rgba(37, 211, 102, 0.14);
  --item-active: #169c50;
  --message-out: #169c50;
}

:root.light-mode {
  --surface-raised: #ffffff;
  --warning-bg: #fff7e5;
  --warning-text: #9a6700;
}

:root.light-mode[data-messenger="telegram"] {
  --accent: #229ed9;
  --accent-rgb: 34, 158, 217;
  --accent-soft: rgba(34, 158, 217, 0.12);
  --item-active: #229ed9;
  --message-out: #229ed9;
  --sidebar-bg: #f5fbfe;
  --input-bg: #eef8fc;
  --item-hover: #e1f3fa;
  --border-color: #d7ebf3;
}

/* MAX stays deliberately purple in the light theme; Telegram remains cyan-blue. */
:root.light-mode[data-messenger="max"] {
  --accent: #6d28d9;
  --accent-rgb: 109, 40, 217;
  --accent-soft: rgba(109, 40, 217, 0.13);
  --item-active: #6d28d9;
  --message-out: #6d28d9;
  --sidebar-bg: #faf7ff;
  --input-bg: #f3edff;
  --item-hover: #ece2ff;
  --border-color: #e4d8f7;
}

body, .sidebar, .main-chat, .chat-header, .chat-input-area, .search-bar,
.messenger-option, .message--outgoing {
  transition: background-color var(--transition-theme), border-color var(--transition-theme), color var(--transition-theme), box-shadow var(--transition-theme);
}

.workspace-header {
  min-height: 72px;
  padding: 14px 18px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.workspace-header-actions { display: flex; align-items: center; gap: 8px; }

.workspace-eyebrow {
  color: var(--accent);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
  transition: color var(--transition-theme);
}

.workspace-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -.02em;
}

.header-icon-button {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: var(--text-secondary);
  background: var(--input-bg);
  cursor: pointer;
}

.header-icon-button:hover { color: var(--accent); }

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

.messenger-switcher {
  margin: 4px 12px 8px;
  padding: 5px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
  border: 1px solid var(--border-color);
  border-radius: 16px;
  background: var(--input-bg);
}

.messenger-option {
  min-width: 0;
  padding: 8px 6px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  position: relative;
}

.messenger-option:hover { background: rgba(var(--accent-rgb), .08); }
.messenger-option.active {
  color: var(--accent);
  background: var(--surface-raised);
  box-shadow: 0 3px 12px rgba(0,0,0,.14);
}

.messenger-icon {
  width: 23px;
  height: 23px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: white;
  font-size: 12px;
  font-weight: 800;
}
.messenger-icon .material-icons { font-size: 14px; }
.all-icon { background: linear-gradient(135deg, #5266d5, #7b5ed7); }
.telegram-icon { background: #229ed9; }
.max-icon { background: linear-gradient(135deg, #9a5cff, #4c68ff); }
.whatsapp-icon { background: #25d366; }
.soon-dot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; opacity: .45; }

.sidebar { width: 390px; min-width: 330px; }
.sidebar-header { height: auto; padding: 7px 12px; gap: 8px; }
.search-bar {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 13px;
  transition: border-color .2s, box-shadow .2s, background-color var(--transition-theme);
}
.search-bar:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.account-health {
  position: relative;
  flex: 0 0 auto;
}
.account-health[hidden] { display: none; }
.account-health-trigger {
  position: relative;
  overflow: visible;
  color: var(--warning-text);
  background: var(--warning-bg);
}
.account-health-trigger:hover,
.account-health-trigger[aria-expanded="true"] {
  color: var(--warning-text);
  background: color-mix(in srgb, var(--warning-bg) 72%, var(--warning-text) 28%);
}
.account-health-trigger::after {
  content: attr(data-tooltip);
  position: absolute;
  z-index: 90;
  top: calc(100% + 8px);
  right: 0;
  width: max-content;
  max-width: 230px;
  padding: 7px 9px;
  border-radius: 8px;
  background: #111827;
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.25;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-3px);
  transition: opacity .15s ease, transform .15s ease;
  box-shadow: 0 7px 22px rgba(0,0,0,.24);
}
.account-health-trigger:hover::after,
.account-health-trigger:focus-visible::after {
  opacity: 1;
  transform: translateY(0);
}
.account-health-trigger[aria-expanded="true"]::after { display: none; }
.account-health-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border: 2px solid var(--sidebar-bg);
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: #ef4444;
  color: #fff;
  font-size: 9px;
  font-weight: 800;
  line-height: 1;
}
.account-health-popover {
  position: absolute;
  z-index: 80;
  top: calc(100% + 10px);
  right: -48px;
  width: min(350px, calc(100vw - 24px));
  padding: 12px;
  border: 1px solid var(--border-color);
  border-radius: 15px;
  background: var(--surface-raised);
  color: var(--text-primary);
  box-shadow: 0 18px 45px rgba(0,0,0,.3);
  font-size: 12px;
}
.account-health-popover[hidden] { display: none; }
.account-health-heading {
  min-width: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 1px 1px 10px;
}
.account-health-heading > div { min-width: 0; display: grid; gap: 2px; }
.account-health-heading strong { font-size: 13px; }
.account-health-heading span { color: var(--text-secondary); }
.account-health-close {
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
  border: 0;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
}
.account-health-close:hover { background: var(--input-bg); color: var(--text-primary); }
.account-health-close .material-icons { font-size: 18px; }
.account-health-list { display: grid; gap: 8px; min-width: 0; }
.account-health-row {
  min-width: 0;
  padding: 10px;
  border-radius: 11px;
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  align-items: start;
  gap: 9px;
  background: var(--input-bg);
}
.account-health-provider {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent);
}
.account-health-provider .material-icons { font-size: 16px; }
.account-health-provider--whatsapp { background: rgba(37,211,102,.13); color: #25b85a; }
.account-health-provider--max { background: rgba(122,92,255,.14); color: #8067ff; }
.account-health-provider--bot { background: rgba(34,158,217,.13); color: #229ed9; }
.account-health-content { min-width: 0; display: grid; gap: 8px; }
.account-health-copy { min-width: 0; flex: 1; display: grid; gap: 2px; }
.account-health-copy strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-health-copy span { color: var(--text-secondary); line-height: 1.35; overflow-wrap: anywhere; }
.account-health-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 7px; }
.account-health-start {
  min-height: 32px;
  padding: 5px 11px;
  border: 0;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
}
.account-health-start:hover:not(:disabled) { filter: brightness(1.08); }
.account-health-start:disabled { cursor: wait; opacity: .72; }
.account-health-start .material-icons { font-size: 17px; }
.account-health-start:disabled .material-icons { animation: spin 1s linear infinite; }
.account-health-admin {
  min-height: 32px;
  padding: 5px 10px;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  color: var(--text-secondary);
  background: var(--surface-raised);
  font-weight: 700;
  text-decoration: none;
}
.account-health-admin:hover { color: var(--accent); }

.sidebar-tabs { align-items: center; justify-content: space-between; padding: 0 16px 4px; }
.tab { padding: 8px 0; cursor: default; font-size: 13px; }
.chat-count {
  min-width: 25px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}

.chat-item {
  min-height: 84px;
  margin: 2px 8px;
  padding: 10px 12px;
  border-left: 3px solid transparent;
  transition: background-color .16s, transform .16s, border-color .16s;
}
.chat-item:hover { transform: translateX(2px); }
.chat-item--bot:not(.active) { border-left-color: var(--accent); background: rgba(var(--accent-rgb), .055); }
.chat-item.active { box-shadow: 0 8px 24px rgba(var(--accent-rgb), .22); }

.chat-avatar {
  width: 46px;
  height: 46px;
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent), #312e81 34%));
}
.chat-item--bot .chat-avatar { border-radius: 15px; }

.chat-top { margin-bottom: 3px; }
.chat-title { font-size: 15px; font-weight: 600; }
.chat-source-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 5px;
  min-width: 0;
}
.account-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 6px;
  border-radius: 999px;
  color: var(--accent);
  background: var(--accent-soft);
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
}
.account-badge .material-icons { font-size: 11px; }
.account-badge--personal { color: var(--text-secondary); background: rgba(127,127,127,.12); }
.chat-account-name {
  min-width: 0;
  overflow: hidden;
  color: var(--text-secondary);
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-item.active .account-badge { background: rgba(255,255,255,.18); color: white; }
.messenger-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 6px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 750;
  white-space: nowrap;
}
.messenger-badge .material-icons { font-size: 11px; }
.messenger-letter-icon { font-size: 10px; font-style: normal; font-weight: 900; }
.messenger-badge--telegram { color: #1689c2; background: rgba(34, 158, 217, .14); }
.messenger-badge--max { color: #7c4ee4; background: rgba(124, 92, 255, .14); }
.messenger-badge--whatsapp { color: #178c49; background: rgba(37, 211, 102, .14); }
.chat-item.active .messenger-badge { color: white; background: rgba(255,255,255,.18); }
.chat-item.active .chat-account-name { color: rgba(255,255,255,.8); }

.unread-indicator {
  width: auto;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  margin-left: 8px;
  display: inline-grid;
  place-items: center;
  background: var(--accent);
  box-shadow: none;
  color: white;
  font-size: 11px;
  font-weight: 700;
}
.chat-item.active .unread-indicator { color: var(--accent); background: white; }

.chat-list-empty, .empty-state {
  margin: auto;
  padding: 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  color: var(--text-secondary);
  text-align: center;
}
.chat-list-empty .material-icons, .empty-state .material-icons {
  width: 48px;
  height: 48px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  color: var(--accent);
  background: var(--accent-soft);
  font-size: 25px;
}
.chat-list-empty strong, .empty-state strong { color: var(--text-primary); font-size: 15px; }
.chat-list-empty span, .empty-state span { max-width: 260px; font-size: 13px; line-height: 1.4; }

.chat-header { min-height: 64px; height: 64px; padding: 0 20px; }
.chat-header-title { font-size: 17px; font-weight: 650; }
.chat-header-status { margin-top: 2px; color: var(--accent); }
.chat-input-area { gap: 8px; padding: 10px 16px; }
.chat-input-area input { min-height: 42px; border-radius: 14px; }
.icon-btn { border-radius: 12px; }
.icon-btn:disabled { opacity: .36; cursor: not-allowed; }
.send-btn { background: var(--accent); color: white; }
.send-btn:hover { filter: brightness(1.08); }

.notification-toast { border-left: 3px solid var(--accent); }

@media (max-width: 820px) {
  .sidebar { width: 340px; min-width: 300px; }
  .account-health-popover { width: 316px; }
  .messenger-option > span:nth-child(2) { display: none; }
}

@media (max-width: 640px) {
  .sidebar { width: 310px; min-width: 280px; }
  .account-health-popover { width: 286px; }
  .workspace-header { min-height: 64px; }
  .chat-header { padding: 0 12px; }
  .chat-header-status { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .message-search { width: min(230px, 42vw); }
  .message__media--audio { width: 240px; min-width: 220px; max-width: 72vw; }
}
.account-badge--whatsapp {
  color: #22a559;
  background: color-mix(in srgb, #22a559 14%, transparent);
}

.account-badge--max {
  color: #8b5cf6;
  background: color-mix(in srgb, #8b5cf6 14%, transparent);
}

.chat-item--whatsapp .chat-avatar {
  background: linear-gradient(145deg, #27c86f, #159447);
}

.chat-item--max .chat-avatar {
  background: linear-gradient(145deg, #9c6cff, #6842d8);
}

.message__reply-preview {
  border-left: 3px solid var(--accent, #25d366);
  margin-bottom: 6px;
  padding: 4px 8px;
  max-width: 320px;
  color: currentColor;
  background: rgba(255, 255, 255, .11);
  opacity: .92;
  font-size: 0.82rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.message--incoming .message__reply-preview { background: rgba(var(--accent-rgb), .12); }
.message__forwarded {
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 0 0 5px;
  color: var(--accent);
  font-size: .78rem;
  font-weight: 650;
  line-height: 1.2;
}
.message__forwarded .material-icons { flex: 0 0 auto; font-size: 15px; }
.message--outgoing .message__forwarded { color: rgba(255, 255, 255, .88); }
.message__media--sticker { background: transparent; margin-bottom: 2px; }
.message__media--sticker img { width: min(190px, 42vw); height: min(190px, 42vw); object-fit: contain; }
.message__media--sticker .sticker-video, .tgs-sticker { width: min(190px, 42vw); height: min(190px, 42vw); display: block; object-fit: contain; }
.sticker-fallback { display: grid; place-items: center; height: 100%; padding: 12px; border-radius: 14px; color: var(--text-secondary); background: var(--input-bg); font-size: 12px; }
.message--sticker { background: transparent; box-shadow: none; padding: 4px; }
.message--sticker .message__time { padding: 3px 6px; border-radius: 9px; background: rgba(0, 0, 0, .42); color: #fff; }

.history-button, .primary-button, .secondary-button {
  border: 0; border-radius: 11px; padding: 9px 12px; font: inherit; font-weight: 600; cursor: pointer;
}
.history-button { display: flex; align-items: center; gap: 7px; color: var(--accent); background: var(--accent-soft); white-space: nowrap; }
.history-button[hidden] { display: none; }
.history-button .material-icons { font-size: 19px; }
.primary-button { color: white; background: var(--accent); }
.secondary-button { color: var(--text-primary); background: var(--input-bg); }
.app-modal[hidden] { display: none; }
.app-modal { position: fixed; inset: 0; z-index: 10000; display: grid; place-items: center; padding: 18px; }
.app-modal__backdrop { position: absolute; inset: 0; background: rgba(5, 10, 18, .66); backdrop-filter: blur(3px); }
.app-modal__card { position: relative; width: min(440px, 100%); padding: 20px; border-radius: 18px; border: 1px solid var(--border-color); background: var(--surface-raised); box-shadow: 0 24px 80px rgba(0,0,0,.38); display: grid; gap: 16px; }
.app-modal__header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.app-modal__header > div { display: grid; gap: 4px; }
.app-modal__header strong { color: var(--text-primary); font-size: 18px; }
.app-modal__header span, .form-hint { color: var(--text-secondary); font-size: 13px; line-height: 1.4; }
.form-field { display: grid; gap: 7px; color: var(--text-primary); font-size: 13px; font-weight: 600; }
.form-field input { border: 1px solid var(--border-color); border-radius: 11px; padding: 11px 12px; background: var(--input-bg); color: var(--text-primary); font: inherit; }
.form-field input:disabled { opacity: .5; }
.check-field { display: flex; align-items: center; gap: 9px; color: var(--text-primary); cursor: pointer; }
.check-field input { accent-color: var(--accent); width: 17px; height: 17px; }
.app-modal__actions { display: flex; justify-content: flex-end; gap: 9px; }

/* AI assistant and Google Contacts controls */
.ai-sidebar-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px 7px;
}
.ai-override-button {
  min-width: 0;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 38px;
  padding: 7px 12px;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  color: var(--text-secondary);
  background: var(--surface-raised);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: color .18s ease, border-color .18s ease, background .18s ease;
}
.ai-override-button:hover:not(:disabled) { color: #dc3545; border-color: rgba(220, 53, 69, .45); }
.ai-override-button.is-active { color: #fff; border-color: #dc3545; background: #dc3545; }
.ai-override-button.is-active:hover:not(:disabled) { color: #fff; border-color: #b92534; background: #b92534; }
.ai-override-button:disabled { opacity: .5; cursor: not-allowed; }
.ai-override-button .material-icons { font-size: 19px; }

.chat-ai-status {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: #8a929b;
  background: color-mix(in srgb, var(--surface-raised) 88%, transparent);
  cursor: help;
}
.chat-ai-status[hidden] { display: none; }
.chat-ai-status.is-active { color: #dc3545; background: rgba(220, 53, 69, .1); }
.chat-ai-status.is-paused { color: #d88916; background: rgba(216, 137, 22, .13); }
.chat-ai-status.is-disabled { color: #737b85; background: rgba(115, 123, 133, .14); }
.chat-ai-status.is-unavailable { cursor: help; opacity: .72; }
.chat-ai-status.is-active:hover:not(:disabled) { color: #fff; background: #dc3545; }
.chat-ai-status.is-paused:hover:not(:disabled),
.chat-ai-status.is-disabled:hover:not(:disabled) { color: #fff; background: #68717c; }
.chat-ai-status:disabled { opacity: .65; cursor: wait; }
.chat-ai-status .material-icons { font-size: 20px; }

.chat-system-name {
  max-width: 155px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-secondary);
  font-size: 11px;
}
.chat-item.active .chat-system-name { color: rgba(255,255,255,.8); }

.human-attention-indicator {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  margin-left: auto;
  border-radius: 50%;
  color: #fff;
  background: #ef7d22;
  flex: 0 0 auto;
}
.human-attention-indicator .material-icons { font-size: 14px; }
.chat-item.active .human-attention-indicator { color: #ef7d22; background: #fff; }

.chat-ai-list-status {
  display: inline-grid;
  place-items: center;
  width: 19px;
  height: 19px;
  margin-left: 4px;
  border-radius: 50%;
  color: #7f8892;
  background: color-mix(in srgb, currentColor 11%, transparent);
  flex: 0 0 auto;
}
.chat-row-indicators {
  display: grid;
  grid-template-columns: 20px 19px 30px;
  align-items: center;
  justify-items: center;
  column-gap: 4px;
  width: 77px;
  min-width: 77px;
}
.chat-row-indicators .human-attention-indicator {
  grid-column: 1;
  margin-left: 0;
}
.chat-row-indicators .chat-ai-list-status {
  grid-column: 2;
  margin-left: 0;
}
.chat-row-indicators .unread-indicator {
  grid-column: 3;
  justify-self: end;
  margin-left: 0;
}
.chat-ai-list-status .material-icons { font-size: 13px; }
.chat-ai-list-status.is-active { color: #dc3545; }
.chat-ai-list-status.is-paused { color: #d88916; }
.chat-ai-list-status.is-disabled { color: #737b85; }
.chat-ai-list-status.is-global-disabled,
.chat-ai-list-status.is-global-paused,
.chat-ai-list-status.is-operator-paused { color: #9aa1a9; opacity: .75; }
.chat-item.active .chat-ai-list-status { color: #fff; background: rgba(255,255,255,.2); opacity: 1; }

.ai-global-control-button { transition: color .18s ease, background .18s ease; }
.ai-global-control-button.is-active { color: #dc3545; background: rgba(220, 53, 69, .12); }
.ai-global-control-button.is-paused { color: #d88916; background: rgba(216, 137, 22, .13); }
.ai-global-control-button.is-disabled { color: #7f8892; }

.chat-ai-control-card { width: min(470px, 100%); }
.chat-ai-disable-options { display: grid; gap: 12px; }
.chat-ai-disable-options[hidden] { display: none; }
.choice-field {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  cursor: pointer;
  background: var(--surface-raised);
}
.choice-field input { margin-top: 3px; accent-color: #dc3545; }
.choice-field span { display: grid; gap: 3px; }
.choice-field small { color: var(--text-secondary); line-height: 1.35; }
.form-hint--warning { color: #b56800; }
.danger-button {
  min-height: 38px;
  padding: 0 16px;
  border: 0;
  border-radius: 10px;
  color: #fff;
  background: #dc3545;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.danger-button:hover:not(:disabled) { background: #b92534; }
.danger-button:disabled { opacity: .6; cursor: wait; }

.app-modal__card--wide {
  width: min(720px, 100%);
  max-height: min(900px, calc(100vh - 36px));
  overflow-y: auto;
}
.app-modal textarea {
  width: 100%;
  resize: vertical;
  border: 1px solid var(--border-color);
  border-radius: 11px;
  padding: 10px 12px;
  color: var(--text-primary);
  background: var(--input-bg);
  font: inherit;
  line-height: 1.45;
}
.app-modal textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 25%, transparent); border-color: var(--accent); }
.form-field small { color: var(--text-secondary); font-size: 12px; }
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.ai-master-toggle { padding: 11px 12px; border-radius: 11px; background: rgba(220, 53, 69, .08); }

@media (max-width: 760px) {
  .settings-grid { grid-template-columns: 1fr; }
  .ai-override-button span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
@media (max-width: 820px) { .history-button span { display: none; } }

.status-icon {
  display: inline-block;
  width: 18px;
  margin-left: 2px;
  text-align: right;
  transition: color .15s ease;
}

.status-icon--read {
  color: #34b7f1;
}
/* Neutral low-contrast wallpaper: independent from the selected messenger color. */
.main-chat {
  background-color: #11151a;
  background-image: url("data:image/svg+xml,%3Csvg width='168' height='168' viewBox='0 0 168 168' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' stroke='%23ffffff' stroke-opacity='.055' stroke-width='1.2'%3E%3Cpath d='M18 31h21a7 7 0 0 1 7 7v9a7 7 0 0 1-7 7H29l-7 6 2-6h-6a7 7 0 0 1-7-7v-9a7 7 0 0 1 7-7Z'/%3E%3Cpath d='M111 102h27a7 7 0 0 1 7 7v10a7 7 0 0 1-7 7h-8l2 7-8-7h-13a7 7 0 0 1-7-7v-10a7 7 0 0 1 7-7Z'/%3E%3Cpath d='m93 20 7 7-7 7M100 27H78M53 112a11 11 0 1 0 22 0 11 11 0 0 0-22 0Z'/%3E%3C/g%3E%3Cg fill='%23ffffff' fill-opacity='.045'%3E%3Ccircle cx='135' cy='35' r='3'/%3E%3Ccircle cx='31' cy='131' r='2.5'/%3E%3Ccircle cx='91' cy='78' r='2'/%3E%3C/g%3E%3C/svg%3E");
  background-size: 168px 168px;
}

:root.light-mode .main-chat {
  background-color: #eef1f4;
  background-image: url("data:image/svg+xml,%3Csvg width='168' height='168' viewBox='0 0 168 168' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' stroke='%235f6b76' stroke-opacity='.105' stroke-width='1.2'%3E%3Cpath d='M18 31h21a7 7 0 0 1 7 7v9a7 7 0 0 1-7 7H29l-7 6 2-6h-6a7 7 0 0 1-7-7v-9a7 7 0 0 1 7-7Z'/%3E%3Cpath d='M111 102h27a7 7 0 0 1 7 7v10a7 7 0 0 1-7 7h-8l2 7-8-7h-13a7 7 0 0 1-7-7v-10a7 7 0 0 1 7-7Z'/%3E%3Cpath d='m93 20 7 7-7 7M100 27H78M53 112a11 11 0 1 0 22 0 11 11 0 0 0-22 0Z'/%3E%3C/g%3E%3Cg fill='%235f6b76' fill-opacity='.08'%3E%3Ccircle cx='135' cy='35' r='3'/%3E%3Ccircle cx='31' cy='131' r='2.5'/%3E%3Ccircle cx='91' cy='78' r='2'/%3E%3C/g%3E%3C/svg%3E");
}

.archive-toggle {
  width: calc(100% - 24px);
  min-height: 58px;
  margin: 1px 12px 8px;
  padding: 7px 10px;
  border: 1px solid var(--border-color);
  border-radius: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-primary);
  background: var(--surface-raised);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color .16s, background-color .16s, transform .16s;
}
.archive-toggle:hover { border-color: var(--accent); transform: translateY(-1px); }
.archive-toggle.active { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.archive-toggle-icon {
  width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center;
  color: var(--accent); background: var(--accent-soft); flex: 0 0 auto;
}
.archive-toggle-icon .material-icons { font-size: 20px; }
.archive-toggle-copy { min-width: 0; flex: 1; display: grid; gap: 2px; }
.archive-toggle-copy strong { font-size: 13px; }
.archive-toggle-copy small { overflow: hidden; color: var(--text-secondary); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.archive-count { min-width: 22px; height: 22px; padding: 0 6px; border-radius: 999px; display: grid; place-items: center; color: var(--accent); background: var(--accent-soft); font-size: 11px; font-weight: 700; }
.archive-chevron { color: var(--text-secondary); font-size: 19px; transition: transform .18s; }
.archive-toggle.active .archive-chevron { transform: rotate(180deg); }

.chat-context-menu {
  position: fixed;
  z-index: 1200;
  min-width: 210px;
  padding: 6px;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  background: var(--surface-raised);
  box-shadow: 0 12px 36px rgba(0,0,0,.24);
}
.chat-context-menu[hidden] { display: none; }
.chat-context-menu button { width: 100%; padding: 10px 12px; border: 0; border-radius: 8px; display: flex; align-items: center; gap: 9px; color: var(--text-primary); background: transparent; font: inherit; font-size: 13px; cursor: pointer; }
.chat-context-menu button:hover { color: var(--accent); background: var(--accent-soft); }
.chat-context-menu .material-icons { font-size: 19px; }

.reply-composer {
  padding: 8px 16px;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-color);
}
.reply-composer[hidden] { display: none; }
.reply-composer > .material-icons { color: var(--accent); }
.reply-composer > div { min-width: 0; flex: 1; display: grid; gap: 2px; }
.reply-composer strong { color: var(--accent); font-size: 12px; }
.reply-composer span { overflow: hidden; color: var(--text-secondary); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.reply-composer .icon-btn { width: 32px; height: 32px; }

.message-reply-button, .message-reaction-button {
  position: absolute;
  z-index: 6;
  top: auto;
  right: 6px;
  bottom: -12px;
  width: 28px;
  height: 28px;
  border: 1px solid color-mix(in srgb, var(--border-color) 78%, transparent);
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--text-secondary);
  background: #fff;
  box-shadow: 0 3px 10px rgba(0, 0, 0, .2);
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(-3px) scale(.94);
  transition: opacity .14s, transform .14s, visibility .14s, color .14s, background .14s;
}
.message-reaction-button { right: 38px; }
.message-reply-button .material-icons, .message-reaction-button .material-icons { font-size: 17px; }
.message:hover .message-reply-button, .message-reply-button:focus-visible,
.message:hover .message-reaction-button, .message-reaction-button:focus-visible,
.message:focus-within .message-reply-button, .message:focus-within .message-reaction-button {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: none;
}
.message-reply-button:hover, .message-reaction-button:hover {
  color: var(--accent);
  background: #fff;
  border-color: color-mix(in srgb, var(--accent) 58%, #fff);
  box-shadow: 0 4px 14px rgba(0, 0, 0, .28);
}
.message { position: relative; }

.message-reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.message-reactions[hidden], .reaction-picker[hidden] { display: none; }
.message-reaction {
  min-height: 24px; padding: 2px 7px; border: 1px solid var(--border-color); border-radius: 999px;
  color: var(--text-primary); background: color-mix(in srgb, var(--bg-color) 82%, transparent);
  font: inherit; font-size: 12px; line-height: 1; cursor: default;
}
button.message-reaction { cursor: pointer; }
.message-reaction.chosen { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.reaction-picker {
  position: absolute; z-index: 15; top: auto; right: 34px; bottom: 22px; display: flex; gap: 2px;
  padding: 6px; border: 1px solid var(--border-color); border-radius: 13px;
  background: var(--surface-raised); box-shadow: 0 10px 32px rgba(0,0,0,.28);
}
.reaction-picker button { width: 30px; height: 30px; border: 0; border-radius: 8px; background: transparent; font-size: 18px; cursor: pointer; }
.reaction-picker button:hover { background: var(--accent-soft); transform: scale(1.08); }
