/* ========================================
   MATERIAL DESIGN 3 - CHAT AREA STYLES
   Abie Messenger
   ======================================== */

/* ========================================
   CHAT AREA CONTAINER
   ======================================== */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--md-sys-color-surface);
  min-width: 0;
}

/* ========================================
   CHAT HEADER (Top App Bar)
   ======================================== */
.chat-header {
  padding: 12px 24px;
  background: var(--md-sys-color-surface);
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

.chat-header-avatar {
  width: 48px;
  height: 48px;
  border-radius: var(--md-sys-shape-corner-full);
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--md-sys-typescale-title-medium-font-family);
  font-size: 18px;
  font-weight: var(--md-sys-typescale-title-medium-font-weight);
  flex-shrink: 0;
  cursor: pointer;
  overflow: hidden;
  transition: transform var(--md-sys-motion-duration-short3) var(--md-sys-motion-easing-standard);
}

.chat-header-avatar:hover {
  transform: scale(1.05);
}

.chat-header-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.chat-header-avatar.has-image {
  background: transparent;
}

.chat-header-info {
  cursor: pointer;
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.chat-header-info h2 {
  font-family: var(--md-sys-typescale-title-large-font-family);
  font-size: var(--md-sys-typescale-title-large-font-size);
  font-weight: 500;
  line-height: 1.2;
  color: var(--md-sys-color-on-surface);
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-subtitle {
  font-family: var(--md-sys-typescale-body-small-font-family);
  font-size: var(--md-sys-typescale-body-small-font-size);
  color: var(--md-sys-color-on-surface-variant);
  margin-top: 0;
  line-height: 1.3;
}

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

.chat-info-btn,
.chat-search-btn {
  width: 48px;
  height: 48px;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: var(--md-sys-shape-corner-full);
  font-size: 20px;
  color: var(--md-sys-color-on-surface-variant);
  cursor: pointer;
  transition: background var(--md-sys-motion-duration-short3) var(--md-sys-motion-easing-standard);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.chat-info-btn::before,
.chat-search-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--md-sys-color-on-surface);
  opacity: 0;
  border-radius: inherit;
  transition: opacity var(--md-sys-motion-duration-short3) var(--md-sys-motion-easing-standard);
}

.chat-info-btn:hover::before,
.chat-search-btn:hover::before {
  opacity: var(--md-sys-state-hover-opacity);
}

/* ========================================
   MESSAGES CONTAINER
   ======================================== */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px 24px;
  background: var(--md-sys-color-surface-container-lowest);
}

/* ========================================
   TYPING INDICATOR
   ======================================== */
.typing-indicator {
  padding: 8px 24px;
  background: var(--md-sys-color-surface-container-lowest);
  color: var(--md-sys-color-primary);
  font-family: var(--md-sys-typescale-body-small-font-family);
  font-size: var(--md-sys-typescale-body-small-font-size);
  font-style: italic;
}

.typing-indicator span {
  font-weight: 500;
}

/* ========================================
   MESSAGE ITEM
   ======================================== */
.message {
  margin-bottom: 16px;
  animation: md-slide-in-bottom var(--md-sys-motion-duration-medium2) var(--md-sys-motion-easing-emphasized-decelerate);
  position: relative;
}

/* ========================================
   MESSAGE HEADER
   ======================================== */
.message-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}

.message-username {
  font-family: var(--md-sys-typescale-title-small-font-family);
  font-size: var(--md-sys-typescale-title-small-font-size);
  font-weight: var(--md-sys-typescale-title-small-font-weight);
  color: var(--md-sys-color-primary);
  cursor: pointer;
  transition: color var(--md-sys-motion-duration-short3) var(--md-sys-motion-easing-standard);
}

.message-username:hover {
  color: var(--md-sys-color-tertiary);
  text-decoration: underline;
}

.message-username.deleted {
  color: var(--md-sys-color-on-surface-variant);
  text-decoration: line-through;
}

