/* ESP RPD — Rapidmail Listenhygiene */
.esp-page {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, #f8fafc 0%, #eef2ff 100%);
  color: var(--text, #0f172a);
  font-family: Inter, system-ui, sans-serif;
}

.esp-wrap {
  max-width: 1400px;
  margin: 0 auto;
  padding: 16px 20px 48px;
}

.esp-topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 16px;
  margin-bottom: 18px;
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  box-shadow: 0 4px 20px rgba(15, 23, 42, 0.05);
}

.esp-topbar h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.esp-topbar h1 i[data-lucide],
.esp-panel-head h2 i[data-lucide],
.esp-chip i[data-lucide] {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  color: #6366f1;
}

.esp-panel-head h2 {
  display: flex;
  align-items: center;
  gap: 8px;
}

.esp-panel-head h2 i[data-lucide] {
  width: 20px;
  height: 20px;
}

.esp-chip i[data-lucide] {
  width: 14px;
  height: 14px;
  opacity: 0.85;
}

.esp-global-busy {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  padding: 10px 14px;
  border-radius: 12px;
  background: linear-gradient(90deg, #eef2ff, #f8fafc);
  border: 1px solid #c7d2fe;
  color: #3730a3;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 4px 16px rgba(99, 102, 241, 0.12);
}

.esp-global-busy i[data-lucide] {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.esp-spin {
  animation: esp-spin 0.75s linear infinite;
}

@keyframes esp-spin {
  to { transform: rotate(360deg); }
}

.esp-panel {
  position: relative;
}

.esp-panel-is-busy .esp-table-wrap,
.esp-panel-is-busy .esp-mailings-grid {
  opacity: 0.45;
  pointer-events: none;
}

.esp-panel-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.72);
  border-radius: 14px;
  backdrop-filter: blur(2px);
}

.esp-panel-overlay-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 20px 24px;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  box-shadow: 0 8px 30px rgba(15, 23, 42, 0.12);
  max-width: 90%;
  text-align: center;
}

.esp-panel-overlay-inner i[data-lucide] {
  width: 28px;
  height: 28px;
  color: #6366f1;
}

.esp-panel-overlay-msg {
  font-size: 13px;
  font-weight: 600;
  color: #334155;
}

.esp-status-inner {
  display: inline-flex;
  align-items: flex-start;
  gap: 8px;
}

.esp-status-inner i[data-lucide] {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  margin-top: 1px;
}

.esp-status.loading {
  background: #eef2ff;
  color: #3730a3;
  border: 1px solid #c7d2fe;
}

.esp-status.ok i[data-lucide] { color: #16a34a; }
.esp-status.err i[data-lucide] { color: #dc2626; }
.esp-status.warn i[data-lucide] { color: #d97706; }
.esp-status.info i[data-lucide] { color: #2563eb; }

.esp-btn-loading {
  opacity: 0.92;
  cursor: wait;
}

.esp-btn-loading i[data-lucide] {
  width: 14px;
  height: 14px;
  vertical-align: -2px;
}

.esp-readonly i[data-lucide] {
  width: 16px;
  height: 16px;
}

.esp-seg-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.esp-seg-tab i[data-lucide] {
  width: 14px;
  height: 14px;
}

.esp-controls label i[data-lucide] {
  width: 13px;
  height: 13px;
  margin-right: 4px;
  vertical-align: -2px;
  color: #64748b;
}

.esp-search-icon {
  position: relative;
  display: flex;
  align-items: center;
}

.esp-search-icon > i[data-lucide] {
  position: absolute;
  left: 10px;
  width: 15px;
  height: 15px;
  color: #94a3b8;
  pointer-events: none;
}

.esp-search-icon input {
  padding-left: 32px !important;
}

.esp-kpi {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.esp-kpi-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: #eef2ff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.esp-kpi-icon i[data-lucide] {
  width: 18px;
  height: 18px;
  color: #6366f1;
}

.esp-kpi-body { min-width: 0; }

.esp-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 28px 16px;
  color: #64748b;
  font-size: 13px;
}

.esp-empty i[data-lucide] {
  width: 32px;
  height: 32px;
  opacity: 0.5;
}

.esp-mailing-card h4 {
  display: flex;
  align-items: center;
  gap: 6px;
}

.esp-mailing-card h4 i[data-lucide] {
  width: 16px;
  height: 16px;
  color: #6366f1;
  flex-shrink: 0;
}

.esp-mailing-stats span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.esp-mailing-stats span i[data-lucide] {
  width: 12px;
  height: 12px;
  opacity: 0.7;
}

.esp-detail-body dt {
  display: flex;
  align-items: center;
  gap: 6px;
}

.esp-detail-body dt i[data-lucide] {
  width: 14px;
  height: 14px;
  color: #94a3b8;
}

.esp-debug-head h3 i[data-lucide] {
  width: 18px;
  height: 18px;
}

.btn i[data-lucide] {
  width: 14px;
  height: 14px;
}

.esp-topbar-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  flex: 1;
}

.esp-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  font-size: 12px;
  color: #475569;
}

.esp-chip b { color: #0f172a; }

.esp-readonly {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 2px solid #22c55e;
  background: #f0fdf4;
  font-size: 13px;
  font-weight: 600;
  color: #166534;
  cursor: pointer;
  user-select: none;
}

.esp-readonly.off {
  border-color: #ef4444;
  background: #fef2f2;
  color: #991b1b;
}

.esp-readonly input { width: 16px; height: 16px; }

.esp-readonly-short {
  display: none;
}

.esp-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 16px;
  align-items: start;
}

@media (max-width: 960px) {
  .esp-layout { grid-template-columns: 1fr; }
}

.esp-nav {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  padding: 10px;
  position: sticky;
  top: 68px;
}

.esp-nav button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  margin: 2px 0;
  border: none;
  border-radius: 10px;
  background: transparent;
  font: inherit;
  font-size: 13px;
  color: #334155;
  cursor: pointer;
}

