:root {
  --primary: #1a6b4e;
  --primary-dark: #134d38;
  --primary-light: #e8f5ef;
  --danger: #d32f2f;
  --danger-light: #fdecea;
  --warning: #f57c00;
  --warning-light: #fff3e0;
  --success: #2e7d32;
  --success-light: #e8f5e9;
  --gray-50: #fafafa;
  --gray-100: #f5f5f5;
  --gray-200: #eeeeee;
  --gray-300: #e0e0e0;
  --gray-400: #bdbdbd;
  --gray-500: #9e9e9e;
  --gray-600: #757575;
  --gray-700: #616161;
  --gray-800: #424242;
  --gray-900: #212121;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.1), 0 2px 4px rgba(0,0,0,0.06);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--gray-100);
  color: var(--gray-900);
  line-height: 1.5;
}

/* Layout */
.container { max-width: 900px; margin: 0 auto; padding: 2rem 1rem; }
.container-wide { max-width: 1200px; margin: 0 auto; padding: 2rem 1rem; }

/* Header */
.header {
  background: var(--primary);
  color: white;
  padding: 1rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-md);
}
.header h1 { font-size: 1.25rem; font-weight: 600; }
.header-user { font-size: 0.875rem; opacity: 0.9; }
.header nav { display: flex; gap: 1.5rem; }
.header nav a {
  color: white;
  text-decoration: none;
  font-size: 0.875rem;
  opacity: 0.85;
  transition: opacity 0.2s;
}
.header nav a:hover, .header nav a.active { opacity: 1; border-bottom: 2px solid white; }

/* Cards */
.card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}
.card h2 { font-size: 1.125rem; margin-bottom: 1rem; color: var(--gray-800); }

/* Forms */
.form-group { margin-bottom: 1.25rem; }
.form-group label {
  display: block;
  font-weight: 500;
  margin-bottom: 0.375rem;
  font-size: 0.875rem;
  color: var(--gray-700);
}
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 0.625rem 0.75rem;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 0.9375rem;
  font-family: inherit;
  transition: border-color 0.2s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26,107,78,0.15);
}
.form-group textarea { resize: vertical; min-height: 80px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-group .hint { font-size: 0.8125rem; color: var(--gray-500); margin-top: 0.25rem; }
.hidden { display: none !important; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.625rem 1.25rem;
  border: none;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s;
  text-decoration: none;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-secondary { background: var(--gray-200); color: var(--gray-800); }
.btn-secondary:hover:not(:disabled) { background: var(--gray-300); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover:not(:disabled) { background: #b71c1c; }
.btn-small { padding: 0.375rem 0.75rem; font-size: 0.8125rem; }
.btn-icon { padding: 0.375rem; background: none; color: var(--gray-600); }
.btn-icon:hover { color: var(--gray-900); }

/* Tables */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.75rem; font-size: 0.875rem; }
th { font-weight: 600; color: var(--gray-600); border-bottom: 2px solid var(--gray-200); }
td { border-bottom: 1px solid var(--gray-200); }
tr:hover td { background: var(--gray-50); }
tr { cursor: pointer; }

/* Badges / Status */
.badge {
  display: inline-block;
  padding: 0.25rem 0.625rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge-pending { background: var(--warning-light); color: var(--warning); }
.badge-processing { background: #e3f2fd; color: #1565c0; }
.badge-completed, .badge-success { background: var(--success-light); color: var(--success); }
.badge-error { background: var(--danger-light); color: var(--danger); }
.badge-skipped { background: var(--gray-200); color: var(--gray-600); }

/* Timeline */
.timeline { list-style: none; }
.timeline-item {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--gray-100);
}
.timeline-item:last-child { border-bottom: none; }
.timeline-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
  flex-shrink: 0;
}
.timeline-icon.success { background: var(--success-light); color: var(--success); }
.timeline-icon.error { background: var(--danger-light); color: var(--danger); }
.timeline-icon.pending { background: var(--gray-200); color: var(--gray-500); }
.timeline-icon.skipped { background: var(--gray-100); color: var(--gray-400); }
.timeline-content { flex: 1; }
.timeline-content h4 { font-size: 0.875rem; font-weight: 500; }
.timeline-content p { font-size: 0.8125rem; color: var(--gray-600); }
.timeline-actions { flex-shrink: 0; }

.error-details {
  margin-top: 0.5rem;
  padding: 0.5rem;
  background: var(--gray-50);
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.75rem;
  color: var(--danger);
  max-height: 120px;
  overflow: auto;
  white-space: pre-wrap;
}

/* Filters bar */
.filters {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.filters select, .filters input {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 0.8125rem;
}

/* Template editor */
.editor-toolbar {
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem;
  background: var(--gray-100);
  border: 1px solid var(--gray-300);
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
  flex-wrap: wrap;
}
.editor-toolbar button {
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--gray-300);
  border-radius: 4px;
  background: white;
  cursor: pointer;
  font-size: 0.8125rem;
}
.editor-toolbar button:hover { background: var(--gray-200); }
.editor-area {
  border: 1px solid var(--gray-300);
  border-radius: 0 0 var(--radius) var(--radius);
  min-height: 250px;
  padding: 1rem;
  outline: none;
  font-size: 0.9375rem;
  line-height: 1.6;
}
.variable-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  margin-top: 0.75rem;
}
.variable-chip {
  padding: 0.25rem 0.5rem;
  background: var(--primary-light);
  color: var(--primary);
  border-radius: 4px;
  font-size: 0.75rem;
  cursor: pointer;
  border: 1px solid transparent;
  transition: border-color 0.2s;
}
.variable-chip:hover { border-color: var(--primary); }

/* Preview panel */
.preview-panel {
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  padding: 1.5rem;
  background: white;
}
.preview-subject { font-weight: 600; margin-bottom: 0.75rem; padding-bottom: 0.75rem; border-bottom: 1px solid var(--gray-200); }

/* Links management */
.link-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  border-bottom: 1px solid var(--gray-100);
}
.link-url {
  flex: 1;
  font-family: monospace;
  font-size: 0.8125rem;
  color: var(--gray-700);
  word-break: break-all;
}
.link-url.inactive { opacity: 0.5; text-decoration: line-through; }

/* Alerts */
.alert {
  padding: 1rem 1.25rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.875rem;
}
.alert-success { background: var(--success-light); color: var(--success); }
.alert-error { background: var(--danger-light); color: var(--danger); }
.alert-info { background: #e3f2fd; color: #1565c0; }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal {
  background: white;
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 90%;
  max-width: 500px;
  box-shadow: var(--shadow-md);
}
.modal h3 { margin-bottom: 1rem; }
.modal-actions { display: flex; gap: 0.75rem; justify-content: flex-end; margin-top: 1.5rem; }

/* Success page */
.success-page { text-align: center; padding: 3rem 1rem; }
.success-page .icon { font-size: 3rem; margin-bottom: 1rem; }
.success-page h2 { margin-bottom: 0.5rem; color: var(--success); }

/* Loading */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--gray-300);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

/* Responsive */
@media (max-width: 640px) {
  .form-row { grid-template-columns: 1fr; }
  .header { flex-direction: column; gap: 0.75rem; }
  .filters { flex-direction: column; align-items: stretch; }
}