.message-time {
  font-family: var(--md-sys-typescale-label-small-font-family);
  font-size: var(--md-sys-typescale-label-small-font-size);
  color: var(--md-sys-color-on-surface-variant);
}

/* ========================================
   MESSAGE BUBBLE (Text)
   ======================================== */
.message-text {
  background: var(--md-sys-color-surface-container-high);
  padding: 12px 16px;
  border-radius: var(--md-sys-shape-corner-large);
  display: inline-block;
  max-width: 70%;
  word-wrap: break-word;
  font-family: var(--md-sys-typescale-body-large-font-family);
  font-size: 16px; /* Увеличен с body-large (14px) */
  line-height: 1.5;
  color: var(--md-sys-color-on-surface);
  box-shadow: none;
}

/* Text inside bubble container - no max-width, it's on parent */
.message-bubble .message-text {
  max-width: none;
  display: block;
}

/* Own messages - Primary container style */
.message.own .message-username {
  color: var(--md-sys-color-tertiary);
}

.message.own .message-text {
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
}

/* ========================================
   SYSTEM MESSAGE
   ======================================== */
.system-message {
  text-align: center;
  color: var(--md-sys-color-on-surface-variant);
  font-family: var(--md-sys-typescale-body-small-font-family);
  font-size: var(--md-sys-typescale-body-small-font-size);
  margin: 16px 0;
  font-style: italic;
}

/* ========================================
   MESSAGE INPUT CONTAINER
   ======================================== */
.message-input-container {
  padding: 12px 24px 16px;
  background: var(--md-sys-color-surface);
  border-top: 1px solid var(--md-sys-color-outline-variant);
  display: flex;
  gap: 8px;
  align-items: center;
  position: relative;
}

/* ========================================
   ATTACH & EMOJI BUTTONS (Icon Buttons)
   ======================================== */
.attach-btn,
.emoji-btn {
  width: 48px;
  height: 48px;
  padding: 0;
  background: var(--md-sys-color-surface-container-high);
  border: none;
  border-radius: var(--md-sys-shape-corner-full);
  font-size: 20px;
  color: var(--md-sys-color-on-surface-variant);
  cursor: pointer;
  transition:
    background var(--md-sys-motion-duration-short3) var(--md-sys-motion-easing-standard),
    transform var(--md-sys-motion-duration-short3) var(--md-sys-motion-easing-standard);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.attach-btn:hover,
.emoji-btn:hover {
  background: var(--md-sys-color-surface-container-highest);
  transform: scale(1.05);
}

.attach-btn:active,
.emoji-btn:active {
  transform: scale(0.95);
}

/* ========================================
   INPUT WRAPPER
   ======================================== */
.input-wrapper {
  flex: 1;
  position: relative;
}

.char-counter {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  font-family: var(--md-sys-typescale-label-small-font-family);
  font-size: var(--md-sys-typescale-label-small-font-size);
  color: var(--md-sys-color-on-surface-variant);
  pointer-events: none;
}

#messageInput {
  width: 100%;
  padding: 14px 70px 14px 20px;
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--md-sys-shape-corner-full);
  font-family: var(--md-sys-typescale-body-large-font-family);
  font-size: var(--md-sys-typescale-body-large-font-size);
  color: var(--md-sys-color-on-surface);
  background: var(--md-sys-color-surface-container-highest);
  transition:
    border-color var(--md-sys-motion-duration-short3) var(--md-sys-motion-easing-standard),
    background var(--md-sys-motion-duration-short3) var(--md-sys-motion-easing-standard);
}

#messageInput::placeholder {
  color: var(--md-sys-color-on-surface-variant);
}

#messageInput:hover {
  background: var(--md-sys-color-surface-container-high);
}

#messageInput:focus {
  outline: none;
  border-color: var(--md-sys-color-primary);
  border-width: 2px;
  padding: 13px 69px 13px 19px;
  background: var(--md-sys-color-surface-container-lowest);
}

/* ========================================
   SEND BUTTON (FAB Style)
   ======================================== */
