/**
 * UAOL Email Module - Phase 7F/G Styles v2
 * Option B: Split Panel with Live Preview
 * 
 * Uses UAOL design system variables
 * All icons are SVG-based (no emojis)
 * 
 * Version: 2.0.0
 * Date: 27 January 2026
 */

/* ==========================================================================
   CSS VARIABLES (UAOL Dark Theme)
   ========================================================================== */

:root {
  --email-bg-primary: #0d1117;
  --email-bg-secondary: #161b22;
  --email-bg-tertiary: #21262d;
  --email-bg-elevated: #30363d;
  --email-border-color: #30363d;
  --email-border-subtle: #21262d;
  
  --email-text-primary: #f0f6fc;
  --email-text-secondary: #8b949e;
  --email-text-muted: #6e7681;
  --email-text-link: #58a6ff;
  
  --email-accent-blue: #58a6ff;
  --email-accent-blue-bg: rgba(56, 139, 253, 0.15);
  --email-accent-green: #3fb950;
  --email-accent-green-bg: rgba(46, 160, 67, 0.15);
  --email-accent-orange: #d29922;
  --email-accent-red: #f85149;
  --email-accent-red-bg: rgba(248, 81, 73, 0.15);
  
  --email-shadow-modal: 0 16px 70px rgba(0, 0, 0, 0.5);
  --email-shadow-dropdown: 0 8px 30px rgba(0, 0, 0, 0.4);
  --email-input-focus: 0 0 0 3px rgba(56, 139, 253, 0.3);
  
  --email-radius-sm: 6px;
  --email-radius-md: 10px;
  --email-radius-lg: 12px;
  --email-radius-xl: 16px;
  
  --email-transition: 0.15s ease;
}

/* Light theme overrides */
[data-theme="light"] .dm-modal.email-compose-modal,
.light-theme .dm-modal.email-compose-modal {
  --email-bg-primary: #ffffff;
  --email-bg-secondary: #f6f8fa;
  --email-bg-tertiary: #f0f2f5;
  --email-bg-elevated: #e1e4e8;
  --email-border-color: #d0d7de;
  --email-border-subtle: #e1e4e8;
  --email-text-primary: #1f2328;
  --email-text-secondary: #656d76;
  --email-text-muted: #8c959f;
  --email-shadow-modal: 0 16px 70px rgba(0, 0, 0, 0.15);
  --email-shadow-dropdown: 0 8px 30px rgba(0, 0, 0, 0.12);
}

/* ==========================================================================
   MODAL FOUNDATION
   ========================================================================== */

/* Modal visibility fix */
.dm-modal.active {
  display: flex;
  align-items: center;
  justify-content: center;
}

.dm-modal.email-compose-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10000;
  display: none;
  font-family: var(--font-sans);
}

.dm-modal.email-compose-modal.active {
  display: flex;
  align-items: center;
  justify-content: center;
}

.dm-modal.email-compose-modal .dm-modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
}

.dm-modal.email-compose-modal .dm-modal-content {
  position: relative;
  background: var(--email-bg-secondary);
  border: 1px solid var(--email-border-color);
  border-radius: var(--email-radius-xl);
  width: 920px;
  max-width: 95vw;
  max-height: 90vh;
  overflow: hidden;
  box-shadow: var(--email-shadow-modal);
  display: flex;
  flex-direction: column;
  z-index: 1;
}

/* ==========================================================================
   MODAL HEADER
   ========================================================================== */

.email-modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--email-border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  background: var(--email-bg-secondary);
}

.email-modal-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  font-weight: 600;
  color: var(--email-text-primary);
  margin: 0;
}

.email-modal-title svg {
  width: 18px;
  height: 18px;
  color: var(--email-accent-blue);
}

.email-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.email-icon-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--email-radius-sm);
  border: none;
  background: transparent;
  color: var(--email-text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--email-transition);
  padding: 0;
}

.email-icon-btn svg {
  width: 16px;
  height: 16px;
}

.email-icon-btn:hover {
  background: var(--email-bg-tertiary);
  color: var(--email-text-primary);
}

.email-icon-btn.close-btn:hover {
  background: var(--email-accent-red-bg);
  color: var(--email-accent-red);
}

/* ==========================================================================
   SPLIT PANEL LAYOUT
   ========================================================================== */

.email-modal-body {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

.email-compose-panel {
  flex: 1;
  min-width: 0;
  padding: 20px;
  overflow-y: auto;
  border-right: 1px solid var(--email-border-subtle);
}

.email-preview-panel {
  width: 340px;
  flex-shrink: 0;
  background: var(--email-bg-primary);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ==========================================================================
   COMPOSE FORM FIELDS
   ========================================================================== */

.email-form-group {
  margin-bottom: 14px;
}

.email-form-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--email-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

/* From Account Selector */
.email-account-selector {
  position: relative;
}

.email-account-selected {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--email-bg-tertiary);
  border: 1px solid var(--email-border-color);
  border-radius: var(--email-radius-md);
  cursor: pointer;
  transition: var(--email-transition);
}

.email-account-selected:hover {
  border-color: var(--email-text-muted);
}

.email-account-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--email-radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 12px;
  color: white;
  flex-shrink: 0;
}

.email-account-avatar.gmail {
  background: linear-gradient(135deg, #EA4335, #FBBC05);
}

.email-account-avatar.m365 {
  background: linear-gradient(135deg, #0078D4, #00BCF2);
}

.email-account-info {
  flex: 1;
  min-width: 0;
}

.email-account-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--email-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.email-account-address {
  font-size: 11px;
  color: var(--email-text-secondary);
}

.email-rate-badge {
  font-size: 10px;
  padding: 3px 8px;
  border-radius: 4px;
  background: var(--email-accent-green-bg);
  color: var(--email-accent-green);
  font-weight: 600;
  white-space: nowrap;
}

.email-rate-badge.low {
  background: rgba(210, 153, 34, 0.15);
  color: var(--email-accent-orange);
}

.email-rate-badge.critical {
  background: var(--email-accent-red-bg);
  color: var(--email-accent-red);
}

.email-dropdown-arrow {
  color: var(--email-text-muted);
  flex-shrink: 0;
}

.email-dropdown-arrow svg {
  width: 16px;
  height: 16px;
}

/* Account Dropdown Menu */
.email-account-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 4px;
  background: var(--email-bg-secondary);
  border: 1px solid var(--email-border-color);
  border-radius: var(--email-radius-md);
  box-shadow: var(--email-shadow-dropdown);
  z-index: 100;
  display: none;
  max-height: 240px;
  overflow-y: auto;
}

.email-account-dropdown.open {
  display: block;
}

.email-account-option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  cursor: pointer;
  transition: var(--email-transition);
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
}

