.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  direction: rtl;
}

.modal-content {
  background: var(--color-background);
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
  max-width: 600px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 30px;
  color: var(--color-text);
}

.whatsapp-modal h2 {
  margin: 0 0 20px 0;
  font-size: 24px;
  color: var(--color-text);
  text-align: center;
}

.whatsapp-modal h3 {
  font-size: 16px;
  color: var(--color-text);
  margin: 0 0 12px 0;
  font-weight: 600;
}

/* Guests Preview */
.guests-preview {
  background: var(--color-background-secondary);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 15px;
  margin-bottom: 20px;
  max-height: 150px;
  overflow-y: auto;
}

.preview-header {
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.guests-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.guest-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px;
  background: var(--color-background);
  border-radius: 4px;
  font-size: 14px;
}

.guest-name {
  font-weight: 500;
  color: var(--color-text);
}

.guest-phone {
  color: var(--color-text-secondary);
  font-size: 12px;
}

.guest-phone.empty {
  color: var(--color-error, #e74c3c);
}

/* Form Styles */
.whatsapp-form {
  margin-bottom: 20px;
}

.form-section {
  margin-bottom: 20px;
}

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

.form-group {
  display: flex;
  flex-direction: column;
}

.form-group label {
  margin-bottom: 6px;
  font-size: 14px;
  font-weight: 500;
  color: var(--color-text);
}

.form-group input {
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-background);
  color: var(--color-text);
  font-size: 14px;
  transition: all 0.2s ease;
}

.form-group input:focus {
  outline: none;
  border-color: var(--color-primary, #667eea);
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.form-group input:disabled {
  background: var(--color-background-secondary);
  cursor: not-allowed;
  opacity: 0.6;
}

/* Dynamic params grid — 2 cols for wider fields, 1 col on mobile */
.dynamic-params-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 8px;
}

/* Date / time / URL inputs span full width */
.dynamic-params-grid .form-group:has(input[type="date"]),
.dynamic-params-grid .form-group:has(input[type="time"]),
.dynamic-params-grid .form-group:has(input[type="url"]) {
  grid-column: span 1;
}

.auto-param-note {
  font-size: 0.82rem;
  color: var(--color-text-secondary);
  margin-bottom: 10px;
  padding: 6px 10px;
  background: var(--color-background-tertiary);
  border-radius: 6px;
  border-right: 3px solid var(--color-primary);
}

@media (max-width: 520px) {
  .dynamic-params-grid {
    grid-template-columns: 1fr;
  }
}

/* Message Preview */
.message-preview {
  background: var(--color-background-secondary);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 15px;
  margin-bottom: 20px;
}

.preview-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-secondary);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.preview-content {
  background: var(--color-background);
  padding: 12px;
  border-radius: 6px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--color-text);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 200px;
  overflow-y: auto;
}

/* Results Screen */
.results-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 15px;
  margin-bottom: 20px;
}

.result-stat {
  padding: 20px;
  border-radius: 8px;
  text-align: center;
  background: var(--color-background-secondary);
  border: 1px solid var(--color-border);
}

.result-stat.success {
  border-left: 4px solid var(--color-success, #27ae60);
}

.result-stat.failed {
  border-left: 4px solid var(--color-error, #e74c3c);
}

.stat-value {
  font-size: 32px;
  font-weight: bold;
  margin-bottom: 5px;
  color: var(--color-text);
}

.stat-label {
  font-size: 12px;
  color: var(--color-text-secondary);
  text-transform: uppercase;
}

.results-list {
  background: var(--color-background-secondary);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  max-height: 250px;
  overflow-y: auto;
  margin-bottom: 20px;
}

.result-item {
  padding: 12px 15px;
  border-bottom: 1px solid var(--color-border);
  font-size: 14px;
}

.result-item:last-child {
  border-bottom: none;
}

.result-item.sent {
  border-right: 3px solid var(--color-success, #27ae60);
}

.result-item.failed {
  border-right: 3px solid var(--color-error, #e74c3c);
}

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

.result-name {
  font-weight: 500;
  color: var(--color-text);
}

.result-status {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 3px;
}

.result-status.sent {
  background: rgba(39, 174, 96, 0.1);
  color: var(--color-success, #27ae60);
}

.result-status.failed {
  background: rgba(231, 76, 60, 0.1);
  color: var(--color-error, #e74c3c);
}

.result-phone {
  font-size: 12px;
  color: var(--color-text-secondary);
  margin-bottom: 4px;
}

.result-error {
  font-size: 12px;
  color: var(--color-error, #e74c3c);
  margin-top: 4px;
  padding: 6px;
  background: rgba(231, 76, 60, 0.05);
  border-radius: 3px;
}

/* Buttons */
.modal-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 20px;
}

.btn-primary,
.btn-secondary {
  padding: 12px 20px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
}

.btn-primary {
  background: var(--color-primary, #667eea);
  color: white;
}

.btn-primary:hover:not(:disabled) {
  background: var(--color-primary-dark, #5568d3);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

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

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

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

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

.btn-warning {
  padding: 12px 20px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
  background: #e67e22;
  color: white;
}

.btn-warning:hover:not(:disabled) {
  background: #d35400;
  box-shadow: 0 4px 12px rgba(230, 126, 34, 0.35);
}

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

/* Responsive */
@media (max-width: 768px) {
  .modal-content {
    width: 95%;
    padding: 20px;
  }

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

  .results-summary {
    grid-template-columns: 1fr;
  }

  .modal-buttons {
    grid-template-columns: 1fr;
  }
}

/* Scrollbar styling */
.guests-preview::-webkit-scrollbar,
.preview-content::-webkit-scrollbar,
.results-list::-webkit-scrollbar {
  width: 6px;
}

.guests-preview::-webkit-scrollbar-track,
.preview-content::-webkit-scrollbar-track,
.results-list::-webkit-scrollbar-track {
  background: transparent;
}

.guests-preview::-webkit-scrollbar-thumb,
.preview-content::-webkit-scrollbar-thumb,
.results-list::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: 3px;
}

.guests-preview::-webkit-scrollbar-thumb:hover,
.preview-content::-webkit-scrollbar-thumb:hover,
.results-list::-webkit-scrollbar-thumb:hover {
  background: var(--color-text-secondary);
}

/* ── Template selector bar ── */
.template-selector {
  margin-bottom: 1rem;
}

.template-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.35rem;
}

.template-select-row {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}

.template-select {
  flex: 1;
  width: 100%;
  padding: 0.45rem 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--color-border, #ccc);
  background: var(--color-background, #fff);
  color: var(--color-text, #222);
  font-size: 0.9rem;
}

.template-description {
  color: var(--color-text-secondary, #888);
  font-size: 0.78rem;
  margin-top: 0.25rem;
  display: block;
}

.template-loading {
  color: var(--color-text-secondary, #888);
  font-size: 0.88rem;
}

.btn-add-template {
  background: transparent;
  border: 1px solid #25d366;
  color: #25d366;
  border-radius: 5px;
  padding: 0.2rem 0.65rem;
  font-size: 0.8rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}

.btn-add-template:hover:not(:disabled) {
  background: #25d366;
  color: #fff;
}

.btn-delete-template {
  background: transparent;
  border: 1px solid #e57373;
  border-radius: 5px;
  padding: 0.25rem 0.5rem;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 0.15s;
  flex-shrink: 0;
}

.btn-delete-template:hover:not(:disabled) {
  background: #fdecea;
}
