/* ===================================
   EMAIL CHANNELS SIDEBAR (sempre visibile, si espande al hover)
   =================================== */

.email-channels-sidebar {
  width: 60px;
  background: var(--sidebar-bg, #fff);
  border-right: 1px solid var(--border-color, #e5e7eb);
  flex-shrink: 0;
  transition: width 0.2s cubic-bezier(0.4,0,0.2,1);
  overflow: visible;
  position: relative;
  z-index: 100;
  display: flex;
  flex-direction: column;
}

.email-channels-sidebar:hover {
  width: 220px;
  box-shadow: 4px 0 12px rgba(0,0,0,0.08);
}

.email-channels-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 12px;
  border-bottom: 1px solid var(--border-color, #e5e7eb);
  font-weight: 600;
  color: var(--text-primary, #1f2937);
  white-space: nowrap;
}

.email-channels-header i {
  width: 24px;
  text-align: center;
  font-size: 1.2rem;
  flex-shrink: 0;
  color: var(--primary, #6366f1);
}

.email-channels-title {
  opacity: 0;
  width: 0;
  overflow: hidden;
  transition: opacity 0.2s, width 0.2s;
}

.email-channels-sidebar:hover .email-channels-title {
  opacity: 1;
  width: auto;
}

.email-channels-search-input {
  width: calc(100% - 16px);
  margin: 8px 8px;
  padding: 6px 10px;
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: 6px;
  font-size: 0.85rem;
  opacity: 0;
  height: 0;
  overflow: hidden;
  transition: opacity 0.2s, height 0.2s;
}

.email-channels-sidebar:hover .email-channels-search-input {
  opacity: 1;
  height: 32px;
}

.email-channels-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.email-channel-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 8px;
  border-radius: 8px;
  color: var(--sidebar-text, #374151);
  margin-bottom: 4px;
  transition: all 0.2s ease;
  cursor: pointer;
  white-space: nowrap;
  position: relative;
}

.email-channel-item:hover {
  background: var(--sidebar-hover, #f3f4f6);
  color: var(--primary, #6366f1);
}

.email-channel-item.active {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.15) 0%, rgba(79, 70, 229, 0.1) 100%);
  color: var(--primary, #6366f1);
  font-weight: 600;
}

.email-channel-item i {
  width: 24px;
  text-align: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.email-channel-label {
  opacity: 0;
  width: 0;
  overflow: hidden;
  transition: opacity 0.2s, width 0.2s;
}

.email-channels-sidebar:hover .email-channel-label {
  opacity: 1;
  width: auto;
}

/* Stile per il composer inline (nuova email in chat) */
#inline-email-composer {
  padding: 2.5rem 2.5rem 1.5rem 2.5rem;
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 8px 40px rgba(123,97,255,0.12), 0 2px 12px rgba(0,0,0,0.08);
  margin: 2.5rem auto 0 auto;
  max-width: 540px;
  transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  border: 1px solid rgba(123,97,255,0.1);
}

#inline-email-composer:hover {
  box-shadow: 0 12px 48px rgba(123,97,255,0.15), 0 4px 16px rgba(0,0,0,0.1);
  transform: translateY(-2px);
}
/* Email Chat UI/UX Enhancements */

.tg-panel-body {
  display: flex;
  height: 100vh;
  background: var(--bg-primary, #f7f7fa);
  position: relative;
  overflow: hidden;
}

.tg-sidebar {
  width: 320px;
  background: var(--card-bg, #fff);
  border-right: 1px solid var(--border-color, #e0e0e0);
  display: flex;
  flex-direction: column;
  box-shadow: 0 4px 16px rgba(0,0,0,0.04);
  transition: box-shadow 0.3s ease;
  backdrop-filter: blur(10px);
}

.tg-sidebar-controls {
  display: flex;
  gap: 0.5rem;
  padding: 1rem 1rem 0.5rem 1rem;
  background: var(--card-bg, #fff);
  border-bottom: 1px solid var(--border-color, #e0e0e0);
}

.tg-sidebar-header {
  padding: 0.35rem 1rem 0.85rem;
  background: var(--card-bg, #fff);
  border-bottom: 1px solid var(--border-color, #eceef5);
}

.tg-sidebar-header h3 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary, #111827);
  letter-spacing: 0.02em;
}

.tg-sidebar-header small {
  color: var(--text-secondary, #6b7280);
  font-size: 0.8rem;
}

.tg-sidebar-search {
  padding: 0 1rem 0.75rem;
  background: var(--card-bg, #fff);
  border-bottom: 1px solid var(--border-color, #e0e0e0);
}

.tg-sidebar-search .input-icon {
  position: relative;
  display: flex;
  align-items: center;
}

.tg-sidebar-search i {
  position: absolute;
  left: 0.85rem;
  color: var(--text-secondary, #94a3b8);
  font-size: 0.85rem;
}

.tg-sidebar-search input {
  width: 100%;
  border: 1px solid var(--border-color, #e0e0e0);
  border-radius: 999px;
  padding: 0.55rem 0.9rem 0.55rem 2.1rem;
  background: var(--bg-primary, #f7f7fa);
  font-size: 0.9rem;
  color: var(--text-primary, #1f2937);
  outline: none;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.tg-sidebar-search input:focus {
  border-color: #7b61ff;
  box-shadow: 0 0 0 3px rgba(123,97,255,0.15), 0 4px 12px rgba(123,97,255,0.12);
  transform: translateY(-1px);
  background: #fff;
}

.tg-sidebar-search input:hover {
  border-color: #c1c7d0;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}

.tg-chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0.5rem 1rem 0.5rem;
}

.tg-chat-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1rem;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  margin-bottom: 0.25rem;
  border: 1px solid transparent;
}
.tg-chat-item.selected, .tg-chat-item:hover {
  background: var(--primary-light, #f0f4ff);
  transform: translateX(4px);
  border-color: rgba(123,97,255,0.2);
  box-shadow: 0 2px 8px rgba(123,97,255,0.08);
}

.tg-chat-item:active {
  transform: translateX(2px) scale(0.98);
}
.tg-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #7b61ff;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.2rem;
  box-shadow: 0 2px 8px rgba(123,97,255,0.15), 0 1px 3px rgba(0,0,0,0.1);
  transition: all 0.3s ease;
}

.tg-chat-item:hover .tg-avatar {
  transform: scale(1.1);
  box-shadow: 0 4px 12px rgba(123,97,255,0.25);
}
.tg-chat-info {
  flex: 1;
  min-width: 0;
}
.tg-chat-name {
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--text-primary, #222);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tg-chat-last {
  font-size: 0.92rem;
  color: var(--text-secondary, #888);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tg-unread {
  background: #ff5e5e;
  color: #fff;
  font-size: 0.8rem;
  border-radius: 999px;
  padding: 2px 8px;
  margin-left: 8px;
  font-weight: 600;
}

/* Priority badge styles */
.tg-priority {
  display: inline-block;
  font-size: 0.7rem;
  padding: 2px 6px;
  margin-left: 8px;
  border-radius: 999px;
  font-weight: 700;
  vertical-align: middle;
}
.tg-priority-high { background: #ff6b6b; color: #fff; }
.tg-priority-medium { background: #f59e0b; color: #fff; }
.tg-priority-normal { background: #3b82f6; color: #fff; }
.tg-priority-low { background: #94a3b8; color: #fff; }

/* Thread priority badge compatibility (used in renderThreadViewer) */
.thread-priority { display:inline-block; font-size:0.78rem; padding:3px 8px; border-radius:12px; font-weight:700; vertical-align:middle; }
.priority-high { background:#ff6b6b; color:#fff; }
.priority-normal { background:#3b82f6; color:#fff; }
.priority-low { background:#94a3b8; color:#fff; }
.priority-unknown { background:#cbd5e1; color:#102a43; }

/* Attachment list in bubbles */
.tg-bubble-attach .attachment-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: rgba(123,97,255,0.08);
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 0.88rem;
  cursor: pointer;
  transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  border: 1px solid transparent;
}
.tg-bubble-attach .attachment-item i { 
  color: #7b61ff;
  transition: transform 0.3s ease;
}
.tg-bubble-attach .attachment-item:hover {
  background: #7b61ff;
  color: #fff;
  box-shadow: 0 6px 16px rgba(123,97,255,0.25);
  transform: translateY(-2px) scale(1.05);
  border-color: #7b61ff;
}
.tg-bubble-attach .attachment-item:hover i {
  transform: rotate(5deg);
}
.tg-bubble-attach .attachment-item:active {
  transform: translateY(-1px) scale(0.98);
}
.tg-bubble-attach a { color: inherit; text-decoration: none; }

/* Summary box in guided compose */
.email-chat-bubble .bubble-text { line-height: 1.25; }
.email-chat-bubble .btn { margin-right: 0.5rem; }

.tg-viewer {
  position: absolute;
  top: 0;
  right: -100vw;
  width: calc(100% - 320px);
  height: 100%;
  background: var(--bg-primary, #f7f7fa);
  display: flex;
  flex-direction: column;
  z-index: 10;
  transition: right 0.35s cubic-bezier(.4,1.4,.6,1);
  box-shadow: -2px 0 18px rgba(123,97,255,0.08);
}
.tg-viewer.open {
  right: 0;
}
.tg-sidebar {
  position: relative;
  z-index: 11;
}
.tg-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem 1.5rem 1rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.tg-thread-viewer {
  display: flex;
  flex-direction: column;
  height: 100%;
}

#email-thread-messages {
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* --- Chat Bubble WhatsApp/Telegram Style --- */
.tg-bubble {
  display: flex;
  align-items: flex-end;
  gap: 0.6rem;
  margin-bottom: 0.7rem;
  max-width: 78%;
  animation: messageIn 0.22s cubic-bezier(.4,1.3,.6,1);
  position: relative;
}

.tg-bubble.thread-item {
  max-width: 100%;
  cursor: pointer;
}

.tg-bubble.thread-item.selected .tg-bubble-content {
  outline: 2px solid rgba(123,97,255,0.35);
  box-shadow: 0 4px 18px rgba(123,97,255,0.18);
}
.tg-bubble.thread-item:hover .tg-bubble-content {
  box-shadow: 0 6px 22px rgba(123,97,255,0.18);
  transform: translateY(-1px);
}

.tg-bubble.sent {
  align-self: flex-end;
  flex-direction: row-reverse;
}
.tg-bubble.received {
  align-self: flex-start;
}
.tg-bubble-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #e0e0e0;
  color: #7b61ff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.15rem;
  border: 2.5px solid #fff;
  box-shadow: 0 2px 8px rgba(123,97,255,0.10);
  transition: box-shadow 0.18s;
}
.tg-bubble.sent .tg-bubble-avatar {
  background: linear-gradient(135deg, #7b61ff 60%, #5a47c2 100%);
  color: #fff;
  border: 2.5px solid #7b61ff;
}
.tg-bubble-content {
  background: #fff;
  border-radius: 22px 22px 22px 6px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.07);
  padding: 0.95em 1.3em;
  min-width: 80px;
  max-width: 440px;
  word-break: break-word;
  overflow-wrap: break-word;
  overflow: hidden;
  position: relative;
  font-size: 1.04em;
  transition: background 0.18s;
}

/* Contiene il contenuto HTML delle email */
.tg-bubble-content * {
  max-width: 100%;
  box-sizing: border-box;
  overflow-wrap: break-word;
}

.tg-bubble-content img {
  max-width: 100%;
  height: auto;
  display: block;
}

.tg-bubble-content table {
  max-width: 100%;
  table-layout: auto;
}
.tg-bubble.sent .tg-bubble-content {
  background: var(--primary-light, #eef2ff);
  color: var(--text-primary, #1f1f25);
  border-radius: 22px 6px 22px 22px;
  box-shadow: 0 2px 12px rgba(111,124,255,0.18);
}
.tg-bubble-content:hover {
  box-shadow: 0 4px 18px rgba(123,97,255,0.18);
}
.tg-bubble-meta {
  font-size: 0.82em;
  color: #b0b0b0;
  margin-top: 6px;
  text-align: right;
  letter-spacing: 0.01em;
}
.tg-bubble-attach {
  margin-top: 8px;
  font-size: 0.97em;
  color: #7b61ff;
  display: flex;
  align-items: center;
  gap: 0.5em;
  flex-wrap: wrap;
}

.email-thread-header {
  padding: 1.25rem 2rem 0.5rem 2rem;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.email-thread-header h2 {
  margin: 0;
  font-size: 1.35rem;
  color: var(--text-primary, #111827);
}

.email-thread-meta {
  color: var(--text-secondary, #6b7280);
  font-size: 0.9rem;
  margin-top: 0.35rem;
  line-height: 1.4;
}

.tg-date-separator {
  text-align: center;
  margin: 1rem auto;
  padding: 0.25rem 0.75rem;
  background: rgba(148,163,184,0.2);
  color: #475569;
  font-size: 0.75rem;
  border-radius: 999px;
  letter-spacing: 0.05em;
}

.email-thread-actions {
  margin-top: auto;
  padding: 0.9rem 2rem 1.2rem 2rem;
  background: var(--card-bg, #fff);
  border-top: 1px solid var(--border-color, #e0e0e0);
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  position: sticky;
  bottom: 0;
  box-shadow: 0 -6px 18px rgba(15,23,42,0.05);
}

.email-thread-actions .btn {
  min-width: 120px;
}

.email-thread-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: #94a3b8;
  padding: 2rem;
}


/* --- Input Bar WhatsApp/Telegram Style --- */
.tg-inputbar {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 1.1rem 2.2rem 1.1rem 2.2rem;
  background: var(--card-bg, #fff);
  border-top: 1px solid var(--border-color, #e0e0e0);
  box-shadow: 0 -2px 8px rgba(123,97,255,0.03);
}
.tg-inputbar input[type="text"], .tg-inputbar textarea {
  flex: 1;
  border: 1.5px solid var(--border-color, #e0e0e0);
  border-radius: 22px;
  padding: 0.8em 1.2em;
  font-size: 1.08em;
  background: #f7f7fa;
  color: #222;
  outline: none;
  transition: border 0.15s, box-shadow 0.15s;
  box-shadow: 0 1px 4px rgba(123,97,255,0.04);
}
.tg-inputbar input[type="text"]:focus, .tg-inputbar textarea:focus {
  border: 1.5px solid #7b61ff;
  box-shadow: 0 2px 8px rgba(123,97,255,0.10);
}
.tg-attach-btn {
  background: none;
  border: none;
  color: #7b61ff;
  font-size: 1.35em;
  cursor: pointer;
  margin-right: 0.5em;
  transition: color 0.15s, transform 0.13s;
}
.tg-attach-btn:hover {
  color: #5a47c2;
  transform: scale(1.13);
}
.tg-send-btn {
  border-radius: 50%;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35em;
  background: linear-gradient(135deg, #7b61ff 80%, #5a47c2 100%);
  color: #fff;
  border: none;
  box-shadow: 0 2px 12px rgba(123,97,255,0.13);
  transition: background 0.15s, transform 0.13s;
}
.tg-send-btn:hover {
  background: linear-gradient(135deg, #5a47c2 80%, #7b61ff 100%);
  transform: scale(1.10);
}



@keyframes messageIn {
  from { opacity: 0; transform: translateY(18px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Empty state */
.empty-state {
  text-align: center;
  color: #bbb;
  margin-top: 3rem;
}
.empty-state i {
  font-size: 2.5em;
  margin-bottom: 0.5em;
}

/* Responsive */
@media (max-width: 900px) {
  .tg-panel-body { flex-direction: column; }
  .tg-sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--border-color, #e0e0e0); }
  .tg-viewer { flex: 1; }
  .tg-messages, .tg-inputbar { padding-left: 1rem; padding-right: 1rem; }
}

/* Composer modal */
.email-compose-modal { position: fixed; inset: 0; z-index: 1200; }
.email-compose-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.35); }
.email-compose-dialog { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 720px; max-width: 96%; background: #fff; border-radius: 10px; box-shadow: 0 10px 40px rgba(0,0,0,0.25); overflow: hidden; display: flex; flex-direction: column; }
.email-compose-header { display:flex; align-items:center; justify-content:space-between; padding: 12px 16px; border-bottom: 1px solid #eee; }
.email-compose-body { padding: 14px; max-height: 60vh; overflow:auto; }
.email-compose-input { padding: 12px 14px; border-top: 1px solid #f1f1f1; background:#fafafa; }
.email-compose-thread .tg-bubble { max-width: 100%; }

/* Chat-style composer attachment preview */
.attachment-list {
  margin-top: 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.attachment-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  background: #fbfbff;
  border: 1px solid #efeff8;
  border-radius: 8px;
  font-size: 0.95rem;
}
.attachment-item .attachment-name {
  color: #333;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 320px;
}
.attachment-item .attachment-remove {
  color: #e11d48;
  font-size: 0.9rem;
  border: none;
  background: transparent;
  cursor: pointer;
}
.chat-step .chat-question {
  font-weight: 700;
  margin-bottom: 0.5rem;
}
.chat-step .chat-actions { margin-top: 0.8rem; }

/* Composer (inline) styles moved from inline markup */
.email-composer-container {
  border-top: 1px solid #eee;
  padding: 12px;
  background: #fafafa;
}
.email-composer-container #composer-to {
  padding: 8px;
  border-radius: 6px;
  border: 1px solid #e6e6e6;
  width: 100%;
  box-sizing: border-box;
  font-size: 0.95rem;
}
.email-composer-container #composer-body {
  flex: 1;
  height: 80px;
  padding: 8px;
  border-radius: 6px;
  border: 1px solid #e6e6e6;
  font-size: 0.95rem;
  resize: vertical;
}
.email-composer-container #composer-send {
  background: linear-gradient(135deg,#7b61ff 80%,#5a47c2 100%);
  color: #fff;
  border: none;
  padding: 8px 10px;
  border-radius: 6px;
}
.email-composer-container #composer-attach {
  background: transparent;
  border: 1px solid #ddd;
  padding: 6px 8px;
  border-radius: 6px;
}
.email-composer-container #composer-help {
  font-size: 0.85rem;
  color: #666;
}

/* ========================================
   3-COLUMN EMAIL VIEW STYLES
   Sinistra: Contatti | Centro: Conversazioni | Destra: Dettagli
   ======================================== */

.email-view-wrapper {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--bg-primary, #f7f7fa);
}

.email-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  background: var(--card-bg, #fff);
  border-bottom: 1px solid var(--border-color, #e0e0e0);
  box-shadow: 0 2px 4px rgba(0,0,0,0.03);
}

.email-toolbar h2 {
  margin: 0;
  font-size: 1.5rem;
  color: var(--text-primary, #111827);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.email-toolbar-actions {
  display: flex;
  gap: 0.5rem;
}

.email-viewer-content {
  flex: 1;
  overflow: hidden;
}

/* ── 8 px Grid – Spacing Tokens ── */
:root {
  --email-base:        8px;                        /* 1×  */
  --email-inner-pad:   calc(var(--email-base) * 2); /* 16 px – horizontal content padding */
  --email-inner-pad-v: calc(var(--email-base) * 2); /* 16 px – vertical content padding   */
  --email-section-pad: calc(var(--email-base) * 3); /* 24 px – section / header padding    */
}

/* 3-Column Layout */
.email-view-3col {
  display: grid;
  grid-template-columns: 4fr 9fr 7fr;
  grid-template-rows: auto 1fr;
  height: 100%;
  width: 100%;
  gap: 0;
  background: var(--bg-primary, #f7f7fa);
  border-radius: 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  position: relative;
  overflow: hidden;
  box-sizing: border-box;
  max-width: 100%;
}

/* COLUMN 1: Contacts List */
.email-contacts-column {
  background: var(--card-bg, #fff);
  border-right: 1px solid var(--border-color, #e0e0e0);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  grid-row: 2;
}

.email-contacts-header {
  padding: var(--email-inner-pad-v) var(--email-inner-pad); /* 16 16 */
  border-bottom: 1px solid var(--border-color, #e0e0e0);
  background: var(--card-bg, #fff);
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 56px;
}

.email-contacts-header h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  flex: 1;
  min-width: 0;
}

.email-contacts-header .btn {
  width: 32px;
  height: 32px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 0.8rem;
}

.email-back-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-primary, #111827);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.email-back-btn:hover {
  background: var(--bg-tertiary, #f3f4f6);
  transform: translateX(-2px);
}

.email-back-btn:active {
  transform: scale(0.95);
}

[data-theme="dark"] .email-back-btn {
  color: var(--text-primary, #e9edef);
}

[data-theme="dark"] .email-back-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.email-refresh-cache-btn {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--text-secondary, #6b7280);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: all 0.2s ease;
  flex-shrink: 0;
  margin-left: auto;
}

.email-refresh-cache-btn:hover {
  background: var(--bg-tertiary, #f3f4f6);
  color: var(--text-primary, #1f2937);
  transform: scale(1.05);
}

.email-refresh-cache-btn:active {
  transform: scale(0.95);
}

.email-refresh-cache-btn.spinning i {
  animation: spin-animation 1s linear infinite;
}

@keyframes spin-animation {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

[data-theme="dark"] .email-refresh-cache-btn {
  color: var(--text-secondary, #9ca3af);
}

[data-theme="dark"] .email-refresh-cache-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary, #e9edef);
}

.email-contacts-header h3 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary, #111827);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
}

.email-contacts-search {
  padding: var(--email-base) var(--email-inner-pad); /* 8 16 */
  border-bottom: 1px solid var(--border-color, #e0e0e0);
  background: var(--card-bg, #fff);
}

.email-contacts-search input {
  width: 100%;
  padding: 0.625rem 0.875rem;
  border: 1px solid var(--border-color, #e0e0e0);
  border-radius: 8px;
  font-size: 0.9rem;
  background: var(--card-bg, #fff);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.email-contacts-search input:focus {
  outline: none;
  border-color: #7b61ff;
  box-shadow: 0 0 0 3px rgba(123,97,255,0.1);
}

.email-contacts-list {
  flex: 1;
  overflow-y: auto;
  padding: var(--email-base) var(--email-inner-pad); /* 8 16 */
}

.email-contact-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.5rem 0.5rem 0.5rem;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  margin-bottom: 0.25rem;
}

.email-contact-item:hover {
  background: var(--primary-light, #f0f4ff);
  transform: translateX(2px);
}

.email-contact-item.active {
  background: linear-gradient(135deg, #7b61ff 0%, #6a52e8 100%);
  color: #fff;
  box-shadow: 0 2px 8px rgba(123,97,255,0.3);
}

.email-contact-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #7b61ff 0%, #9381ff 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.8rem;
  flex-shrink: 0;
  box-shadow: 0 2px 4px rgba(123,97,255,0.2);
}

.email-contact-item.active .email-contact-avatar {
  background: rgba(255,255,255,0.25);
  color: #fff;
}

.email-contact-info {
  flex: 1;
  min-width: 0;
}

.email-contact-name {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text-primary, #111827);
  margin: 0 0 0.125rem 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.email-contact-item.active .email-contact-name {
  color: #fff;
}

.email-contact-email {
  font-size: 0.75rem;
  color: var(--text-secondary, #6b7280);
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.email-contact-item.active .email-contact-email {
  color: rgba(255,255,255,0.85);
}

.email-contact-unread {
  background: #ff5e5e;
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.25rem 0.5rem;
  border-radius: 999px;
  min-width: 20px;
  text-align: center;
}

/* COLUMN 2: Threads/Conversations */
.email-threads-column {
  background: var(--bg-primary, #f7f7fa);
  border-right: 1px solid var(--border-color, #e0e0e0);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  grid-row: 2;
}

.email-threads-header {
  padding: var(--email-inner-pad-v) var(--email-inner-pad); /* 16 16 */
  border-bottom: 1px solid var(--border-color, #e0e0e0);
  background: var(--card-bg, #fff);
}

.email-threads-header h3 {
  margin: 0 0 0.25rem 0;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary, #111827);
}

.email-threads-header p {
  margin: 0;
  font-size: 0.875rem;
  color: var(--text-secondary, #6b7280);
}

.email-threads-list {
  flex: 1;
  overflow-y: auto;
  padding: var(--email-inner-pad-v) var(--email-inner-pad); /* 16 16 */
}

.email-thread-group {
  background: var(--card-bg, #fff);
  border-radius: 12px;
  padding: var(--email-inner-pad); /* 16 */
  margin-bottom: var(--email-inner-pad-v); /* 16 */
  border: 1px solid var(--border-color, #e0e0e0);
  transition: box-shadow 0.2s, border-color 0.2s;
}

.email-thread-group:hover {
  border-color: rgba(123,97,255,0.3);
  box-shadow: 0 4px 12px rgba(123,97,255,0.08);
}

.email-thread-subject {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text-primary, #111827);
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-color, #e0e0e0);
}

.email-thread-subject i {
  color: #7b61ff;
}

.email-thread-count {
  background: var(--primary-light, #f0f4ff);
  color: #7b61ff;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.25rem 0.5rem;
  border-radius: 999px;
  margin-left: auto;
}

.email-thread-item {
  padding: 0.875rem;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  margin-bottom: 0.5rem;
}

.email-thread-item:hover {
  background: var(--primary-light, #f0f4ff);
  transform: translateX(2px);
}

.email-thread-item.active {
  background: linear-gradient(135deg, #7b61ff 0%, #6a52e8 100%);
  color: #fff;
  box-shadow: 0 2px 8px rgba(123,97,255,0.3);
}

.email-thread-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.email-thread-sender {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-primary, #111827);
}

.email-thread-item.active .email-thread-sender {
  color: #fff;
}

.email-thread-time {
  font-size: 0.75rem;
  color: var(--text-secondary, #6b7280);
}

.email-thread-item.active .email-thread-time {
  color: rgba(255,255,255,0.85);
}

.email-thread-preview {
  font-size: 0.85rem;
  color: var(--text-secondary, #6b7280);
  line-height: 1.4;
  margin-bottom: 0.5rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.email-thread-item.active .email-thread-preview {
  color: rgba(255,255,255,0.9);
}

.email-thread-tags {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.email-tag {
  font-size: 0.7rem;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  background: var(--bg-primary, #f7f7fa);
  color: var(--text-secondary, #6b7280);
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.email-thread-item.active .email-tag {
  background: rgba(255,255,255,0.2);
  color: #fff;
}

.email-tag.has-attachment {
  background: rgba(123,97,255,0.1);
  color: #7b61ff;
}

.email-thread-item.active .email-tag.has-attachment {
  background: rgba(255,255,255,0.25);
  color: #fff;
}

/* COLUMN 3: Details & Composer */
.email-threads-column {
  min-width: 0; /* allow content to shrink and prevent overflow pushing right column */
}

.email-details-column {
  background: var(--card-bg, #fff);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  width: 100%;
  max-width: 100%;
  height: 100%;
  box-sizing: border-box;
  position: relative;
  min-width: 0;
  padding-left: 0;
  grid-row: 2;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  min-height: 0;
  border-left: 1px solid var(--border-color, #e0e0e0);
  background: var(--bg-primary, #f9fafb);
}

/* Collapsed state: 40px width */
.email-details-column.collapsed {
  min-width: 40px;
  width: 40px;
  padding-left: 0;
}

.email-details-column.collapsed .email-details-header {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  padding: 0.75rem 0;
  transform: rotate(180deg);
}

.email-details-column.collapsed .email-details-header h3 {
  font-size: 0.8rem;
  white-space: nowrap;
}

.email-details-column.collapsed .email-details-body,
.email-details-column.collapsed .email-column-resize-handle {
  display: none;
}

/* Resize Handle — hidden in compact layout */
.email-column-resize-handle {
  display: none;
}

/* Desktop resize handles between columns */
.email-col-resize-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 10px;
  transform: translateX(-50%);
  cursor: col-resize;
  z-index: 25;
  background: transparent;
  touch-action: none;
}

.email-col-resize-handle::before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 4px;
  width: 2px;
  background: transparent;
  transition: background-color 0.15s ease;
}

.email-col-resize-handle:hover::before {
  background: rgba(100, 116, 139, 0.35);
}

.email-col-resize-handle.resizing::before {
  background: #3b82f6;
}

.email-column-resize-handle:hover {
  background: linear-gradient(to right, #3b82f6 0%, #60a5fa 100%);
  color: white;
  box-shadow: inset -2px 0 8px rgba(59, 130, 246, 0.3);
  border-right-color: #3b82f6;
}

.email-column-resize-handle.resizing {
  background: linear-gradient(to right, #3b82f6 0%, #60a5fa 100%);
  color: white;
  box-shadow: inset -2px 0 12px rgba(59, 130, 246, 0.4);
}

.email-details-header {
  padding: var(--email-inner-pad-v) var(--email-inner-pad); /* 16 16 */
  border-bottom: 1px solid var(--border-color, #e0e0e0);
  background: var(--card-bg, #fff);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--email-base); /* 8 */
  transition: all 0.2s ease;
  min-height: 56px;
}

.email-details-header h3 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary, #111827);
}

.email-details-toggle-btn {
  color: #6b7280;
  font-size: 1.1rem;
  padding: 0.5rem;
  border-radius: 6px;
  transition: all 0.2s ease;
}

.email-details-toggle-btn:hover {
  background: #f3f4f6;
  color: #3b82f6;
  transform: scale(1.1);
}

.email-details-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  padding: var(--email-inner-pad); /* 16 */
  width: 100%;
  box-sizing: border-box;
  transition: opacity 0.3s ease;
}

/* Remove double padding when wizard is inside */
.email-details-body:has(.wizard-container) {
  padding: 0;
  overflow: hidden;
}

.email-message-detail {
  background: var(--bg-primary, #f7f7fa);
  border-radius: 12px;
  padding: var(--email-inner-pad); /* 16 */
  margin-bottom: var(--email-inner-pad-v); /* 16 */
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}

.email-message-header-detail {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-color, #e0e0e0);
}

.email-from-detail {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.email-from-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, #7b61ff 0%, #9381ff 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1rem;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(123,97,255,0.25);
}

.email-from-info h4 {
  margin: 0 0 0.25rem 0;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary, #111827);
}

.email-from-info p {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-secondary, #6b7280);
}

.email-message-time-detail {
  font-size: 0.85rem;
  color: var(--text-secondary, #6b7280);
}

.email-message-body {
  color: var(--text-primary, #1f2937);
  line-height: 1.6;
  font-size: 0.95rem;
}

.email-message-body p {
  margin: 0 0 1rem 0;
}

/* Isolamento CSS per email HTML */
.email-html-iframe {
  width: 100%;
  min-height: 400px;
  border: none;
  background: white;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.email-html-iframe-inline {
  width: 100%;
  min-height: 200px;
  border: none;
  border-radius: 4px;
  margin: 0.5rem 0;
}

.email-message-content {
  position: relative;
  overflow: hidden;
}

/* Menu contestuale lista contatti (tasto destro) */
.email-contact-context-menu {
  position: fixed;
  z-index: 99999;
  min-width: 240px;
  max-width: 320px;
  background: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 10px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.18);
  overflow: hidden;
  padding: 0.35rem;
}

.email-contact-context-menu__title {
  padding: 0.5rem 0.6rem;
  font-size: 0.8rem;
  font-weight: 700;
  color: #111827;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  margin-bottom: 0.25rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.email-contact-context-menu__item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 0.65rem;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 8px;
  font-size: 0.875rem;
  color: #111827;
  font-weight: 500;
  text-align: left;
}

.email-contact-context-menu__item:hover {
  background: rgba(0, 0, 0, 0.05);
}

.email-contact-context-menu__item[data-action="delete-thread"] {
  color: #ef4444;
  font-weight: 600;
}

.email-contact-context-menu__item[data-action="delete-thread"]:hover {
  background: rgba(239, 68, 68, 0.08);
}

.email-message-attachments {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color, #e0e0e0);
}

.email-message-attachments h5 {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--text-primary, #111827);
  margin: 0 0 0.75rem 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.email-attachment-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.email-attachment-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  background: var(--card-bg, #fff);
  border: 1px solid var(--border-color, #e0e0e0);
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.email-attachment-item:hover {
  border-color: #7b61ff;
  box-shadow: 0 2px 8px rgba(123,97,255,0.1);
}

.email-attachment-icon {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(123,97,255,0.1);
  border-radius: 6px;
  color: #7b61ff;
  font-size: 1.1rem;
}

.email-attachment-info {
  flex: 1;
  min-width: 0;
}

.email-attachment-name {
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--text-primary, #111827);
  margin: 0 0 0.25rem 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.email-attachment-size {
  font-size: 0.75rem;
  color: var(--text-secondary, #6b7280);
  margin: 0;
}

.email-details-actions {
  padding: var(--email-inner-pad-v) var(--email-inner-pad); /* 16 16 */
  border-top: 1px solid var(--border-color, #e0e0e0);
  background: var(--bg-primary, #f7f7fa);
  display: flex;
  gap: var(--email-base); /* 8 */
  flex-shrink: 0;
  flex-wrap: wrap;
}

.email-action-btn {
  flex: 1;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border-color, #e0e0e0);
  border-radius: 8px;
  background: var(--card-bg, #fff);
  color: var(--text-primary, #111827);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.email-action-btn:hover {
  background: var(--primary-light, #f0f4ff);
  border-color: #7b61ff;
  color: #7b61ff;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(123,97,255,0.15);
}

.email-action-btn.primary {
  background: linear-gradient(135deg, #7b61ff 0%, #6a52e8 100%);
  color: #fff;
  border-color: transparent;
}

.email-action-btn.primary:hover {
  background: linear-gradient(135deg, #6a52e8 0%, #5941d0 100%);
  box-shadow: 0 4px 12px rgba(123,97,255,0.3);
}

/* Responsive Design */
@media (max-width: 1200px) {
  .email-view-3col {
    grid-template-columns: 4fr 9fr 7fr;
  }
}

@media (max-width: 992px) {
  .email-view-3col {
    grid-template-columns: 280px 1fr;
  }

  .email-col-resize-handle {
    display: none !important;
  }
  
  .email-details-column {
    position: fixed;
    right: -100%;
    top: 0;
    bottom: 0;
    width: 300px;
    z-index: 1000;
    transition: right 0.3s ease;
    box-shadow: -4px 0 12px rgba(0,0,0,0.1);
  }
  
  .email-details-column.open {
    right: 0;
  }
  
  .email-details-column.open #email-details-close-btn {
    display: block !important;
  }
}

@media (max-width: 768px) {
  .email-view-3col {
    grid-template-columns: 1fr;
    padding: 0;
    column-gap: 0;
    /* Contenitore relativo per le colonne absolute */
    position: relative;
    overflow: hidden;
    height: 100%;
  }
  
  .email-contacts-column,
  .email-threads-column,
  .email-details-column {
    /* absolute invece di fixed: non esce dal main-content, non sovrappone la navbar,
       non viene clippato da overflow:auto su iOS Safari */
    position: absolute;
    top: 0;
    bottom: 0;
    width: 100%;
    left: -100%;
    transition: left 0.3s ease;
    border-radius: 0;
    overflow-y: auto;
  }
  
  /* Contacts è la colonna base — visibile di default, coperta dalle colonne con z-index più alto */
  .email-contacts-column {
    left: 0;
    z-index: 1001;
  }
  
  /* Threads e details: nascosti di default, coprono contacts quando .open */
  .email-threads-column {
    left: -100%;
    z-index: 1002;
  }
  
  .email-details-column {
    left: -100%;
    z-index: 1003;
  }

  .email-contacts-column.open,
  .email-threads-column.open,
  .email-details-column.open {
    left: 0;
  }

  .email-col-resize-handle {
    display: none !important;
  }
}

/* Folder item styling in manage modal */
.folder-item {
  transition: all 0.2s ease;
}

.folder-item:hover {
  background: #f9fafb !important;
}

/* Folder tabs container */
#email-folder-tabs > div {
  display: flex;
  gap: 0.25rem;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  scrollbar-color: #cbd5e1 #f1f5f9;
  padding-bottom: 0.25rem;
}

#email-folder-tabs > div::-webkit-scrollbar {
  height: 6px;
}

#email-folder-tabs > div::-webkit-scrollbar-track {
  background: #f1f5f9;
  border-radius: 3px;
}

#email-folder-tabs > div::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 3px;
}

#email-folder-tabs > div::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* Folder tabs styling */
.folder-tab {
  transition: all 0.2s ease !important;
  flex-shrink: 0;
}

.folder-tab:hover {
  background: #e5e7eb !important;
}

.folder-tab.active {
  background: #6366f1 !important;
  color: white !important;
}

.folder-tab.active:hover {
  background: #5558e3 !important;
}

/* Reusable empty state styles */
.empty-state {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--text-secondary, #6b7280);
}

.empty-state .empty-state-icon {
  font-size: 2.5rem;
  margin-bottom: 0.75rem;
  opacity: 0.3;
  display: inline-block;
  color: var(--text-secondary, #6b7280);
}

.empty-state .empty-state-title {
  margin: 0 0 0.25rem 0;
  font-weight: 700;
  color: var(--text-primary, #111827);
  font-size: 1rem;
}

/* ===================================
   WIZARD / COMPOSER - Integrated Design
   =================================== */
.wizard-container {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  overflow-x: hidden;
  background: var(--bg-primary, #f9fafb);
  font-family: inherit;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  padding: 1.25rem !important;
  gap: 1rem !important;
}

.wizard-container > div {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

/* Wizard Step Header (step indicator circles) */
.wizard-container .wizard-step-header {
  text-align: center;
  padding: 1rem 1rem 0.75rem;
  border-bottom: 1px solid var(--border-color, #e5e7eb);
  background: var(--card-bg, #fff);
  border-radius: 12px 12px 0 0;
  margin: 0;
}

.wizard-step-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #7b61ff 0%, #6366f1 100%);
  color: white;
  font-weight: 700;
  font-size: 1rem;
  margin-bottom: 0.5rem;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.25);
}

/* Wizard footer buttons */
.wizard-container .wizard-footer {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  border-top: 1px solid var(--border-color, #e5e7eb);
  padding: 1rem 0 0;
  margin-top: auto;
}

.wizard-btn-cancel,
.wizard-btn-back {
  padding: 0.6rem 1.25rem;
  border: 1px solid var(--border-color, #d1d5db);
  background: var(--card-bg, #fff);
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-primary, #374151);
  font-weight: 500;
  font-size: 0.875rem;
  transition: all 0.2s;
}

.wizard-btn-cancel:hover,
.wizard-btn-back:hover {
  background: var(--bg-primary, #f3f4f6);
  border-color: var(--text-secondary, #9ca3af);
}

.wizard-btn-next,
.wizard-btn-send {
  padding: 0.6rem 1.25rem;
  background: linear-gradient(135deg, #7b61ff 0%, #6366f1 100%);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.875rem;
  transition: all 0.2s;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.25);
}

.wizard-btn-next:hover,
.wizard-btn-send:hover {
  background: linear-gradient(135deg, #6a52e8 0%, #4f46e5 100%);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.35);
  transform: translateY(-1px);
}

/* Wizard card sections (To, Subject, Template, CC etc.) */
.wizard-card {
  background: var(--card-bg, #fff);
  border-radius: 12px;
  padding: 1.25rem;
  border: 1px solid var(--border-color, #e5e7eb);
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.wizard-card:hover {
  border-color: rgba(123, 97, 255, 0.3);
}

.wizard-card-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.wizard-card-icon {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.wizard-card label {
  margin: 0;
  font-weight: 600;
  color: var(--text-primary, #1f2937);
  font-size: 0.9rem;
}

.wizard-card input[type="text"],
.wizard-card textarea,
.wizard-card select {
  width: 100%;
  padding: 0.75rem 0.875rem;
  border: 1px solid var(--border-color, #d1d5db);
  border-radius: 8px;
  font-size: 0.9rem;
  box-sizing: border-box;
  transition: border-color 0.2s, box-shadow 0.2s;
  background: var(--card-bg, #fff);
  color: var(--text-primary, #1f2937);
  font-family: inherit;
}

.wizard-card input[type="text"]:focus,
.wizard-card textarea:focus,
.wizard-card select:focus {
  outline: none;
  border-color: #7b61ff;
  box-shadow: 0 0 0 3px rgba(123, 97, 255, 0.1);
}

/* Addressbook option cards */
.addressbook-option {
  border: 1.5px solid var(--border-color, #e5e7eb) !important;
  border-radius: 10px !important;
  transition: all 0.2s !important;
  background: var(--card-bg, #fff) !important;
}

.addressbook-option:hover {
  border-color: #7b61ff !important;
  box-shadow: 0 2px 12px rgba(123, 97, 255, 0.12) !important;
  transform: translateY(-1px);
}

/* Mode choice cards (Liste vs Tutta rubrica) */
.mode-option {
  border: 1.5px solid var(--border-color, #e5e7eb) !important;
  border-radius: 10px !important;
  transition: all 0.2s !important;
  background: var(--card-bg, #fff) !important;
}

.mode-option:hover {
  border-color: #7b61ff !important;
  box-shadow: 0 2px 12px rgba(123, 97, 255, 0.12) !important;
}

.mode-choice-card {
  box-sizing: border-box;
  max-width: 100%;
}

/* Variable insert buttons */
.insert-variable {
  padding: 0.55rem 0.5rem;
  background: var(--card-bg, #fff);
  border: 1.5px solid rgba(123, 97, 255, 0.3);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  color: #6366f1;
  transition: all 0.2s;
  text-align: center;
}

.insert-variable:hover {
  background: rgba(123, 97, 255, 0.08);
  border-color: #7b61ff;
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(99, 102, 241, 0.15);
}

/* ===================================
   CONTACTS SEARCH - Polished
   =================================== */
.email-contacts-search {
  padding: 0.625rem var(--spacing-sm, 0.75rem);
  border-bottom: 1px solid var(--border-color, #e5e7eb);
  background: var(--card-bg, #fff);
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.email-contacts-search input {
  flex: 1;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: 8px;
  font-size: 0.85rem;
  background: var(--bg-primary, #f7f7fa);
  color: var(--text-primary, #1f2937);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.email-contacts-search input:focus {
  outline: none;
  border-color: #7b61ff;
  box-shadow: 0 0 0 3px rgba(123, 97, 255, 0.1);
  background: var(--card-bg, #fff);
}

.email-contacts-search input::placeholder {
  color: var(--text-secondary, #9ca3af);
  font-size: 0.82rem;
}

.email-contacts-search .btn {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: 1px solid var(--border-color, #e5e7eb);
  background: var(--card-bg, #fff);
  color: var(--text-secondary, #6b7280);
  cursor: pointer;
  transition: all 0.2s;
}

.email-contacts-search .btn:hover {
  background: var(--bg-primary, #f3f4f6);
  color: #7b61ff;
  border-color: rgba(123, 97, 255, 0.3);
}

/* ===================================
   COMPOSE BUTTON - Details Column
   =================================== */
.email-compose-menu {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: center;
}

.email-action-btn.primary {
  padding: 0.75rem 1.75rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.95rem;
  border-radius: 10px;
  border: none;
  background: linear-gradient(135deg, #7b61ff 0%, #6366f1 100%);
  color: white;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 2px 10px rgba(99, 102, 241, 0.25);
}

.email-action-btn.primary:hover {
  background: linear-gradient(135deg, #6a52e8 0%, #4f46e5 100%);
  box-shadow: 0 4px 16px rgba(99, 102, 241, 0.35);
  transform: translateY(-2px);
}

/* ===================================
   COMPOSER PROGRESS BAR
   =================================== */
.wizard-progress-bar {
  width: 100%;
  height: 3px;
  background: var(--border-color, #e5e7eb);
  border-radius: 10px;
  overflow: hidden;
  margin-top: 0.75rem;
}

.wizard-progress-bar .wizard-progress-fill {
  height: 100%;
  background: linear-gradient(135deg, #7b61ff 0%, #6366f1 100%);
  border-radius: 10px;
  transition: width 0.3s ease;
}

.empty-state .empty-state-desc {
  margin: 0;
  font-size: 0.9rem;
}

/* ===================================
   EMAIL THREAD UNREAD STYLES
   Mantiene coerenza con WhatsApp
   =================================== */

.thread-item.unread {
  background: #faf5ff;
  border-left: 3px solid #c084fc;
}

[data-theme="dark"] .thread-item.unread {
  background: rgba(192, 132, 252, 0.08);
}

.thread-item.unread:hover {
  background: #f3e8ff;
}

[data-theme="dark"] .thread-item.unread:hover {
  background: rgba(192, 132, 252, 0.15);
}

.thread-item strong.unread-name {
  font-weight: 700;
  color: #991b1b;
}

[data-theme="dark"] .thread-item strong.unread-name {
  color: #fca5a5;
}

/* ===================================
   DELETED MESSAGE PLACEHOLDER STYLES
   Stile per messaggi eliminati esternamente
   =================================== */

.message-item.message-deleted {
  opacity: 0.7;
}

/* 🔴 DELETED ON SERVER: Stile per messaggi rimossi dal server IMAP */
.message-item.message-deleted-on-server {
  border-left: 3px solid #ef4444;
  background: rgba(239, 68, 68, 0.05);
}

[data-theme="dark"] .message-item.message-deleted-on-server {
  border-left-color: #f87171;
  background: rgba(239, 68, 68, 0.1);
}

.badge-deleted-server {
  background: #ef4444;
  color: #fff;
  font-size: 0.7rem;
  padding: 2px 6px;
  border-radius: 4px;
  margin-left: 8px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
}

.badge-deleted-server i {
  margin-right: 3px;
}

.message-body.deletion-placeholder {
  background: #f3f4f6;
  border-left: 3px solid #9ca3af;
  padding: 0.75rem;
  border-radius: 0.375rem;
  font-style: italic;
  color: #6b7280;
}

[data-theme="dark"] .message-body.deletion-placeholder {
  background: rgba(75, 85, 99, 0.2);
  border-left-color: #6b7280;
  color: #9ca3af;
}

.deletion-placeholder .deletion-icon {
  font-size: 1.2rem;
  margin-right: 0.5rem;
  opacity: 0.6;
}

.deletion-placeholder em {
  font-style: italic;
  font-size: 0.9rem;
}

/* ===== Channel Health Modal ===== */
.email-health-modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 10000;
  justify-content: center;
  align-items: center;
  animation: healthOverlayFadeIn 0.25s ease-out;
}

.email-health-modal-overlay.visible {
  display: flex;
}

@keyframes healthOverlayFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.email-health-modal {
  position: relative;
  background: #fff;
  border-radius: 16px;
  padding: 2rem 2.2rem 1.6rem;
  min-width: 360px;
  max-width: 480px;
  width: 90%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  text-align: center;
  animation: healthModalSlideIn 0.3s ease-out;
}

@keyframes healthModalSlideIn {
  from { opacity: 0; transform: translateY(-20px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.email-health-modal-close {
  position: absolute;
  top: 0.75rem;
  right: 0.85rem;
  background: none;
  border: none;
  font-size: 1.4rem;
  color: #9ca3af;
  cursor: pointer;
  padding: 0.25rem 0.4rem;
  line-height: 1;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
}

.email-health-modal-close:hover {
  color: #374151;
  background: #f3f4f6;
}

.email-health-modal-icon {
  font-size: 2.8rem;
  margin-bottom: 0.8rem;
}

.email-health-modal.severity-error .email-health-modal-icon {
  color: #dc2626;
}

.email-health-modal.severity-warning .email-health-modal-icon {
  color: #d97706;
}

.email-health-modal.severity-ok .email-health-modal-icon {
  color: #16a34a;
}

.email-health-modal-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  color: #1f2937;
}

.email-health-modal.severity-error .email-health-modal-title {
  color: #991b1b;
}

.email-health-modal.severity-warning .email-health-modal-title {
  color: #92400e;
}

.email-health-modal.severity-ok .email-health-modal-title {
  color: #166534;
}

.email-health-modal-detail {
  font-size: 0.88rem;
  color: #6b7280;
  line-height: 1.5;
  margin-bottom: 1.4rem;
  padding: 0 0.5rem;
}

.email-health-modal-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
}

.email-health-modal-actions .health-retry-btn {
  padding: 0.55rem 1.3rem;
  border: none;
  border-radius: 8px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, transform 0.1s;
}

.email-health-modal.severity-error .health-retry-btn {
  background: #dc2626;
  color: #fff;
}

.email-health-modal.severity-error .health-retry-btn:hover {
  background: #b91c1c;
}

.email-health-modal.severity-warning .health-retry-btn {
  background: #d97706;
  color: #fff;
}

.email-health-modal.severity-warning .health-retry-btn:hover {
  background: #b45309;
}

.email-health-modal-actions .health-retry-btn:active {
  transform: scale(0.97);
}

.email-health-modal-actions .health-retry-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.email-health-modal-actions .health-close-btn {
  padding: 0.55rem 1.3rem;
  background: #f3f4f6;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  color: #374151;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}

.email-health-modal-actions .health-close-btn:hover {
  background: #e5e7eb;
}

/* Dark mode */
[data-theme="dark"] .email-health-modal-overlay {
  background: rgba(0, 0, 0, 0.7);
}

[data-theme="dark"] .email-health-modal {
  background: #1f2937;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

[data-theme="dark"] .email-health-modal-close {
  color: #6b7280;
}

[data-theme="dark"] .email-health-modal-close:hover {
  color: #d1d5db;
  background: #374151;
}

[data-theme="dark"] .email-health-modal-title {
  color: #f3f4f6;
}

[data-theme="dark"] .email-health-modal.severity-error .email-health-modal-title {
  color: #fca5a5;
}

[data-theme="dark"] .email-health-modal.severity-warning .email-health-modal-title {
  color: #fcd34d;
}

[data-theme="dark"] .email-health-modal.severity-ok .email-health-modal-title {
  color: #86efac;
}

[data-theme="dark"] .email-health-modal-detail {
  color: #9ca3af;
}

[data-theme="dark"] .email-health-modal-actions .health-close-btn {
  background: #374151;
  border-color: #4b5563;
  color: #d1d5db;
}

[data-theme="dark"] .email-health-modal-actions .health-close-btn:hover {
  background: #4b5563;
}

/* ============================================================
   EMAIL ATTACHMENT DROP ZONE + DRAG REORDER
   ============================================================ */

/* Drop zone */
.email-att-dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 1.25rem 1rem;
  border: 2px dashed var(--border-color, #d1d5db);
  border-radius: 10px;
  background: var(--bg-primary, #fafafa);
  color: var(--text-secondary, #6b7280);
  font-size: 0.85rem;
  transition: all 0.2s ease;
  cursor: default;
}
.email-att-dropzone i {
  font-size: 1.5rem;
  color: var(--text-secondary, #9ca3af);
  transition: color 0.2s;
}
.email-att-dropzone small {
  font-size: 0.72rem;
  color: var(--text-secondary, #9ca3af);
}
.email-att-dropzone.active,
.email-att-dropzone:hover {
  border-color: #a855f7;
  background: rgba(168, 85, 247, 0.04);
}
.email-att-dropzone.active i {
  color: #a855f7;
}
.email-att-browse {
  color: #7c3aed;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
}
.email-att-browse:hover {
  color: #6d28d9;
}

/* Attachment list */
.email-att-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 0.65rem;
}
.email-att-list.compact {
  margin-top: 0;
  gap: 4px;
}

/* Single attachment item */
.email-att-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--card-bg, #fff);
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: 8px;
  font-size: 0.88rem;
  transition: all 0.2s ease;
  cursor: grab;
  user-select: none;
}
.email-att-item:hover {
  border-color: #a855f7;
  box-shadow: 0 1px 4px rgba(168, 85, 247, 0.1);
}
.email-att-item.dragging {
  opacity: 0.45;
  border-color: #a855f7;
  background: rgba(168, 85, 247, 0.06);
}
.email-att-item.att-drag-over {
  border-color: #7c3aed;
  box-shadow: 0 0 0 2px rgba(124, 58, 237, 0.18);
  transform: scale(1.01);
}

/* Drag handle */
.email-att-handle {
  color: var(--text-secondary, #9ca3af);
  font-size: 0.82rem;
  cursor: grab;
  padding: 0 2px;
  flex-shrink: 0;
}
.email-att-handle:hover {
  color: #7c3aed;
}

/* File icon */
.email-att-icon {
  color: #a855f7;
  font-size: 1rem;
  flex-shrink: 0;
}

/* File name */
.email-att-name {
  flex: 1;
  color: var(--text-primary, #374151);
  font-size: 0.88rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* File size */
.email-att-size {
  color: var(--text-secondary, #9ca3af);
  font-size: 0.75rem;
  flex-shrink: 0;
}

/* Remove button */
.email-att-remove {
  background: none;
  border: none;
  color: var(--text-secondary, #9ca3af);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  transition: all 0.15s;
  flex-shrink: 0;
}
.email-att-remove:hover {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.08);
}

/* Inline composer drag-over state */
.email-composer-dragover {
  outline: 2px dashed #a855f7 !important;
  outline-offset: -2px;
  background: rgba(168, 85, 247, 0.03) !important;
}

/* ---- Dark mode ---- */
[data-theme="dark"] .email-att-dropzone {
  border-color: #4b5563;
  background: #1f2937;
  color: #9ca3af;
}
[data-theme="dark"] .email-att-dropzone.active,
[data-theme="dark"] .email-att-dropzone:hover {
  border-color: #a855f7;
  background: rgba(168, 85, 247, 0.08);
}
[data-theme="dark"] .email-att-item {
  background: #1f2937;
  border-color: #374151;
}
[data-theme="dark"] .email-att-item:hover {
  border-color: #a855f7;
}
[data-theme="dark"] .email-att-item.dragging {
  background: rgba(168, 85, 247, 0.1);
}
[data-theme="dark"] .email-att-item.att-drag-over {
  border-color: #7c3aed;
  box-shadow: 0 0 0 2px rgba(124, 58, 237, 0.25);
}
[data-theme="dark"] .email-att-name {
  color: #e5e7eb;
}
[data-theme="dark"] .email-att-remove:hover {
  background: rgba(239, 68, 68, 0.15);
}

/* ================================================================
   DARK MODE — GLOBAL EMAIL FIXES
   Fix hardcoded #fff / #fafafa backgrounds not covered above
   ================================================================ */

/* Inline email composer */
[data-theme="dark"] #inline-email-composer {
  background: var(--card-bg, #1f2937);
  border-color: var(--border-color, #374151);
  box-shadow: 0 8px 40px rgba(0,0,0,0.4);
  color: var(--text-primary, #f9fafb);
}

/* Compose modal dialog */
[data-theme="dark"] .email-compose-dialog {
  background: var(--card-bg, #1f2937);
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
}
[data-theme="dark"] .email-compose-header {
  border-bottom-color: var(--border-color, #374151);
  color: var(--text-primary, #f9fafb);
}
[data-theme="dark"] .email-compose-input {
  background: var(--bg-secondary, #111827);
  border-top-color: var(--border-color, #374151);
}

/* Composer container (inline) */
[data-theme="dark"] .email-composer-container {
  background: var(--bg-secondary, #111827);
  border-top-color: var(--border-color, #374151);
}
[data-theme="dark"] .email-composer-container #composer-to,
[data-theme="dark"] .email-composer-container #composer-body {
  background: var(--card-bg, #1f2937);
  border-color: var(--border-color, #374151);
  color: var(--text-primary, #f9fafb);
}

/* Chat bubble content */
[data-theme="dark"] .tg-bubble-content {
  background: var(--card-bg, #1f2937);
  color: var(--text-primary, #f9fafb);
  box-shadow: 0 2px 12px rgba(0,0,0,0.25);
}
[data-theme="dark"] .tg-bubble.sent .tg-bubble-content {
  background: #312e81;
}
[data-theme="dark"] .tg-bubble-avatar {
  border-color: var(--bg-secondary, #1f2937);
}

/* Input bar */
[data-theme="dark"] .tg-inputbar {
  background: var(--bg-secondary, #111827);
  border-top-color: var(--border-color, #374151);
}
[data-theme="dark"] .tg-inputbar input[type="text"],
[data-theme="dark"] .tg-inputbar textarea {
  background: var(--card-bg, #1f2937);
  border-color: var(--border-color, #374151);
  color: var(--text-primary, #f9fafb);
}

/* Search input */
[data-theme="dark"] .tg-sidebar-search input:focus {
  background: var(--card-bg, #1f2937);
}

/* Thread viewer background */
[data-theme="dark"] .tg-viewer {
  background: var(--bg-primary, #111827);
}

/* Attachment item background fallback */
[data-theme="dark"] .attachment-item {
  background: var(--card-bg, #1f2937);
  border-color: var(--border-color, #374151);
  color: var(--text-primary, #f9fafb);
}

/* Selected chat item */
[data-theme="dark"] .tg-chat-item.selected,
[data-theme="dark"] .tg-chat-item:hover {
  background: rgba(124, 97, 255, 0.15);
  border-color: rgba(124, 97, 255, 0.3);
}

/* Panel body panels */
[data-theme="dark"] .tg-panel-body .tg-sidebar {
  border-right-color: var(--border-color, #374151);
  background: var(--bg-secondary, #111827);
}