.email-account-option:hover {
  background: var(--email-bg-tertiary);
}

.email-account-option.selected {
  background: var(--email-accent-blue-bg);
}

.email-account-option.disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Recipient Fields */
.email-recipient-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 10px;
}

.email-recipient-label {
  width: 36px;
  padding-top: 11px;
  font-size: 12px;
  font-weight: 500;
  color: var(--email-text-secondary);
  flex-shrink: 0;
}

.email-recipient-input-wrap {
  flex: 1;
  min-height: 40px;
  padding: 6px 10px;
  background: var(--email-bg-tertiary);
  border: 1px solid var(--email-border-color);
  border-radius: var(--email-radius-md);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  transition: var(--email-transition);
}

.email-recipient-input-wrap:focus-within {
  border-color: var(--email-accent-blue);
  box-shadow: var(--email-input-focus);
}

.email-recipient-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--email-bg-elevated);
  border-radius: var(--email-radius-sm);
  font-size: 13px;
  color: var(--email-text-primary);
}

.email-recipient-chip .remove {
  width: 18px;
  height: 18px;
  border: none;
  background: var(--email-bg-tertiary);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--email-text-muted);
  transition: var(--email-transition);
  font-size: 13px;
  line-height: 1;
  padding: 0;
}

.email-recipient-chip .remove:hover {
  background: var(--email-accent-red-bg);
  color: var(--email-accent-red);
}

.email-recipient-input {
  flex: 1;
  min-width: 120px;
  background: transparent;
  border: none;
  outline: none;
  font-size: 13px;
  color: var(--email-text-primary);
  font-family: inherit;
}

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

/* Bulk Recipients Badge */
.email-bulk-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--email-accent-blue-bg);
  border-radius: var(--email-radius-sm);
  font-size: 13px;
  font-weight: 500;
  color: var(--email-accent-blue);
}

.email-bulk-badge svg {
  width: 14px;
  height: 14px;
}

/* CC/BCC Toggle */
.email-cc-toggle {
  margin-left: 46px;
  margin-bottom: 10px;
}

.email-cc-toggle-btn {
  font-size: 12px;
  color: var(--email-accent-blue);
  cursor: pointer;
  background: transparent;
  border: none;
  padding: 4px 0;
  font-family: inherit;
}

.email-cc-toggle-btn:hover {
  text-decoration: underline;
}

.email-cc-fields {
  display: none;
}

.email-cc-fields.visible {
  display: block;
}

/* Subject Field */
.email-subject-input {
  width: 100%;
  padding: 11px 12px;
  background: var(--email-bg-tertiary);
  border: 1px solid var(--email-border-color);
  border-radius: var(--email-radius-md);
  font-size: 14px;
  font-weight: 500;
  color: var(--email-text-primary);
  transition: var(--email-transition);
  font-family: inherit;
}

.email-subject-input:focus {
  outline: none;
  border-color: var(--email-accent-blue);
  box-shadow: var(--email-input-focus);
}

.email-subject-input::placeholder {
  color: var(--email-text-muted);
  font-weight: 400;
}

/* Template & Signature Row */
.email-presets-row {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
}

.email-preset-select {
  flex: 1;
  position: relative;
}

.email-preset-btn {
  width: 100%;
  padding: 9px 12px;
  background: var(--email-bg-tertiary);
  border: 1px solid var(--email-border-color);
  border-radius: var(--email-radius-md);
  font-size: 12px;
  color: var(--email-text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: var(--email-transition);
  font-family: inherit;
  text-align: left;
}

.email-preset-btn:hover {
  border-color: var(--email-text-muted);
}

.email-preset-btn svg {
  width: 14px;
  height: 14px;
  color: var(--email-text-muted);
  flex-shrink: 0;
}

.email-preset-btn .preset-icon {
  margin-right: 6px;
}

/* ==========================================================================
   RICH TEXT EDITOR
   ========================================================================== */

.email-editor-wrap {
  border: 1px solid var(--email-border-color);
  border-radius: var(--email-radius-lg);
  overflow: hidden;
  background: var(--email-bg-tertiary);
}

.email-editor-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 8px 10px;
  background: var(--email-bg-secondary);
  border-bottom: 1px solid var(--email-border-subtle);
  flex-wrap: wrap;
}

.email-toolbar-group {
  display: flex;
  align-items: center;
  gap: 2px;
}

.email-toolbar-divider {
  width: 1px;
  height: 20px;
  background: var(--email-border-color);
  margin: 0 6px;
}

.email-toolbar-btn {
  width: 30px;
  height: 30px;
  border: none;
  background: transparent;
  border-radius: var(--email-radius-sm);
  color: var(--email-text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--email-transition);
  font-size: 13px;
  padding: 0;
}

.email-toolbar-btn svg {
  width: 16px;
  height: 16px;
}

.email-toolbar-btn:hover {
  background: var(--email-bg-tertiary);
  color: var(--email-text-primary);
}

.email-toolbar-btn.active {
  background: var(--email-accent-blue-bg);
  color: var(--email-accent-blue);
}

/* Insert Field Button */
.email-insert-field-btn {
  padding: 5px 10px;
  width: auto;
  gap: 5px;
  font-size: 11px;
  font-weight: 500;
  background: var(--email-bg-tertiary);
  border: 1px solid var(--email-border-color);
  margin-left: auto;
}

.email-insert-field-btn:hover {
  background: var(--email-bg-elevated);
  border-color: var(--email-accent-blue);
  color: var(--email-accent-blue);
}

/* Merge Field Popover */
.email-merge-popover {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 6px;
  background: var(--email-bg-secondary);
  border: 1px solid var(--email-border-color);
  border-radius: var(--email-radius-lg);
  box-shadow: var(--email-shadow-dropdown);
  width: 260px;
  z-index: 100;
  padding: 6px;
  display: none;
}

.email-merge-popover.open {
  display: block;
}

.email-merge-section {
  padding: 6px 10px;
  font-size: 10px;
  font-weight: 600;
  color: var(--email-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.email-merge-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--email-radius-sm);
  cursor: pointer;
  transition: var(--email-transition);
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  font-family: inherit;
}

.email-merge-item:hover {
  background: var(--email-bg-tertiary);
}

.email-merge-icon {
  width: 28px;
  height: 28px;
  border-radius: var(--email-radius-sm);
  background: var(--email-accent-blue-bg);
  color: var(--email-accent-blue);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.email-merge-icon svg {
  width: 14px;
  height: 14px;
}

.email-merge-info {
  flex: 1;
  min-width: 0;
}

.email-merge-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--email-text-primary);
  margin-bottom: 1px;
}

.email-merge-code {
  font-size: 10px;
  color: var(--email-text-muted);
  font-family: var(--font-mono);
}

