/* =========================================
   CHAT SCREEN
   ========================================= */

.chat-screen {
  display: flex;

  justify-content: center;
}

.chat-container {
  position: relative;

  width: min(900px, 100%);

  height: min(820px, calc(100vh - 48px));

  display: flex;
  flex-direction: column;

  background: var(--surface);

  border: 1px solid var(--border);

  border-radius: 20px;

  box-shadow: var(--shadow);

  overflow: hidden;
}


/* =========================================
   HEADER
   ========================================= */

.chat-header {
  display: flex;

  align-items: center;

  justify-content: space-between;

  gap: 16px;

  padding: 18px 22px;

  border-bottom: 1px solid var(--border);
}

.chat-title h1 {
  margin: 0;

  font-size: 1.05rem;

  font-weight: 650;

  letter-spacing: -0.015em;
}

.chat-meta {
  display: flex;

  align-items: center;

  gap: 12px;

  margin-top: 5px;

  color: var(--text-soft);

  font-size: 0.73rem;
}

.online-status {
  display: flex;

  align-items: center;

  gap: 5px;
}

.status-dot {
  width: 7px;
  height: 7px;

  border-radius: 50%;

  background: #bdbdbd;
}

.status-dot.online {
  background: #83bf9d;
}

.message-count {
  opacity: 0.75;
}


/* =========================================
   SETTINGS BUTTON
   ========================================= */

.icon-button {
  width: 36px;
  height: 36px;

  display: flex;

  align-items: center;
  justify-content: center;

  padding: 0;

  border: none;

  border-radius: 50%;

  background: transparent;

  color: var(--text-soft);

  font-size: 1.1rem;

  transition:
    background var(--transition),
    color var(--transition),
    transform var(--transition);
}

.icon-button:hover {
  background: var(--accent-soft);

  color: var(--accent-strong);

  transform: rotate(20deg);
}


/* =========================================
   MESSAGES
   ========================================= */

.messages {
  flex: 1;

  overflow-y: auto;

  padding: 22px;

  display: flex;

  flex-direction: column;

  gap: 7px;

  scrollbar-width: thin;
}

.message {
  position: relative;

  max-width: 75%;

  align-self: flex-start;
}

.message.own {
  align-self: flex-end;
}

.message-author {
  margin: 0 0 3px 7px;

  color: var(--text-soft);

  font-size: 0.7rem;
}

.message-bubble {
  padding: 9px 12px;

  border-radius: 14px;

  background: var(--surface-soft);

  color: var(--text);

  line-height: 1.4;

  word-break: break-word;
}

.message.own .message-bubble {
  background: var(--accent-soft);
}


/* =========================================
   MESSAGE TIME
   ========================================= */

.message-time {
  margin-top: 3px;

  padding: 0 6px;

  color: var(--text-soft);

  font-size: 0.62rem;

  opacity: 0;

  transition: opacity var(--transition);
}

.message:hover .message-time {
  opacity: 0.7;
}


/* =========================================
   MESSAGE CONTROLS
   ========================================= */

.message-controls {
  position: absolute;

  right: 0;

  top: -28px;

  display: flex;

  gap: 3px;

  padding: 3px;

  border: 1px solid var(--border);

  border-radius: 8px;

  background: var(--surface);

  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.06);

  opacity: 0;

  pointer-events: none;

  transition: opacity var(--transition);
}

.message:hover .message-controls,
.message:focus-within .message-controls {
  opacity: 1;

  pointer-events: auto;
}

.message-action {
  padding: 4px 6px;

  border: none;

  border-radius: 5px;

  background: transparent;

  color: var(--text-soft);

  font-size: 0.68rem;
}

.message-action:hover {
  background: var(--accent-soft);

  color: var(--text);
}


/* =========================================
   REPLIES
   ========================================= */

.message-reply-preview {
  display: flex;

  flex-direction: column;

  width: 100%;

  margin-bottom: 4px;

  padding: 6px 9px;

  border: none;

  border-left: 3px solid var(--accent);

  border-radius: 6px;

  background: var(--accent-soft);

  color: var(--text-soft);

  text-align: left;

  cursor: pointer;
}

.reply-name {
  font-size: 0.68rem;

  font-weight: 650;

  color: var(--accent-strong);
}

