/**
 * Shared Chat Sidebar styles.
 * Used by both the Vue ChatSidebar component (plan-edit SPA)
 * and the standalone ChatWidget (Pug pages).
 *
 * Class names mirror the Vue component's scoped styles so both
 * integrations render identically.
 */

/* Toggle button — fixed middle-right side  Req 1.5 */
.chat-toggle-btn {
  position: fixed;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  z-index: 10000;
  width: auto;
  height: 44px;
  padding: 0 14px 0 12px;
  border-radius: 22px 0 0 22px;
  border: none;
  background-color: #1976d2;
  color: white;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: -2px 2px 12px rgba(0,0,0,0.2);
  transition: background-color 0.2s;
  display: flex;
  align-items: center;
  gap: 6px;
}
.chat-toggle-btn:hover { background-color: #1565c0; }

.chat-toggle-btn__icon {
  font-size: 1.1rem;
  line-height: 1;
}

.chat-toggle-btn__label {
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

/* Content push when sidebar is open */
#container {
  transition: margin-right 0.3s ease;
}
body.chat-open #container {
  margin-right: 360px;
}

/* Sidebar panel  Req 1.1, 1.7 */
.chat-sidebar {
  position: fixed;
  top: 0;
  right: 0;
  width: 360px;
  height: 100vh;
  background: #fff;
  border-left: 1px solid #e0e0e0;
  box-shadow: -4px 0 16px rgba(0,0,0,0.08);
  display: flex;
  flex-direction: column;
  z-index: 10001;
  transform: translateX(100%);
  transition: transform 0.3s ease;
}
.chat-sidebar--open { transform: translateX(0); }

