/**
 * 對話功能模組 - 樣式
 * Macy 課程系統 Phase 2
 */

/* ============================================
   通用樣式
   ============================================ */

/* 導航未讀標記 */
.nav-unread-badge {
  position: absolute;
  top: 0.5rem;
  right: 0.25rem;
  background: var(--danger);
  color: white;
  font-size: 0.625rem;
  font-weight: 700;
  padding: 0.125rem 0.375rem;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}

.nav-item {
  position: relative;
}

/* ============================================
   學員端 - 對話列表
   ============================================ */

.thread-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.thread-card {
  background: var(--card);
  border-radius: 12px;
  padding: 1.25rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
  cursor: pointer;
  transition: all 0.3s;
  border: 2px solid transparent;
}

.thread-card:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  transform: translateY(-2px);
}

.thread-card.unread {
  border-color: var(--primary);
  background: linear-gradient(135deg, #fff 0%, #fff8f5 100%);
}

.thread-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.thread-status-icon {
  font-size: 1.25rem;
}

.thread-subject {
  flex: 1;
  font-weight: 600;
  font-size: 1.0625rem;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thread-time {
  font-size: 0.8125rem;
  color: var(--text-light);
}

.thread-preview {
  color: var(--text-light);
  font-size: 0.9375rem;
  margin-bottom: 0.75rem;
  line-height: 1.5;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.thread-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8125rem;
}

.thread-last-by {
  color: var(--text-light);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.unread-badge {
  background: var(--danger);
  color: white;
  font-size: 0.6875rem;
  font-weight: 700;
  padding: 0.125rem 0.5rem;
  border-radius: 10px;
}

.thread-status-text {
  padding: 0.25rem 0.625rem;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 500;
}

.thread-status-text.open {
  background: #e9ecef;
  color: #6c757d;
}

.thread-status-text.resolved {
  background: #d4edda;
  color: #155724;
}

.thread-status-text.closed {
  background: #f8f9fa;
  color: #6c757d;
}

/* ============================================
   新對話彈窗
   ============================================ */

#newThreadModal .modal {
  max-width: 600px;
}

.new-thread-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.priority-selector {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.priority-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  border: 2px solid var(--border);
  transition: all 0.2s;
}

.priority-option:hover {
  border-color: var(--primary);
}

.priority-option input[type="radio"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

.priority-option.selected {
  border-color: var(--primary);
  background: #fff8f5;
}

/* ============================================
   對話詳情（聊天界面）
   ============================================ */

.thread-detail-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.thread-detail-title {
  flex: 1;
  font-size: 1.25rem;
  font-weight: 600;
}

.thread-detail-status {
  padding: 0.375rem 0.875rem;
  border-radius: 20px;
  font-size: 0.8125rem;
  font-weight: 500;
}

.thread-detail-status.open {
  background: #e9ecef;
  color: #6c757d;
}

.thread-detail-status.resolved {
  background: #d4edda;
  color: #155724;
}

.thread-detail-status.closed {
  background: #f8f9fa;
  color: #6c757d;
}

/* 消息列表 */
.thread-messages {
  min-height: 300px;
  max-height: calc(100vh - 400px);
  overflow-y: auto;
  padding: 1rem;
  background: #f8f9fa;
  border-radius: 12px;
  margin-bottom: 1rem;
}

.date-divider {
  text-align: center;
  margin: 1.5rem 0;
  position: relative;
}

.date-divider::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--border);
}

.date-divider span {
  background: #f8f9fa;
  padding: 0 1rem;
  color: var(--text-light);
  font-size: 0.8125rem;
  position: relative;
}

/* 消息氣泡 */
.message {
  margin-bottom: 1rem;
  max-width: 75%;
}

.message.student-bubble {
  margin-left: auto;
}

.message.macy-bubble {
  margin-right: auto;
}

.message-content {
  padding: 0.875rem 1.125rem;
  border-radius: 16px;
  font-size: 0.9375rem;
  line-height: 1.6;
  word-wrap: break-word;
}

.student-bubble .message-content {
  background: white;
  border: 1px solid var(--border);
  border-bottom-right-radius: 4px;
}

.macy-bubble .message-content {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
  border-bottom-left-radius: 4px;
}

.message-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.375rem;
  font-size: 0.75rem;
  color: var(--text-light);
}

.macy-bubble .message-meta {
  justify-content: flex-end;
}

.message-meta .sender {
  font-weight: 500;
}

/* 附件 */
.attachment {
  margin-top: 0.75rem;
}

.attachment.image img {
  max-width: 200px;
  max-height: 150px;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.2s;
}

.attachment.image img:hover {
  transform: scale(1.02);
}

.attachment-name {
  font-size: 0.75rem;
  color: var(--text-light);
  margin-top: 0.25rem;
}

.attachment.file .file-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.875rem;
  background: rgba(255,255,255,0.9);
  border-radius: 8px;
  text-decoration: none;
  color: var(--text);
  font-size: 0.875rem;
  transition: background 0.2s;
}

.attachment.file .file-link:hover {
  background: white;
}

.macy-bubble .attachment.file .file-link {
  background: rgba(255,255,255,0.2);
  color: white;
}

/* 消息輸入區 */
.message-input-area {
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
  padding: 1rem;
  background: white;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.message-input-wrapper {
  flex: 1;
  position: relative;
}

.message-input {
  width: 100%;
  padding: 0.875rem 1rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 0.9375rem;
  resize: none;
  min-height: 48px;
  max-height: 120px;
  font-family: inherit;
}

.message-input:focus {
  outline: none;
  border-color: var(--primary);
}

.attach-btn {
  padding: 0.75rem;
  background: var(--bg);
  border: none;
  border-radius: 12px;
  cursor: pointer;
  font-size: 1.25rem;
  transition: all 0.2s;
}

.attach-btn:hover {
  background: var(--border);
}

.send-btn {
  padding: 0.75rem 1.5rem;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s;
}

.send-btn:hover {
  background: var(--primary-dark);
}

.send-btn:disabled {
  background: var(--border);
  cursor: not-allowed;
}

/* 過期提示 */
.file-expiry-notice {
  padding: 0.75rem 1rem;
  background: #fff3cd;
  border-left: 4px solid var(--warning);
  border-radius: 8px;
  font-size: 0.875rem;
  color: #856404;
  margin-bottom: 1rem;
}

/* ============================================
   響應式設計
   ============================================ */

@media (max-width: 768px) {
  .thread-card {
    padding: 1rem;
  }
  
  .thread-subject {
    font-size: 0.9375rem;
  }
  
  .thread-preview {
    font-size: 0.875rem;
  }
  
  .thread-messages {
    min-height: 250px;
    max-height: calc(100vh - 350px);
    padding: 0.75rem;
  }
  
  .message {
    max-width: 85%;
  }
  
  .message-content {
    padding: 0.75rem 0.875rem;
    font-size: 0.875rem;
  }
  
  .thread-detail-header {
    flex-wrap: wrap;
  }
  
  .thread-detail-title {
    width: 100%;
    order: -1;
    margin-bottom: 0.5rem;
  }
  
  .message-input-area {
    padding: 0.75rem;
  }
  
  .send-btn {
    padding: 0.75rem 1rem;
  }
}

@media (max-width: 480px) {
  .thread-header {
    flex-wrap: wrap;
  }
  
  .thread-time {
    width: 100%;
    margin-top: 0.25rem;
  }
  
  .thread-footer {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }
  
  .attachment.image img {
    max-width: 150px;
    max-height: 120px;
  }
}