.reply-content {
  margin-top: 2px;

  overflow: hidden;

  text-overflow: ellipsis;

  white-space: nowrap;

  font-size: 0.7rem;
}


/* =========================================
   EDITED / DELETED
   ========================================= */

.edited-label {
  color: var(--text-soft);

  font-size: 0.62rem;

  font-style: italic;
}

.deleted-message {
  color: var(--text-soft) !important;

  background: var(--surface-soft) !important;

  font-style: italic;
}


/* =========================================
   EDIT INPUT
   ========================================= */

.message-edit-input {
  width: 100%;

  padding: 9px 12px;

  border: 1px solid var(--accent);

  border-radius: 12px;

  outline: none;

  background: var(--surface);

  color: var(--text);
}


/* =========================================
   TYPING INDICATOR
   ========================================= */

.typing-indicator {
  min-height: 24px;

  padding: 0 22px 6px;

  color: var(--text-soft);

  font-size: 0.7rem;
}


/* =========================================
   MESSAGE FORM
   ========================================= */

.message-form {
  display: flex;

  gap: 8px;

  padding: 14px 18px;

  border-top: 1px solid var(--border);
}

.message-form input {
  flex: 1;

  min-width: 0;

  padding: 10px 13px;

  border: 1px solid var(--border);

  border-radius: 12px;

  outline: none;

  background: var(--surface);

  color: var(--text);

  transition:
    border var(--transition),
    box-shadow var(--transition);
}

.message-form input:focus {
  border-color: var(--accent);

  box-shadow:
    0 0 0 3px var(--accent-soft);
}

.message-form button {
  width: 42px;

  border: none;

  border-radius: 12px;

  background: var(--accent);

  color: white;

  font-size: 1rem;

  transition:
    background var(--transition),
    transform var(--transition);
}

.message-form button:hover {
  background: var(--accent-strong);
}

.message-form button:active {
  transform: scale(0.95);
}


/* =========================================
   DELETE CONFIRMATION
   ========================================= */

.delete-modal {
  position: fixed;

  inset: 0;

  z-index: 1000;

  display: flex;

  align-items: center;
  justify-content: center;

  padding: 20px;

  background: rgba(0, 0, 0, 0.18);

  opacity: 0;

  pointer-events: none;

  transition: opacity var(--transition);
}

.delete-modal.visible {
  opacity: 1;

  pointer-events: auto;
}

.delete-modal-box {
  width: min(360px, 100%);

  padding: 22px;

  border-radius: 18px;

  background: var(--surface);

  color: var(--text);

  box-shadow: var(--shadow);
}

.delete-modal-title {
  font-weight: 650;
}

.delete-modal-text {
  margin-top: 6px;

  color: var(--text-soft);

  font-size: 0.85rem;
}

.delete-modal-actions {
  display: flex;

  justify-content: flex-end;

  gap: 8px;

  margin-top: 20px;
}

.delete-modal-actions button {
  padding: 8px 13px;

  border: none;

  border-radius: 9px;

  cursor: pointer;
}

.delete-modal-cancel {
  background: var(--surface-soft);

  color: var(--text);
}

.delete-modal-confirm {
  background: var(--danger);

  color: white;
}


/* =========================================
   MOBILE
   ========================================= */

@media (max-width: 600px) {
  .chat-container {
    height: 100vh;

    border-radius: 0;

    border-left: none;
    border-right: none;
  }

  .chat-header {
    padding: 15px;
  }

  .messages {
    padding: 15px;
  }

  .message {
    max-width: 85%;
  }

  .message-controls {
    position: static;

    margin-top: 4px;

    width: fit-content;

    opacity: 1;

    pointer-events: auto;

    box-shadow: none;
  }

  .message-form {
    padding: 10px;
  }
}

/* ==============================
   DELETE CONFIRMATION MODAL
   ============================== */

.modal {
  position: fixed;
  inset: 0;

  display: flex;
  align-items: center;
  justify-content: center;

  z-index: 1000;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;

  background: rgba(0, 0, 0, 0.45);

  backdrop-filter: blur(4px);
}

.modal-card {
  position: relative;
  z-index: 1;

  width: min(
    420px,
    calc(100% - 32px)
  );

  padding: 24px;

  border-radius: 16px;

  background: var(--surface);
  color: var(--text);

  border: 1px solid var(--border);

  box-shadow:
    0 20px 60px rgba(0, 0, 0, 0.25);
}

