/**
 * Chat Panel Styles
 * Responsive chat panel for master and user views
 */

/* Chat Panel Container */
.chat-panel {
  position: fixed;
  bottom: 0;
  left: 50%;
  right: auto;
  width: min(460px, 94vw);
  max-width: 90vw;
  height: min(62vh, 560px);
  max-height: 560px;
  background: #fff;
  border: 1px solid #ddd;
  border-bottom: none;
  border-top-left-radius: 14px;
  border-top-right-radius: 14px;
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  z-index: 1000;
  transform: translateX(-50%);
  transition: transform 0.3s ease-out, width 0.3s ease-out;
}

.chat-panel.collapsed {
  width: fit-content;
  min-width: 0;
  max-height: 36px;
  height: 36px;
  box-shadow: 0 -4px 14px rgba(0, 0, 0, 0.14);
  border: 1px solid #ddd;
  border-bottom: none;
  border-top-left-radius: 12px;
  border-top-right-radius: 12px;
}

/* Chat Header & Toggle Button */
.chat-header {
  padding: 0;
  border-bottom: 1px solid #eee;
  background: #f9f9f9;
  border-top-left-radius: 14px;
  border-top-right-radius: 14px;
  overflow: hidden;
}

.chat-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  width: 100%;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: #333;
  text-align: center;
  transition: background-color 0.2s;
  position: relative;
  white-space: nowrap;
  justify-content: center;
}

.chat-toggle::after {
  content: "▼";
  font-size: 11px;
  margin-left: 2px;
  opacity: 0.85;
}

.chat-panel.collapsed .chat-toggle::after {
  content: "▲";
}

.chat-panel.collapsed .chat-header {
  border-bottom: none;
}

.chat-panel.collapsed .chat-toggle {
  width: auto;
  min-width: 120px;
  padding: 6px 10px;
  font-size: 11px;
  gap: 6px;
}

.chat-toggle:hover {
  background-color: #cbd5e1;
}

.chat-toggle .badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  background: #dc3545;
  color: white;
  border-radius: 8px;
  font-size: 10px;
  font-weight: bold;
  margin-left: 0;
}

.chat-toggle.unread-alert {
  animation: chat-heartbeat 1.2s ease-in-out infinite;
  transform-origin: center;
}

.chat-toggle.unread-alert .badge {
  box-shadow: 0 0 0 0 rgba(220, 53, 69, 0.55);
  animation: chat-badge-heartbeat 1.2s ease-in-out infinite;
}

@keyframes chat-heartbeat {
  0%,
  100% {
    transform: scale(1);
  }
  20% {
    transform: scale(1.04);
  }
  35% {
    transform: scale(1.08);
  }
  50% {
    transform: scale(1.03);
  }
}

@keyframes chat-badge-heartbeat {
  0%,
  100% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(220, 53, 69, 0.55);
  }
  35% {
    transform: scale(1.14);
    box-shadow: 0 0 0 6px rgba(220, 53, 69, 0);
  }
}

.chat-toggle .badge:empty::after {
  content: "0";
}

/* Pulse Animation */
.pulse {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  margin-left: 2px;
  opacity: 0;
  transition: opacity 0.2s;
}

.pulse.active {
  opacity: 1;
  background: #dc3545;
  animation: pulse-blink 1s infinite;
}

@keyframes pulse-blink {
  0%, 50% {
    opacity: 1;
    background: #dc3545;
  }
  51%, 100% {
    opacity: 0.3;
    background: #dc3545;
  }
}

/* Chat Wrapper (hidden when collapsed) */
.chat-panel.collapsed .chat-wrapper {
  display: none;
}

.chat-wrapper {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* Chat Body (Messages) */
.chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  background: #fff;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-guide-line {
  font-size: 11px;
  line-height: 1.35;
  color: #475569;
  background: #e2e8f0;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 6px 8px;
}

.chat-panel.dragover .chat-header,
.chat-panel.dragover .chat-input-area {
  background: #dbeafe;
}

.chat-panel.dragover .chat-body {
  border: 2px dashed #3b82f6;
  border-radius: 10px;
}

.chat-system-message {
  font-size: 12px;
  color: #334155;
  background: #f1f5f9;
}

.chat-file-link {
  color: #0f172a;
  text-decoration: underline;
  font-weight: 600;
}

.chat-body::-webkit-scrollbar {
  width: 6px;
}

.chat-body::-webkit-scrollbar-track {
  background: #f0f0f0;
}

.chat-body::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 3px;
}

.chat-body::-webkit-scrollbar-thumb:hover {
  background: #999;
}

