/* ===== Dark Mode ===== */
:root {
  --bg-primary: #ffffff;
  --bg-secondary: #f8fafc;
  --bg-tertiary: #f1f5f9;
  --bg-hover: #f8fafc;
  --bg-active: #eff6ff;
  --border-primary: #e2e8f0;
  --border-secondary: #f1f5f9;
  --text-primary: #1e293b;
  --text-secondary: #475569;
  --text-tertiary: #64748b;
  --text-muted: #94a3b8;
  --shadow-sm: rgba(0,0,0,0.05);
  --shadow-md: rgba(0,0,0,0.1);
}

.dark {
  --bg-primary: #1e1e2e;
  --bg-secondary: #181825;
  --bg-tertiary: #313244;
  --bg-hover: #313244;
  --bg-active: #1e3a5f;
  --border-primary: #45475a;
  --border-secondary: #313244;
  --text-primary: #cdd6f4;
  --text-secondary: #bac2de;
  --text-tertiary: #a6adc8;
  --text-muted: #6c7086;
  --shadow-sm: rgba(0,0,0,0.2);
  --shadow-md: rgba(0,0,0,0.3);
}

/* Dark mode overrides */
.dark body,
.dark .bg-gray-100 { background-color: var(--bg-secondary) !important; color: var(--text-primary); }
.dark .bg-white,
.dark .bg-gray-50,
.dark .bg-gray-50\/80 { background-color: var(--bg-primary) !important; }
.dark header.bg-white { background-color: var(--bg-primary) !important; border-color: var(--border-primary) !important; }
.dark .border-gray-200,
.dark .border-gray-100 { border-color: var(--border-primary) !important; }
.dark .text-gray-800 { color: var(--text-primary) !important; }
.dark .text-gray-700 { color: var(--text-secondary) !important; }
.dark .text-gray-600 { color: var(--text-secondary) !important; }
.dark .text-gray-500 { color: var(--text-tertiary) !important; }
.dark .text-gray-400 { color: var(--text-muted) !important; }
.dark .text-gray-300 { color: var(--text-muted) !important; }
.dark .hover\:bg-gray-100:hover { background-color: var(--bg-tertiary) !important; }
.dark .hover\:bg-gray-200:hover { background-color: var(--bg-tertiary) !important; }
.dark .bg-gray-50 { background-color: var(--bg-tertiary) !important; }
.dark .border-gray-300 { border-color: var(--border-primary) !important; }
.dark input, .dark textarea, .dark select {
  background-color: var(--bg-tertiary) !important;
  color: var(--text-primary) !important;
  border-color: var(--border-primary) !important;
}
.dark input::placeholder, .dark textarea::placeholder { color: var(--text-muted) !important; }
.dark .email-item { border-color: var(--border-secondary) !important; }
.dark .email-item:hover { background-color: var(--bg-hover) !important; }
.dark .email-item.active { background-color: var(--bg-active) !important; }
.dark .email-item.unread { background-color: rgba(30,58,95,0.3) !important; }
.dark .email-item.unread .email-subject,
.dark .email-item.unread .email-from { color: var(--text-primary) !important; }
.dark .email-actions { background: linear-gradient(90deg, transparent, var(--bg-primary) 20%) !important; }
.dark .email-action-btn:hover { background: var(--bg-tertiary) !important; color: var(--text-primary) !important; }
.dark .reader-action-bar { background: var(--bg-secondary) !important; border-color: var(--border-secondary) !important; }
.dark .reader-action-btn:hover { background: var(--bg-tertiary) !important; color: var(--text-primary) !important; }
.dark .contact-card { background: var(--bg-primary) !important; border-color: var(--border-primary) !important; }
.dark .contact-card:hover { border-color: #93c5fd !important; }
.dark .contact-card-name { color: var(--text-primary) !important; }
.dark .contact-card-detail { color: var(--text-tertiary) !important; }
.dark .contact-action-btn:hover { background: var(--bg-tertiary) !important; color: var(--text-secondary) !important; }
.dark .calendar-grid { background: var(--border-primary) !important; border-color: var(--border-primary) !important; }
.dark .calendar-day { background: var(--bg-primary) !important; }
.dark .calendar-day:hover { background: var(--bg-hover) !important; }
.dark .calendar-day.today { background: var(--bg-active) !important; }
.dark .calendar-day.other-month { background: var(--bg-secondary) !important; }
.dark .calendar-day-header { background: var(--bg-secondary) !important; color: var(--text-tertiary) !important; }
.dark .calendar-day-number { color: var(--text-secondary) !important; }
.dark .calendar-day.other-month .calendar-day-number { color: var(--text-muted) !important; }
.dark .week-header { background: var(--bg-primary) !important; border-color: var(--border-primary) !important; }
.dark .week-row { border-color: var(--border-secondary) !important; }
.dark .week-cell { border-color: var(--border-secondary) !important; }
.dark .week-cell:hover { background: var(--bg-hover) !important; }
.dark .week-day-header { color: var(--text-tertiary) !important; }
.dark .week-day-header:hover { background: var(--bg-hover) !important; }
.dark .week-day-header.today { background: var(--bg-active) !important; }
.dark .week-day-num { color: var(--text-primary) !important; }
.dark .move-dropdown { background: var(--bg-primary) !important; border-color: var(--border-primary) !important; }
.dark .move-dropdown-item { color: var(--text-secondary) !important; }
.dark .move-dropdown-item:hover { background: var(--bg-tertiary) !important; color: var(--text-primary) !important; }
.dark .autocomplete-dropdown { background: var(--bg-primary) !important; border-color: var(--border-primary) !important; }
.dark .autocomplete-item:hover,
.dark .autocomplete-item.selected { background: var(--bg-tertiary) !important; }
.dark .autocomplete-item .name { color: var(--text-primary) !important; }
.dark .nav-tabs { background: var(--bg-tertiary) !important; }
.dark .nav-tab { color: var(--text-muted) !important; }
.dark .nav-tab.active { background: var(--bg-primary) !important; color: var(--text-primary) !important; }
.dark .nav-tab:hover:not(.active) { color: var(--text-secondary) !important; background: rgba(255,255,255,0.05) !important; }
.dark .btn-secondary { background: var(--bg-tertiary) !important; color: var(--text-secondary) !important; }
.dark .btn-secondary:hover { background: var(--border-primary) !important; }
.dark .attachment-chip { background: var(--bg-tertiary) !important; border-color: var(--border-primary) !important; color: var(--text-secondary) !important; }
.dark .settings-tab.active { background: var(--bg-active) !important; }
.dark .settings-tab:hover:not(.active) { background: var(--bg-tertiary) !important; }
.dark .skeleton { background: linear-gradient(90deg, var(--bg-tertiary) 25%, var(--border-primary) 50%, var(--bg-tertiary) 75%) !important; }
.dark .spinner { border-color: var(--border-primary) !important; border-top-color: #3b82f6 !important; }
.dark .signature-preview { border-color: var(--border-primary) !important; color: var(--text-tertiary) !important; }
.dark #composer-modal > div:not(.absolute) { background: var(--bg-primary) !important; }
.dark #contact-modal > div:not(.absolute) { background: var(--bg-primary) !important; }
.dark #event-modal > div:not(.absolute) { background: var(--bg-primary) !important; }
.dark #settings-modal > div:not(.absolute) { background: var(--bg-primary) !important; }
.dark .login-card { background: rgba(30, 30, 46, 0.97) !important; border-color: var(--border-primary) !important; }
.dark ::-webkit-scrollbar-thumb { background: #45475a; }
.dark ::-webkit-scrollbar-thumb:hover { background: #585b70; }

/* ===== Animazioni ===== */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

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

@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.4); }
  50% { box-shadow: 0 0 20px 4px rgba(59, 130, 246, 0.2); }
}

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

@keyframes bg-shift {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

.animate-fade-in { animation: fadeIn 0.4s ease-out; }
.animate-slide-up { animation: slideUp 0.3s ease-out; }

/* ===== Login background animated ===== */
.login-bg {
  background: linear-gradient(-45deg, #1e3a8a, #2563eb, #3b82f6, #1d4ed8);
  background-size: 400% 400%;
  animation: bg-shift 12s ease infinite;
  position: relative;
  overflow: hidden;
}

.login-bg::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(circle at 20% 50%, rgba(255,255,255,0.08) 0%, transparent 50%),
    radial-gradient(circle at 80% 20%, rgba(255,255,255,0.06) 0%, transparent 40%),
    radial-gradient(circle at 60% 80%, rgba(255,255,255,0.04) 0%, transparent 40%);
  pointer-events: none;
}

.login-card {
  backdrop-filter: blur(20px);
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.login-input {
  transition: all 0.25s ease;
  border: 1.5px solid #e2e8f0;
}

.login-input:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
  transform: translateY(-1px);
}

.login-btn {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.login-btn:hover {
  background: linear-gradient(135deg, #1d4ed8, #1e40af);
  transform: translateY(-1px);
  box-shadow: 0 8px 25px rgba(37, 99, 235, 0.35);
}

.login-btn:active {
  transform: translateY(0);
}

/* ===== Scrollbar personalizzata ===== */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ===== Navigazione Tab ===== */
.nav-tabs {
  display: flex;
  gap: 2px;
  background: #f1f5f9;
  border-radius: 10px;
  padding: 3px;
}

.nav-tab {
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  color: #64748b;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  cursor: pointer;
  border: none;
  background: transparent;
}

.nav-tab.active {
  background: white;
  color: #1e293b;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.nav-tab:hover:not(.active) {
  color: #374151;
  background: rgba(255,255,255,0.5);
}

/* ===== Sidebar premium ===== */
.sidebar-gradient {
  background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
}

.compose-btn {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  transition: all 0.3s ease;
  position: relative;
}

.compose-btn:hover {
  background: linear-gradient(135deg, #60a5fa, #3b82f6);
  transform: translateY(-1px);
  box-shadow: 0 8px 25px rgba(59, 130, 246, 0.4);
}

.compose-btn:active {
  transform: translateY(0);
}

.sidebar-divider {
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.1), transparent);
  margin: 8px 12px;
}

/* ===== Email list item ===== */
.email-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid #f1f5f9;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
}

.email-item:hover {
  background-color: #f8fafc;
}

.email-item:hover .email-actions {
  opacity: 1;
  pointer-events: auto;
}

.email-item.active {
  background-color: #eff6ff;
  border-left: 3px solid #2563eb;
}

.email-item.unread {
  background-color: #fefefe;
}

.email-checkbox { margin-right: -4px; }
.email-item.unread::before {
  content: '';
  position: absolute;
  left: 4px;
  top: 50%;
  transform: translateY(-50%);
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #3b82f6;
}

.email-item.unread .email-subject { font-weight: 600; color: #1e293b; }
.email-item.unread .email-from { font-weight: 600; color: #1e293b; }

.email-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
  flex-shrink: 0;
  transition: transform 0.2s ease;
}

.email-item:hover .email-avatar {
  transform: scale(1.05);
}

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

.email-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 2px;
}

.email-from {
  font-size: 13px;
  color: #475569;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.email-date {
  font-size: 11px;
  color: #94a3b8;
  white-space: nowrap;
  flex-shrink: 0;
}

.email-subject {
  font-size: 13px;
  color: #64748b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
  transition: color 0.3s ease, font-weight 0.3s ease;
}

.email-preview {
  font-size: 12px;
  color: #94a3b8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
}

.email-badges {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* Azioni rapide hover */
.email-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: linear-gradient(90deg, transparent, #f8fafc 20%);
  padding-left: 20px;
}

.email-action-btn {
  padding: 4px;
  border-radius: 6px;
  transition: all 0.15s ease;
  color: #94a3b8;
}

.email-action-btn:hover {
  background: #e2e8f0;
  color: #475569;
}

.email-action-btn.delete-btn:hover {
  background: #fee2e2;
  color: #dc2626;
}

.email-star {
  color: #cbd5e1;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.email-star:hover,
.email-star.active {
  color: #f59e0b;
}

.email-star.active {
  fill: #f59e0b;
}

/* ===== Folder item ===== */
.folder-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
  color: #94a3b8;
  font-size: 13px;
}

.folder-item:hover {
  background-color: rgba(255,255,255,0.08);
  color: #e2e8f0;
  transform: translateX(2px);
}

.folder-item.active {
  background: linear-gradient(135deg, rgba(59,130,246,0.25), rgba(59,130,246,0.15));
  color: white;
  font-weight: 500;
}

.folder-badge {
  margin-left: auto;
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: white;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  min-width: 22px;
  text-align: center;
  box-shadow: 0 2px 6px rgba(59, 130, 246, 0.3);
}

/* ===== Composer placeholder ===== */
#composer-body:empty:before {
  content: attr(data-placeholder);
  color: #9ca3af;
  pointer-events: none;
}

/* ===== Signature editor placeholder ===== */
#signature-editor:empty:before {
  content: attr(data-placeholder);
  color: #9ca3af;
  pointer-events: none;
}

/* ===== Composer minimized ===== */
.composer-minimized {
  position: fixed !important;
  bottom: 0 !important;
  right: 24px !important;
  left: auto !important;
  top: auto !important;
  width: 320px !important;
  max-width: calc(100vw - 48px) !important;
  height: auto !important;
  max-height: none !important;
  z-index: 50;
  display: flex !important;
  flex-direction: column;
}

.composer-minimized > .absolute { display: none !important; }

.composer-minimized > div:not(.absolute) {
  border-radius: 12px 12px 0 0 !important;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.15) !important;
  max-height: 48px !important;
  overflow: hidden;
}

