/**
 * Email Editor Styles
 * Inline email editor with rich text formatting
 */

/* ========================================
   EMAIL EDITOR CONTAINER
   ======================================== */

.email-editor {
  background: var(--color-surface);
  border: 1px solid var(--border-primary, #e2e8f0);
  border-radius: var(--radius-lg, 12px);
  overflow: hidden;
}

/* ========================================
   HEADER (Recommended badge, action badge)
   ======================================== */

.email-editor__header {
  display: flex;
  align-items: center;
  gap: var(--space-2, 8px);
  padding: var(--space-3, 12px) var(--space-4, 16px);
  background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
  border-bottom: 1px solid var(--border-primary, #e2e8f0);
}

.email-editor__star {
  font-size: 1rem;
}

.email-editor__recommended {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: #92400e;
  text-transform: uppercase;
}

/* ========================================
   RECIPIENTS SECTION
   ======================================== */

.email-editor__recipients {
  border-bottom: 1px solid var(--border-primary, #e2e8f0);
}

.email-editor__field {
  display: flex;
  align-items: center;
  gap: var(--space-2, 8px);
  padding: var(--space-2, 8px) var(--space-4, 16px);
  border-bottom: 1px solid var(--border-secondary, #f1f5f9);
}

.email-editor__field:last-child {
  border-bottom: none;
}

.email-editor__field--from {
  background: var(--color-slate-50);
}

.email-editor__field--collapsed {
  display: none;
}

.email-editor__label {
  flex: 0 0 60px;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary, #64748b);
}

.email-editor__input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 0.875rem;
  color: var(--text-primary, #1e293b);
  outline: none;
  padding: var(--space-1, 4px) 0;
}

.email-editor__input::placeholder {
  color: var(--text-tertiary, #94a3b8);
}

.email-editor__from-value {
  flex: 1;
  font-size: 0.875rem;
  color: var(--text-primary, #1e293b);
}

.email-editor__cc-toggle {
  flex: 0 0 auto;
  padding: var(--space-1, 4px) var(--space-2, 8px);
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--color-primary, #2563EB);
  background: transparent;
  border: 1px solid var(--color-primary, #2563EB);
  border-radius: var(--radius-sm, 4px);
  cursor: pointer;
  transition: all 0.15s ease;
}

.email-editor__cc-toggle:hover {
  background: var(--color-primary, #2563EB);
  color: white;
}

/* ========================================
   SUBJECT LINE
   ======================================== */

.email-editor__subject-wrapper {
  display: flex;
  align-items: center;
  gap: var(--space-2, 8px);
  padding: var(--space-2, 8px) var(--space-4, 16px);
  border-bottom: 1px solid var(--border-primary, #e2e8f0);
}

.email-editor__subject-input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--text-primary, #1e293b);
  outline: none;
  padding: var(--space-1, 4px) 0;
}

.email-editor__subject-input::placeholder {
  color: var(--text-tertiary, #94a3b8);
  font-weight: 400;
}

/* ========================================
   FORMATTING TOOLBAR
   ======================================== */

.email-editor__toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-1, 4px);
  padding: var(--space-2, 8px) var(--space-4, 16px);
  background: var(--color-slate-50);
  border-bottom: 1px solid var(--border-primary, #e2e8f0);
}

.email-editor__toolbar-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm, 4px);
  cursor: pointer;
  transition: all 0.15s ease;
  font-size: 0.875rem;
  color: var(--text-secondary, #64748b);
}

.email-editor__toolbar-btn:hover {
  background: var(--color-slate-100);
  color: var(--text-primary, #1e293b);
}

.email-editor__toolbar-btn.is-active {
  background: var(--color-primary, #2563EB);
  color: white;
}

.email-editor__toolbar-divider {
  width: 1px;
  height: 20px;
  background: var(--border-primary, #e2e8f0);
  margin: 0 var(--space-1, 4px);
}

.email-editor__toolbar-spacer {
  flex: 1;
}

.email-editor__autosave-status {
  font-size: 0.75rem;
  color: var(--text-tertiary, #94a3b8);
  white-space: nowrap;
}

/* ========================================
   BODY (CONTENTEDITABLE)
   ======================================== */

.email-editor__body {
  min-height: 250px;
  max-height: 400px;
  overflow-y: auto;
  padding: var(--space-4, 16px);
  font-size: 0.9375rem;
  line-height: 1.6;
  color: var(--text-primary, #1e293b);
  outline: none;
}

.email-editor__body:empty::before {
  content: attr(data-placeholder);
  color: var(--text-tertiary, #94a3b8);
  pointer-events: none;
}

.email-editor__body:focus {
  background: var(--color-surface);
}

/* Body text styling */
.email-editor__body p {
  margin: 0 0 1em 0;
}

.email-editor__body ul,
.email-editor__body ol {
  margin: 0 0 1em 0;
  padding-left: 1.5em;
}

.email-editor__body a {
  color: var(--color-primary, #2563EB);
  text-decoration: underline;
}

/* ========================================
   ACTION BUTTONS
   ======================================== */

.email-editor__actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-3, 12px);
  padding: var(--space-3, 12px) var(--space-4, 16px);
  background: var(--color-slate-50);
  border-top: 1px solid var(--border-primary, #e2e8f0);
}

.email-editor__actions-right {
  display: flex;
  align-items: center;
  gap: var(--space-2, 8px);
}

.email-editor__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1, 4px);
  padding: var(--space-2, 8px) var(--space-4, 16px);
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: var(--radius-md, 8px);
  cursor: pointer;
  transition: all 0.15s ease;
  border: none;
  white-space: nowrap;
}

.email-editor__btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Copy button */
.email-editor__btn--copy {
  background: transparent;
  color: var(--text-secondary, #64748b);
  border: 1px solid var(--border-primary, #e2e8f0);
}

.email-editor__btn--copy:hover:not(:disabled) {
  background: var(--color-slate-100);
  color: var(--text-primary, #1e293b);
}

/* Secondary button (Save Draft) */
.email-editor__btn--secondary {
  background: white;
  color: var(--text-primary, #1e293b);
  border: 1px solid var(--border-primary, #e2e8f0);
}

.email-editor__btn--secondary:hover:not(:disabled) {
  background: var(--color-slate-100);
  border-color: var(--color-slate-300);
}

/* Primary button (Send) */
.email-editor__btn--primary {
  background: var(--color-primary, #2563EB);
  color: white;
}

.email-editor__btn--primary:hover:not(:disabled) {
  background: var(--color-primary-hover, #1D4ED8);
}

/* Connect button */
.email-editor__btn--connect {
  background: var(--color-primary, #2563EB);
  color: white;
}

.email-editor__btn--connect:hover:not(:disabled) {
  background: var(--color-primary-hover, #1D4ED8);
}

/* Success state */
.email-editor__btn--success {
  background: var(--color-success, #22c55e) !important;
  border-color: var(--color-success, #22c55e) !important;
  color: white !important;
}

/* Error state */
.email-editor__btn--error {
  background: white !important;
  border-color: var(--color-error, #ef4444) !important;
  color: var(--color-error, #ef4444) !important;
}

/* ========================================
   SEND CONFIRMATION MODAL
   ======================================== */

.email-editor-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.email-editor-modal.is-visible {
  opacity: 1;
}

.email-editor-modal__backdrop {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
}

.email-editor-modal__content {
  position: relative;
  background: var(--color-surface);
  border-radius: var(--radius-lg, 12px);
  padding: var(--space-6, 24px);
  max-width: 400px;
  width: 90%;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

.email-editor-modal__title {
  margin: 0 0 var(--space-4, 16px) 0;
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text-primary, #1e293b);
}

.email-editor-modal__preview {
  background: var(--color-slate-50);
  border-radius: var(--radius-md, 8px);
  padding: var(--space-3, 12px);
  margin-bottom: var(--space-4, 16px);
}

.email-editor-modal__preview p {
  margin: 0 0 var(--space-1, 4px) 0;
  font-size: 0.875rem;
  color: var(--text-secondary, #64748b);
}

.email-editor-modal__preview p:last-child {
  margin-bottom: 0;
}

.email-editor-modal__preview strong {
  color: var(--text-primary, #1e293b);
}

.email-editor-modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2, 8px);
}

/* ========================================
   RESPONSIVE ADJUSTMENTS
   ======================================== */

@media (max-width: 640px) {
  .email-editor__toolbar {
    flex-wrap: wrap;
    gap: var(--space-1, 4px);
  }
  
  .email-editor__toolbar-spacer {
    display: none;
  }
  
  .email-editor__autosave-status {
    width: 100%;
    text-align: right;
    margin-top: var(--space-1, 4px);
  }
  
  .email-editor__actions {
    flex-direction: column;
    gap: var(--space-2, 8px);
  }
  
  .email-editor__actions-right {
    width: 100%;
    justify-content: flex-end;
  }
  
  .email-editor__btn--copy {
    width: 100%;
  }
}

/* ========================================
   COMPOSE AREA (Phase 2 Placeholder)
   Temporary styles until full component built
   ======================================== */

.compose-area {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
  min-height: 200px;
}

.compose-area__placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 48px 24px;
  text-align: center;
  color: var(--color-text-secondary);
}

.compose-area__placeholder-icon {
  font-size: 48px;
  opacity: 0.5;
}

.compose-area__placeholder-text {
  font-size: 18px;
  font-weight: 600;
  color: var(--color-text);
}

.compose-area__placeholder-hint {
  font-size: 13px;
  opacity: 0.7;
}

/* ========================================
   COMPOSE AREA COMPONENT
   Full compose editor with all sections
   ======================================== */

/* Reply Options Bar — matches rz-intents design */
.compose-options {
  position: relative;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 8px 18px;
  border-bottom: 1px solid var(--color-border-light, #f1f5f9);
  overflow-x: auto;
  flex-shrink: 0;
  flex-wrap: wrap;
}

/* Respect hidden attribute */
.compose-options[hidden] {
  display: none;
}

.compose-options__label {
  font-size: 11px;
  font-weight: 600;
  color: var(--color-primary, #2563eb);
  white-space: nowrap;
  margin-right: 4px;
}

.compose-options__list {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  flex: 1;
  min-width: 0;
}

.compose-option {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 13px;
  background: var(--color-surface, #fff);
  border: 1px solid var(--color-border, rgba(0, 0, 0, 0.08));
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text);
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.compose-option:hover {
  border-color: var(--color-primary, #2563eb);
  color: var(--color-primary, #2563eb);
}

.compose-option.is-selected {
  background: var(--color-primary, #2563eb);
  border-color: var(--color-primary, #2563eb);
  color: #fff;
}

/* Hero option — same blue style when selected */
.compose-option--hero {
  border-color: var(--color-border, rgba(0, 0, 0, 0.08));
}

.compose-option--hero.is-selected {
  background: var(--color-primary, #2563eb);
  border-color: var(--color-primary, #2563eb);
  color: #fff;
}

.compose-option__radio {
  font-size: 10px;
  color: var(--color-text-muted);
}

.compose-option.is-selected .compose-option__radio {
  color: #fff;
}

.compose-option--hero.is-selected .compose-option__radio {
  color: #fff;
}

.compose-option__label {
  font-size: 12px;
}

.compose-option__check {
  font-size: 11px;
  color: #fff;
}

/* +N more button for option overflow */
.compose-option--more {
  border-style: dashed;
  border-color: var(--color-primary, #2563eb);
  color: var(--color-primary, #2563eb);
  background: transparent;
  font-weight: 500;
}

.compose-option--more:hover {
  background: var(--color-primary-muted, #eff6ff);
  border-style: solid;
}

/* Option preview modal (shown on hover) */
.compose-option-preview {
  position: fixed;
  z-index: 10000;
  margin-top: 8px;
  min-width: 320px;
  max-width: 500px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  animation: fadeInUp 150ms ease;
  pointer-events: none; /* Don't interfere with mouse events */
}

.compose-option-preview[hidden] {
  display: none;
}

.compose-option-preview__content {
  padding: 12px 16px;
  max-height: 300px;
  overflow-y: auto;
  font-size: 13px;
  line-height: 1.6;
  color: var(--color-text);
}

.compose-option-preview__content p {
  margin: 0 0 8px 0;
}

.compose-option-preview__content p:last-child {
  margin-bottom: 0;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Header Fields */
.compose-header {
  display: flex;
  flex-direction: column;
  border-bottom: 1px solid var(--color-border);
  position: relative;
}

.compose-field {
  display: flex;
  align-items: center;
  padding: 8px 16px;
  border-bottom: 1px solid var(--color-border-light, #f1f5f9);
}

/* Respect hidden attribute */
.compose-field[hidden] {
  display: none;
}

.compose-field:last-of-type {
  border-bottom: none;
}

.compose-field__label {
  width: 60px;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-secondary);
  flex-shrink: 0;
}

.compose-field__input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 14px;
  color: var(--color-text);
  outline: none;
  padding: 4px 0;
}

.compose-field__input::placeholder {
  color: var(--color-text-muted, #94a3b8);
}

.compose-header__toggle {
  position: absolute;
  right: 16px;
  top: 8px;
  padding: 4px 8px;
  font-size: 12px;
  color: var(--color-primary);
  background: transparent;
  border: none;
  cursor: pointer;
  border-radius: 4px;
}

.compose-header__toggle:hover {
  background: var(--color-primary-light, #fff7ed);
}

.compose-header__toggle.is-expanded {
  color: var(--color-text-secondary);
}

/* Formatting Toolbar — matches rz-toolbar design */
.compose-toolbar {
  display: flex;
  align-items: center;
  gap: 1px;
  flex-wrap: wrap;
  padding: 3px 14px;
  background: var(--color-surface-secondary, #f8fafc);
  border-bottom: 1px solid var(--color-border-light, #f1f5f9);
  flex-shrink: 0;
}

.compose-toolbar__sep {
  width: 1px;
  height: 18px;
  background: var(--color-border, rgba(0, 0, 0, 0.08));
  margin: 0 3px;
}

.compose-toolbar__select {
  height: 26px;
  padding: 0 6px;
  border-radius: 4px;
  border: 1px solid var(--color-border, rgba(0, 0, 0, 0.08));
  background: var(--color-surface, #fff);
  font-size: 11px;
  color: var(--color-text-secondary, #64748b);
  cursor: pointer;
  font-family: inherit;
}

.compose-toolbar__select:hover {
  border-color: var(--color-text-muted, #94a3b8);
}

.compose-toolbar__select--size {
  width: 44px;
}

.compose-toolbar__btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 26px;
  border: none;
  background: none;
  border-radius: 4px;
  cursor: pointer;
  color: var(--color-text-secondary, #64748b);
  font-size: 12px;
  transition: all 0.1s;
}

.compose-toolbar__btn:hover {
  background: var(--color-surface, #fff);
  color: var(--color-text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.compose-toolbar__btn:active,
.compose-toolbar__btn.is-active {
  background: #dbeafe;
  color: var(--color-primary);
}

/* Color buttons (font colour / highlight) */
.compose-toolbar__color-btn {
  width: 28px;
  height: 26px;
  border-radius: 4px;
  border: none;
  background: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  line-height: 1;
  gap: 0;
  position: relative;
}

.compose-toolbar__color-btn:hover {
  background: var(--color-surface, #fff);
}

.compose-toolbar__color-letter {
  font-size: 13px;
}

.compose-toolbar__color-icon {
  font-size: 11px;
}

.compose-toolbar__color-bar {
  width: 14px;
  height: 3px;
  border-radius: 1px;
  margin-top: 1px;
}

/* ========================================
   COLOUR-PICKER POPUP (shared)
   ======================================== */

.compose-color-picker {
  position: absolute;
  top: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 1020;
  background: var(--color-surface, #fff);
  border: 1px solid var(--color-border, #e5e7eb);
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.14);
  padding: 8px;
  width: 220px;
  cursor: default;
}

.compose-color-picker__grid {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 2px;
}

.compose-color-picker__swatch {
  width: 18px;
  height: 18px;
  border: 1px solid transparent;
  border-radius: 3px;
  cursor: pointer;
  padding: 0;
  transition: transform 0.1s, box-shadow 0.1s;
}

.compose-color-picker__swatch:hover {
  transform: scale(1.25);
  box-shadow: 0 0 0 2px var(--color-primary, #2563eb);
  z-index: 1;
  position: relative;
}

.compose-color-picker__swatch.is-selected {
  box-shadow: 0 0 0 2px var(--color-primary, #2563eb);
  border-radius: 3px;
}

.compose-color-picker__swatch--white {
  border-color: var(--color-border, #e5e7eb);
}

.compose-color-picker__action {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 6px 4px;
  margin-top: 4px;
  border: none;
  border-top: 1px solid var(--color-border-light, #f1f5f9);
  background: none;
  font-size: 11px;
  color: var(--color-text-secondary, #64748b);
  cursor: pointer;
  border-radius: 4px;
}

.compose-color-picker__action:hover {
  background: var(--color-surface-secondary, #f8fafc);
  color: var(--color-text, #1e293b);
}

/* Do Better: inside compose-options, at right of options list, 20px from right edge */
.compose-do-better {
  flex-shrink: 0;
  margin-left: auto;
  margin-right: 40px;
}

.compose-do-better[hidden] {
  display: none;
}

.compose-do-better__btn {
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  color: var(--color-primary, #0d7377);
  background: transparent;
  border: 1px solid var(--color-primary, #0d7377);
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.compose-do-better__btn:hover:not(:disabled) {
  background: var(--color-primary, #0d7377);
  color: var(--color-surface, #fff);
}

.compose-do-better__btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

/* Do Better questions modal */
.compose-do-better-modal {
  position: absolute;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.compose-do-better-modal[hidden] {
  display: none;
}

.compose-do-better-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
}

.compose-do-better-modal__box {
  position: relative;
  width: 100%;
  max-width: 420px;
  padding: 20px;
  background: var(--color-surface, #fff);
  border: 1px solid var(--color-border, #e2e8f0);
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
}

.compose-do-better-modal__title {
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 16px;
}

.compose-do-better-modal__content {
  margin-bottom: 16px;
}

.compose-do-better-modal__item {
  margin-bottom: 12px;
}

.compose-do-better-modal__label {
  display: block;
  font-size: 13px;
  color: var(--color-text-secondary, #64748b);
  margin-bottom: 4px;
  line-height: 1.4;
}

.compose-do-better-modal__input {
  width: 100%;
  padding: 8px 12px;
  font-size: 14px;
  font-family: inherit;
  border: 1px solid var(--color-border, #cbd5e1);
  border-radius: 8px;
  background: var(--color-surface, #fff);
  color: var(--color-text);
}

.compose-do-better-modal__input:focus {
  outline: none;
  border-color: var(--color-primary, #0d7377);
}

.compose-do-better-modal__actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.compose-do-better-modal__skip,
.compose-do-better-modal__submit {
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  border-radius: 8px;
  cursor: pointer;
}

.compose-do-better-modal__skip {
  background: transparent;
  border: 1px solid var(--color-border, #cbd5e1);
  color: var(--color-text-secondary, #64748b);
}

.compose-do-better-modal__skip:hover {
  background: var(--color-surface-secondary, #f1f5f9);
}

.compose-do-better-modal__submit {
  background: var(--color-primary, #0d7377);
  border: none;
  color: var(--color-surface, #fff);
}

.compose-do-better-modal__submit:hover {
  opacity: 0.9;
}

/* Editor Area */
.compose-editor-wrapper {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  min-height: 170px;
  overflow: hidden;
}

.compose-editor {
  flex: 1;
  padding: 16px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--color-text);
  outline: none;
  overflow-y: auto;
  min-height: 120px;
}

/* Paragraph spacing for proper email formatting */
.compose-editor p {
  margin: 0 0 12px 0; /* Bottom margin for spacing between paragraphs */
}

.compose-editor p:last-child {
  margin-bottom: 0; /* Remove margin from last paragraph */
}

.compose-editor:empty::before {
  content: attr(placeholder);
  color: var(--color-text-muted, #94a3b8);
  pointer-events: none;
}

.compose-editor:focus {
  background: var(--color-surface);
}

/* Drag-over state for file drop */
.compose-editor--dragover {
  background: var(--color-primary-light, #fff7ed);
  outline: 2px dashed var(--color-primary);
  outline-offset: -4px;
}

/* Compose Attachments List (user-added) */
.compose-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 16px;
  background: var(--color-surface-secondary, #f8fafc);
  border-bottom: 1px solid var(--color-border-light, #f1f5f9);
}

.compose-attachments[hidden] {
  display: none;
}

.compose-attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 20px;
  font-size: 12px;
  color: var(--color-text);
  transition: all 150ms ease;
}

.compose-attachment-chip:hover {
  background: var(--color-slate-100);
  border-color: var(--color-slate-300);
}

.compose-attachment-chip__icon {
  font-size: 14px;
  line-height: 1;
}

.compose-attachment-chip__name {
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.compose-attachment-chip__size {
  color: var(--color-text-muted, #94a3b8);
  font-size: 11px;
}

.compose-attachment-chip__remove {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: 50%;
  color: var(--color-text-muted, #94a3b8);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  transition: all 150ms ease;
}

.compose-attachment-chip__remove:hover {
  background: var(--color-error-light, #fef2f2);
  color: var(--color-error, #ef4444);
}

/* Attachment count badge in toolbar */
.compose-toolbar__btn--attach {
  position: relative;
}

.compose-toolbar__attach-count {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  background: var(--color-primary);
  color: white;
  font-size: 10px;
  font-weight: 600;
  line-height: 16px;
  text-align: center;
  border-radius: 8px;
}

.compose-toolbar__attach-count[hidden] {
  display: none;
}

/* Original Email Preview */
.compose-original {
  border-top: 1px solid var(--color-border);
  background: var(--color-surface-secondary, #f8fafc);
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  min-height: 80px;
  overflow: hidden;
}

.compose-original__header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  cursor: pointer;
  user-select: none;
  transition: background 150ms ease;
  border-bottom: 1px solid var(--color-border-light, #f1f5f9);
}

.compose-original__header:hover {
  background: var(--color-surface);
}

.compose-original__icon {
  font-size: 14px;
  opacity: 0.7;
}

.compose-original__label {
  font-size: 12px;
  font-weight: 500;
  color: var(--color-text-secondary);
  flex: 1;
}

.compose-original__chevron {
  font-size: 10px;
  color: var(--color-text-muted);
  transition: transform 150ms ease;
}

.compose-original__preview {
  padding: 12px 16px;
  overflow-y: auto;
  background: var(--color-surface);
  flex: 1;
}

/* Hide when using hidden attribute - needs !important to override display */
.compose-original__preview[hidden] {
  display: none !important;
}

/* Outlook-style email header in preview */
.compose-original__email-header {
  padding-bottom: 12px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--color-border-light, #e2e8f0);
}

.compose-original__sender {
  font-size: 14px;
  margin-bottom: 4px;
}

.compose-original__sender strong {
  color: var(--color-text);
}

.compose-original__email-addr {
  color: var(--color-text-muted);
  font-size: 13px;
  margin-left: 4px;
}

.compose-original__date-line {
  font-size: 12px;
  color: var(--color-text-muted);
  margin-bottom: 2px;
}

.compose-original__to-line {
  font-size: 12px;
  color: var(--color-text-secondary);
}

/* Attachments section */
.compose-original__attachments {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--color-border-light, #e2e8f0);
}

.compose-original__attachments-icon {
  font-size: 14px;
  opacity: 0.7;
}

.compose-original__attachments-label {
  font-size: 12px;
  color: var(--color-text-secondary);
  white-space: nowrap;
}

.compose-original__attachments-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex: 1;
}

.compose-original__attachment {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: var(--color-surface-secondary, #f8fafc);
  border: 1px solid var(--color-border);
  border-radius: 16px;
  font-size: 12px;
  cursor: pointer;
  transition: all 150ms ease;
}

.compose-original__attachment:hover {
  background: var(--color-surface);
  border-color: var(--color-primary);
}

.compose-original__attachment-icon {
  font-size: 12px;
}

.compose-original__attachment-name {
  color: var(--color-text);
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.compose-original__attachment-size {
  color: var(--color-text-muted);
  font-size: 11px;
}

/* Download button inside attachment chip */
.compose-original__attachment-download {
  display: none;
  background: transparent;
  border: none;
  padding: 0 2px;
  font-size: 10px;
  cursor: pointer;
  opacity: 0.6;
  transition: opacity 150ms ease;
  margin-left: 4px;
}

.compose-original__attachment:hover .compose-original__attachment-download {
  display: inline-block;
}

.compose-original__attachment-download:hover {
  opacity: 1;
}

/* Download All button */
.compose-original__download-all {
  background: var(--color-surface-secondary, #f8fafc);
  border: 1px solid var(--color-border);
  border-radius: 16px;
  padding: 4px 12px;
  font-size: 11px;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: all 150ms ease;
  white-space: nowrap;
}

.compose-original__download-all:hover {
  background: var(--color-surface);
  border-color: var(--color-primary);
  color: var(--color-primary);
}

/* Loading state for attachment */
.compose-original__attachment--loading {
  opacity: 0.6;
  pointer-events: none;
  position: relative;
}

.compose-original__attachment--loading::after {
  content: '';
  position: absolute;
  width: 12px;
  height: 12px;
  border: 2px solid var(--color-primary);
  border-top-color: transparent;
  border-radius: 50%;
  animation: attachment-spin 0.8s linear infinite;
  right: 8px;
}

@keyframes attachment-spin {
  to { transform: rotate(360deg); }
}

/* Email body - preserve HTML formatting */
.compose-original__body {
  font-size: 14px;
  line-height: 1.6;
  color: var(--color-text);
}

/* Style elements within the email body */
.compose-original__body p {
  margin: 0 0 1em 0;
}

.compose-original__body a {
  color: var(--color-primary);
  text-decoration: underline;
}

.compose-original__body img {
  max-width: 100%;
  height: auto;
}

.compose-original__body table {
  border-collapse: collapse;
  max-width: 100%;
}

.compose-original__body blockquote {
  margin: 8px 0;
  padding-left: 12px;
  border-left: 3px solid var(--color-border);
  color: var(--color-text-secondary);
}

/* Signature styling */
.compose-original__body .signature,
.compose-original__body [class*="signature"] {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--color-border-light, #e2e8f0);
  color: var(--color-text-secondary);
  font-size: 13px;
}

/* Expanded state - show more content */
.compose-original__full {
  flex: 1;
}

/* Legacy text styles (fallback) */
.compose-original__meta {
  font-size: 12px;
  color: var(--color-text-secondary);
  margin-bottom: 6px;
}

.compose-original__meta strong {
  color: var(--color-text);
}

.compose-original__email {
  color: var(--color-text-muted);
  margin-left: 4px;
}

.compose-original__date {
  color: var(--color-text-muted);
  margin-left: 8px;
}

.compose-original__text {
  font-size: 13px;
  line-height: 1.5;
  color: var(--color-text-secondary);
  white-space: pre-wrap;
}

/* Footer Actions */
.compose-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 18px;
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
  flex-shrink: 0;
  gap: 5px;
}

.compose-footer__left,
.compose-footer__center,
.compose-footer__right {
  display: flex;
  align-items: center;
  gap: 5px;
}

.compose-footer__right {
  margin-left: auto;
}

.compose-footer__btn {
  padding: 6px 13px;
  font-size: 12px;
  font-weight: 500;
  border-radius: 6px;
  cursor: pointer;
  transition: all 150ms ease;
}

.compose-footer__btn--send {
  background: var(--color-primary);
  color: #fff;
  border: none;
  font-weight: 600;
}

.compose-footer__btn--send:hover {
  background: var(--color-primary-dark, #1d4ed8);
}

.compose-footer__btn--send.is-confirm {
  background: var(--color-warning, #f59e0b);
  color: #fff;
  animation: pulse-confirm 600ms ease-in-out infinite alternate;
}

@keyframes pulse-confirm {
  from { opacity: 1; }
  to   { opacity: 0.8; }
}

.compose-footer__btn--secondary {
  background: none;
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border);
}

.compose-footer__btn--secondary:hover {
  border-color: var(--color-text-muted, #94a3b8);
  color: var(--color-text);
}

.compose-footer__btn--text {
  background: transparent;
  color: var(--color-text-secondary);
  border: none;
}

.compose-footer__btn--text:hover {
  color: var(--color-text);
  background: var(--color-surface-secondary, #f8fafc);
}

.compose-footer__btn--danger {
  background: none;
  color: var(--color-error, #dc2626);
  border: 1px solid var(--color-border);
}

.compose-footer__btn--danger:hover {
  background: var(--color-error, #dc2626);
  color: white;
  border-color: var(--color-error, #dc2626);
}

.compose-footer__guardian {
  font-size: 11px;
  color: var(--color-success, #16a34a);
  display: flex;
  align-items: center;
  gap: 3px;
}

/* Responsive */
@media (max-width: 768px) {
  .compose-options {
    padding: 10px 12px;
  }
  
  .compose-field {
    padding: 8px 12px;
  }
  
  .compose-field__label {
    width: 50px;
  }
  
  .compose-toolbar {
    padding: 3px 10px;
  }
  
  .compose-editor {
    padding: 12px;
    min-height: 100px;
  }
  
  .compose-footer {
    padding: 8px 14px;
  }
  
  .compose-footer__btn {
    padding: 5px 10px;
    font-size: 11px;
  }
}
/* ============================================
   CHAT REFINEMENT PANEL
   ============================================ */

.chat-refinement {
  border-top: 1px solid var(--color-border-light, #f1f5f9);
  background: var(--color-surface-secondary, #f8fafc);
}

.chat-refinement__header {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 7px 18px;
  cursor: pointer;
}

.chat-refinement__header:hover {
  background: none;
}

.chat-refinement__icon {
  font-size: 11px;
}

.chat-refinement__inline-input {
  flex: 1;
  min-width: 160px;
  padding: 5px 9px;
  border-radius: 5px;
  border: 1px solid var(--color-border, rgba(0, 0, 0, 0.08));
  font-size: 12px;
  outline: none;
  font-family: inherit;
  background: var(--color-surface, #fff);
  color: var(--color-text);
}

.chat-refinement__inline-input:focus {
  border-color: var(--color-primary, #2563eb);
}

.chat-refinement__label {
  font-size: 11px;
  font-weight: 600;
  color: var(--color-primary, #2563eb);
  white-space: nowrap;
}

.chat-refinement__quick-actions {
  display: flex;
  gap: 10px;
  margin-left: 0;
  margin-right: 0;
}

.chat-refinement__quick-btn {
  padding: 0;
  font-size: 12px;
  font-weight: 400;
  background: none;
  border: none;
  color: var(--color-text-secondary, #64748b);
  cursor: pointer;
  text-decoration: underline dotted;
  text-underline-offset: 3px;
  transition: color 0.1s ease;
}

.chat-refinement__quick-btn:hover {
  color: var(--color-primary, #2563eb);
}

.chat-refinement__chevron {
  font-size: 10px;
  color: var(--color-text-muted);
  transition: transform 150ms ease;
}

/* Expanded body */
.chat-refinement__body {
  padding: 0 16px 12px 16px;
}

/* Messages container */
.chat-refinement__messages {
  max-height: 150px;
  overflow-y: auto;
  margin-bottom: 10px;
  padding: 8px;
  background: var(--color-surface, #fff);
  border-radius: 8px;
  border: 1px solid var(--color-border-light, #e2e8f0);
}

.chat-refinement__messages:empty {
  display: none;
}

.chat-history-toggle {
  display: block;
  width: 100%;
  padding: 4px 0;
  margin-bottom: 4px;
  background: none;
  border: none;
  border-bottom: 1px solid var(--color-border-light, #e2e8f0);
  font-size: 11px;
  color: var(--color-primary, #2563EB);
  cursor: pointer;
  text-align: left;
}

.chat-history-toggle:hover {
  text-decoration: underline;
}

/* Individual chat message */
.chat-message {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 6px 0;
  font-size: 12px;
  line-height: 1.4;
}

.chat-message + .chat-message {
  border-top: 1px solid var(--color-border-light, #e2e8f0);
}

.chat-message__icon {
  flex-shrink: 0;
  font-size: 12px;
}

.chat-message__content {
  flex: 1;
  color: var(--color-text);
}

.chat-message--user .chat-message__content {
  color: var(--color-text);
}

.chat-message--assistant .chat-message__content {
  color: var(--color-text-secondary);
}

.chat-message--system .chat-message__content {
  color: var(--color-text-muted);
  font-style: italic;
}

.chat-message--processing .chat-message__content {
  color: var(--color-primary);
}

.chat-message--processing .chat-message__content::after {
  content: '';
  display: inline-block;
  width: 4px;
  height: 4px;
  margin-left: 4px;
  background: var(--color-primary);
  border-radius: 50%;
  animation: chat-pulse 1s ease-in-out infinite;
}

@keyframes chat-pulse {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; }
}

/* Input row */
.chat-refinement__input-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.chat-refinement__input {
  flex: 1;
  padding: 8px 12px;
  font-size: 13px;
  border: 1px solid var(--color-border);
  border-radius: 20px;
  background: var(--color-surface, #fff);
  outline: none;
  transition: border-color 150ms ease;
}

.chat-refinement__input:focus {
  border-color: var(--color-primary);
}

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

.chat-refinement__send-btn {
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: 20px;
  cursor: pointer;
  transition: background 150ms ease;
}

.chat-refinement__send-btn:hover {
  background: var(--color-primary-dark, #2563eb);
}

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

/* Preset buttons */
.chat-refinement__presets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chat-refinement__preset {
  padding: 4px 10px;
  font-size: 11px;
  background: var(--color-surface, #fff);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: all 150ms ease;
}

.chat-refinement__preset:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
  background: var(--color-primary-muted, #eff6ff);
}

.chat-refinement__preset--undo {
  background: var(--color-background-alt, #f5f5f5);
  border-color: var(--color-border);
  color: var(--color-text);
  font-weight: 500;
}

.chat-refinement__preset--undo:hover {
  background: #e8e8e8;
  border-color: #999;
  color: var(--color-text);
}

/* Mobile responsive */
@media (max-width: 640px) {
  .chat-refinement__quick-actions {
    display: none;
  }
  
  .chat-refinement__presets {
    gap: 4px;
  }
  
  .chat-refinement__preset {
    padding: 3px 8px;
    font-size: 10px;
  }
}

/* ========================================
   TRANSITIONS & ANIMATIONS
   ======================================== */

/* Smooth transitions for buttons */
.compose-footer__btn,
.compose-toolbar__btn,
.compose-toolbar__color-btn,
.compose-toolbar__select,
.chat-refinement__preset,
.chat-refinement__send-btn,
.compose-header__toggle {
  transition: all 0.2s ease;
}

/* Smooth panel expansion */
.chat-refinement__body {
  transition: max-height 0.3s ease, opacity 0.3s ease;
  overflow: hidden;
}

.chat-refinement__body[hidden] {
  max-height: 0;
  opacity: 0;
}

.chat-refinement__body:not([hidden]) {
  max-height: 500px;
  opacity: 1;
}

/* Chevron rotation animation */
.chat-refinement__chevron,
.compose-original__chevron {
  transition: transform 0.3s ease;
}

/* Loading spinner for send/save actions */
@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.compose-footer__btn--loading::after {
  content: '';
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-left: 8px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

/* Fade-in for tabs */
.reading-pane-tabs {
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Slide-in for chat messages */
.chat-message {
  animation: slideIn 0.2s ease;
}

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

/* ----------------------------------------
   GUARDIAN RISK OVERLAY
   ---------------------------------------- */

/* Locked state: editor not editable */
.compose-area--risk-locked {
  position: relative;
}

.compose-area--risk-locked .compose-editor {
  pointer-events: none;
  opacity: 0.3;
  filter: blur(1px);
  user-select: none;
}

.compose-area--risk-locked .compose-toolbar {
  pointer-events: none;
  opacity: 0.3;
}

.compose-area--risk-locked .compose-footer__btn--send {
  pointer-events: none;
  opacity: 0.4;
  cursor: not-allowed;
}

.compose-area--risk-locked .compose-options {
  pointer-events: none;
  opacity: 0.3;
}

/* Risk overlay container */
.compose-risk-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  pointer-events: none;  /* Allow clicks through to overlay content only */
}

.compose-risk-overlay__card {
  pointer-events: auto;   /* Card itself is clickable */
  background: var(--color-surface);
  border-radius: 16px;
  padding: 32px;
  max-width: 380px;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
  border: 1px solid var(--color-border);
}

/* Severity-coloured top border */
.compose-risk-overlay__card--caution {
  border-top: 3px solid var(--color-error);
}

.compose-risk-overlay__card--review {
  border-top: 3px solid var(--color-warning);
}

.compose-risk-overlay__icon {
  font-size: 48px;
  margin-bottom: 16px;
}

.compose-risk-overlay__title {
  font-size: 16px;
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: 8px;
}

.compose-risk-overlay__message {
  font-size: 13px;
  color: var(--color-text-secondary);
  line-height: 1.5;
  margin-bottom: 24px;
}

.compose-risk-overlay__score {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 20px;
  margin-bottom: 20px;
}

.compose-risk-overlay__score--caution {
  background: rgba(239, 68, 68, 0.1);
  color: #dc2626;
}

.compose-risk-overlay__score--review {
  background: rgba(245, 158, 11, 0.1);
  color: #d97706;
}

.compose-risk-overlay__btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 24px;
  border: none;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.compose-risk-overlay__btn--caution {
  background: var(--color-error);
  color: #fff;
}

.compose-risk-overlay__btn--caution:hover {
  background: #dc2626;
  transform: translateY(-1px);
}

.compose-risk-overlay__btn--review {
  background: var(--color-warning);
  color: #fff;
}

.compose-risk-overlay__btn--review:hover {
  background: #d97706;
  transform: translateY(-1px);
}

/* ========================================
   OUTBOUND GUARDIAN — Send Lock Button
   ======================================== */

.compose-footer__btn--locked {
  background: #ef4444 !important;
  color: #fff !important;
  border: none !important;
  cursor: not-allowed !important;
  opacity: 0.9;
  pointer-events: none;
  animation: guardian-pulse 1.5s ease-in-out infinite;
}

@keyframes guardian-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.3); }
  50%      { box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); }
}
