/**
 * 100x Shared Component Styles
 * Chat interface, statement editors, guided questions, sign-in
 * Note: Despite the filename, these styles are shared across modules.
 */

/* ===== CHAT INTERFACE ===== */
.chat-container {
  background: var(--bg-primary);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-light);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.chat-messages {
  height: 400px;
  overflow-y: auto;
  padding: var(--spacing-lg);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  background: var(--bg-secondary);
}

.message {
  max-width: 85%;
  padding: 1rem 1.25rem;
  border-radius: var(--radius-lg);
  line-height: 1.5;
}

.message.ai {
  background: var(--bg-primary);
  color: var(--text-dark);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  border: 1px solid var(--border-light);
}

.message.user {
  background: var(--navy-primary);
  color: var(--text-light);
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.message.loading {
  color: var(--text-muted);
}

.message.error-message {
  color: var(--text-muted);
  font-style: italic;
  background: transparent;
  border: 1px dashed var(--border-light, #e2e8f0);
}

/* Typing Indicator */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 0.5rem 0;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing {
  0%, 60%, 100% {
    transform: translateY(0);
  }
  30% {
    transform: translateY(-4px);
  }
}

/* Chat Input */
.chat-input-container {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-light);
  display: flex;
  gap: 0.75rem;
  background: var(--bg-primary);
}

.chat-input {
  flex: 1;
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
  color: var(--text-dark);
  font-family: var(--font-body);
  font-size: calc(0.95rem + var(--text-bump));
  resize: none;
}

.chat-input:focus {
  outline: none;
  border-color: var(--teal-accent);
}

.chat-input::placeholder {
  color: var(--text-muted);
}

.send-btn {
  background: var(--teal-accent);
  border: none;
  border-radius: var(--radius-md);
  width: 48px;
  height: 48px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

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

.send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.send-btn svg,
.send-btn i {
  width: 20px;
  height: 20px;
  color: var(--text-light);
}

/* ===== STATEMENT EDITOR ===== */
.statement-editor {
  background: var(--bg-primary);
  border: 2px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-top: var(--spacing-xl);
  box-shadow: var(--shadow-md);
}

.statement-editor.has-content {
  border-color: var(--teal-accent);
}

.statement-editor-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-light);
}

.statement-editor-header-left {
  flex: 1;
}

.statement-editor-title {
  font-family: var(--font-heading);
  font-size: calc(1.25rem + var(--text-bump));
  color: var(--navy-primary);
  font-weight: 600;
  margin: 0 0 0.5rem 0;
}

.statement-editor-subtitle {
  font-size: calc(0.9rem + var(--text-bump));
  color: var(--text-muted);
  margin: 0;
  line-height: 1.4;
}

.statement-editor-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: calc(0.8rem + var(--text-bump));
  color: var(--text-muted);
  font-family: var(--font-body);
  padding: 0.35rem 0.75rem;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
}

.statement-editor-status .status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border-medium);
}

.statement-editor.has-content .statement-editor-status .status-dot {
  background: var(--teal-accent);
}

.statement-editor-body {
  margin-bottom: 1rem;
}

/* Trix Editor Customization */
.statement-trix-editor {
  min-height: 280px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 1rem;
  color: var(--text-dark);
  font-family: var(--font-body);
  font-size: calc(1rem + var(--text-bump));
  line-height: 1.7;
}

.statement-trix-editor:focus {
  outline: none;
  border-color: var(--teal-accent);
  box-shadow: 0 0 0 3px rgba(74, 155, 181, 0.1);
}

.statement-trix-editor:empty:not(:focus)::before {
  color: var(--text-muted);
  font-style: italic;
}

/* Lightweight Trix Toolbar */
trix-toolbar {
  background: transparent;
  border: none;
  padding: 0.25rem 0;
  display: flex;
  align-items: center;
}

/* Remove default Trix button group borders */
trix-toolbar .trix-button-group:not(:first-child) {
  border-left: none !important;
  margin-left: 0 !important;
}

