/* Modern Compact & Mobile-Responsive Design for Conversational Email Sender & Bulk Mailer */
:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --bg-main: #f8fafc;
  --card-bg: #ffffff;
  --border-color: #e2e8f0;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-sub: #475569;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background-color: var(--bg-main);
  color: var(--text-main);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  font-size: 13.5px;
}

/* Header */
.app-header {
  height: 52px;
  background: #ffffff;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 30;
  flex-shrink: 0;
}

.brand-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  width: 30px;
  height: 30px;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  flex-shrink: 0;
}

.brand-title {
  font-size: 14.5px;
  font-weight: 700;
  color: #0f172a;
  line-height: 1.2;
}

.brand-subtitle {
  font-size: 11px;
  color: #64748b;
  font-weight: 500;
}

/* View Switcher in Header */
.nav-view-switcher {
  display: flex;
  background: #f1f5f9;
  padding: 3px;
  border-radius: 8px;
  gap: 4px;
}

.nav-view-btn {
  padding: 5px 14px;
  font-size: 12.5px;
  font-weight: 600;
  color: #64748b;
  border: none;
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  gap: 6px;
}

.nav-view-btn:hover {
  color: #1e293b;
}

.nav-view-btn.active {
  background: #ffffff;
  color: var(--primary);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

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

/* App Main Container */
.app-main {
  display: flex;
  flex: 1;
  overflow: hidden;
  height: calc(100vh - 52px);
  position: relative;
}

/* View Container */
.view-section {
  display: flex;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.view-section.hidden {
  display: none !important;
}

/* Sidebar Conversations */
.sidebar-pane {
  width: 320px;
  min-width: 280px;
  max-width: 360px;
  background: #ffffff;
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-top {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-color);
}

.btn-compose {
  width: 100%;
  background: var(--primary);
  color: #ffffff;
  border: none;
  border-radius: 7px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.15s ease;
}

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

.search-box {
  margin-top: 10px;
  position: relative;
}

.search-input {
  width: 100%;
  padding: 7px 10px 7px 30px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  font-size: 12.5px;
  outline: none;
  background: #f8fafc;
  transition: border-color 0.15s ease;
}

.search-input:focus {
  border-color: var(--primary);
  background: #ffffff;
}

.search-icon {
  position: absolute;
  left: 9px;
  top: 50%;
  transform: translateY(-50%);
  color: #94a3b8;
  font-size: 12px;
}

/* Filter Tabs */
.filter-tabs {
  display: flex;
  padding: 6px 14px;
  gap: 6px;
  border-bottom: 1px solid var(--border-color);
  background: #fafbfd;
}

.filter-tab {
  padding: 4px 10px;
  font-size: 11.5px;
  font-weight: 600;
  color: #64748b;
  border-radius: 5px;
  cursor: pointer;
  border: none;
  background: transparent;
  transition: all 0.15s ease;
}

.filter-tab.active {
  background: #ffffff;
  color: var(--primary);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

/* Conversation List */
.conversation-list {
  flex: 1;
  overflow-y: auto;
}

.conversation-item {
  padding: 10px 14px;
  border-bottom: 1px solid #f1f5f9;
  cursor: pointer;
  display: flex;
  gap: 10px;
  transition: background 0.15s ease;
  position: relative;
}

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

.conversation-item.active {
  background-color: #eff6ff;
  border-left: 3px solid var(--primary);
}

.item-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #e2e8f0;
  color: #334155;
  font-weight: 700;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

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

.item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2px;
}

.item-name {
  font-size: 12.5px;
  font-weight: 600;
  color: #1e293b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-date {
  font-size: 10.5px;
  color: #94a3b8;
  flex-shrink: 0;
}

.item-subject {
  font-size: 12.5px;
  color: #334155;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}

.item-snippet {
  font-size: 11.5px;
  color: #64748b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.35;
}

.unread-badge {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: var(--primary);
  margin-left: 4px;
}

/* Thread Center Pane */
.thread-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #f8fafc;
  overflow: hidden;
}

.thread-header {
  height: 52px;
  padding: 0 18px;
  background: #ffffff;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.thread-header-info {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.mobile-back-btn {
  display: none;
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  color: #1e293b;
}

.thread-subject {
  font-size: 14.5px;
  font-weight: 700;
  color: #0f172a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.thread-participant {
  font-size: 11.5px;
  color: #64748b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.thread-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.thread-history {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Message Cards */
.message-bubble {
  max-width: 820px;
  width: 100%;
  border-radius: 9px;
  background: #ffffff;
  border: 1px solid var(--border-color);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  overflow: hidden;
}

.message-bubble.incoming {
  align-self: flex-start;
  border-left: 3px solid #64748b;
}

.message-bubble.outgoing {
  align-self: flex-end;
  border-left: 3px solid var(--primary);
  background: #ffffff;
}

.msg-header {
  padding: 8px 14px;
  background: #fafbfd;
  border-bottom: 1px solid #f1f5f9;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
}

.msg-from {
  font-weight: 600;
  color: #1e293b;
}

.msg-date {
  color: #94a3b8;
  font-size: 11px;
}

.msg-body {
  padding: 14px 16px;
  font-size: 13.5px;
  line-height: 1.6;
  color: #1e293b;
  word-break: break-word;
}

.msg-body p {
  margin-bottom: 10px;
}

.msg-body p:last-child {
  margin-bottom: 0;
}

/* Quoted text collapsible */
.quoted-text-toggle {
  display: inline-flex;
  align-items: center;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  padding: 2px 7px;
  font-size: 11px;
  font-weight: 600;
  color: #64748b;
  cursor: pointer;
  margin-top: 8px;
}

.quoted-text-content {
  display: none;
  margin-top: 8px;
  padding: 8px 12px;
  background: #f8fafc;
  border-left: 2px solid #cbd5e1;
  font-size: 12px;
  color: #64748b;
}

.quoted-text-content.open {
  display: block;
}

/* Outgoing Clean Summary Box */
.outgoing-content-box {
  color: #1e293b;
  font-size: 13.5px;
  line-height: 1.6;
}

.template-footer-badge {
  margin-top: 10px;
  padding: 6px 10px;
  background: #f8fafc;
  border: 1px dashed #e2e8f0;
  border-radius: 6px;
  font-size: 11px;
  color: #64748b;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Reply Box */
.thread-reply-box {
  background: #ffffff;
  border-top: 1px solid var(--border-color);
  padding: 12px 18px;
  flex-shrink: 0;
}

.reply-textarea {
  width: 100%;
  min-height: 70px;
  max-height: 160px;
  padding: 10px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 7px;
  font-size: 13px;
  line-height: 1.5;
  font-family: inherit;
  outline: none;
  resize: vertical;
  background-color: #ffffff !important;
  color: #0f172a !important;
  transition: border-color 0.15s ease;
}

.reply-textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}

.reply-footer {
  margin-top: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Spam Meter Component */
.spam-meter {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 500;
  background: #f1f5f9;
  padding: 3px 8px;
  border-radius: 16px;
}

.spam-meter.excellent {
  background: #ecfdf5;
  color: #065f46;
}

.spam-meter.good {
  background: #eff6ff;
  color: #1e40af;
}

.spam-meter.warning {
  background: #fffbeb;
  color: #92400e;
}

.spam-meter.danger {
  background: #fef2f2;
  color: #991b1b;
}

.spam-pill {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
}

/* Buttons */
.btn {
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: all 0.15s ease;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}

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

.btn-outline {
  background: #ffffff;
  border-color: var(--border-color);
  color: #334155;
}

.btn-outline:hover {
  background: #f8fafc;
  border-color: #cbd5e1;
}

.btn-sm {
  padding: 4px 8px;
  font-size: 11.5px;
}

/* Empty States */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #94a3b8;
  padding: 30px;
  text-align: center;
}

.empty-state-icon {
  font-size: 40px;
  margin-bottom: 10px;
  color: #cbd5e1;
}

/* ========================================================
   BULK EMAIL SENDER VIEW STYLES
   ======================================================== */
.bulk-layout {
  display: flex;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #f8fafc;
}

.bulk-form-pane {
  flex: 1.2;
  overflow-y: auto;
  padding: 20px 24px;
  border-right: 1px solid var(--border-color);
  background: #ffffff;
}

.bulk-side-pane {
  flex: 0.9;
  overflow-y: auto;
  padding: 20px 24px;
  background: #f8fafc;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.bulk-hero-card {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  padding: 14px 16px;
  margin-bottom: 18px;
  font-size: 12.5px;
  color: #1e40af;
  line-height: 1.5;
}

.bulk-textarea {
  width: 100%;
  min-height: 110px;
  max-height: 200px;
  padding: 10px 12px;
  border: 1px solid var(--border-color);
  border-radius: 7px;
  font-size: 12.5px;
  font-family: monospace;
  outline: none;
  background: #ffffff !important;
  color: #0f172a !important;
  resize: vertical;
}

.bulk-textarea:focus {
  border-color: var(--primary);
}

.recipients-stats-bar {
  display: flex;
  gap: 12px;
  margin-top: 6px;
  font-size: 12px;
  font-weight: 500;
  color: #64748b;
}

.tag-badge {
  display: inline-block;
  padding: 2px 7px;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  font-size: 11px;
  font-family: monospace;
  color: #334155;
  cursor: pointer;
}

.tag-badge:hover {
  background: #e2e8f0;
}

/* Progress Monitor */
.progress-card {
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.progress-bar-outer {
  width: 100%;
  height: 8px;
  background: #e2e8f0;
  border-radius: 4px;
  overflow: hidden;
  margin: 10px 0;
}

.progress-bar-inner {
  height: 100%;
  background: var(--primary);
  width: 0%;
  transition: width 0.25s ease;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  text-align: center;
  margin-top: 12px;
}

.stat-item {
  background: #f8fafc;
  border: 1px solid #f1f5f9;
  border-radius: 6px;
  padding: 8px 4px;
}

.stat-value {
  font-size: 16px;
  font-weight: 700;
  color: #0f172a;
}

.stat-label {
  font-size: 10.5px;
  color: #64748b;
  text-transform: uppercase;
  font-weight: 600;
}

/* Bulk Log Table */
.bulk-log-list {
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 12px;
  max-height: 260px;
  overflow-y: auto;
  font-size: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.bulk-log-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 8px;
  border-radius: 5px;
  background: #f8fafc;
}

.bulk-log-item.success {
  border-left: 3px solid var(--success);
}

.bulk-log-item.failed {
  border-left: 3px solid var(--danger);
  background: #fef2f2;
}

/* Modals */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-overlay.active {
  display: flex;
}

.modal-dialog {
  background: #ffffff;
  border-radius: 10px;
  width: 90%;
  max-width: 580px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
  overflow: hidden;
}

.modal-dialog.modal-lg {
  max-width: 760px;
}

.modal-header {
  padding: 12px 18px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 14.5px;
  font-weight: 700;
  color: #0f172a;
}

.modal-close {
  background: none;
  border: none;
  font-size: 18px;
  color: #94a3b8;
  cursor: pointer;
}

.modal-body {
  padding: 18px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 12px 18px;
  border-top: 1px solid var(--border-color);
  background: #fafbfd;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

/* Forms */
.form-group {
  margin-bottom: 14px;
}

.form-label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: #334155;
  margin-bottom: 5px;
}

.form-control {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  font-size: 12.5px;
  outline: none;
  background-color: #ffffff !important;
  color: #0f172a !important;
  transition: border-color 0.15s ease;
  font-family: inherit;
}

.form-control:focus {
  border-color: var(--primary);
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

/* Toast Notification */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: #1e293b;
  color: #ffffff;
  padding: 10px 14px;
  border-radius: 7px;
  font-size: 12.5px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
  animation: slideIn 0.2s ease-out forwards;
}

.toast.toast-error {
  background: #dc2626;
}

.toast.toast-success {
  background: #059669;
}

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

/* ========================================================
   MOBILE RESPONSIVENESS (< 768px)
   ======================================================== */
@media (max-width: 768px) {
  .app-header {
    height: 50px;
    padding: 0 12px;
  }

  .brand-subtitle {
    display: none;
  }

  .nav-view-switcher {
    padding: 2px;
  }

  .nav-view-btn {
    padding: 4px 8px;
    font-size: 11.5px;
  }

  .header-actions .btn-sm {
    padding: 4px 6px;
    font-size: 11px;
  }

  /* Split layout on mobile */
  .sidebar-pane {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 100% !important;
    border-right: none;
  }

  .thread-pane {
    width: 100% !important;
    display: none; /* hidden until conversation selected */
  }

  /* When mobile thread active */
  body.mobile-thread-active .sidebar-pane {
    display: none !important;
  }

  body.mobile-thread-active .thread-pane {
    display: flex !important;
  }

  .mobile-back-btn {
    display: inline-flex !important;
  }

  .thread-header {
    padding: 0 12px;
    height: 48px;
  }

  .thread-subject {
    max-width: 160px;
  }

  .thread-history {
    padding: 12px;
    gap: 10px;
  }

  .message-bubble {
    border-radius: 8px;
  }

  .msg-body {
    padding: 12px;
    font-size: 13px;
  }

  .thread-reply-box {
    padding: 10px 12px;
  }

  .reply-textarea {
    min-height: 60px;
  }

  /* Bulk view mobile layout */
  .bulk-layout {
    flex-direction: column;
    overflow-y: auto;
  }

  .bulk-form-pane {
    border-right: none;
    border-bottom: 1px solid var(--border-color);
    padding: 16px;
    flex: none;
  }

  .bulk-side-pane {
    padding: 16px;
    flex: none;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .modal-dialog {
    width: 95%;
    max-height: 94vh;
  }
}