#sendBtn {
  width: 56px;
  height: 56px;
  padding: 0;
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  border: none;
  border-radius: var(--md-sys-shape-corner-large);
  font-size: 20px;
  cursor: pointer;
  transition:
    box-shadow var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-standard),
    transform var(--md-sys-motion-duration-short3) var(--md-sys-motion-easing-standard);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: var(--md-sys-elevation-level2);
  position: relative;
  overflow: hidden;
}

#sendBtn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: currentColor;
  opacity: 0;
  transition: opacity var(--md-sys-motion-duration-short3) var(--md-sys-motion-easing-standard);
}

#sendBtn:hover {
  box-shadow: var(--md-sys-elevation-level3);
}

#sendBtn:hover::before {
  opacity: var(--md-sys-state-hover-opacity);
}

#sendBtn:active {
  transform: scale(0.95);
}

/* ========================================
   EMOJI PICKER
   ======================================== */
.emoji-picker {
  position: fixed;
  background: var(--md-sys-color-surface-container-high);
  border: none;
  border-radius: var(--md-sys-shape-corner-extra-large);
  box-shadow: var(--md-sys-elevation-level3);
  padding: 12px;
  z-index: 200;
  transform-origin: bottom left;
  animation: md-scale-in var(--md-sys-motion-duration-medium2) var(--md-sys-motion-easing-emphasized-decelerate);
  width: 340px;
  max-width: calc(100vw - 24px);
  overflow: hidden;
}

/* Emoji Search */
.emoji-search-container {
  margin-bottom: 8px;
}

.emoji-search {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-full);
  font-family: var(--md-sys-typescale-body-medium-font-family);
  font-size: var(--md-sys-typescale-body-medium-font-size);
  color: var(--md-sys-color-on-surface);
  background: var(--md-sys-color-surface-container-lowest);
  transition: border-color var(--md-sys-motion-duration-short3) var(--md-sys-motion-easing-standard);
}

.emoji-search:focus {
  outline: none;
  border-color: var(--md-sys-color-primary);
}

.emoji-search::placeholder {
  color: var(--md-sys-color-on-surface-variant);
}

/* Emoji Tabs */
.emoji-tabs {
  display: flex;
  gap: 2px;
  padding: 4px;
  background: var(--md-sys-color-surface-container);
  border-radius: var(--md-sys-shape-corner-medium);
  margin-bottom: 8px;
  overflow: hidden;
}

.emoji-tab {
  flex: 1;
  min-width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  background: transparent;
  border-radius: var(--md-sys-shape-corner-small);
  font-size: 18px;
  cursor: pointer;
  transition:
    background var(--md-sys-motion-duration-short3) var(--md-sys-motion-easing-standard),
    transform var(--md-sys-motion-duration-short3) var(--md-sys-motion-easing-standard);
  display: flex;
  align-items: center;
  justify-content: center;
}

.emoji-tab:hover {
  background: var(--md-sys-color-surface-container-highest);
}

.emoji-tab.active {
  background: var(--md-sys-color-secondary-container);
}

.emoji-tab.hidden {
  display: none;
}

/* Emoji Grid */
.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  max-height: 240px;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 4px;
}

.emoji-item {
  font-size: 22px;
  padding: 6px;
  cursor: pointer;
  border-radius: var(--md-sys-shape-corner-medium);
  text-align: center;
  transition:
    background var(--md-sys-motion-duration-short3) var(--md-sys-motion-easing-standard),
    transform var(--md-sys-motion-duration-short3) var(--md-sys-motion-easing-standard);
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.emoji-item:hover {
  background: var(--md-sys-color-surface-container-highest);
  transform: scale(1.15);
}

.emoji-item:active {
  transform: scale(0.95);
}

.emoji-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 24px;
  color: var(--md-sys-color-on-surface-variant);
  font-family: var(--md-sys-typescale-body-medium-font-family);
  font-size: var(--md-sys-typescale-body-medium-font-size);
}