/* Chat Message */
.chat-message {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px;
  background: #f5f5f5;
  border-radius: 6px;
  font-size: 13px;
  line-height: 1.4;
  word-break: break-word;
  position: relative;
  animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chat-message-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.chat-sender {
  font-weight: 600;
  color: #333;
  flex-shrink: 0;
}

.chat-sender.master {
  color: #0066cc;
  font-style: italic;
}

.chat-time {
  font-size: 11px;
  color: #999;
  flex-shrink: 0;
}

.chat-message-text {
  color: #333;
  white-space: pre-wrap;
  word-wrap: break-word;
  padding-right: 28px;
}

/* Delete Button */
.chat-message-delete {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  padding: 0;
  background: none;
  border: none;
  color: #ccc;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  transition: color 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-message-delete:hover {
  color: #dc3545;
}

/* Typing Indicator */
.chat-typing-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
  font-size: 12px;
  color: #999;
  font-style: italic;
  line-height: 1.25;
  min-height: 0;
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  border-top: 1px solid #eee;
  background: #f9f9f9;
  transition: max-height 0.2s ease-out, opacity 0.2s ease-out, padding 0.2s ease-out;
}

.chat-typing-indicator.visible {
  max-height: 36px;
  opacity: 1;
  padding: 8px 12px;
}

.chat-typing-indicator::before {
  content: "● ● ●";
  letter-spacing: 2px;
  flex-shrink: 0;
  animation: typing-dots 1.4s infinite;
}

@keyframes typing-dots {
  0%, 60%, 100% {
    opacity: 0.3;
  }
  30% {
    opacity: 1;
  }
}

/* Chat Input Area */
.chat-input-area {
  display: flex;
  gap: 6px;
  padding: 10px;
  border-top: 1px solid #eee;
  background: #f9f9f9;
  flex-shrink: 0;
}

.chat-input {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 13px;
  font-family: inherit;
  resize: none;
  outline: none;
  transition: border-color 0.2s;
}

.chat-input:focus {
  border-color: #0066cc;
  box-shadow: 0 0 0 2px rgba(0, 102, 204, 0.1);
}

.chat-input::placeholder {
  color: #ccc;
}

.chat-send-btn {
  padding: 8px 12px;
  background: #0066cc;
  color: white;
  border: none;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.2s;
  flex-shrink: 0;
  min-width: 60px;
}

.chat-send-btn:hover {
  background: #0052a3;
}

.chat-send-btn:active {
  background: #00408a;
}

/* Responsive Design */
@media (max-width: 768px) {
  .chat-panel {
    width: calc(100vw - 12px);
    max-width: 100vw;
    height: 100vh;
    max-height: 50vh;
    bottom: 0;
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    border-left: 1px solid #ddd;
    border-right: 1px solid #ddd;
    border-top: 1px solid #ddd;
  }

  .chat-panel.collapsed {
    max-height: 36px;
    width: fit-content;
  }

  .chat-toggle {
    width: auto;
  }

  .chat-body {
    padding: 10px;
  }

  .chat-message {
    font-size: 12px;
    padding: 6px;
  }

  .chat-message-text {
    padding-right: 24px;
  }

  .chat-input-area {
    padding: 8px;
    gap: 4px;
  }

  .chat-input {
    font-size: 12px;
    padding: 6px 8px;
  }

  .chat-send-btn {
    padding: 6px 10px;
    font-size: 11px;
    min-width: 50px;
  }
}

/* Mobile - very small screens */
@media (max-width: 480px) {
  .chat-panel {
    max-height: 40vh;
  }

  .chat-panel.collapsed {
    max-height: 45px;
  }

  .chat-body {
    padding: 8px;
  }

  .chat-message {
    padding: 5px;
    gap: 1px;
  }

  .chat-sender {
    font-size: 12px;
  }

  .chat-time {
    font-size: 10px;
  }

  .chat-message-text {
    font-size: 12px;
  }
}

/* Dark mode support (optional) */
@media (prefers-color-scheme: dark) {
  .chat-panel {
    background: #2a2a2a;
    border-color: #444;
    color: #e0e0e0;
  }

  .chat-toggle {
    color: #e0e0e0;
    background: none;
  }

  .chat-toggle:hover {
    background-color: #334155;
  }

  .chat-header {
    border-bottom-color: #444;
    background: #333;
  }

  .chat-body {
    background: #2a2a2a;
  }

  .chat-body::-webkit-scrollbar-track {
    background: #333;
  }

  .chat-body::-webkit-scrollbar-thumb {
    background: #555;
  }

  .chat-message {
    background: #3a3a3a;
  }

  .chat-sender {
    color: #e0e0e0;
  }

  .chat-sender.master {
    color: #66b3ff;
  }

  .chat-time {
    color: #888;
  }

  .chat-message-text {
    color: #d0d0d0;
  }

  .chat-guide-line {
    color: #cbd5e1;
    background: #334155;
    border-color: #475569;
  }

  .chat-system-message {
    color: #e2e8f0;
    background: #374151;
  }

  .chat-file-link {
    color: #bfdbfe;
  }

  .chat-input {
    background: #333;
    border-color: #444;
    color: #e0e0e0;
  }

  .chat-input:focus {
    border-color: #66b3ff;
    box-shadow: 0 0 0 2px rgba(102, 179, 255, 0.1);
  }

  .chat-input-area {
    border-top-color: #444;
    background: #333;
  }

  .chat-typing-indicator {
    border-top-color: #444;
    background: #333;
    color: #b5b5b5;
  }
}