trix-toolbar .trix-button-group + .trix-button-group {
  border: none !important;
}

trix-toolbar .trix-button-row {
  display: flex;
  align-items: center;
  gap: 0;
  flex-wrap: nowrap;
  width: 100%;
}

/* Button styling - minimal icon-only look */
trix-toolbar .trix-button {
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0;
  margin: 0;
  width: 24px;
  height: 24px;
  opacity: 0.5;
  transition: opacity var(--transition-fast);
}

trix-toolbar .trix-button:hover {
  background: transparent;
  opacity: 0.8;
}

trix-toolbar .trix-button.trix-active {
  background: transparent;
  opacity: 1;
  color: var(--teal-accent);
}

trix-toolbar .trix-button::before {
  width: 15px;
  height: 15px;
}

/* Hide ALL button groups first */
trix-toolbar .trix-button-group {
  display: none;
  margin: 0 !important;
  border: none !important;
  border-radius: 0 !important;
  padding: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
}

/* Show text tools (bold/italic) */
trix-toolbar .trix-button-group--text-tools {
  display: flex;
  gap: 0;
}

/* Show block tools (lists) */
trix-toolbar .trix-button-group--block-tools {
  display: flex;
  gap: 0;
  margin-left: 0.25rem !important;
}

/* Show history tools (undo/redo) - push to right */
trix-toolbar .trix-button-group--history-tools {
  display: flex;
  gap: 0;
  margin-left: auto !important;
}

/* Hide extra buttons within shown groups */
trix-toolbar .trix-button--icon-strike,
trix-toolbar .trix-button--icon-link,
trix-toolbar .trix-button--icon-heading-1,
trix-toolbar .trix-button--icon-quote,
trix-toolbar .trix-button--icon-code,
trix-toolbar .trix-button--icon-decrease-nesting-level,
trix-toolbar .trix-button--icon-increase-nesting-level {
  display: none;
}

/* Dialog panels */
trix-toolbar .trix-dialogs {
  display: none;
}

.statement-editor-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 1rem;
  border-top: 1px solid var(--border-light);
}

.statement-editor-actions {
  display: flex;
  gap: 0.75rem;
}

.statement-editor-hint {
  font-size: calc(0.85rem + var(--text-bump));
  color: var(--text-muted);
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.statement-editor-hint i {
  color: var(--teal-accent);
}

/* ===== GUIDED QUESTIONS ===== */
.guided-questions-container {
  display: none;
}

.guided-questions-container.active {
  display: block;
}

.guided-question {
  background: var(--bg-primary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow-sm);
}

.guided-question.completed {
  border-color: var(--teal-accent);
  border-left: 4px solid var(--teal-accent);
}

.guided-question-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.75rem;
}

.guided-question-number {
  font-size: calc(0.75rem + var(--text-bump));
  color: var(--navy-primary);
  font-weight: 600;
}

.guided-question-status {
  font-size: calc(0.7rem + var(--text-bump));
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.guided-question-status.answered {
  color: var(--teal-accent);
}

.guided-question-text {
  font-size: calc(0.95rem + var(--text-bump));
  line-height: 1.5;
  margin-bottom: 0.75rem;
  color: var(--text-dark);
}

.guided-question textarea {
  width: 100%;
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  color: var(--text-dark);
  font-family: var(--font-body);
  font-size: calc(0.9rem + var(--text-bump));
  line-height: 1.5;
  min-height: 80px;
  resize: vertical;
}

.guided-question textarea:focus {
  outline: none;
  border-color: var(--teal-accent);
}

.guided-question textarea::placeholder {
  color: var(--text-muted);
}

.guided-progress-row {
  display: flex;
  justify-content: flex-end;
  margin-top: 1rem;
  margin-bottom: 0.5rem;
}

.guided-progress {
  font-size: calc(0.85rem + var(--text-bump));
  color: var(--text-muted);
}

.guided-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 1rem;
  border-top: 1px solid var(--border-light);
}