/* Editor Content */
.email-editor-content {
  min-height: 180px;
  max-height: 280px;
  overflow-y: auto;
  padding: 14px;
}

/* Quill overrides */
.email-editor-wrap .ql-container {
  border: none !important;
  font-family: var(--font-sans) !important;
  font-size: 14px !important;
}

.email-editor-wrap .ql-editor {
  padding: 14px !important;
  min-height: 180px !important;
  max-height: 280px !important;
  color: var(--email-text-primary) !important;
  line-height: 1.6 !important;
}

.email-editor-wrap .ql-editor.ql-blank::before {
  color: var(--email-text-muted) !important;
  font-style: normal !important;
}

.email-editor-wrap .ql-toolbar {
  display: none !important;
}

.email-editor-wrap .ql-editor p {
  margin-bottom: 10px;
}

/* ==========================================================================
   PREVIEW PANEL
   ========================================================================== */

.email-preview-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--email-border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.email-preview-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--email-text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
}

.email-preview-title svg {
  width: 14px;
  height: 14px;
}

.email-preview-tabs {
  display: flex;
  gap: 4px;
}

.email-preview-tab {
  padding: 5px 10px;
  border-radius: var(--email-radius-sm);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  background: transparent;
  border: none;
  color: var(--email-text-muted);
  transition: var(--email-transition);
  font-family: inherit;
}

.email-preview-tab:hover {
  color: var(--email-text-secondary);
}

.email-preview-tab.active {
  background: var(--email-bg-tertiary);
  color: var(--email-text-primary);
}

.email-preview-content {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
}

.email-preview-mock {
  background: var(--email-bg-secondary, #ffffff);
  border-radius: var(--email-radius-md);
  padding: 16px;
  font-family: var(--font-sans);
  color: var(--email-text-primary, #1a1a1a);
  font-size: 13px;
  line-height: 1.5;
}

.email-preview-from {
  font-size: 12px;
  color: var(--email-text-muted, #666);
  margin-bottom: 4px;
}

.email-preview-subject {
  font-size: 14px;
  font-weight: 600;
  color: var(--email-text-primary, #1a1a1a);
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--email-border-color, #eee);
}

.email-preview-body {
  font-size: 13px;
  line-height: 1.6;
}

.email-preview-body p {
  margin: 0 0 10px 0;
}

/* Mobile Preview */
.email-preview-content.mobile .email-preview-mock {
  max-width: 280px;
  margin: 0 auto;
  font-size: 12px;
}

/* Empty Preview State */
.email-preview-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 200px;
  color: var(--email-text-muted);
  text-align: center;
}

.email-preview-empty svg {
  width: 40px;
  height: 40px;
  margin-bottom: 12px;
  opacity: 0.5;
}

.email-preview-empty span {
  font-size: 13px;
}

/* ==========================================================================
   MODAL FOOTER
   ========================================================================== */

.email-modal-footer {
  padding: 14px 20px;
  background: var(--email-bg-secondary);
  border-top: 1px solid var(--email-border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.email-footer-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.email-footer-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: var(--email-radius-sm);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--email-transition);
  border: 1px solid transparent;
  font-family: inherit;
}

.email-footer-btn svg {
  width: 14px;
  height: 14px;
}

.email-footer-btn.secondary {
  background: transparent;
  color: var(--email-text-secondary);
  border-color: var(--email-border-color);
}

.email-footer-btn.secondary:hover {
  background: var(--email-bg-tertiary);
  color: var(--email-text-primary);
}

.email-footer-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.email-btn-cancel {
  padding: 9px 18px;
  border-radius: var(--email-radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  background: transparent;
  border: 1px solid var(--email-border-color);
  color: var(--email-text-secondary);
  transition: var(--email-transition);
  font-family: inherit;
}

.email-btn-cancel:hover {
  background: var(--email-bg-tertiary);
  color: var(--email-text-primary);
}

.email-btn-send {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 20px;
  border-radius: var(--email-radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  background: var(--email-accent-blue);
  border: none;
  color: white;
  transition: var(--email-transition);
  font-family: inherit;
}

.email-btn-send svg {
  width: 14px;
  height: 14px;
}

.email-btn-send:hover {
  background: #4a9eff;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(88, 166, 255, 0.3);
}

.email-btn-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* ==========================================================================
   TEMPLATE/SIGNATURE EDITOR MODALS
   ========================================================================== */

.dm-modal.email-template-modal .dm-modal-content,
.dm-modal.email-signature-modal .dm-modal-content {
  width: 700px;
}

/* ==========================================================================
   BULK EMAIL CONFIRMATION MODAL
   ========================================================================== */

.dm-modal.email-bulk-confirm-modal .dm-modal-content {
  width: 480px;
}

.email-bulk-summary {
  background: var(--email-bg-tertiary);
  border-radius: var(--email-radius-md);
  padding: 16px;
  margin-bottom: 16px;
}

.email-bulk-stat {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  font-size: 13px;
  border-bottom: 1px solid var(--email-border-subtle);
}

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

.email-bulk-stat-label {
  color: var(--email-text-secondary);
}

.email-bulk-stat-value {
  color: var(--email-text-primary);
  font-weight: 500;
}

.email-bulk-warning {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px;
  background: rgba(210, 153, 34, 0.1);
  border-radius: var(--email-radius-sm);
  font-size: 12px;
  color: var(--email-accent-orange);
}

.email-bulk-warning svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  margin-top: 1px;
}

/* ==========================================================================
   PROGRESS INDICATOR
   ========================================================================== */

.email-progress-wrap {
  margin: 16px 0;
}

.email-progress-bar {
  height: 8px;
  background: var(--email-bg-tertiary);
  border-radius: 4px;
  overflow: hidden;
}

.email-progress-fill {
  height: 100%;
  background: var(--email-accent-blue);
  border-radius: 4px;
  transition: width 0.3s ease;
}

.email-progress-fill.complete {
  background: var(--email-accent-green);
}

.email-progress-fill.error {
  background: var(--email-accent-red);
}

.email-progress-stats {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  font-size: 12px;
  color: var(--email-text-secondary);
}

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

@media (max-width: 960px) {
  .dm-modal.email-compose-modal .dm-modal-content {
    width: 95vw;
  }
  
  .email-preview-panel {
    width: 300px;
  }
}

@media (max-width: 768px) {
  .email-modal-body {
    flex-direction: column;
  }
  
  .email-compose-panel {
    border-right: none;
    border-bottom: 1px solid var(--email-border-subtle);
  }
  
  .email-preview-panel {
    width: 100%;
    max-height: 300px;
  }
  
  .email-presets-row {
    flex-direction: column;
    gap: 8px;
  }
}

/* ==========================================================================
   SVG ICON UTILITIES
   ========================================================================== */

.email-svg-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.email-svg-icon svg {
  width: 16px;
  height: 16px;
}

/* Hide old emoji-based elements if they exist */
.email-merge-field-btn span:first-child:not(.email-svg-icon),
.email-preset-btn span:first-child:not(.preset-icon) {
  display: none;
}
/**
 * UAOL Email v2 - CSS Patch
 * Fixes: selector targeting, light theme, visibility issues
 * 
 * Apply after email.css
 */

/* ==========================================================================
   SELECTOR FIXES - Target by ID instead of class
   ========================================================================== */

/* Modal visibility - use ID selector */
#dm-compose-email-modal {
  font-family: var(--font-sans);
}

#dm-compose-email-modal.active {
  display: flex !important;
  align-items: center;
  justify-content: center;
}

/* ==========================================================================
   LIGHT THEME FIXES
   ========================================================================== */

/* Detect light theme from body or html */
body:not(.dark-theme) #dm-compose-email-modal,
html:not(.dark-theme) #dm-compose-email-modal,
[data-theme="light"] #dm-compose-email-modal,
.light-theme #dm-compose-email-modal {
  --email-bg-primary: #ffffff;
  --email-bg-secondary: #f6f8fa;
  --email-bg-tertiary: #f0f2f5;
  --email-bg-elevated: #e1e4e8;
  --email-border-color: #d0d7de;
  --email-border-subtle: #e1e4e8;
  --email-text-primary: #1f2328;
  --email-text-secondary: #656d76;
  --email-text-muted: #8c959f;
  --email-shadow-modal: 0 16px 70px rgba(0, 0, 0, 0.15);
  --email-shadow-dropdown: 0 8px 30px rgba(0, 0, 0, 0.12);
}

/* Force light theme colors if not in dark mode */
@media (prefers-color-scheme: light) {
  #dm-compose-email-modal {
    --email-bg-primary: #ffffff;
    --email-bg-secondary: #f6f8fa;
    --email-bg-tertiary: #f0f2f5;
    --email-bg-elevated: #e1e4e8;
    --email-border-color: #d0d7de;
    --email-border-subtle: #e1e4e8;
    --email-text-primary: #1f2328;
    --email-text-secondary: #656d76;
    --email-text-muted: #8c959f;
  }
}