/* ========================================
   IMAGE PREVIEW (Full Screen Dialog)
   ======================================== */
.image-preview {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: var(--z-index-modal);
  animation: md-fade-in var(--md-sys-motion-duration-medium2) var(--md-sys-motion-easing-standard);
}

.preview-container {
  background: var(--md-sys-color-surface-container-high);
  padding: 24px;
  border-radius: var(--md-sys-shape-corner-extra-large);
  max-width: 80%;
  max-height: 80%;
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: md-scale-in var(--md-sys-motion-duration-medium2) var(--md-sys-motion-easing-emphasized-decelerate);
}

#previewImg {
  max-width: 100%;
  max-height: 60vh;
  object-fit: contain;
  border-radius: var(--md-sys-shape-corner-medium);
}

.preview-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.preview-actions button {
  padding: 12px 24px;
  border: none;
  border-radius: var(--md-sys-shape-corner-full);
  font-family: var(--md-sys-typescale-label-large-font-family);
  font-size: var(--md-sys-typescale-label-large-font-size);
  font-weight: var(--md-sys-typescale-label-large-font-weight);
  cursor: pointer;
  transition:
    background var(--md-sys-motion-duration-short3) var(--md-sys-motion-easing-standard),
    box-shadow var(--md-sys-motion-duration-short3) var(--md-sys-motion-easing-standard);
}

#sendImageBtn {
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
}

#sendImageBtn:hover {
  box-shadow: var(--md-sys-elevation-level1);
}

#cancelImageBtn {
  background: var(--md-sys-color-surface-container-highest);
  color: var(--md-sys-color-on-surface);
}

#cancelImageBtn:hover {
  background: var(--md-sys-color-surface-container-high);
}

/* ========================================
   IMAGE VIEWER OVERLAY
   ======================================== */
.image-viewer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.95);
  display: flex;
  flex-direction: column;
  z-index: 2000;
  animation: md-fade-in var(--md-sys-motion-duration-medium2) var(--md-sys-motion-easing-standard);
}

.image-viewer-header {
  display: flex;
  align-items: center;
  padding: 16px 20px;
  background: rgba(0, 0, 0, 0.5);
}

.image-viewer-back {
  background: transparent;
  border: none;
  color: white;
  font-size: 24px;
  cursor: pointer;
  padding: 12px;
  border-radius: var(--md-sys-shape-corner-full);
  transition: background var(--md-sys-motion-duration-short3) var(--md-sys-motion-easing-standard);
}

.image-viewer-back:hover {
  background: rgba(255, 255, 255, 0.1);
}

.image-viewer-content {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 16px;
  overflow: hidden;
}

.image-viewer-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}

.message-image {
  max-width: 300px;
  max-height: 300px;
  border-radius: var(--md-sys-shape-corner-medium);
  cursor: pointer;
  margin-top: 8px;
  transition: transform var(--md-sys-motion-duration-short3) var(--md-sys-motion-easing-standard);
}

.message-image:hover {
  transform: scale(1.02);
}

/* Image inside bubble (with reply) */
.message-bubble-image {
  display: inline-block;
  border-radius: var(--md-sys-shape-corner-large);
  overflow: hidden;
  background: var(--md-sys-color-surface-container);
}

.message-bubble-image .message-image {
  margin-top: 0;
  border-radius: 0;
  display: block;
}

.message-bubble-image.has-reply .message-image {
  padding: 8px;
}

/* Lazy loading images */
.message-image.lazy-image {
  background: var(--md-sys-color-surface-container-high);
  min-height: 100px;
  min-width: 100px;
}

.message-image.lazy-image[data-src] {
  opacity: 0;
  transition: opacity 0.3s ease;
}

.message-image.lazy-image:not([data-src]) {
  opacity: 1;
}

/* ========================================
   MESSAGE MENU BUTTON
   ======================================== */