.guided-nav-buttons {
  display: flex;
  gap: 0.5rem;
}

/* ===== PRINT PREVIEW STYLES ===== */
.export-content.print-preview h1 {
  font-family: var(--font-heading);
  color: var(--navy-primary);
  font-size: calc(1.5rem + var(--text-bump));
  margin-bottom: 0.5rem;
  border-bottom: 2px solid var(--teal-accent);
  padding-bottom: 0.5rem;
}

.export-content.print-preview h2 {
  font-family: var(--font-heading);
  color: #0a1628;
  font-size: calc(1.1rem + var(--text-bump));
  margin-top: 1.25rem;
  margin-bottom: 0.5rem;
}

.export-content.print-preview h3 {
  font-family: var(--font-heading);
  color: #152238;
  font-size: calc(0.95rem + var(--text-bump));
  margin-top: 1rem;
  margin-bottom: 0.25rem;
}

.export-content.print-preview p {
  margin: 0.25rem 0;
  line-height: 1.5;
}

.export-content.print-preview .section {
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid #e5e5e5;
}

.export-content.print-preview .empty {
  color: #999;
  font-style: italic;
}

/* ===== CLOUD SIGN IN ===== */
.cloud-signin-section {
  margin-top: 1rem;
  text-align: center;
}

.signin-options {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.google-signin-btn {
  width: 100%;
  justify-content: center;
  padding: 0.75rem 1rem;
  font-size: calc(0.95rem + var(--text-bump));
}

/* Sign-in divider */
.signin-divider {
  display: flex;
  align-items: center;
  gap: 1rem;
  color: var(--text-muted);
  font-size: calc(0.85rem + var(--text-bump));
}

.signin-divider::before,
.signin-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-light, #e5e5e5);
}

/* Email sign-in form */
.email-signin-form {
  text-align: left;
}

.email-input-group {
  display: flex;
  gap: 0.5rem;
}