.modal-card h2 {
  margin: 0 0 8px;

  font-size: 1.25rem;
}

.modal-card p {
  margin: 0;

  color: var(--text-secondary);
  line-height: 1.5;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;

  margin-top: 24px;
}

.modal-button {
  padding: 9px 16px;

  border: 1px solid var(--border);
  border-radius: 8px;

  background: var(--surface);
  color: var(--text);

  cursor: pointer;

  font: inherit;

  transition:
    background 0.15s ease,
    transform 0.15s ease;
}

.modal-button:hover {
  background: var(--surface-hover);
}

.modal-button:active {
  transform: scale(0.97);
}

.modal-button.danger {
  background: var(--danger);
  color: white;

  border-color: var(--danger);
}

.modal-button.danger:hover {
  filter: brightness(0.92);
}

.unread-indicator {
  position: absolute;

  left: 50%;
  bottom: 80px;

  transform: translateX(-50%);

  z-index: 20;

  border: none;
  border-radius: 999px;

  padding: 8px 14px;

  font-size: 13px;
  font-weight: 600;

  cursor: pointer;

  background: var(--accent);
  color: var(--accent-contrast);

  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);

  transition:
    transform 0.15s ease,
    opacity 0.15s ease;
}

.unread-indicator:hover {
  transform: translateX(-50%) translateY(-2px);
}

.unread-indicator.hidden {
  display: none;
}

.date-separator {
  display: flex;

  align-items: center;

  gap: 10px;

  margin: 18px 0 12px;

  color: var(--text-muted);

  font-size: 12px;

  font-weight: 600;

  user-select: none;
}

.date-separator span:first-child,
.date-separator span:last-child {
  flex: 1;

  height: 1px;

  background: var(--border);
}

.date-separator span:nth-child(2) {
  white-space: nowrap;
}

.chat-header-actions {
  display: flex;

  align-items: center;

  gap: 8px;

  flex-shrink: 0;
}

.message-search {
  display: flex;

  align-items: center;

  width: 220px;

  height: 38px;

  padding: 0 10px;

  gap: 7px;

  background: var(--surface-alt);

  border: 1px solid var(--border);

  border-radius: 10px;

  overflow: hidden;

  white-space: nowrap;
}

.message-search:focus-within {
  border-color: var(--accent);

  box-shadow:
    0 0 0 2px
    color-mix(
      in srgb,
      var(--accent) 15%,
      transparent
    );
}

.message-search-icon {
  flex-shrink: 0;

  font-size: 14px;

  opacity: 0.65;
}

#message-search-input {
  width: 100%;

  min-width: 0;

  border: none;

  outline: none;

  background: transparent;

  color: var(--text);

  font: inherit;

  font-size: 12px;
}

#message-search-input::placeholder {
  color: var(--text-muted);
}

.message-search-match {
  outline: 1px solid
    color-mix(
      in srgb,
      var(--accent) 35%,
      transparent
    );

  outline-offset: 2px;

  border-radius: 10px;
}

.message-search-current {
  outline: 3px solid var(--accent);

  outline-offset: 4px;

  border-radius: 12px;

  box-shadow:
    0 0 0 4px
    color-mix(
      in srgb,
      var(--accent) 25%,
      transparent
    );

  transition:
    outline-color 0.15s ease,
    box-shadow 0.15s ease;
}

.message-search-count {
  flex-shrink: 0;

  white-space: nowrap;

  color: var(--text-muted);

  font-size: 10px;

  font-weight: 600;

  opacity: 0.8;
}

/*
 * Hide the browser's default search clear button.
 */
#message-search-input::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
}


/*
 * Custom search clear button.
 */
.message-search-clear {
  display: none;

  flex-shrink: 0;

  width: 24px;
  height: 24px;

  padding: 0;

  border: none;
  border-radius: 7px;

  background: transparent;

  color: var(--text-muted);

  font-size: 20px;
  line-height: 24px;

  cursor: pointer;

  align-items: center;
  justify-content: center;
}

.message-search-clear {
  transform: translateY(-2px);
}

.message-search-clear:hover {
  background: var(--surface-hover);

  color: var(--text);
}

.message-search-clear.visible {
  display: flex;
}