.message-menu-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  background: var(--md-sys-color-surface-container-high);
  border: none;
  border-radius: var(--md-sys-shape-corner-full);
  width: 28px;
  height: 28px;
  font-size: 14px;
  cursor: pointer;
  opacity: 0;
  transition:
    opacity var(--md-sys-motion-duration-short3) var(--md-sys-motion-easing-standard),
    background var(--md-sys-motion-duration-short3) var(--md-sys-motion-easing-standard);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--md-sys-color-on-surface-variant);
}

.message:hover .message-menu-btn {
  opacity: 1;
}

.message-menu-btn:hover {
  background: var(--md-sys-color-surface-container-highest);
}

/* ========================================
   SCROLL DOWN BUTTON
   ======================================== */
.scroll-down-btn {
  position: absolute;
  bottom: 90px;
  right: 24px;
  width: 48px;
  height: 48px;
  border-radius: var(--md-sys-shape-corner-full);
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--md-sys-elevation-level2);
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px) scale(0.8);
  transition:
    opacity var(--md-sys-motion-duration-medium2) var(--md-sys-motion-easing-emphasized),
    visibility var(--md-sys-motion-duration-medium2) var(--md-sys-motion-easing-emphasized),
    transform var(--md-sys-motion-duration-medium2) var(--md-sys-motion-easing-emphasized),
    background var(--md-sys-motion-duration-short3) var(--md-sys-motion-easing-standard);
  z-index: 100;
}

.scroll-down-btn.visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

.scroll-down-btn:hover {
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  box-shadow: var(--md-sys-elevation-level3);
}

.scroll-down-btn:active {
  transform: scale(0.95);
}

.scroll-down-btn svg {
  width: 24px;
  height: 24px;
}

/* ========================================
   CONTEXT MENU
   ======================================== */
.context-menu {
  position: fixed;
  background: var(--md-sys-color-surface-container-high);
  border: none;
  border-radius: var(--md-sys-shape-corner-medium);
  box-shadow: var(--md-sys-elevation-level3);
  padding: 8px 0;
  z-index: var(--z-index-modal);
  min-width: 180px;
  animation: md-scale-in var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-emphasized-decelerate);
}

.context-menu-item {
  padding: 12px 16px;
  cursor: pointer;
  font-family: var(--md-sys-typescale-body-medium-font-family);
  font-size: var(--md-sys-typescale-body-medium-font-size);
  color: var(--md-sys-color-on-surface);
  display: flex;
  align-items: center;
  gap: 12px;
  transition: background var(--md-sys-motion-duration-short3) var(--md-sys-motion-easing-standard);
}

.context-menu-item:hover {
  background: var(--md-sys-color-surface-container-highest);
}

.context-menu-item.danger {
  color: var(--md-sys-color-error);
}

.context-menu-item.danger:hover {
  background: var(--md-sys-color-error-container);
}

/* ========================================
   EDITING STATE
   ======================================== */
.message.editing {
  background: var(--md-sys-color-tertiary-container);
  padding: 12px;
  border-radius: var(--md-sys-shape-corner-medium);
}

.message-edit-input {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--md-sys-color-primary);
  border-radius: var(--md-sys-shape-corner-medium);
  font-family: var(--md-sys-typescale-body-large-font-family);
  font-size: var(--md-sys-typescale-body-large-font-size);
  color: var(--md-sys-color-on-surface);
  background: var(--md-sys-color-surface-container-lowest);
  resize: vertical;
  min-height: 60px;
}

.message-edit-input:focus {
  outline: none;
  border-color: var(--md-sys-color-tertiary);
}

.message-edit-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  justify-content: flex-end;
}

.btn-save-edit,
.btn-cancel-edit {
  padding: 10px 20px;
  border: none;
  border-radius: var(--md-sys-shape-corner-full);
  font-family: var(--md-sys-typescale-label-large-font-family);
  font-size: var(--md-sys-typescale-label-large-font-size);
  font-weight: var(--md-sys-typescale-label-large-font-weight);
  cursor: pointer;
  transition:
    background var(--md-sys-motion-duration-short3) var(--md-sys-motion-easing-standard),
    box-shadow var(--md-sys-motion-duration-short3) var(--md-sys-motion-easing-standard);
}