/* ==========================================================================
   PRESET BUTTONS FIX (Template/Signature)
   ========================================================================== */

.email-presets-row {
  display: flex !important;
  gap: 10px;
  margin-bottom: 14px;
}

.email-preset-select {
  flex: 1;
  position: relative;
}

.email-preset-btn {
  width: 100%;
  padding: 10px 14px;
  background: var(--email-bg-tertiary, #f0f2f5);
  border: 1px solid var(--email-border-color, #d0d7de);
  border-radius: 8px;
  font-size: 13px;
  color: var(--email-text-primary, #1f2328);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: all 0.15s ease;
  font-family: inherit;
  text-align: left;
  min-height: 42px;
}

.email-preset-btn:hover {
  border-color: var(--email-text-muted, #8c959f);
  background: var(--email-bg-elevated, #e1e4e8);
}

.email-preset-btn span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.email-preset-btn .preset-icon {
  display: inline-flex;
  width: 16px;
  height: 16px;
}

.email-preset-btn .preset-icon svg {
  width: 16px;
  height: 16px;
}

.email-preset-btn > svg {
  width: 16px;
  height: 16px;
  color: var(--email-text-muted, #8c959f);
  flex-shrink: 0;
}

/* Dropdown menu for presets */
.email-account-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 4px;
  background: var(--email-bg-secondary, #f6f8fa);
  border: 1px solid var(--email-border-color, #d0d7de);
  border-radius: 10px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
  z-index: 1000;
  display: none;
  max-height: 280px;
  overflow-y: auto;
}

.email-account-dropdown.open {
  display: block;
}

/* ==========================================================================
   PREVIEW TABS FIX
   ========================================================================== */

.email-preview-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--email-border-subtle, #e1e4e8);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  background: var(--email-bg-primary, #ffffff);
}

.email-preview-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--email-text-secondary, #656d76);
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
}

.email-preview-title svg {
  width: 14px;
  height: 14px;
}

.email-preview-tabs {
  display: flex !important;
  gap: 4px;
}

.email-preview-tab {
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  background: transparent;
  border: 1px solid transparent;
  color: var(--email-text-muted, #8c959f);
  transition: all 0.15s ease;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  min-height: 32px;
}

.email-preview-tab svg {
  width: 16px;
  height: 16px;
}

.email-preview-tab:hover {
  color: var(--email-text-secondary, #656d76);
  background: var(--email-bg-tertiary, #f0f2f5);
}

.email-preview-tab.active {
  background: var(--email-bg-tertiary, #f0f2f5);
  color: var(--email-text-primary, #1f2328);
  border-color: var(--email-border-color, #d0d7de);
}

/* ==========================================================================
   MERGE FIELD POPOVER FIX
   ========================================================================== */

.email-merge-popover {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 6px;
  background: var(--email-bg-secondary, #f6f8fa);
  border: 1px solid var(--email-border-color, #d0d7de);
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
  width: 280px;
  z-index: 1000;
  padding: 8px;
  display: none;
}

.email-merge-popover.open {
  display: block;
}

/* ==========================================================================
   SVG ICON VISIBILITY
   ========================================================================== */

.email-modal-title svg,
.email-icon-btn svg,
.email-toolbar-btn svg,
.email-footer-btn svg,
.email-btn-send svg,
.email-merge-icon svg,
.email-bulk-badge svg {
  display: inline-block;
  vertical-align: middle;
  width: 16px;
  height: 16px;
}

/* Ensure SVGs in buttons are visible */
button svg {
  pointer-events: none;
}

/* ==========================================================================
   QUILL EDITOR LIGHT THEME
   ========================================================================== */

#dm-compose-email-modal .ql-editor {
  color: var(--email-text-primary, #1f2328) !important;
  background: var(--email-bg-tertiary, #f0f2f5) !important;
}

#dm-compose-email-modal .ql-editor.ql-blank::before {
  color: var(--email-text-muted, #8c959f) !important;
}

/* ==========================================================================
   PREVIEW PANEL BACKGROUND
   ========================================================================== */

.email-preview-panel {
  background: var(--email-bg-primary, #ffffff);
}

.email-preview-content {
  background: var(--email-bg-tertiary, #f0f2f5);
  flex: 1;
  padding: 16px;
  overflow-y: auto;
}

/* ==========================================================================
   FORM LABEL VISIBILITY
   ========================================================================== */

.email-form-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--email-text-muted, #8c959f);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

/* ==========================================================================
   FONT SELECTOR DROPDOWNS
   ========================================================================== */

.email-font-select {
  padding: 6px 10px;
  background: var(--email-bg-tertiary, #f0f2f5);
  border: 1px solid var(--email-border-color, #d0d7de);
  border-radius: 6px;
  font-size: 12px;
  color: var(--email-text-primary, #1f2328);
  cursor: pointer;
  font-family: inherit;
  min-width: 100px;
  outline: none;
  transition: all 0.15s ease;
}

.email-font-select:hover {
  border-color: var(--email-text-muted, #8c959f);
}

.email-font-select:focus {
  border-color: var(--email-accent-blue, #58a6ff);
  box-shadow: 0 0 0 3px rgba(56, 139, 253, 0.15);
}

.email-font-select.email-font-size {
  min-width: 80px;
}

/* ==========================================================================
   PRESET BUTTON FIXES (Template/Signature)
   ========================================================================== */

.email-presets-row {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}

.email-preset-select {
  flex: 1;
  position: relative;
}

.email-preset-btn {
  width: 100%;
  padding: 10px 14px;
  background: var(--email-bg-tertiary, #f0f2f5);
  border: 1px solid var(--email-border-color, #d0d7de);
  border-radius: 8px;
  font-size: 13px;
  color: var(--email-text-primary, #1f2328);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: all 0.15s ease;
  font-family: inherit;
  text-align: left;
  gap: 8px;
}

.email-preset-btn:hover {
  border-color: var(--email-text-muted, #8c959f);
  background: var(--email-bg-elevated, #e1e4e8);
}

.email-preset-btn .preset-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.email-preset-btn .preset-arrow {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--email-text-muted, #8c959f);
  flex-shrink: 0;
}

.email-preset-btn .preset-arrow svg {
  width: 16px;
  height: 16px;
}

/* ==========================================================================
   DROPDOWN EMPTY STATE
   ========================================================================== */

.email-dropdown-empty {
  padding: 16px;
  text-align: center;
  color: var(--email-text-muted, #8c959f);
  font-size: 13px;
}

/* ==========================================================================
   NO ACCOUNTS MESSAGE
   ========================================================================== */

.email-no-accounts {
  color: var(--email-text-muted, #8c959f);
  font-size: 13px;
}

/* ==========================================================================
   INSERT FIELD BUTTON TEXT
   ========================================================================== */

.email-insert-field-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 500;
}

.email-insert-field-btn span {
  display: inline;
}

/* ==========================================================================
   FOOTER BUTTON TEXT
   ========================================================================== */

.email-footer-btn span,
.email-btn-send span {
  display: inline;
}

/* ==========================================================================
   BULK BADGE TEXT
   ========================================================================== */

.email-bulk-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.email-bulk-badge span {
  display: inline;
}
/**
 * UAOL Email v4 - CSS Patch
 * Fixes: Dark theme detection, Insert Field dropdown position, misc
 */

/* ==========================================================================
   DARK THEME DETECTION - Check multiple selectors
   ========================================================================== */

/* Default to light theme */
#dm-compose-email-modal {
  --email-bg-primary: #ffffff;
  --email-bg-secondary: #f6f8fa;
  --email-bg-tertiary: #f0f2f5;
  --email-bg-elevated: #e1e4e8;
  --email-border-color: #d0d7de;
  --email-border-subtle: #e1e4e8;
  --email-text-primary: #1f2328;
  --email-text-secondary: #656d76;
  --email-text-muted: #8c959f;
  --email-accent-blue: #0969da;
  --email-accent-blue-bg: rgba(9, 105, 218, 0.1);
  --email-accent-green: #1a7f37;
  --email-accent-green-bg: rgba(26, 127, 55, 0.1);
  --email-accent-red: #cf222e;
  --email-accent-red-bg: rgba(207, 34, 46, 0.1);
  --email-accent-orange: #9a6700;
}

/* Dark theme when body has dark class or data attribute */
body.dark-theme #dm-compose-email-modal,
body[data-theme="dark"] #dm-compose-email-modal,
html.dark-theme #dm-compose-email-modal,
html[data-theme="dark"] #dm-compose-email-modal,
.dark-mode #dm-compose-email-modal,
[data-color-mode="dark"] #dm-compose-email-modal {
  --email-bg-primary: #0d1117;
  --email-bg-secondary: #161b22;
  --email-bg-tertiary: #21262d;
  --email-bg-elevated: #30363d;
  --email-border-color: #30363d;
  --email-border-subtle: #21262d;
  --email-text-primary: #f0f6fc;
  --email-text-secondary: #8b949e;
  --email-text-muted: #6e7681;
  --email-accent-blue: #58a6ff;
  --email-accent-blue-bg: rgba(56, 139, 253, 0.15);
  --email-accent-green: #3fb950;
  --email-accent-green-bg: rgba(46, 160, 67, 0.15);
  --email-accent-red: #f85149;
  --email-accent-red-bg: rgba(248, 81, 73, 0.15);
  --email-accent-orange: #d29922;
}

/* Also check for UAOL specific dark theme indicator */
body:has(.sidebar.dark) #dm-compose-email-modal,
body:has([data-theme="dark"]) #dm-compose-email-modal {
  --email-bg-primary: #0d1117;
  --email-bg-secondary: #161b22;
  --email-bg-tertiary: #21262d;
  --email-bg-elevated: #30363d;
  --email-border-color: #30363d;
  --email-border-subtle: #21262d;
  --email-text-primary: #f0f6fc;
  --email-text-secondary: #8b949e;
  --email-text-muted: #6e7681;
  --email-accent-blue: #58a6ff;
  --email-accent-blue-bg: rgba(56, 139, 253, 0.15);
  --email-accent-green: #3fb950;
  --email-accent-green-bg: rgba(46, 160, 67, 0.15);
  --email-accent-red: #f85149;
  --email-accent-red-bg: rgba(248, 81, 73, 0.15);
  --email-accent-orange: #d29922;
}

/* Prefers dark color scheme */
@media (prefers-color-scheme: dark) {
  #dm-compose-email-modal:not([data-theme="light"]) {
    --email-bg-primary: #0d1117;
    --email-bg-secondary: #161b22;
    --email-bg-tertiary: #21262d;
    --email-bg-elevated: #30363d;
    --email-border-color: #30363d;
    --email-border-subtle: #21262d;
    --email-text-primary: #f0f6fc;
    --email-text-secondary: #8b949e;
    --email-text-muted: #6e7681;
    --email-accent-blue: #58a6ff;
    --email-accent-blue-bg: rgba(56, 139, 253, 0.15);
    --email-accent-green: #3fb950;
    --email-accent-green-bg: rgba(46, 160, 67, 0.15);
    --email-accent-red: #f85149;
    --email-accent-red-bg: rgba(248, 81, 73, 0.15);
    --email-accent-orange: #d29922;
  }
}

/* ==========================================================================
   MERGE FIELD POPOVER - Position ABOVE the button
   ========================================================================== */

.email-merge-popover {
  position: absolute;
  bottom: 100%;  /* Position above */
  top: auto;
  right: 0;
  margin-bottom: 8px;
  margin-top: 0;
  background: var(--email-bg-secondary);
  border: 1px solid var(--email-border-color);
  border-radius: 12px;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.25);
  width: 280px;
  max-height: 320px;
  overflow-y: auto;
  z-index: 10001;
  padding: 8px;
  display: none;
}

.email-merge-popover.open {
  display: block;
}

/* Ensure toolbar group has relative positioning */
.email-editor-toolbar .email-toolbar-group {
  position: relative;
}

/* ==========================================================================
   MODAL CONTENT - Allow overflow for dropdowns
   ========================================================================== */

#dm-compose-email-modal .dm-modal-content {
  overflow: visible;
}

#dm-compose-email-modal .email-modal-body {
  overflow: visible;
}

#dm-compose-email-modal .email-compose-panel {
  overflow-y: auto;
  overflow-x: visible;
}

#dm-compose-email-modal .email-editor-wrap {
  overflow: visible;
}

#dm-compose-email-modal .email-editor-toolbar {
  overflow: visible;
}

/* ==========================================================================
   HIDDEN FILE INPUT FOR ATTACHMENTS
   ========================================================================== */

.email-attach-input {
  display: none;
}

/* Attachment list styling */
.email-attachments-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--email-border-subtle);
}

.email-attachment-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--email-bg-tertiary);
  border: 1px solid var(--email-border-color);
  border-radius: 6px;
  font-size: 12px;
  color: var(--email-text-primary);
}

.email-attachment-item .attachment-icon {
  color: var(--email-text-muted);
}

.email-attachment-item .attachment-icon svg {
  width: 14px;
  height: 14px;
}

.email-attachment-item .attachment-name {
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.email-attachment-item .attachment-size {
  color: var(--email-text-muted);
  font-size: 11px;
}

.email-attachment-item .attachment-remove {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  border: none;
  background: transparent;
  color: var(--email-text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: all 0.15s;
}

.email-attachment-item .attachment-remove:hover {
  background: var(--email-accent-red-bg);
  color: var(--email-accent-red);
}

.email-attachment-item .attachment-remove svg {
  width: 12px;
  height: 12px;
}

/* ==========================================================================
   APPLY BACKGROUND COLORS EXPLICITLY
   ========================================================================== */

#dm-compose-email-modal .dm-modal-content {
  background: var(--email-bg-secondary) !important;
}

#dm-compose-email-modal .email-modal-header {
  background: var(--email-bg-secondary);
  border-bottom-color: var(--email-border-subtle);
}

#dm-compose-email-modal .email-modal-footer {
  background: var(--email-bg-secondary);
  border-top-color: var(--email-border-subtle);
}

#dm-compose-email-modal .email-compose-panel {
  background: var(--email-bg-secondary);
  border-right-color: var(--email-border-subtle);
}

#dm-compose-email-modal .email-preview-panel {
  background: var(--email-bg-primary);
}

#dm-compose-email-modal .email-preview-header {
  background: var(--email-bg-primary);
  border-bottom-color: var(--email-border-subtle);
}

#dm-compose-email-modal .email-preview-content {
  background: var(--email-bg-tertiary);
}

#dm-compose-email-modal .email-editor-wrap {
  background: var(--email-bg-tertiary);
  border-color: var(--email-border-color);
}

#dm-compose-email-modal .email-editor-toolbar {
  background: var(--email-bg-secondary);
  border-bottom-color: var(--email-border-subtle);
}

#dm-compose-email-modal .ql-editor {
  background: var(--email-bg-tertiary) !important;
  color: var(--email-text-primary) !important;
}

#dm-compose-email-modal .email-account-selected,
#dm-compose-email-modal .email-recipient-input-wrap,
#dm-compose-email-modal .email-subject-input,
#dm-compose-email-modal .email-preset-btn,
#dm-compose-email-modal .email-font-select {
  background: var(--email-bg-tertiary);
  border-color: var(--email-border-color);
  color: var(--email-text-primary);
}

#dm-compose-email-modal .email-account-dropdown,
#dm-compose-email-modal .email-merge-popover {
  background: var(--email-bg-secondary);
  border-color: var(--email-border-color);
}

#dm-compose-email-modal .email-recipient-input {
  color: var(--email-text-primary);
}

#dm-compose-email-modal .email-recipient-input::placeholder {
  color: var(--email-text-muted);
}

#dm-compose-email-modal .email-subject-input::placeholder {
  color: var(--email-text-muted);
}