.email-signin-input {
  flex: 1;
  padding: 0.625rem 0.875rem;
  border: 1px solid var(--border-light, #e5e5e5);
  border-radius: var(--radius-md, 6px);
  font-size: calc(0.95rem + var(--text-bump));
  background: var(--bg-primary, #fff);
  color: var(--text-dark);
}

.email-signin-input:focus {
  outline: none;
  border-color: var(--teal-accent);
  box-shadow: 0 0 0 3px rgba(74, 155, 181, 0.1);
}

.email-signin-btn {
  white-space: nowrap;
  padding: 0.625rem 1rem;
}

.email-signin-hint {
  font-size: calc(0.8rem + var(--text-bump));
  color: var(--text-muted);
  margin-top: 0.5rem;
  text-align: center;
}

/* Email sent confirmation */
.email-sent-message {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 1.25rem;
  background: rgba(74, 155, 181, 0.08);
  border-radius: var(--radius-md, 6px);
  text-align: center;
}

.email-sent-message i {
  font-size: calc(2rem + var(--text-bump));
  color: var(--teal-accent);
}

.email-sent-message p {
  margin: 0;
  font-weight: 500;
  color: var(--text-dark);
}

.email-sent-address {
  font-size: calc(0.85rem + var(--text-bump));
  color: var(--text-muted);
}

.cloud-signin-note {
  font-size: calc(0.8rem + var(--text-bump));
  color: var(--text-muted);
  margin-top: 0.75rem;
}

/* Signed In State */
.cloud-signedin-section {
  margin-top: 1rem;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem;
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
}

.user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
}

/* Rails-only: initial-letter fallback when the user has no avatar photo.
   Matches the original .user-avatar circle so the signed-in card looks the
   same whether or not a photo exists. */
.user-avatar-initial {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--teal-accent);
  color: var(--text-light, #fff);
  font-weight: 600;
  font-size: calc(1rem + var(--text-bump));
  text-transform: uppercase;
}

/* User avatar with upload overlay */
.user-avatar-wrapper {
  position: relative;
  width: 40px;
  height: 40px;
  cursor: pointer;
  flex-shrink: 0;
}

.user-avatar-wrapper .user-avatar {
  width: 100%;
  height: 100%;
}

.user-avatar-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.user-avatar-overlay i {
  color: white;
  font-size: calc(1rem + var(--text-bump));
}

.user-avatar-wrapper:hover .user-avatar-overlay {
  opacity: 1;
}

.user-avatar-wrapper.uploading .user-avatar-overlay {
  opacity: 1;
}

.user-avatar-wrapper.uploading .user-avatar-overlay i::before {
  content: "\F130";  /* Bootstrap Icons spinner */
  animation: spin 1s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.user-details {
  flex: 1;
}

.user-name {
  font-weight: 600;
  color: var(--navy-primary);
}

.user-email {
  font-size: calc(0.85rem + var(--text-bump));
  color: var(--text-muted);
}

/* "Remove photo" link under the name (only shown when an avatar is uploaded). */
.btn-link-remove-avatar {
  background: none;
  border: none;
  padding: 0;
  margin-top: 0.25rem;
  font-size: calc(0.78rem + var(--text-bump));
  color: var(--text-muted);
  cursor: pointer;
  text-decoration: underline;
}

.btn-link-remove-avatar:hover {
  color: var(--danger, #dc3545);
}

.avatar-upload-error {
  margin: 0.5rem 0 0;
  font-size: calc(0.8rem + var(--text-bump));
  color: var(--danger, #dc3545);
}

.sync-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
  font-size: calc(0.85rem + var(--text-bump));
  color: var(--teal-accent);
}

/* Memory sync toggle (inside cloud signed-in section) */
.memory-sync-row {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-light);
}

/* ===== RESPONSIVE - MOBILE ===== */
@media (max-width: 768px) {
  /* Statement editor */
  .statement-editor {
    padding: 0.75rem;
  }

  .statement-editor textarea {
    min-height: 80px;
    padding: 0.75rem;
    font-size: calc(0.9rem + var(--text-bump));
  }

  .statement-editor-actions {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .statement-editor-actions .btn {
    padding: 0.5rem 0.75rem;
    font-size: calc(0.8rem + var(--text-bump));
  }
}

/* ===== Dark Theme ===== */
[data-theme="dark"] trix-toolbar {
  background: var(--bg-tertiary);
  border-color: var(--border-medium);
}

[data-theme="dark"] trix-toolbar .trix-button {
  background: transparent;
}

[data-theme="dark"] trix-toolbar .trix-button:hover {
  background: var(--bg-secondary);
}

[data-theme="dark"] trix-toolbar .trix-button.trix-active {
  background: rgba(91, 184, 212, 0.2);
}

/* Trix button icons - invert for dark mode */
[data-theme="dark"] trix-toolbar .trix-button::before {
  filter: invert(1);
}

[data-theme="dark"] trix-toolbar .trix-button-group--block-tools {
  border-left-color: var(--border-medium) !important;
}

[data-theme="dark"] .statement-trix-editor {
  background: var(--bg-secondary);
  border-color: var(--border-medium);
  color: #e8ecf4;
}

[data-theme="dark"] .statement-trix-editor:focus {
  border-color: var(--teal-accent);
}

/* Dark theme email sign-in */
[data-theme="dark"] .signin-divider::before,
[data-theme="dark"] .signin-divider::after {
  background: var(--border-medium);
}

[data-theme="dark"] .email-signin-input {
  background: var(--bg-secondary);
  border-color: var(--border-medium);
  color: #e8ecf4;
}

[data-theme="dark"] .email-signin-input:focus {
  border-color: var(--teal-accent);
}

[data-theme="dark"] .email-sent-message {
  background: rgba(91, 184, 212, 0.15);
}

[data-theme="dark"] .email-sent-message p {
  color: #e8ecf4;
}