.btn-save-edit {
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
}

.btn-save-edit:hover {
  box-shadow: var(--md-sys-elevation-level1);
}

.btn-cancel-edit {
  background: var(--md-sys-color-surface-container-highest);
  color: var(--md-sys-color-on-surface);
}

.btn-cancel-edit:hover {
  background: var(--md-sys-color-surface-container-high);
}

/* ========================================
   MESSAGE EDITED BADGE
   ======================================== */
.message-edited-badge {
  font-family: var(--md-sys-typescale-label-small-font-family);
  font-size: var(--md-sys-typescale-label-small-font-size);
  color: var(--md-sys-color-on-surface-variant);
  font-style: italic;
  margin-left: 6px;
}

/* ========================================
   REPLY STYLES
   ======================================== */
.message-reply {
  background: var(--md-sys-color-surface-container-highest);
  border-left: 3px solid var(--md-sys-color-tertiary);
  padding: 8px 12px;
  margin-bottom: 8px;
  border-radius: var(--md-sys-shape-corner-small);
  font-family: var(--md-sys-typescale-body-small-font-family);
  font-size: var(--md-sys-typescale-body-small-font-size);
  cursor: pointer;
  transition: background var(--md-sys-motion-duration-short3) var(--md-sys-motion-easing-standard);
}

.message-reply:hover {
  filter: brightness(0.97);
}

.message-reply-author {
  font-weight: 500;
  color: var(--md-sys-color-tertiary);
  margin-bottom: 2px;
}

.message-reply-text {
  color: var(--md-sys-color-on-surface);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ========================================
   REPLY PANEL
   ======================================== */
.reply-panel {
  background: var(--md-sys-color-surface-container);
  border-top: 1px solid var(--md-sys-color-outline-variant);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.reply-panel-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.reply-panel-label {
  font-family: var(--md-sys-typescale-label-medium-font-family);
  font-size: var(--md-sys-typescale-label-medium-font-size);
  font-weight: var(--md-sys-typescale-label-medium-font-weight);
  color: var(--md-sys-color-primary);
}

.reply-panel-text {
  font-family: var(--md-sys-typescale-body-medium-font-family);
  font-size: var(--md-sys-typescale-body-medium-font-size);
  color: var(--md-sys-color-on-surface-variant);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reply-panel-close {
  background: transparent;
  border: none;
  color: var(--md-sys-color-on-surface-variant);
  font-size: 20px;
  cursor: pointer;
  padding: 8px;
  border-radius: var(--md-sys-shape-corner-full);
  transition: background var(--md-sys-motion-duration-short3) var(--md-sys-motion-easing-standard);
}

.reply-panel-close:hover {
  background: var(--md-sys-color-surface-container-highest);
}

/* ========================================
   SEARCH PANEL
   ======================================== */
.search-panel {
  background: var(--md-sys-color-surface-container);
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  padding: 12px 24px;
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  box-shadow: var(--md-sys-elevation-level1);
}

.search-input-wrapper {
  flex: 1;
  position: relative;
  min-width: 200px;
}

.search-input {
  width: 100%;
  padding: 12px 40px 12px 16px;
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--md-sys-shape-corner-full);
  font-family: var(--md-sys-typescale-body-large-font-family);
  font-size: var(--md-sys-typescale-body-large-font-size);
  color: var(--md-sys-color-on-surface);
  background: var(--md-sys-color-surface-container-lowest);
  transition: border-color var(--md-sys-motion-duration-short3) var(--md-sys-motion-easing-standard);
}

.search-input:focus {
  outline: none;
  border-color: var(--md-sys-color-primary);
  border-width: 2px;
  padding: 11px 39px 11px 15px;
}

.search-clear-btn {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  color: var(--md-sys-color-on-surface-variant);
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
  border-radius: var(--md-sys-shape-corner-full);
}

.search-clear-btn:hover {
  color: var(--md-sys-color-on-surface);
}

.search-close-btn {
  background: var(--md-sys-color-surface-container-highest);
  border: none;
  border-radius: var(--md-sys-shape-corner-full);
  width: 40px;
  height: 40px;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--md-sys-color-on-surface-variant);
  transition: background var(--md-sys-motion-duration-short3) var(--md-sys-motion-easing-standard);
}

.search-close-btn:hover {
  background: var(--md-sys-color-surface-container-high);
}

.search-results-count {
  font-family: var(--md-sys-typescale-label-medium-font-family);
  font-size: var(--md-sys-typescale-label-medium-font-size);
  color: var(--md-sys-color-on-surface-variant);
  white-space: nowrap;
  min-width: 60px;
  text-align: center;
}

/* ========================================
   SEARCH NAVIGATION
   ======================================== */
.search-navigation {
  display: flex;
  align-items: center;
  gap: 4px;
}

.search-nav-btn {
  background: var(--md-sys-color-surface-container-highest);
  border: none;
  border-radius: var(--md-sys-shape-corner-small);
  width: 36px;
  height: 36px;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--md-sys-color-on-surface-variant);
  transition:
    background var(--md-sys-motion-duration-short3) var(--md-sys-motion-easing-standard),
    color var(--md-sys-motion-duration-short3) var(--md-sys-motion-easing-standard);
}