#dm-compose-email-modal .email-form-label {
  color: var(--email-text-muted);
}

#dm-compose-email-modal .email-modal-title {
  color: var(--email-text-primary);
}

#dm-compose-email-modal .email-toolbar-btn {
  color: var(--email-text-secondary);
}

#dm-compose-email-modal .email-toolbar-btn:hover {
  background: var(--email-bg-tertiary);
  color: var(--email-text-primary);
}

#dm-compose-email-modal .email-btn-cancel {
  background: transparent;
  border-color: var(--email-border-color);
  color: var(--email-text-secondary);
}

#dm-compose-email-modal .email-btn-cancel:hover {
  background: var(--email-bg-tertiary);
  color: var(--email-text-primary);
}

#dm-compose-email-modal .email-footer-btn.secondary {
  background: transparent;
  border-color: var(--email-border-color);
  color: var(--email-text-secondary);
}

#dm-compose-email-modal .email-footer-btn.secondary:hover {
  background: var(--email-bg-tertiary);
  color: var(--email-text-primary);
}

/* ==========================================================================
   PREVIEW EMPTY STATE
   ========================================================================== */

#dm-compose-email-modal .email-preview-empty {
  color: var(--email-text-muted);
}

#dm-compose-email-modal .email-preview-empty svg {
  color: var(--email-text-muted);
  opacity: 0.5;
}

