/* ── Reset & Base ── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --color-bg: #f4f5f7;
  --color-surface: #ffffff;
  --color-border: #dfe1e6;
  --color-text: #172b4d;
  --color-text-secondary: #5e6c84;
  --color-text-muted: #97a0af;
  --color-primary: #0052cc;
  --color-primary-hover: #0747a6;
  --color-danger: #de350b;
  --color-danger-hover: #bf2600;
  --color-success: #00875a;
  --color-warning: #ff8b00;
  --color-info: #00b8d9;
  --color-gray: #97a0af;
  --radius: 4px;
  --shadow: 0 1px 3px rgba(9, 30, 66, 0.08), 0 0 1px rgba(9, 30, 66, 0.12);
  --shadow-lg: 0 4px 8px rgba(9, 30, 66, 0.12), 0 0 1px rgba(9, 30, 66, 0.16);
  --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,
    Ubuntu, Cantarell, 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Fira Mono', 'Roboto Mono', monospace;
}

html {
  font-size: 14px;
}

body {
  font-family: var(--font-family);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  min-height: 100vh;
}

/* ── Header ── */
.header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-logo {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--color-primary);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-logo span {
  display: inline-block;
  width: 28px;
  height: 28px;
  background: var(--color-primary);
  color: white;
  border-radius: var(--radius);
  text-align: center;
  line-height: 28px;
  font-size: 0.85rem;
}

.header-status {
  display: flex;
  align-items: center;
  gap: 12px;
}

.api-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--color-text-secondary);
}

.api-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-gray);
}

.api-dot.connected {
  background: var(--color-success);
}

.api-dot.disconnected {
  background: var(--color-danger);
}

/* ── Navigation ── */
.nav {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 0 24px;
  display: flex;
  gap: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.nav-btn {
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  padding: 12px 16px;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--color-text-secondary);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
  font-family: var(--font-family);
}

.nav-btn:hover {
  color: var(--color-text);
  background: rgba(9, 30, 66, 0.04);
}

.nav-btn.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
}

.nav-btn .badge {
  display: inline-block;
  background: var(--color-border);
  color: var(--color-text-secondary);
  font-size: 0.7rem;
  padding: 1px 6px;
  border-radius: 10px;
  margin-left: 6px;
  font-weight: 600;
}

/* ── Main Content ── */
.main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* ── Cards ── */
.card {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.card-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--color-text);
}

.card-body {
  padding: 0;
}

.card-body.padded {
  padding: 20px;
}

/* ── Help Page ── */
.help-page {
  color: var(--color-text);
}

.help-lead {
  max-width: 760px;
  margin-bottom: 20px;
  color: var(--color-text-secondary);
  font-size: 0.95rem;
}

.help-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 20px 24px;
}

.help-section {
  border-top: 1px solid var(--color-border);
  padding-top: 14px;
}

.help-section h3 {
  margin-bottom: 10px;
  color: var(--color-text);
  font-size: 0.98rem;
  font-weight: 600;
}

.help-steps {
  padding-left: 20px;
}

.help-steps li {
  margin-bottom: 8px;
  color: var(--color-text-secondary);
}

.help-steps li::marker {
  color: var(--color-primary);
  font-weight: 600;
}

.help-note {
  margin-top: 10px;
  color: var(--color-text-muted);
  font-size: 0.84rem;
}

.help-page a {
  color: var(--color-primary);
  font-weight: 600;
  text-decoration: none;
}

.help-page a:hover {
  text-decoration: underline;
}

.help-callout {
  margin-top: 20px;
  padding: 12px 14px;
  border: 1px solid #b3d4ff;
  border-radius: var(--radius);
  background: #deebff;
  color: #0747a6;
  font-size: 0.9rem;
}

.from-email-hint {
  display: block;
  line-height: 1.35;
}

/* ── Toolbar ── */
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.search-input {
  padding: 6px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-family: var(--font-family);
  outline: none;
  width: 220px;
  transition: border-color 0.15s;
}

.search-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(0, 82, 204, 0.15);
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: none;
  border-radius: var(--radius);
  font-size: 0.88rem;
  font-weight: 500;
  font-family: var(--font-family);
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  text-decoration: none;
  line-height: 1.4;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

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

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

.btn-danger {
  background: var(--color-danger);
  color: white;
}

.btn-danger:hover:not(:disabled) {
  background: var(--color-danger-hover);
}

.btn-secondary {
  background: var(--color-bg);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--color-border);
}

.btn-sm {
  padding: 4px 10px;
  font-size: 0.8rem;
}

.btn-icon {
  padding: 4px 8px;
  background: none;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--color-text-secondary);
  font-size: 0.85rem;
  transition: all 0.15s;
}

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

/* ── Tables ── */
.table-wrap {
  overflow-x: auto;
}

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