.search-nav-btn:hover:not(:disabled) {
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
}

.search-nav-btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

/* ========================================
   SEARCH MODE TOGGLE
   ======================================== */
.search-mode-toggle {
  display: flex;
  gap: 4px;
}

.search-mode-btn {
  padding: 8px 16px;
  background: var(--md-sys-color-surface-container-highest);
  border: none;
  border-radius: var(--md-sys-shape-corner-full);
  font-family: var(--md-sys-typescale-label-large-font-family);
  font-size: var(--md-sys-typescale-label-large-font-size);
  font-weight: var(--md-sys-typescale-label-large-font-weight);
  cursor: pointer;
  transition:
    background var(--md-sys-motion-duration-short3) var(--md-sys-motion-easing-standard),
    color var(--md-sys-motion-duration-short3) var(--md-sys-motion-easing-standard);
  color: var(--md-sys-color-on-surface-variant);
}

.search-mode-btn:hover {
  background: var(--md-sys-color-surface-container-high);
}

.search-mode-btn.active {
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}

/* ========================================
   GLOBAL SEARCH RESULTS
   ======================================== */
.search-global-results {
  width: 100%;
  max-height: 400px;
  overflow-y: auto;
  margin-top: 12px;
  border-top: 1px solid var(--md-sys-color-outline-variant);
  padding-top: 12px;
}

.search-global-results.hidden {
  display: none;
}

.search-global-item {
  padding: 12px 16px;
  border-radius: var(--md-sys-shape-corner-medium);
  cursor: pointer;
  transition:
    background var(--md-sys-motion-duration-short3) var(--md-sys-motion-easing-standard),
    transform var(--md-sys-motion-duration-short3) var(--md-sys-motion-easing-standard);
  margin-bottom: 8px;
  background: var(--md-sys-color-surface-container-lowest);
}

.search-global-item:hover {
  background: var(--md-sys-color-secondary-container);
  transform: translateX(4px);
}

.search-global-chat {
  font-family: var(--md-sys-typescale-label-medium-font-family);
  font-size: var(--md-sys-typescale-label-medium-font-size);
  color: var(--md-sys-color-primary);
  font-weight: 500;
  margin-bottom: 4px;
}

.search-global-message {
  font-family: var(--md-sys-typescale-body-medium-font-family);
  font-size: var(--md-sys-typescale-body-medium-font-size);
  color: var(--md-sys-color-on-surface);
  line-height: 1.4;
}