/* ==========================================================================
   DATA-THEME ATTRIBUTE TARGETING (set by JS)
   ========================================================================== */

#dm-compose-email-modal[data-theme="dark"],
#dm-compose-email-modal.email-theme-dark {
  --email-bg-primary: #0d1117;
  --email-bg-secondary: #161b22;
  --email-bg-tertiary: #21262d;
  --email-bg-elevated: #30363d;
  --email-border-color: #30363d;
  --email-border-subtle: #21262d;
  --email-text-primary: #f0f6fc;
  --email-text-secondary: #8b949e;
  --email-text-muted: #6e7681;
  --email-accent-blue: #58a6ff;
  --email-accent-blue-bg: rgba(56, 139, 253, 0.15);
  --email-accent-green: #3fb950;
  --email-accent-green-bg: rgba(46, 160, 67, 0.15);
  --email-accent-red: #f85149;
  --email-accent-red-bg: rgba(248, 81, 73, 0.15);
  --email-accent-orange: #d29922;
}

#dm-compose-email-modal[data-theme="light"],
#dm-compose-email-modal.email-theme-light {
  --email-bg-primary: #ffffff;
  --email-bg-secondary: #f6f8fa;
  --email-bg-tertiary: #f0f2f5;
  --email-bg-elevated: #e1e4e8;
  --email-border-color: #d0d7de;
  --email-border-subtle: #e1e4e8;
  --email-text-primary: #1f2328;
  --email-text-secondary: #656d76;
  --email-text-muted: #8c959f;
  --email-accent-blue: #0969da;
  --email-accent-blue-bg: rgba(9, 105, 218, 0.1);
  --email-accent-green: #1a7f37;
  --email-accent-green-bg: rgba(26, 127, 55, 0.1);
  --email-accent-red: #cf222e;
  --email-accent-red-bg: rgba(207, 34, 46, 0.1);
  --email-accent-orange: #9a6700;
}