thead th {
  text-align: left;
  padding: 10px 16px;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--color-text-muted);
  background: var(--color-bg);
  border-bottom: 2px solid var(--color-border);
  white-space: nowrap;
}

tbody td {
  padding: 10px 16px;
  font-size: 0.9rem;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}

tbody tr:nth-child(even) {
  background: rgba(9, 30, 66, 0.015);
}

tbody tr:hover {
  background: rgba(9, 30, 66, 0.04);
}

/* ── Status Badges ── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  white-space: nowrap;
}

.badge-draft {
  background: #dfe1e6;
  color: #42526e;
}

.badge-scheduled {
  background: #deebff;
  color: #0747a6;
}

.badge-sending {
  background: #deebff;
  color: #0052cc;
}

.badge-sent {
  background: #e3fcef;
  color: #006644;
}

.badge-failed {
  background: #ffebe6;
  color: #bf2600;
}

.badge-active {
  background: #e3fcef;
  color: #006644;
}

.badge-unsubscribed {
  background: #fff7e6;
  color: #974f0c;
}

.badge-bounced {
  background: #ffebe6;
  color: #bf2600;
}

.badge-complained {
  background: #ffebe6;
  color: #bf2600;
}

.badge-queued {
  background: #deebff;
  color: #0052cc;
}

.badge-pending {
  background: #f4f5f7;
  color: #42526e;
}

.badge-partial {
  background: #fff7e6;
  color: #974f0c;
}

.badge-completed {
  background: #e3fcef;
  color: #006644;
}

.badge-processing {
  background: #deebff;
  color: #0052cc;
}

.badge-system {
  background: #e3fcef;
  color: #006644;
}

.badge-custom {
  background: #deebff;
  color: #0747a6;
}

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

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-text-secondary);
  margin-bottom: 4px;
}

.form-group .hint {
  font-size: 0.78rem;
  color: var(--color-text-muted);
  margin-top: 2px;
}

.form-control {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-family: var(--font-family);
  outline: none;
  transition: border-color 0.15s;
  background: var(--color-surface);
}

.form-control:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(0, 82, 204, 0.15);
}

textarea.form-control {
  min-height: 120px;
  resize: vertical;
  font-family: var(--font-mono);
  font-size: 0.82rem;
}

select.form-control {
  cursor: pointer;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 20px;
}

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(9, 30, 66, 0.5);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal.wide {
  max-width: 800px;
}

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

.modal-header h3 {
  font-size: 1.05rem;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  color: var(--color-text-secondary);
  padding: 4px;
  line-height: 1;
}

.modal-close:hover {
  color: var(--color-text);
}

.modal-body {
  padding: 20px;
}

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

/* ── Alerts ── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  margin-bottom: 16px;
}

.alert-error {
  background: #ffebe6;
  color: #bf2600;
  border: 1px solid #ffbdad;
}

.alert-success {
  background: #e3fcef;
  color: #006644;
  border: 1px solid #abf5d1;
}

.alert-info {
  background: #deebff;
  color: #0747a6;
  border: 1px solid #b3d4ff;
}

.alert-warning {
  background: #fff7e6;
  color: #974f0c;
  border: 1px solid #ffe2a8;
}

/* ── Loading ── */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: var(--color-text-muted);
  font-size: 0.95rem;
}

.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-right: 10px;
}

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

/* ── Empty State ── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--color-text-muted);
}

.empty-state .empty-icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
  opacity: 0.5;
}

.empty-state p {
  font-size: 0.95rem;
  margin-bottom: 16px;
}

/* ── Pagination ── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px;
  border-top: 1px solid var(--color-border);
}

.pagination-info {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  margin: 0 8px;
}

/* ── Send Progress ── */
.progress-bar {
  width: 100%;
  height: 8px;
  background: var(--color-border);
  border-radius: 4px;
  overflow: hidden;
  margin: 8px 0;
}

.progress-fill {
  height: 100%;
  background: var(--color-primary);
  border-radius: 4px;
  transition: width 0.5s ease;
}

.progress-stats {
  display: flex;
  gap: 16px;
  font-size: 0.85rem;
  color: var(--color-text-secondary);
  margin-top: 8px;
  flex-wrap: wrap;
}

.progress-stats span {
  display: flex;
  align-items: center;
  gap: 4px;
}

.progress-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.progress-dot.sent {
  background: var(--color-success);
}

.progress-dot.failed {
  background: var(--color-danger);
}

.progress-dot.pending {
  background: var(--color-gray);
}

/* ── Import Result ── */
.import-result {
  padding: 20px;
}

.import-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
  margin: 16px 0;
}

.import-stat {
  text-align: center;
  padding: 12px;
  background: var(--color-bg);
  border-radius: var(--radius);
}

.import-stat .stat-value {
  font-size: 1.4rem;
  font-weight: 700;
}

.import-stat .stat-label {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-top: 2px;
}

.stat-value.success {
  color: var(--color-success);
}