.esp-nav button:hover { background: #f1f5f9; }
.esp-nav button.active {
  background: #eef2ff;
  color: #3730a3;
  font-weight: 600;
}

.esp-nav button i[data-lucide] { width: 16px; height: 16px; flex-shrink: 0; }

.esp-main {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  padding: 18px;
  min-height: 420px;
}

.esp-panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.esp-panel-head h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
}

.esp-panel-desc {
  margin: 0 0 14px;
  color: #64748b;
  font-size: 13px;
  line-height: 1.5;
}

.esp-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
}

.esp-controls label {
  font-size: 12px;
  color: #64748b;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.esp-controls label.esp-grow {
  flex: 1 1 220px;
  min-width: 200px;
}

.esp-controls input,
.esp-controls select {
  padding: 7px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font: inherit;
  font-size: 13px;
}

.esp-list-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 120px;
  overflow: auto;
  padding: 8px;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  background: #f8fafc;
  margin-bottom: 12px;
}

.esp-list-picker label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid #e2e8f0;
  font-size: 12px;
  cursor: pointer;
}

.esp-status {
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13px;
  margin-bottom: 12px;
}

.esp-status.info { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }
.esp-status.ok { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
.esp-status.err { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.esp-status.warn { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }

.esp-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.esp-badge i[data-lucide] {
  width: 12px;
  height: 12px;
}

.esp-badge-critical {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.esp-badge-low {
  background: #fff7ed;
  color: #c2410c;
  border: 1px solid #fed7aa;
}

.esp-badge-ok {
  background: #f0fdf4;
  color: #166534;
  border: 1px solid #bbf7d0;
}

.esp-table tr.esp-row-critical {
  background: rgba(254, 226, 226, 0.35);
}

.esp-table tr.esp-row-low {
  background: rgba(255, 237, 213, 0.35);
}

.esp-long-action-dialog {
  width: min(96vw, 520px);
}

.esp-long-action-body {
  padding: 16px 18px;
}

.esp-long-action-msg {
  margin: 0 0 12px;
  font-size: 14px;
  line-height: 1.5;
  color: #334155;
}

.esp-long-action-estimate {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #fff7ed;
  border: 1px solid #fed7aa;
  color: #9a3412;
  font-size: 14px;
}

.esp-long-action-estimate i[data-lucide] {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.esp-long-action-details {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  font-size: 13px;
  color: #475569;
  line-height: 1.45;
}

.esp-long-action-details ul {
  margin: 0;
  padding-left: 18px;
}

.esp-long-action-hint {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 0;
  font-size: 12px;
  color: #64748b;
  line-height: 1.45;
}

.esp-long-action-hint i[data-lucide] {
  width: 14px;
  height: 14px;
  margin-top: 2px;
  flex-shrink: 0;
}

.esp-long-action-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 12px 16px 16px;
  border-top: 1px solid #e2e8f0;
  background: #f8fafc;
}

.esp-table-wrap {
  overflow: auto;
  max-height: 520px;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
}

.esp-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.esp-table th,
.esp-table td {
  padding: 8px 10px;
  border-bottom: 1px solid #f1f5f9;
  text-align: left;
  vertical-align: top;
}

.esp-table th {
  position: sticky;
  top: 0;
  background: #f8fafc;
  font-weight: 600;
  color: #475569;
  z-index: 1;
}

.esp-table th.esp-num,
.esp-table td.esp-num {
  text-align: right;
  white-space: nowrap;
}

.esp-table-compact td,
.esp-table-compact th {
  padding: 6px 9px;
}

.esp-pct {
  display: block;
  font-size: 11px;
  color: #94a3b8;
  font-variant-numeric: tabular-nums;
}

.esp-mail-name {
  font-weight: 600;
  color: #1e293b;
  max-width: 360px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.esp-mail-sub {
  font-size: 11px;
  color: #94a3b8;
  margin-top: 2px;
}

.esp-loading {
  padding: 16px;
  text-align: center;
  color: #64748b;
  font-size: 13px;
}

.esp-table tr:hover td { background: #fafafa; }

.esp-kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.esp-kpi {
  padding: 12px;
  border-radius: 12px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
}

.esp-kpi .lbl { font-size: 11px; color: #64748b; text-transform: uppercase; letter-spacing: 0.04em; }
.esp-kpi .val { font-size: 22px; font-weight: 700; margin-top: 4px; }

.esp-hidden { display: none !important; }

.esp-actions-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid #e2e8f0;
}

.esp-actions-bar .btn.danger {
  background: #fef2f2;
  border-color: #fca5a5;
  color: #991b1b;
}

.esp-actions-bar .btn.danger:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.esp-mailings-grid {
  display: grid;
  gap: 10px;
}

.esp-mailing-card {
  padding: 12px;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  background: #fafafa;
}

.esp-mailing-card h4 {
  margin: 0 0 6px;
  font-size: 14px;
}

.esp-mailing-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 12px;
  color: #475569;
}

.esp-mailing-stats span {
  padding: 3px 8px;
  background: #fff;
  border-radius: 6px;
  border: 1px solid #e2e8f0;
}

.esp-search {
  flex: 1;
  min-width: 180px;
}

.esp-search input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font: inherit;
}

.esp-debug-modal {
  position: fixed;
  inset: 0;
  z-index: 5000;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.esp-debug-dialog {
  width: min(96vw, 1200px);
  max-height: 92vh;
  background: #fff;
  border-radius: 14px;
  border: 1px solid #e2e8f0;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.25);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.esp-debug-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid #e2e8f0;
  background: #f8fafc;
}

.esp-debug-head h3 {
  margin: 0;
  font-size: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.esp-debug-head-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.esp-debug-hint {
  margin: 0;
  padding: 10px 16px;
  font-size: 12px;
  color: #64748b;
  background: #fffbeb;
  border-bottom: 1px solid #fde68a;
}

.esp-debug-preview {
  flex: 1;
  overflow: auto;
  padding: 12px;
  background: #0f172a;
  min-height: 280px;
}

.esp-debug-preview svg {
  display: block;
  max-width: 100%;
  height: auto;
}

.esp-debug-text {
  margin: 0;
  font: 11px/1.4 Consolas, Monaco, monospace;
  color: #e2e8f0;
  white-space: pre-wrap;
  word-break: break-word;
}

.esp-job-progress {
  margin: 8px 0;
  font-size: 12px;
  color: #475569;
}

.esp-seg-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
}

.esp-seg-tab {
  padding: 7px 14px;
  border: 1px solid #cbd5e1;
  border-radius: 999px;
  background: #fff;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.esp-seg-tab.active {
  background: #eef2ff;
  border-color: #818cf8;
  color: #3730a3;
  font-weight: 600;
}

.esp-check-inline {
  flex-direction: row !important;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: #334155;
}

.esp-table-click tbody tr {
  cursor: pointer;
}

.esp-table-click tbody tr.selected td {
  background: #eef2ff;
}

.esp-table-click tbody tr.row-both td {
  box-shadow: inset 3px 0 0 #f59e0b;
}

.esp-bar-cell {
  min-width: 120px;
}

.esp-bar {
  height: 8px;
  background: #e2e8f0;
  border-radius: 4px;
  overflow: hidden;
}

.esp-bar > i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #6366f1, #818cf8);
  border-radius: 4px;
}

.esp-detail-body {
  padding: 16px 18px 20px;
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 8px 14px;
  font-size: 13px;
}

.esp-detail-body dt {
  margin: 0;
  color: #64748b;
  font-weight: 600;
}

.esp-detail-body dd {
  margin: 0;
  color: #0f172a;
  word-break: break-word;
}

.esp-detail-dialog {
  max-width: 640px;
}

.esp-table tr.row-not-on-list td {
  opacity: 0.55;
}

.rebuy-upload-row {
  margin-bottom: 8px;
}

.esp-segment-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0;
}

.esp-seg-tab {
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid #cbd5e1;
  background: #fff;
  cursor: pointer;
}

.esp-seg-tab.active {
  background: #0f172a;
  color: #fff;
  border-color: #0f172a;
}

.esp-exec-summary {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 12px;
  font-size: 13px;
}

.esp-exec-summary ul {
  margin: 8px 0 0;
  padding-left: 1.2rem;
}

.esp-mgr-modal .esp-mgr-body {
  max-height: 70vh;
  overflow: auto;
  padding: 4px 2px;
}

.mgr-report .mgr-verdict {
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 14px;
}

.mgr-verdict-good { background: #ecfdf5; border: 1px solid #6ee7b7; }
.mgr-verdict-neutral { background: #f8fafc; border: 1px solid #cbd5e1; }
.mgr-verdict-warn { background: #fffbeb; border: 1px solid #fcd34d; }
.mgr-verdict-critical { background: #fef2f2; border: 1px solid #fca5a5; }

.mgr-block { margin-bottom: 14px; }
.mgr-block h3 { font-size: 13px; margin: 0 0 8px; }
.mgr-table { width: 100%; font-size: 13px; border-collapse: collapse; }
.mgr-table td { padding: 4px 8px; border-bottom: 1px solid #e2e8f0; }
.mgr-segments { display: grid; gap: 10px; }
.mgr-seg { background: #f8fafc; padding: 10px; border-radius: 6px; font-size: 12px; }

body.esp-print-mgr .esp-wrap,
body.esp-print-mgr .tool-app-top,
body.esp-print-mgr .esp-nav {
  display: none !important;
}

body.esp-print-mgr #espRebuyManagerModal {
  display: block !important;
  position: static;
  background: #fff;
}

body.esp-print-mgr #espRebuyManagerModal.esp-hidden {
  display: block !important;
}

/* —— Mobile / Tablet —— */
@media (max-width: 960px) {
  .esp-nav {
    position: static;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px;
    padding: 8px;
    max-height: none;
  }

  .esp-nav button {
    padding: 10px 8px;
    font-size: 12px;
    min-height: 44px;
  }

  .esp-wrap {
    padding: 12px 12px 32px;
  }

  .esp-main {
    padding: 14px 12px;
  }
}

@media (max-width: 640px) {
  .esp-topbar {
    padding: 12px;
    gap: 10px;
  }

  .esp-topbar h1 {
    font-size: 17px;
    flex: 1 1 100%;
  }

  .esp-readonly {
    flex: 1 1 100%;
    font-size: 12px;
  }

  .esp-readonly-short {
    display: inline;
  }

  .esp-readonly-long {
    display: none;
  }

  .esp-controls label {
    flex: 1 1 100%;
    min-width: 0;
  }

  .esp-controls label.esp-grow {
    min-width: 0;
    flex: 1 1 100%;
  }

  .esp-controls input,
  .esp-controls select {
    width: 100%;
    font-size: 16px;
    min-height: 44px;
  }

  .esp-search {
    min-width: 0;
    flex: 1 1 100%;
    font-size: 16px;
  }

  .esp-seg-tabs {
    flex-wrap: wrap;
  }

  .esp-seg-tab {
    min-height: 40px;
  }

  .esp-table {
    min-width: 520px;
    font-size: 13px;
  }

  .esp-bar-cell {
    min-width: 72px;
  }

  .esp-kpi-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #panel-preflight .esp-controls .btn {
    flex: 1 1 100%;
    justify-content: center;
  }

  .esp-long-action-actions {
    flex-direction: column;
  }

  .esp-long-action-actions .btn {
    width: 100%;
    min-height: 44px;
  }

  .esp-debug-head-actions .btn {
    flex: 1 1 calc(50% - 4px);
    min-height: 40px;
  }
}

@media (max-width: 480px) {
  .esp-detail-body {
    grid-template-columns: 1fr;
    padding: 14px 12px 16px;
  }

  .esp-detail-body dt {
    margin-top: 8px;
  }

  .esp-nav {
    grid-template-columns: 1fr;
  }

  .esp-kpi-row {
    grid-template-columns: 1fr;
  }

  .mgr-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}