/* Header */
.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid #e0e0e0;
  flex-shrink: 0;
}
.chat-header__left { display: flex; flex-direction: column; gap: 2px; }
.chat-header__title { margin: 0; font-size: 1rem; font-weight: 600; color: #333; }
.chat-header__subtitle { font-size: 0.6875rem; color: #888; font-weight: 400; }
.chat-header__model { font-size: 0.75rem; color: #888; }
.chat-header__right { display: flex; gap: 4px; }

/* Buttons */
.chat-btn {
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  transition: background-color 0.2s;
}

.chat-btn--icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: #666;
  font-size: 1rem;
}
.chat-btn--icon:hover { background-color: #f0f0f0; }
.chat-btn--primary { background-color: #1976d2; color: #fff; padding: 6px 14px; }
.chat-btn--primary:hover:not(:disabled) { background-color: #1565c0; }
.chat-btn--primary:disabled { opacity: 0.5; cursor: not-allowed; }
.chat-btn--secondary { background-color: #f5f5f5; color: #666; padding: 6px 14px; }
.chat-btn--secondary:hover { background-color: #e0e0e0; }
.chat-btn--danger { background-color: #f44336; color: #fff; padding: 6px 14px; }
.chat-btn--danger:hover { background-color: #d32f2f; }
.chat-btn--sm { font-size: 0.75rem; padding: 4px 10px; }

/* Session list */
.chat-session-list {
  max-height: 200px;
  overflow-y: auto;
  border-bottom: 1px solid #e0e0e0;
  flex-shrink: 0;
}
.chat-session-item {
  padding: 8px 16px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8125rem;
  transition: background-color 0.15s;
}
.chat-session-item:hover { background-color: #f5f5f5; }
.chat-session-item--active { background-color: #e3f2fd; }
.chat-session-item--empty { color: #999; cursor: default; justify-content: center; }
.chat-session-item__title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.chat-session-item__date { color: #999; font-size: 0.75rem; margin-left: 8px; flex-shrink: 0; }

/* Usage stats */
.chat-usage {
  padding: 6px 16px;
  font-size: 0.75rem;
  color: #888;
  border-bottom: 1px solid #f0f0f0;
  flex-shrink: 0;
}

/* Suggestions  Req 15.4 */
.chat-suggestions {
  padding: 12px 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  flex-shrink: 0;
}
.chat-suggestion-chip {
  background: #e3f2fd;
  border: 1px solid #90caf9;
  border-radius: 16px;
  padding: 6px 14px;
  font-size: 0.8125rem;
  color: #1565c0;
  cursor: pointer;
  transition: background-color 0.15s;
}
.chat-suggestion-chip:hover { background: #bbdefb; }

/* Messages area */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-msg { display: flex; }
.chat-msg--user { justify-content: flex-end; }
.chat-msg--assistant { justify-content: flex-start; }

.chat-msg__bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 0.875rem;
  line-height: 1.5;
  word-break: break-word;
}
.chat-msg__bubble--user {
  background-color: #1976d2;
  color: #fff;
  border-bottom-right-radius: 4px;
}
.chat-msg__bubble--assistant {
  background-color: #f5f5f5;
  color: #333;
  border-bottom-left-radius: 4px;
}

/* Streaming cursor */
.chat-cursor {
  display: inline-block;
  animation: chat-blink 1s step-end infinite;
  color: #1976d2;
}
@keyframes chat-blink {
  50% { opacity: 0; }
}

/* Message status subtext */
.chat-msg__status {
  font-size: 0.6875rem;
  color: #999;
  margin-top: 4px;
  padding: 0 2px;
}

/* Actions inside messages */
.chat-action { margin-top: 8px; }
.chat-action-link {
  color: #1976d2;
  text-decoration: underline;
  cursor: pointer;
  font-size: 0.8125rem;
}
.chat-action-confirm {
  background: #fff3e0;
  border: 1px solid #ffcc80;
  border-radius: 8px;
  padding: 10px;
  font-size: 0.8125rem;
}
.chat-action-confirm p { margin: 0 0 8px; }
.chat-action-confirm button { margin-right: 6px; }
.chat-action-error {
  color: #d32f2f;
  font-size: 0.8125rem;
  padding: 4px 0;
}

/* Error bar */
.chat-error {
  padding: 8px 16px;
  background: #ffebee;
  color: #c62828;
  font-size: 0.8125rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}
.chat-error__actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* Input area  Req 1.4 */
.chat-input-area {
  padding: 12px 16px;
  border-top: 1px solid #e0e0e0;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-shrink: 0;
}
.chat-input {
  flex: 1;
  resize: none;
  border: 1px solid #ccc;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.875rem;
  font-family: inherit;
  line-height: 1.4;
  outline: none;
  transition: border-color 0.2s;
}
.chat-input:focus { border-color: #1976d2; }
.chat-input:disabled { background: #f5f5f5; cursor: not-allowed; }
.chat-input-actions { display: flex; flex-direction: column; gap: 4px; }

/* Markdown content inside assistant bubbles */
.chat-msg__bubble--assistant h1,
.chat-msg__bubble--assistant h2,
.chat-msg__bubble--assistant h3 {
  margin: 8px 0 4px;
  font-size: 0.9375rem;
}
.chat-msg__bubble--assistant p { margin: 4px 0; }
.chat-msg__bubble--assistant pre {
  background: #263238;
  color: #eee;
  padding: 8px;
  border-radius: 6px;
  overflow-x: auto;
  font-size: 0.8125rem;
}
.chat-msg__bubble--assistant code {
  background: rgba(0,0,0,0.06);
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 0.8125rem;
}
.chat-msg__bubble--assistant pre code {
  background: none;
  padding: 0;
}
.chat-msg__bubble--assistant ul,
.chat-msg__bubble--assistant ol {
  margin: 4px 0;
  padding-left: 20px;
}
.chat-msg__bubble--assistant table {
  border-collapse: collapse;
  width: 100%;
  margin: 8px 0;
  font-size: 0.8125rem;
}
.chat-msg__bubble--assistant th,
.chat-msg__bubble--assistant td {
  border: 1px solid #ddd;
  padding: 4px 8px;
  text-align: left;
}
.chat-msg__bubble--assistant th {
  background: #e0e0e0;
  font-weight: 600;
}

/* Chat table (rendered by ChatMessageRenderer.renderTable) */
.chat-table {
  border-collapse: collapse;
  width: 100%;
  margin: 8px 0;
  font-size: 0.8125rem;
}
.chat-table th,
.chat-table td {
  border: 1px solid #ddd;
  padding: 4px 8px;
  text-align: left;
}
.chat-table th {
  background: #e0e0e0;
  font-weight: 600;
}

/* Action button styles (rendered by ChatMessageRenderer.renderActionButton) */
.chat-action-btn {
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.75rem;
  padding: 4px 10px;
  font-weight: 500;
}
.chat-action-btn--confirm { background-color: #1976d2; color: #fff; }
.chat-action-btn--confirm:hover { background-color: #1565c0; }
.chat-action-btn--cancel { background-color: #f5f5f5; color: #666; }
.chat-action-btn--cancel:hover { background-color: #e0e0e0; }
.chat-action-summary { margin: 0 0 8px; }

/* ===== RESPONSIVE ===== */
@media (max-width: 480px) {
  .chat-toggle-btn__label {
    display: none;
  }

  .chat-toggle-btn {
    width: 44px;
    height: 44px;
    padding: 0;
    border-radius: 50% 0 0 50%;
  }

  .chat-sidebar {
    width: 100vw;
  }

  body.chat-open #container {
    margin-right: 0;
  }
}