.stat-value.warning {
  color: var(--color-warning);
}

.stat-value.danger {
  color: var(--color-danger);
}

/* ── Confirm Dialog ── */
.confirm-message {
  font-size: 0.95rem;
  margin-bottom: 8px;
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .header {
    padding: 0 12px;
  }

  .nav {
    padding: 0 12px;
  }

  .nav-btn {
    padding: 12px 10px;
    font-size: 0.8rem;
  }

  .main {
    padding: 16px 12px;
  }

  .card-header {
    padding: 12px 16px;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .toolbar {
    width: 100%;
  }

  .search-input {
    width: 100%;
  }

  .modal {
    max-width: 100%;
    margin: 0;
    border-radius: var(--radius) var(--radius) 0 0;
    align-self: flex-end;
    max-height: 85vh;
  }

  .table-wrap table {
    font-size: 0.82rem;
  }

  thead th,
  tbody td {
    padding: 8px 10px;
  }

  .header-status {
    display: none;
  }
}

@media (max-width: 480px) {
  .nav-btn {
    padding: 10px 8px;
    font-size: 0.75rem;
  }

  .btn {
    padding: 6px 10px;
    font-size: 0.8rem;
  }
}

/* ── Editor Toolbar ── */
.editor-toolbar {
  display: flex;
  gap: 6px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}

/* ── Preview Panel ── */
.preview-panel {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  margin-top: 12px;
  margin-bottom: 16px;
  overflow: hidden;
}
.preview-panel-header {
  padding: 8px 12px;
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.preview-panel-header h4 {
  font-size: 0.85rem;
  font-weight: 600;
}
.preview-subject-line {
  padding: 8px 12px;
  border-bottom: 1px solid var(--color-border);
  font-size: 0.85rem;
  background: #fffbe6;
}
.preview-subject-line strong {
  margin-right: 4px;
}
.preview-mode-tabs {
  display: flex;
  border-bottom: 1px solid var(--color-border);
}
.preview-mode-tab {
  padding: 6px 12px;
  font-size: 0.8rem;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  font-family: var(--font-family);
  color: var(--color-text-secondary);
}
.preview-mode-tab.active {
  border-bottom-color: var(--color-primary);
  color: var(--color-primary);
}
.preview-iframe-wrap {
  background: #fff;
}
.preview-iframe-wrap iframe {
  width: 100%;
  border: none;
  min-height: 350px;
  display: block;
}
.preview-iframe-wrap.mobile-preview iframe {
  max-width: 375px;
  margin: 0 auto;
  border-left: 1px solid var(--color-border);
  border-right: 1px solid var(--color-border);
}

/* ── Link Validation ── */
.link-validation {
  margin-top: 8px;
  margin-bottom: 16px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
}
.link-validation-header {
  padding: 8px 12px;
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.85rem;
  font-weight: 600;
}
.link-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--color-border);
  font-size: 0.82rem;
}
.link-item:last-child {
  border-bottom: none;
}
.link-icon {
  font-weight: bold;
  flex-shrink: 0;
}
.link-icon.valid {
  color: var(--color-success);
}
.link-icon.invalid {
  color: var(--color-danger);
}
.link-url {
  flex: 1;
  word-break: break-all;
  font-family: var(--font-mono);
  font-size: 0.78rem;
}
.link-issues {
  color: var(--color-danger);
  font-size: 0.78rem;
  flex-shrink: 0;
}

/* ── R2 Body Note ── */
.r2-note {
  padding: 8px 12px;
  background: #deebff;
  border-radius: var(--radius);
  margin-bottom: 12px;
  font-size: 0.82rem;
  color: #0747a6;
}

/* ── Validation Link Check ── */
.validation-controls {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-top: 4px;
}

/* ── Template Picker ── */
.template-picker-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.template-picker-row .form-control {
  flex: 1;
}

/* ── Toggle Switch ── */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}
.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #d1d5db;
  border-radius: 24px;
  transition: 0.2s;
}
.toggle-slider::before {
  content: "";
  position: absolute;
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  border-radius: 50%;
  transition: 0.2s;
}
.toggle-switch input:checked + .toggle-slider {
  background-color: #4f46e5;
}
.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(20px);
}

/* ── Success Button ── */
.btn-success {
  background-color: #16a34a !important;
  color: #fff !important;
}

/* ── Filter Bar ── */
.filter-bar {
  background: var(--color-bg);
  border-radius: var(--radius);
  padding: 12px 16px;
}

.filter-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: flex-end;
}

.filter-row + .filter-row {
  margin-top: 10px;
}

.filter-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 140px;
}

.filter-item label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--color-text-muted);
}

.filter-select {
  padding: 6px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-family: var(--font-family);
  background: var(--color-surface);
  outline: none;
  transition: border-color 0.15s;
}

.filter-select:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(0, 82, 204, 0.15);
}