.composer-minimized .composer-min-bar {
  cursor: pointer;
}

/* ===== Toast ===== */
.toast {
  padding: 12px 20px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 10px 40px rgba(0,0,0,0.15);
  animation: slideUp 0.3s ease-out;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 400px;
  backdrop-filter: blur(10px);
}

.toast.success { background: linear-gradient(135deg, #059669, #047857); color: white; }
.toast.error { background: linear-gradient(135deg, #dc2626, #b91c1c); color: white; }
.toast.info { background: linear-gradient(135deg, #2563eb, #1d4ed8); color: white; }

/* ===== Attachment chip ===== */
.attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  font-size: 12px;
  color: #475569;
  cursor: pointer;
  transition: all 0.2s ease;
}

.attachment-chip:hover {
  background: #e2e8f0;
  border-color: #cbd5e1;
  transform: translateY(-1px);
}

.attachment-icon {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.att-pdf { background: #fee2e2; color: #dc2626; }
.att-img { background: #dbeafe; color: #2563eb; }
.att-doc { background: #dbeafe; color: #1d4ed8; }
.att-zip { background: #fef3c7; color: #d97706; }
.att-default { background: #f1f5f9; color: #64748b; }

/* ===== Loading skeleton ===== */
.skeleton {
  background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 50%, #f1f5f9 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 6px;
}

.skeleton-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
}

.skeleton-line {
  height: 12px;
  margin-bottom: 6px;
}

.skeleton-line.short { width: 60%; }
.skeleton-line.medium { width: 80%; }
.skeleton-line.long { width: 95%; }

.email-skeleton {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid #f1f5f9;
}

/* ===== Loading spinner ===== */
.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid #e2e8f0;
  border-top-color: #3b82f6;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

.loading-center {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  flex-direction: column;
  gap: 12px;
  color: #94a3b8;
}

/* ===== Reader improvements ===== */
.reader-action-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 16px;
  border-bottom: 1px solid #f1f5f9;
  background: #fafbfc;
}

.reader-action-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 12px;
  color: #64748b;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.reader-action-btn:hover {
  background: #f1f5f9;
  color: #1e293b;
}

.reader-action-btn.danger:hover {
  background: #fee2e2;
  color: #dc2626;
}

/* Move dropdown */
.move-dropdown {
  position: absolute;
  right: 0;
  top: 100%;
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.12);
  min-width: 200px;
  z-index: 50;
  padding: 4px;
  animation: fadeIn 0.2s ease-out;
}

.move-dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  color: #475569;
  cursor: pointer;
  transition: all 0.15s ease;
}

.move-dropdown-item:hover {
  background: #f1f5f9;
  color: #1e293b;
}

/* ===== Mobile back button ===== */
.mobile-back-btn {
  display: none;
  padding: 8px;
  border-radius: 8px;
  transition: all 0.2s ease;
  color: #64748b;
}

.mobile-back-btn:hover {
  background: #f1f5f9;
  color: #1e293b;
}

/* ===== Contacts Card Grid ===== */
.contacts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 12px;
}

.contact-card {
  background: white;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
  padding: 16px;
  display: flex;
  gap: 14px;
  align-items: flex-start;
  transition: all 0.2s ease;
  position: relative;
}

.contact-card:hover {
  border-color: #93c5fd;
  box-shadow: 0 2px 12px rgba(59, 130, 246, 0.08);
}

.contact-card:hover .contact-card-actions {
  opacity: 1;
}

.contact-card-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  flex-shrink: 0;
}

.contact-card-info {
  flex: 1;
  min-width: 0;
}

.contact-card-name {
  font-size: 15px;
  font-weight: 600;
  color: #1e293b;
  margin-bottom: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contact-card-detail {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: #64748b;
  margin-bottom: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contact-card-detail i {
  color: #94a3b8;
  flex-shrink: 0;
}

.contact-card-actions {
  display: flex;
  gap: 4px;
  position: absolute;
  top: 12px;
  right: 12px;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.contact-action-btn {
  padding: 6px;
  border-radius: 8px;
  color: #94a3b8;
  transition: all 0.15s ease;
  cursor: pointer;
  border: none;
  background: transparent;
}

.contact-action-btn:hover {
  background: #f1f5f9;
  color: #475569;
}

.contact-delete-btn:hover {
  background: #fee2e2 !important;
  color: #dc2626 !important;
}

.contact-email-btn:hover {
  background: #dbeafe !important;
  color: #2563eb !important;
}

/* ===== Autocomplete dropdown ===== */
.autocomplete-dropdown {
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.12);
  max-height: 200px;
  overflow-y: auto;
  z-index: 50;
  animation: fadeIn 0.2s ease-out;
}

.autocomplete-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.autocomplete-item:hover,
.autocomplete-item.selected {
  background: #f1f5f9;
}

.autocomplete-item .name {
  font-size: 13px;
  font-weight: 500;
  color: #1e293b;
}

.autocomplete-item .email {
  font-size: 12px;
  color: #94a3b8;
}

/* ===== Signature area ===== */
.signature-preview {
  border-top: 1px dashed #e2e8f0;
  padding-top: 12px;
  margin-top: 12px;
  color: #64748b;
  font-size: 13px;
}

/* ===== Avatar colors ===== */
.avatar-0 { background: #dbeafe; color: #2563eb; }
.avatar-1 { background: #dcfce7; color: #16a34a; }
.avatar-2 { background: #fef3c7; color: #d97706; }
.avatar-3 { background: #fce7f3; color: #db2777; }
.avatar-4 { background: #e0e7ff; color: #4f46e5; }
.avatar-5 { background: #ccfbf1; color: #0d9488; }
.avatar-6 { background: #fee2e2; color: #dc2626; }
.avatar-7 { background: #f3e8ff; color: #9333ea; }

/* ===== Settings modal ===== */
.settings-tab {
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  color: #64748b;
  cursor: pointer;
  transition: all 0.2s ease;
}

.settings-tab.active {
  background: #eff6ff;
  color: #2563eb;
  font-weight: 500;
}

.settings-tab:hover:not(.active) {
  background: #f8fafc;
}

/* ===== General buttons ===== */
.btn-primary {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: white;
  padding: 8px 20px;
  border-radius: 10px;
  font-weight: 500;
  font-size: 14px;
  transition: all 0.25s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
  cursor: pointer;
}

.btn-primary:hover {
  background: linear-gradient(135deg, #1d4ed8, #1e40af);
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(37, 99, 235, 0.3);
}

.btn-secondary {
  background: #f1f5f9;
  color: #475569;
  padding: 8px 20px;
  border-radius: 10px;
  font-weight: 500;
  font-size: 14px;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
  cursor: pointer;
}

.btn-secondary:hover {
  background: #e2e8f0;
}

/* ========== CALENDARIO ========== */

.calendar-view-btn {
  background: transparent;
  border: none;
  color: #64748b;
  cursor: pointer;
  transition: all 0.2s;
  font-weight: 500;
}

.calendar-view-btn:hover {
  background: #f1f5f9;
}

.calendar-view-btn.active {
  background: #3b82f6;
  color: white;
}

/* Griglia mese */
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
  background: #e2e8f0;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  overflow: hidden;
}

.calendar-day-header {
  background: #f8fafc;
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  color: #64748b;
  padding: 8px 0;
  text-transform: uppercase;
}

.calendar-day {
  background: white;
  min-height: 100px;
  padding: 6px;
  cursor: pointer;
  transition: background 0.15s;
}

.calendar-day:hover {
  background: #f0f9ff;
}

.calendar-day.today {
  background: #eff6ff;
}

.calendar-day.today .calendar-day-number {
  background: #3b82f6;
  color: white;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
}

.calendar-day.other-month {
  background: #fafbfc;
}

.calendar-day.other-month .calendar-day-number {
  color: #cbd5e1;
}

.calendar-day-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.calendar-day-number {
  font-size: 13px;
  font-weight: 500;
  color: #374151;
}

.calendar-day-add {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: #94a3b8;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: all 0.15s ease;
  line-height: 1;
}

.calendar-day:hover .calendar-day-add {
  opacity: 1;
}

.calendar-day-add:hover {
  background: #3b82f6;
  color: white;
}

.calendar-day-events {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.calendar-event-dot {
  font-size: 11px;
  padding: 3px 6px;
  border-radius: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  line-height: 1.4;
  font-weight: 500;
  transition: opacity 0.15s;
}

.calendar-event-dot:hover {
  opacity: 0.8;
}

.calendar-event-more {
  font-size: 10px;
  color: #64748b;
  padding: 1px 4px;
  cursor: pointer;
}

.calendar-event-more:hover {
  color: #3b82f6;
}

/* Colori eventi */
.event-blue { background: #dbeafe; color: #1d4ed8; }
.event-green { background: #dcfce7; color: #15803d; }
.event-red { background: #fee2e2; color: #b91c1c; }
.event-amber { background: #fef3c7; color: #b45309; }
.event-purple { background: #f3e8ff; color: #7e22ce; }
.event-teal { background: #ccfbf1; color: #0f766e; }

/* Vista settimana */
.week-grid {
  display: flex;
  flex-direction: column;
  min-height: 600px;
}

.week-header {
  display: flex;
  border-bottom: 2px solid #e2e8f0;
  position: sticky;
  top: 0;
  z-index: 2;
  background: white;
}

.week-hour-spacer {
  width: 56px;
  flex-shrink: 0;
}

.week-day-header {
  flex: 1;
  text-align: center;
  padding: 8px 4px;
  font-size: 12px;
  color: #64748b;
  cursor: pointer;
  transition: background 0.15s;
}

.week-day-header:hover {
  background: #f1f5f9;
}

.week-day-header.today {
  background: #eff6ff;
}

.week-day-header.today .week-day-num {
  background: #3b82f6;
  color: white;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
}

.week-day-name {
  display: block;
  font-weight: 600;
  text-transform: uppercase;
  font-size: 10px;
}

.week-day-num {
  font-size: 15px;
  font-weight: 600;
  color: #374151;
}

.week-body {
  flex: 1;
  position: relative;
  overflow: visible;
}

.week-row {
  display: flex;
  min-height: 48px;
  border-bottom: 1px solid #e9edf2;
}

.week-hour-label {
  width: 56px;
  flex-shrink: 0;
  font-size: 11px;
  color: #94a3b8;
  text-align: right;
  padding-right: 10px;
  padding-top: 2px;
}

.week-cell {
  flex: 1;
  border-left: 1px solid #e9edf2;
  cursor: pointer;
  transition: background 0.15s;
}

.week-cell:hover {
  background: #f0f9ff;
}

.week-event-block {
  position: absolute;
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 11px;
  overflow: hidden;
  cursor: pointer;
  z-index: 1;
  border-left: 3px solid;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  font-weight: 500;
}

.week-event-block.event-blue { border-left-color: #2563eb; }
.week-event-block.event-green { border-left-color: #16a34a; }
.week-event-block.event-red { border-left-color: #dc2626; }
.week-event-block.event-amber { border-left-color: #d97706; }
.week-event-block.event-purple { border-left-color: #9333ea; }
.week-event-block.event-teal { border-left-color: #0d9488; }

/* All-day events area */
.week-allday-area {
  display: flex;
  border-bottom: 2px solid #e2e8f0;
  min-height: 32px;
  position: relative;
}

.week-allday-cell {
  flex: 1;
  border-left: 1px solid #e9edf2;
  padding: 2px;
  min-height: 28px;
}

.week-event-allday {
  padding: 3px 10px;
  border-radius: 6px;
  font-size: 11px;
  margin: 2px;
  cursor: pointer;
  font-weight: 500;
}

/* ===== Density options ===== */
.density-compact .email-item { padding: 8px 16px; gap: 8px; }
.density-compact .email-avatar { width: 32px; height: 32px; font-size: 12px; }
.density-compact .email-from { font-size: 12px; }
.density-compact .email-subject { font-size: 12px; }
.density-compact .email-preview { font-size: 11px; }
.density-compact .email-date { font-size: 10px; }

.density-comfortable .email-item { padding: 16px 16px; gap: 14px; }
.density-comfortable .email-avatar { width: 46px; height: 46px; font-size: 16px; }
.density-comfortable .email-from { font-size: 14px; }
.density-comfortable .email-subject { font-size: 14px; margin-bottom: 4px; }
.density-comfortable .email-preview { font-size: 13px; }

/* ===== Reader resize handle ===== */
.reader-resize-handle {
  width: 4px;
  cursor: col-resize;
  background: transparent;
  transition: background 0.2s;
  flex-shrink: 0;
  position: relative;
  z-index: 5;
}

.reader-resize-handle:hover,
.reader-resize-handle.active {
  background: #3b82f6;
}

.reader-resize-handle::after {
  content: '';
  position: absolute;
  inset: 0 -4px;
}

/* ===== Responsive ===== */
@media (max-width: 1023px) {
  #reader-panel {
    position: fixed;
    inset: 0;
    width: 100% !important;
    z-index: 30;
    display: none;
  }
  #reader-panel.mobile-open {
    display: flex !important;
  }
  .mobile-back-btn {
    display: flex !important;
  }
  .email-item.unread::before {
    left: 4px;
    width: 6px;
    height: 6px;
  }
  .email-actions {
    display: none !important;
  }
  .contacts-grid {
    grid-template-columns: 1fr;
  }
  .contact-card-actions {
    opacity: 1;
  }
  .nav-tab {
    padding: 6px 10px;
  }
}

@media (max-width: 639px) {
  .contacts-grid {
    gap: 8px;
  }
  .contact-card {
    padding: 12px;
  }
  .calendar-day {
    min-height: 60px;
    padding: 3px;
  }
  .calendar-day-number {
    font-size: 11px;
  }
  .calendar-event-dot {
    font-size: 9px;
    padding: 1px 3px;
  }
  /* Settimana mobile: scroll orizzontale su 3 giorni */
  .week-grid {
    min-height: 400px;
  }
  .week-header {
    overflow-x: auto;
    scroll-snap-type: x mandatory;
  }
  .week-day-header {
    min-width: calc(100% / 3);
    scroll-snap-align: start;
  }
  .week-body {
    overflow-x: auto;
  }
  .week-row {
    min-width: calc(700px / 3 * 7);
  }
  .week-cell {
    min-width: calc(700px / 3);
  }
  /* Hide calendar sidebar on mobile */
  #calendar-sidebar {
    display: none;
  }
}

/* ===== Calendar Sidebar ===== */
#calendar-sidebar {
  background: var(--bg-secondary);
  border-color: var(--border-primary);
}
.cal-sidebar-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 6px;
  border-radius: 6px;
  transition: background 0.15s;
}
.cal-sidebar-item:hover {
  background: var(--bg-hover);
}
.cal-sidebar-label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  flex: 1;
  min-width: 0;
}
.cal-sidebar-label input[type="checkbox"] {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  flex-shrink: 0;
}
.cal-color-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.cal-name-text {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cal-shared-badge {
  font-size: 9px;
  color: var(--text-muted);
  background: var(--bg-tertiary);
  padding: 1px 5px;
  border-radius: 4px;
  flex-shrink: 0;
}
.cal-sidebar-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity 0.15s;
}
.cal-sidebar-item:hover .cal-sidebar-actions {
  opacity: 1;
}
.cal-action-btn {
  padding: 3px;
  border-radius: 4px;
  color: var(--text-tertiary);
  cursor: pointer;
  border: none;
  background: none;
  transition: all 0.15s;
}
.cal-action-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}
.cal-add-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 6px 8px;
  margin-top: 4px;
  border: 1px dashed var(--border-primary);
  border-radius: 6px;
  font-size: 12px;
  color: var(--text-tertiary);
  background: none;
  cursor: pointer;
  transition: all 0.15s;
}
.cal-add-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--text-muted);
}

/* ===== Share Modal ===== */
.cal-share-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border-secondary);
}
.cal-share-item:last-child {
  border-bottom: none;
}
.cal-share-email {
  flex: 1;
  font-size: 13px;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cal-share-role-badge {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  background: #e0f2fe;
  color: #0369a1;
}
.cal-share-role-badge.pending {
  background: #fef3c7;
  color: #92400e;
}
.cal-share-role-badge.declined {
  background: #fee2e2;
  color: #991b1b;
}
.cal-share-remove-btn {
  padding: 3px;
  border-radius: 4px;
  color: var(--text-muted);
  cursor: pointer;
  border: none;
  background: none;
  transition: all 0.15s;
}
.cal-share-remove-btn:hover {
  color: #dc2626;
  background: #fee2e2;
}

/* ===== Invitation Modal ===== */
.invitation-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border: 1px solid var(--border-primary);
  border-radius: 8px;
  background: var(--bg-secondary);
}
.invitation-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.invitation-sender {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
}
.invitation-calendar {
  font-size: 12px;
  color: var(--text-tertiary);
}
.invitation-actions {
  display: flex;
  gap: 6px;
}

/* ===== Dark Mode overrides for calendar sidebar/modals ===== */
.dark #calendar-sidebar {
  background: var(--bg-secondary);
  border-color: var(--border-primary);
}
.dark .cal-share-role-badge {
  background: #1e3a5f;
  color: #7dd3fc;
}
.dark .cal-share-role-badge.pending {
  background: #451a03;
  color: #fcd34d;
}
.dark .cal-share-role-badge.declined {
  background: #450a0a;
  color: #fca5a5;
}
.dark .cal-share-remove-btn:hover {
  background: #450a0a;
  color: #fca5a5;
}

/* ===== Calendar mode toggle ===== */
.calendar-mode-btn {
  transition: all 0.15s ease;
  color: #64748b;
  cursor: pointer;
}
.calendar-mode-btn:hover { color: #334155; background: #e2e8f0; }
.calendar-mode-btn.active {
  background: white;
  color: #1e293b;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}
.dark .calendar-mode-btn { color: var(--text-muted); }
.dark .calendar-mode-btn:hover { color: var(--text-primary); background: var(--bg-tertiary); }
.dark .calendar-mode-btn.active { background: var(--bg-primary); color: var(--text-primary); }

/* ===== Attendee tags ===== */
.attendee-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px 2px 10px;
  background: #eff6ff;
  color: #2563eb;
  border-radius: 9999px;
  font-size: 12px;
  line-height: 1.5;
}
.attendee-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  font-size: 14px;
  line-height: 1;
  color: #93c5fd;
  cursor: pointer;
  transition: all 0.15s;
}
.attendee-remove:hover {
  background: #bfdbfe;
  color: #1d4ed8;
}
.dark .attendee-tag { background: #1e3a5f; color: #7dd3fc; }
.dark .attendee-remove { color: #38bdf8; }
.dark .attendee-remove:hover { background: #164e63; color: #e0f2fe; }

/* ===== Tasks list ===== */
.task-group { margin-bottom: 20px; }
.task-group-title {
  font-size: 13px;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding-bottom: 6px;
  border-bottom: 1px solid #e2e8f0;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.task-group-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  background: #f1f5f9;
  color: #475569;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
}
.task-group-overdue .task-group-title { color: #dc2626; border-color: #fecaca; }
.task-group-overdue .task-group-count { background: #fee2e2; color: #dc2626; }
.task-group-today .task-group-title { color: #2563eb; border-color: #bfdbfe; }
.task-group-today .task-group-count { background: #dbeafe; color: #2563eb; }

.task-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  transition: background 0.15s;
  cursor: default;
}
.task-item:hover { background: #f8fafc; }
.task-item.task-completed { opacity: 0.55; }
.task-item.task-completed .task-item-title { text-decoration: line-through; }

.task-check {
  margin-top: 3px;
  width: 16px;
  height: 16px;
  border-radius: 4px;
  border: 2px solid #cbd5e1;
  cursor: pointer;
  flex-shrink: 0;
  accent-color: #2563eb;
}
.task-item-body {
  flex: 1;
  min-width: 0;
  cursor: pointer;
}
.task-item-title {
  font-size: 14px;
  font-weight: 500;
  color: #1e293b;
  line-height: 1.3;
}
.task-item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 3px;
  font-size: 11px;
  color: #94a3b8;
}
.task-due {
  color: #64748b;
}
.task-group-overdue .task-due { color: #dc2626; font-weight: 500; }
.task-pct {
  background: #f1f5f9;
  padding: 0 5px;
  border-radius: 4px;
  font-weight: 500;
}
.task-cat-badge {
  background: #ede9fe;
  color: #7c3aed;
  padding: 0 6px;
  border-radius: 4px;
  font-weight: 500;
}
.task-loc { color: #94a3b8; }
.task-priority {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 3px;
  font-size: 11px;
  font-weight: 700;
  margin-right: 4px;
  vertical-align: middle;
}
.task-priority-high { background: #fee2e2; color: #dc2626; }
.task-priority-medium { background: #fef3c7; color: #d97706; }

/* Dark mode tasks */
.dark .task-group-title { color: var(--text-muted); border-color: var(--border-primary); }
.dark .task-group-count { background: var(--bg-tertiary); color: var(--text-secondary); }
.dark .task-group-overdue .task-group-title { color: #f87171; }
.dark .task-group-overdue .task-group-count { background: #450a0a; color: #fca5a5; }
.dark .task-group-today .task-group-title { color: #60a5fa; }
.dark .task-group-today .task-group-count { background: #1e3a5f; color: #93c5fd; }
.dark .task-item:hover { background: var(--bg-hover); }
.dark .task-item-title { color: var(--text-primary); }
.dark .task-item-meta { color: var(--text-muted); }
.dark .task-check { border-color: var(--border-primary); }
.dark .task-pct { background: var(--bg-tertiary); }
.dark .task-cat-badge { background: #2e1065; color: #c4b5fd; }
.dark .task-priority-high { background: #450a0a; color: #fca5a5; }
.dark .task-priority-medium { background: #451a03; color: #fcd34d; }