/* ==========================================================================
   EMAIL SETTINGS - Templates & Signatures (Phase F5)
   ========================================================================== */

.email-settings-card { padding: 0; overflow: hidden; }

.email-settings-tabs {
  display: flex;
  border-bottom: 1px solid var(--dm-border-color);
  background: var(--dm-bg-secondary);
}

.email-settings-tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 20px;
  background: transparent;
  border: none;
  color: var(--dm-text-secondary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.email-settings-tab:hover {
  color: var(--dm-text-primary);
  background: var(--dm-bg-tertiary);
}

.email-settings-tab.active {
  color: var(--dm-accent-blue);
  border-bottom-color: var(--dm-accent-blue);
  background: var(--dm-bg-primary);
}

.email-settings-tab svg { opacity: 0.7; }
.email-settings-tab.active svg { opacity: 1; }

.email-settings-panel { display: none; padding: 20px; }
.email-settings-panel.active { display: block; }

.email-settings-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 20px;
}

.email-settings-panel-info h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--dm-text-primary);
  margin: 0 0 4px 0;
}

.email-settings-panel-info p {
  font-size: 13px;
  color: var(--dm-text-secondary);
  margin: 0;
}

.email-settings-list { min-height: 150px; }

.settings-table { width: 100%; border-collapse: collapse; }

.settings-table th, .settings-table td {
  padding: 12px;
  text-align: left;
  border-bottom: 1px solid var(--dm-border-color);
}

.settings-table th {
  font-size: 12px;
  font-weight: 600;
  color: var(--dm-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: var(--dm-bg-secondary);
}

.settings-table td {
  font-size: 14px;
  color: var(--dm-text-primary);
}

.settings-table tbody tr:hover { background: var(--dm-bg-secondary); }
.settings-table-name { font-weight: 500; }
.settings-table-subject, .settings-table-preview {
  color: var(--dm-text-secondary);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.settings-table-preview { font-size: 13px; color: var(--dm-text-muted); }
.settings-table-default { text-align: center; }
.settings-table-actions { white-space: nowrap; text-align: right; }

.email-type-badge {
  display: inline-block;
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 500;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.email-type-first-contact { background: rgba(56, 139, 253, 0.15); color: #58a6ff; }
.email-type-follow-up { background: rgba(46, 160, 67, 0.15); color: #3fb950; }
.email-type-market-update { background: rgba(210, 153, 34, 0.15); color: #d29922; }
.email-type-property-appraisal { background: rgba(163, 113, 247, 0.15); color: #a371f7; }
.email-type-listing-proposal { background: rgba(248, 81, 73, 0.15); color: #f85149; }
.email-type-custom { background: rgba(139, 148, 158, 0.15); color: #8b949e; }

.settings-default-star { color: #d29922; font-size: 16px; }

.settings-btn-icon {
  background: transparent;
  border: none;
  padding: 6px;
  cursor: pointer;
  color: var(--dm-text-secondary);
  border-radius: 4px;
  transition: all 0.15s ease;
}

.settings-btn-icon:hover {
  background: var(--dm-bg-tertiary);
  color: var(--dm-text-primary);
}

.settings-btn-icon.settings-btn-danger:hover {
  background: rgba(248, 81, 73, 0.15);
  color: #f85149;
}

.settings-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--dm-text-secondary);
}

.settings-empty p { margin: 0 0 8px 0; }
.settings-empty-hint { font-size: 13px; color: var(--dm-text-muted); }

.settings-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  gap: 12px;
  color: var(--dm-text-secondary);
}

.settings-loading-spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--dm-border-color);
  border-top-color: var(--dm-accent-blue);
  border-radius: 50%;
  animation: settings-spin 0.8s linear infinite;
}

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

.settings-editor-modal .dm-modal-content { max-width: 700px; width: 95%; }
.settings-editor-modal.active { display: flex; align-items: center; justify-content: center; }
.settings-editor-body { padding: 20px; }
.settings-form-group { margin-bottom: 16px; }
.settings-form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--dm-text-secondary);
  margin-bottom: 6px;
}
.settings-form-row { display: flex; gap: 16px; }
.settings-form-row .settings-form-group { flex: 1; }
.settings-form-group-wide { flex: 2 !important; }

.settings-input, .settings-select {
  width: 100%;
  padding: 10px 12px;
  background: var(--dm-bg-secondary);
  border: 1px solid var(--dm-border-color);
  border-radius: 6px;
  color: var(--dm-text-primary);
  font-size: 14px;
}

.settings-input:focus, .settings-select:focus {
  outline: none;
  border-color: var(--dm-accent-blue);
  box-shadow: 0 0 0 3px rgba(56, 139, 253, 0.2);
}

.settings-select { cursor: pointer; }
.settings-form-hint { margin: 6px 0 0 0; font-size: 12px; color: var(--dm-text-muted); }
.settings-form-checkbox { display: flex; align-items: center; }
.settings-form-checkbox label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  margin-bottom: 0;
}
.settings-form-checkbox input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; }

.settings-quill-editor {
  background: var(--dm-bg-secondary);
  border: 1px solid var(--dm-border-color);
  border-radius: 6px;
  min-height: 200px;
}

.settings-quill-editor .ql-toolbar {
  border: none;
  border-bottom: 1px solid var(--dm-border-color);
  background: var(--dm-bg-tertiary);
}

.settings-quill-editor .ql-container { border: none; font-size: 14px; }
.settings-quill-editor .ql-editor { min-height: 150px; color: var(--dm-text-primary); }
.settings-quill-editor .ql-editor.ql-blank::before { color: var(--dm-text-muted); font-style: normal; }

.settings-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
  border: 1px solid transparent;
}