.search-global-author {
  font-weight: 500;
  color: var(--md-sys-color-on-surface);
}

.search-global-text {
  color: var(--md-sys-color-on-surface-variant);
}

.search-global-text mark {
  background: var(--md-sys-color-tertiary-container);
  color: var(--md-sys-color-on-tertiary-container);
  padding: 1px 4px;
  border-radius: var(--md-sys-shape-corner-extra-small);
}

.search-global-time {
  font-family: var(--md-sys-typescale-label-small-font-family);
  font-size: var(--md-sys-typescale-label-small-font-size);
  color: var(--md-sys-color-on-surface-variant);
  margin-top: 4px;
}

.search-no-results {
  text-align: center;
  color: var(--md-sys-color-on-surface-variant);
  padding: 24px;
  font-family: var(--md-sys-typescale-body-medium-font-family);
  font-size: var(--md-sys-typescale-body-medium-font-size);
}

.search-navigation.hidden {
  display: none;
}

/* Highlight text in search */
.message-text mark {
  background: var(--md-sys-color-tertiary-container);
  color: var(--md-sys-color-on-tertiary-container);
  padding: 2px 4px;
  border-radius: var(--md-sys-shape-corner-extra-small);
}

/* Current search result */
.message.search-current {
  background: var(--md-sys-color-tertiary-container) !important;
  box-shadow: 0 0 0 2px var(--md-sys-color-tertiary), var(--md-sys-elevation-level2);
  animation: md-pulse 0.5s var(--md-sys-motion-easing-standard);
  border-radius: var(--md-sys-shape-corner-medium);
  padding: 8px;
}

.message.search-current mark {
  background: var(--md-sys-color-tertiary);
  color: var(--md-sys-color-on-tertiary);
}

/* ========================================
   DELETE ANIMATION
   ======================================== */
@keyframes fadeOut {
  from {
    opacity: 1;
    transform: scale(1);
  }
  to {
    opacity: 0;
    transform: scale(0.9);
  }
}

.message.deleting {
  animation: fadeOut var(--md-sys-motion-duration-medium2) var(--md-sys-motion-easing-standard) forwards;
}

/* ========================================
   FORWARD MODAL
   ======================================== */
.forward-modal {
  position: fixed;
  inset: 0;
  background: var(--md-sys-color-scrim);
  background: rgba(0, 0, 0, 0.32);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: var(--z-index-modal);
  animation: md-fade-in var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-standard);
}

.forward-modal-content {
  background: var(--md-sys-color-surface-container-high);
  padding: 24px;
  border-radius: var(--md-sys-shape-corner-extra-large);
  width: 90%;
  max-width: 400px;
  animation: md-scale-in var(--md-sys-motion-duration-medium2) var(--md-sys-motion-easing-emphasized-decelerate);
}

.forward-modal h3 {
  margin: 0 0 16px 0;
  font-family: var(--md-sys-typescale-headline-small-font-family);
  font-size: var(--md-sys-typescale-headline-small-font-size);
  font-weight: 500;
  color: var(--md-sys-color-on-surface);
}

.forward-chat-list {
  max-height: 300px;
  overflow-y: auto;
  margin-bottom: 16px;
}

.forward-chat-item {
  padding: 12px 16px;
  border: 2px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-medium);
  margin-bottom: 8px;
  cursor: pointer;
  transition:
    border-color var(--md-sys-motion-duration-short3) var(--md-sys-motion-easing-standard),
    background var(--md-sys-motion-duration-short3) var(--md-sys-motion-easing-standard);
  font-family: var(--md-sys-typescale-body-large-font-family);
  font-size: var(--md-sys-typescale-body-large-font-size);
  color: var(--md-sys-color-on-surface);
}

.forward-chat-item:hover {
  border-color: var(--md-sys-color-primary);
  background: var(--md-sys-color-primary-container);
}

.forward-chat-item.selected {
  border-color: var(--md-sys-color-primary);
  background: var(--md-sys-color-secondary-container);
}