.settings-btn-primary {
  background: var(--dm-accent-blue);
  color: #fff;
  border-color: var(--dm-accent-blue);
}

.settings-btn-primary:hover { background: #4c9aff; border-color: #4c9aff; }

[data-theme="light"] .email-settings-tabs,
[data-theme="light"] .settings-table th { background: #f6f8fa; }
[data-theme="light"] .settings-table tbody tr:hover { background: #f6f8fa; }
[data-theme="light"] .settings-quill-editor { background: #fff; }
[data-theme="light"] .settings-quill-editor .ql-toolbar { background: #f6f8fa; }
[data-theme="light"] .settings-input,
[data-theme="light"] .settings-select { background: #fff; border-color: #d0d7de; color: #1f2328; }

/* Template Editor - Insert Field */
.template-editor-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  position: relative;
}

.settings-btn-sm {
  padding: 6px 10px;
  font-size: 12px;
}

.template-merge-popover {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 1000;
  background: var(--dm-bg-elevated);
  border: 1px solid var(--dm-border-color);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  padding: 12px;
  min-width: 200px;
}

.template-merge-popover .merge-section {
  margin-bottom: 12px;
}

.template-merge-popover .merge-section:last-child {
  margin-bottom: 0;
}

.template-merge-popover .merge-section-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--dm-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.template-merge-popover button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 6px 10px;
  background: transparent;
  border: none;
  color: var(--dm-text-primary);
  font-size: 13px;
  font-family: 'SF Mono', 'Monaco', 'Inconsolata', monospace;
  cursor: pointer;
  border-radius: 4px;
  transition: background 0.15s ease;
}

.template-merge-popover button:hover {
  background: var(--dm-bg-tertiary);
}

/* Dark theme fixes for Settings buttons */
.settings-btn {
  background: var(--dm-bg-tertiary);
  border: 1px solid var(--dm-border-color);
  color: var(--dm-text-primary);
}

.settings-btn:hover {
  background: var(--dm-bg-elevated);
}

.settings-btn-primary {
  background: var(--dm-accent-blue) !important;
  border-color: var(--dm-accent-blue) !important;
  color: #fff !important;
}

.settings-btn-primary:hover {
  background: #4c9aff !important;
  border-color: #4c9aff !important;
}

.settings-btn-sm {
  background: var(--dm-bg-tertiary);
  border: 1px solid var(--dm-border-color);
  color: var(--dm-text-primary);
  padding: 6px 10px;
  font-size: 12px;
}

.settings-btn-sm:hover {
  background: var(--dm-bg-elevated);
}

/* Template editor toolbar dark theme */
.template-editor-toolbar .settings-btn,
.template-editor-toolbar .settings-btn-sm {
  background: var(--dm-bg-tertiary);
  border: 1px solid var(--dm-border-color);
  color: var(--dm-text-primary);
}

/* Quill editor dark theme in settings */
.settings-quill-editor .ql-toolbar.ql-snow {
  background: var(--dm-bg-tertiary) !important;
  border-color: var(--dm-border-color) !important;
}

.settings-quill-editor .ql-toolbar .ql-stroke {
  stroke: var(--dm-text-secondary);
}

.settings-quill-editor .ql-toolbar .ql-fill {
  fill: var(--dm-text-secondary);
}

.settings-quill-editor .ql-toolbar button:hover .ql-stroke {
  stroke: var(--dm-text-primary);
}

.settings-quill-editor .ql-toolbar button:hover .ql-fill {
  fill: var(--dm-text-primary);
}

.settings-quill-editor .ql-toolbar button.ql-active .ql-stroke {
  stroke: var(--dm-accent-blue);
}

.settings-quill-editor .ql-toolbar button.ql-active .ql-fill {
  fill: var(--dm-accent-blue);
}

/* Quill picker (dropdowns) dark theme */
.settings-quill-editor .ql-picker-label {
  color: var(--dm-text-secondary) !important;
}

.settings-quill-editor .ql-picker-options {
  background: var(--dm-bg-elevated) !important;
  border-color: var(--dm-border-color) !important;
}

.settings-quill-editor .ql-picker-item {
  color: var(--dm-text-primary) !important;
}

.settings-quill-editor .ql-picker-item:hover {
  background: var(--dm-bg-tertiary) !important;
}

/* Light theme overrides for settings buttons */
[data-theme="light"] .settings-btn,
[data-theme="light"] .settings-btn-sm {
  background: #f6f8fa;
  border-color: #d0d7de;
  color: #1f2328;
}

[data-theme="light"] .settings-btn:hover,
[data-theme="light"] .settings-btn-sm:hover {
  background: #e1e4e8;
}

[data-theme="light"] .settings-quill-editor .ql-toolbar.ql-snow {
  background: #f6f8fa !important;
  border-color: #d0d7de !important;
}

[data-theme="light"] .settings-quill-editor .ql-toolbar .ql-stroke {
  stroke: #656d76;
}

[data-theme="light"] .settings-quill-editor .ql-toolbar .ql-fill {
  fill: #656d76;
}

/* Light theme for Insert Field popover */
[data-theme="light"] .template-merge-popover,
.light-theme .template-merge-popover {
  background: #ffffff;
  border-color: #d0d7de;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

[data-theme="light"] .template-merge-popover .merge-section-title,
.light-theme .template-merge-popover .merge-section-title {
  color: #656d76;
}

[data-theme="light"] .template-merge-popover button,
.light-theme .template-merge-popover button {
  color: #1f2328;
}

[data-theme="light"] .template-merge-popover button:hover,
.light-theme .template-merge-popover button:hover {
  background: #f6f8fa;
}

/* Settings editor modal light theme */
[data-theme="light"] .settings-editor-modal .dm-modal-content,
.light-theme .settings-editor-modal .dm-modal-content {
  background: #ffffff;
  color: #1f2328;
}

[data-theme="light"] .settings-editor-modal .dm-modal-header,
.light-theme .settings-editor-modal .dm-modal-header {
  border-color: #d0d7de;
}

[data-theme="light"] .settings-editor-modal .dm-modal-footer,
.light-theme .settings-editor-modal .dm-modal-footer {
  border-color: #d0d7de;
  background: #f6f8fa;
}

[data-theme="light"] .settings-editor-modal h2,
.light-theme .settings-editor-modal h2 {
  color: #1f2328;
}

[data-theme="light"] .settings-editor-modal label,
.light-theme .settings-editor-modal label {
  color: #656d76;
}
